Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/site/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#SNAP_ORIGIN=npm:@metamask/stellar-wallet-snap
#SNAP_ORIGIN=npm:@metamask/stellar-wallet-snap
SNAP_ORIGIN=local:http://localhost:8080
2 changes: 1 addition & 1 deletion packages/snap/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"message": "It may have expired or your account balance changed. Close this request and try again."
},
"confirmation.validationScanErrorTitle": {
"message": "Security validation failed"
"message": "Security check unavailable"
},
"confirmation.validationScanErrorSubtitle": {
"message": "{reason}"
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"message": "It may have expired or your account balance changed. Close this request and try again."
},
"confirmation.validationScanErrorTitle": {
"message": "Security validation failed"
"message": "Security check unavailable"
},
"confirmation.validationScanErrorSubtitle": {
"message": "{reason}"
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snap-stellar-wallet.git"
},
"source": {
"shasum": "fcXiAJRViO4Lb+5+PZ8Nhi9yA6B3/kafroMv9FYTe3A=",
"shasum": "Inf8VxNlsHTyLYST3nsK1X0sdkSiAbkFciLrCTsYZNY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
3 changes: 1 addition & 2 deletions packages/snap/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export const ACCOUNT_REQUIRES_MEMO = 'MQ==';
* Maximum native XLM threshold for an incoming
* payment to be treated as dust spam.
*
* Incoming native XLM payments at or below this value are omitted from activity
* history. The threshold matches the 0.001 value used on TRON and Solana.
* Incoming native XLM payments at or below this value are omitted from activity history.
*/
export const DUST_XLM_AMOUNT = '0.001';
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ describe('ChangeTrustOptHandler', () => {
},
renderOptions: {
loadPrice: true,
scanTxn: true,
validateTxn: true,
securityScanning: true,
localSimulation: true,
},
securityScanRequest: {
accountAddress: account.address,
Expand Down Expand Up @@ -464,8 +464,8 @@ describe('ChangeTrustOptHandler', () => {
interfaceKey: ConfirmationInterfaceKey.ChangeTrustlineOptOut,
renderOptions: {
loadPrice: true,
scanTxn: true,
validateTxn: true,
securityScanning: true,
localSimulation: true,
},
securityScanRequest: {
accountAddress: account.address,
Expand Down
7 changes: 5 additions & 2 deletions packages/snap/src/handlers/clientRequest/changeTrustOpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,13 @@ export class ChangeTrustOptHandler extends BaseClientRequestHandler<
},
fee,
interfaceKey: confirmationInterfaceKey,
// localSimulation drives re-validation only; a trustline op moves no
// balance, so there are no estimated changes to seed or display (we
// intentionally pass no initialScan).
renderOptions: {
loadPrice: true,
scanTxn: true,
validateTxn: true,
securityScanning: true,
localSimulation: true,
},
securityScanRequest: {
accountAddress: account.address,
Expand Down
24 changes: 20 additions & 4 deletions packages/snap/src/handlers/clientRequest/confirmSend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
TransactionValidationException,
} from '../../services/transaction/exceptions';
import { KeyringTransactionType } from '../../services/transaction/KeyringTransactionBuilder';
import { AssetChangeDirection } from '../../services/transaction-scan';
import { WalletService } from '../../services/wallet';
import { getTestWallet } from '../../services/wallet/__mocks__/wallet.fixtures';
import { ConfirmationInterfaceKey } from '../../ui/confirmation/api';
Expand Down Expand Up @@ -290,19 +291,34 @@ describe('ConfirmSendHandler', () => {
origin: METAMASK_ORIGIN,
renderContext: {
account,
assetMetadata,
toAddress: destinationAddress,
amount: '1',
},
renderOptions: {
loadPrice: true,
scanTxn: true,
validateTxn: true,
securityScanning: true,
localSimulation: true,
},
securityScanRequest: {
accountAddress: account.address,
transaction: unsignedScanXdr,
},
initialScan: {
status: 'SUCCESS',
estimatedChanges: {
assets: [
{
type: AssetChangeDirection.Out,
value: 1,
price: null,
symbol: assetMetadata.symbol,
name: assetMetadata.name,
logo: assetMetadata.iconUrl,
},
],
},
validation: null,
error: null,
},
transactionValidationRequest: {
accountId: account.id,
transaction: unsignedScanXdr,
Expand Down
55 changes: 51 additions & 4 deletions packages/snap/src/handlers/clientRequest/confirmSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type { ContextWithPrices } from '../../ui/confirmation/api';
import { ConfirmationInterfaceKey } from '../../ui/confirmation/api';
import {
hasDecimals,
isSlip44Id,
toSmallestUnit,
trackTransactionAdded,
trackTransactionApproved,
Expand All @@ -46,6 +47,8 @@ import type {
} from '../accountResolver';
import { BaseClientRequestHandler } from './base';
import { AccountNotActivatedException } from '../../services/network';
import { AssetChangeDirection } from '../../services/transaction-scan';
import type { TransactionScanEstimatedChanges } from '../../services/transaction-scan';
import type { ConfirmationUXController } from '../../ui/confirmation/controller';
import { TrackTransactionHandler } from '../cronjob/trackTransaction';

Expand Down Expand Up @@ -294,28 +297,38 @@ export class ConfirmSendHandler extends BaseClientRequestHandler<
const { request, account, assetMetadata, fee, scope, transaction } = params;
const { toAddress, amount, assetId } = request.params;
const xdr = transaction.getRaw().toXDR();
// The send asset and amount are known from the request, so the estimated
// changes are just a single outgoing row — no local simulation needed.
const estimatedChanges = this.#buildEstimatedChanges({
amount,
assetMetadata,
});

return (
(await this.#confirmationUIController.renderConfirmationDialog({
scope,
origin: METAMASK_ORIGIN,
renderContext: {
account,
assetMetadata,
toAddress,
amount,
},
fee: fee.toString(),
interfaceKey: ConfirmationInterfaceKey.ConfirmSendTransaction,
renderOptions: {
loadPrice: true,
scanTxn: true,
validateTxn: true,
securityScanning: true,
localSimulation: true,
},
securityScanRequest: {
accountAddress: account.address,
transaction: xdr,
},
initialScan: {
status: 'SUCCESS',
estimatedChanges,
validation: null,
error: null,
},
transactionValidationRequest: {
accountId: account.id,
transaction: xdr,
Expand All @@ -328,6 +341,40 @@ export class ConfirmSendHandler extends BaseClientRequestHandler<
);
}

/**
* Builds the estimated balance changes for the send confirmation: a single
* outgoing row for the known send asset and amount. The network fee is
* surfaced separately, so it is excluded here.
*
* @param params - The parameters.
* @param params.amount - The send amount in human-readable units.
* @param params.assetMetadata - The asset metadata for the row.
* @returns The estimated changes to seed the confirmation.
*/
#buildEstimatedChanges({
amount,
assetMetadata,
}: {
amount: string;
assetMetadata: StellarAssetMetadata;
}): TransactionScanEstimatedChanges {
const { assetId, symbol, iconUrl, name } = assetMetadata;
const logo = isSlip44Id(assetId) ? null : (iconUrl ?? null);

return {
assets: [
{
type: AssetChangeDirection.Out,
value: Number(amount),
price: null,
symbol,
name: name ?? symbol,
logo,
},
],
};
}

/**
* Override the base handler to return invalid when the account is not activated.
* Instead of showing the account not activated alert, it returns an invalid response.
Expand Down
Loading
Loading