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

45 lines
850 B
React
Raw Normal View History

import React from 'react'
import {
CreditAmount,
} from 'component/common'
2017-05-12 19:14:06 +02:00
class FilePrice extends React.Component{
componentWillMount() {
2017-05-12 19:14:06 +02:00
this.fetchCost(this.props)
}
componentWillReceiveProps(nextProps) {
this.fetchCost(nextProps)
}
2017-05-12 19:14:06 +02:00
fetchCost(props) {
const {
costInfo,
fetchCostInfo,
uri,
fetching,
2017-05-12 19:14:06 +02:00
} = props
if (costInfo === undefined && !fetching) {
2017-05-12 19:14:06 +02:00
fetchCostInfo(uri)
}
}
2017-05-12 19:14:06 +02:00
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