Skip to content

feat: enhance transaction alert scanning#138

Merged
stanleyyconsensys merged 2 commits into
mainfrom
feat/enhance-scan-error
Jun 26, 2026
Merged

feat: enhance transaction alert scanning#138
stanleyyconsensys merged 2 commits into
mainfrom
feat/enhance-scan-error

Conversation

@stanleyyconsensys

@stanleyyconsensys stanleyyconsensys commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Explanation

Enhances the snap’s transaction scanning and confirmation UX by adding more robust error localization/mapping (including new simulation error codes), improving estimated-change rendering for Stellar assets (native/classic/SEP-41), and introducing a local preflight check for expired transactions before calling the Security Alerts API.

References

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

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.

Pull request overview

Enhances the snap’s transaction scanning and confirmation UX by adding more robust error localization/mapping (including new simulation error codes), improving estimated-change rendering for Stellar assets (native/classic/SEP-41), and introducing a local preflight check for expired transactions before calling the Security Alerts API.

Changes:

  • Added TransactionScanErrorId + expanded localized scan error coverage (e.g., trustline missing, transaction expired) and updated simulation error copy.
  • Refactored scan response mapping to output string display balances (no scientific notation) and derive icons/metadata for native/classic/SEP-41 assets.
  • Added local preflight validation for expired transactions and introduced Security Alerts API response fixtures for more realistic tests.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/snap/src/ui/confirmation/components/TransactionAlert.tsx Adds localized error IDs for new scan error codes used in the alert banner.
packages/snap/src/ui/confirmation/components/TransactionAlert.test.tsx Updates simulation title assertion and adds coverage for the new expired-tx message path.
packages/snap/src/ui/confirmation/components/EstimatedChanges/EstimatedChanges.tsx Stops formatting numeric values locally; renders the scan-provided display string.
packages/snap/src/ui/confirmation/components/EstimatedChanges/EstimatedChanges.test.tsx Updates tests to expect string-valued asset changes.
packages/snap/src/services/transaction-scan/TransactionScanService.ts Adds preflight timebound check, refactors asset mapping, and normalizes error codes for localization.
packages/snap/src/services/transaction-scan/TransactionScanService.test.ts Reworks tests around realistic fixtures; adds preflight validation coverage and asset-mapping scenarios.
packages/snap/src/services/transaction-scan/SecurityAlertsApiClient.ts Renames/aligns request typing for the scan endpoint payload.
packages/snap/src/services/transaction-scan/api.ts Introduces TransactionScanErrorId, new asset structs (native/classic/SEP-41), and changes estimated-change value to `string
packages/snap/src/services/transaction-scan/mocks/security-alerts-api-response.fixture.ts Adds realistic canned Blockaid responses to use in service tests.
packages/snap/src/handlers/keyring/signTransaction.ts Removes fee computation/simulation step before confirmation/signing; relies on dapp-provided fee.
packages/snap/src/handlers/keyring/signTransaction.test.ts Updates handler setup and removes the fee-simulation failure test.
packages/snap/src/handlers/cronjob/refreshConfirmationContext/scanRefresher.test.ts Updates expected estimated-change value fields to strings.
packages/snap/src/handlers/clientRequest/confirmSend.ts Seeds estimated changes using the string amount directly (no Number(...)).
packages/snap/src/handlers/clientRequest/confirmSend.test.ts Updates expected seeded estimated-change values to strings.
packages/snap/src/context.ts Removes transactionService injection from SignTransactionHandler wiring.
packages/snap/messages.json Updates simulation error title copy and adds new scan error messages.
packages/snap/locales/es.json Mirrors messages.json updates for the ES locale file.
packages/snap/locales/en.json Mirrors messages.json updates for the EN locale file.
packages/snap/.env.example Updates the example static API base URL.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/snap/src/services/transaction-scan/TransactionScanService.ts Outdated
Comment thread packages/snap/src/services/transaction-scan/TransactionScanService.ts Outdated
Comment on lines +74 to +76
// We do not process RPC simulation here, we trust the fee that provided by the dapp.
// If the transaction is invalid, the security scan will output the error.
if (!(await this.#confirmation(request, transaction, account))) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this is expected, we trust the dapp

{
type: AssetChangeDirection.Out,
value: Number(amount),
value: amount,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

we use string instead of number to display


import { KnownCaip2ChainId, XdrStruct } from '../../api';

/**

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

re structure the api struct

options: TransactionScanOption[];
}): Promise<TransactionScanResult | null> {
try {
const preflightValidationErrorResult = options.includes(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

add preflight check to handle some check that blockaids not supported

// failures.
const error =
simulationError ??
preflightValidationError ??

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

preflightValidationError should display if simulationError does not hv error

): StellarAssetDiff[] {
return (
simulation.assets_diffs?.[accountAddress] ??
simulation.account_summary.account_assets_diffs ??

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

simulation.account_summary.account_assets_diffs is useless

* @param value - The human-readable asset amount, or null.
* @returns The amount as a plain decimal string.
*/
function formatValue(value: number | null): string {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

no use anymore


# Static API Base URL
STATIC_API_BASE_URL=https://static.api.cx.metamask.io
STATIC_API_BASE_URL=https://static.cx.metamask.io

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

previous url is incorrect

// Map them to a known error id.
// - "insufficient balance" to "insufficientbalance".
// - "no trustline" to "notrustline".
if (message.toLowerCase().includes('insufficient balance')) {

@stanleyyconsensys stanleyyconsensys Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

try our best to map the error into some expected error

so instead of show a branch of error code, we show some readable error

return TransactionScanErrorId.NoTrustline;
}
return (
this.#getErrorCode(message) ?? TransactionScanErrorId.InvalidTransaction

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

hide the error message , and using invalid transaction

@wantedsystem wantedsystem 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 merged commit 9502f4d into main Jun 26, 2026
10 checks passed
@stanleyyconsensys stanleyyconsensys deleted the feat/enhance-scan-error branch June 26, 2026 09:53
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