Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 0 additions & 24 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,30 +443,6 @@
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/state/IStateManager.ts": {
"@typescript-eslint/no-explicit-any": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/state/State.test.ts": {
"@typescript-eslint/no-explicit-any": {
"count": 1
},
"import-x/no-named-as-default": {
"count": 1
},
"n/no-sync": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/state/State.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 2
},
"@typescript-eslint/no-explicit-any": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/subscriptions/KeyringAccountMonitor.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 1
Expand Down
1 change: 0 additions & 1 deletion packages/solana-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"@types/lodash": "^4.17.15",
"@types/react": "18.2.4",
"@types/react-dom": "18.2.4",
"async-mutex": "^0.5.0",
"bignumber.js": "^9.3.1",
"bs58": "^6.0.0",
"buffer": "^6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/solana-wallet-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/internal-snaps.git"
},
"source": {
"shasum": "Szf70/ghTVTeyeEcPUPnHGKxE+tWaZBEZJuR4Kh+gks=",
"shasum": "ZqSe1KRFMXRwvFxy8zShPbafw2c3AKz+HfBxJ2RwIxA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
transactionScanService,
} from '../../../../snapContext';
import { METAMASK_ORIGIN } from '../../../constants/solana';
import type { UnencryptedStateValue } from '../../../services/state/State';
import type { UnencryptedStateValue } from '../../../services/state/stateTypes';
import { EXPIRED_TRANSACTION_SCAN } from '../../../services/transaction-scan/buildExpiredScanResult';
import { isTransactionBlockhashExpired } from '../../../services/transaction-scan/isTransactionBlockhashExpired';
import { trackError } from '../../../utils/errors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import type { KeyringRequest } from '@metamask/keyring-api';
import { AccountCreationType, SolMethod } from '@metamask/keyring-api';
import { Logger } from '@metamask/snap-networks-utils';
import { InMemoryState, Logger } from '@metamask/snap-networks-utils';
import type { IStateManager } from '@metamask/snap-networks-utils';
import { InvalidParamsError, SnapError } from '@metamask/snaps-sdk';
import type { CaipAssetType, JsonRpcRequest } from '@metamask/snaps-sdk';
import { signature } from '@solana/kit';
Expand All @@ -18,10 +19,8 @@ import type {
TransactionsService,
} from '../../services';
import type { ConfirmationHandler } from '../../services/confirmation/ConfirmationHandler';
import { InMemoryState } from '../../services/state/InMemoryState';
import type { IStateManager } from '../../services/state/IStateManager';
import { DEFAULT_UNENCRYPTED_STATE } from '../../services/state/State';
import type { UnencryptedStateValue } from '../../services/state/State';
import { DEFAULT_UNENCRYPTED_STATE } from '../../services/state/stateTypes';
import type { UnencryptedStateValue } from '../../services/state/stateTypes';
import { MOCK_SIGN_AND_SEND_TRANSACTION_REQUEST } from '../../services/wallet/mocks';
import type { WalletService } from '../../services/wallet/WalletService';
import {
Expand Down Expand Up @@ -301,18 +300,26 @@ describe('SolanaKeyring', () => {

describe('deleteAccount', () => {
it('deletes an account', async () => {
const accountBeforeDeletion = await keyring.getAccount(
MOCK_SOLANA_KEYRING_ACCOUNT_1.id,
);
const accountId = MOCK_SOLANA_KEYRING_ACCOUNT_1.id;
await mockState.setKey(`transactions.${accountId}`, []);
await mockState.setKey(`assetEntities.${accountId}`, [
MOCK_ASSET_ENTITY_1,
]);

const accountBeforeDeletion = await keyring.getAccount(accountId);
expect(accountBeforeDeletion).toBeDefined();

await keyring.deleteAccount(MOCK_SOLANA_KEYRING_ACCOUNT_1.id);
await keyring.deleteAccount(accountId);

await expect(
keyring.getAccount(MOCK_SOLANA_KEYRING_ACCOUNT_1.id),
).rejects.toThrow(
`Account "${MOCK_SOLANA_KEYRING_ACCOUNT_1.id}" not found`,
await expect(keyring.getAccount(accountId)).rejects.toThrow(
`Account "${accountId}" not found`,
);
expect(
await mockState.getKey(`transactions.${accountId}`),
).toBeUndefined();
expect(
await mockState.getKey(`assetEntities.${accountId}`),
).toBeUndefined();
});

it('throws an error if account provided is not a uuid', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import type {
ExportedAccount,
KeyringSnapRpc,
} from '@metamask/keyring-api/v2';
import type { Logger } from '@metamask/snap-networks-utils';
import { UuidStruct } from '@metamask/snap-networks-utils';
import type { IStateManager, Logger } from '@metamask/snap-networks-utils';
import type { CaipAssetType, JsonRpcRequest } from '@metamask/snaps-sdk';
import {
InvalidParamsError,
Expand All @@ -51,8 +51,7 @@ import type {
TransactionsService,
} from '../../services';
import type { ConfirmationHandler } from '../../services/confirmation/ConfirmationHandler';
import type { IStateManager } from '../../services/state/IStateManager';
import type { UnencryptedStateValue } from '../../services/state/State';
import type { UnencryptedStateValue } from '../../services/state/stateTypes';
import { SolanaWalletRequestStruct } from '../../services/wallet/structs';
import type {
SolanaSignAndSendTransactionResponse,
Expand Down Expand Up @@ -382,10 +381,10 @@ export class SolanaKeyring implements KeyringSnapRpc {
}

async #deleteAccountFromState(accountId: string): Promise<void> {
await Promise.all([
this.#state.deleteKey(`keyringAccounts.${accountId}`),
this.#state.deleteKey(`transactions.${accountId}`),
this.#state.deleteKey(`assets.${accountId}`),
await this.#state.deleteKeys([
`keyringAccounts.${accountId}`,
`transactions.${accountId}`,
`assetEntities.${accountId}`,
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IStateManager } from '@metamask/snap-networks-utils';

import type { SolanaKeyringAccount } from '../../../entities';
import type { IStateManager } from '../state/IStateManager';
import type { UnencryptedStateValue } from '../state/State';
import type { UnencryptedStateValue } from '../state/stateTypes';

export class AccountsRepository {
readonly #state: IStateManager<UnencryptedStateValue>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { InMemoryState } from '@metamask/snap-networks-utils';
import type { IStateManager } from '@metamask/snap-networks-utils';
import { cloneDeep } from 'lodash';

import {
Expand All @@ -10,10 +12,8 @@ import {
MOCK_SOLANA_KEYRING_ACCOUNT_0,
MOCK_SOLANA_KEYRING_ACCOUNT_1,
} from '../../test/mocks/solana-keyring-accounts';
import { InMemoryState } from '../state/InMemoryState';
import type { IStateManager } from '../state/IStateManager';
import type { UnencryptedStateValue } from '../state/State';
import { DEFAULT_UNENCRYPTED_STATE } from '../state/State';
import { DEFAULT_UNENCRYPTED_STATE } from '../state/stateTypes';
import type { UnencryptedStateValue } from '../state/stateTypes';
import { AssetsRepository } from './AssetsRepository';

describe('AssetsRepository', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IStateManager } from '@metamask/snap-networks-utils';
import { cloneDeep } from 'lodash';

import type { AssetEntity } from '../../../entities';
import type { IStateManager } from '../state/IStateManager';
import type { UnencryptedStateValue } from '../state/State';
import type { UnencryptedStateValue } from '../state/stateTypes';

export class AssetsRepository {
readonly #state: IStateManager<UnencryptedStateValue>;
Expand Down
122 changes: 0 additions & 122 deletions packages/solana-wallet-snap/src/core/services/state/IStateManager.ts

This file was deleted.

This file was deleted.

Loading