@metamask-previews/assets-controllers 93.1.0-preview-267e79c3 → 93.1.0-preview-d2037635
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 +8 -10
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs +14 -9
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.cts.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.mts.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.mjs +14 -9
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.mjs.map +1 -1
- package/dist/NftDetectionController.cjs +10 -6
- package/dist/NftDetectionController.cjs.map +1 -1
- package/dist/NftDetectionController.d.cts +4 -0
- package/dist/NftDetectionController.d.cts.map +1 -1
- package/dist/NftDetectionController.d.mts +4 -0
- package/dist/NftDetectionController.d.mts.map +1 -1
- package/dist/NftDetectionController.mjs +10 -6
- package/dist/NftDetectionController.mjs.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs +377 -376
- package/dist/TokenBalancesController.cjs.map +1 -1
- package/dist/TokenBalancesController.d.cts +40 -20
- package/dist/TokenBalancesController.d.cts.map +1 -1
- package/dist/TokenBalancesController.d.mts +40 -20
- package/dist/TokenBalancesController.d.mts.map +1 -1
- package/dist/TokenBalancesController.mjs +377 -376
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/TokenDetectionController.cjs +205 -44
- package/dist/TokenDetectionController.cjs.map +1 -1
- package/dist/TokenDetectionController.d.cts +10 -12
- package/dist/TokenDetectionController.d.cts.map +1 -1
- package/dist/TokenDetectionController.d.mts +10 -12
- package/dist/TokenDetectionController.d.mts.map +1 -1
- package/dist/TokenDetectionController.mjs +206 -45
- package/dist/TokenDetectionController.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/rpc-service/rpc-balance-fetcher.cjs +0 -4
- package/dist/rpc-service/rpc-balance-fetcher.cjs.map +1 -1
- package/dist/rpc-service/rpc-balance-fetcher.d.cts.map +1 -1
- package/dist/rpc-service/rpc-balance-fetcher.d.mts.map +1 -1
- package/dist/rpc-service/rpc-balance-fetcher.mjs +0 -4
- package/dist/rpc-service/rpc-balance-fetcher.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -20,7 +20,9 @@ export declare const STATIC_MAINNET_TOKEN_LIST: TokenDetectionMap;
|
|
|
20
20
|
* @param tokensChainsCache - TokensChainsCache input object
|
|
21
21
|
* @returns returns the map of chainId with TokenListMap
|
|
22
22
|
*/
|
|
23
|
-
export declare function mapChainIdWithTokenListMap(tokensChainsCache: TokensChainsCache):
|
|
23
|
+
export declare function mapChainIdWithTokenListMap(tokensChainsCache: TokensChainsCache): {
|
|
24
|
+
[x: `0x${string}`]: TokenListMap;
|
|
25
|
+
};
|
|
24
26
|
export declare const controllerName = "TokenDetectionController";
|
|
25
27
|
export type TokenDetectionState = Record<never, never>;
|
|
26
28
|
export type TokenDetectionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, TokenDetectionState>;
|
|
@@ -28,11 +30,7 @@ export type TokenDetectionControllerAddDetectedTokensViaWsAction = {
|
|
|
28
30
|
type: `TokenDetectionController:addDetectedTokensViaWs`;
|
|
29
31
|
handler: TokenDetectionController['addDetectedTokensViaWs'];
|
|
30
32
|
};
|
|
31
|
-
export type
|
|
32
|
-
type: `TokenDetectionController:detectTokens`;
|
|
33
|
-
handler: TokenDetectionController['detectTokens'];
|
|
34
|
-
};
|
|
35
|
-
export type TokenDetectionControllerActions = TokenDetectionControllerGetStateAction | TokenDetectionControllerAddDetectedTokensViaWsAction | TokenDetectionControllerDetectTokensAction;
|
|
33
|
+
export type TokenDetectionControllerActions = TokenDetectionControllerGetStateAction | TokenDetectionControllerAddDetectedTokensViaWsAction;
|
|
36
34
|
export type AllowedActions = AccountsControllerGetSelectedAccountAction | AccountsControllerGetAccountAction | NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetNetworkConfigurationByNetworkClientId | NetworkControllerGetStateAction | GetTokenListState | KeyringControllerGetStateAction | PreferencesControllerGetStateAction | TokensControllerGetStateAction | TokensControllerAddDetectedTokensAction | TokensControllerAddTokensAction | NetworkControllerFindNetworkClientIdByChainIdAction | AuthenticationController.AuthenticationControllerGetBearerToken;
|
|
37
35
|
export type TokenDetectionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, TokenDetectionState>;
|
|
38
36
|
export type TokenDetectionControllerEvents = TokenDetectionControllerStateChangeEvent;
|
|
@@ -85,10 +83,12 @@ export declare class TokenDetectionController extends TokenDetectionController_b
|
|
|
85
83
|
* @param options.interval - Polling interval used to fetch new token rates
|
|
86
84
|
* @param options.getBalancesInSingleCall - Gets the balances of a list of tokens for the given address.
|
|
87
85
|
* @param options.trackMetaMetricsEvent - Sets options for MetaMetrics event tracking.
|
|
86
|
+
* @param options.useAccountsAPI - Feature Switch for using the accounts API when detecting tokens (default: true)
|
|
88
87
|
* @param options.useTokenDetection - Feature Switch for using token detection (default: true)
|
|
89
88
|
* @param options.useExternalServices - Feature Switch for using external services (default: false)
|
|
89
|
+
* @param options.platform - Indicates whether the platform is extension or mobile
|
|
90
90
|
*/
|
|
91
|
-
constructor({ interval, disabled, getBalancesInSingleCall, trackMetaMetricsEvent, messenger, useTokenDetection, useExternalServices, }: {
|
|
91
|
+
constructor({ interval, disabled, getBalancesInSingleCall, trackMetaMetricsEvent, messenger, useAccountsAPI, useTokenDetection, useExternalServices, platform, }: {
|
|
92
92
|
interval?: number;
|
|
93
93
|
disabled?: boolean;
|
|
94
94
|
getBalancesInSingleCall: AssetsContractController['getBalancesInSingleCall'];
|
|
@@ -102,8 +102,10 @@ export declare class TokenDetectionController extends TokenDetectionController_b
|
|
|
102
102
|
};
|
|
103
103
|
}) => void;
|
|
104
104
|
messenger: TokenDetectionControllerMessenger;
|
|
105
|
+
useAccountsAPI?: boolean;
|
|
105
106
|
useTokenDetection?: () => boolean;
|
|
106
107
|
useExternalServices?: () => boolean;
|
|
108
|
+
platform: 'extension' | 'mobile';
|
|
107
109
|
});
|
|
108
110
|
/**
|
|
109
111
|
* Allows controller to make active and passive polling requests
|
|
@@ -135,14 +137,10 @@ export declare class TokenDetectionController extends TokenDetectionController_b
|
|
|
135
137
|
* @param options - Options for token detection.
|
|
136
138
|
* @param options.chainIds - The chain IDs of the network client to use.
|
|
137
139
|
* @param options.selectedAddress - the selectedAddress against which to detect for token balances.
|
|
138
|
-
* @param options.forceRpc - Force RPC-based token detection for all specified chains,
|
|
139
|
-
* bypassing external services check and ensuring RPC is used even for chains
|
|
140
|
-
* that might otherwise be handled by the Accounts API.
|
|
141
140
|
*/
|
|
142
|
-
detectTokens({ chainIds, selectedAddress,
|
|
141
|
+
detectTokens({ chainIds, selectedAddress, }?: {
|
|
143
142
|
chainIds?: Hex[];
|
|
144
143
|
selectedAddress?: string;
|
|
145
|
-
forceRpc?: boolean;
|
|
146
144
|
}): Promise<void>;
|
|
147
145
|
/**
|
|
148
146
|
* Add tokens detected from websocket balance updates
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenDetectionController.d.cts","sourceRoot":"","sources":["../src/TokenDetectionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0CAA0C,EAC1C,kCAAkC,EAClC,+CAA+C,EAChD,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;
|
|
1
|
+
{"version":3,"file":"TokenDetectionController.d.cts","sourceRoot":"","sources":["../src/TokenDetectionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0CAA0C,EAC1C,kCAAkC,EAClC,+CAA+C,EAChD,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAYnC,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAEV,mDAAmD,EACnD,2CAA2C,EAC3C,yDAAyD,EACzD,+BAA+B,EAC/B,sCAAsC,EACvC,qCAAqC;AAEtC,OAAO,KAAK,EACV,mCAAmC,EACnC,qCAAqC,EACtC,yCAAyC;AAC1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAClF,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AACvG,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAmC;AAM3E,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EAClB,kCAA8B;AAE/B,OAAO,KAAK,EACV,uCAAuC,EACvC,+BAA+B,EAC/B,8BAA8B,EAC/B,+BAA2B;AAc5B,KAAK,iBAAiB,GAAG;KACtB,CAAC,IAAI,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC;CAChE,CAAC;AAOF,eAAO,MAAM,yBAAyB,mBAahC,CAAC;AAEP;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,iBAAiB,EAAE,iBAAiB;;EAQrC;AAED,eAAO,MAAM,cAAc,6BAA6B,CAAC;AAEzD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAA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AsB,CAAC,EAC3B,WAAW,EACX,OAAO,GACR,EAAE;QACD,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,OAAO,EAAE,GAAG,CAAC;KACd,GAAG,OAAO,CAAC,IAAI,CAAC;CAwElB;AAED,eAAe,wBAAwB,CAAC"}
|
|
@@ -20,7 +20,9 @@ export declare const STATIC_MAINNET_TOKEN_LIST: TokenDetectionMap;
|
|
|
20
20
|
* @param tokensChainsCache - TokensChainsCache input object
|
|
21
21
|
* @returns returns the map of chainId with TokenListMap
|
|
22
22
|
*/
|
|
23
|
-
export declare function mapChainIdWithTokenListMap(tokensChainsCache: TokensChainsCache):
|
|
23
|
+
export declare function mapChainIdWithTokenListMap(tokensChainsCache: TokensChainsCache): {
|
|
24
|
+
[x: `0x${string}`]: TokenListMap;
|
|
25
|
+
};
|
|
24
26
|
export declare const controllerName = "TokenDetectionController";
|
|
25
27
|
export type TokenDetectionState = Record<never, never>;
|
|
26
28
|
export type TokenDetectionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, TokenDetectionState>;
|
|
@@ -28,11 +30,7 @@ export type TokenDetectionControllerAddDetectedTokensViaWsAction = {
|
|
|
28
30
|
type: `TokenDetectionController:addDetectedTokensViaWs`;
|
|
29
31
|
handler: TokenDetectionController['addDetectedTokensViaWs'];
|
|
30
32
|
};
|
|
31
|
-
export type
|
|
32
|
-
type: `TokenDetectionController:detectTokens`;
|
|
33
|
-
handler: TokenDetectionController['detectTokens'];
|
|
34
|
-
};
|
|
35
|
-
export type TokenDetectionControllerActions = TokenDetectionControllerGetStateAction | TokenDetectionControllerAddDetectedTokensViaWsAction | TokenDetectionControllerDetectTokensAction;
|
|
33
|
+
export type TokenDetectionControllerActions = TokenDetectionControllerGetStateAction | TokenDetectionControllerAddDetectedTokensViaWsAction;
|
|
36
34
|
export type AllowedActions = AccountsControllerGetSelectedAccountAction | AccountsControllerGetAccountAction | NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetNetworkConfigurationByNetworkClientId | NetworkControllerGetStateAction | GetTokenListState | KeyringControllerGetStateAction | PreferencesControllerGetStateAction | TokensControllerGetStateAction | TokensControllerAddDetectedTokensAction | TokensControllerAddTokensAction | NetworkControllerFindNetworkClientIdByChainIdAction | AuthenticationController.AuthenticationControllerGetBearerToken;
|
|
37
35
|
export type TokenDetectionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, TokenDetectionState>;
|
|
38
36
|
export type TokenDetectionControllerEvents = TokenDetectionControllerStateChangeEvent;
|
|
@@ -85,10 +83,12 @@ export declare class TokenDetectionController extends TokenDetectionController_b
|
|
|
85
83
|
* @param options.interval - Polling interval used to fetch new token rates
|
|
86
84
|
* @param options.getBalancesInSingleCall - Gets the balances of a list of tokens for the given address.
|
|
87
85
|
* @param options.trackMetaMetricsEvent - Sets options for MetaMetrics event tracking.
|
|
86
|
+
* @param options.useAccountsAPI - Feature Switch for using the accounts API when detecting tokens (default: true)
|
|
88
87
|
* @param options.useTokenDetection - Feature Switch for using token detection (default: true)
|
|
89
88
|
* @param options.useExternalServices - Feature Switch for using external services (default: false)
|
|
89
|
+
* @param options.platform - Indicates whether the platform is extension or mobile
|
|
90
90
|
*/
|
|
91
|
-
constructor({ interval, disabled, getBalancesInSingleCall, trackMetaMetricsEvent, messenger, useTokenDetection, useExternalServices, }: {
|
|
91
|
+
constructor({ interval, disabled, getBalancesInSingleCall, trackMetaMetricsEvent, messenger, useAccountsAPI, useTokenDetection, useExternalServices, platform, }: {
|
|
92
92
|
interval?: number;
|
|
93
93
|
disabled?: boolean;
|
|
94
94
|
getBalancesInSingleCall: AssetsContractController['getBalancesInSingleCall'];
|
|
@@ -102,8 +102,10 @@ export declare class TokenDetectionController extends TokenDetectionController_b
|
|
|
102
102
|
};
|
|
103
103
|
}) => void;
|
|
104
104
|
messenger: TokenDetectionControllerMessenger;
|
|
105
|
+
useAccountsAPI?: boolean;
|
|
105
106
|
useTokenDetection?: () => boolean;
|
|
106
107
|
useExternalServices?: () => boolean;
|
|
108
|
+
platform: 'extension' | 'mobile';
|
|
107
109
|
});
|
|
108
110
|
/**
|
|
109
111
|
* Allows controller to make active and passive polling requests
|
|
@@ -135,14 +137,10 @@ export declare class TokenDetectionController extends TokenDetectionController_b
|
|
|
135
137
|
* @param options - Options for token detection.
|
|
136
138
|
* @param options.chainIds - The chain IDs of the network client to use.
|
|
137
139
|
* @param options.selectedAddress - the selectedAddress against which to detect for token balances.
|
|
138
|
-
* @param options.forceRpc - Force RPC-based token detection for all specified chains,
|
|
139
|
-
* bypassing external services check and ensuring RPC is used even for chains
|
|
140
|
-
* that might otherwise be handled by the Accounts API.
|
|
141
140
|
*/
|
|
142
|
-
detectTokens({ chainIds, selectedAddress,
|
|
141
|
+
detectTokens({ chainIds, selectedAddress, }?: {
|
|
143
142
|
chainIds?: Hex[];
|
|
144
143
|
selectedAddress?: string;
|
|
145
|
-
forceRpc?: boolean;
|
|
146
144
|
}): Promise<void>;
|
|
147
145
|
/**
|
|
148
146
|
* Add tokens detected from websocket balance updates
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenDetectionController.d.mts","sourceRoot":"","sources":["../src/TokenDetectionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0CAA0C,EAC1C,kCAAkC,EAClC,+CAA+C,EAChD,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;
|
|
1
|
+
{"version":3,"file":"TokenDetectionController.d.mts","sourceRoot":"","sources":["../src/TokenDetectionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0CAA0C,EAC1C,kCAAkC,EAClC,+CAA+C,EAChD,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAYnC,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAA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EAAE,MAAM,EAAE,CAAC;gBACjB,cAAc,EAAE,MAAM,CAAC;gBACvB,UAAU,EAAE,MAAM,CAAC;aACpB,CAAC;SACH,KAAK,IAAI,CAAC;QACX,SAAS,EAAE,iCAAiC,CAAC;QAC7C,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC;QAClC,mBAAmB,CAAC,EAAE,MAAM,OAAO,CAAC;QACpC,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;KAClC;IAsHD;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,OAAO,IAAI,IAAI;IAIf;;;;OAIG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAkFN,YAAY,CAAC,EACjB,QAAQ,EACR,OAAO,GACR,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC;IAiJ7C;;;;;;;OAOG;IACG,YAAY,CAAC,EACjB,QAAQ,EACR,eAAe,GAChB,GAAE;QACD,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QACjB,eAAe,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyWtB;;;;;;;;;;;OAWG;IACG,sBAAsB,CAAC,EAC3B,WAAW,EACX,OAAO,GACR,EAAE;QACD,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,OAAO,EAAE,GAAG,CAAC;KACd,GAAG,OAAO,CAAC,IAAI,CAAC;CAwElB;AAED,eAAe,wBAAwB,CAAC"}
|
|
@@ -9,7 +9,7 @@ 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 _TokenDetectionController_instances, _TokenDetectionController_intervalId, _TokenDetectionController_selectedAccountId, _TokenDetectionController_tokensChainsCache, _TokenDetectionController_disabled, _TokenDetectionController_isUnlocked, _TokenDetectionController_isDetectionEnabledFromPreferences, _TokenDetectionController_useTokenDetection, _TokenDetectionController_useExternalServices, _TokenDetectionController_getBalancesInSingleCall, _TokenDetectionController_trackMetaMetricsEvent, _TokenDetectionController_registerEventListeners, _TokenDetectionController_stopPolling, _TokenDetectionController_startPolling, _TokenDetectionController_compareTokensChainsCache, _TokenDetectionController_getCorrectNetworkClientIdByChainId, _TokenDetectionController_restartTokenDetection, _TokenDetectionController_shouldDetectTokens, _TokenDetectionController_detectTokensUsingRpc, _TokenDetectionController_getSlicesOfTokensToDetect, _TokenDetectionController_getConvertedStaticMainnetTokenList, _TokenDetectionController_addDetectedTokens, _TokenDetectionController_getSelectedAccount, _TokenDetectionController_getSelectedAddress;
|
|
12
|
+
var _TokenDetectionController_instances, _TokenDetectionController_intervalId, _TokenDetectionController_selectedAccountId, _TokenDetectionController_tokensChainsCache, _TokenDetectionController_disabled, _TokenDetectionController_isUnlocked, _TokenDetectionController_isDetectionEnabledFromPreferences, _TokenDetectionController_useTokenDetection, _TokenDetectionController_useExternalServices, _TokenDetectionController_getBalancesInSingleCall, _TokenDetectionController_trackMetaMetricsEvent, _TokenDetectionController_accountsAPI, _TokenDetectionController_registerEventListeners, _TokenDetectionController_stopPolling, _TokenDetectionController_startPolling, _TokenDetectionController_compareTokensChainsCache, _TokenDetectionController_getCorrectNetworkClientIdByChainId, _TokenDetectionController_restartTokenDetection, _TokenDetectionController_getChainsToDetect, _TokenDetectionController_attemptAccountAPIDetection, _TokenDetectionController_addChainsToRpcDetection, _TokenDetectionController_shouldDetectTokens, _TokenDetectionController_detectTokensUsingRpc, _TokenDetectionController_getSlicesOfTokensToDetect, _TokenDetectionController_getConvertedStaticMainnetTokenList, _TokenDetectionController_addDetectedTokensViaAPI, _TokenDetectionController_filterAndBuildTokensWithBalance, _TokenDetectionController_addDetectedTokens, _TokenDetectionController_getSelectedAccount, _TokenDetectionController_getSelectedAddress;
|
|
13
13
|
function $importDefault(module) {
|
|
14
14
|
if (module?.__esModule) {
|
|
15
15
|
return module.default;
|
|
@@ -18,13 +18,15 @@ function $importDefault(module) {
|
|
|
18
18
|
}
|
|
19
19
|
import $contractMap from "@metamask/contract-metadata";
|
|
20
20
|
const contractMap = $importDefault($contractMap);
|
|
21
|
-
import { ASSET_TYPES, ChainId, ERC20, safelyExecute, isEqualCaseInsensitive, toChecksumHexAddress } from "@metamask/controller-utils";
|
|
21
|
+
import { ASSET_TYPES, ChainId, ERC20, safelyExecute, safelyExecuteWithTimeout, isEqualCaseInsensitive, toChecksumHexAddress, toHex } from "@metamask/controller-utils";
|
|
22
22
|
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
23
|
+
import { hexToNumber } from "@metamask/utils";
|
|
23
24
|
import $lodash from "lodash";
|
|
24
25
|
const { isEqual, mapValues, isObject, get } = $lodash;
|
|
25
26
|
import { isTokenDetectionSupportedForNetwork } from "./assetsUtil.mjs";
|
|
26
|
-
import {
|
|
27
|
+
import { fetchMultiChainBalances, fetchSupportedNetworks } from "./multi-chain-accounts-service/index.mjs";
|
|
27
28
|
const DEFAULT_INTERVAL = 180000;
|
|
29
|
+
const ACCOUNTS_API_TIMEOUT_MS = 10000;
|
|
28
30
|
export const STATIC_MAINNET_TOKEN_LIST = Object.entries(contractMap).reduce((acc, [base, contract]) => {
|
|
29
31
|
const { logo, erc20, erc721, ...tokenMetadata } = contract;
|
|
30
32
|
return {
|
|
@@ -78,10 +80,12 @@ export class TokenDetectionController extends StaticIntervalPollingController()
|
|
|
78
80
|
* @param options.interval - Polling interval used to fetch new token rates
|
|
79
81
|
* @param options.getBalancesInSingleCall - Gets the balances of a list of tokens for the given address.
|
|
80
82
|
* @param options.trackMetaMetricsEvent - Sets options for MetaMetrics event tracking.
|
|
83
|
+
* @param options.useAccountsAPI - Feature Switch for using the accounts API when detecting tokens (default: true)
|
|
81
84
|
* @param options.useTokenDetection - Feature Switch for using token detection (default: true)
|
|
82
85
|
* @param options.useExternalServices - Feature Switch for using external services (default: false)
|
|
86
|
+
* @param options.platform - Indicates whether the platform is extension or mobile
|
|
83
87
|
*/
|
|
84
|
-
constructor({ interval = DEFAULT_INTERVAL, disabled = true, getBalancesInSingleCall, trackMetaMetricsEvent, messenger, useTokenDetection = () => true, useExternalServices = () => true, }) {
|
|
88
|
+
constructor({ interval = DEFAULT_INTERVAL, disabled = true, getBalancesInSingleCall, trackMetaMetricsEvent, messenger, useAccountsAPI = true, useTokenDetection = () => true, useExternalServices = () => true, platform, }) {
|
|
85
89
|
super({
|
|
86
90
|
name: controllerName,
|
|
87
91
|
messenger,
|
|
@@ -99,8 +103,38 @@ export class TokenDetectionController extends StaticIntervalPollingController()
|
|
|
99
103
|
_TokenDetectionController_useExternalServices.set(this, void 0);
|
|
100
104
|
_TokenDetectionController_getBalancesInSingleCall.set(this, void 0);
|
|
101
105
|
_TokenDetectionController_trackMetaMetricsEvent.set(this, void 0);
|
|
106
|
+
_TokenDetectionController_accountsAPI.set(this, {
|
|
107
|
+
isAccountsAPIEnabled: true,
|
|
108
|
+
supportedNetworksCache: null,
|
|
109
|
+
platform: '',
|
|
110
|
+
async getSupportedNetworks() {
|
|
111
|
+
/* istanbul ignore next */
|
|
112
|
+
if (!this.isAccountsAPIEnabled) {
|
|
113
|
+
throw new Error('Accounts API Feature Switch is disabled');
|
|
114
|
+
}
|
|
115
|
+
/* istanbul ignore next */
|
|
116
|
+
if (this.supportedNetworksCache) {
|
|
117
|
+
return this.supportedNetworksCache;
|
|
118
|
+
}
|
|
119
|
+
const result = await fetchSupportedNetworks().catch(() => null);
|
|
120
|
+
this.supportedNetworksCache = result;
|
|
121
|
+
return result;
|
|
122
|
+
},
|
|
123
|
+
async getMultiNetworksBalances(address, chainIds, supportedNetworks, jwtToken) {
|
|
124
|
+
const chainIdNumbers = chainIds.map((chainId) => hexToNumber(chainId));
|
|
125
|
+
if (!supportedNetworks ||
|
|
126
|
+
!chainIdNumbers.every((id) => supportedNetworks.includes(id))) {
|
|
127
|
+
const supportedNetworksErrStr = (supportedNetworks ?? []).toString();
|
|
128
|
+
throw new Error(`Unsupported Network: supported networks ${supportedNetworksErrStr}, requested networks: ${chainIdNumbers.toString()}`);
|
|
129
|
+
}
|
|
130
|
+
const result = await fetchMultiChainBalances(address, {
|
|
131
|
+
networks: chainIdNumbers,
|
|
132
|
+
}, this.platform, jwtToken);
|
|
133
|
+
// Return the full response including unprocessedNetworks
|
|
134
|
+
return result;
|
|
135
|
+
},
|
|
136
|
+
});
|
|
102
137
|
this.messenger.registerActionHandler(`${controllerName}:addDetectedTokensViaWs`, this.addDetectedTokensViaWs.bind(this));
|
|
103
|
-
this.messenger.registerActionHandler(`${controllerName}:detectTokens`, this.detectTokens.bind(this));
|
|
104
138
|
__classPrivateFieldSet(this, _TokenDetectionController_disabled, disabled, "f");
|
|
105
139
|
this.setIntervalLength(interval);
|
|
106
140
|
__classPrivateFieldSet(this, _TokenDetectionController_selectedAccountId, __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getSelectedAccount).call(this).id, "f");
|
|
@@ -112,8 +146,10 @@ export class TokenDetectionController extends StaticIntervalPollingController()
|
|
|
112
146
|
__classPrivateFieldSet(this, _TokenDetectionController_trackMetaMetricsEvent, trackMetaMetricsEvent, "f");
|
|
113
147
|
const { isUnlocked } = this.messenger.call('KeyringController:getState');
|
|
114
148
|
__classPrivateFieldSet(this, _TokenDetectionController_isUnlocked, isUnlocked, "f");
|
|
149
|
+
__classPrivateFieldGet(this, _TokenDetectionController_accountsAPI, "f").isAccountsAPIEnabled = useAccountsAPI;
|
|
115
150
|
__classPrivateFieldSet(this, _TokenDetectionController_useTokenDetection, useTokenDetection, "f");
|
|
116
151
|
__classPrivateFieldSet(this, _TokenDetectionController_useExternalServices, useExternalServices, "f");
|
|
152
|
+
__classPrivateFieldGet(this, _TokenDetectionController_accountsAPI, "f").platform = platform;
|
|
117
153
|
__classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_registerEventListeners).call(this);
|
|
118
154
|
}
|
|
119
155
|
/**
|
|
@@ -166,33 +202,43 @@ export class TokenDetectionController extends StaticIntervalPollingController()
|
|
|
166
202
|
* @param options - Options for token detection.
|
|
167
203
|
* @param options.chainIds - The chain IDs of the network client to use.
|
|
168
204
|
* @param options.selectedAddress - the selectedAddress against which to detect for token balances.
|
|
169
|
-
* @param options.forceRpc - Force RPC-based token detection for all specified chains,
|
|
170
|
-
* bypassing external services check and ensuring RPC is used even for chains
|
|
171
|
-
* that might otherwise be handled by the Accounts API.
|
|
172
205
|
*/
|
|
173
|
-
async detectTokens({ chainIds, selectedAddress,
|
|
206
|
+
async detectTokens({ chainIds, selectedAddress, } = {}) {
|
|
174
207
|
if (!this.isActive) {
|
|
175
208
|
return;
|
|
176
209
|
}
|
|
177
|
-
|
|
178
|
-
if (!forceRpc && !__classPrivateFieldGet(this, _TokenDetectionController_useTokenDetection, "f").call(this)) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
// If external services are disabled and not forcing RPC, skip all detection
|
|
182
|
-
if (!forceRpc && !__classPrivateFieldGet(this, _TokenDetectionController_useExternalServices, "f").call(this)) {
|
|
210
|
+
if (!__classPrivateFieldGet(this, _TokenDetectionController_useTokenDetection, "f").call(this)) {
|
|
183
211
|
return;
|
|
184
212
|
}
|
|
185
213
|
const addressToDetect = selectedAddress ?? __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getSelectedAddress).call(this);
|
|
186
214
|
const clientNetworks = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getCorrectNetworkClientIdByChainId).call(this, chainIds);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
215
|
+
const jwtToken = await safelyExecuteWithTimeout(() => {
|
|
216
|
+
return this.messenger.call('AuthenticationController:getBearerToken');
|
|
217
|
+
}, false, 5000);
|
|
218
|
+
let supportedNetworks;
|
|
219
|
+
if (__classPrivateFieldGet(this, _TokenDetectionController_accountsAPI, "f").isAccountsAPIEnabled && __classPrivateFieldGet(this, _TokenDetectionController_useExternalServices, "f").call(this)) {
|
|
220
|
+
supportedNetworks = await __classPrivateFieldGet(this, _TokenDetectionController_accountsAPI, "f").getSupportedNetworks();
|
|
221
|
+
}
|
|
222
|
+
const { chainsToDetectUsingRpc, chainsToDetectUsingAccountAPI } = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getChainsToDetect).call(this, clientNetworks, supportedNetworks);
|
|
223
|
+
// Try detecting tokens via Account API first if conditions allow
|
|
224
|
+
if (supportedNetworks && chainsToDetectUsingAccountAPI.length > 0) {
|
|
225
|
+
const apiResult = await __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_attemptAccountAPIDetection).call(this, chainsToDetectUsingAccountAPI, addressToDetect, supportedNetworks, jwtToken);
|
|
226
|
+
// If the account API call failed or returned undefined, have those chains fall back to RPC detection
|
|
227
|
+
if (!apiResult || apiResult.result === 'failed') {
|
|
228
|
+
__classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_addChainsToRpcDetection).call(this, chainsToDetectUsingRpc, chainsToDetectUsingAccountAPI, clientNetworks);
|
|
229
|
+
}
|
|
230
|
+
else if (apiResult?.result === 'success' &&
|
|
231
|
+
apiResult.unprocessedNetworks &&
|
|
232
|
+
apiResult.unprocessedNetworks.length > 0) {
|
|
233
|
+
// Handle unprocessed networks by adding them to RPC detection
|
|
234
|
+
const unprocessedChainIds = apiResult.unprocessedNetworks.map((chainId) => toHex(chainId));
|
|
235
|
+
__classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_addChainsToRpcDetection).call(this, chainsToDetectUsingRpc, unprocessedChainIds, clientNetworks);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// Proceed with RPC detection if there are chains remaining in chainsToDetectUsingRpc
|
|
239
|
+
if (chainsToDetectUsingRpc.length > 0) {
|
|
240
|
+
await __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_detectTokensUsingRpc).call(this, chainsToDetectUsingRpc, addressToDetect);
|
|
194
241
|
}
|
|
195
|
-
await __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_detectTokensUsingRpc).call(this, chainsToDetectUsingRpc, addressToDetect);
|
|
196
242
|
}
|
|
197
243
|
/**
|
|
198
244
|
* Add tokens detected from websocket balance updates
|
|
@@ -248,56 +294,46 @@ export class TokenDetectionController extends StaticIntervalPollingController()
|
|
|
248
294
|
}
|
|
249
295
|
}
|
|
250
296
|
}
|
|
251
|
-
_TokenDetectionController_intervalId = new WeakMap(), _TokenDetectionController_selectedAccountId = new WeakMap(), _TokenDetectionController_tokensChainsCache = new WeakMap(), _TokenDetectionController_disabled = new WeakMap(), _TokenDetectionController_isUnlocked = new WeakMap(), _TokenDetectionController_isDetectionEnabledFromPreferences = new WeakMap(), _TokenDetectionController_useTokenDetection = new WeakMap(), _TokenDetectionController_useExternalServices = new WeakMap(), _TokenDetectionController_getBalancesInSingleCall = new WeakMap(), _TokenDetectionController_trackMetaMetricsEvent = new WeakMap(), _TokenDetectionController_instances = new WeakSet(), _TokenDetectionController_registerEventListeners = function _TokenDetectionController_registerEventListeners() {
|
|
252
|
-
this.messenger.subscribe('KeyringController:unlock', () => {
|
|
297
|
+
_TokenDetectionController_intervalId = new WeakMap(), _TokenDetectionController_selectedAccountId = new WeakMap(), _TokenDetectionController_tokensChainsCache = new WeakMap(), _TokenDetectionController_disabled = new WeakMap(), _TokenDetectionController_isUnlocked = new WeakMap(), _TokenDetectionController_isDetectionEnabledFromPreferences = new WeakMap(), _TokenDetectionController_useTokenDetection = new WeakMap(), _TokenDetectionController_useExternalServices = new WeakMap(), _TokenDetectionController_getBalancesInSingleCall = new WeakMap(), _TokenDetectionController_trackMetaMetricsEvent = new WeakMap(), _TokenDetectionController_accountsAPI = new WeakMap(), _TokenDetectionController_instances = new WeakSet(), _TokenDetectionController_registerEventListeners = function _TokenDetectionController_registerEventListeners() {
|
|
298
|
+
this.messenger.subscribe('KeyringController:unlock', async () => {
|
|
253
299
|
__classPrivateFieldSet(this, _TokenDetectionController_isUnlocked, true, "f");
|
|
254
|
-
__classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this)
|
|
255
|
-
// Silently handle token detection errors
|
|
256
|
-
});
|
|
300
|
+
await __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this);
|
|
257
301
|
});
|
|
258
302
|
this.messenger.subscribe('KeyringController:lock', () => {
|
|
259
303
|
__classPrivateFieldSet(this, _TokenDetectionController_isUnlocked, false, "f");
|
|
260
304
|
__classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_stopPolling).call(this);
|
|
261
305
|
});
|
|
262
|
-
this.messenger.subscribe('TokenListController:stateChange', ({ tokensChainsCache }) => {
|
|
306
|
+
this.messenger.subscribe('TokenListController:stateChange', async ({ tokensChainsCache }) => {
|
|
263
307
|
const isEqualValues = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_compareTokensChainsCache).call(this, tokensChainsCache, __classPrivateFieldGet(this, _TokenDetectionController_tokensChainsCache, "f"));
|
|
264
308
|
if (!isEqualValues) {
|
|
265
|
-
__classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this)
|
|
266
|
-
// Silently handle token detection errors
|
|
267
|
-
});
|
|
309
|
+
await __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this);
|
|
268
310
|
}
|
|
269
311
|
});
|
|
270
|
-
this.messenger.subscribe('PreferencesController:stateChange', ({ useTokenDetection }) => {
|
|
312
|
+
this.messenger.subscribe('PreferencesController:stateChange', async ({ useTokenDetection }) => {
|
|
271
313
|
const selectedAccount = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getSelectedAccount).call(this);
|
|
272
314
|
const isDetectionChangedFromPreferences = __classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f") !== useTokenDetection;
|
|
273
315
|
__classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, useTokenDetection, "f");
|
|
274
316
|
if (isDetectionChangedFromPreferences) {
|
|
275
|
-
__classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
|
|
317
|
+
await __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
|
|
276
318
|
selectedAddress: selectedAccount.address,
|
|
277
|
-
}).catch(() => {
|
|
278
|
-
// Silently handle token detection errors
|
|
279
319
|
});
|
|
280
320
|
}
|
|
281
321
|
});
|
|
282
|
-
this.messenger.subscribe('AccountsController:selectedEvmAccountChange', (selectedAccount) => {
|
|
322
|
+
this.messenger.subscribe('AccountsController:selectedEvmAccountChange', async (selectedAccount) => {
|
|
283
323
|
const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
|
|
284
324
|
const chainIds = Object.keys(networkConfigurationsByChainId);
|
|
285
325
|
const isSelectedAccountIdChanged = __classPrivateFieldGet(this, _TokenDetectionController_selectedAccountId, "f") !== selectedAccount.id;
|
|
286
326
|
if (isSelectedAccountIdChanged) {
|
|
287
327
|
__classPrivateFieldSet(this, _TokenDetectionController_selectedAccountId, selectedAccount.id, "f");
|
|
288
|
-
__classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
|
|
328
|
+
await __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
|
|
289
329
|
selectedAddress: selectedAccount.address,
|
|
290
330
|
chainIds,
|
|
291
|
-
}).catch(() => {
|
|
292
|
-
// Silently handle token detection errors
|
|
293
331
|
});
|
|
294
332
|
}
|
|
295
333
|
});
|
|
296
|
-
this.messenger.subscribe('TransactionController:transactionConfirmed', (transactionMeta) => {
|
|
297
|
-
this.detectTokens({
|
|
334
|
+
this.messenger.subscribe('TransactionController:transactionConfirmed', async (transactionMeta) => {
|
|
335
|
+
await this.detectTokens({
|
|
298
336
|
chainIds: [transactionMeta.chainId],
|
|
299
|
-
}).catch(() => {
|
|
300
|
-
// Silently handle token detection errors
|
|
301
337
|
});
|
|
302
338
|
});
|
|
303
339
|
}, _TokenDetectionController_stopPolling = function _TokenDetectionController_stopPolling() {
|
|
@@ -358,6 +394,41 @@ async function _TokenDetectionController_restartTokenDetection({ selectedAddress
|
|
|
358
394
|
selectedAddress,
|
|
359
395
|
});
|
|
360
396
|
this.setIntervalLength(DEFAULT_INTERVAL);
|
|
397
|
+
}, _TokenDetectionController_getChainsToDetect = function _TokenDetectionController_getChainsToDetect(clientNetworks, supportedNetworks) {
|
|
398
|
+
const chainsToDetectUsingAccountAPI = [];
|
|
399
|
+
const chainsToDetectUsingRpc = [];
|
|
400
|
+
clientNetworks.forEach(({ chainId, networkClientId }) => {
|
|
401
|
+
if (supportedNetworks?.includes(hexToNumber(chainId))) {
|
|
402
|
+
chainsToDetectUsingAccountAPI.push(chainId);
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
chainsToDetectUsingRpc.push({ chainId, networkClientId });
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
return { chainsToDetectUsingRpc, chainsToDetectUsingAccountAPI };
|
|
409
|
+
}, _TokenDetectionController_attemptAccountAPIDetection = async function _TokenDetectionController_attemptAccountAPIDetection(chainsToDetectUsingAccountAPI, addressToDetect, supportedNetworks, jwtToken) {
|
|
410
|
+
const result = await safelyExecuteWithTimeout(async () => {
|
|
411
|
+
return __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_addDetectedTokensViaAPI).call(this, {
|
|
412
|
+
chainIds: chainsToDetectUsingAccountAPI,
|
|
413
|
+
selectedAddress: addressToDetect,
|
|
414
|
+
supportedNetworks,
|
|
415
|
+
jwtToken,
|
|
416
|
+
});
|
|
417
|
+
}, false, ACCOUNTS_API_TIMEOUT_MS);
|
|
418
|
+
if (!result) {
|
|
419
|
+
return { result: 'failed' };
|
|
420
|
+
}
|
|
421
|
+
return result;
|
|
422
|
+
}, _TokenDetectionController_addChainsToRpcDetection = function _TokenDetectionController_addChainsToRpcDetection(chainsToDetectUsingRpc, chainsToDetectUsingAccountAPI, clientNetworks) {
|
|
423
|
+
chainsToDetectUsingAccountAPI.forEach((chainId) => {
|
|
424
|
+
const networkEntry = clientNetworks.find((network) => network.chainId === chainId);
|
|
425
|
+
if (networkEntry) {
|
|
426
|
+
chainsToDetectUsingRpc.push({
|
|
427
|
+
chainId: networkEntry.chainId,
|
|
428
|
+
networkClientId: networkEntry.networkClientId,
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
});
|
|
361
432
|
}, _TokenDetectionController_shouldDetectTokens = function _TokenDetectionController_shouldDetectTokens(chainId) {
|
|
362
433
|
if (!isTokenDetectionSupportedForNetwork(chainId)) {
|
|
363
434
|
return false;
|
|
@@ -432,6 +503,96 @@ async function _TokenDetectionController_restartTokenDetection({ selectedAddress
|
|
|
432
503
|
timestamp: 0,
|
|
433
504
|
},
|
|
434
505
|
};
|
|
506
|
+
}, _TokenDetectionController_addDetectedTokensViaAPI =
|
|
507
|
+
/**
|
|
508
|
+
* This adds detected tokens from the Accounts API, avoiding the multi-call RPC calls for balances
|
|
509
|
+
*
|
|
510
|
+
* @param options - method arguments
|
|
511
|
+
* @param options.selectedAddress - address to check against
|
|
512
|
+
* @param options.chainIds - array of chainIds to check tokens for
|
|
513
|
+
* @param options.supportedNetworks - array of chainIds to check tokens for
|
|
514
|
+
* @param options.jwtToken - JWT token for authentication
|
|
515
|
+
* @returns a success or failed object
|
|
516
|
+
*/
|
|
517
|
+
async function _TokenDetectionController_addDetectedTokensViaAPI({ selectedAddress, chainIds, supportedNetworks, jwtToken, }) {
|
|
518
|
+
return await safelyExecute(async () => {
|
|
519
|
+
// Fetch balances for multiple chain IDs at once
|
|
520
|
+
const apiResponse = await __classPrivateFieldGet(this, _TokenDetectionController_accountsAPI, "f")
|
|
521
|
+
.getMultiNetworksBalances(selectedAddress, chainIds, supportedNetworks, jwtToken)
|
|
522
|
+
.catch(() => null);
|
|
523
|
+
if (apiResponse === null) {
|
|
524
|
+
return { result: 'failed' };
|
|
525
|
+
}
|
|
526
|
+
const tokenBalancesByChain = apiResponse.balances;
|
|
527
|
+
// Process each chain ID individually
|
|
528
|
+
for (const chainId of chainIds) {
|
|
529
|
+
const isTokenDetectionInactiveInMainnet = !__classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f") &&
|
|
530
|
+
chainId === ChainId.mainnet;
|
|
531
|
+
const { tokensChainsCache } = this.messenger.call('TokenListController:getState');
|
|
532
|
+
__classPrivateFieldSet(this, _TokenDetectionController_tokensChainsCache, isTokenDetectionInactiveInMainnet
|
|
533
|
+
? __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getConvertedStaticMainnetTokenList).call(this)
|
|
534
|
+
: (tokensChainsCache ?? {}), "f");
|
|
535
|
+
// Generate token candidates based on chainId and selectedAddress
|
|
536
|
+
const tokenCandidateSlices = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getSlicesOfTokensToDetect).call(this, {
|
|
537
|
+
chainId,
|
|
538
|
+
selectedAddress,
|
|
539
|
+
});
|
|
540
|
+
// Filter balances for the current chainId
|
|
541
|
+
const tokenBalances = tokenBalancesByChain.filter((balance) => balance.chainId === hexToNumber(chainId));
|
|
542
|
+
if (!tokenBalances || tokenBalances.length === 0) {
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
// Use helper function to filter tokens with balance for this chainId
|
|
546
|
+
const { tokensWithBalance, eventTokensDetails } = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_filterAndBuildTokensWithBalance).call(this, tokenCandidateSlices, tokenBalances, chainId);
|
|
547
|
+
if (tokensWithBalance.length) {
|
|
548
|
+
__classPrivateFieldGet(this, _TokenDetectionController_trackMetaMetricsEvent, "f").call(this, {
|
|
549
|
+
event: 'Token Detected',
|
|
550
|
+
category: 'Wallet',
|
|
551
|
+
properties: {
|
|
552
|
+
tokens: eventTokensDetails,
|
|
553
|
+
token_standard: ERC20,
|
|
554
|
+
asset_type: ASSET_TYPES.TOKEN,
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', chainId);
|
|
558
|
+
await this.messenger.call('TokensController:addTokens', tokensWithBalance, networkClientId);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
result: 'success',
|
|
563
|
+
unprocessedNetworks: apiResponse.unprocessedNetworks,
|
|
564
|
+
};
|
|
565
|
+
});
|
|
566
|
+
}, _TokenDetectionController_filterAndBuildTokensWithBalance = function _TokenDetectionController_filterAndBuildTokensWithBalance(tokenCandidateSlices, tokenBalances, chainId) {
|
|
567
|
+
const tokensWithBalance = [];
|
|
568
|
+
const eventTokensDetails = [];
|
|
569
|
+
const tokenCandidateSet = new Set(tokenCandidateSlices.flat());
|
|
570
|
+
tokenBalances?.forEach((token) => {
|
|
571
|
+
const tokenAddress = token.address;
|
|
572
|
+
// Make sure the token to add is in our candidate list
|
|
573
|
+
if (!tokenCandidateSet.has(tokenAddress)) {
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
// Retrieve token data from cache to safely add it
|
|
577
|
+
const tokenData = __classPrivateFieldGet(this, _TokenDetectionController_tokensChainsCache, "f")[chainId]?.data[tokenAddress];
|
|
578
|
+
// We need specific data from tokensChainsCache to correctly create a token
|
|
579
|
+
// So even if we have a token that was detected correctly by the API, if its missing data we cannot safely add it.
|
|
580
|
+
if (!tokenData) {
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
const { decimals, symbol, aggregators, iconUrl, name } = tokenData;
|
|
584
|
+
eventTokensDetails.push(`${symbol} - ${tokenAddress}`);
|
|
585
|
+
tokensWithBalance.push({
|
|
586
|
+
address: tokenAddress,
|
|
587
|
+
decimals,
|
|
588
|
+
symbol,
|
|
589
|
+
aggregators,
|
|
590
|
+
image: iconUrl,
|
|
591
|
+
isERC721: false,
|
|
592
|
+
name,
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
return { tokensWithBalance, eventTokensDetails };
|
|
435
596
|
}, _TokenDetectionController_addDetectedTokens = async function _TokenDetectionController_addDetectedTokens({ tokensSlice, selectedAddress, networkClientId, chainId, }) {
|
|
436
597
|
await safelyExecute(async () => {
|
|
437
598
|
const balances = await __classPrivateFieldGet(this, _TokenDetectionController_getBalancesInSingleCall, "f").call(this, selectedAddress, tokensSlice, networkClientId);
|
|
@@ -468,7 +629,7 @@ async function _TokenDetectionController_restartTokenDetection({ selectedAddress
|
|
|
468
629
|
}, _TokenDetectionController_getSelectedAddress = function _TokenDetectionController_getSelectedAddress() {
|
|
469
630
|
// If the address is not defined (or empty), we fallback to the currently selected account's address
|
|
470
631
|
const account = this.messenger.call('AccountsController:getAccount', __classPrivateFieldGet(this, _TokenDetectionController_selectedAccountId, "f"));
|
|
471
|
-
return account?.address
|
|
632
|
+
return account?.address || '';
|
|
472
633
|
};
|
|
473
634
|
export default TokenDetectionController;
|
|
474
635
|
//# sourceMappingURL=TokenDetectionController.mjs.map
|