Skip to content
Draft
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
10 changes: 10 additions & 0 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@
"count": 2
}
},
"packages/tron-wallet-snap/src/services/assets/AssetsRepository.ts": {
"import-x/no-extraneous-dependencies": {
"count": 1
}
},
"packages/tron-wallet-snap/src/services/assets/AssetsService.ts": {
"import-x/no-extraneous-dependencies": {
"count": 2
}
},
"packages/tron-wallet-snap/src/services/assets/AssetsService.test.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 3
Expand Down
5 changes: 5 additions & 0 deletions packages/tron-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Move assets handler logic (metadata, conversions, market data, historical prices) into `AssetsService`; slim `SnapAssetsAdapter` to snap-owned fetch/save/read only. Cron asset sync uses `syncSnapOwnedAssets` for protocol assets.
- Update `snap.manifest.json` bundle shasum ([#82](https://github.com/MetaMask/internal-snaps/pull/82))

### Removed

- Assets migration feature-flag routing. Fungible reads (`getAccountAssetByID`, `getAccountAssetsByIDs`, `getAccountAssetsByScope`) now always use Core `AssetsController` via `AssetsProvider`; snap-owned protocol assets remain on the Snap adapter. Removed `RemoteFeatureFlagController:getState` messenger endowment.

## [2.0.0]

### Changed
Expand Down
2 changes: 0 additions & 2 deletions packages/tron-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
"@metamask/keyring-api": "^23.7.0",
"@metamask/keyring-snap-sdk": "^9.2.1",
"@metamask/messenger": "^2.0.0",
"@metamask/remote-feature-flag-controller": "4.2.2",
"@metamask/snap-networks-utils": "workspace:^",
"@metamask/snaps-cli": "^8.4.1",
"@metamask/snaps-jest": "^10.2.0",
"@metamask/snaps-sdk": "^11.2.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/tron-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": "mmM+5X+wVXS5Xhoa2fhXaeB0IKoqwRduZ7vY7iU4wFs=",
"shasum": "ac/9ewd8ZZXTLl5K5ZMg5PSsUeITzUwYtvfHPNjKQu4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down Expand Up @@ -53,8 +53,7 @@
"actions": [
"AssetsController:getAccountAssetByID",
"AssetsController:getAccountAssetsByIDs",
"AssetsController:getAccountAssetsByScope",
"RemoteFeatureFlagController:getState"
"AssetsController:getAccountAssetsByScope"
]
}
},
Expand Down
2 changes: 0 additions & 2 deletions packages/tron-wallet-snap/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ const securityAlertsApiClient = new SecurityAlertsApiClient(
// Business Services
const assetsService = new AssetsService({
logger,
state,
assetsRepository,
trongridApiClient,
tronHttpClient,
priceApiClient,
tokenApiClient,
snapClient,
coreMessenger,
assetsProvider,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {

import type { SnapClient } from '../../clients/snap/SnapClient';
import { Network } from '../../constants';
import type { NativeAsset } from '../../entities/assets';
import type { TronKeyringAccount } from '../../entities/keyring-account';
import type { ILogger } from '../../utils/logger';
import { mockLogger } from '../../utils/mockLogger';
Expand Down Expand Up @@ -119,9 +118,7 @@ type WithAccountsServiceCallback = (payload: {
>;
mockConfigProvider: jest.Mocked<Pick<ConfigProvider, 'get'>>;
mockLogger: ILogger;
mockAssetsService: jest.Mocked<
Pick<AssetsService, 'fetchAssetsAndBalancesForAccount' | 'saveMany'>
>;
mockAssetsService: jest.Mocked<Pick<AssetsService, 'syncSnapOwnedAssets'>>;
mockSnapClient: jest.Mocked<
Pick<SnapClient, 'getBip32Entropy' | 'listEntropySources'>
>;
Expand Down Expand Up @@ -268,10 +265,9 @@ async function withAccountsService(
};

const mockAssetsService: jest.Mocked<
Pick<AssetsService, 'fetchAssetsAndBalancesForAccount' | 'saveMany'>
Pick<AssetsService, 'syncSnapOwnedAssets'>
> = {
fetchAssetsAndBalancesForAccount: jest.fn().mockResolvedValue([]),
saveMany: jest.fn().mockResolvedValue(undefined),
syncSnapOwnedAssets: jest.fn().mockResolvedValue(undefined),
};

const mockTransactionsService: jest.Mocked<
Expand Down Expand Up @@ -1194,7 +1190,7 @@ describe('AccountsService', () => {
});

describe('synchronizeAssets', () => {
it('calls fetch for each account and scope, then saveMany', async () => {
it('calls syncSnapOwnedAssets with accounts and active networks', async () => {
const account: TronKeyringAccount = {
id: 'sync-asset-id',
address: 'TSyncAsset12345678901234567',
Expand All @@ -1206,42 +1202,22 @@ describe('AccountsService', () => {
derivationPath: "m/44'/195'/0'/0/0",
index: 0,
};
const mockAssets: NativeAsset[] = [
{
assetType: `${Network.Mainnet}/slip44:195`,
keyringAccountId: 'sync-asset-id',
network: Network.Mainnet,
symbol: 'TRX',
decimals: 6,
rawAmount: '1000000',
uiAmount: '1',
iconUrl: '',
},
];

await withAccountsService(
async ({ accountsService, mockConfigProvider, mockAssetsService }) => {
mockConfigProvider.get.mockReturnValue({
...MOCK_CONFIG,
activeNetworks: [Network.Mainnet, Network.Shasta],
});
mockAssetsService.fetchAssetsAndBalancesForAccount.mockResolvedValue(
mockAssets,
);

await accountsService.synchronizeAssets([account]);

expect(
mockAssetsService.fetchAssetsAndBalancesForAccount,
).toHaveBeenCalledTimes(2);
expect(
mockAssetsService.fetchAssetsAndBalancesForAccount,
).toHaveBeenCalledWith(Network.Mainnet, account);
expect(
mockAssetsService.fetchAssetsAndBalancesForAccount,
).toHaveBeenCalledWith(Network.Shasta, account);
expect(mockAssetsService.saveMany).toHaveBeenCalledWith(
expect.arrayContaining(mockAssets),
expect(mockAssetsService.syncSnapOwnedAssets).toHaveBeenCalledTimes(
1,
);
expect(mockAssetsService.syncSnapOwnedAssets).toHaveBeenCalledWith(
[account],
[Network.Mainnet, Network.Shasta],
);
},
);
Expand All @@ -1266,10 +1242,10 @@ describe('AccountsService', () => {

await accountsService.synchronizeAssets([account]);

expect(
mockAssetsService.fetchAssetsAndBalancesForAccount,
).not.toHaveBeenCalled();
expect(mockAssetsService.saveMany).toHaveBeenCalledWith([]);
expect(mockAssetsService.syncSnapOwnedAssets).toHaveBeenCalledWith(
[account],
[],
);
},
);
});
Expand Down Expand Up @@ -1358,9 +1334,10 @@ describe('AccountsService', () => {

await accountsService.synchronize([account]);

expect(
mockAssetsService.fetchAssetsAndBalancesForAccount,
).toHaveBeenCalledWith(Network.Mainnet, account);
expect(mockAssetsService.syncSnapOwnedAssets).toHaveBeenCalledWith(
[account],
[Network.Mainnet],
);
expect(
mockTransactionsService.fetchNewTransactionsForAccount,
).toHaveBeenCalledWith(Network.Mainnet, account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,24 +522,7 @@ export class AccountsService {
*/
async synchronizeAssets(accounts: TronKeyringAccount[]): Promise<void> {
const scopes = this.#configProvider.get().activeNetworks;
const combinations = accounts.flatMap((account) =>
scopes.map((scope) => ({ account, scope })),
);

const assetResponses = await Promise.allSettled(
combinations.map(async ({ account, scope }) => {
return this.#assetsService.fetchAssetsAndBalancesForAccount(
scope,
account,
);
}),
);

const assets = assetResponses.flatMap((response) =>
response.status === 'fulfilled' ? response.value : [],
);

await this.#assetsService.saveMany(assets);
await this.#assetsService.syncSnapOwnedAssets(accounts, scopes);
}

async synchronizeTransactions(accounts: TronKeyringAccount[]): Promise<void> {
Expand Down
Loading
Loading