2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { compose } from 'redux';
|
|
|
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../selectors';
|
|
|
|
import { getTokens } from '../../ducks/metamask/metamask';
|
|
|
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../helpers/utils/token-util';
|
|
|
|
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 = {} },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = ownProps;
|
|
|
|
const { id: paramsTransactionId } = params;
|
2020-03-06 22:34:56 +01:00
|
|
|
const {
|
|
|
|
confirmTransaction,
|
|
|
|
metamask: { currentCurrency, conversionRate, currentNetworkTxList },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = 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 } = {},
|
|
|
|
} = {},
|
2021-02-04 19:15:23 +01:00
|
|
|
} = confirmTransaction;
|
2018-07-14 22:47:07 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const transaction =
|
|
|
|
currentNetworkTxList.find(
|
|
|
|
({ id }) => id === (Number(paramsTransactionId) || transactionId),
|
2021-02-04 19:15:23 +01:00
|
|
|
) || {};
|
2019-06-28 05:53:12 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const { ethTransactionTotal, fiatTransactionTotal } = transactionFeeSelector(
|
|
|
|
state,
|
|
|
|
transaction,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const tokens = getTokens(state);
|
|
|
|
const currentToken = tokens?.find(({ address }) => tokenAddress === address);
|
|
|
|
const { decimals, symbol: tokenSymbol } = currentToken || {};
|
2019-06-28 05:53:12 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const tokenData = getTokenData(data);
|
|
|
|
const tokenValue = getTokenValueParam(tokenData);
|
|
|
|
const toAddress = getTokenAddressParam(tokenData);
|
2020-11-03 00:41:28 +01:00
|
|
|
const tokenAmount =
|
2021-02-04 19:15:23 +01:00
|
|
|
tokenData && calcTokenAmount(tokenValue, decimals).toFixed();
|
|
|
|
const contractExchangeRate = contractExchangeRateSelector(state);
|
2018-07-14 22:47:07 +02:00
|
|
|
|
|
|
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-07-14 22:47:07 +02:00
|
|
|
|
2019-07-03 22:33:44 +02:00
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2020-07-14 17:20:41 +02:00
|
|
|
connect(mapStateToProps),
|
2021-02-04 19:15:23 +01:00
|
|
|
)(ConfirmTokenTransactionBase);
|