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

62 lines
1.4 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
2018-03-26 23:32:43 +02:00
import CreditAmount from 'component/common/credit-amount';
type Props = {
showFullPrice: boolean,
costInfo: ?{ includesData: boolean, cost: number },
fetchCostInfo: string => void,
uri: string,
fetching: boolean,
claim: ?{},
2018-07-25 06:23:58 +02:00
// below props are just passed to <CreditAmount />
2018-10-19 22:38:07 +02:00
badge?: boolean,
2018-07-25 06:23:58 +02:00
inheritStyle?: boolean,
showLBC?: boolean,
2018-08-06 19:58:33 +02:00
hideFree?: boolean, // hide the file price if it's free
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, fetchCostInfo, uri, fetching, claim } = props;
if (costInfo === undefined && !fetching && claim) {
2017-06-06 23:19:12 +02:00
fetchCostInfo(uri);
2017-05-12 19:14:06 +02:00
}
};
render() {
2018-10-19 22:38:07 +02:00
const { costInfo, showFullPrice, badge, inheritStyle, showLBC, hideFree } = this.props;
2018-08-06 19:58:33 +02:00
if (costInfo && !costInfo.cost && hideFree) {
return null;
}
2017-05-12 19:14:06 +02:00
return costInfo ? (
2017-06-06 23:19:12 +02:00
<CreditAmount
showFree
2018-10-19 22:38:07 +02:00
badge={badge}
2018-07-25 06:23:58 +02:00
inheritStyle={inheritStyle}
showLBC={showLBC}
2017-06-06 23:19:12 +02:00
amount={costInfo.cost}
isEstimate={!costInfo.includesData}
showFullPrice={showFullPrice}
2017-06-06 23:19:12 +02:00
/>
) : null;
2017-05-12 19:14:06 +02:00
}
}
2017-06-06 06:21:55 +02:00
export default FilePrice;