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';
|
2021-08-06 03:07:04 +02:00
|
|
|
import { hexWEIToDecETH } from '../../helpers/utils/conversions.util';
|
2021-09-10 19:37:19 +02:00
|
|
|
import { isEqualCaseInsensitive } from '../../helpers/utils/util';
|
2021-02-04 19:15:23 +01: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 = {} },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = ownProps;
|
|
|
|
const { id: paramsTransactionId } = params;
|
2020-03-06 22:34:56 +01:00
|
|
|
const {
|
|
|
|
confirmTransaction,
|
2021-08-06 03:07:04 +02:00
|
|
|
metamask: {
|
|
|
|
currentCurrency,
|
|
|
|
conversionRate,
|
|
|
|
currentNetworkTxList,
|
|
|
|
nativeCurrency,
|
|
|
|
},
|
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,
|
2021-08-06 21:31:30 +02:00
|
|
|
txParams: { to: tokenAddress, data } = {},
|
2020-11-03 00:41:28 +01:00
|
|
|
} = {},
|
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
|
|
|
|
2021-08-06 21:31:30 +02:00
|
|
|
const {
|
|
|
|
ethTransactionTotal,
|
|
|
|
fiatTransactionTotal,
|
|
|
|
hexMaximumTransactionFee,
|
|
|
|
} = transactionFeeSelector(state, transaction);
|
2021-02-04 19:15:23 +01:00
|
|
|
const tokens = getTokens(state);
|
2021-09-10 19:37:19 +02:00
|
|
|
const currentToken = tokens?.find(({ address }) =>
|
|
|
|
isEqualCaseInsensitive(tokenAddress, address),
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
const { decimals, symbol: tokenSymbol } = currentToken || {};
|
2019-06-28 05:53:12 +02:00
|
|
|
|
2021-08-06 21:31:30 +02:00
|
|
|
const ethTransactionTotalMaxAmount = Number(
|
|
|
|
hexWEIToDecETH(hexMaximumTransactionFee),
|
|
|
|
).toFixed(6);
|
|
|
|
|
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-08-06 03:07:04 +02:00
|
|
|
ethTransactionTotalMaxAmount,
|
|
|
|
nativeCurrency,
|
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);
|