@metamask/assets-controller 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -3
- package/dist/AssetsController.cjs +74 -12
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +36 -11
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +36 -11
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +74 -12
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/RpcDataSource.cjs.map +1 -1
- package/dist/data-sources/RpcDataSource.d.cts +0 -7
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
- package/dist/data-sources/RpcDataSource.d.mts +0 -7
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs +27 -35
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.cts.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.mts.map +1 -1
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.mjs +27 -35
- package/dist/data-sources/evm-rpc-services/clients/MulticallClient.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +10 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +10 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -5,48 +5,50 @@ import type { KeyringControllerLockEvent, KeyringControllerUnlockEvent } from "@
|
|
|
5
5
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
6
6
|
import type { Messenger } from "@metamask/messenger";
|
|
7
7
|
import type { NetworkEnablementControllerGetStateAction, NetworkEnablementControllerEvents } from "@metamask/network-enablement-controller";
|
|
8
|
-
import type { Json } from "@metamask/utils";
|
|
9
8
|
import type { AccountsApiDataSourceGetAssetsMiddlewareAction } from "./data-sources/AccountsApiDataSource.mjs";
|
|
10
9
|
import type { PriceDataSourceGetAssetsMiddlewareAction, PriceDataSourceFetchAction, PriceDataSourceSubscribeAction, PriceDataSourceUnsubscribeAction } from "./data-sources/PriceDataSource.mjs";
|
|
11
10
|
import type { RpcDataSourceGetAssetsMiddlewareAction } from "./data-sources/RpcDataSource.mjs";
|
|
12
11
|
import type { SnapDataSourceGetAssetsMiddlewareAction } from "./data-sources/SnapDataSource.mjs";
|
|
13
12
|
import type { TokenDataSourceGetAssetsMiddlewareAction } from "./data-sources/TokenDataSource.mjs";
|
|
14
13
|
import type { DetectionMiddlewareGetAssetsMiddlewareAction } from "./middlewares/DetectionMiddleware.mjs";
|
|
15
|
-
import type { AccountId, ChainId, Caip19AssetId, AssetMetadata, AssetPrice, AssetBalance, AssetType, DataType, DataResponse, DataSourceDefinition, Asset } from "./types.mjs";
|
|
14
|
+
import type { AccountId, AssetPreferences, ChainId, Caip19AssetId, AssetMetadata, AssetPrice, AssetBalance, AssetType, DataType, DataResponse, DataSourceDefinition, Asset } from "./types.mjs";
|
|
16
15
|
declare const CONTROLLER_NAME: "AssetsController";
|
|
17
16
|
/**
|
|
18
17
|
* State structure for AssetsController.
|
|
19
18
|
*
|
|
20
|
-
* All values are JSON-serializable.
|
|
21
|
-
*
|
|
22
|
-
* conform to AssetMetadata, AssetPrice, and AssetBalance interfaces.
|
|
19
|
+
* All values are JSON-serializable. UI preferences (e.g. hidden) are in
|
|
20
|
+
* assetPreferences, not in metadata.
|
|
23
21
|
*
|
|
24
22
|
* @see AssetsControllerStateInternal for the semantic type structure
|
|
25
23
|
*/
|
|
26
24
|
export type AssetsControllerState = {
|
|
27
25
|
/** Shared metadata for all assets (stored once per asset) */
|
|
28
26
|
assetsMetadata: {
|
|
29
|
-
[assetId: string]:
|
|
27
|
+
[assetId: string]: AssetMetadata;
|
|
30
28
|
};
|
|
31
29
|
/** Per-account balance data */
|
|
32
30
|
assetsBalance: {
|
|
33
31
|
[accountId: string]: {
|
|
34
|
-
[assetId: string]:
|
|
32
|
+
[assetId: string]: AssetBalance;
|
|
35
33
|
};
|
|
36
34
|
};
|
|
37
35
|
/** Price data for assets */
|
|
38
36
|
assetsPrice: {
|
|
39
|
-
[assetId: string]:
|
|
37
|
+
[assetId: string]: AssetPrice;
|
|
40
38
|
};
|
|
41
39
|
/** Custom assets added by users per account (CAIP-19 asset IDs) */
|
|
42
40
|
customAssets: {
|
|
43
|
-
[accountId: string]:
|
|
41
|
+
[accountId: string]: Caip19AssetId[];
|
|
42
|
+
};
|
|
43
|
+
/** UI preferences per asset (e.g. hidden) */
|
|
44
|
+
assetPreferences: {
|
|
45
|
+
[assetId: string]: AssetPreferences;
|
|
44
46
|
};
|
|
45
47
|
};
|
|
46
48
|
/**
|
|
47
49
|
* Returns the default state for AssetsController.
|
|
48
50
|
*
|
|
49
|
-
* @returns The default AssetsController state with empty
|
|
51
|
+
* @returns The default AssetsController state with empty maps.
|
|
50
52
|
*/
|
|
51
53
|
export declare function getDefaultAssetsControllerState(): AssetsControllerState;
|
|
52
54
|
export type AssetsControllerGetStateAction = ControllerGetStateAction<typeof CONTROLLER_NAME, AssetsControllerState>;
|
|
@@ -86,7 +88,15 @@ export type AssetsControllerGetCustomAssetsAction = {
|
|
|
86
88
|
type: `${typeof CONTROLLER_NAME}:getCustomAssets`;
|
|
87
89
|
handler: AssetsController['getCustomAssets'];
|
|
88
90
|
};
|
|
89
|
-
export type
|
|
91
|
+
export type AssetsControllerHideAssetAction = {
|
|
92
|
+
type: `${typeof CONTROLLER_NAME}:hideAsset`;
|
|
93
|
+
handler: AssetsController['hideAsset'];
|
|
94
|
+
};
|
|
95
|
+
export type AssetsControllerUnhideAssetAction = {
|
|
96
|
+
type: `${typeof CONTROLLER_NAME}:unhideAsset`;
|
|
97
|
+
handler: AssetsController['unhideAsset'];
|
|
98
|
+
};
|
|
99
|
+
export type AssetsControllerActions = AssetsControllerGetStateAction | AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction | AssetsControllerGetAssetsPriceAction | AssetsControllerActiveChainsUpdateAction | AssetsControllerAssetsUpdateAction | AssetsControllerAddCustomAssetAction | AssetsControllerRemoveCustomAssetAction | AssetsControllerGetCustomAssetsAction | AssetsControllerHideAssetAction | AssetsControllerUnhideAssetAction;
|
|
90
100
|
export type AssetsControllerStateChangeEvent = ControllerStateChangeEvent<typeof CONTROLLER_NAME, AssetsControllerState>;
|
|
91
101
|
export type AssetsControllerBalanceChangedEvent = {
|
|
92
102
|
type: `${typeof CONTROLLER_NAME}:balanceChanged`;
|
|
@@ -211,6 +221,7 @@ export declare class AssetsController extends BaseController<typeof CONTROLLER_N
|
|
|
211
221
|
/**
|
|
212
222
|
* Add a custom asset for an account.
|
|
213
223
|
* Custom assets are included in subscription and fetch operations.
|
|
224
|
+
* Adding a custom asset also unhides it if it was previously hidden.
|
|
214
225
|
*
|
|
215
226
|
* @param accountId - The account ID to add the custom asset for.
|
|
216
227
|
* @param assetId - The CAIP-19 asset ID to add.
|
|
@@ -230,6 +241,20 @@ export declare class AssetsController extends BaseController<typeof CONTROLLER_N
|
|
|
230
241
|
* @returns Array of CAIP-19 asset IDs for the account's custom assets.
|
|
231
242
|
*/
|
|
232
243
|
getCustomAssets(accountId: AccountId): Caip19AssetId[];
|
|
244
|
+
/**
|
|
245
|
+
* Hide an asset globally.
|
|
246
|
+
* Hidden assets are excluded from the asset list returned by getAssets.
|
|
247
|
+
* The hidden state is stored in assetPreferences.
|
|
248
|
+
*
|
|
249
|
+
* @param assetId - The CAIP-19 asset ID to hide.
|
|
250
|
+
*/
|
|
251
|
+
hideAsset(assetId: Caip19AssetId): void;
|
|
252
|
+
/**
|
|
253
|
+
* Unhide an asset globally.
|
|
254
|
+
*
|
|
255
|
+
* @param assetId - The CAIP-19 asset ID to unhide.
|
|
256
|
+
*/
|
|
257
|
+
unhideAsset(assetId: Caip19AssetId): void;
|
|
233
258
|
/**
|
|
234
259
|
* Subscribe to price updates for all assets held by the given accounts.
|
|
235
260
|
* Polls PriceDataSource which fetches prices from balance state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController.d.mts","sourceRoot":"","sources":["../src/AssetsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8DAA8D,EAC9D,oDAAoD,EACrD,0CAA0C;AAC3C,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,yCAAyC,EACzC,iCAAiC,EAElC,gDAAgD;
|
|
1
|
+
{"version":3,"file":"AssetsController.d.mts","sourceRoot":"","sources":["../src/AssetsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8DAA8D,EAC9D,oDAAoD,EACrD,0CAA0C;AAC3C,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,yCAAyC,EACzC,iCAAiC,EAElC,gDAAgD;AAMjD,OAAO,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EAAE,UAAU,CAAC,CAAC;IAyB7C;;;;;;;OAOG;IACG,cAAc,CAClB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC;IAqChB;;;;;OAKG;IACH,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAmBrE;;;;;OAKG;IACH,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,aAAa,EAAE;IAQtD;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAavC;;;;OAIG;IACH,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IA8DzC;;;;;;;;OAQG;IACH,oBAAoB,CAClB,QAAQ,EAAE,eAAe,EAAE,EAC3B,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAO,GACxC,IAAI;IAmCP;;OAEG;IACH,sBAAsB,IAAI,IAAI;IAypB9B;;;;;;OAMG;IACG,kBAAkB,CACtB,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IA8ChB,OAAO,IAAI,IAAI;CA6BhB"}
|
|
@@ -28,7 +28,7 @@ const log = createModuleLogger(projectLogger, CONTROLLER_NAME);
|
|
|
28
28
|
/**
|
|
29
29
|
* Returns the default state for AssetsController.
|
|
30
30
|
*
|
|
31
|
-
* @returns The default AssetsController state with empty
|
|
31
|
+
* @returns The default AssetsController state with empty maps.
|
|
32
32
|
*/
|
|
33
33
|
export function getDefaultAssetsControllerState() {
|
|
34
34
|
return {
|
|
@@ -36,6 +36,7 @@ export function getDefaultAssetsControllerState() {
|
|
|
36
36
|
assetsBalance: {},
|
|
37
37
|
assetsPrice: {},
|
|
38
38
|
customAssets: {},
|
|
39
|
+
assetPreferences: {},
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
42
|
// ============================================================================
|
|
@@ -66,6 +67,12 @@ const stateMetadata = {
|
|
|
66
67
|
includeInDebugSnapshot: false,
|
|
67
68
|
usedInUi: true,
|
|
68
69
|
},
|
|
70
|
+
assetPreferences: {
|
|
71
|
+
persist: true,
|
|
72
|
+
includeInStateLogs: false,
|
|
73
|
+
includeInDebugSnapshot: false,
|
|
74
|
+
usedInUi: true,
|
|
75
|
+
},
|
|
69
76
|
};
|
|
70
77
|
// ============================================================================
|
|
71
78
|
// HELPER FUNCTIONS
|
|
@@ -348,6 +355,7 @@ export class AssetsController extends BaseController {
|
|
|
348
355
|
/**
|
|
349
356
|
* Add a custom asset for an account.
|
|
350
357
|
* Custom assets are included in subscription and fetch operations.
|
|
358
|
+
* Adding a custom asset also unhides it if it was previously hidden.
|
|
351
359
|
*
|
|
352
360
|
* @param accountId - The account ID to add the custom asset for.
|
|
353
361
|
* @param assetId - The CAIP-19 asset ID to add.
|
|
@@ -364,6 +372,14 @@ export class AssetsController extends BaseController {
|
|
|
364
372
|
if (!customAssets[accountId].includes(normalizedAssetId)) {
|
|
365
373
|
customAssets[accountId].push(normalizedAssetId);
|
|
366
374
|
}
|
|
375
|
+
// Unhide the asset if it was hidden (via assetPreferences)
|
|
376
|
+
const prefs = state.assetPreferences[normalizedAssetId];
|
|
377
|
+
if (prefs?.hidden) {
|
|
378
|
+
delete prefs.hidden;
|
|
379
|
+
if (Object.keys(prefs).length === 0) {
|
|
380
|
+
delete state.assetPreferences[normalizedAssetId];
|
|
381
|
+
}
|
|
382
|
+
}
|
|
367
383
|
});
|
|
368
384
|
// Fetch data for the newly added custom asset
|
|
369
385
|
const account = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).find((a) => a.id === accountId);
|
|
@@ -385,12 +401,11 @@ export class AssetsController extends BaseController {
|
|
|
385
401
|
const normalizedAssetId = normalizeAssetId(assetId);
|
|
386
402
|
log('Removing custom asset', { accountId, assetId: normalizedAssetId });
|
|
387
403
|
this.update((state) => {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
customAssets[accountId] = customAssets[accountId].filter((id) => id !== normalizedAssetId);
|
|
404
|
+
if (state.customAssets[accountId]) {
|
|
405
|
+
state.customAssets[accountId] = state.customAssets[accountId].filter((id) => id !== normalizedAssetId);
|
|
391
406
|
// Clean up empty arrays
|
|
392
|
-
if (customAssets[accountId].length === 0) {
|
|
393
|
-
delete customAssets[accountId];
|
|
407
|
+
if (state.customAssets[accountId].length === 0) {
|
|
408
|
+
delete state.customAssets[accountId];
|
|
394
409
|
}
|
|
395
410
|
}
|
|
396
411
|
});
|
|
@@ -402,7 +417,45 @@ export class AssetsController extends BaseController {
|
|
|
402
417
|
* @returns Array of CAIP-19 asset IDs for the account's custom assets.
|
|
403
418
|
*/
|
|
404
419
|
getCustomAssets(accountId) {
|
|
405
|
-
return
|
|
420
|
+
return this.state.customAssets[accountId] ?? [];
|
|
421
|
+
}
|
|
422
|
+
// ============================================================================
|
|
423
|
+
// HIDDEN ASSETS MANAGEMENT
|
|
424
|
+
// ============================================================================
|
|
425
|
+
/**
|
|
426
|
+
* Hide an asset globally.
|
|
427
|
+
* Hidden assets are excluded from the asset list returned by getAssets.
|
|
428
|
+
* The hidden state is stored in assetPreferences.
|
|
429
|
+
*
|
|
430
|
+
* @param assetId - The CAIP-19 asset ID to hide.
|
|
431
|
+
*/
|
|
432
|
+
hideAsset(assetId) {
|
|
433
|
+
const normalizedAssetId = normalizeAssetId(assetId);
|
|
434
|
+
log('Hiding asset', { assetId: normalizedAssetId });
|
|
435
|
+
this.update((state) => {
|
|
436
|
+
if (!state.assetPreferences[normalizedAssetId]) {
|
|
437
|
+
state.assetPreferences[normalizedAssetId] = {};
|
|
438
|
+
}
|
|
439
|
+
state.assetPreferences[normalizedAssetId].hidden = true;
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Unhide an asset globally.
|
|
444
|
+
*
|
|
445
|
+
* @param assetId - The CAIP-19 asset ID to unhide.
|
|
446
|
+
*/
|
|
447
|
+
unhideAsset(assetId) {
|
|
448
|
+
const normalizedAssetId = normalizeAssetId(assetId);
|
|
449
|
+
log('Unhiding asset', { assetId: normalizedAssetId });
|
|
450
|
+
this.update((state) => {
|
|
451
|
+
const prefs = state.assetPreferences[normalizedAssetId];
|
|
452
|
+
if (prefs) {
|
|
453
|
+
delete prefs.hidden;
|
|
454
|
+
if (Object.keys(prefs).length === 0) {
|
|
455
|
+
delete state.assetPreferences[normalizedAssetId];
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
});
|
|
406
459
|
}
|
|
407
460
|
/**
|
|
408
461
|
* Subscribe to price updates for all assets held by the given accounts.
|
|
@@ -495,6 +548,8 @@ export class AssetsController extends BaseController {
|
|
|
495
548
|
this.messenger.unregisterActionHandler('AssetsController:addCustomAsset');
|
|
496
549
|
this.messenger.unregisterActionHandler('AssetsController:removeCustomAsset');
|
|
497
550
|
this.messenger.unregisterActionHandler('AssetsController:getCustomAssets');
|
|
551
|
+
this.messenger.unregisterActionHandler('AssetsController:hideAsset');
|
|
552
|
+
this.messenger.unregisterActionHandler('AssetsController:unhideAsset');
|
|
498
553
|
}
|
|
499
554
|
}
|
|
500
555
|
_AssetsController_isEnabled = new WeakMap(), _AssetsController_defaultUpdateInterval = new WeakMap(), _AssetsController_controllerMutex = new WeakMap(), _AssetsController_activeSubscriptions = new WeakMap(), _AssetsController_enabledChains = new WeakMap(), _AssetsController_dataSources = new WeakMap(), _AssetsController_instances = new WeakSet(), _AssetsController_selectedAccounts_get = function _AssetsController_selectedAccounts_get() {
|
|
@@ -556,6 +611,8 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_defaultUpdateInte
|
|
|
556
611
|
this.messenger.registerActionHandler('AssetsController:addCustomAsset', this.addCustomAsset.bind(this));
|
|
557
612
|
this.messenger.registerActionHandler('AssetsController:removeCustomAsset', this.removeCustomAsset.bind(this));
|
|
558
613
|
this.messenger.registerActionHandler('AssetsController:getCustomAssets', this.getCustomAssets.bind(this));
|
|
614
|
+
this.messenger.registerActionHandler('AssetsController:hideAsset', this.hideAsset.bind(this));
|
|
615
|
+
this.messenger.registerActionHandler('AssetsController:unhideAsset', this.unhideAsset.bind(this));
|
|
559
616
|
}, _AssetsController_executeMiddlewares =
|
|
560
617
|
// ============================================================================
|
|
561
618
|
// MIDDLEWARE EXECUTION
|
|
@@ -627,7 +684,7 @@ async function _AssetsController_updateState(response) {
|
|
|
627
684
|
const changedBalances = [];
|
|
628
685
|
const changedMetadata = [];
|
|
629
686
|
this.update((state) => {
|
|
630
|
-
// Use type assertions to avoid deep type instantiation issues with Draft
|
|
687
|
+
// Use type assertions to avoid deep type instantiation issues with Immer Draft types
|
|
631
688
|
const metadata = state.assetsMetadata;
|
|
632
689
|
const balances = state.assetsBalance;
|
|
633
690
|
const prices = state.assetsPrice;
|
|
@@ -738,16 +795,21 @@ async function _AssetsController_updateState(response) {
|
|
|
738
795
|
const accountBalances = this.state.assetsBalance[account.id] ?? {};
|
|
739
796
|
for (const [assetId, balance] of Object.entries(accountBalances)) {
|
|
740
797
|
const typedAssetId = assetId;
|
|
741
|
-
const assetChainId = extractChainId(typedAssetId);
|
|
742
|
-
if (!chainIdSet.has(assetChainId)) {
|
|
743
|
-
continue;
|
|
744
|
-
}
|
|
745
798
|
const metadataRaw = this.state.assetsMetadata[typedAssetId];
|
|
746
799
|
// Skip assets without metadata
|
|
747
800
|
if (!metadataRaw) {
|
|
748
801
|
continue;
|
|
749
802
|
}
|
|
750
803
|
const metadata = metadataRaw;
|
|
804
|
+
// Skip hidden assets (assetPreferences)
|
|
805
|
+
const prefs = this.state.assetPreferences[typedAssetId];
|
|
806
|
+
if (prefs?.hidden) {
|
|
807
|
+
continue;
|
|
808
|
+
}
|
|
809
|
+
const assetChainId = extractChainId(typedAssetId);
|
|
810
|
+
if (!chainIdSet.has(assetChainId)) {
|
|
811
|
+
continue;
|
|
812
|
+
}
|
|
751
813
|
// Filter by asset type
|
|
752
814
|
const tokenAssetType = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_tokenStandardToAssetType).call(this, metadata.type);
|
|
753
815
|
if (!assetTypeSet.has(tokenAssetType)) {
|