diff options
author | Alexander Tseung <alextsg@gmail.com> | 2018-08-16 10:18:01 +0800 |
---|---|---|
committer | Alexander Tseung <alextsg@gmail.com> | 2018-08-24 07:45:27 +0800 |
commit | da0df790472c816d933e9b697e4dab1a429740a3 (patch) | |
tree | aa29b66b2a8aa6f0bff0141664aef2a49ec0d291 /ui/app/components/token-currency-display | |
parent | 6670bc0e09dacaf9a91031a348d1a551ed1e3987 (diff) | |
download | tangerine-wallet-browser-da0df790472c816d933e9b697e4dab1a429740a3.tar tangerine-wallet-browser-da0df790472c816d933e9b697e4dab1a429740a3.tar.gz tangerine-wallet-browser-da0df790472c816d933e9b697e4dab1a429740a3.tar.bz2 tangerine-wallet-browser-da0df790472c816d933e9b697e4dab1a429740a3.tar.lz tangerine-wallet-browser-da0df790472c816d933e9b697e4dab1a429740a3.tar.xz tangerine-wallet-browser-da0df790472c816d933e9b697e4dab1a429740a3.tar.zst tangerine-wallet-browser-da0df790472c816d933e9b697e4dab1a429740a3.zip |
Add CurrencyDisplay and TokenCurrencyDisplay components
Diffstat (limited to 'ui/app/components/token-currency-display')
-rw-r--r-- | ui/app/components/token-currency-display/index.js | 1 | ||||
-rw-r--r-- | ui/app/components/token-currency-display/token-currency-display.component.js | 54 |
2 files changed, 55 insertions, 0 deletions
diff --git a/ui/app/components/token-currency-display/index.js b/ui/app/components/token-currency-display/index.js new file mode 100644 index 000000000..6065cae1f --- /dev/null +++ b/ui/app/components/token-currency-display/index.js @@ -0,0 +1 @@ +export { default } from './token-currency-display.component' diff --git a/ui/app/components/token-currency-display/token-currency-display.component.js b/ui/app/components/token-currency-display/token-currency-display.component.js new file mode 100644 index 000000000..e992442d4 --- /dev/null +++ b/ui/app/components/token-currency-display/token-currency-display.component.js @@ -0,0 +1,54 @@ +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 TokenCurrencyDisplayContainer 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} + /> + ) + } +} |