1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-10 11:35:10 +02:00
blog/src/components/molecules/Web3Donation/Conversion.tsx

46 lines
965 B
TypeScript
Raw Normal View History

2018-10-14 20:28:35 +02:00
import React, { PureComponent } from 'react'
2019-11-21 21:32:55 +01:00
import { getFiat } from './utils'
2018-10-14 20:28:35 +02:00
import styles from './Conversion.module.scss'
2019-10-02 13:35:50 +02:00
export default class Conversion extends PureComponent<
2019-10-11 23:50:03 +02:00
{ amount: number },
2019-10-02 13:35:50 +02:00
{ euro: string; dollar: string }
> {
2018-10-14 20:28:35 +02:00
state = {
euro: '0.00',
dollar: '0.00'
}
componentDidMount() {
this.getFiatResponse()
}
2019-10-02 13:35:50 +02:00
componentDidUpdate(prevProps: any) {
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() {
try {
const { dollar, euro } = await getFiat(this.props.amount)
this.setState({ euro, dollar })
} catch (error) {
2019-11-21 21:32:55 +01:00
console.error(error.message)
}
2018-10-14 20:28:35 +02:00
}
render() {
const { dollar, euro } = this.state
2018-10-14 20:28:35 +02:00
return (
<div className={styles.conversion}>
<span>{dollar !== '0.00' && `= $ ${dollar}`}</span>
<span>{euro !== '0.00' && `= € ${euro}`}</span>
2018-10-14 20:28:35 +02:00
</div>
)
}
}