1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-17 01:53:13 +02:00
blog/src/components/Web3Donation/Conversion.jsx

47 lines
979 B
React
Raw Normal View History

2018-10-14 20:28:35 +02:00
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { getFiat } from './utils'
import styles from './Conversion.module.scss'
export default class Conversion extends PureComponent {
static propTypes = {
amount: PropTypes.string.isRequired
}
state = {
euro: '0.00',
dollar: '0.00'
}
componentDidMount() {
this.getFiatResponse()
}
componentDidUpdate(prevProps) {
2019-01-01 19:32:49 +01:00
const { amount } = this.props
2018-10-14 20:28:35 +02:00
if (amount !== prevProps.amount) {
this.getFiatResponse()
}
}
async getFiatResponse() {
const { dollar, euro } = await getFiat(this.props.amount)
this.setState({
euro: euro,
dollar: dollar
})
}
render() {
return (
<div className={styles.conversion}>
<span>
{this.state.dollar !== '0.00' && `= $ ${this.state.dollar}`}
</span>
<span>{this.state.euro !== '0.00' && `= € ${this.state.euro}`}</span>
</div>
)
}
}