mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 12:56:01 +01:00
4c87c05a02
* Fix rounding issue when sending max tokens * Ensure amount row shows exact amount of max tokens on send screen (#2) * Fix tests * Change stored redux value from BigNumber to hex string. Fix TokenInput default value
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
import React, { PureComponent } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import CurrencyDisplay from '../currency-display'
|
|
import { getTokenData } from '../../helpers/transactions.util'
|
|
import { getTokenValue, calcTokenAmount } from '../../token-util'
|
|
|
|
export default class TokenCurrencyDisplay extends PureComponent {
|
|
static propTypes = {
|
|
transactionData: PropTypes.string,
|
|
token: PropTypes.object,
|
|
}
|
|
|
|
state = {
|
|
displayValue: '',
|
|
suffix: '',
|
|
}
|
|
|
|
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: suffix = '' } = token
|
|
const tokenData = getTokenData(data)
|
|
|
|
let displayValue
|
|
|
|
if (tokenData.params && tokenData.params.length) {
|
|
const tokenValue = getTokenValue(tokenData.params)
|
|
displayValue = calcTokenAmount(tokenValue, decimals).toString()
|
|
}
|
|
|
|
this.setState({ displayValue, suffix })
|
|
}
|
|
|
|
render () {
|
|
const { displayValue, suffix } = this.state
|
|
|
|
return (
|
|
<CurrencyDisplay
|
|
{...this.props}
|
|
displayValue={displayValue}
|
|
suffix={suffix}
|
|
/>
|
|
)
|
|
}
|
|
}
|