2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2021-10-28 22:25:34 +02:00
|
|
|
import 'scss/component/_file-price.scss';
|
2020-05-21 17:38:28 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import classnames from 'classnames';
|
2018-03-26 23:32:43 +02:00
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
2020-05-21 17:38:28 +02:00
|
|
|
import Icon from 'component/common/icon';
|
2021-10-28 22:25:34 +02:00
|
|
|
import React from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
claim: ?{},
|
2020-05-21 17:38:28 +02:00
|
|
|
claimIsMine: boolean,
|
2021-10-28 22:25:34 +02:00
|
|
|
claimWasPurchased: boolean,
|
|
|
|
costInfo: ?{ includesData: boolean, cost: number },
|
|
|
|
fetching: boolean,
|
|
|
|
showFullPrice: boolean,
|
2020-05-21 17:38:28 +02:00
|
|
|
type?: string,
|
2021-10-28 22:25:34 +02:00
|
|
|
uri: string,
|
2018-07-25 06:23:58 +02:00
|
|
|
// below props are just passed to <CreditAmount />
|
2021-10-28 22:25:34 +02:00
|
|
|
customPrice: number,
|
2018-08-06 19:58:33 +02:00
|
|
|
hideFree?: boolean, // hide the file price if it's free
|
2021-10-28 22:25:34 +02:00
|
|
|
isFiat?: boolean,
|
|
|
|
showLBC?: boolean,
|
|
|
|
doFetchCostInfoForUri: (string) => void,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class FilePrice extends React.PureComponent<Props> {
|
2021-10-28 22:25:34 +02:00
|
|
|
static defaultProps = { showFullPrice: false };
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2019-08-21 20:22:51 +02:00
|
|
|
componentDidMount() {
|
2018-05-03 07:20:31 +02:00
|
|
|
this.fetchCost(this.props);
|
|
|
|
}
|
|
|
|
|
2019-08-21 20:22:51 +02:00
|
|
|
componentDidUpdate() {
|
|
|
|
this.fetchCost(this.props);
|
2018-05-03 07:20:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fetchCost = (props: Props) => {
|
2021-12-31 18:52:26 +01:00
|
|
|
const { costInfo, doFetchCostInfoForUri, uri, fetching, claim } = props;
|
2017-06-05 10:37:37 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
if (uri && costInfo === undefined && !fetching && claim) doFetchCostInfoForUri(uri);
|
2018-05-03 07:20:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2021-10-28 22:25:34 +02:00
|
|
|
const {
|
|
|
|
costInfo,
|
|
|
|
showFullPrice,
|
|
|
|
showLBC,
|
|
|
|
isFiat, // this goes
|
|
|
|
hideFree,
|
|
|
|
claimWasPurchased,
|
|
|
|
type,
|
|
|
|
claimIsMine,
|
|
|
|
customPrice,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!customPrice && (claimIsMine || !costInfo || !costInfo.cost || (!costInfo.cost && hideFree))) return null;
|
2020-05-21 17:38:28 +02:00
|
|
|
|
2021-10-28 22:25:34 +02:00
|
|
|
const className = classnames(claimWasPurchased ? 'filePrice__key' : 'filePrice', {
|
|
|
|
'filePrice--filepage': type === 'filepage',
|
|
|
|
'filePrice--modal': type === 'modal',
|
|
|
|
});
|
2017-05-12 19:14:06 +02:00
|
|
|
|
2020-05-21 17:38:28 +02:00
|
|
|
return claimWasPurchased ? (
|
2021-10-28 22:25:34 +02:00
|
|
|
<span className={className}>
|
2020-05-21 17:38:28 +02:00
|
|
|
<Icon icon={ICONS.PURCHASED} size={type === 'filepage' ? 22 : undefined} />
|
|
|
|
</span>
|
|
|
|
) : (
|
2017-06-06 23:19:12 +02:00
|
|
|
<CreditAmount
|
2021-10-28 22:25:34 +02:00
|
|
|
amount={costInfo ? costInfo.cost : customPrice}
|
|
|
|
className={className}
|
|
|
|
isEstimate={!!costInfo && !costInfo.includesData}
|
|
|
|
isFiat={isFiat} // this goes
|
2018-07-25 02:50:04 +02:00
|
|
|
showFree
|
2017-08-23 02:59:36 +02:00
|
|
|
showFullPrice={showFullPrice}
|
2021-10-28 22:25:34 +02:00
|
|
|
showLBC={showLBC}
|
2017-06-06 23:19:12 +02:00
|
|
|
/>
|
2020-05-21 17:38:28 +02:00
|
|
|
);
|
2017-05-12 19:14:06 +02:00
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default FilePrice;
|