Skip to content

Commit 2df917d

Browse files
Merge branch 'main' into NNT-399-solana-snap-write-unit-tests-for-on-accounts-refresh-ts
2 parents 3412e16 + 149e7cf commit 2df917d

22 files changed

Lines changed: 58 additions & 50 deletions

File tree

packages/snap/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snap-solana-wallet.git"
88
},
99
"source": {
10-
"shasum": "NfjYYpYE9M/qdyVE1zrmo40xozAuPrqS2ayUgh3eS1M=",
10+
"shasum": "ssZ6XwPzUpBCXstPx6ko5dEVFVlcF6aqcaO9LhE4gj8=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snap/src/core/handlers/onKeyringRequest/Keyring.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SolMethod } from '@metamask/keyring-api';
55
import type { CaipAssetType, JsonRpcRequest } from '@metamask/snaps-sdk';
66
import { signature } from '@solana/kit';
77

8+
import { asStrictKeyringAccount } from '../../../entities';
89
import { KnownCaip19Id, Network } from '../../constants/solana';
910
import type { AssetsService } from '../../services/assets/AssetsService';
1011
import type { ConfirmationHandler } from '../../services/confirmation/ConfirmationHandler';
@@ -34,7 +35,7 @@ import {
3435
import { getBip32EntropyMock } from '../../test/mocks/utils/getBip32Entropy';
3536
import { getBip32Entropy } from '../../utils/getBip32Entropy';
3637
import logger from '../../utils/logger';
37-
import { asStrictKeyringAccount, SolanaKeyring } from './Keyring';
38+
import { SolanaKeyring } from './Keyring';
3839

3940
jest.mock('@metamask/keyring-snap-sdk', () => ({
4041
...jest.requireActual('@metamask/keyring-snap-sdk'),

packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable prettier/prettier */
12
/* eslint-disable @typescript-eslint/restrict-plus-operands */
23
/* eslint-disable @typescript-eslint/prefer-reduce-type-parameter */
34
import type {
@@ -33,6 +34,10 @@ import type { Signature } from '@solana/kit';
3334
import { address as asAddress, getAddressDecoder } from '@solana/kit';
3435
import { sortBy } from 'lodash';
3536

37+
import {
38+
asStrictKeyringAccount,
39+
type SolanaKeyringAccount,
40+
} from '../../../entities';
3641
import { type Network } from '../../constants/solana';
3742
import type { AssetsService } from '../../services/assets/AssetsService';
3843
import type { ConfirmationHandler } from '../../services/confirmation/ConfirmationHandler';
@@ -60,36 +65,6 @@ import {
6065
SolanaKeyringRequestStruct,
6166
} from './structs';
6267

63-
/**
64-
* We need to store the index of the KeyringAccount in the state because
65-
* we want to be able to restore any account with a previously used index.
66-
*/
67-
export type SolanaKeyringAccount = {
68-
entropySource: EntropySourceId;
69-
derivationPath: `m/${string}`;
70-
index: number;
71-
} & KeyringAccount;
72-
73-
/**
74-
* Converts a Solana keyring account to its stricter form (required by the Keyring API).
75-
*
76-
* @param account - A Solana keyring account.
77-
* @returns A strict keyring account (with no additional fields).
78-
*/
79-
export function asStrictKeyringAccount(
80-
account: SolanaKeyringAccount,
81-
): KeyringAccount {
82-
const { type, id, address, options, methods, scopes } = account;
83-
return {
84-
type,
85-
id,
86-
address,
87-
options,
88-
methods,
89-
scopes,
90-
};
91-
}
92-
9368
export class SolanaKeyring implements Keyring {
9469
readonly #state: IStateManager<UnencryptedStateValue>;
9570

packages/snap/src/core/services/analytics/AnalyticsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Transaction } from '@metamask/keyring-api';
22
import { assert } from '@metamask/superstruct';
33

4+
import type { SolanaKeyringAccount } from '../../../entities';
45
import type { Network } from '../../constants/solana';
5-
import type { SolanaKeyringAccount } from '../../handlers/onKeyringRequest/Keyring';
66
import logger from '../../utils/logger';
77
import { Base64Struct } from '../../validation/structs';
88

packages/snap/src/core/services/assets/AssetsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import type { Address } from '@solana/kit';
88
import { address as asAddress } from '@solana/kit';
99
import { map, uniq } from 'lodash';
1010

11+
import type { SolanaKeyringAccount } from '../../../entities';
1112
import type { ICache } from '../../caching/ICache';
1213
import { useCache } from '../../caching/useCache';
1314
import {
1415
Network,
1516
SolanaCaip19Tokens,
1617
TOKEN_2022_PROGRAM_ADDRESS,
1718
} from '../../constants/solana';
18-
import type { SolanaKeyringAccount } from '../../handlers/onKeyringRequest/Keyring';
1919
import type {
2020
GetTokenAccountsByOwnerResponse,
2121
TokenAccountInfoWithJsonData,

packages/snap/src/core/services/confirmation/ConfirmationHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { SolMethod } from '@metamask/keyring-api';
22
import { assert, union } from '@metamask/superstruct';
33

4+
import type { SolanaKeyringAccount } from '../../../entities';
45
import { render as renderConfirmSignIn } from '../../../features/confirmation/views/ConfirmSignIn/render';
56
import { render as renderConfirmSignMessage } from '../../../features/confirmation/views/ConfirmSignMessage/render';
67
import {
78
DEFAULT_CONFIRMATION_CONTEXT,
89
render as renderConfirmTransactionRequest,
910
} from '../../../features/confirmation/views/ConfirmTransactionRequest/render';
1011
import { ScheduleBackgroundEventMethod } from '../../handlers/onCronjob/backgroundEvents/ScheduleBackgroundEventMethod';
11-
import type { SolanaKeyringAccount } from '../../handlers/onKeyringRequest/Keyring';
1212
import type { SolanaKeyringRequest } from '../../handlers/onKeyringRequest/structs';
1313
import {
1414
SolanaSignAndSendTransactionRequestStruct,

packages/snap/src/core/services/execution/TransactionHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
type Blockhash,
2323
} from '@solana/kit';
2424

25+
import type { SolanaKeyringAccount } from '../../../entities';
2526
import type { Network } from '../../constants/solana';
26-
import type { SolanaKeyringAccount } from '../../handlers/onKeyringRequest/Keyring';
2727
import type { DecompileTransactionMessageFetchingLookupTablesConfig } from '../../sdk-extensions/codecs';
2828
import {
2929
fromBytesToCompilableTransactionMessage,

packages/snap/src/core/services/execution/mocks/scenarios/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CompilableTransactionMessage } from '@solana/kit';
22

3+
import type { SolanaKeyringAccount } from '../../../../../entities';
34
import type { Network } from '../../../../constants/solana';
4-
import type { SolanaKeyringAccount } from '../../../../handlers/onKeyringRequest/Keyring';
55

66
export type MockExecutionScenario = {
77
name: string;

packages/snap/src/core/services/state/State.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { CaipAssetType } from '@metamask/utils';
55
import type { Address, Signature } from '@solana/kit';
66
import { unset } from 'lodash';
77

8+
import type { SolanaKeyringAccount } from '../../../entities';
89
import type { SpotPrices } from '../../clients/price-api/types';
9-
import type { SolanaKeyringAccount } from '../../handlers/onKeyringRequest/Keyring';
1010
import { deserialize } from '../../serialization/deserialize';
1111
import { serialize } from '../../serialization/serialize';
1212
import type { Serializable } from '../../serialization/types';

packages/snap/src/core/services/transactions/TransactionsService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
type Signature,
1111
} from '@solana/kit';
1212

13+
import type { SolanaKeyringAccount } from '../../../entities';
1314
import { Network } from '../../constants/solana';
14-
import type { SolanaKeyringAccount } from '../../handlers/onKeyringRequest/Keyring';
1515
import type { ILogger } from '../../utils/logger';
1616
import type { ConfigProvider } from '../config';
1717
import type { SolanaConnection } from '../connection';
@@ -144,7 +144,7 @@ export class TransactionsService {
144144

145145
const next =
146146
signatures.length === pagination.limit
147-
? (signatures[signatures.length - 1] ?? null)
147+
? (signatures[signatures.length - 1] ?? null) // eslint-disable-line prettier/prettier
148148
: null;
149149

150150
return {

0 commit comments

Comments
 (0)