Skip to content
Merged
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
14 changes: 0 additions & 14 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,6 @@
},
"no-restricted-syntax": {
"count": 1
},
"no-unused-private-class-members": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/handlers/onRpcRequest/index.ts": {
Expand Down Expand Up @@ -363,9 +360,6 @@
"@typescript-eslint/explicit-function-return-type": {
"count": 10
},
"@typescript-eslint/no-unused-vars": {
"count": 1
},
"no-unused-private-class-members": {
"count": 2
}
Expand Down Expand Up @@ -519,11 +513,6 @@
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/send/SendService.ts": {
"@typescript-eslint/no-unused-vars": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/send/SendSolBuilder.test.ts": {
"import-x/no-named-as-default": {
"count": 1
Expand Down Expand Up @@ -1256,9 +1245,6 @@
"@typescript-eslint/no-explicit-any": {
"count": 1
},
"@typescript-eslint/no-shadow": {
"count": 1
},
"jest/unbound-method": {
"count": 2
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"test:packages": "yarn test:verbose --silent --collectCoverage=false --reporters=jest-silent-reporter",
"test:scripts": "NODE_OPTIONS=--experimental-vm-modules yarn jest --config ./jest.config.scripts.js --silent",
"test:verbose": "yarn workspaces foreach --all --exclude @metamask/sample-snap --parallel --verbose run test:verbose",
"typecheck": "yarn workspaces foreach --all --parallel --verbose exec tsc --noEmit",
"typecheck": "yarn workspace @metamask/snap-networks-utils run build && yarn workspaces foreach --all --parallel --verbose exec tsc --noEmit",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This will be removed when we coordinate how we want typescript to work across the repo. For now, we need it.

"workspaces:list-versions": "./scripts/list-workspace-versions.sh"
},
"devDependencies": {
Expand Down Expand Up @@ -91,6 +91,7 @@
"resolutions": {
"@metamask/snaps-execution-environments": "11.2.0",
"@metamask/snaps-sdk": "11.2.0",
"@solana/addresses": "2.1.0",
"@solana/kit": "2.1.0",
"@types/react": "18.2.4",
"@types/react-dom": "18.2.4",
Expand Down
4 changes: 4 additions & 0 deletions packages/solana-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Align `AssetsService` read API with `snap-networks-utils` / AssetsController shapes by adding `getAccountAssetByID`, `getAccountAssetsByIDs`, `getAccountAssetsByScope`, and `getAccountAssets`, and routing Keyring and Send through them (still Snap-owned storage). ([#120](https://github.com/MetaMask/internal-snaps/pull/120))

## [6.0.0]

### Changed
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": "Zj/AFb6WtXcDvQqAvfHjjEBTdWVdP0tVGUzLnPhAhQ4=",
"shasum": "YaPEFBNuMbbASorQCj4MFJKRSlqOjSOqJoOGUB9ET2I=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ describe('SolanaKeyring', () => {
mockAssetsService = {
fetch: jest.fn().mockResolvedValue(MOCK_ASSET_ENTITIES),
saveMany: jest.fn(),
findByAccount: jest.fn(),
getAccountAssets: jest.fn(),
getAccountAssetsByIDs: jest.fn(),
getNativeAssetTypes: jest
.fn()
.mockReturnValue([KnownCaip19Id.SolMainnet]),
Expand Down Expand Up @@ -143,13 +144,16 @@ describe('SolanaKeyring', () => {
describe('getAccountAssets', () => {
it('calls the assets service', async () => {
jest
.spyOn(mockAssetsService, 'findByAccount')
.spyOn(mockAssetsService, 'getAccountAssets')
.mockResolvedValue(MOCK_ASSET_ENTITIES);

const result = await keyring.getAccountAssets(
MOCK_SOLANA_KEYRING_ACCOUNT_0.id,
);

expect(mockAssetsService.getAccountAssets).toHaveBeenCalledWith(
MOCK_SOLANA_KEYRING_ACCOUNT_0.id,
);
expect(result).toStrictEqual([
MOCK_ASSET_ENTITY_0.assetType,
MOCK_ASSET_ENTITY_1.assetType,
Expand All @@ -158,7 +162,7 @@ describe('SolanaKeyring', () => {
});

it('removes token assets with zero balance', async () => {
jest.spyOn(mockAssetsService, 'findByAccount').mockResolvedValue([
jest.spyOn(mockAssetsService, 'getAccountAssets').mockResolvedValue([
MOCK_ASSET_ENTITY_1, // Token asset with non-zero balance
{ ...MOCK_ASSET_ENTITY_2, rawAmount: '0' }, // Token asset with zero balance
]);
Expand All @@ -171,7 +175,7 @@ describe('SolanaKeyring', () => {
});

it('keeps the native asset even if it has zero balance', async () => {
jest.spyOn(mockAssetsService, 'findByAccount').mockResolvedValue([
jest.spyOn(mockAssetsService, 'getAccountAssets').mockResolvedValue([
{ ...MOCK_ASSET_ENTITY_0, rawAmount: '0' }, // Native asset with zero balance
{ ...MOCK_ASSET_ENTITY_1, rawAmount: '0' }, // Token asset with zero balance
]);
Expand Down Expand Up @@ -343,9 +347,9 @@ describe('SolanaKeyring', () => {
symbol: 4,
} as unknown as AssetEntity;

jest
.spyOn(mockAssetsService, 'findByAccount')
.mockResolvedValue([invalidAsset]);
jest.spyOn(mockAssetsService, 'getAccountAssetsByIDs').mockResolvedValue({
[KnownCaip19Id.SolMainnet]: invalidAsset,
});

await expect(
keyring.getAccountBalances(MOCK_SOLANA_KEYRING_ACCOUNT_1.id, [
Expand All @@ -355,10 +359,13 @@ describe('SolanaKeyring', () => {
});

it('removes token assets with zero balance', async () => {
jest.spyOn(mockAssetsService, 'findByAccount').mockResolvedValue([
MOCK_ASSET_ENTITY_1, // Token asset with non-zero balance
{ ...MOCK_ASSET_ENTITY_2, rawAmount: '0' }, // Token asset with zero balance
]);
jest.spyOn(mockAssetsService, 'getAccountAssetsByIDs').mockResolvedValue({
[MOCK_ASSET_ENTITY_1.assetType]: MOCK_ASSET_ENTITY_1,
[MOCK_ASSET_ENTITY_2.assetType]: {
...MOCK_ASSET_ENTITY_2,
rawAmount: '0',
},
});

const result = await keyring.getAccountBalances(
MOCK_SOLANA_KEYRING_ACCOUNT_0.id,
Expand All @@ -374,10 +381,16 @@ describe('SolanaKeyring', () => {
});

it('keeps the native asset even if it has zero balance', async () => {
jest.spyOn(mockAssetsService, 'findByAccount').mockResolvedValue([
{ ...MOCK_ASSET_ENTITY_0, rawAmount: '0' }, // Native asset with zero balance
{ ...MOCK_ASSET_ENTITY_1, rawAmount: '0' }, // Token asset with zero balance
]);
jest.spyOn(mockAssetsService, 'getAccountAssetsByIDs').mockResolvedValue({
[MOCK_ASSET_ENTITY_0.assetType]: {
...MOCK_ASSET_ENTITY_0,
rawAmount: '0',
},
[MOCK_ASSET_ENTITY_1.assetType]: {
...MOCK_ASSET_ENTITY_1,
rawAmount: '0',
},
});

const result = await keyring.getAccountBalances(
MOCK_SOLANA_KEYRING_ACCOUNT_0.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ export class SolanaKeyring implements KeyringSnapRpc {

readonly #keyringAccountMonitor: KeyringAccountMonitor;

readonly #traceName: string = 'Create Solana Account';

readonly #traceNameBatch: string = 'Create Solana Account Batch';

constructor({
Expand Down Expand Up @@ -413,9 +411,10 @@ export class SolanaKeyring implements KeyringSnapRpc {
try {
validateRequest({ accountId }, ListAccountAssetsStruct);

const account = await this.getAccountOrThrow(accountId);
await this.getAccountOrThrow(accountId);

const assetEntities = await this.#assetsService.findByAccount(account);
const assetEntities =
await this.#assetsService.getAccountAssets(accountId);

const result = assetEntities
// Remove token assets with zero balance
Expand Down Expand Up @@ -448,10 +447,15 @@ export class SolanaKeyring implements KeyringSnapRpc {
try {
validateRequest({ accountId, assets }, GetAccountBalancesStruct);

const account = await this.getAccountOrThrow(accountId);
await this.getAccountOrThrow(accountId);

const assetsById = await this.#assetsService.getAccountAssetsByIDs(
accountId,
assets,
);

const assetsToUse = (await this.#assetsService.findByAccount(account))
.filter((asset) => assets.includes(asset.assetType))
const assetsToUse = Object.values(assetsById)
.filter((asset): asset is NonNullable<typeof asset> => asset !== null)
// Remove token assets with zero balance
.filter(
(asset) =>
Expand Down
Loading