1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/ui/app/pages/confirm-token-transaction-base/confirm-token-transaction-base.container.js
Erik Marks 76a2a9bb8b
@metamask/eslint config@5.0.0 (#10358)
* @metamask/eslint-config@5.0.0
* Update eslintrc and prettierrc
* yarn lint:fix
2021-02-04 10:15:23 -08:00

71 lines
1.9 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 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 },
} = state;
const {
txData: {
id: transactionId,
txParams: { to: tokenAddress, data } = {},
} = {},
} = confirmTransaction;
const transaction =
currentNetworkTxList.find(
({ id }) => id === (Number(paramsTransactionId) || transactionId),
) || {};
const { ethTransactionTotal, fiatTransactionTotal } = transactionFeeSelector(
state,
transaction,
);
const tokens = getTokens(state);
const currentToken = tokens?.find(({ address }) => tokenAddress === address);
const { decimals, symbol: tokenSymbol } = currentToken || {};
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,
};
};
export default compose(
withRouter,
connect(mapStateToProps),
)(ConfirmTokenTransactionBase);