@metamask-previews/assets-controller 0.2.0-preview-c3cd77f → 0.2.0-preview-d01b2f93d
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 +4 -0
- package/dist/AssetsController-method-action-types.cjs +7 -0
- package/dist/AssetsController-method-action-types.cjs.map +1 -0
- package/dist/AssetsController-method-action-types.d.cts +78 -0
- package/dist/AssetsController-method-action-types.d.cts.map +1 -0
- package/dist/AssetsController-method-action-types.d.mts +78 -0
- package/dist/AssetsController-method-action-types.d.mts.map +1 -0
- package/dist/AssetsController-method-action-types.mjs +6 -0
- package/dist/AssetsController-method-action-types.mjs.map +1 -0
- package/dist/AssetsController.cjs +161 -116
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +23 -80
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +23 -80
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +161 -116
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AbstractDataSource.cjs.map +1 -1
- package/dist/data-sources/AbstractDataSource.d.cts +10 -1
- package/dist/data-sources/AbstractDataSource.d.cts.map +1 -1
- package/dist/data-sources/AbstractDataSource.d.mts +10 -1
- package/dist/data-sources/AbstractDataSource.d.mts.map +1 -1
- package/dist/data-sources/AbstractDataSource.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +23 -99
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.cts +5 -67
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.mts +5 -67
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.mjs +22 -97
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.cjs +135 -45
- package/dist/data-sources/BackendWebsocketDataSource.cjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.d.cts +19 -66
- package/dist/data-sources/BackendWebsocketDataSource.d.cts.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.d.mts +19 -66
- package/dist/data-sources/BackendWebsocketDataSource.d.mts.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.mjs +135 -45
- package/dist/data-sources/BackendWebsocketDataSource.mjs.map +1 -1
- package/dist/data-sources/PriceDataSource.cjs +22 -44
- package/dist/data-sources/PriceDataSource.cjs.map +1 -1
- package/dist/data-sources/PriceDataSource.d.cts +6 -89
- package/dist/data-sources/PriceDataSource.d.cts.map +1 -1
- package/dist/data-sources/PriceDataSource.d.mts +6 -89
- package/dist/data-sources/PriceDataSource.d.mts.map +1 -1
- package/dist/data-sources/PriceDataSource.mjs +22 -44
- package/dist/data-sources/PriceDataSource.mjs.map +1 -1
- package/dist/data-sources/RpcDataSource.cjs +57 -98
- package/dist/data-sources/RpcDataSource.cjs.map +1 -1
- package/dist/data-sources/RpcDataSource.d.cts +16 -55
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
- package/dist/data-sources/RpcDataSource.d.mts +16 -55
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
- package/dist/data-sources/RpcDataSource.mjs +57 -98
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/data-sources/SnapDataSource.cjs +30 -30
- package/dist/data-sources/SnapDataSource.cjs.map +1 -1
- package/dist/data-sources/SnapDataSource.d.cts +7 -44
- package/dist/data-sources/SnapDataSource.d.cts.map +1 -1
- package/dist/data-sources/SnapDataSource.d.mts +7 -44
- package/dist/data-sources/SnapDataSource.d.mts.map +1 -1
- package/dist/data-sources/SnapDataSource.mjs +30 -30
- package/dist/data-sources/SnapDataSource.mjs.map +1 -1
- package/dist/data-sources/TokenDataSource.cjs +3 -16
- package/dist/data-sources/TokenDataSource.cjs.map +1 -1
- package/dist/data-sources/TokenDataSource.d.cts +2 -25
- package/dist/data-sources/TokenDataSource.d.cts.map +1 -1
- package/dist/data-sources/TokenDataSource.d.mts +2 -25
- package/dist/data-sources/TokenDataSource.d.mts.map +1 -1
- package/dist/data-sources/TokenDataSource.mjs +3 -16
- package/dist/data-sources/TokenDataSource.mjs.map +1 -1
- package/dist/data-sources/index.cjs +1 -6
- package/dist/data-sources/index.cjs.map +1 -1
- package/dist/data-sources/index.d.cts +6 -7
- package/dist/data-sources/index.d.cts.map +1 -1
- package/dist/data-sources/index.d.mts +6 -7
- package/dist/data-sources/index.d.mts.map +1 -1
- package/dist/data-sources/index.mjs +1 -3
- package/dist/data-sources/index.mjs.map +1 -1
- package/dist/index.cjs +1 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -11
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +9 -11
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- package/dist/middlewares/DetectionMiddleware.cjs +4 -27
- package/dist/middlewares/DetectionMiddleware.cjs.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.cts +3 -26
- package/dist/middlewares/DetectionMiddleware.d.cts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.mts +3 -26
- package/dist/middlewares/DetectionMiddleware.d.mts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.mjs +4 -27
- package/dist/middlewares/DetectionMiddleware.mjs.map +1 -1
- package/dist/middlewares/index.cjs.map +1 -1
- package/dist/middlewares/index.d.cts +1 -1
- package/dist/middlewares/index.d.cts.map +1 -1
- package/dist/middlewares/index.d.mts +1 -1
- package/dist/middlewares/index.d.mts.map +1 -1
- package/dist/middlewares/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +52 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +52 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/data-sources/initDataSources.cjs +0 -215
- package/dist/data-sources/initDataSources.cjs.map +0 -1
- package/dist/data-sources/initDataSources.d.cts +0 -140
- package/dist/data-sources/initDataSources.d.cts.map +0 -1
- package/dist/data-sources/initDataSources.d.mts +0 -140
- package/dist/data-sources/initDataSources.d.mts.map +0 -1
- package/dist/data-sources/initDataSources.mjs +0 -210
- package/dist/data-sources/initDataSources.mjs.map +0 -1
|
@@ -9,12 +9,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _RpcDataSource_instances, _RpcDataSource_timeout, _RpcDataSource_tokenDetectionEnabled, _RpcDataSource_activeChains, _RpcDataSource_chainStatuses, _RpcDataSource_providerCache, _RpcDataSource_activeSubscriptions, _RpcDataSource_multicallClient, _RpcDataSource_balanceFetcher, _RpcDataSource_tokenDetector, _RpcDataSource_convertToHumanReadable, _RpcDataSource_collectMetadataForBalances, _RpcDataSource_handleBalanceUpdate, _RpcDataSource_handleDetectionUpdate,
|
|
12
|
+
var _RpcDataSource_instances, _RpcDataSource_messenger, _RpcDataSource_onActiveChainsUpdated, _RpcDataSource_timeout, _RpcDataSource_tokenDetectionEnabled, _RpcDataSource_activeChains, _RpcDataSource_chainStatuses, _RpcDataSource_providerCache, _RpcDataSource_activeSubscriptions, _RpcDataSource_multicallClient, _RpcDataSource_balanceFetcher, _RpcDataSource_tokenDetector, _RpcDataSource_convertToHumanReadable, _RpcDataSource_collectMetadataForBalances, _RpcDataSource_handleBalanceUpdate, _RpcDataSource_handleDetectionUpdate, _RpcDataSource_subscribeToNetworkController, _RpcDataSource_initializeFromNetworkController, _RpcDataSource_updateFromNetworkState, _RpcDataSource_getProvider, _RpcDataSource_getMulticallProvider, _RpcDataSource_clearProviderCache, _RpcDataSource_buildNativeAssetId, _RpcDataSource_getExistingAssetsMetadata, _RpcDataSource_getTokenMetadataFromTokenList;
|
|
13
13
|
import { Web3Provider } from "@ethersproject/providers";
|
|
14
|
-
import { BaseController } from "@metamask/base-controller";
|
|
15
14
|
import { toHex } from "@metamask/controller-utils";
|
|
16
15
|
import { isStrictHexString, isCaipChainId, parseCaipChainId } from "@metamask/utils";
|
|
17
16
|
import BigNumberJS from "bignumber.js";
|
|
17
|
+
import { AbstractDataSource } from "./AbstractDataSource.mjs";
|
|
18
18
|
import { BalanceFetcher, MulticallClient, TokenDetector } from "./evm-rpc-services/index.mjs";
|
|
19
19
|
import { projectLogger, createModuleLogger } from "../logger.mjs";
|
|
20
20
|
const CONTROLLER_NAME = 'RpcDataSource';
|
|
@@ -54,15 +54,12 @@ export const caipChainIdToHex = (chainId) => {
|
|
|
54
54
|
* - RpcDataSource:activeChainsUpdated
|
|
55
55
|
* - RpcDataSource:assetsUpdated
|
|
56
56
|
*/
|
|
57
|
-
export class RpcDataSource extends
|
|
57
|
+
export class RpcDataSource extends AbstractDataSource {
|
|
58
58
|
constructor(options) {
|
|
59
|
-
super({
|
|
60
|
-
name: CONTROLLER_NAME,
|
|
61
|
-
metadata: {},
|
|
62
|
-
state: {},
|
|
63
|
-
messenger: options.messenger,
|
|
64
|
-
});
|
|
59
|
+
super(CONTROLLER_NAME, { activeChains: [] });
|
|
65
60
|
_RpcDataSource_instances.add(this);
|
|
61
|
+
_RpcDataSource_messenger.set(this, void 0);
|
|
62
|
+
_RpcDataSource_onActiveChainsUpdated.set(this, void 0);
|
|
66
63
|
_RpcDataSource_timeout.set(this, void 0);
|
|
67
64
|
_RpcDataSource_tokenDetectionEnabled.set(this, void 0);
|
|
68
65
|
/** Currently active chains */
|
|
@@ -77,6 +74,8 @@ export class RpcDataSource extends BaseController {
|
|
|
77
74
|
_RpcDataSource_multicallClient.set(this, void 0);
|
|
78
75
|
_RpcDataSource_balanceFetcher.set(this, void 0);
|
|
79
76
|
_RpcDataSource_tokenDetector.set(this, void 0);
|
|
77
|
+
__classPrivateFieldSet(this, _RpcDataSource_messenger, options.messenger, "f");
|
|
78
|
+
__classPrivateFieldSet(this, _RpcDataSource_onActiveChainsUpdated, options.onActiveChainsUpdated, "f");
|
|
80
79
|
__classPrivateFieldSet(this, _RpcDataSource_timeout, options.timeout ?? 10000, "f");
|
|
81
80
|
__classPrivateFieldSet(this, _RpcDataSource_tokenDetectionEnabled, options.tokenDetectionEnabled ?? false, "f");
|
|
82
81
|
const balanceInterval = options.balanceInterval ?? DEFAULT_BALANCE_INTERVAL;
|
|
@@ -94,7 +93,7 @@ export class RpcDataSource extends BaseController {
|
|
|
94
93
|
// Create messenger adapters for BalanceFetcher and TokenDetector
|
|
95
94
|
const balanceFetcherMessenger = {
|
|
96
95
|
call: (_action) => {
|
|
97
|
-
const state = this.
|
|
96
|
+
const state = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('AssetsController:getState');
|
|
98
97
|
return {
|
|
99
98
|
assetsBalance: (state.assetsBalance ?? {}),
|
|
100
99
|
};
|
|
@@ -102,7 +101,7 @@ export class RpcDataSource extends BaseController {
|
|
|
102
101
|
};
|
|
103
102
|
const tokenDetectorMessenger = {
|
|
104
103
|
call: (_action) => {
|
|
105
|
-
return this.
|
|
104
|
+
return __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('TokenListController:getState');
|
|
106
105
|
},
|
|
107
106
|
};
|
|
108
107
|
// Initialize BalanceFetcher with polling interval
|
|
@@ -111,7 +110,6 @@ export class RpcDataSource extends BaseController {
|
|
|
111
110
|
// Initialize TokenDetector with polling interval
|
|
112
111
|
__classPrivateFieldSet(this, _RpcDataSource_tokenDetector, new TokenDetector(__classPrivateFieldGet(this, _RpcDataSource_multicallClient, "f"), tokenDetectorMessenger, { pollingInterval: detectionInterval }), "f");
|
|
113
112
|
__classPrivateFieldGet(this, _RpcDataSource_tokenDetector, "f").setOnDetectionUpdate(__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_handleDetectionUpdate).bind(this));
|
|
114
|
-
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_registerActionHandlers).call(this);
|
|
115
113
|
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_subscribeToNetworkController).call(this);
|
|
116
114
|
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_initializeFromNetworkController).call(this);
|
|
117
115
|
}
|
|
@@ -120,17 +118,6 @@ export class RpcDataSource extends BaseController {
|
|
|
120
118
|
*
|
|
121
119
|
* @returns The name of this data source.
|
|
122
120
|
*/
|
|
123
|
-
getName() {
|
|
124
|
-
return this.name;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Get currently active chains.
|
|
128
|
-
*
|
|
129
|
-
* @returns Promise resolving to array of active chain IDs.
|
|
130
|
-
*/
|
|
131
|
-
async getActiveChains() {
|
|
132
|
-
return __classPrivateFieldGet(this, _RpcDataSource_activeChains, "f");
|
|
133
|
-
}
|
|
134
121
|
/**
|
|
135
122
|
* Get the status of all configured chains.
|
|
136
123
|
*
|
|
@@ -186,7 +173,7 @@ export class RpcDataSource extends BaseController {
|
|
|
186
173
|
const response = {};
|
|
187
174
|
const chainsToFetch = request.chainIds.filter((chainId) => __classPrivateFieldGet(this, _RpcDataSource_activeChains, "f").includes(chainId));
|
|
188
175
|
log('Fetch requested', {
|
|
189
|
-
accounts: request.
|
|
176
|
+
accounts: request.accountsWithSupportedChains.map((a) => a.account.id),
|
|
190
177
|
requestedChains: request.chainIds,
|
|
191
178
|
chainsToFetch,
|
|
192
179
|
});
|
|
@@ -197,14 +184,15 @@ export class RpcDataSource extends BaseController {
|
|
|
197
184
|
const assetsBalance = {};
|
|
198
185
|
const assetsMetadata = {};
|
|
199
186
|
const failedChains = [];
|
|
200
|
-
// Fetch balances for each
|
|
201
|
-
for (const
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
187
|
+
// Fetch balances for each account and its supported chains (pre-computed in request)
|
|
188
|
+
for (const { account, supportedChains, } of request.accountsWithSupportedChains) {
|
|
189
|
+
const chainsForAccount = chainsToFetch.filter((chain) => supportedChains.includes(chain));
|
|
190
|
+
if (chainsForAccount.length === 0) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const { address, id: accountId } = account;
|
|
194
|
+
for (const chainId of chainsForAccount) {
|
|
195
|
+
const hexChainId = caipChainIdToHex(chainId);
|
|
208
196
|
try {
|
|
209
197
|
// Use BalanceFetcher for batched balance fetching
|
|
210
198
|
const result = await __classPrivateFieldGet(this, _RpcDataSource_balanceFetcher, "f").fetchBalancesForTokens(hexChainId, accountId, address, [], // Empty array means just native token
|
|
@@ -352,7 +340,7 @@ export class RpcDataSource extends BaseController {
|
|
|
352
340
|
let successfullyHandledChains = [];
|
|
353
341
|
log('Middleware fetching', {
|
|
354
342
|
chains: supportedChains,
|
|
355
|
-
accounts: request.
|
|
343
|
+
accounts: request.accountsWithSupportedChains.map((a) => a.account.id),
|
|
356
344
|
});
|
|
357
345
|
const response = await this.fetch({
|
|
358
346
|
...request,
|
|
@@ -402,7 +390,7 @@ export class RpcDataSource extends BaseController {
|
|
|
402
390
|
log('Subscribe requested', {
|
|
403
391
|
subscriptionId,
|
|
404
392
|
isUpdate,
|
|
405
|
-
accounts: request.
|
|
393
|
+
accounts: request.accountsWithSupportedChains.map((a) => a.account.id),
|
|
406
394
|
chainsToSubscribe,
|
|
407
395
|
});
|
|
408
396
|
if (chainsToSubscribe.length === 0) {
|
|
@@ -423,16 +411,17 @@ export class RpcDataSource extends BaseController {
|
|
|
423
411
|
}
|
|
424
412
|
// Clean up existing subscription (stops old polling)
|
|
425
413
|
await this.unsubscribe(subscriptionId);
|
|
426
|
-
// Start polling through BalanceFetcher and TokenDetector
|
|
414
|
+
// Start polling through BalanceFetcher and TokenDetector (use pre-computed supportedChains per account)
|
|
427
415
|
const balancePollingTokens = [];
|
|
428
416
|
const detectionPollingTokens = [];
|
|
429
|
-
for (const
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
417
|
+
for (const { account, supportedChains, } of request.accountsWithSupportedChains) {
|
|
418
|
+
const chainsForAccount = chainsToSubscribe.filter((chain) => supportedChains.includes(chain));
|
|
419
|
+
if (chainsForAccount.length === 0) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const { address, id: accountId } = account;
|
|
423
|
+
for (const chainId of chainsForAccount) {
|
|
424
|
+
const hexChainId = caipChainIdToHex(chainId);
|
|
436
425
|
// Start balance polling
|
|
437
426
|
const balanceInput = {
|
|
438
427
|
chainId: hexChainId,
|
|
@@ -454,11 +443,13 @@ export class RpcDataSource extends BaseController {
|
|
|
454
443
|
}
|
|
455
444
|
}
|
|
456
445
|
// Store subscription data
|
|
446
|
+
const accounts = request.accountsWithSupportedChains.map((entry) => entry.account);
|
|
457
447
|
__classPrivateFieldGet(this, _RpcDataSource_activeSubscriptions, "f").set(subscriptionId, {
|
|
458
448
|
balancePollingTokens,
|
|
459
449
|
detectionPollingTokens,
|
|
460
450
|
chains: chainsToSubscribe,
|
|
461
|
-
accounts
|
|
451
|
+
accounts,
|
|
452
|
+
onAssetsUpdate: subscriptionRequest.onAssetsUpdate,
|
|
462
453
|
});
|
|
463
454
|
log('Subscription SUCCESS', {
|
|
464
455
|
subscriptionId,
|
|
@@ -501,7 +492,7 @@ export class RpcDataSource extends BaseController {
|
|
|
501
492
|
__classPrivateFieldGet(this, _RpcDataSource_providerCache, "f").clear();
|
|
502
493
|
}
|
|
503
494
|
}
|
|
504
|
-
_RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = new WeakMap(), _RpcDataSource_activeChains = new WeakMap(), _RpcDataSource_chainStatuses = new WeakMap(), _RpcDataSource_providerCache = new WeakMap(), _RpcDataSource_activeSubscriptions = new WeakMap(), _RpcDataSource_multicallClient = new WeakMap(), _RpcDataSource_balanceFetcher = new WeakMap(), _RpcDataSource_tokenDetector = new WeakMap(), _RpcDataSource_instances = new WeakSet(), _RpcDataSource_convertToHumanReadable = function _RpcDataSource_convertToHumanReadable(rawBalance, decimals) {
|
|
495
|
+
_RpcDataSource_messenger = new WeakMap(), _RpcDataSource_onActiveChainsUpdated = new WeakMap(), _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = new WeakMap(), _RpcDataSource_activeChains = new WeakMap(), _RpcDataSource_chainStatuses = new WeakMap(), _RpcDataSource_providerCache = new WeakMap(), _RpcDataSource_activeSubscriptions = new WeakMap(), _RpcDataSource_multicallClient = new WeakMap(), _RpcDataSource_balanceFetcher = new WeakMap(), _RpcDataSource_tokenDetector = new WeakMap(), _RpcDataSource_instances = new WeakSet(), _RpcDataSource_convertToHumanReadable = function _RpcDataSource_convertToHumanReadable(rawBalance, decimals) {
|
|
505
496
|
const rawAmount = new BigNumberJS(rawBalance);
|
|
506
497
|
const divisor = new BigNumberJS(10).pow(decimals);
|
|
507
498
|
return rawAmount.dividedBy(divisor).toString();
|
|
@@ -577,11 +568,11 @@ _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = n
|
|
|
577
568
|
accountId: result.accountId,
|
|
578
569
|
newBalanceCount: Object.keys(newBalances).length,
|
|
579
570
|
});
|
|
580
|
-
this.
|
|
581
|
-
.
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
}
|
|
571
|
+
for (const subscription of __classPrivateFieldGet(this, _RpcDataSource_activeSubscriptions, "f").values()) {
|
|
572
|
+
subscription.onAssetsUpdate(response)?.catch((error) => {
|
|
573
|
+
log('Failed to update assets', { error });
|
|
574
|
+
});
|
|
575
|
+
}
|
|
585
576
|
}, _RpcDataSource_handleDetectionUpdate = function _RpcDataSource_handleDetectionUpdate(result) {
|
|
586
577
|
log('Detected new tokens', {
|
|
587
578
|
count: result.detectedAssets.length,
|
|
@@ -627,24 +618,13 @@ _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = n
|
|
|
627
618
|
[result.accountId]: newBalances,
|
|
628
619
|
},
|
|
629
620
|
};
|
|
630
|
-
this.
|
|
631
|
-
.
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
}, _RpcDataSource_registerActionHandlers = function _RpcDataSource_registerActionHandlers() {
|
|
636
|
-
const getAssetsMiddlewareHandler = () => this.assetsMiddleware;
|
|
637
|
-
const getActiveChainsHandler = async () => this.getActiveChains();
|
|
638
|
-
const fetchHandler = async (request) => this.fetch(request);
|
|
639
|
-
const subscribeHandler = async (request) => this.subscribe(request);
|
|
640
|
-
const unsubscribeHandler = async (subscriptionId) => this.unsubscribe(subscriptionId);
|
|
641
|
-
this.messenger.registerActionHandler('RpcDataSource:getAssetsMiddleware', getAssetsMiddlewareHandler);
|
|
642
|
-
this.messenger.registerActionHandler('RpcDataSource:getActiveChains', getActiveChainsHandler);
|
|
643
|
-
this.messenger.registerActionHandler('RpcDataSource:fetch', fetchHandler);
|
|
644
|
-
this.messenger.registerActionHandler('RpcDataSource:subscribe', subscribeHandler);
|
|
645
|
-
this.messenger.registerActionHandler('RpcDataSource:unsubscribe', unsubscribeHandler);
|
|
621
|
+
for (const subscription of __classPrivateFieldGet(this, _RpcDataSource_activeSubscriptions, "f").values()) {
|
|
622
|
+
subscription.onAssetsUpdate(response)?.catch((error) => {
|
|
623
|
+
log('Failed to update detected assets', { error });
|
|
624
|
+
});
|
|
625
|
+
}
|
|
646
626
|
}, _RpcDataSource_subscribeToNetworkController = function _RpcDataSource_subscribeToNetworkController() {
|
|
647
|
-
this.
|
|
627
|
+
__classPrivateFieldGet(this, _RpcDataSource_messenger, "f").subscribe('NetworkController:stateChange', (networkState) => {
|
|
648
628
|
log('NetworkController state changed');
|
|
649
629
|
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_clearProviderCache).call(this);
|
|
650
630
|
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_updateFromNetworkState).call(this, networkState);
|
|
@@ -652,7 +632,7 @@ _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = n
|
|
|
652
632
|
}, _RpcDataSource_initializeFromNetworkController = function _RpcDataSource_initializeFromNetworkController() {
|
|
653
633
|
log('Initializing from NetworkController');
|
|
654
634
|
try {
|
|
655
|
-
const networkState = this.
|
|
635
|
+
const networkState = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('NetworkController:getState');
|
|
656
636
|
__classPrivateFieldGet(this, _RpcDataSource_instances, "m", _RpcDataSource_updateFromNetworkState).call(this, networkState);
|
|
657
637
|
}
|
|
658
638
|
catch (error) {
|
|
@@ -695,8 +675,9 @@ _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = n
|
|
|
695
675
|
__classPrivateFieldSet(this, _RpcDataSource_chainStatuses, chainStatuses, "f");
|
|
696
676
|
__classPrivateFieldSet(this, _RpcDataSource_activeChains, activeChains, "f");
|
|
697
677
|
if (hasChanges) {
|
|
698
|
-
this.
|
|
678
|
+
__classPrivateFieldGet(this, _RpcDataSource_onActiveChainsUpdated, "f").call(this, activeChains);
|
|
699
679
|
}
|
|
680
|
+
this.state.activeChains = activeChains;
|
|
700
681
|
}, _RpcDataSource_getProvider = function _RpcDataSource_getProvider(chainId) {
|
|
701
682
|
const cached = __classPrivateFieldGet(this, _RpcDataSource_providerCache, "f").get(chainId);
|
|
702
683
|
if (cached) {
|
|
@@ -707,7 +688,10 @@ _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = n
|
|
|
707
688
|
return undefined;
|
|
708
689
|
}
|
|
709
690
|
try {
|
|
710
|
-
const networkClient = this.
|
|
691
|
+
const networkClient = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('NetworkController:getNetworkClientById', chainStatus.networkClientId);
|
|
692
|
+
if (!networkClient?.provider) {
|
|
693
|
+
return undefined;
|
|
694
|
+
}
|
|
711
695
|
const web3Provider = new Web3Provider(networkClient.provider);
|
|
712
696
|
__classPrivateFieldGet(this, _RpcDataSource_providerCache, "f").set(chainId, web3Provider);
|
|
713
697
|
return web3Provider;
|
|
@@ -737,38 +721,13 @@ _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = n
|
|
|
737
721
|
};
|
|
738
722
|
}, _RpcDataSource_clearProviderCache = function _RpcDataSource_clearProviderCache() {
|
|
739
723
|
__classPrivateFieldGet(this, _RpcDataSource_providerCache, "f").clear();
|
|
740
|
-
}, _RpcDataSource_accountSupportsChain = function _RpcDataSource_accountSupportsChain(account, chainId) {
|
|
741
|
-
const scopes = account.scopes ?? [];
|
|
742
|
-
if (scopes.length === 0) {
|
|
743
|
-
return true;
|
|
744
|
-
}
|
|
745
|
-
const [chainNamespace, chainReference] = chainId.split(':');
|
|
746
|
-
for (const scope of scopes) {
|
|
747
|
-
const [scopeNamespace, scopeReference] = scope.split(':');
|
|
748
|
-
if (scopeNamespace !== chainNamespace) {
|
|
749
|
-
continue;
|
|
750
|
-
}
|
|
751
|
-
// Wildcard scope (e.g., eip155:0) matches all chains in the namespace
|
|
752
|
-
if (scopeReference === '0') {
|
|
753
|
-
return true;
|
|
754
|
-
}
|
|
755
|
-
// RpcDataSource only handles eip155 (EVM) chains
|
|
756
|
-
// Normalize hex chain references (e.g., 0x1 -> 1) for comparison
|
|
757
|
-
const normalizedScopeRef = scopeReference?.startsWith('0x')
|
|
758
|
-
? parseInt(scopeReference, 16).toString()
|
|
759
|
-
: scopeReference;
|
|
760
|
-
if (normalizedScopeRef === chainReference) {
|
|
761
|
-
return true;
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
return false;
|
|
765
724
|
}, _RpcDataSource_buildNativeAssetId = function _RpcDataSource_buildNativeAssetId(chainId) {
|
|
766
|
-
const { nativeAssetIdentifiers } = this.
|
|
725
|
+
const { nativeAssetIdentifiers } = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('NetworkEnablementController:getState');
|
|
767
726
|
return (nativeAssetIdentifiers[chainId] ??
|
|
768
727
|
`${chainId}/slip44:60`);
|
|
769
728
|
}, _RpcDataSource_getExistingAssetsMetadata = function _RpcDataSource_getExistingAssetsMetadata() {
|
|
770
729
|
try {
|
|
771
|
-
const state = this.
|
|
730
|
+
const state = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('AssetsController:getState');
|
|
772
731
|
return (state.assetsMetadata ?? {});
|
|
773
732
|
}
|
|
774
733
|
catch {
|
|
@@ -786,8 +745,8 @@ _RpcDataSource_timeout = new WeakMap(), _RpcDataSource_tokenDetectionEnabled = n
|
|
|
786
745
|
const tokenAddress = assetPart.slice(6); // Remove 'erc20:' prefix
|
|
787
746
|
const chainIdDecimal = chainPart.split(':')[1];
|
|
788
747
|
const hexChainId = `0x${parseInt(chainIdDecimal, 10).toString(16)}`;
|
|
789
|
-
const tokenListState = this.
|
|
790
|
-
const chainCacheEntry = tokenListState
|
|
748
|
+
const tokenListState = __classPrivateFieldGet(this, _RpcDataSource_messenger, "f").call('TokenListController:getState');
|
|
749
|
+
const chainCacheEntry = tokenListState?.tokensChainsCache?.[hexChainId];
|
|
791
750
|
const chainTokenList = chainCacheEntry?.data;
|
|
792
751
|
if (!chainTokenList) {
|
|
793
752
|
return undefined;
|