lbry-desktop/ui/js/component/filePrice/view.jsx
2017-06-05 21:21:55 -07:00

43 lines
817 B
JavaScript

import React from 'react';
import { CreditAmount } from 'component/common';
class FilePrice extends React.Component {
componentWillMount() {
this.fetchCost(this.props);
}
componentWillReceiveProps(nextProps) {
this.fetchCost(nextProps);
}
fetchCost(props) {
const { costInfo, fetchCostInfo, uri, fetching } = props;
if (costInfo === undefined && !fetching) {
fetchCostInfo(uri);
}
}
render() {
const { costInfo, look = 'indicator' } = this.props;
const isEstimate = costInfo ? !costInfo.includesData : null;
if (!costInfo) {
return (
<span className={`credit-amount credit-amount--${look}`}>???</span>
);
}
return (
<CreditAmount
label={false}
amount={costInfo.cost}
isEstimate={isEstimate}
showFree={true}
/>
);
}
}
export default FilePrice;