Add fallback when no function found, fix network colors, add fiat values for tokens with contract exchange rates
parent
e9a8c24cc4
commit
d19c42fcae
@ -0,0 +1,85 @@ |
||||
import React, { Component } from 'react' |
||||
import PropTypes from 'prop-types' |
||||
import ConfirmTransactionBase from '../confirm-transaction-base' |
||||
import { |
||||
formatCurrency, |
||||
convertTokenToFiat, |
||||
addFiat, |
||||
} from '../../../helpers/confirm-transaction/util' |
||||
|
||||
export default class ConfirmTokenTransactionBase extends Component { |
||||
static contextTypes = { |
||||
t: PropTypes.func, |
||||
} |
||||
|
||||
static propTypes = { |
||||
tokenAddress: PropTypes.string, |
||||
toAddress: PropTypes.string, |
||||
tokenAmount: PropTypes.number, |
||||
tokenSymbol: PropTypes.string, |
||||
fiatTransactionTotal: PropTypes.string, |
||||
ethTransactionTotal: PropTypes.string, |
||||
contractExchangeRate: PropTypes.number, |
||||
conversionRate: PropTypes.number, |
||||
currentCurrency: PropTypes.string, |
||||
} |
||||
|
||||
getFiatTransactionAmount () { |
||||
const { tokenAmount, currentCurrency, conversionRate, contractExchangeRate } = this.props |
||||
|
||||
return convertTokenToFiat({ |
||||
value: tokenAmount, |
||||
toCurrency: currentCurrency, |
||||
conversionRate, |
||||
contractExchangeRate, |
||||
}) |
||||
} |
||||
|
||||
getSubtitle () { |
||||
const { currentCurrency, contractExchangeRate } = this.props |
||||
|
||||
if (typeof contractExchangeRate === 'undefined') { |
||||
return this.context.t('noConversionRate') |
||||
} else { |
||||
const fiatTransactionAmount = this.getFiatTransactionAmount() |
||||
return formatCurrency(fiatTransactionAmount, currentCurrency) |
||||
} |
||||
} |
||||
|
||||
getFiatTotalTextOverride () { |
||||
const { fiatTransactionTotal, currentCurrency, contractExchangeRate } = this.props |
||||
|
||||
if (typeof contractExchangeRate === 'undefined') { |
||||
return formatCurrency(fiatTransactionTotal, currentCurrency) |
||||
} else { |
||||
const fiatTransactionAmount = this.getFiatTransactionAmount() |
||||
const fiatTotal = addFiat(fiatTransactionAmount, fiatTransactionTotal) |
||||
return formatCurrency(fiatTotal, currentCurrency) |
||||
} |
||||
} |
||||
|
||||
render () { |
||||
const { |
||||
toAddress, |
||||
tokenAddress, |
||||
tokenSymbol, |
||||
tokenAmount, |
||||
ethTransactionTotal, |
||||
...restProps |
||||
} = this.props |
||||
|
||||
const tokensText = `${tokenAmount} ${tokenSymbol}` |
||||
|
||||
return ( |
||||
<ConfirmTransactionBase |
||||
toAddress={toAddress} |
||||
identiconAddress={tokenAddress} |
||||
title={tokensText} |
||||
subtitle={this.getSubtitle()} |
||||
ethTotalTextOverride={`${tokensText} + \u2666 ${ethTransactionTotal}`} |
||||
fiatTotalTextOverride={this.getFiatTotalTextOverride()} |
||||
{...restProps} |
||||
/> |
||||
) |
||||
} |
||||
} |
@ -0,0 +1,34 @@ |
||||
import { connect } from 'react-redux' |
||||
import ConfirmTokenTransactionBase from './confirm-token-transaction-base.component' |
||||
import { |
||||
tokenAmountAndToAddressSelector, |
||||
contractExchangeRateSelector, |
||||
} from '../../../selectors/confirm-transaction' |
||||
|
||||
const mapStateToProps = (state, ownProps) => { |
||||
const { tokenAmount: ownTokenAmount } = ownProps |
||||
const { confirmTransaction, metamask: { currentCurrency, conversionRate } } = state |
||||
const { |
||||
txData: { txParams: { to: tokenAddress } = {} } = {}, |
||||
tokenProps: { tokenSymbol } = {}, |
||||
fiatTransactionTotal, |
||||
ethTransactionTotal, |
||||
} = confirmTransaction |
||||
|
||||
const { tokenAmount, toAddress } = tokenAmountAndToAddressSelector(state) |
||||
const contractExchangeRate = contractExchangeRateSelector(state) |
||||
|
||||
return { |
||||
toAddress, |
||||
tokenAddress, |
||||
tokenAmount: typeof ownTokenAmount !== 'undefined' ? ownTokenAmount : tokenAmount, |
||||
tokenSymbol, |
||||
currentCurrency, |
||||
conversionRate, |
||||
contractExchangeRate, |
||||
fiatTransactionTotal, |
||||
ethTransactionTotal, |
||||
} |
||||
} |
||||
|
||||
export default connect(mapStateToProps)(ConfirmTokenTransactionBase) |
@ -0,0 +1,2 @@ |
||||
export { default } from './confirm-token-transaction-base.container' |
||||
export { default as ConfirmTokenTransactionBase } from './confirm-token-transaction-base.component' |
@ -1,2 +1,3 @@ |
||||
export const TOKEN_METHOD_TRANSFER = 'transfer' |
||||
export const TOKEN_METHOD_APPROVE = 'approve' |
||||
export const TOKEN_METHOD_TRANSFER_FROM = 'transferfrom' |
||||
|
Loading…
Reference in new issue