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';
|
2022-01-10 17:23:53 +01:00
|
|
|
import { getCollectibles, getTokens } from '../../ducks/metamask/metamask';
|
|
|
|
import { getTransactionData } 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);
|
2022-01-10 17:23:53 +01:00
|
|
|
const collectibles = getCollectibles(state);
|
2019-06-28 05:53:12 +02:00
|
|
|
|
2022-01-10 17:23:53 +01:00
|
|
|
const transactionData = getTransactionData(data);
|
|
|
|
const toAddress = getTokenAddressParam(transactionData);
|
|
|
|
const tokenAmountOrTokenId = getTokenValueParam(transactionData);
|
2021-08-06 21:31:30 +02:00
|
|
|
const ethTransactionTotalMaxAmount = Number(
|
|
|
|
hexWEIToDecETH(hexMaximumTransactionFee),
|
|
|
|
).toFixed(6);
|
|
|
|
|
2022-01-10 17:23:53 +01:00
|
|
|
const currentToken = tokens?.find(({ address }) =>
|
|
|
|
isEqualCaseInsensitive(tokenAddress, address),
|
|
|
|
);
|
|
|
|
const currentCollectible = collectibles?.find(
|
|
|
|
({ address, tokenId }) =>
|
|
|
|
isEqualCaseInsensitive(tokenAddress, address) &&
|
|
|
|
tokenId === tokenAmountOrTokenId,
|
|
|
|
);
|
|
|
|
|
|
|
|
let image,
|
|
|
|
tokenId,
|
|
|
|
collectibleName,
|
|
|
|
tokenAmount,
|
|
|
|
contractExchangeRate,
|
|
|
|
title,
|
|
|
|
subtitle;
|
|
|
|
|
|
|
|
if (currentCollectible) {
|
|
|
|
({ image, tokenId, name: collectibleName } = currentCollectible || {});
|
|
|
|
|
|
|
|
title = collectibleName;
|
|
|
|
subtitle = `#${tokenId}`;
|
|
|
|
} else if (currentToken) {
|
|
|
|
const { decimals, symbol: tokenSymbol } = currentToken || {};
|
|
|
|
tokenAmount =
|
|
|
|
transactionData &&
|
|
|
|
calcTokenAmount(tokenAmountOrTokenId, decimals).toFixed();
|
|
|
|
contractExchangeRate = contractExchangeRateSelector(state);
|
|
|
|
title = `${tokenAmount} ${tokenSymbol}`;
|
|
|
|
}
|
2018-07-14 22:47:07 +02:00
|
|
|
|
|
|
|
return {
|
2022-01-10 17:23:53 +01:00
|
|
|
title,
|
|
|
|
subtitle,
|
|
|
|
image,
|
2018-07-14 22:47:07 +02:00
|
|
|
toAddress,
|
|
|
|
tokenAddress,
|
2019-06-28 05:53:12 +02:00
|
|
|
tokenAmount,
|
2018-07-14 22:47:07 +02:00
|
|
|
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);
|