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 {
|
|
|
|
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'
|
2020-11-03 00:41:28 +01:00
|
|
|
import { getTokenData } from '../../helpers/utils/transactions.util'
|
2019-06-28 05:53:12 +02:00
|
|
|
import {
|
|
|
|
calcTokenAmount,
|
2020-08-22 04:29:19 +02:00
|
|
|
getTokenAddressParam,
|
|
|
|
getTokenValueParam,
|
2019-06-28 05:53:12 +02:00
|
|
|
} from '../../helpers/utils/token-util'
|
2020-08-18 21:18:25 +02:00
|
|
|
import ConfirmTokenTransactionBase from './confirm-token-transaction-base.component'
|
2019-06-28 05:53:12 +02:00
|
|
|
|
2019-07-03 22:33:44 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
match: { params = {} },
|
|
|
|
} = ownProps
|
2019-07-03 22:33:44 +02:00
|
|
|
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 {
|
2020-11-03 00:41:28 +01:00
|
|
|
txData: {
|
|
|
|
id: transactionId,
|
|
|
|
txParams: { to: tokenAddress, data } = {},
|
|
|
|
} = {},
|
2018-07-14 22:47:07 +02:00
|
|
|
} = confirmTransaction
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const transaction =
|
|
|
|
currentNetworkTxList.find(
|
|
|
|
({ id }) => id === (Number(paramsTransactionId) || transactionId),
|
|
|
|
) || {}
|
2019-06-28 05:53:12 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const { ethTransactionTotal, fiatTransactionTotal } = transactionFeeSelector(
|
|
|
|
state,
|
|
|
|
transaction,
|
|
|
|
)
|
2020-05-29 02:43:44 +02:00
|
|
|
const tokens = getTokens(state)
|
2020-11-05 18:09:42 +01:00
|
|
|
const currentToken = tokens?.find(({ address }) => tokenAddress === address)
|
2019-06-28 05:53:12 +02:00
|
|
|
const { decimals, symbol: tokenSymbol } = currentToken || {}
|
|
|
|
|
|
|
|
const tokenData = getTokenData(data)
|
2020-08-22 04:29:19 +02:00
|
|
|
const tokenValue = getTokenValueParam(tokenData)
|
|
|
|
const toAddress = getTokenAddressParam(tokenData)
|
2020-11-03 00:41:28 +01:00
|
|
|
const tokenAmount =
|
|
|
|
tokenData && calcTokenAmount(tokenValue, decimals).toFixed()
|
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,
|
2020-07-14 17:20:41 +02:00
|
|
|
connect(mapStateToProps),
|
2019-07-03 22:33:44 +02:00
|
|
|
)(ConfirmTokenTransactionBase)
|