You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
4 years ago
|
import { connect } from 'react-redux';
|
||
|
import { compose } from 'redux';
|
||
|
import { withRouter } from 'react-router-dom';
|
||
6 years ago
|
import {
|
||
|
contractExchangeRateSelector,
|
||
5 years ago
|
transactionFeeSelector,
|
||
4 years ago
|
} from '../../selectors';
|
||
|
import { getTokens } from '../../ducks/metamask/metamask';
|
||
|
import { getTokenData } from '../../helpers/utils/transactions.util';
|
||
6 years ago
|
import {
|
||
|
calcTokenAmount,
|
||
4 years ago
|
getTokenAddressParam,
|
||
|
getTokenValueParam,
|
||
4 years ago
|
} from '../../helpers/utils/token-util';
|
||
|
import ConfirmTokenTransactionBase from './confirm-token-transaction-base.component';
|
||
6 years ago
|
|
||
5 years ago
|
const mapStateToProps = (state, ownProps) => {
|
||
4 years ago
|
const {
|
||
|
match: { params = {} },
|
||
4 years ago
|
} = ownProps;
|
||
|
const { id: paramsTransactionId } = params;
|
||
5 years ago
|
const {
|
||
|
confirmTransaction,
|
||
|
metamask: { currentCurrency, conversionRate, currentNetworkTxList },
|
||
4 years ago
|
} = state;
|
||
5 years ago
|
|
||
6 years ago
|
const {
|
||
4 years ago
|
txData: {
|
||
|
id: transactionId,
|
||
|
txParams: { to: tokenAddress, data } = {},
|
||
|
} = {},
|
||
4 years ago
|
} = confirmTransaction;
|
||
6 years ago
|
|
||
4 years ago
|
const transaction =
|
||
|
currentNetworkTxList.find(
|
||
|
({ id }) => id === (Number(paramsTransactionId) || transactionId),
|
||
4 years ago
|
) || {};
|
||
6 years ago
|
|
||
4 years ago
|
const { ethTransactionTotal, fiatTransactionTotal } = transactionFeeSelector(
|
||
|
state,
|
||
|
transaction,
|
||
4 years ago
|
);
|
||
|
const tokens = getTokens(state);
|
||
|
const currentToken = tokens?.find(({ address }) => tokenAddress === address);
|
||
|
const { decimals, symbol: tokenSymbol } = currentToken || {};
|
||
6 years ago
|
|
||
4 years ago
|
const tokenData = getTokenData(data);
|
||
|
const tokenValue = getTokenValueParam(tokenData);
|
||
|
const toAddress = getTokenAddressParam(tokenData);
|
||
4 years ago
|
const tokenAmount =
|
||
4 years ago
|
tokenData && calcTokenAmount(tokenValue, decimals).toFixed();
|
||
|
const contractExchangeRate = contractExchangeRateSelector(state);
|
||
6 years ago
|
|
||
|
return {
|
||
|
toAddress,
|
||
|
tokenAddress,
|
||
6 years ago
|
tokenAmount,
|
||
6 years ago
|
tokenSymbol,
|
||
|
currentCurrency,
|
||
|
conversionRate,
|
||
|
contractExchangeRate,
|
||
|
fiatTransactionTotal,
|
||
|
ethTransactionTotal,
|
||
4 years ago
|
};
|
||
|
};
|
||
6 years ago
|
|
||
5 years ago
|
export default compose(
|
||
|
withRouter,
|
||
4 years ago
|
connect(mapStateToProps),
|
||
4 years ago
|
)(ConfirmTokenTransactionBase);
|