1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 14:15:06 +01:00
metamask-extension/ui/pages/confirm-token-transaction-base/confirm-token-transaction-base.container.js
Dan J Miller 738d2722c5 Fixes updates on the confirm screen. (#11788)
* Fixes updates on the confirm screen.

* Better handling of internal send transactions

* maxFee -> maxFeePerGas property name fix

* Remove redundant setEstimateToUse call in onManualChange

* Fix unit tests

* rebase error fix

* Fixes to speedup loading and transaction breakdown priority fee

* Fix lint and unit tests

* Ensure gas price based transaction that have been customized (e.g. speed up and retry) are properly initialized in useGasFeeInputs

* Clean up

* Link fix
2021-08-06 19:30:10 -02:30

84 lines
2.2 KiB
JavaScript

import { connect } from 'react-redux';
import { compose } from 'redux';
import { withRouter } from 'react-router-dom';
import {
contractExchangeRateSelector,
transactionFeeSelector,
} from '../../selectors';
import { getTokens } from '../../ducks/metamask/metamask';
import { getTokenData } from '../../helpers/utils/transactions.util';
import {
calcTokenAmount,
getTokenAddressParam,
getTokenValueParam,
} from '../../helpers/utils/token-util';
import { hexWEIToDecETH } from '../../helpers/utils/conversions.util';
import ConfirmTokenTransactionBase from './confirm-token-transaction-base.component';
const mapStateToProps = (state, ownProps) => {
const {
match: { params = {} },
} = ownProps;
const { id: paramsTransactionId } = params;
const {
confirmTransaction,
metamask: {
currentCurrency,
conversionRate,
currentNetworkTxList,
nativeCurrency,
},
} = state;
const {
txData: {
id: transactionId,
txParams: { to: tokenAddress, data } = {},
} = {},
} = confirmTransaction;
const transaction =
currentNetworkTxList.find(
({ id }) => id === (Number(paramsTransactionId) || transactionId),
) || {};
const {
ethTransactionTotal,
fiatTransactionTotal,
hexMaximumTransactionFee,
} = transactionFeeSelector(state, transaction);
const tokens = getTokens(state);
const currentToken = tokens?.find(({ address }) => tokenAddress === address);
const { decimals, symbol: tokenSymbol } = currentToken || {};
const ethTransactionTotalMaxAmount = Number(
hexWEIToDecETH(hexMaximumTransactionFee),
).toFixed(6);
const tokenData = getTokenData(data);
const tokenValue = getTokenValueParam(tokenData);
const toAddress = getTokenAddressParam(tokenData);
const tokenAmount =
tokenData && calcTokenAmount(tokenValue, decimals).toFixed();
const contractExchangeRate = contractExchangeRateSelector(state);
return {
toAddress,
tokenAddress,
tokenAmount,
tokenSymbol,
currentCurrency,
conversionRate,
contractExchangeRate,
fiatTransactionTotal,
ethTransactionTotal,
ethTransactionTotalMaxAmount,
nativeCurrency,
};
};
export default compose(
withRouter,
connect(mapStateToProps),
)(ConfirmTokenTransactionBase);