From 22737b855226a4afef9708c7f7059acc6fa927ec Mon Sep 17 00:00:00 2001 From: Andrew Taran Date: Tue, 3 Nov 2026 14:56:31 +0100 Subject: [PATCH 1/2] fix(tron): allow confirmation after simulation failures --- packages/tron-wallet-snap/CHANGELOG.md | 4 ++ .../isTransactionDeadlinePassedError.ts | 5 +- .../ConfirmSignTransaction.test.tsx | 62 +++++++++++++++--- .../ConfirmSignTransaction.tsx | 10 +-- .../ConfirmTransactionRequest.test.tsx | 65 ++++++++++++++----- .../ConfirmTransactionRequest.tsx | 8 ++- 6 files changed, 117 insertions(+), 37 deletions(-) diff --git a/packages/tron-wallet-snap/CHANGELOG.md b/packages/tron-wallet-snap/CHANGELOG.md index 6b8d5ddda..b6ef96301 100644 --- a/packages/tron-wallet-snap/CHANGELOG.md +++ b/packages/tron-wallet-snap/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Allow transaction confirmation after remote simulation failures while retaining security warnings and checks for locally invalid transactions. ([#522](https://github.com/MetaMask/internal-snaps/pull/552)) + ## [4.3.0] ### Changed diff --git a/packages/tron-wallet-snap/src/services/transaction-scan/isTransactionDeadlinePassedError.ts b/packages/tron-wallet-snap/src/services/transaction-scan/isTransactionDeadlinePassedError.ts index 7770cd1eb..6c621380a 100644 --- a/packages/tron-wallet-snap/src/services/transaction-scan/isTransactionDeadlinePassedError.ts +++ b/packages/tron-wallet-snap/src/services/transaction-scan/isTransactionDeadlinePassedError.ts @@ -24,9 +24,8 @@ export const TRANSACTION_TAPOS_EXPIRED = 'TransactionTaposExpired'; * * Used only to select the friendly banner copy in the confirmation dialog's * `TransactionAlert` (via `getErrorMessage`). It does NOT control the submit - * button: the button is disabled for every failed simulation, including the - * expired/TAPOS-expired case, so the user is blocked from confirming a - * transaction that won't broadcast. + * button: locally detected TAPOS expiry blocks confirmation, while remote + * simulation failures, including contract deadline failures, do not. * * @param error - The transaction scan error, if any. * @returns Whether the error is an expired/deadline failure. diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.test.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.test.tsx index 376fb6c5b..668153bec 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.test.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.test.tsx @@ -189,7 +189,7 @@ describe('ConfirmSignTransaction', () => { ); }); - it('disables the confirm button when the scan fails on a deadline (expired)', () => { + it('allows confirmation when the remote simulation reports a contract deadline failure', () => { expect( isConfirmDisabled( buildContext({ @@ -200,21 +200,63 @@ describe('ConfirmSignTransaction', () => { }), }), ), - ).toBe(true); + ).toBe(false); }); - it('disables the confirm button for other failed simulations', () => { + it.each([FetchStatus.Fetched, FetchStatus.Fetching, FetchStatus.Error])( + 'allows confirmation after a remote simulation failure when the scan is %s', + (scanFetchStatus) => { + expect( + isConfirmDisabled( + buildContext({ + scanFetchStatus, + scan: buildScanResult({ + status: 'ERROR', + simulationStatus: SimulationStatus.Failed, + error: otherError, + }), + }), + ), + ).toBe(false); + }, + ); + + it.each([TRANSACTION_TAPOS_EXPIRED, 'MALFORMED_TRANSACTION'])( + 'keeps confirm disabled for local validation failure %s with security alerts off', + (type) => { + expect( + isConfirmDisabled( + buildContext({ + preferences: { ...mockPreferences, useSecurityAlerts: false }, + scan: buildScanResult({ + status: 'ERROR', + simulationStatus: SimulationStatus.Failed, + error: { type, code: null, message: null }, + }), + }), + ), + ).toBe(true); + }, + ); + + it('keeps the initial scan load and local insufficient balance blocking after a remote failure', () => { + const scan = buildScanResult({ + status: 'ERROR', + simulationStatus: SimulationStatus.Failed, + error: otherError, + }); + expect( isConfirmDisabled( - buildContext({ - scan: buildScanResult({ - status: 'ERROR', - simulationStatus: SimulationStatus.Failed, - error: otherError, - }), - }), + buildContext({ scan, scanFetchStatus: FetchStatus.Loading }), ), ).toBe(true); + expect( + isConfirmDisabled(buildContext({ scan, isInsufficientBalance: true })), + ).toBe(true); + expect(renderTexts(buildContext({ scan }))).toContain( + SIMULATION_ERROR_TITLE, + ); }); it('renders the expiry banner with the friendly message even when security alerts are off', () => { diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.tsx index b912ecbe6..89dee2394 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.tsx @@ -15,6 +15,7 @@ import { } from '@metamask/snaps-sdk/jsx'; import { Networks } from '../../../../constants'; +import { TRANSACTION_TAPOS_EXPIRED } from '../../../../services/transaction-scan/isTransactionDeadlinePassedError'; import { SimulationStatus } from '../../../../services/transaction-scan/types'; import { TRX_IMAGE_SVG } from '../../../../static/tron-logo'; import { FetchStatus } from '../../../../types/snap'; @@ -47,14 +48,13 @@ export const ConfirmSignTransaction = ({ } = context; /** - * Only disable the confirm button on the first load (FetchStatus.Loading), - * not during subsequent cron re-scans (FetchStatus.Fetching), and whenever - * the simulation has failed — including the expired/TAPOS-expired case, so - * the user is blocked from confirming a transaction that won't broadcast. + * Block the initial scan load and local validation failures. Remote + * simulation failures and background refreshes do not block confirmation. */ const shouldDisableConfirmButton = scanFetchStatus === FetchStatus.Loading || - scan?.simulationStatus === SimulationStatus.Failed || + scan?.error?.type === TRANSACTION_TAPOS_EXPIRED || + scan?.error?.type === 'MALFORMED_TRANSACTION' || isInsufficientBalance; const addressCaip10 = account ? `${scope}:${account.address}` : null; diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.test.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.test.tsx index 20955942a..8f7a71f84 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.test.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.test.tsx @@ -1,6 +1,7 @@ import { DEFAULT_METAMASK_ORIGIN } from '@metamask/snap-networks-utils'; import { Network } from '../../../../constants'; +import { TRANSACTION_TAPOS_EXPIRED } from '../../../../services/transaction-scan/isTransactionDeadlinePassedError'; import { SimulationStatus } from '../../../../services/transaction-scan/types'; import type { TransactionScanResult } from '../../../../services/transaction-scan/types'; import { FetchStatus } from '../../../../types/snap'; @@ -178,25 +179,57 @@ describe('ConfirmTransactionRequest', () => { expect(serialized).toContain('"disabled":true'); }); - it('disables confirm button when scan status is ERROR', () => { - const errorScanResult: TransactionScanResult = { - ...mockScanResult, - status: 'ERROR', - simulationStatus: SimulationStatus.Failed, - }; + it.each([ + [FetchStatus.Fetched, 'confirmation.simulationErrorTitle'], + [FetchStatus.Fetching, 'confirmation.securityScanInProgressTitle'], + [FetchStatus.Error, 'confirmation.simulationTitleAPIError'], + ])( + 'enables confirm after a remote simulation failure when the scan is %s', + (scanFetchStatus, bannerTitle) => { + const errorScanResult: TransactionScanResult = { + ...mockScanResult, + status: 'ERROR', + simulationStatus: SimulationStatus.Failed, + error: { + type: 'Revert', + code: 'INSUFFICIENT_BALANCE', + message: 'Reverted: insufficient balance', + }, + }; - const context: ConfirmTransactionRequestContext = { - ...baseContext, - scan: errorScanResult, - scanFetchStatus: FetchStatus.Fetched, - }; + const context: ConfirmTransactionRequestContext = { + ...baseContext, + scan: errorScanResult, + scanFetchStatus, + }; - const result = ConfirmTransactionRequest({ context }); - const serialized = JSON.stringify(result); + const result = ConfirmTransactionRequest({ context }); + const serialized = JSON.stringify(result); - // The confirm button should have disabled=true - expect(serialized).toContain('"disabled":true'); - }); + expect(serialized).not.toContain('"disabled":true'); + expect(serialized).toContain(bannerTitle); + }, + ); + + it.each([TRANSACTION_TAPOS_EXPIRED, 'MALFORMED_TRANSACTION'])( + 'keeps confirm disabled for local validation failure %s with security alerts off', + (type) => { + const context: ConfirmTransactionRequestContext = { + ...baseContext, + preferences: { ...mockPreferences, useSecurityAlerts: false }, + scan: { + ...mockScanResult, + status: 'ERROR', + simulationStatus: SimulationStatus.Failed, + error: { type, code: null, message: null }, + }, + }; + + const serialized = JSON.stringify(ConfirmTransactionRequest({ context })); + + expect(serialized).toContain('"disabled":true'); + }, + ); it('enables confirm button when scan is successful', () => { const result = ConfirmTransactionRequest({ context: baseContext }); diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.tsx index 8b45830c9..9888e7915 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.tsx @@ -15,6 +15,7 @@ import { } from '@metamask/snaps-sdk/jsx'; import { Networks } from '../../../../constants'; +import { TRANSACTION_TAPOS_EXPIRED } from '../../../../services/transaction-scan/isTransactionDeadlinePassedError'; import { SimulationStatus } from '../../../../services/transaction-scan/types'; import { TRX_IMAGE_SVG } from '../../../../static/tron-logo'; import { FetchStatus } from '../../../../types/snap'; @@ -47,12 +48,13 @@ export const ConfirmTransactionRequest = ({ const translate = i18n(preferences.locale); /** - * Only disable confirm button upon first load (FetchStatus.Loading) - * as opposed to subsequent loads (FetchStatus.Fetching) + * Block the initial scan load and locally invalid transactions. Remote + * simulation failures and background refreshes do not block confirmation. */ const shouldDisableConfirmButton = scanFetchStatus === FetchStatus.Loading || - scan?.simulationStatus === SimulationStatus.Failed; + scan?.error?.type === TRANSACTION_TAPOS_EXPIRED || + scan?.error?.type === 'MALFORMED_TRANSACTION'; let estimatedChangesSection: ComponentOrElement | null = null; if (preferences.simulateOnChainActions) { From e1702e91b95f518fb817844007b31314a5265410 Mon Sep 17 00:00:00 2001 From: Andrew Taran Date: Wed, 4 Nov 2026 11:52:06 +0100 Subject: [PATCH 2/2] fix: changelog and confirm transaction request alert --- packages/tron-wallet-snap/CHANGELOG.md | 2 +- .../ConfirmTransactionRequest.test.tsx | 5 ++++- .../ConfirmTransactionRequest/ConfirmTransactionRequest.tsx | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/tron-wallet-snap/CHANGELOG.md b/packages/tron-wallet-snap/CHANGELOG.md index b6ef96301..73a6e0821 100644 --- a/packages/tron-wallet-snap/CHANGELOG.md +++ b/packages/tron-wallet-snap/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Allow transaction confirmation after remote simulation failures while retaining security warnings and checks for locally invalid transactions. ([#522](https://github.com/MetaMask/internal-snaps/pull/552)) +- Allow transaction confirmation after remote simulation failures while retaining security warnings and checks for locally invalid transactions. ([#552](https://github.com/MetaMask/internal-snaps/pull/552)) ## [4.3.0] diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.test.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.test.tsx index 8f7a71f84..5a62974c6 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.test.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.test.tsx @@ -212,7 +212,7 @@ describe('ConfirmTransactionRequest', () => { ); it.each([TRANSACTION_TAPOS_EXPIRED, 'MALFORMED_TRANSACTION'])( - 'keeps confirm disabled for local validation failure %s with security alerts off', + 'shows an error banner and keeps confirm disabled for local validation failure %s with security alerts off', (type) => { const context: ConfirmTransactionRequestContext = { ...baseContext, @@ -228,6 +228,9 @@ describe('ConfirmTransactionRequest', () => { const serialized = JSON.stringify(ConfirmTransactionRequest({ context })); expect(serialized).toContain('"disabled":true'); + expect(serialized).toContain('confirmation.simulationErrorTitle'); + expect(serialized).toContain('confirmation.simulationErrorSubtitle'); + expect(serialized).toContain('"severity":"warning"'); }, ); diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.tsx index 9888e7915..a084eb6ce 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest.tsx @@ -92,7 +92,7 @@ export const ConfirmTransactionRequest = ({ {/* Security Alert */} - {preferences.useSecurityAlerts ? ( + {preferences.useSecurityAlerts || scan?.error ? (