mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-28 05:12:18 +01:00
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
import React, { PureComponent } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import CurrencyDisplay from '../currency-display/currency-display.component'
|
|
import { getTokenData } from '../../helpers/transactions.util'
|
|
import { calcTokenAmount } from '../../token-util'
|
|
|
|
export default class TokenCurrencyDisplay extends PureComponent {
|
|
static propTypes = {
|
|
transactionData: PropTypes.string,
|
|
token: PropTypes.object,
|
|
}
|
|
|
|
state = {
|
|
displayValue: '',
|
|
}
|
|
|
|
componentDidMount () {
|
|
this.setDisplayValue()
|
|
}
|
|
|
|
componentDidUpdate (prevProps) {
|
|
const { transactionData } = this.props
|
|
const { transactionData: prevTransactionData } = prevProps
|
|
|
|
if (transactionData !== prevTransactionData) {
|
|
this.setDisplayValue()
|
|
}
|
|
}
|
|
|
|
setDisplayValue () {
|
|
const { transactionData: data, token } = this.props
|
|
const { decimals = '', symbol = '' } = token
|
|
const tokenData = getTokenData(data)
|
|
|
|
let displayValue
|
|
|
|
if (tokenData.params && tokenData.params.length === 2) {
|
|
const tokenValue = tokenData.params[1].value
|
|
const tokenAmount = calcTokenAmount(tokenValue, decimals)
|
|
displayValue = `${tokenAmount} ${symbol}`
|
|
}
|
|
|
|
this.setState({ displayValue })
|
|
}
|
|
|
|
render () {
|
|
return (
|
|
<CurrencyDisplay
|
|
{...this.props}
|
|
displayValue={this.state.displayValue}
|
|
/>
|
|
)
|
|
}
|
|
}
|