2018-07-14 22:47:07 +02:00
|
|
|
import { connect } from 'react-redux'
|
2020-02-24 23:58:26 +01:00
|
|
|
import { compose } from 'redux'
|
2019-07-03 22:33:44 +02:00
|
|
|
import { withRouter } from 'react-router-dom'
|
2018-07-14 22:47:07 +02:00
|
|
|
import ConfirmTokenTransactionBase from './confirm-token-transaction-base.component'
|
|
|
|
import {
|
|
|
|
contractExchangeRateSelector,
|
2019-07-03 22:33:44 +02:00
|
|
|
transactionFeeSelector,
|
2020-05-02 21:41:17 +02:00
|
|
|
} from '../../selectors'
|
2020-05-29 02:43:44 +02:00
|
|
|
import { getTokens } from '../../ducks/metamask/metamask'
|
2019-06-28 05:53:12 +02:00
|
|
|
import {
|
|
|
|
getTokenData,
|
|
|
|
} from '../../helpers/utils/transactions.util'
|
|
|
|
import {
|
|
|
|
calcTokenAmount,
|
|
|
|
getTokenToAddress,
|
|
|
|
getTokenValue,
|
|
|
|
} from '../../helpers/utils/token-util'
|
|
|
|
|
2018-07-14 22:47:07 +02:00
|
|
|
|
2019-07-03 22:33:44 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
const { match: { params = {} } } = ownProps
|
|
|
|
const { id: paramsTransactionId } = params
|
2020-03-06 22:34:56 +01:00
|
|
|
const {
|
|
|
|
confirmTransaction,
|
|
|
|
metamask: { currentCurrency, conversionRate, currentNetworkTxList },
|
|
|
|
} = state
|
2019-07-03 22:33:44 +02:00
|
|
|
|
2018-07-14 22:47:07 +02:00
|
|
|
const {
|
2019-07-03 22:33:44 +02:00
|
|
|
txData: { id: transactionId, txParams: { to: tokenAddress, data } = {} } = {},
|
2018-07-14 22:47:07 +02:00
|
|
|
} = confirmTransaction
|
|
|
|
|
2020-03-06 22:34:56 +01:00
|
|
|
const transaction = (
|
|
|
|
currentNetworkTxList.find(({ id }) => id === (Number(paramsTransactionId) ||
|
|
|
|
transactionId)) || {}
|
|
|
|
)
|
2019-06-28 05:53:12 +02:00
|
|
|
|
2019-07-03 22:33:44 +02:00
|
|
|
const {
|
|
|
|
ethTransactionTotal,
|
|
|
|
fiatTransactionTotal,
|
|
|
|
} = transactionFeeSelector(state, transaction)
|
2020-05-29 02:43:44 +02:00
|
|
|
const tokens = getTokens(state)
|
2019-06-28 05:53:12 +02:00
|
|
|
const currentToken = tokens && tokens.find(({ address }) => tokenAddress === address)
|
|
|
|
const { decimals, symbol: tokenSymbol } = currentToken || {}
|
|
|
|
|
|
|
|
const tokenData = getTokenData(data)
|
|
|
|
const tokenValue = tokenData && getTokenValue(tokenData.params)
|
|
|
|
const toAddress = tokenData && getTokenToAddress(tokenData.params)
|
2019-08-31 18:26:49 +02:00
|
|
|
const tokenAmount = tokenData && calcTokenAmount(tokenValue, decimals).toNumber()
|
2018-07-14 22:47:07 +02:00
|
|
|
const contractExchangeRate = contractExchangeRateSelector(state)
|
|
|
|
|
|
|
|
return {
|
|
|
|
toAddress,
|
|
|
|
tokenAddress,
|
2019-06-28 05:53:12 +02:00
|
|
|
tokenAmount,
|
2018-07-14 22:47:07 +02:00
|
|
|
tokenSymbol,
|
|
|
|
currentCurrency,
|
|
|
|
conversionRate,
|
|
|
|
contractExchangeRate,
|
|
|
|
fiatTransactionTotal,
|
|
|
|
ethTransactionTotal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:33:44 +02:00
|
|
|
export default compose(
|
|
|
|
withRouter,
|
|
|
|
connect(mapStateToProps)
|
|
|
|
)(ConfirmTokenTransactionBase)
|