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-11-05 20:31:51 +01:00
|
|
|
customPrices?: { priceFiat: number, priceLBC: 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-10-28 22:25:34 +02:00
|
|
|
const { costInfo, uri, fetching, claim, doFetchCostInfoForUri } = 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,
|
|
|
|
hideFree,
|
|
|
|
claimWasPurchased,
|
|
|
|
type,
|
|
|
|
claimIsMine,
|
2021-11-05 20:31:51 +01:00
|
|
|
customPrices,
|
2021-10-28 22:25:34 +02:00
|
|
|
} = this.props;
|
|
|
|
|
2021-11-05 20:31:51 +01:00
|
|
|
if (!customPrices && (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-11-05 20:31:51 +01:00
|
|
|
amount={costInfo ? costInfo.cost : undefined}
|
|
|
|
customAmounts={
|
|
|
|
customPrices ? { amountFiat: customPrices.priceFiat, amountLBC: customPrices.priceLBC } : undefined
|
|
|
|
}
|
2021-10-28 22:25:34 +02:00
|
|
|
className={className}
|
|
|
|
isEstimate={!!costInfo && !costInfo.includesData}
|
|
|
|
isFiat={isFiat}
|
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;
|