2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { compose } from 'redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
import { clearConfirmTransaction } from '../../ducks/confirm-transaction/confirm-transaction.duck';
|
2019-07-03 22:33:44 +02:00
|
|
|
|
2019-09-27 06:30:36 +02:00
|
|
|
import {
|
|
|
|
updateCustomNonce,
|
|
|
|
cancelTx,
|
|
|
|
cancelTxs,
|
|
|
|
updateAndApproveTx,
|
|
|
|
showModal,
|
|
|
|
getNextNonce,
|
2019-11-01 18:54:00 +01:00
|
|
|
tryReverseResolveAddress,
|
2021-05-03 19:51:09 +02:00
|
|
|
setDefaultHomeActiveTabName,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../store/actions';
|
|
|
|
import { isBalanceSufficient, calcGasTotal } from '../send/send.utils';
|
2021-05-17 23:19:39 +02:00
|
|
|
import { shortenAddress, valuesFor } from '../../helpers/utils/util';
|
2020-05-02 21:41:17 +02:00
|
|
|
import {
|
|
|
|
getAdvancedInlineGasShown,
|
|
|
|
getCustomNonceValue,
|
|
|
|
getIsMainnet,
|
|
|
|
getKnownMethodData,
|
|
|
|
getMetaMaskAccounts,
|
|
|
|
getUseNonceField,
|
|
|
|
transactionFeeSelector,
|
2021-04-28 20:02:01 +02:00
|
|
|
getNoGasPriceFetched,
|
|
|
|
getIsEthGasPriceFetched,
|
2021-06-24 01:28:49 +02:00
|
|
|
getShouldShowFiat,
|
2021-08-03 00:52:18 +02:00
|
|
|
checkNetworkAndAccountSupports1559,
|
2021-08-06 03:07:04 +02:00
|
|
|
getPreferences,
|
2021-10-21 21:17:03 +02:00
|
|
|
doesAddressRequireLedgerHidConnection,
|
2021-09-09 22:56:27 +02:00
|
|
|
getUseTokenDetection,
|
|
|
|
getTokenList,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../selectors';
|
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
2021-08-17 22:08:13 +02:00
|
|
|
import {
|
2021-10-21 21:17:03 +02:00
|
|
|
isAddressLedger,
|
2021-08-06 01:59:58 +02:00
|
|
|
updateTransactionGasFees,
|
|
|
|
getIsGasEstimatesLoading,
|
2021-09-15 23:54:51 +02:00
|
|
|
getNativeCurrency,
|
2021-08-06 01:59:58 +02:00
|
|
|
} from '../../ducks/metamask/metamask';
|
2021-10-21 21:17:03 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
transactionMatchesNetwork,
|
|
|
|
txParamsAreDappSuggested,
|
|
|
|
} from '../../../shared/modules/transaction.utils';
|
|
|
|
import { toChecksumHexAddress } from '../../../shared/modules/hexstring-utils';
|
|
|
|
|
2021-08-06 01:59:58 +02:00
|
|
|
import { getGasLoadingAnimationIsShowing } from '../../ducks/app/app';
|
2021-10-06 20:29:57 +02:00
|
|
|
import { isLegacyTransaction } from '../../helpers/utils/transactions.util';
|
2021-02-04 19:15:23 +01:00
|
|
|
import ConfirmTransactionBase from './confirm-transaction-base.component';
|
2018-07-20 23:18:50 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let customNonceValue = '';
|
2020-11-03 00:41:28 +01:00
|
|
|
const customNonceMerge = (txData) =>
|
|
|
|
customNonceValue
|
|
|
|
? {
|
|
|
|
...txData,
|
|
|
|
customNonceValue,
|
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
: txData;
|
2019-09-27 06:30:36 +02:00
|
|
|
|
2019-06-18 14:17:14 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
toAddress: propsToAddress,
|
|
|
|
customTxParamsData,
|
|
|
|
match: { params = {} },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = ownProps;
|
|
|
|
const { id: paramsTransactionId } = params;
|
|
|
|
const isMainnet = getIsMainnet(state);
|
2021-08-06 01:59:58 +02:00
|
|
|
|
|
|
|
const isGasEstimatesLoading = getIsGasEstimatesLoading(state);
|
|
|
|
const gasLoadingAnimationIsShowing = getGasLoadingAnimationIsShowing(state);
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { confirmTransaction, metamask } = state;
|
2019-07-03 22:33:44 +02:00
|
|
|
const {
|
2019-11-01 18:54:00 +01:00
|
|
|
ensResolutionsByAddress,
|
2019-07-03 22:33:44 +02:00
|
|
|
conversionRate,
|
|
|
|
identities,
|
2019-08-08 20:45:30 +02:00
|
|
|
addressBook,
|
2019-07-03 22:33:44 +02:00
|
|
|
network,
|
|
|
|
unapprovedTxs,
|
2019-09-27 06:30:36 +02:00
|
|
|
nextNonce,
|
2021-03-01 16:15:42 +01:00
|
|
|
provider: { chainId },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = metamask;
|
|
|
|
const { tokenData, txData, tokenProps, nonce } = confirmTransaction;
|
2021-06-29 18:02:00 +02:00
|
|
|
const { txParams = {}, id: transactionId, type } = txData;
|
2020-11-03 00:41:28 +01:00
|
|
|
const transaction =
|
|
|
|
Object.values(unapprovedTxs).find(
|
|
|
|
({ id }) => id === (transactionId || Number(paramsTransactionId)),
|
2021-02-04 19:15:23 +01:00
|
|
|
) || {};
|
2019-02-06 01:24:28 +01:00
|
|
|
const {
|
|
|
|
from: fromAddress,
|
|
|
|
to: txParamsToAddress,
|
|
|
|
gasPrice,
|
|
|
|
gas: gasLimit,
|
|
|
|
value: amount,
|
2019-06-18 14:17:14 +02:00
|
|
|
data,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = (transaction && transaction.txParams) || txParams;
|
|
|
|
const accounts = getMetaMaskAccounts(state);
|
2018-09-13 10:47:05 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { balance } = accounts[fromAddress];
|
|
|
|
const { name: fromName } = identities[fromAddress];
|
|
|
|
const toAddress = propsToAddress || txParamsToAddress;
|
2020-08-13 22:00:09 +02:00
|
|
|
|
2021-09-09 22:56:27 +02:00
|
|
|
const tokenList = getTokenList(state);
|
|
|
|
const useTokenDetection = getUseTokenDetection(state);
|
|
|
|
const casedTokenList = useTokenDetection
|
|
|
|
? tokenList
|
|
|
|
: Object.keys(tokenList).reduce((acc, base) => {
|
|
|
|
return {
|
|
|
|
...acc,
|
|
|
|
[base.toLowerCase()]: tokenList[base],
|
|
|
|
};
|
|
|
|
}, {});
|
2020-11-03 00:41:28 +01:00
|
|
|
const toName =
|
|
|
|
identities[toAddress]?.name ||
|
2021-09-09 22:56:27 +02:00
|
|
|
casedTokenList[toAddress]?.name ||
|
2021-05-17 23:19:39 +02:00
|
|
|
shortenAddress(toChecksumHexAddress(toAddress));
|
2018-07-20 23:18:50 +02:00
|
|
|
|
2021-05-17 23:19:39 +02:00
|
|
|
const checksummedAddress = toChecksumHexAddress(toAddress);
|
2021-02-04 19:15:23 +01:00
|
|
|
const addressBookObject = addressBook[checksummedAddress];
|
|
|
|
const toEns = ensResolutionsByAddress[checksummedAddress] || '';
|
|
|
|
const toNickname = addressBookObject ? addressBookObject.name : '';
|
|
|
|
const transactionStatus = transaction ? transaction.status : '';
|
2021-10-06 20:29:57 +02:00
|
|
|
const supportsEIP1559 =
|
|
|
|
checkNetworkAndAccountSupports1559(state) && !isLegacyTransaction(txParams);
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2019-07-03 22:33:44 +02:00
|
|
|
const {
|
|
|
|
hexTransactionAmount,
|
2021-07-31 02:45:18 +02:00
|
|
|
hexMinimumTransactionFee,
|
|
|
|
hexMaximumTransactionFee,
|
2019-07-03 22:33:44 +02:00
|
|
|
hexTransactionTotal,
|
2021-08-06 21:31:30 +02:00
|
|
|
gasEstimationObject,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = transactionFeeSelector(state, transaction);
|
2019-07-03 22:33:44 +02:00
|
|
|
|
2019-06-25 21:42:35 +02:00
|
|
|
if (transaction && transaction.simulationFails) {
|
2021-02-04 19:15:23 +01:00
|
|
|
txData.simulationFails = transaction.simulationFails;
|
2019-06-25 21:42:35 +02:00
|
|
|
}
|
|
|
|
|
2020-01-10 15:34:02 +01:00
|
|
|
const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs)
|
2021-03-01 16:15:42 +01:00
|
|
|
.filter((key) =>
|
|
|
|
transactionMatchesNetwork(unapprovedTxs[key], chainId, network),
|
|
|
|
)
|
2021-02-04 19:15:23 +01:00
|
|
|
.reduce((acc, key) => ({ ...acc, [key]: unapprovedTxs[key] }), {});
|
|
|
|
const unapprovedTxCount = valuesFor(currentNetworkUnapprovedTxs).length;
|
2018-09-20 02:48:28 +02:00
|
|
|
|
2019-02-06 01:24:28 +01:00
|
|
|
const insufficientBalance = !isBalanceSufficient({
|
|
|
|
amount,
|
|
|
|
gasTotal: calcGasTotal(gasLimit, gasPrice),
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-02-06 01:24:28 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const methodData = getKnownMethodData(state, data) || {};
|
2019-06-18 14:17:14 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let fullTxData = { ...txData, ...transaction };
|
2019-11-05 16:13:48 +01:00
|
|
|
if (customTxParamsData) {
|
|
|
|
fullTxData = {
|
|
|
|
...fullTxData,
|
|
|
|
txParams: {
|
|
|
|
...fullTxData.txParams,
|
|
|
|
data: customTxParamsData,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-05 16:13:48 +01:00
|
|
|
}
|
2021-04-17 00:00:18 +02:00
|
|
|
customNonceValue = getCustomNonceValue(state);
|
2021-04-28 20:02:01 +02:00
|
|
|
const isEthGasPrice = getIsEthGasPriceFetched(state);
|
2021-10-06 20:29:57 +02:00
|
|
|
const noGasPrice = !supportsEIP1559 && getNoGasPriceFetched(state);
|
2021-08-06 03:07:04 +02:00
|
|
|
const { useNativeCurrencyAsPrimaryCurrency } = getPreferences(state);
|
2021-08-17 22:08:13 +02:00
|
|
|
const gasFeeIsCustom =
|
|
|
|
fullTxData.userFeeLevel === 'custom' ||
|
|
|
|
txParamsAreDappSuggested(fullTxData);
|
2021-10-21 21:17:03 +02:00
|
|
|
const fromAddressIsLedger = isAddressLedger(state, fromAddress);
|
2021-09-15 23:54:51 +02:00
|
|
|
const nativeCurrency = getNativeCurrency(state);
|
2021-08-06 21:31:30 +02:00
|
|
|
|
2021-10-21 21:17:03 +02:00
|
|
|
const hardwareWalletRequiresConnection = doesAddressRequireLedgerHidConnection(
|
|
|
|
state,
|
|
|
|
fromAddress,
|
|
|
|
);
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
return {
|
|
|
|
balance,
|
|
|
|
fromAddress,
|
|
|
|
fromName,
|
|
|
|
toAddress,
|
2019-11-01 18:54:00 +01:00
|
|
|
toEns,
|
2018-06-23 08:52:45 +02:00
|
|
|
toName,
|
2019-08-08 20:45:30 +02:00
|
|
|
toNickname,
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionAmount,
|
2021-07-31 02:45:18 +02:00
|
|
|
hexMinimumTransactionFee,
|
|
|
|
hexMaximumTransactionFee,
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionTotal,
|
2019-11-05 16:13:48 +01:00
|
|
|
txData: fullTxData,
|
2018-06-23 08:52:45 +02:00
|
|
|
tokenData,
|
2018-06-28 20:23:31 +02:00
|
|
|
methodData,
|
2018-06-23 08:52:45 +02:00
|
|
|
tokenProps,
|
|
|
|
conversionRate,
|
|
|
|
transactionStatus,
|
|
|
|
nonce,
|
2018-09-20 02:48:28 +02:00
|
|
|
unapprovedTxs,
|
|
|
|
unapprovedTxCount,
|
2018-11-13 18:19:12 +01:00
|
|
|
currentNetworkUnapprovedTxs,
|
2018-09-13 10:47:05 +02:00
|
|
|
customGas: {
|
2019-07-03 22:33:44 +02:00
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
2018-09-13 10:47:05 +02:00
|
|
|
},
|
2019-02-06 01:24:28 +01:00
|
|
|
advancedInlineGasShown: getAdvancedInlineGasShown(state),
|
2019-09-27 06:30:36 +02:00
|
|
|
useNonceField: getUseNonceField(state),
|
2021-04-17 00:00:18 +02:00
|
|
|
customNonceValue,
|
2019-02-06 01:24:28 +01:00
|
|
|
insufficientBalance,
|
2021-06-24 01:28:49 +02:00
|
|
|
hideSubtitle: !getShouldShowFiat(state),
|
|
|
|
hideFiatConversion: !getShouldShowFiat(state),
|
2021-03-10 21:16:44 +01:00
|
|
|
type,
|
2019-09-27 06:30:36 +02:00
|
|
|
nextNonce,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2020-08-19 16:03:15 +02:00
|
|
|
isMainnet,
|
2021-04-28 20:02:01 +02:00
|
|
|
isEthGasPrice,
|
|
|
|
noGasPrice,
|
2021-10-06 20:29:57 +02:00
|
|
|
supportsEIP1559,
|
2021-08-06 01:59:58 +02:00
|
|
|
gasIsLoading: isGasEstimatesLoading || gasLoadingAnimationIsShowing,
|
2021-08-06 03:07:04 +02:00
|
|
|
useNativeCurrencyAsPrimaryCurrency,
|
2021-08-06 21:31:30 +02:00
|
|
|
maxFeePerGas: gasEstimationObject.maxFeePerGas,
|
|
|
|
maxPriorityFeePerGas: gasEstimationObject.maxPriorityFeePerGas,
|
2021-08-07 00:18:53 +02:00
|
|
|
baseFeePerGas: gasEstimationObject.baseFeePerGas,
|
2021-08-17 00:45:55 +02:00
|
|
|
gasFeeIsCustom,
|
2021-10-21 21:17:03 +02:00
|
|
|
showLedgerSteps: fromAddressIsLedger,
|
2021-09-15 23:54:51 +02:00
|
|
|
nativeCurrency,
|
2021-10-21 21:17:03 +02:00
|
|
|
hardwareWalletRequiresConnection,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
export const mapDispatchToProps = (dispatch) => {
|
2018-06-23 08:52:45 +02:00
|
|
|
return {
|
2019-11-01 18:54:00 +01:00
|
|
|
tryReverseResolveAddress: (address) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return dispatch(tryReverseResolveAddress(address));
|
2019-11-01 18:54:00 +01:00
|
|
|
},
|
2020-02-15 21:34:12 +01:00
|
|
|
updateCustomNonce: (value) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
customNonceValue = value;
|
|
|
|
dispatch(updateCustomNonce(value));
|
2019-09-27 06:30:36 +02:00
|
|
|
},
|
2018-06-23 08:52:45 +02:00
|
|
|
clearConfirmTransaction: () => dispatch(clearConfirmTransaction()),
|
2018-09-17 19:34:29 +02:00
|
|
|
showTransactionConfirmedModal: ({ onSubmit }) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return dispatch(showModal({ name: 'TRANSACTION_CONFIRMED', onSubmit }));
|
2018-06-23 08:52:45 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
showRejectTransactionsConfirmationModal: ({
|
|
|
|
onSubmit,
|
|
|
|
unapprovedTxCount,
|
|
|
|
}) => {
|
|
|
|
return dispatch(
|
|
|
|
showModal({ name: 'REJECT_TRANSACTIONS', onSubmit, unapprovedTxCount }),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-24 07:07:19 +02:00
|
|
|
},
|
2018-06-23 08:52:45 +02:00
|
|
|
cancelTransaction: ({ id }) => dispatch(cancelTx({ id })),
|
2018-09-20 02:48:28 +02:00
|
|
|
cancelAllTransactions: (txList) => dispatch(cancelTxs(txList)),
|
2020-11-03 00:41:28 +01:00
|
|
|
sendTransaction: (txData) =>
|
|
|
|
dispatch(updateAndApproveTx(customNonceMerge(txData))),
|
2019-09-27 06:30:36 +02:00
|
|
|
getNextNonce: () => dispatch(getNextNonce()),
|
2021-05-03 19:51:09 +02:00
|
|
|
setDefaultHomeActiveTabName: (tabName) =>
|
|
|
|
dispatch(setDefaultHomeActiveTabName(tabName)),
|
2021-07-08 22:23:00 +02:00
|
|
|
updateTransactionGasFees: (gasFees) => {
|
|
|
|
dispatch(updateTransactionGasFees({ ...gasFees, expectHexWei: true }));
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2018-07-06 20:58:41 +02:00
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
2021-08-02 16:07:15 +02:00
|
|
|
const { txData, unapprovedTxs } = stateProps;
|
2021-04-28 20:02:01 +02:00
|
|
|
|
2018-07-06 20:58:41 +02:00
|
|
|
const {
|
2018-09-20 02:48:28 +02:00
|
|
|
cancelAllTransactions: dispatchCancelAllTransactions,
|
2021-07-08 22:23:00 +02:00
|
|
|
updateTransactionGasFees: dispatchUpdateTransactionGasFees,
|
2018-07-06 20:58:41 +02:00
|
|
|
...otherDispatchProps
|
2021-02-04 19:15:23 +01:00
|
|
|
} = dispatchProps;
|
2018-07-06 20:58:41 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
...stateProps,
|
|
|
|
...otherDispatchProps,
|
|
|
|
...ownProps,
|
2020-11-03 00:41:28 +01:00
|
|
|
cancelAllTransactions: () =>
|
|
|
|
dispatchCancelAllTransactions(valuesFor(unapprovedTxs)),
|
2019-07-03 22:33:44 +02:00
|
|
|
updateGasAndCalculate: ({ gasLimit, gasPrice }) => {
|
2021-07-08 22:23:00 +02:00
|
|
|
dispatchUpdateTransactionGasFees({
|
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
transaction: txData,
|
|
|
|
});
|
2019-07-03 22:33:44 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-07-06 20:58:41 +02:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2020-07-14 17:20:41 +02:00
|
|
|
connect(mapStateToProps, mapDispatchToProps, mergeProps),
|
2021-02-04 19:15:23 +01:00
|
|
|
)(ConfirmTransactionBase);
|