diff --git a/ui/hooks/useMMICustodySendTransaction.ts b/ui/hooks/useMMICustodySendTransaction.ts index 0c05d9e16f96..49634fbf0174 100644 --- a/ui/hooks/useMMICustodySendTransaction.ts +++ b/ui/hooks/useMMICustodySendTransaction.ts @@ -34,9 +34,9 @@ export function useMMICustodySendTransaction() { const accountType = useSelector(getAccountType); const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage); - const { currentConfirmation } = useConfirmContext() as unknown as { - currentConfirmation: TransactionMeta | undefined; - }; + const { currentConfirmation } = useConfirmContext< + TransactionMeta | undefined + >(); const { from } = getConfirmationSender(currentConfirmation); const fromChecksumHexAddress = toChecksumHexAddress(from || ''); diff --git a/ui/pages/confirmations/components/confirm/info/approve/approve-static-simulation/approve-static-simulation.tsx b/ui/pages/confirmations/components/confirm/info/approve/approve-static-simulation/approve-static-simulation.tsx index f1117e2a22b2..ad8a3565f619 100644 --- a/ui/pages/confirmations/components/confirm/info/approve/approve-static-simulation/approve-static-simulation.tsx +++ b/ui/pages/confirmations/components/confirm/info/approve/approve-static-simulation/approve-static-simulation.tsx @@ -25,9 +25,8 @@ import { useIsNFT } from '../hooks/use-is-nft'; export const ApproveStaticSimulation = () => { const t = useI18nContext(); - const { currentConfirmation: transactionMeta } = useConfirmContext() as { - currentConfirmation: TransactionMeta; - }; + const { currentConfirmation: transactionMeta } = + useConfirmContext(); const { decimals: initialDecimals } = useAssetDetails( transactionMeta?.txParams?.to, diff --git a/ui/pages/confirmations/components/confirm/info/approve/approve.tsx b/ui/pages/confirmations/components/confirm/info/approve/approve.tsx index fed03a75e17e..fa1766a8aa72 100644 --- a/ui/pages/confirmations/components/confirm/info/approve/approve.tsx +++ b/ui/pages/confirmations/components/confirm/info/approve/approve.tsx @@ -18,9 +18,8 @@ import { RevokeStaticSimulation } from './revoke-static-simulation/revoke-static import { SpendingCap } from './spending-cap/spending-cap'; const ApproveInfo = () => { - const { currentConfirmation: transactionMeta } = useConfirmContext() as { - currentConfirmation: TransactionMeta; - }; + const { currentConfirmation: transactionMeta } = + useConfirmContext(); const { isNFT } = useIsNFT(transactionMeta); diff --git a/ui/pages/confirmations/components/confirm/info/approve/edit-spending-cap-modal/edit-spending-cap-modal.tsx b/ui/pages/confirmations/components/confirm/info/approve/edit-spending-cap-modal/edit-spending-cap-modal.tsx index f908333e4f25..961e63ae8f92 100644 --- a/ui/pages/confirmations/components/confirm/info/approve/edit-spending-cap-modal/edit-spending-cap-modal.tsx +++ b/ui/pages/confirmations/components/confirm/info/approve/edit-spending-cap-modal/edit-spending-cap-modal.tsx @@ -47,9 +47,8 @@ export const EditSpendingCapModal = ({ const dispatch = useDispatch(); - const { currentConfirmation: transactionMeta } = useConfirmContext() as { - currentConfirmation: TransactionMeta; - }; + const { currentConfirmation: transactionMeta } = + useConfirmContext(); const { userBalance, tokenSymbol, decimals } = useAssetDetails( transactionMeta.txParams.to, diff --git a/ui/pages/confirmations/components/confirm/info/approve/revoke-static-simulation/revoke-static-simulation.tsx b/ui/pages/confirmations/components/confirm/info/approve/revoke-static-simulation/revoke-static-simulation.tsx index 77cee271d667..e121e01b6320 100644 --- a/ui/pages/confirmations/components/confirm/info/approve/revoke-static-simulation/revoke-static-simulation.tsx +++ b/ui/pages/confirmations/components/confirm/info/approve/revoke-static-simulation/revoke-static-simulation.tsx @@ -12,9 +12,8 @@ import StaticSimulation from '../../shared/static-simulation/static-simulation'; export const RevokeStaticSimulation = () => { const t = useI18nContext(); - const { currentConfirmation: transactionMeta } = useConfirmContext() as { - currentConfirmation: TransactionMeta; - }; + const { currentConfirmation: transactionMeta } = + useConfirmContext(); const { chainId } = transactionMeta; diff --git a/ui/pages/confirmations/components/confirm/info/approve/spending-cap/spending-cap.tsx b/ui/pages/confirmations/components/confirm/info/approve/spending-cap/spending-cap.tsx index 2ebd9d8e7e4e..638ff638844c 100644 --- a/ui/pages/confirmations/components/confirm/info/approve/spending-cap/spending-cap.tsx +++ b/ui/pages/confirmations/components/confirm/info/approve/spending-cap/spending-cap.tsx @@ -28,9 +28,8 @@ const SpendingCapGroup = ({ }) => { const t = useI18nContext(); - const { currentConfirmation: transactionMeta } = useConfirmContext() as { - currentConfirmation: TransactionMeta; - }; + const { currentConfirmation: transactionMeta } = + useConfirmContext(); const { spendingCap, formattedSpendingCap, value } = useApproveTokenSimulation(transactionMeta, decimals); @@ -81,9 +80,8 @@ export const SpendingCap = ({ }) => { const t = useI18nContext(); - const { currentConfirmation: transactionMeta } = useConfirmContext() as { - currentConfirmation: TransactionMeta; - }; + const { currentConfirmation: transactionMeta } = + useConfirmContext(); const { userBalance, tokenSymbol, decimals } = useAssetDetails( transactionMeta.txParams.to, diff --git a/ui/pages/confirmations/components/confirm/info/shared/advanced-details/advanced-details.tsx b/ui/pages/confirmations/components/confirm/info/shared/advanced-details/advanced-details.tsx index ebb0f69d75c1..d0a6d72d11e9 100644 --- a/ui/pages/confirmations/components/confirm/info/shared/advanced-details/advanced-details.tsx +++ b/ui/pages/confirmations/components/confirm/info/shared/advanced-details/advanced-details.tsx @@ -1,5 +1,7 @@ import React, { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; +import { TransactionMeta } from '@metamask/transaction-controller'; + import { ConfirmInfoRow, ConfirmInfoRowText, @@ -17,15 +19,23 @@ import { updateCustomNonce, } from '../../../../../../../store/actions'; import { selectConfirmationAdvancedDetailsOpen } from '../../../../../selectors/preferences'; +import { useConfirmContext } from '../../../../../context/confirm'; +import { isSignatureTransactionType } from '../../../../../utils'; import { TransactionData } from '../transaction-data/transaction-data'; const NonceDetails = () => { + const { currentConfirmation } = useConfirmContext(); const t = useI18nContext(); const dispatch = useDispatch(); useEffect(() => { - dispatch(getNextNonce()); - }, [dispatch]); + if ( + currentConfirmation && + !isSignatureTransactionType(currentConfirmation) + ) { + dispatch(getNextNonce(currentConfirmation.txParams.from)); + } + }, [currentConfirmation, dispatch]); const enableCustomNonce = useSelector(getUseNonceField); const nextNonce = useSelector(getNextSuggestedNonce); diff --git a/ui/pages/confirmations/confirm-approve/confirm-approve.js b/ui/pages/confirmations/confirm-approve/confirm-approve.js index a5dcaeb6202d..1b604ec43e6b 100644 --- a/ui/pages/confirmations/confirm-approve/confirm-approve.js +++ b/ui/pages/confirmations/confirm-approve/confirm-approve.js @@ -66,7 +66,7 @@ export default function ConfirmApprove({ isSetApproveForAll, }) { const dispatch = useDispatch(); - const { txParams: { data: transactionData } = {} } = transaction; + const { txParams: { data: transactionData, from } = {} } = transaction; const currentCurrency = useSelector(getCurrentCurrency); const nativeCurrency = useSelector(getNativeCurrency); @@ -266,7 +266,7 @@ export default function ConfirmApprove({ updateCustomNonce={(value) => { dispatch(updateCustomNonce(value)); }} - getNextNonce={() => dispatch(getNextNonce())} + getNextNonce={() => dispatch(getNextNonce(from))} showCustomizeNonceModal={({ /* eslint-disable no-shadow */ useNonceField, diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js index c07b8a263f8a..25d99e8a9f16 100644 --- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js @@ -217,6 +217,7 @@ export default class ConfirmTransactionBase extends Component { mostRecentOverviewPage, txData, getNextNonce, + fromAddress, } = this.props; const { @@ -236,7 +237,7 @@ export default class ConfirmTransactionBase extends Component { transactionStatus === TransactionStatus.confirmed; if (txData.id !== prevTxData.id) { - getNextNonce(); + getNextNonce(fromAddress); } if ( @@ -413,6 +414,7 @@ export default class ConfirmTransactionBase extends Component { tokenSymbol, isUsingPaymaster, isSigningOrSubmitting, + fromAddress, } = this.props; const { t } = this.context; @@ -447,7 +449,7 @@ export default class ConfirmTransactionBase extends Component { updateCustomNonce(inputValue); - getNextNonce(); + getNextNonce(fromAddress); }; const renderTotalMaxAmount = ({ @@ -1012,6 +1014,7 @@ export default class ConfirmTransactionBase extends Component { this._isMounted = true; const { toAddress, + fromAddress, txData: { origin, chainId: txChainId } = {}, getNextNonce, tryReverseResolveAddress, @@ -1041,7 +1044,7 @@ export default class ConfirmTransactionBase extends Component { }, }); - getNextNonce(); + getNextNonce(fromAddress); if (toAddress) { tryReverseResolveAddress(toAddress); } diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.container.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.container.js index e06090f48e75..795dfae0c63a 100644 --- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.container.js +++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.container.js @@ -429,7 +429,7 @@ export const mapDispatchToProps = (dispatch) => { fetchSmartTransactionsLiveness: () => { dispatch(fetchSmartTransactionsLiveness()); }, - getNextNonce: () => dispatch(getNextNonce()), + getNextNonce: (address) => dispatch(getNextNonce(address)), setNextNonce: (val) => dispatch(setNextNonce(val)), setDefaultHomeActiveTabName: (tabName) => dispatch(setDefaultHomeActiveTabName(tabName)), diff --git a/ui/pages/confirmations/token-allowance/token-allowance.js b/ui/pages/confirmations/token-allowance/token-allowance.js index 8ccd19ecb566..61bf5e0974df 100644 --- a/ui/pages/confirmations/token-allowance/token-allowance.js +++ b/ui/pages/confirmations/token-allowance/token-allowance.js @@ -347,12 +347,12 @@ export default function TokenAllowance({ }; const handleNextNonce = useCallback(() => { - dispatch(getNextNonce()); - }, [getNextNonce, dispatch]); + dispatch(getNextNonce(txData.txParams.from)); + }, [dispatch, txData.txParams.from]); useEffect(() => { - dispatch(getNextNonce()); - }, [getNextNonce, dispatch]); + dispatch(getNextNonce(txData.txParams.from)); + }, [dispatch, txData.txParams.from]); const handleUpdateCustomNonce = (value) => { dispatch(updateCustomNonce(value)); diff --git a/ui/store/actions.ts b/ui/store/actions.ts index 886739d2d54f..3ffb09929816 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -4374,16 +4374,13 @@ export function setNextNonce(nextNonce: string): PayloadAction { * accidental usage of a stale nonce as the call to getNextNonce only works for * the currently selected address. * + * @param address - address for which nonce lock shouuld be obtained. * @returns */ -export function getNextNonce(): ThunkAction< - Promise, - MetaMaskReduxState, - unknown, - AnyAction -> { +export function getNextNonce( + address, +): ThunkAction, MetaMaskReduxState, unknown, AnyAction> { return async (dispatch, getState) => { - const { address } = getSelectedInternalAccount(getState()); const networkClientId = getSelectedNetworkClientId(getState()); let nextNonce; try {