From 22fc60a3419ff248aac57480360ee7dfb6124b20 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Mon, 19 Dec 2022 13:38:28 -0330 Subject: [PATCH] Show user the general contract interaction screen for token approvals, when the asset standard is undefined (#16765) Co-authored-by: Jyoti Puri --- ui/pages/confirm-approve/confirm-approve.js | 4 ++++ .../confirm-transaction-base.component.js | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ui/pages/confirm-approve/confirm-approve.js b/ui/pages/confirm-approve/confirm-approve.js index 1dd08cd75..4fa2fe8fe 100644 --- a/ui/pages/confirm-approve/confirm-approve.js +++ b/ui/pages/confirm-approve/confirm-approve.js @@ -16,6 +16,7 @@ import { getNativeCurrency, isAddressLedger, } from '../../ducks/metamask/metamask'; +import ConfirmContractInteraction from '../confirm-contract-interaction'; import { getCurrentCurrency, getSubjectMetadata, @@ -164,6 +165,9 @@ export default function ConfirmApprove({ if (tokenSymbol === undefined && assetName === undefined) { return ; } + if (assetStandard === undefined) { + return ; + } if (improvedTokenAllowanceEnabled && assetStandard === ERC20) { return ( diff --git a/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js b/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js index c5dddfdaa..ab9bef765 100644 --- a/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/pages/confirm-transaction-base/confirm-transaction-base.component.js @@ -1162,8 +1162,21 @@ export default class ConfirmTransactionBase extends Component { requestsWaitingText, } = this.getNavigateTxData(); + // This `isTokenApproval` case is added to handle possible rendering of this component from + // confirm-approve.js when `assetStandard` is `undefined`. That will happen if the request to + // get the asset standard fails. In that scenario, confirm-approve.js returns the `` + // component, which in turn returns this `` component. We meed to prevent + // the user from editing the transaction in those cases. + + const isTokenApproval = + txData.type === TRANSACTION_TYPES.TOKEN_METHOD_SET_APPROVAL_FOR_ALL || + txData.type === TRANSACTION_TYPES.TOKEN_METHOD_APPROVE; + + const isContractInteraction = + txData.type === TRANSACTION_TYPES.CONTRACT_INTERACTION; + const isContractInteractionFromDapp = - txData.type === TRANSACTION_TYPES.CONTRACT_INTERACTION && + (isTokenApproval || isContractInteraction) && txData.origin !== 'metamask'; let functionType; if (isContractInteractionFromDapp) {