1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-18 07:23:21 +01:00
metamask-extension/ui/app/pages/confirm-token-transaction-base/confirm-token-transaction-base.container.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux'
2020-02-24 23:58:26 +01:00
import { compose } from 'redux'
import { withRouter } from 'react-router-dom'
import {
contractExchangeRateSelector,
transactionFeeSelector,
2020-05-02 21:41:17 +02:00
} from '../../selectors'
import { getTokens } from '../../ducks/metamask/metamask'
2020-11-03 00:41:28 +01:00
import { getTokenData } from '../../helpers/utils/transactions.util'
import {
calcTokenAmount,
getTokenAddressParam,
getTokenValueParam,
} from '../../helpers/utils/token-util'
import ConfirmTokenTransactionBase from './confirm-token-transaction-base.component'
const mapStateToProps = (state, ownProps) => {
2020-11-03 00:41:28 +01:00
const {
match: { params = {} },
} = ownProps
const { id: paramsTransactionId } = params
const {
confirmTransaction,
metamask: { currentCurrency, conversionRate, currentNetworkTxList },
} = state
const {
2020-11-03 00:41:28 +01:00
txData: {
id: transactionId,
txParams: { to: tokenAddress, data } = {},
} = {},
} = confirmTransaction
2020-11-03 00:41:28 +01:00
const transaction =
currentNetworkTxList.find(
({ id }) => id === (Number(paramsTransactionId) || transactionId),
) || {}
2020-11-03 00:41:28 +01:00
const { ethTransactionTotal, fiatTransactionTotal } = transactionFeeSelector(
state,
transaction,
)
const tokens = getTokens(state)
2020-11-05 18:09:42 +01:00
const currentToken = tokens?.find(({ address }) => tokenAddress === address)
const { decimals, symbol: tokenSymbol } = currentToken || {}
const tokenData = getTokenData(data)
const tokenValue = getTokenValueParam(tokenData)
const toAddress = getTokenAddressParam(tokenData)
2020-11-03 00:41:28 +01:00
const tokenAmount =
tokenData && calcTokenAmount(tokenValue, decimals).toFixed()
const contractExchangeRate = contractExchangeRateSelector(state)
return {
toAddress,
tokenAddress,
tokenAmount,
tokenSymbol,
currentCurrency,
conversionRate,
contractExchangeRate,
fiatTransactionTotal,
ethTransactionTotal,
}
}
export default compose(
withRouter,
connect(mapStateToProps),
)(ConfirmTokenTransactionBase)