Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bcf5b87
chore: adds snap_trackEvent and origin param
zone-live Jun 12, 2025
13806e1
chore: lint and prettier
zone-live Jun 12, 2025
95b44ee
chore: shasum
zone-live Jun 12, 2025
71f04fd
chore: adds tests for AnalyticsService
zone-live Jun 12, 2025
b715893
chore: adds eslint-disable
zone-live Jun 12, 2025
e6a6c07
chore: adds nullable for origin
zone-live Jun 12, 2025
4d5e30e
chore: prettier
zone-live Jun 12, 2025
2a8f57a
chore: shasum
zone-live Jun 12, 2025
00f79cf
chore: adds the metadata object
zone-live Jun 13, 2025
1a29767
chore: clean up
zone-live Jun 13, 2025
dcdcdbd
Merge branch 'main' into NNT-406-track-events-snap_trackEvent
zone-live Jun 13, 2025
aa38f8b
chore: shasum
zone-live Jun 13, 2025
330d601
Merge branch 'NNT-406-track-events-snap_trackEvent' of github.com:Met…
zone-live Jun 13, 2025
af4b98d
chore: fix
zone-live Jun 13, 2025
8873435
chore: shasum
zone-live Jun 13, 2025
dd4e160
chore: update value to be 'metamask'
zone-live Jun 17, 2025
ada31f6
chore: shasum
zone-live Jun 17, 2025
8aee9ae
chore: adds the METAMASK_ORIGIN
zone-live Jun 17, 2025
bb5a22f
chore: shasum
zone-live Jun 17, 2025
c3e461f
chore: clean up from null values
zone-live Jun 17, 2025
2dc8c19
chore: update test
zone-live Jun 17, 2025
771c5f7
Merge branch 'main' into NNT-406-track-events-snap_trackEvent
zone-live Jun 17, 2025
92efdd5
chore: shasum update
zone-live Jun 17, 2025
acd8565
Merge branch 'NNT-406-track-events-snap_trackEvent' of github.com:Met…
zone-live Jun 17, 2025
59106b5
chore: quick fix
zone-live Jun 18, 2025
043627a
chore: shasum update
zone-live Jun 18, 2025
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
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-solana-wallet.git"
},
"source": {
"shasum": "0G8PXZNx7ioU2jbDWfX7Qv94bxORrt2q1mgWZj/ajow=",
"shasum": "x3HW8KRRDyLlfHoWtHxjKnQppnBshP4O+YlTeVgjhzo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
5 changes: 5 additions & 0 deletions packages/snap/src/core/constants/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export type TokenInfo = {
decimals: number;
};

export type TransactionMetadata = {
scope: Network;
origin: string | null;
};

export const TokenMetadata = {
[KnownCaip19Id.SolMainnet]: {
symbol: 'SOL',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('ClientRequestHandler', () => {
MOCK_SOLANA_KEYRING_ACCOUNT_0,
mockTransaction,
Network.Testnet,
undefined,
{
commitment: 'confirmed',
skipPreflight: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class ClientRequestHandler {
account,
base64EncodedTransaction,
scope,
undefined,
Comment thread
zone-live marked this conversation as resolved.
Outdated
options,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { InternalError, type OnCronjobHandler } from '@metamask/snaps-sdk';
import { assert, literal, object, string } from '@metamask/superstruct';
import {
assert,
literal,
nullable,
object,
string,
} from '@metamask/superstruct';

import { analyticsService, keyring } from '../../../../snapContext';
import logger from '../../../utils/logger';
Expand All @@ -18,7 +24,10 @@ export const OnTransactionAddedRequestStruct = object({
accountId: UuidStruct,
/** The base64 encoded transaction or transaction message. */
base64EncodedTransaction: Base64Struct,
scope: NetworkStruct,
metadata: object({
scope: NetworkStruct,
origin: nullable(string()),
}),
}),
});

Expand All @@ -35,14 +44,14 @@ export const onTransactionAdded: OnCronjobHandler = async ({ request }) => {

assert(request, OnTransactionAddedRequestStruct);

const { accountId, base64EncodedTransaction, scope } = request.params;
const { accountId, base64EncodedTransaction, metadata } = request.params;

const account = await keyring.getAccountOrThrow(accountId);

await analyticsService.trackEventTransactionAdded(
account,
base64EncodedTransaction,
scope,
metadata,
);
} catch (error) {
logger.error(error);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { InternalError, type OnCronjobHandler } from '@metamask/snaps-sdk';
import { assert, literal, object, string } from '@metamask/superstruct';
import {
assert,
literal,
nullable,
object,
string,
} from '@metamask/superstruct';

import { analyticsService, keyring } from '../../../../snapContext';
import logger from '../../../utils/logger';
Expand All @@ -18,7 +24,10 @@ export const OnTransactionApprovedRequestStruct = object({
accountId: UuidStruct,
/** The base64 encoded transaction or transaction message. */
base64EncodedTransaction: Base64Struct,
scope: NetworkStruct,
metadata: object({
scope: NetworkStruct,
origin: nullable(string()),
}),
}),
});

Expand All @@ -35,14 +44,14 @@ export const onTransactionApproved: OnCronjobHandler = async ({ request }) => {

assert(request, OnTransactionApprovedRequestStruct);

const { accountId, base64EncodedTransaction, scope } = request.params;
const { accountId, base64EncodedTransaction, metadata } = request.params;

const account = await keyring.getAccountOrThrow(accountId);

await analyticsService.trackEventTransactionApproved(
account,
base64EncodedTransaction,
scope,
metadata,
);
} catch (error) {
logger.error(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('onTransactionFinalized', () => {

it('refreshes assets, balances and transactions for all accounts that are involved in the transaction', async () => {
const mockAccountId = MOCK_SOLANA_KEYRING_ACCOUNT_0.id;
const mockOrigin = 'https://metamask.io';

// A special transaction with multiple senders and recipients that are all owned by the keyring
const mockTransaction: Transaction = {
Expand Down Expand Up @@ -117,6 +118,10 @@ describe('onTransactionFinalized', () => {
params: {
accountId: mockAccountId,
transaction: mockTransaction,
metadata: {
scope: Network.Testnet,
origin: mockOrigin,
},
},
},
});
Expand Down Expand Up @@ -144,6 +149,7 @@ describe('onTransactionFinalized', () => {

it('refreshes balances and transactions for the sender only if it is the only account involved in the transaction', async () => {
const mockAccountId = MOCK_SOLANA_KEYRING_ACCOUNT_0.id;
const mockOrigin = 'https://metamask.io';

// Transaction with only one owned sender, and one non-owned recipient
const mockTransaction: Transaction = {
Expand Down Expand Up @@ -187,6 +193,10 @@ describe('onTransactionFinalized', () => {
params: {
accountId: mockAccountId,
transaction: mockTransaction,
metadata: {
scope: Network.Testnet,
origin: mockOrigin,
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { TransactionStruct } from '@metamask/keyring-api';
import { InternalError, type OnCronjobHandler } from '@metamask/snaps-sdk';
import { assert, literal, object, string } from '@metamask/superstruct';
import {
assert,
literal,
nullable,
object,
string,
} from '@metamask/superstruct';

import {
analyticsService,
Expand All @@ -9,7 +15,7 @@ import {
transactionsService,
} from '../../../../snapContext';
import logger from '../../../utils/logger';
import { UuidStruct } from '../../../validation/structs';
import { NetworkStruct, UuidStruct } from '../../../validation/structs';
import { ScheduleBackgroundEventMethod } from './ScheduleBackgroundEventMethod';

export const OnTransactionFinalizedRequestStruct = object({
Expand All @@ -19,6 +25,10 @@ export const OnTransactionFinalizedRequestStruct = object({
params: object({
accountId: UuidStruct,
transaction: TransactionStruct,
metadata: object({
scope: NetworkStruct,
origin: nullable(string()),
}),
}),
});

Expand All @@ -36,7 +46,7 @@ export const onTransactionFinalized: OnCronjobHandler = async ({ request }) => {

assert(request, OnTransactionFinalizedRequestStruct);

const { accountId, transaction } = request.params;
const { accountId, transaction, metadata } = request.params;

const account = await keyring.getAccountOrThrow(accountId);

Expand Down Expand Up @@ -64,6 +74,7 @@ export const onTransactionFinalized: OnCronjobHandler = async ({ request }) => {
const trackEventPromise = analyticsService.trackEventTransactionFinalized(
account,
transaction,
metadata,
);

await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { InternalError, type OnCronjobHandler } from '@metamask/snaps-sdk';
import { assert, literal, object, string } from '@metamask/superstruct';
import {
assert,
literal,
nullable,
object,
string,
} from '@metamask/superstruct';

import { analyticsService, keyring } from '../../../../snapContext';
import logger from '../../../utils/logger';
Expand All @@ -18,7 +24,10 @@ export const OnTransactionRejectedRequestStruct = object({
accountId: UuidStruct,
/** The base64 encoded transaction or transaction message. */
base64EncodedTransaction: Base64Struct,
scope: NetworkStruct,
metadata: object({
scope: NetworkStruct,
origin: nullable(string()),
}),
}),
});

Expand All @@ -35,14 +44,14 @@ export const onTransactionRejected: OnCronjobHandler = async ({ request }) => {

assert(request, OnTransactionRejectedRequestStruct);

const { accountId, base64EncodedTransaction, scope } = request.params;
const { accountId, base64EncodedTransaction, metadata } = request.params;

const account = await keyring.getAccountOrThrow(accountId);

await analyticsService.trackEventTransactionRejected(
account,
base64EncodedTransaction,
scope,
metadata,
);
} catch (error) {
logger.error(error);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { InternalError, type OnCronjobHandler } from '@metamask/snaps-sdk';
import { assert, literal, object, string } from '@metamask/superstruct';
import {
assert,
literal,
nullable,
object,
string,
} from '@metamask/superstruct';

import { analyticsService, keyring } from '../../../../snapContext';
import logger from '../../../utils/logger';
Expand All @@ -19,7 +25,10 @@ export const OnTransactionSubmittedRequestStruct = object({
/** The base64 encoded transaction message. */
transactionMessageBase64Encoded: Base64Struct,
signature: string(),
scope: NetworkStruct,
metadata: object({
scope: NetworkStruct,
origin: nullable(string()),
}),
}),
});

Expand All @@ -36,7 +45,7 @@ export const onTransactionSubmitted: OnCronjobHandler = async ({ request }) => {

assert(request, OnTransactionSubmittedRequestStruct);

const { accountId, transactionMessageBase64Encoded, signature, scope } =
const { accountId, transactionMessageBase64Encoded, signature, metadata } =
request.params;

const account = await keyring.getAccountOrThrow(accountId);
Expand All @@ -45,7 +54,7 @@ export const onTransactionSubmitted: OnCronjobHandler = async ({ request }) => {
account,
transactionMessageBase64Encoded,
signature,
scope,
metadata,
);
} catch (error) {
logger.error(error);
Expand Down
2 changes: 2 additions & 0 deletions packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ export class SolanaKeyring implements Keyring {
request: { method, params },
scope,
account: accountId,
origin,
} = request;

const account = await this.getAccountOrThrow(accountId);
Expand Down Expand Up @@ -441,6 +442,7 @@ export class SolanaKeyring implements Keyring {
account,
base64EncodedTransaction,
scope,
origin,
options,
);
}
Expand Down
Loading
Loading