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
2 changes: 1 addition & 1 deletion eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
"count": 1
}
},
"packages/tron-wallet-snap/src/services/assets/AssetsService.ts": {
"packages/tron-wallet-snap/src/services/assets/adapters/SnapAssetsAdapter.ts": {
"import-x/no-extraneous-dependencies": {
"count": 1
}
Expand Down
2 changes: 1 addition & 1 deletion 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": "kpXPl/gHuE6MQIAy2ZxMvI3XByIC/Gj7xss6WPFWCe4=",
"shasum": "TEEXgH0mFwQ1x70iGzw0kNN7P/lPzIiLa+ATCM2v/vY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { mapKeys } from 'lodash';

import type { ICache } from '../../caching/ICache';
import { useCache } from '../../caching/useCache';
import { SPECIAL_ASSETS } from '../../constants';
import { SNAP_OWNED_ASSETS } from '../../constants';
import type { ConfigProvider } from '../../services/config';
import { buildUrl } from '../../utils/buildUrl';
import type { ILogger } from '../../utils/logger';
Expand Down Expand Up @@ -257,7 +257,7 @@ export class PriceApiClient {
assert(vsCurrency, VsCurrencyParamStruct);

const filteredTokens = tokenCaip19Types.filter(
(tokenCaip19Type) => !SPECIAL_ASSETS.includes(tokenCaip19Type),
(tokenCaip19Type) => !SNAP_OWNED_ASSETS.includes(tokenCaip19Type),
);

return this.#getMultipleSpotPrices_CACHE(filteredTokens, vsCurrency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { array, assert } from '@metamask/superstruct';
import type { Infer } from '@metamask/superstruct';
import { CaipAssetTypeStruct, parseCaipAssetType } from '@metamask/utils';

import { Network, SPECIAL_ASSETS } from '../../constants';
import { Network, SNAP_OWNED_ASSETS } from '../../constants';
import type { TokenCaipAssetType } from '../../services/assets/types';
import { TokenCaipAssetTypeStruct } from '../../services/assets/types';
import type { ConfigProvider } from '../../services/config';
Expand Down Expand Up @@ -94,7 +94,7 @@ export class TokenApiClient {
* Exclude TRON resource tokens (energy and bandwidth), staked tokens, and tokens not from supported networks.
*/
const supportedAssetTypes = assetTypes.filter((assetType) => {
if (SPECIAL_ASSETS.includes(assetType)) {
if (SNAP_OWNED_ASSETS.includes(assetType)) {
return false;
}
const { chainId } = parseCaipAssetType(assetType);
Expand Down
7 changes: 5 additions & 2 deletions packages/tron-wallet-snap/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export const Networks = {
},
} as const;

export const SPECIAL_ASSETS: string[] = [
export const SNAP_OWNED_ASSETS: string[] = [
KnownCaip19Id.TrxStakedForBandwidthMainnet,
KnownCaip19Id.TrxStakedForBandwidthNile,
KnownCaip19Id.TrxStakedForBandwidthShasta,
Expand Down Expand Up @@ -418,9 +418,12 @@ export const SPECIAL_ASSETS: string[] = [
KnownCaip19Id.MaximumEnergyShasta,
];

/** @deprecated Use {@link SNAP_OWNED_ASSETS} instead. */
export const SPECIAL_ASSETS = SNAP_OWNED_ASSETS;

export const ESSENTIAL_ASSETS: string[] = [
KnownCaip19Id.TrxMainnet,
KnownCaip19Id.TrxNile,
KnownCaip19Id.TrxShasta,
...SPECIAL_ASSETS,
...SNAP_OWNED_ASSETS,
];
Original file line number Diff line number Diff line change
Expand Up @@ -2830,4 +2830,79 @@ describe('AssetsService', () => {
});
});
});

describe('facade delegation', () => {
it('delegates repository reads and market helpers to SnapAssetsAdapter', async () => {
await withAssetsService(
async ({ assetsService, mockAssetsRepository, mockPriceApiClient }) => {
const asset: AssetEntity = {
assetType: KnownCaip19Id.TrxMainnet,
keyringAccountId: mockAccount.id,
network: Network.Mainnet,
symbol: 'TRX',
decimals: 6,
rawAmount: '1',
uiAmount: '1',
};

mockAssetsRepository.getByAccountId.mockResolvedValue([asset]);
mockAssetsRepository.getByAccountIdAndAssetTypes.mockResolvedValue([
asset,
]);
mockAssetsRepository.getByAccountIdAndAssetType.mockResolvedValue(
asset,
);
mockPriceApiClient.getFiatExchangeRates.mockResolvedValue({
usd: { value: 1 },
});
mockPriceApiClient.getMultipleSpotPrices.mockResolvedValue(
createSpotPrices({
[KnownCaip19Id.TrxMainnet]: {
id: KnownCaip19Id.TrxMainnet,
price: 1,
},
}),
);

expect(AssetsService.isFiat('eip155:1/erc20:0x0')).toBe(false);
expect(AssetsService.isFiat('swift:0/iso4217:usd')).toBe(true);
expect(AssetsService.hasChanged(asset, [])).toBe(true);
expect(AssetsService.hasChanged(asset, [asset])).toBe(false);

expect(
await assetsService.getAccountAssets(mockAccount.id),
).toStrictEqual([asset]);
expect(
await assetsService.getAccountAssetsByIDs(mockAccount.id, [
KnownCaip19Id.TrxMainnet,
]),
).toStrictEqual([asset]);
expect(
await assetsService.getAccountAssetByID(
mockAccount.id,
KnownCaip19Id.TrxMainnet,
),
).toStrictEqual(asset);
const byKeyringAccountId = await assetsService.getByKeyringAccountId(
mockAccount.id,
);
expect(
byKeyringAccountId.some(
(savedAsset) => savedAsset.assetType === KnownCaip19Id.TrxMainnet,
),
).toBe(true);
const marketData = await assetsService.getMultipleTokensMarketData([
{
asset: KnownCaip19Id.TrxMainnet,
unit: 'swift:0/iso4217:usd',
},
]);
expect(marketData[KnownCaip19Id.TrxMainnet]).toBeDefined();
expect(assetsService.cacheTtlsMilliseconds.historicalPrices).toBe(
3600000,
);
},
);
});
});
});
Loading
Loading