Skip to content

fix(stellar-wallet-snap): display transaction error message + skip security scanning when failed during the background validation in confirmation dialog - #282

Merged
stanleyyconsensys merged 7 commits into
mainfrom
fix/on-going-txn-validation
Sep 7, 2026
Merged

fix(stellar-wallet-snap): display transaction error message + skip security scanning when failed during the background validation in confirmation dialog #282
stanleyyconsensys merged 7 commits into
mainfrom
fix/on-going-txn-validation

Conversation

@stanleyyconsensys

@stanleyyconsensys stanleyyconsensys commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Explanation

This PR:

  • Align error message for confirmation dialog during the concurrent background validation
  • Stop security scanning if the the local validation failed

References

Ticket: https://consensyssoftware.atlassian.net/browse/WPN-2027

https://www.loom.com/share/7a961d45b97b4bc5ba1fce2a98f6307f

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@stanleyyconsensys
stanleyyconsensys requested a review from a team as a code owner September 7, 2026 06:46
*/
export function getTxnErrorMessageKey(
error: TransactionValidationException,
error: unknown,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to unknown to accept any error

transactionService.createValidatedSendTransaction.mockRejectedValueOnce(
new Error('insufficient balance'),
);
it.each([

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add all coverage to the test

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Writing securityScanRequest: null can invalidate the scan refresher context shape and cause the refresh handler to skip all subsequent refresh cycles when scan refresh is enabled.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates the Stellar wallet snap’s background confirmation re-validation flow so that when the pending transaction becomes invalid during periodic refresh, the UI can display a mapped (localized) transaction error message.

Changes:

  • Add errorMessage (mapped via getTxnErrorMessageKey) to the transaction refresher’s error result when background re-validation fails.
  • Expand transaction refresher tests to cover multiple transaction-validation error subclasses and assert the expected message keys.
  • Widen getTxnErrorMessageKey’s input type to unknown and record the behavior change in the package changelog.
File summaries
File Description
packages/stellar-wallet-snap/src/handlers/cronjob/refreshConfirmationContext/transactionRefresher.ts Adds mapped transaction error message to the refresh result when re-validation fails; attempts to suppress scan work on failure.
packages/stellar-wallet-snap/src/handlers/cronjob/refreshConfirmationContext/transactionRefresher.test.ts Converts the single failure test into a parameterized suite covering specific validation exceptions and expected message keys.
packages/stellar-wallet-snap/src/handlers/clientRequest/utils.ts Broadens getTxnErrorMessageKey’s parameter type from a specific exception to unknown.
packages/stellar-wallet-snap/CHANGELOG.md Adds a “Fixed” entry describing the new error banner mapping behavior and scan-skip behavior on failure.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +254 to +261
expect(result).toStrictEqual({
result: {
transactionsFetchStatus: FetchStatus.Error,
errorMessage,
securityScanRequest: null,
},
reschedule: false,
});

@stanleyyconsensys stanleyyconsensys Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not valid

local Transaction validation always go first, and set securityScanRequest to null if any error

in security scan there is a method shouldFetch, if securityScanRequest is null, the whole scan will be skip

shouldFetch(ctx: ConfirmationDataContext): boolean {
    const scanCtx = ctx as SecurityScanContext;
    if (scanCtx.scanFetchStatus === FetchStatus.Error) {
      return false;
    }
    if (!scanCtx.securityScanRequest) {<---this will skip the scan
      return false;
    }
    return this.#getScanOptions(scanCtx).length > 0;
  }

Comment on lines 183 to +189
return {
result: { transactionsFetchStatus: FetchStatus.Error },
result: {
transactionsFetchStatus: FetchStatus.Error,
errorMessage: getTxnErrorMessageKey(error, accountAddress),
// Skip the security scan request to avoid wasting time on a failed transaction.
securityScanRequest: null,
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, this is not a valid comment

const { request, accountId, scope, securityScanRequest, origin } =
validationCtx;
// Use the scan request address as Default if it is present.
let accountAddress = securityScanRequest?.accountAddress ?? '';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on a re-scan process, address will be already extracted in securityScanRequest?.accountAddress
this is just best effort

});
accountAddress = onChainAccount.accountId;

// TODO(follow-up): this validates a rebuilt draft as a proxy for the stored

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment not valid anymore

const { securityScanRequest, origin } = validationCtx;
const rebuiltTransactionXdr = rebuiltTransaction.getRaw().toXDR();

// Always feed the rebuilt envelope to the scan refresher. The user-facing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment not valid anymore

transactionsFetchStatus: FetchStatus.Error,
errorMessage: getTxnErrorMessageKey(error, accountAddress),
// Skip the security scan request to avoid wasting time on a failed transaction.
securityScanRequest: null,

@stanleyyconsensys stanleyyconsensys Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop the security scanning for whatever reason that we cant scan locally

@stanleyyconsensys stanleyyconsensys changed the title fix(stellar-wallet-snap): display transaction error message when failed during the background validation in confirmation dialog fix(stellar-wallet-snap): display transaction error message + skip security scanning when failed during the background validation in confirmation dialog Sep 7, 2026
@sonarqubecloud

sonarqubecloud Bot commented Sep 7, 2026

Copy link
Copy Markdown

@khanti42 khanti42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stanleyyconsensys
stanleyyconsensys added this pull request to the merge queue Sep 7, 2026
@stanleyyconsensys
stanleyyconsensys removed this pull request from the merge queue due to a manual request Sep 7, 2026
@stanleyyconsensys
stanleyyconsensys added this pull request to the merge queue Sep 7, 2026
Merged via the queue into main with commit f67a6d9 Sep 7, 2026
96 checks passed
@stanleyyconsensys
stanleyyconsensys deleted the fix/on-going-txn-validation branch September 7, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants