|
|
@ -1,5 +1,7 @@ |
|
|
|
import React, { Component } from 'react' |
|
|
|
import React, { useContext, useMemo } from 'react' |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
|
|
|
|
import BigNumber from 'bignumber.js' |
|
|
|
|
|
|
|
import { I18nContext } from '../../contexts/i18n' |
|
|
|
import ConfirmTransactionBase from '../confirm-transaction-base' |
|
|
|
import ConfirmTransactionBase from '../confirm-transaction-base' |
|
|
|
import UserPreferencedCurrencyDisplay from '../../components/app/user-preferenced-currency-display' |
|
|
|
import UserPreferencedCurrencyDisplay from '../../components/app/user-preferenced-currency-display' |
|
|
|
import { |
|
|
|
import { |
|
|
@ -11,112 +13,103 @@ import { |
|
|
|
import { getWeiHexFromDecimalValue } from '../../helpers/utils/conversions.util' |
|
|
|
import { getWeiHexFromDecimalValue } from '../../helpers/utils/conversions.util' |
|
|
|
import { ETH, PRIMARY } from '../../helpers/constants/common' |
|
|
|
import { ETH, PRIMARY } from '../../helpers/constants/common' |
|
|
|
|
|
|
|
|
|
|
|
export default class ConfirmTokenTransactionBase extends Component { |
|
|
|
export default function ConfirmTokenTransactionBase ({ |
|
|
|
static contextTypes = { |
|
|
|
toAddress, |
|
|
|
t: PropTypes.func, |
|
|
|
tokenAddress, |
|
|
|
} |
|
|
|
tokenAmount = '0', |
|
|
|
|
|
|
|
tokenSymbol, |
|
|
|
|
|
|
|
fiatTransactionTotal, |
|
|
|
|
|
|
|
ethTransactionTotal, |
|
|
|
|
|
|
|
contractExchangeRate, |
|
|
|
|
|
|
|
conversionRate, |
|
|
|
|
|
|
|
currentCurrency, |
|
|
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
const t = useContext(I18nContext) |
|
|
|
|
|
|
|
|
|
|
|
static propTypes = { |
|
|
|
const hexWeiValue = useMemo(() => { |
|
|
|
tokenAddress: PropTypes.string, |
|
|
|
if (tokenAmount === '0' || !contractExchangeRate) { |
|
|
|
toAddress: PropTypes.string, |
|
|
|
return '0' |
|
|
|
tokenAmount: PropTypes.string, |
|
|
|
} |
|
|
|
tokenSymbol: PropTypes.string, |
|
|
|
|
|
|
|
fiatTransactionTotal: PropTypes.string, |
|
|
|
|
|
|
|
ethTransactionTotal: PropTypes.string, |
|
|
|
|
|
|
|
contractExchangeRate: PropTypes.number, |
|
|
|
|
|
|
|
conversionRate: PropTypes.number, |
|
|
|
|
|
|
|
currentCurrency: PropTypes.string, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static defaultProps = { |
|
|
|
|
|
|
|
tokenAmount: '0', |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getFiatTransactionAmount () { |
|
|
|
|
|
|
|
const { tokenAmount, currentCurrency, conversionRate, contractExchangeRate } = this.props |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return convertTokenToFiat({ |
|
|
|
|
|
|
|
value: tokenAmount, |
|
|
|
|
|
|
|
toCurrency: currentCurrency, |
|
|
|
|
|
|
|
conversionRate, |
|
|
|
|
|
|
|
contractExchangeRate, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderSubtitleComponent () { |
|
|
|
const decimalEthValue = ( |
|
|
|
const { contractExchangeRate, tokenAmount } = this.props |
|
|
|
(new BigNumber(tokenAmount)).times(new BigNumber(contractExchangeRate)) |
|
|
|
|
|
|
|
).toFixed() |
|
|
|
|
|
|
|
|
|
|
|
const decimalEthValue = (tokenAmount * contractExchangeRate) || '0' |
|
|
|
return getWeiHexFromDecimalValue({ |
|
|
|
const hexWeiValue = getWeiHexFromDecimalValue({ |
|
|
|
|
|
|
|
value: decimalEthValue, |
|
|
|
value: decimalEthValue, |
|
|
|
fromCurrency: ETH, |
|
|
|
fromCurrency: ETH, |
|
|
|
fromDenomination: ETH, |
|
|
|
fromDenomination: ETH, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
}, [tokenAmount, contractExchangeRate]) |
|
|
|
|
|
|
|
|
|
|
|
return typeof contractExchangeRate === 'undefined' |
|
|
|
const secondaryTotalTextOverride = useMemo(() => { |
|
|
|
? ( |
|
|
|
|
|
|
|
<span> |
|
|
|
|
|
|
|
{ this.context.t('noConversionRateAvailable') } |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
<UserPreferencedCurrencyDisplay |
|
|
|
|
|
|
|
value={hexWeiValue} |
|
|
|
|
|
|
|
type={PRIMARY} |
|
|
|
|
|
|
|
showEthLogo |
|
|
|
|
|
|
|
hideLabel |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderPrimaryTotalTextOverride () { |
|
|
|
|
|
|
|
const { tokenAmount, tokenSymbol, ethTransactionTotal } = this.props |
|
|
|
|
|
|
|
const tokensText = `${tokenAmount} ${tokenSymbol}` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<div> |
|
|
|
|
|
|
|
<span>{ `${tokensText} + ` }</span> |
|
|
|
|
|
|
|
<img |
|
|
|
|
|
|
|
src="/images/eth.svg" |
|
|
|
|
|
|
|
height="18" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
<span>{ ethTransactionTotal }</span> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getSecondaryTotalTextOverride () { |
|
|
|
|
|
|
|
const { fiatTransactionTotal, currentCurrency, contractExchangeRate } = this.props |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof contractExchangeRate === 'undefined') { |
|
|
|
if (typeof contractExchangeRate === 'undefined') { |
|
|
|
return formatCurrency(fiatTransactionTotal, currentCurrency) |
|
|
|
return formatCurrency(fiatTransactionTotal, currentCurrency) |
|
|
|
} |
|
|
|
} |
|
|
|
const fiatTransactionAmount = this.getFiatTransactionAmount() |
|
|
|
|
|
|
|
|
|
|
|
const fiatTransactionAmount = convertTokenToFiat({ |
|
|
|
|
|
|
|
value: tokenAmount, |
|
|
|
|
|
|
|
toCurrency: currentCurrency, |
|
|
|
|
|
|
|
conversionRate, |
|
|
|
|
|
|
|
contractExchangeRate, |
|
|
|
|
|
|
|
}) |
|
|
|
const fiatTotal = addFiat(fiatTransactionAmount, fiatTransactionTotal) |
|
|
|
const fiatTotal = addFiat(fiatTransactionAmount, fiatTransactionTotal) |
|
|
|
const roundedFiatTotal = roundExponential(fiatTotal) |
|
|
|
const roundedFiatTotal = roundExponential(fiatTotal) |
|
|
|
return formatCurrency(roundedFiatTotal, currentCurrency) |
|
|
|
return formatCurrency(roundedFiatTotal, currentCurrency) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
currentCurrency, |
|
|
|
|
|
|
|
conversionRate, |
|
|
|
|
|
|
|
contractExchangeRate, |
|
|
|
|
|
|
|
fiatTransactionTotal, |
|
|
|
|
|
|
|
tokenAmount, |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
render () { |
|
|
|
const tokensText = `${tokenAmount} ${tokenSymbol}` |
|
|
|
const { |
|
|
|
|
|
|
|
toAddress, |
|
|
|
|
|
|
|
tokenAddress, |
|
|
|
|
|
|
|
tokenSymbol, |
|
|
|
|
|
|
|
tokenAmount, |
|
|
|
|
|
|
|
...restProps |
|
|
|
|
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tokensText = `${tokenAmount} ${tokenSymbol}` |
|
|
|
return ( |
|
|
|
|
|
|
|
<ConfirmTransactionBase |
|
|
|
|
|
|
|
toAddress={toAddress} |
|
|
|
|
|
|
|
identiconAddress={tokenAddress} |
|
|
|
|
|
|
|
title={tokensText} |
|
|
|
|
|
|
|
subtitleComponent={ |
|
|
|
|
|
|
|
contractExchangeRate === undefined |
|
|
|
|
|
|
|
? ( |
|
|
|
|
|
|
|
<span> |
|
|
|
|
|
|
|
{ t('noConversionRateAvailable') } |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
<UserPreferencedCurrencyDisplay |
|
|
|
|
|
|
|
value={hexWeiValue} |
|
|
|
|
|
|
|
type={PRIMARY} |
|
|
|
|
|
|
|
showEthLogo |
|
|
|
|
|
|
|
hideLabel |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
primaryTotalTextOverride={( |
|
|
|
|
|
|
|
<div> |
|
|
|
|
|
|
|
<span>{ `${tokensText} + ` }</span> |
|
|
|
|
|
|
|
<img |
|
|
|
|
|
|
|
src="/images/eth.svg" |
|
|
|
|
|
|
|
height="18" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
<span>{ ethTransactionTotal }</span> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
secondaryTotalTextOverride={secondaryTotalTextOverride} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
ConfirmTokenTransactionBase.propTypes = { |
|
|
|
<ConfirmTransactionBase |
|
|
|
tokenAddress: PropTypes.string, |
|
|
|
toAddress={toAddress} |
|
|
|
toAddress: PropTypes.string, |
|
|
|
identiconAddress={tokenAddress} |
|
|
|
tokenAmount: PropTypes.string, |
|
|
|
title={tokensText} |
|
|
|
tokenSymbol: PropTypes.string, |
|
|
|
subtitleComponent={this.renderSubtitleComponent()} |
|
|
|
fiatTransactionTotal: PropTypes.string, |
|
|
|
primaryTotalTextOverride={this.renderPrimaryTotalTextOverride()} |
|
|
|
ethTransactionTotal: PropTypes.string, |
|
|
|
secondaryTotalTextOverride={this.getSecondaryTotalTextOverride()} |
|
|
|
contractExchangeRate: PropTypes.number, |
|
|
|
{...restProps} |
|
|
|
conversionRate: PropTypes.number, |
|
|
|
/> |
|
|
|
currentCurrency: PropTypes.string, |
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|