lbry-desktop/ui/component/filePrice/view.jsx

82 lines
2.1 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
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';
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,
claimWasPurchased: boolean,
costInfo?: ?{ includesData: boolean, cost: number },
fetching: boolean,
showFullPrice: boolean,
2020-05-21 17:38:28 +02:00
type?: string,
uri: string,
2018-07-25 06:23:58 +02:00
// below props are just passed to <CreditAmount />
customPrice: number,
2018-08-06 19:58:33 +02:00
hideFree?: boolean, // hide the file price if it's free
isFiat?: boolean,
showLBC?: boolean,
doFetchCostInfoForUri: (string) => void,
2018-03-26 23:32:43 +02:00
};
class FilePrice extends React.PureComponent<Props> {
static defaultProps = { showFullPrice: false };
2019-08-21 20:22:51 +02:00
componentDidMount() {
this.fetchCost(this.props);
}
2019-08-21 20:22:51 +02:00
componentDidUpdate() {
this.fetchCost(this.props);
}
fetchCost = (props: Props) => {
const { costInfo, uri, fetching, claim, doFetchCostInfoForUri } = props;
if (uri && costInfo === undefined && !fetching && claim) doFetchCostInfoForUri(uri);
};
render() {
const {
costInfo,
showFullPrice,
showLBC,
isFiat,
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
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 ? (
<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
amount={costInfo ? costInfo.cost : customPrice}
className={className}
isEstimate={!!costInfo && !costInfo.includesData}
isFiat={isFiat}
showFree
showFullPrice={showFullPrice}
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-06-06 06:21:55 +02:00
export default FilePrice;