@metamask-previews/assets-controllers 25.0.0-preview.8cdddaf → 25.0.0-preview.bc4dd941

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  # Changelog
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -6,14 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
7
 
7
8
  ## [Unreleased]
8
9
 
10
+ ### Added
11
+
12
+ - **BREAKING:** Adds `@metamask/accounts-controller` ^8.0.0 and `@metamask/keyring-controller` ^12.0.0 as dependencies and peer dependencies. ([#3775](https://github.com/MetaMask/core/pull/3775/)).
13
+ - **BREAKING:** `TokenDetectionController` newly subscribes to the `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`, `KeyringController:lock`, `KeyringController:unlock` events, and allows the `PreferencesController:getState` messenger action. ([#3775](https://github.com/MetaMask/core/pull/3775/))
14
+
15
+ ### Changed
16
+
17
+ - **BREAKING:** `TokenDetectionController` is merged with `DetectTokensController` from the `metamask-extension` repo. ([#3775](https://github.com/MetaMask/core/pull/3775/))
18
+ - **BREAKING:** `TokenDetectionController` now resets its polling interval to the default value of 3 minutes when token detection is triggered by external controller events `KeyringController:unlock`, `TokenListController:stateChange`, `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`.
19
+ - **BREAKING:** `TokenDetectionController` now refetches tokens on `NetworkController:networkDidChange` if the `networkClientId` is changed instead of `chainId`.
20
+ - **BREAKING:** `TokenDetectionController` cannot initiate polling or token detection if `KeyringController` state is locked.
21
+ - **BREAKING:** The `detectTokens` method now excludes tokens that are already included in the `TokensController`'s `detectedTokens` list from the batch of incoming tokens it sends to the `TokensController` `addDetectedTokens` method.
22
+ - **BREAKING:** The constructor for `TokenDetectionController` expects a new required proprerty `trackMetaMetricsEvent`, which defines the callback that is called in the `detectTokens` method.
23
+ - **BREAKING:** In Mainnet, even if the `PreferenceController`'s `useTokenDetection` option is set to false, automatic token detection is performed on the legacy token list (token data from the contract-metadata repo).
24
+
25
+ ### Removed
26
+
27
+ - **BREAKING:** `TokenDetectionController` constructor no longer accepts options `onPreferencesStateChange`, `getPreferencesState`. ([#3775](https://github.com/MetaMask/core/pull/3775/))
28
+ - **BREAKING:** `TokenDetectionController` no longer allows the `NetworkController:stateChange` event. The `NetworkController:networkDidChange` event can be used instead. ([#3775](https://github.com/MetaMask/core/pull/3775/))
29
+
9
30
  ## [25.0.0]
31
+
10
32
  ### Added
33
+
11
34
  - Add Linea to price api supported chains ([#3797](https://github.com/MetaMask/core/pull/3797))
12
35
 
13
36
  ### Changed
37
+
14
38
  - **BREAKING:** Convert `TokenBalancesController` to `BaseControllerV2` ([#3750](https://github.com/MetaMask/core/pull/3750))
15
- - The constructor parameters have changed; rather than accepting a "config" parameter for interval and tokens we now pass both values as controller options, and a "state" parameter, there is now just a single object for all constructor arguments. This object has a mandatory `messenger` and an optional `state`, `tokens`, `interval` properties a disabled property has also been added.
16
- - State now saves tokens balances as strings and not as a BNs.
39
+ - The constructor parameters have changed; rather than accepting a "config" parameter for interval and tokens we now pass both values as controller options, and a "state" parameter, there is now just a single object for all constructor arguments. This object has a mandatory `messenger` and an optional `state`, `tokens`, `interval` properties a disabled property has also been added.
40
+ - State now saves tokens balances as strings and not as a BNs.
17
41
  - Additional BN export has been removed as it was intended to be removed in the next major release.
18
42
  - **BREAKING:** Bump `@metamask/approval-controller` peer dependency to `^5.1.2` ([#3821](https://github.com/MetaMask/core/pull/3821))
19
43
  - **BREAKING:** Bump `@metamask/network-controller` peer dependency to `^17.2.0` ([#3821](https://github.com/MetaMask/core/pull/3821))
@@ -24,33 +48,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
24
48
  - Bump `@metamask/polling-controller` to `^5.0.0` ([#3821](https://github.com/MetaMask/core/pull/3821))
25
49
 
26
50
  ## [24.0.0]
51
+
27
52
  ### Added
53
+
28
54
  - Add `getDefaultTokenListState` function to `TokenListController` ([#3744](https://github.com/MetaMask/core/pull/3744))
29
55
  - Add `getDefaultNftState` function to the `NftController` ([#3742](https://github.com/MetaMask/core/pull/3742))
30
56
  - Add `getDefaultTokensState` function to the `TokensController` ([#3743](https://github.com/MetaMask/core/pull/3743))
31
57
 
32
58
  ### Changed
59
+
33
60
  - **BREAKING:** Bump `@metamask/preferences-controller` to ^6.0.0
34
61
  - Price API perf improvements ([#3753](https://github.com/MetaMask/core/pull/3753), [#3755](https://github.com/MetaMask/core/pull/3755))
35
62
  - Reduce token batch size from 100 to 30
36
63
  - Sort token addresses in query params for more cache hits
37
64
 
38
65
  ## [23.1.0]
66
+
39
67
  ### Added
68
+
40
69
  - Add support to `CodefiTokenPricesServiceV2` for tracking degraded service ([#3691](https://github.com/MetaMask/core/pull/3691))
41
70
  - The constructor has two new options: `onDegraded` and `degradedThreshold`. `onDegraded` is an event handler for instances of degraded service (i.e. failed or slow requests), and `degradedThreshold` determines how slow a request has to be before we consider service to be degraded.
42
71
 
43
72
  ## [23.0.0]
73
+
44
74
  ### Added
75
+
45
76
  - Add `onBreak` handler to `CodefiTokenPricesServiceV2` ([#3677](https://github.com/MetaMask/core/pull/3677))
46
77
  - This allows listening for "circuit breaks", which can indicate an outage. Useful for metrics.
47
78
  - Add `fetchTokenContractExchangeRates` utility method ([#3657](https://github.com/MetaMask/core/pull/3657))
48
79
  - `TokenListController` now exports a `TokenListControllerMessenger` type ([#3609](https://github.com/MetaMask/core/pull/3609)).
49
80
  - `TokenDetectionController` exports types `TokenDetectionControllerMessenger`, `TokenDetectionControllerActions`, `TokenDetectionControllerGetStateAction`, `TokenDetectionControllerEvents`, `TokenDetectionControllerStateChangeEvent` ([#3609](https://github.com/MetaMask/core/pull/3609)).
50
- - Add `enable` and `disable` methods to `TokenDetectionController`, which control whether the controller is able to make polling requests or all of its network calls are blocked. ([#3609](https://github.com/MetaMask/core/pull/3609)).
81
+ - Add `enable` and `disable` methods to `TokenDetectionController`, which control whether the controller is able to make polling requests or all of its network calls are blocked. ([#3609](https://github.com/MetaMask/core/pull/3609)).
51
82
  - Note that if the controller is initiated without the `disabled` constructor option set to `false`, the `enable` method will need to be called before the controller can make polling requests in response to subscribed events.
52
83
 
53
84
  ### Changed
85
+
54
86
  - **BREAKING:** Bump `@metamask/approval-controller` dependency and peer dependency from `^5.1.0` to `^5.1.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
55
87
  - **BREAKING:** Bump `@metamask/network-controller` dependency and peer dependency from `^17.0.0` to `^17.1.0` ([#3695](https://github.com/MetaMask/core/pull/3695))
56
88
  - **BREAKING:** Bump `@metamask/preferences-controller` dependency and peer dependency from `^5.0.0` to `^5.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
@@ -63,19 +95,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
63
95
  - Bump `@metamask/controller-utils` from `8.0.0` to `^8.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
64
96
 
65
97
  ### Fixed
98
+
66
99
  - Fix error caused by OpenSea API rename of `supply` to `total_supply` ([#3692](https://github.com/MetaMask/core/pull/3692))
67
100
  - Fix `CodefiTokenPricesServiceV2` support for Shiden ([#3683](https://github.com/MetaMask/core/pull/3683))
68
101
  - Improve how `CodefiTokenPricesServiceV2` handles token price update failures ([#3687](https://github.com/MetaMask/core/pull/3687))
69
102
  - Previously a single failed token price update would prevent all other token prices from updating as well. With this update, we log and error and continue when we fail to update a token price, ensuring the others still get updated.
70
103
 
71
104
  ## [22.0.0]
105
+
72
106
  ### Changed
107
+
73
108
  - **BREAKING:** OpenSea V2 API is used instead of V1 ([#3654](https://github.com/MetaMask/core/pull/3654))
74
- - `NftDetectionController` constructor now requires the `NftController.getNftApi` function.
109
+ - `NftDetectionController` constructor now requires the `NftController.getNftApi` function.
75
110
  - NFT controllers will no longer return `last_sale` information for NFTs fetched after the OpenSea V2 update
76
111
 
77
112
  ## [21.0.0]
113
+
78
114
  ### Added
115
+
79
116
  - Add `CodefiTokenPricesServiceV2` ([#3600](https://github.com/MetaMask/core/pull/3600), [#3655](https://github.com/MetaMask/core/pull/3655), [#3655](https://github.com/MetaMask/core/pull/3655))
80
117
  - This class can be used for the new `tokenPricesService` argument for TokenRatesController. It uses a MetaMask API to fetch prices for tokens instead of CoinGecko.
81
118
  - The `CodefiTokenPricesServiceV2` will retry if the token price update fails
@@ -90,6 +127,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
90
127
  - Support token detection on Arbitrum and Optimism ([#2035](https://github.com/MetaMask/core/pull/2035))
91
128
 
92
129
  ### Changed
130
+
93
131
  - **BREAKING:** `TokenRatesController` now takes a required argument `tokenPricesService` ([#3600](https://github.com/MetaMask/core/pull/3600))
94
132
  - This object is responsible for fetching the prices for tokens held by this controller.
95
133
  - **BREAKING:** Update signature of `TokenRatesController.updateExchangeRatesByChainId` ([#3600](https://github.com/MetaMask/core/pull/3600), [#3653](https://github.com/MetaMask/core/pull/3653))
@@ -123,6 +161,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
123
161
  - Add dependencies `cockatiel` and `lodash` ([#3586](https://github.com/MetaMask/core/pull/3586), [#3655](https://github.com/MetaMask/core/pull/3655))
124
162
 
125
163
  ### Removed
164
+
126
165
  - **BREAKING:** Remove `fetchExchangeRate` method from TokenRatesController ([#3600](https://github.com/MetaMask/core/pull/3600))
127
166
  - This method (not to be confused with `updateExchangeRate`, which is still present) was only ever intended to be used internally and should not be accessed directly.
128
167
  - **BREAKING:** Remove `getChainSlug` method from TokenRatesController ([#3600](https://github.com/MetaMask/core/pull/3600))
@@ -135,6 +174,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
135
174
  - **BREAKING**: `TokenRatesController.fetchAndMapExchangeRates` is no longer exposed publicly ([#3621](https://github.com/MetaMask/core/pull/3621))
136
175
 
137
176
  ### Fixed
177
+
138
178
  - Prevent `TokenRatesController` from making redundant token rate updates when tokens change ([#3647](https://github.com/MetaMask/core/pull/3647), [#3663](https://github.com/MetaMask/core/pull/3663))
139
179
  - Previously, token rates would be re-fetched for the globally selected network on all TokensController state changes, but now token rates are always performed for a deduplicated and normalized set of addresses, and changes to this set determine whether rates should be re-fetched.
140
180
  - Prevent redundant overlapping token rate updates in `TokenRatesController` ([#3635](https://github.com/MetaMask/core/pull/3635))
@@ -146,7 +186,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
146
186
  - This affects `watchNft` and `addNft` methods
147
187
 
148
188
  ## [20.0.0]
189
+
149
190
  ### Added
191
+
150
192
  - **BREAKING**: `TokenRatesControllerState` now has required `contractExchangeRatesByChainId` property which an object keyed by `chainId` and `nativeCurrency` ([#2015](https://github.com/MetaMask/core/pull/2015))
151
193
  - **BREAKING**: `TokenRatesController` constructor params now requires `getNetworkClientById` ([#2015](https://github.com/MetaMask/core/pull/2015))
152
194
  - Add types `CurrencyRateControllerEvents` and `CurrencyRateControllerActions` ([#2029](https://github.com/MetaMask/core/pull/2029))
@@ -163,6 +205,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
163
205
  - `TokenRatesController.fetchAndMapExchangeRates()` now accepts an optional `tokenAddresses` as the last parameter ([#2015](https://github.com/MetaMask/core/pull/2015))
164
206
 
165
207
  ### Changed
208
+
166
209
  - **BREAKING:** Bump dependency on `@metamask/base-controller` to ^4.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
167
210
  - This is breaking because the type of the `messenger` has backward-incompatible changes. See the changelog for this package for more.
168
211
  - Bump `@metamask/approval-controller` to ^5.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
@@ -172,14 +215,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
172
215
  - Bump `@metamask/preferences-controller` to ^5.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
173
216
 
174
217
  ## [19.0.0]
218
+
175
219
  ### Changed
220
+
176
221
  - **BREAKING:** Bump dependency and peer dependency on `@metamask/network-controller` to ^16.0.0
177
222
  - Add optional `networkClientId` and `userAddress` args to remaining `NftController` public methods ([#2006](https://github.com/MetaMask/core/pull/2006))
178
223
  - `watchNft`, `removeNft`, `removeAndIgnoreNft`, `removeNftContract`, `updateNftFavoriteStatus`, and `checkAndUpdateAllNftsOwnershipStatus` methods on `NftController` all now accept an optional options object argument containing `networkClientId` and `userAddress` to identify where in state to mutate.
179
224
  - **BREAKING**: `addNft` no longer accepts a `chainId` property in its options argument since this value can be retrieved by the `networkClientId` property and is therefore redundant.
180
225
  - **BREAKING**: The third and fourth arguments on NftController's `addNftVerifyOwnership` method, have been replaced with an options object containing optional properties `networkClientId`, `userAddress` and `source`. This method signature is more aligned with the options pattern for passing `networkClientId` and `userAddress` on this controller and elsewhere.
181
226
  - **BREAKING**: `checkAndUpdateSingleNftOwnershipStatus` on NftController no longer accepts a `chainId` in its options argument. This is replaced with an optional `networkClientId` property which can be used to fetch chainId.
182
- ***BREAKING**: The fourth argument of the `isNftOwner` method on `NftController` is now an options object with an optional `networkClientId` property. This method signature is more aligned with the options pattern for passing `networkClientId` on this controller and elsewhere.
227
+ **\*BREAKING**: The fourth argument of the `isNftOwner` method on `NftController` is now an options object with an optional `networkClientId` property. This method signature is more aligned with the options pattern for passing `networkClientId` on this controller and elsewhere.
183
228
  - **BREAKING**: `validateWatchNft` method on `NftController` is now private.
184
229
  - **BREAKING**: `detectNfts` on `NftDetectionController` now accepts a single object argument with optional properties `networkClientId` and `userAddress`, rather than taking these as two sequential arguments.
185
230
  - Bump dependency `@metamask/eth-query` from ^3.0.1 to ^4.0.0 ([#2028](https://github.com/MetaMask/core/pull/2028))
@@ -187,10 +232,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
187
232
  - Bump `@metamask/utils` from 8.1.0 to 8.2.0 ([#1957](https://github.com/MetaMask/core/pull/1957))
188
233
 
189
234
  ### Fixed
235
+
190
236
  - Add name and symbol to the payload returned by the `ERC1155Standard` class `getDetails` method for `ERC1155` contracts ([#1727](https://github.com/MetaMask/core/pull/1727))
191
237
 
192
238
  ## [18.0.0]
239
+
193
240
  ### Changed
241
+
194
242
  - **BREAKING**: `CurrencyRateController` is now keyed by `nativeCurrency` (i.e. ticker) for `conversionDate`, `conversionRate`, and `usdConversionRate` in the `currencyRates` object. `nativeCurrency`, `pendingNativeCurrency`, and `pendingCurrentCurrency` have been removed.
195
243
  - ```
196
244
  export type CurrencyRateState = {
@@ -205,27 +253,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
205
253
  >;
206
254
  };
207
255
  ```
208
- - **BREAKING**: `CurrencyRateController` now extends `PollingController` ([#1805](https://github.com/MetaMask/core/pull/1805))
256
+ - **BREAKING**: `CurrencyRateController` now extends `PollingController` ([#1805](https://github.com/MetaMask/core/pull/1805))
209
257
  - `start()` and `stop()` methods replaced with `startPollingByNetworkClientId()`, `stopPollingByPollingToken()`, and `stopAllPolling()`
210
258
  - **BREAKING**: `CurrencyRateController` now sends the `NetworkController:getNetworkClientById` action via messaging controller ([#1805](https://github.com/MetaMask/core/pull/1805))
211
259
 
212
260
  ### Fixed
261
+
213
262
  - Parallelize network requests in assets controllers for performance enhancement ([#1801](https://github.com/MetaMask/core/pull/1801))
214
263
  - Fix token detection on accounts when user changes account after token detection request is inflight ([#1848](https://github.com/MetaMask/core/pull/1848))
215
264
 
216
265
  ## [17.0.0]
266
+
217
267
  ### Changed
268
+
218
269
  - **BREAKING:** Bump dependency on `@metamask/polling-controller` to ^1.0.0
219
270
  - Bump dependency and peer dependency on `@metamask/network-controller` to ^15.1.0
220
271
 
221
272
  ## [16.0.0]
273
+
222
274
  ### Added
275
+
223
276
  - Add way to start and stop different polling sessions for the same network client ID by providing extra scoping data ([#1776](https://github.com/MetaMask/core/pull/1776))
224
277
  - Add optional second argument to `stopPollingByPollingToken` (formerly `stopPollingByNetworkClientId`)
225
278
  - Add optional second argument to `onPollingCompleteByNetworkClientId`
226
279
  - Add support for token detection for Linea mainnet and Linea Goerli ([#1799](https://github.com/MetaMask/core/pull/1799))
227
280
 
228
281
  ### Changed
282
+
229
283
  - **BREAKING:** Bump dependency and peer dependency on `@metamask/network-controller` to ^15.0.0
230
284
  - **BREAKING:** Make `executePoll` in TokenListController private ([#1810](https://github.com/MetaMask/core/pull/1810))
231
285
  - **BREAKING:** Update TokenListController to rename `stopPollingByNetworkClientId` to `stopPollingByPollingToken` ([#1810](https://github.com/MetaMask/core/pull/1810))
@@ -235,7 +289,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
235
289
  - Fix support for NFT metadata stored outside IPFS ([#1772](https://github.com/MetaMask/core/pull/1772))
236
290
 
237
291
  ## [15.0.0]
292
+
238
293
  ### Changed
294
+
239
295
  - **BREAKING**: `NftController` now expects `getNetworkClientById` in constructor options ([#1698](https://github.com/MetaMask/core/pull/1698))
240
296
  - **BREAKING**: `NftController.addNft` function signature has changed ([#1698](https://github.com/MetaMask/core/pull/1698))
241
297
  - Previously
@@ -261,7 +317,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
261
317
  networkClientId?: NetworkClientId; // new
262
318
  },
263
319
  ```
264
- - `NftController.addNftVerifyOwnership`: Now accepts optional 3rd argument `networkClientId` which is used to fetch NFT metadata and determine by which chainId the added NFT should be stored in state. Also accepts optional 4th argument `source` used for metrics to identify the flow in which the NFT was added to the wallet. ([#1698](https://github.com/MetaMask/core/pull/1698))
320
+ - `NftController.addNftVerifyOwnership`: Now accepts optional 3rd argument `networkClientId` which is used to fetch NFT metadata and determine by which chainId the added NFT should be stored in state. Also accepts optional 4th argument `source` used for metrics to identify the flow in which the NFT was added to the wallet. ([#1698](https://github.com/MetaMask/core/pull/1698))
265
321
  - `NftController.isNftOwner`: Now accepts optional `networkClientId` which is used to instantiate the provider for the correct chain and call the NFT contract to verify ownership ([#1698](https://github.com/MetaMask/core/pull/1698))
266
322
  - `NftController.addNft` will use the chainId value derived from `networkClientId` if provided ([#1698](https://github.com/MetaMask/core/pull/1698))
267
323
  - `NftController.watchNft` options now accepts optional `networkClientId` which is used to fetch NFT metadata and determine by which chainId the added NFT should be stored in state ([#1698](https://github.com/MetaMask/core/pull/1698))
@@ -272,19 +328,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
272
328
  - Bump dependency and peer dependency on `@metamask/network-controller` to ^14.0.0
273
329
 
274
330
  ### Fixed
331
+
275
332
  - Fix bug in TokensController where batched `addToken` overwrote each other because mutex was acquired after reading state ([#1768](https://github.com/MetaMask/core/pull/1768))
276
333
 
277
334
  ## [14.0.0]
335
+
278
336
  ### Changed
337
+
279
338
  - Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
280
339
  - Update `@metamask/rpc-errors` to `^6.0.0` ([#1690](https://github.com/MetaMask/core/pull/1690))
281
340
 
282
341
  ### Removed
342
+
283
343
  - **BREAKING:** Remove AbortController polyfill
284
344
  - This package now assumes that the AbortController global exists
285
345
 
286
346
  ## [13.0.0]
347
+
287
348
  ### Changed
349
+
288
350
  - **BREAKING**: `TokensController` now expects `getNetworkClientById` in constructor options ([#1676](https://github.com/MetaMask/core/pull/1676))
289
351
  - **BREAKING**: `TokensController.addToken` now accepts a single options object ([#1676](https://github.com/MetaMask/core/pull/1676))
290
352
  ```
@@ -307,33 +369,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
307
369
  - Bump dependency on `@metamask/preferences-controller` to ^4.4.1 ([#1676](https://github.com/MetaMask/core/pull/1676))
308
370
 
309
371
  ## [12.0.0]
372
+
310
373
  ### Added
374
+
311
375
  - Add `AssetsContractController` methods `getProvider`, `getChainId`, `getERC721Standard`, and `getERC1155Standard` ([#1638](https://github.com/MetaMask/core/pull/1638))
312
376
 
313
377
  ### Changed
378
+
314
379
  - **BREAKING**: Add `getNetworkClientById` to `AssetsContractController` constructor options ([#1638](https://github.com/MetaMask/core/pull/1638))
315
- - Add optional `networkClientId` parameter to various `AssetContractController` methods ([#1638](https://github.com/MetaMask/core/pull/1638))
316
- - The affected methods are:
317
- - `getERC20BalanceOf`
318
- - `getERC20TokenDecimals`
319
- - `getERC20TokenName`
320
- - `getERC721NftTokenId`
321
- - `getTokenStandardAndDetails`
322
- - `getERC721TokenURI`
323
- - `getERC721AssetName`
324
- - `getERC721AssetSymbol`
325
- - `getERC721OwnerOf`
326
- - `getERC1155TokenURI`
327
- - `getERC1155BalanceOf`
328
- - `transferSingleERC1155`
329
- - `getBalancesInSingleCall`
380
+ - Add optional `networkClientId` parameter to various `AssetContractController` methods ([#1638](https://github.com/MetaMask/core/pull/1638))
381
+ - The affected methods are:
382
+ - `getERC20BalanceOf`
383
+ - `getERC20TokenDecimals`
384
+ - `getERC20TokenName`
385
+ - `getERC721NftTokenId`
386
+ - `getTokenStandardAndDetails`
387
+ - `getERC721TokenURI`
388
+ - `getERC721AssetName`
389
+ - `getERC721AssetSymbol`
390
+ - `getERC721OwnerOf`
391
+ - `getERC1155TokenURI`
392
+ - `getERC1155BalanceOf`
393
+ - `transferSingleERC1155`
394
+ - `getBalancesInSingleCall`
330
395
 
331
396
  ## [11.1.0]
397
+
332
398
  ### Added
399
+
333
400
  - Add `tokenURI` to `NftMetadata` type ([#1577](https://github.com/MetaMask/core/pull/1577))
334
401
  - Populate token URL for NFT metadata under `tokenURI` ([#1577](https://github.com/MetaMask/core/pull/1577))
335
402
 
336
403
  ### Changed
404
+
337
405
  - Bump dependency and peer dependency on `@metamask/approval-controller` to ^3.5.1
338
406
  - Bump dependency on `@metamask/base-controller` to ^3.2.1
339
407
  - Bump dependency on `@metamask/controller-utils` to ^4.3.2
@@ -342,14 +410,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
342
410
  - Update NftController to add fallback for when IPFS gateway is disabled ([#1577](https://github.com/MetaMask/core/pull/1577))
343
411
 
344
412
  ## [11.0.1]
413
+
345
414
  ### Changed
415
+
346
416
  - Replace `eth-query` ^2.1.2 with `@metamask/eth-query` ^3.0.1 ([#1546](https://github.com/MetaMask/core/pull/1546))
347
417
 
348
418
  ## [11.0.0]
419
+
349
420
  ### Added
421
+
350
422
  - Add a `stop` method to stop polling
351
423
 
352
424
  ### Changed
425
+
353
426
  - **BREAKING**: New required constructor parameters for the `TokenRatesController` ([#1497](https://github.com/MetaMask/core/pull/1497), [#1511](https://github.com/MetaMask/core/pull/1511))
354
427
  - The new required parameters are `ticker`, `onSelectedAddress`, and `onPreferencesStateChange`
355
428
  - **BREAKING**: Remove `onCurrencyRateStateChange` constructor parameter from `TokenRatesController` ([#1496](https://github.com/MetaMask/core/pull/1496))
@@ -364,16 +437,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
364
437
  - Remove unnecessary `babel-runtime` dependency ([#1504](https://github.com/MetaMask/core/pull/1504))
365
438
 
366
439
  ### Fixed
440
+
367
441
  - Fix bug where token rates were incorrect after first update if initialized with a non-Ethereum selected network ([#1497](https://github.com/MetaMask/core/pull/1497))
368
442
  - Fix bug where token rates would be invalid if event handlers were triggered in the wrong order ([#1496](https://github.com/MetaMask/core/pull/1496), [#1511](https://github.com/MetaMask/core/pull/1511))
369
443
  - Prevent redundant token rate updates ([#1512](https://github.com/MetaMask/core/pull/1512))
370
444
 
371
445
  ## [10.0.0]
446
+
372
447
  ### Added
448
+
373
449
  - The method `getERC20TokenName` has been added to `AssetsContractController` ([#1127](https://github.com/MetaMask/core/pull/1127))
374
450
  - This method gets the token name from the token contract
375
451
 
376
452
  ### Changed
453
+
377
454
  - **BREAKING:** The tokens controller now requires `onTokenListStateChange` and `getERC20TokenName` as constructor parameters ([#1127](https://github.com/MetaMask/core/pull/1127))
378
455
  - The `getERC20TokenName` method is used to get the token name for tokens added via `wallet_watchAsset`
379
456
  - The `onTokenListStateChange` method is used to trigger a name update when the token list changes. On each change, token names are copied from the token list if they're missing from token controller state.
@@ -384,19 +461,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
384
461
  - The `Token` type now includes an optional `name` field ([#1127](https://github.com/MetaMask/core/pull/1127))
385
462
 
386
463
  ## [9.2.0]
464
+
387
465
  ### Added
466
+
388
467
  - Add validation that the nft standard matches the type argument of a `wallet_watchAsset` request when type is 'ERC721' or 'ERC1155' ([#1455](https://github.com/MetaMask/core/pull/1455))
389
468
 
390
469
  ## [9.1.0]
470
+
391
471
  ### Added
472
+
392
473
  - Add a fifth argument, `source`, to NftController's `addNft` method ([#1417](https://github.com/MetaMask/core/pull/1417))
393
474
  - This argument can be used to specify whether the NFT was detected, added manually, or suggested by a dapp
394
475
 
395
476
  ### Fixed
477
+
396
478
  - Fix `watchNft` in NftController to ensure that if the network changes before the user accepts the request, the NFT is added to the chain ID and address before the request was initiated ([#1417](https://github.com/MetaMask/core/pull/1417))
397
479
 
398
480
  ## [9.0.0]
481
+
399
482
  ### Added
483
+
400
484
  - **BREAKING**: Add required options `getSelectedAddress` and `getMultiAccountBalancesEnabled` to AccountTrackerController constructor and make use of them when refreshing account balances ([#1146](https://github.com/MetaMask/core/pull/1146))
401
485
  - Previously, the controller would refresh all account balances, but these options can be used to only refresh the currently selected account
402
486
  - **BREAKING:** Add logic to support validating and adding ERC721 and ERC1155 tokens to NFTController state via `wallet_watchAsset` API. ([#1173](https://github.com/MetaMask/core/pull/1173), [#1406](https://github.com/MetaMask/core/pull/1406))
@@ -404,15 +488,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
404
488
  - The `NFTController` now requires an instance of a ControllerMessenger to be passed to its constructor. This is messenger is used to pass the `watchNFT` message to the `ApprovalController`.
405
489
 
406
490
  ### Changed
491
+
407
492
  - Add dependency on `@ethersproject/address` ([#1173](https://github.com/MetaMask/core/pull/1173))
408
493
  - Replace `eth-rpc-errors` with `@metamask/rpc-errors` ([#1173](https://github.com/MetaMask/core/pull/1173))
409
494
 
410
495
  ## [8.0.0]
496
+
411
497
  ### Added
498
+
412
499
  - Support NFT detection on Ethereum Mainnet custom RPC endpoints ([#1360](https://github.com/MetaMask/core/pull/1360))
413
500
  - Enable token detection for the Aurora network ([#1327](https://github.com/MetaMask/core/pull/1327))
414
501
 
415
502
  ### Changed
503
+
416
504
  - **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
417
505
  - **BREAKING:** Change format of chain ID in state to 0x-prefixed hex string ([#1367](https://github.com/MetaMask/core/pull/1367))
418
506
  - The functions `isTokenDetectionSupportedForNetwork` and `formatIconUrlWithProxy` now expect a chain ID as type `Hex` rather than as a decimal `string`
@@ -438,11 +526,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
438
526
  - The return type for `watchAsset` has changed. It now returns a Promise that settles after the request has been confirmed or rejected.
439
527
  - **BREAKING:** Initialize controllers with the current network ([#1361](https://github.com/MetaMask/core/pull/1361))
440
528
  - The following controllers now have a new `chainId` required constructor parameter:
441
- * `AssetsContractController`
442
- * `NftController`
443
- * `NftDetectionController`
444
- * `TokenRatesController`
445
- * `TokensController`
529
+ - `AssetsContractController`
530
+ - `NftController`
531
+ - `NftDetectionController`
532
+ - `TokenRatesController`
533
+ - `TokensController`
446
534
  - **BREAKING:** The token list controller messenger requires the `NetworkController:stateChange` event instead of the `NetworkController:providerConfigChange` event ([#1329](https://github.com/MetaMask/core/pull/1329))
447
535
  - **BREAKING:** The token list controller `onNetworkStateChange` option now has a more restrictive type ([#1329](https://github.com/MetaMask/core/pull/1329))
448
536
  - The event handler parameter type has been changed from `NetworkState | ProviderConfig` to `NetworkState`
@@ -454,42 +542,58 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
454
542
  - Bump @metamask/utils from 5.0.1 to 5.0.2 ([#1271](https://github.com/MetaMask/core/pull/1271))
455
543
 
456
544
  ### Removed
545
+
457
546
  - **BREAKING:** Remove the `networkType` configuration option from the NFT detection controller, NFT controller, and tokens controller ([#1360](https://github.com/MetaMask/core/pull/1360), [#1359](https://github.com/MetaMask/core/pull/1359))
458
547
  - **BREAKING:** Remove the `SuggestedAssetMeta` and `SuggestedAssetMetaBase` types from the token controller ([#1268](https://github.com/MetaMask/core/pull/1268))
459
548
  - **BREAKING:** Remove the `acceptWatchAsset` and `rejectWatchAsset` methods from the token controller ([#1268](https://github.com/MetaMask/core/pull/1268))
460
549
  - Suggested assets can be accepted or rejected using the approval controller instead
461
550
 
462
551
  ## [7.0.0]
552
+
463
553
  ### Changed
554
+
464
555
  - **BREAKING**: peerDeps: @metamask/network-controller@6.0.0->8.0.0 ([#1196](https://github.com/MetaMask/core/pull/1196))
465
556
 
466
557
  ## [6.0.0]
558
+
467
559
  ### Changed
560
+
468
561
  - **BREAKING:** Create approval requests using `@metamask/approval-controller` ([#1166](https://github.com/MetaMask/core/pull/1166))
469
562
 
470
563
  ## [5.1.0]
564
+
471
565
  ### Added
566
+
472
567
  - Support watching assets on a specific account ([#1124](https://github.com/MetaMask/core/pull/1124))
473
568
 
474
569
  ## [5.0.1]
570
+
475
571
  ### Changed
572
+
476
573
  - Update `@metamask/contract-metadata` from 2.1.0 to 2.3.1 ([#1141](https://github.com/MetaMask/core/pull/1141))
477
574
 
478
575
  ## [5.0.0]
576
+
479
577
  ### Removed
578
+
480
579
  - **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))
481
580
  - Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`
482
581
 
483
582
  ## [4.0.1]
583
+
484
584
  ### Fixed
585
+
485
586
  - Update Nft Controller to add the NFT back to its own group if we are re-importing it ([#1082](https://github.com/MetaMask/core/pull/1082))
486
587
 
487
588
  ## [4.0.0]
589
+
488
590
  ### Added
591
+
489
592
  - Add Sepolia support to the currency rate controller ([#1041](https://github.com/MetaMask/controllers/pull/1041))
490
593
  - The currency rate controller will now treat Sepolia as a testnet, and return the Mainnet exchange rate when asked for the Sepolia exchange rate.
491
594
 
492
595
  ### Changed
596
+
493
597
  - **BREAKING:** Update `@metamask/network-controller` peer dependency to v3 ([#1041](https://github.com/MetaMask/controllers/pull/1041))
494
598
  - **BREAKING:** Migrate from `metaswap` to `metafi` subdomain for OpenSea proxy and token icons API ([#1060](https://github.com/MetaMask/core/pull/1060))
495
599
  - Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
@@ -497,29 +601,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
497
601
  - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
498
602
 
499
603
  ## Removed
604
+
500
605
  - **BREAKING**: Drop support for Ropsten, Rinkeby, and Kovan ([#1041](https://github.com/MetaMask/controllers/pull/1041))
501
606
  - The currency rate controller no longer has special handling of these three networks. It used to return the Mainnet exchange rate for these three networks, but now it includes no special handling for them.
502
607
  - The NFT controller no longer supports the Rinkeby OpenSea test API.
503
608
 
504
609
  ## [3.0.1]
610
+
505
611
  ### Changed
612
+
506
613
  - Export `isTokenDetectionSupportedForNetwork` function ([#1034](https://github.com/MetaMask/controllers/pull/1034))
507
614
  - Update `@metamask/contract-metadata` from 1.35.0 to 2.1.0 ([#1013](https://github.com/MetaMask/controllers/pull/1013))
508
615
 
509
616
  ### Fixed
617
+
510
618
  - Fix token controller state updates ([#1015](https://github.com/MetaMask/controllers/pull/1015))
511
619
  - Attempts to empty the list of "added", "ignored", or "detected" tokens were not saved in state correctly, resulting in that operation being undone after switching account or network.
512
620
 
513
621
  ## [3.0.0]
622
+
514
623
  ### Changed
624
+
515
625
  - **BREAKING:** A new private property, controlled by the `start` and `stop` methods, is added to the CurrencyRateController: `enabled`. When this is false, no network requests will be made from the controller. Previously, setNativeCurrency or setCurrentCurrency would trigger a network request. That is now prevented if `enabled` is false. ([#1002](https://github.com/MetaMask/core/pull/1002))
516
626
 
517
627
  ### Fixed
628
+
518
629
  - The TokenRatesController no longer overwrites the `disabled` config property passed to the constructor, allowing the controller to be instantiated with `config.disabled` set to either true or false. ([#1002](https://github.com/MetaMask/core/pull/1002))
519
630
  - This package will now warn if a required package is not present ([#1003](https://github.com/MetaMask/core/pull/1003))
520
631
 
521
632
  ## [2.0.0]
633
+
522
634
  ### Changed
635
+
523
636
  - **BREAKING:** Update `onNetworkStateChange`, a constructor option for several controllers, to take an object with a `providerConfig` property instead of `provider` ([#995](https://github.com/MetaMask/core/pull/995))
524
637
  - This affects:
525
638
  - AssetsContractController
@@ -533,19 +646,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
533
646
  - Relax dependencies on `@metamask/base-controller`, `@metamask/controller-utils`, `@metamask/network-controller`, and `@metamask/preferences-controller` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
534
647
 
535
648
  ## [1.0.1]
649
+
536
650
  ### Fixed
651
+
537
652
  - Fix race condition where some token detections can get mistakenly added to the wrong account ([#956](https://github.com/MetaMask/core/pull/956))
538
653
 
539
654
  ## [1.0.0]
655
+
540
656
  ### Added
657
+
541
658
  - Initial release
659
+
542
660
  - As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/core/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/core/tree/v33.0.0), namely:
661
+
543
662
  - Everything in `src/assets`
544
663
  - Asset-related functions from `src/util.ts` and accompanying tests
545
664
 
546
665
  All changes listed after this point were applied to this package following the monorepo conversion.
547
666
 
548
667
  ### Changed
668
+
549
669
  - Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
550
670
 
551
671
  [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@25.0.0...HEAD
@@ -1,18 +1,21 @@
1
+ import type { AccountsControllerSelectedAccountChangeEvent } from '@metamask/accounts-controller';
1
2
  import type { RestrictedControllerMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
2
- import type { NetworkClientId, NetworkControllerNetworkDidChangeEvent, NetworkControllerStateChangeEvent, NetworkControllerGetNetworkConfigurationByNetworkClientId } from '@metamask/network-controller';
3
+ import type { KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent } from '@metamask/keyring-controller';
4
+ import type { NetworkClientId, NetworkControllerNetworkDidChangeEvent, NetworkControllerGetNetworkConfigurationByNetworkClientId } from '@metamask/network-controller';
3
5
  import { StaticIntervalPollingController } from '@metamask/polling-controller';
4
- import type { PreferencesState } from '@metamask/preferences-controller';
6
+ import type { PreferencesControllerGetStateAction, PreferencesControllerStateChangeEvent } from '@metamask/preferences-controller';
5
7
  import type { AssetsContractController } from './AssetsContractController';
6
- import type { GetTokenListState, TokenListStateChange } from './TokenListController';
8
+ import type { GetTokenListState, TokenListStateChange, TokenListToken } from './TokenListController';
7
9
  import type { TokensController, TokensState } from './TokensController';
10
+ export declare const STATIC_MAINNET_TOKEN_LIST: Record<string, Partial<TokenListToken>>;
8
11
  export declare const controllerName = "TokenDetectionController";
9
12
  export declare type TokenDetectionState = Record<never, never>;
10
13
  export declare type TokenDetectionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, TokenDetectionState>;
11
14
  export declare type TokenDetectionControllerActions = TokenDetectionControllerGetStateAction;
12
- export declare type AllowedActions = NetworkControllerGetNetworkConfigurationByNetworkClientId | GetTokenListState;
15
+ export declare type AllowedActions = NetworkControllerGetNetworkConfigurationByNetworkClientId | GetTokenListState | KeyringControllerGetStateAction | PreferencesControllerGetStateAction;
13
16
  export declare type TokenDetectionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, TokenDetectionState>;
14
17
  export declare type TokenDetectionControllerEvents = TokenDetectionControllerStateChangeEvent;
15
- export declare type AllowedEvents = NetworkControllerStateChangeEvent | NetworkControllerNetworkDidChangeEvent | TokenListStateChange;
18
+ export declare type AllowedEvents = AccountsControllerSelectedAccountChangeEvent | NetworkControllerNetworkDidChangeEvent | TokenListStateChange | KeyringControllerLockEvent | KeyringControllerUnlockEvent | PreferencesControllerStateChangeEvent;
16
19
  export declare type TokenDetectionControllerMessenger = RestrictedControllerMessenger<typeof controllerName, TokenDetectionControllerActions | AllowedActions, TokenDetectionControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
17
20
  /**
18
21
  * Controller that passively polls on a set interval for Tokens auto detection
@@ -21,6 +24,7 @@ export declare type TokenDetectionControllerMessenger = RestrictedControllerMess
21
24
  * @property selectedAddress - Vault selected address
22
25
  * @property networkClientId - The network client ID of the current selected network
23
26
  * @property disabled - Boolean to track if network requests are blocked
27
+ * @property isUnlocked - Boolean to track if the keyring state is unlocked
24
28
  * @property isDetectionEnabledFromPreferences - Boolean to track if detection is enabled from PreferencesController
25
29
  * @property isDetectionEnabledForNetwork - Boolean to track if detected is enabled for current network
26
30
  */
@@ -35,22 +39,28 @@ export declare class TokenDetectionController extends StaticIntervalPollingContr
35
39
  * @param options.interval - Polling interval used to fetch new token rates
36
40
  * @param options.networkClientId - The selected network client ID of the current network
37
41
  * @param options.selectedAddress - Vault selected address
38
- * @param options.onPreferencesStateChange - Allows subscribing to preferences controller state changes.
39
42
  * @param options.addDetectedTokens - Add a list of detected tokens.
40
43
  * @param options.getBalancesInSingleCall - Gets the balances of a list of tokens for the given address.
41
44
  * @param options.getTokensState - Gets the current state of the Tokens controller.
42
- * @param options.getPreferencesState - Gets the state of the preferences controller.
45
+ * @param options.trackMetaMetricsEvent - Sets options for MetaMetrics event tracking.
43
46
  */
44
- constructor({ networkClientId, selectedAddress, interval, disabled, onPreferencesStateChange, getBalancesInSingleCall, addDetectedTokens, getPreferencesState, getTokensState, messenger, }: {
47
+ constructor({ networkClientId, selectedAddress, interval, disabled, getBalancesInSingleCall, addDetectedTokens, getTokensState, trackMetaMetricsEvent, messenger, }: {
45
48
  networkClientId: NetworkClientId;
46
49
  selectedAddress?: string;
47
50
  interval?: number;
48
51
  disabled?: boolean;
49
- onPreferencesStateChange: (listener: (preferencesState: PreferencesState) => void) => void;
50
52
  addDetectedTokens: TokensController['addDetectedTokens'];
51
53
  getBalancesInSingleCall: AssetsContractController['getBalancesInSingleCall'];
52
54
  getTokensState: () => TokensState;
53
- getPreferencesState: () => PreferencesState;
55
+ trackMetaMetricsEvent: (options: {
56
+ event: string;
57
+ category: string;
58
+ properties: {
59
+ tokens: string[];
60
+ token_standard: string;
61
+ asset_type: string;
62
+ };
63
+ }) => void;
54
64
  messenger: TokenDetectionControllerMessenger;
55
65
  });
56
66
  /**
@@ -61,6 +71,12 @@ export declare class TokenDetectionController extends StaticIntervalPollingContr
61
71
  * Blocks controller from making network calls
62
72
  */
63
73
  disable(): void;
74
+ /**
75
+ * Internal isActive state
76
+ *
77
+ * @type {object}
78
+ */
79
+ get isActive(): boolean;
64
80
  /**
65
81
  * Start polling for detected tokens.
66
82
  */
@@ -73,11 +89,12 @@ export declare class TokenDetectionController extends StaticIntervalPollingContr
73
89
  address: string;
74
90
  }): Promise<void>;
75
91
  /**
76
- * Triggers asset ERC20 token auto detection for each contract address in contract metadata on mainnet.
92
+ * For each token in the token list provided by the TokenListController, checks the token's balance for the selected account address on the active network.
93
+ * On mainnet, if token detection is disabled in preferences, ERC20 token auto detection will be triggered for each contract address in the legacy token list from the @metamask/contract-metadata repo.
77
94
  *
78
- * @param options - Options to detect tokens.
95
+ * @param options - Options for token detection.
79
96
  * @param options.networkClientId - The ID of the network client to use.
80
- * @param options.accountAddress - The account address to use.
97
+ * @param options.accountAddress - the selectedAddress against which to detect for token balances.
81
98
  */
82
99
  detectTokens({ networkClientId, accountAddress, }?: {
83
100
  networkClientId?: NetworkClientId;
@@ -1 +1 @@
1
- {"version":3,"file":"TokenDetectionController.d.ts","sourceRoot":"","sources":["../src/TokenDetectionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAKnC,OAAO,KAAK,EACV,eAAe,EACf,sCAAsC,EACtC,iCAAiC,EACjC,yDAAyD,EAC1D,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BA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G,OAAO,CAAC,IAAI,CAAC;CAiHvB;AAED,eAAe,wBAAwB,CAAC"}
@@ -19,13 +19,41 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
19
19
  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");
20
20
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
21
  };
22
- var _TokenDetectionController_instances, _TokenDetectionController_intervalId, _TokenDetectionController_chainId, _TokenDetectionController_selectedAddress, _TokenDetectionController_networkClientId, _TokenDetectionController_disabled, _TokenDetectionController_isDetectionEnabledFromPreferences, _TokenDetectionController_isDetectionEnabledForNetwork, _TokenDetectionController_addDetectedTokens, _TokenDetectionController_getBalancesInSingleCall, _TokenDetectionController_getTokensState, _TokenDetectionController_stopPolling, _TokenDetectionController_startPolling, _TokenDetectionController_getCorrectChainId;
22
+ var __rest = (this && this.__rest) || function (s, e) {
23
+ var t = {};
24
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
25
+ t[p] = s[p];
26
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
27
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
28
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
29
+ t[p[i]] = s[p[i]];
30
+ }
31
+ return t;
32
+ };
33
+ var __importDefault = (this && this.__importDefault) || function (mod) {
34
+ return (mod && mod.__esModule) ? mod : { "default": mod };
35
+ };
36
+ var _TokenDetectionController_instances, _TokenDetectionController_intervalId, _TokenDetectionController_chainId, _TokenDetectionController_selectedAddress, _TokenDetectionController_networkClientId, _TokenDetectionController_disabled, _TokenDetectionController_isUnlocked, _TokenDetectionController_isDetectionEnabledFromPreferences, _TokenDetectionController_isDetectionEnabledForNetwork, _TokenDetectionController_addDetectedTokens, _TokenDetectionController_getBalancesInSingleCall, _TokenDetectionController_getTokensState, _TokenDetectionController_trackMetaMetricsEvent, _TokenDetectionController_registerEventListeners, _TokenDetectionController_stopPolling, _TokenDetectionController_startPolling, _TokenDetectionController_getCorrectChainId, _TokenDetectionController_restartTokenDetection;
23
37
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.TokenDetectionController = exports.controllerName = void 0;
38
+ exports.TokenDetectionController = exports.controllerName = exports.STATIC_MAINNET_TOKEN_LIST = void 0;
39
+ const contract_metadata_1 = __importDefault(require("@metamask/contract-metadata"));
25
40
  const controller_utils_1 = require("@metamask/controller-utils");
26
41
  const polling_controller_1 = require("@metamask/polling-controller");
27
42
  const assetsUtil_1 = require("./assetsUtil");
28
43
  const DEFAULT_INTERVAL = 180000;
44
+ /**
45
+ * Finds a case insensitive match in an array of strings
46
+ * @param source - An array of strings to search.
47
+ * @param target - The target string to search for.
48
+ * @returns The first match that is found.
49
+ */
50
+ function findCaseInsensitiveMatch(source, target) {
51
+ return source.find((e) => e.toLowerCase() === target.toLowerCase());
52
+ }
53
+ exports.STATIC_MAINNET_TOKEN_LIST = Object.entries(contract_metadata_1.default).reduce((acc, [base, contract]) => {
54
+ const { logo } = contract, tokenMetadata = __rest(contract, ["logo"]);
55
+ return Object.assign(Object.assign({}, acc), { [base.toLowerCase()]: Object.assign(Object.assign({}, tokenMetadata), { address: base.toLowerCase(), iconUrl: `images/contract/${logo}`, aggregators: [] }) });
56
+ }, {});
29
57
  exports.controllerName = 'TokenDetectionController';
30
58
  /**
31
59
  * Controller that passively polls on a set interval for Tokens auto detection
@@ -34,6 +62,7 @@ exports.controllerName = 'TokenDetectionController';
34
62
  * @property selectedAddress - Vault selected address
35
63
  * @property networkClientId - The network client ID of the current selected network
36
64
  * @property disabled - Boolean to track if network requests are blocked
65
+ * @property isUnlocked - Boolean to track if the keyring state is unlocked
37
66
  * @property isDetectionEnabledFromPreferences - Boolean to track if detection is enabled from PreferencesController
38
67
  * @property isDetectionEnabledForNetwork - Boolean to track if detected is enabled for current network
39
68
  */
@@ -47,14 +76,12 @@ class TokenDetectionController extends polling_controller_1.StaticIntervalPollin
47
76
  * @param options.interval - Polling interval used to fetch new token rates
48
77
  * @param options.networkClientId - The selected network client ID of the current network
49
78
  * @param options.selectedAddress - Vault selected address
50
- * @param options.onPreferencesStateChange - Allows subscribing to preferences controller state changes.
51
79
  * @param options.addDetectedTokens - Add a list of detected tokens.
52
80
  * @param options.getBalancesInSingleCall - Gets the balances of a list of tokens for the given address.
53
81
  * @param options.getTokensState - Gets the current state of the Tokens controller.
54
- * @param options.getPreferencesState - Gets the state of the preferences controller.
82
+ * @param options.trackMetaMetricsEvent - Sets options for MetaMetrics event tracking.
55
83
  */
56
- constructor({ networkClientId, selectedAddress = '', interval = DEFAULT_INTERVAL, disabled = true, onPreferencesStateChange, getBalancesInSingleCall, addDetectedTokens, getPreferencesState, getTokensState, messenger, }) {
57
- const { useTokenDetection: defaultUseTokenDetection } = getPreferencesState();
84
+ constructor({ networkClientId, selectedAddress = '', interval = DEFAULT_INTERVAL, disabled = true, getBalancesInSingleCall, addDetectedTokens, getTokensState, trackMetaMetricsEvent, messenger, }) {
58
85
  super({
59
86
  name: exports.controllerName,
60
87
  messenger,
@@ -67,47 +94,28 @@ class TokenDetectionController extends polling_controller_1.StaticIntervalPollin
67
94
  _TokenDetectionController_selectedAddress.set(this, void 0);
68
95
  _TokenDetectionController_networkClientId.set(this, void 0);
69
96
  _TokenDetectionController_disabled.set(this, void 0);
97
+ _TokenDetectionController_isUnlocked.set(this, void 0);
70
98
  _TokenDetectionController_isDetectionEnabledFromPreferences.set(this, void 0);
71
99
  _TokenDetectionController_isDetectionEnabledForNetwork.set(this, void 0);
72
100
  _TokenDetectionController_addDetectedTokens.set(this, void 0);
73
101
  _TokenDetectionController_getBalancesInSingleCall.set(this, void 0);
74
102
  _TokenDetectionController_getTokensState.set(this, void 0);
103
+ _TokenDetectionController_trackMetaMetricsEvent.set(this, void 0);
75
104
  __classPrivateFieldSet(this, _TokenDetectionController_disabled, disabled, "f");
76
105
  this.setIntervalLength(interval);
77
106
  __classPrivateFieldSet(this, _TokenDetectionController_networkClientId, networkClientId, "f");
78
107
  __classPrivateFieldSet(this, _TokenDetectionController_selectedAddress, selectedAddress, "f");
79
108
  __classPrivateFieldSet(this, _TokenDetectionController_chainId, __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getCorrectChainId).call(this, networkClientId), "f");
109
+ const { useTokenDetection: defaultUseTokenDetection } = this.messagingSystem.call('PreferencesController:getState');
80
110
  __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, defaultUseTokenDetection, "f");
81
111
  __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledForNetwork, (0, assetsUtil_1.isTokenDetectionSupportedForNetwork)(__classPrivateFieldGet(this, _TokenDetectionController_chainId, "f")), "f");
82
112
  __classPrivateFieldSet(this, _TokenDetectionController_addDetectedTokens, addDetectedTokens, "f");
83
113
  __classPrivateFieldSet(this, _TokenDetectionController_getBalancesInSingleCall, getBalancesInSingleCall, "f");
84
114
  __classPrivateFieldSet(this, _TokenDetectionController_getTokensState, getTokensState, "f");
85
- this.messagingSystem.subscribe('TokenListController:stateChange', ({ tokenList }) => __awaiter(this, void 0, void 0, function* () {
86
- const hasTokens = Object.keys(tokenList).length;
87
- if (hasTokens) {
88
- yield this.detectTokens();
89
- }
90
- }));
91
- onPreferencesStateChange(({ selectedAddress: newSelectedAddress, useTokenDetection }) => __awaiter(this, void 0, void 0, function* () {
92
- const isSelectedAddressChanged = __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f") !== newSelectedAddress;
93
- const isDetectionChangedFromPreferences = __classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f") !== useTokenDetection;
94
- __classPrivateFieldSet(this, _TokenDetectionController_selectedAddress, newSelectedAddress, "f");
95
- __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, useTokenDetection, "f");
96
- if (useTokenDetection &&
97
- (isSelectedAddressChanged || isDetectionChangedFromPreferences)) {
98
- yield this.detectTokens();
99
- }
100
- }));
101
- this.messagingSystem.subscribe('NetworkController:networkDidChange', ({ selectedNetworkClientId }) => __awaiter(this, void 0, void 0, function* () {
102
- __classPrivateFieldSet(this, _TokenDetectionController_networkClientId, selectedNetworkClientId, "f");
103
- const newChainId = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getCorrectChainId).call(this, selectedNetworkClientId);
104
- const isChainIdChanged = __classPrivateFieldGet(this, _TokenDetectionController_chainId, "f") !== newChainId;
105
- __classPrivateFieldSet(this, _TokenDetectionController_chainId, newChainId, "f");
106
- __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledForNetwork, (0, assetsUtil_1.isTokenDetectionSupportedForNetwork)(newChainId), "f");
107
- if (__classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledForNetwork, "f") && isChainIdChanged) {
108
- yield this.detectTokens();
109
- }
110
- }));
115
+ __classPrivateFieldSet(this, _TokenDetectionController_trackMetaMetricsEvent, trackMetaMetricsEvent, "f");
116
+ const { isUnlocked } = this.messagingSystem.call('KeyringController:getState');
117
+ __classPrivateFieldSet(this, _TokenDetectionController_isUnlocked, isUnlocked, "f");
118
+ __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_registerEventListeners).call(this);
111
119
  }
112
120
  /**
113
121
  * Allows controller to make active and passive polling requests
@@ -121,6 +129,14 @@ class TokenDetectionController extends polling_controller_1.StaticIntervalPollin
121
129
  disable() {
122
130
  __classPrivateFieldSet(this, _TokenDetectionController_disabled, true, "f");
123
131
  }
132
+ /**
133
+ * Internal isActive state
134
+ *
135
+ * @type {object}
136
+ */
137
+ get isActive() {
138
+ return !__classPrivateFieldGet(this, _TokenDetectionController_disabled, "f") && __classPrivateFieldGet(this, _TokenDetectionController_isUnlocked, "f");
139
+ }
124
140
  /**
125
141
  * Start polling for detected tokens.
126
142
  */
@@ -139,7 +155,7 @@ class TokenDetectionController extends polling_controller_1.StaticIntervalPollin
139
155
  }
140
156
  _executePoll(networkClientId, options) {
141
157
  return __awaiter(this, void 0, void 0, function* () {
142
- if (__classPrivateFieldGet(this, _TokenDetectionController_disabled, "f")) {
158
+ if (!this.isActive) {
143
159
  return;
144
160
  }
145
161
  yield this.detectTokens({
@@ -149,29 +165,35 @@ class TokenDetectionController extends polling_controller_1.StaticIntervalPollin
149
165
  });
150
166
  }
151
167
  /**
152
- * Triggers asset ERC20 token auto detection for each contract address in contract metadata on mainnet.
168
+ * For each token in the token list provided by the TokenListController, checks the token's balance for the selected account address on the active network.
169
+ * On mainnet, if token detection is disabled in preferences, ERC20 token auto detection will be triggered for each contract address in the legacy token list from the @metamask/contract-metadata repo.
153
170
  *
154
- * @param options - Options to detect tokens.
171
+ * @param options - Options for token detection.
155
172
  * @param options.networkClientId - The ID of the network client to use.
156
- * @param options.accountAddress - The account address to use.
173
+ * @param options.accountAddress - the selectedAddress against which to detect for token balances.
157
174
  */
158
175
  detectTokens({ networkClientId, accountAddress, } = {}) {
159
176
  return __awaiter(this, void 0, void 0, function* () {
160
- if (__classPrivateFieldGet(this, _TokenDetectionController_disabled, "f") ||
161
- !__classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledForNetwork, "f") ||
162
- !__classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f")) {
177
+ if (!this.isActive || !__classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledForNetwork, "f")) {
163
178
  return;
164
179
  }
165
- const { tokens } = __classPrivateFieldGet(this, _TokenDetectionController_getTokensState, "f").call(this);
166
- const selectedAddress = accountAddress || __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f");
180
+ const selectedAddress = accountAddress !== null && accountAddress !== void 0 ? accountAddress : __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f");
167
181
  const chainId = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getCorrectChainId).call(this, networkClientId);
168
- const tokensAddresses = tokens.map(
169
- /* istanbul ignore next*/ (token) => token.address.toLowerCase());
182
+ if (!__classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f") &&
183
+ chainId !== controller_utils_1.ChainId.mainnet) {
184
+ return;
185
+ }
186
+ const isTokenDetectionInactiveInMainnet = !__classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f") && chainId === controller_utils_1.ChainId.mainnet;
170
187
  const { tokenList } = this.messagingSystem.call('TokenListController:getState');
188
+ const tokenListUsed = isTokenDetectionInactiveInMainnet
189
+ ? exports.STATIC_MAINNET_TOKEN_LIST
190
+ : tokenList;
191
+ const { tokens, detectedTokens } = __classPrivateFieldGet(this, _TokenDetectionController_getTokensState, "f").call(this);
171
192
  const tokensToDetect = [];
172
- for (const address of Object.keys(tokenList)) {
173
- if (!tokensAddresses.includes(address)) {
174
- tokensToDetect.push(address);
193
+ for (const tokenAddress of Object.keys(tokenListUsed)) {
194
+ if (!findCaseInsensitiveMatch(tokens.map(({ address }) => address), tokenAddress) &&
195
+ !findCaseInsensitiveMatch(detectedTokens.map(({ address }) => address), tokenAddress)) {
196
+ tokensToDetect.push(tokenAddress);
175
197
  }
176
198
  }
177
199
  const sliceOfTokensToDetect = [];
@@ -189,6 +211,7 @@ class TokenDetectionController extends polling_controller_1.StaticIntervalPollin
189
211
  var _a;
190
212
  const balances = yield __classPrivateFieldGet(this, _TokenDetectionController_getBalancesInSingleCall, "f").call(this, selectedAddress, tokensSlice);
191
213
  const tokensToAdd = [];
214
+ const eventTokensDetails = [];
192
215
  for (const tokenAddress of Object.keys(balances)) {
193
216
  let ignored;
194
217
  /* istanbul ignore else */
@@ -196,9 +219,10 @@ class TokenDetectionController extends polling_controller_1.StaticIntervalPollin
196
219
  if (ignoredTokens.length) {
197
220
  ignored = ignoredTokens.find((ignoredTokenAddress) => ignoredTokenAddress === (0, controller_utils_1.toChecksumHexAddress)(tokenAddress));
198
221
  }
199
- const caseInsensitiveTokenKey = (_a = Object.keys(tokenList).find((i) => i.toLowerCase() === tokenAddress.toLowerCase())) !== null && _a !== void 0 ? _a : '';
222
+ const caseInsensitiveTokenKey = (_a = findCaseInsensitiveMatch(Object.keys(tokenListUsed), tokenAddress)) !== null && _a !== void 0 ? _a : '';
200
223
  if (ignored === undefined) {
201
224
  const { decimals, symbol, aggregators, iconUrl, name } = tokenList[caseInsensitiveTokenKey];
225
+ eventTokensDetails.push(`${symbol} - ${tokenAddress}`);
202
226
  tokensToAdd.push({
203
227
  address: tokenAddress,
204
228
  decimals,
@@ -211,6 +235,15 @@ class TokenDetectionController extends polling_controller_1.StaticIntervalPollin
211
235
  }
212
236
  }
213
237
  if (tokensToAdd.length) {
238
+ __classPrivateFieldGet(this, _TokenDetectionController_trackMetaMetricsEvent, "f").call(this, {
239
+ event: 'Token Detected',
240
+ category: 'Wallet',
241
+ properties: {
242
+ tokens: eventTokensDetails,
243
+ token_standard: 'ERC20',
244
+ asset_type: 'TOKEN',
245
+ },
246
+ });
214
247
  yield __classPrivateFieldGet(this, _TokenDetectionController_addDetectedTokens, "f").call(this, tokensToAdd, {
215
248
  selectedAddress,
216
249
  chainId,
@@ -222,13 +255,61 @@ class TokenDetectionController extends polling_controller_1.StaticIntervalPollin
222
255
  }
223
256
  }
224
257
  exports.TokenDetectionController = TokenDetectionController;
225
- _TokenDetectionController_intervalId = new WeakMap(), _TokenDetectionController_chainId = new WeakMap(), _TokenDetectionController_selectedAddress = new WeakMap(), _TokenDetectionController_networkClientId = new WeakMap(), _TokenDetectionController_disabled = new WeakMap(), _TokenDetectionController_isDetectionEnabledFromPreferences = new WeakMap(), _TokenDetectionController_isDetectionEnabledForNetwork = new WeakMap(), _TokenDetectionController_addDetectedTokens = new WeakMap(), _TokenDetectionController_getBalancesInSingleCall = new WeakMap(), _TokenDetectionController_getTokensState = new WeakMap(), _TokenDetectionController_instances = new WeakSet(), _TokenDetectionController_stopPolling = function _TokenDetectionController_stopPolling() {
258
+ _TokenDetectionController_intervalId = new WeakMap(), _TokenDetectionController_chainId = new WeakMap(), _TokenDetectionController_selectedAddress = new WeakMap(), _TokenDetectionController_networkClientId = new WeakMap(), _TokenDetectionController_disabled = new WeakMap(), _TokenDetectionController_isUnlocked = new WeakMap(), _TokenDetectionController_isDetectionEnabledFromPreferences = new WeakMap(), _TokenDetectionController_isDetectionEnabledForNetwork = new WeakMap(), _TokenDetectionController_addDetectedTokens = new WeakMap(), _TokenDetectionController_getBalancesInSingleCall = new WeakMap(), _TokenDetectionController_getTokensState = new WeakMap(), _TokenDetectionController_trackMetaMetricsEvent = new WeakMap(), _TokenDetectionController_instances = new WeakSet(), _TokenDetectionController_registerEventListeners = function _TokenDetectionController_registerEventListeners() {
259
+ this.messagingSystem.subscribe('KeyringController:unlock', () => __awaiter(this, void 0, void 0, function* () {
260
+ __classPrivateFieldSet(this, _TokenDetectionController_isUnlocked, true, "f");
261
+ yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this);
262
+ }));
263
+ this.messagingSystem.subscribe('KeyringController:lock', () => {
264
+ __classPrivateFieldSet(this, _TokenDetectionController_isUnlocked, false, "f");
265
+ __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_stopPolling).call(this);
266
+ });
267
+ this.messagingSystem.subscribe('TokenListController:stateChange', ({ tokenList }) => __awaiter(this, void 0, void 0, function* () {
268
+ const hasTokens = Object.keys(tokenList).length;
269
+ if (hasTokens) {
270
+ yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this);
271
+ }
272
+ }));
273
+ this.messagingSystem.subscribe('PreferencesController:stateChange', ({ selectedAddress: newSelectedAddress, useTokenDetection }) => __awaiter(this, void 0, void 0, function* () {
274
+ const isSelectedAddressChanged = __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f") !== newSelectedAddress;
275
+ const isDetectionChangedFromPreferences = __classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f") !== useTokenDetection;
276
+ __classPrivateFieldSet(this, _TokenDetectionController_selectedAddress, newSelectedAddress, "f");
277
+ __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, useTokenDetection, "f");
278
+ if (useTokenDetection &&
279
+ (isSelectedAddressChanged || isDetectionChangedFromPreferences)) {
280
+ yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
281
+ selectedAddress: __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f"),
282
+ });
283
+ }
284
+ }));
285
+ this.messagingSystem.subscribe('AccountsController:selectedAccountChange', ({ address: newSelectedAddress }) => __awaiter(this, void 0, void 0, function* () {
286
+ const isSelectedAddressChanged = __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f") !== newSelectedAddress;
287
+ if (isSelectedAddressChanged &&
288
+ __classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledFromPreferences, "f")) {
289
+ __classPrivateFieldSet(this, _TokenDetectionController_selectedAddress, newSelectedAddress, "f");
290
+ yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
291
+ selectedAddress: __classPrivateFieldGet(this, _TokenDetectionController_selectedAddress, "f"),
292
+ });
293
+ }
294
+ }));
295
+ this.messagingSystem.subscribe('NetworkController:networkDidChange', ({ selectedNetworkClientId }) => __awaiter(this, void 0, void 0, function* () {
296
+ const isNetworkClientIdChanged = __classPrivateFieldGet(this, _TokenDetectionController_networkClientId, "f") !== selectedNetworkClientId;
297
+ const newChainId = __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_getCorrectChainId).call(this, selectedNetworkClientId);
298
+ __classPrivateFieldSet(this, _TokenDetectionController_isDetectionEnabledForNetwork, (0, assetsUtil_1.isTokenDetectionSupportedForNetwork)(newChainId), "f");
299
+ if (isNetworkClientIdChanged && __classPrivateFieldGet(this, _TokenDetectionController_isDetectionEnabledForNetwork, "f")) {
300
+ __classPrivateFieldSet(this, _TokenDetectionController_networkClientId, selectedNetworkClientId, "f");
301
+ yield __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_restartTokenDetection).call(this, {
302
+ networkClientId: __classPrivateFieldGet(this, _TokenDetectionController_networkClientId, "f"),
303
+ });
304
+ }
305
+ }));
306
+ }, _TokenDetectionController_stopPolling = function _TokenDetectionController_stopPolling() {
226
307
  if (__classPrivateFieldGet(this, _TokenDetectionController_intervalId, "f")) {
227
308
  clearInterval(__classPrivateFieldGet(this, _TokenDetectionController_intervalId, "f"));
228
309
  }
229
310
  }, _TokenDetectionController_startPolling = function _TokenDetectionController_startPolling() {
230
311
  return __awaiter(this, void 0, void 0, function* () {
231
- if (__classPrivateFieldGet(this, _TokenDetectionController_disabled, "f")) {
312
+ if (!this.isActive) {
232
313
  return;
233
314
  }
234
315
  __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_stopPolling).call(this);
@@ -241,6 +322,14 @@ _TokenDetectionController_intervalId = new WeakMap(), _TokenDetectionController_
241
322
  var _a;
242
323
  const { chainId } = (_a = this.messagingSystem.call('NetworkController:getNetworkConfigurationByNetworkClientId', networkClientId !== null && networkClientId !== void 0 ? networkClientId : __classPrivateFieldGet(this, _TokenDetectionController_networkClientId, "f"))) !== null && _a !== void 0 ? _a : {};
243
324
  return chainId !== null && chainId !== void 0 ? chainId : __classPrivateFieldGet(this, _TokenDetectionController_chainId, "f");
325
+ }, _TokenDetectionController_restartTokenDetection = function _TokenDetectionController_restartTokenDetection({ selectedAddress, networkClientId, } = {}) {
326
+ return __awaiter(this, void 0, void 0, function* () {
327
+ yield this.detectTokens({
328
+ networkClientId,
329
+ accountAddress: selectedAddress,
330
+ });
331
+ this.setIntervalLength(DEFAULT_INTERVAL);
332
+ });
244
333
  };
245
334
  exports.default = TokenDetectionController;
246
335
  //# sourceMappingURL=TokenDetectionController.js.map
@@ -1 +1 @@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ACR;QACD,uBAAA,IAAI,kFAAa,MAAjB,IAAI,CAAe,CAAC;QACpB,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC1B,uBAAA,IAAI,wCAAe,WAAW,CAAC,GAAS,EAAE;YACxC,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,CAAC,CAAA,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,MAAA,CAAC;IAC/B,CAAC;sGAEkB,eAAiC;;IAClD,MAAM,EAAE,OAAO,EAAE,GACf,MAAA,IAAI,CAAC,eAAe,CAAC,IAAI,CACvB,4DAA4D,EAC5D,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,uBAAA,IAAI,iDAAiB,CACzC,mCAAI,EAAE,CAAC;IACV,OAAO,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,uBAAA,IAAI,yCAAS,CAAC;AAClC,CAAC;AAoHH,kBAAe,wBAAwB,CAAC","sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n safelyExecute,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkControllerNetworkDidChangeEvent,\n NetworkControllerStateChangeEvent,\n NetworkControllerGetNetworkConfigurationByNetworkClientId,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { PreferencesState } from '@metamask/preferences-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { AssetsContractController } from './AssetsContractController';\nimport { isTokenDetectionSupportedForNetwork } from './assetsUtil';\nimport type {\n GetTokenListState,\n TokenListStateChange,\n} from './TokenListController';\nimport type { Token } from './TokenRatesController';\nimport type { TokensController, TokensState } from './TokensController';\n\nconst DEFAULT_INTERVAL = 180000;\n\nexport const controllerName = 'TokenDetectionController';\n\nexport type TokenDetectionState = Record<never, never>;\n\nexport type TokenDetectionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n TokenDetectionState\n>;\n\nexport type TokenDetectionControllerActions =\n TokenDetectionControllerGetStateAction;\n\nexport type AllowedActions =\n | NetworkControllerGetNetworkConfigurationByNetworkClientId\n | GetTokenListState;\n\nexport type TokenDetectionControllerStateChangeEvent =\n ControllerStateChangeEvent<typeof controllerName, TokenDetectionState>;\n\nexport type TokenDetectionControllerEvents =\n TokenDetectionControllerStateChangeEvent;\n\nexport type AllowedEvents =\n | NetworkControllerStateChangeEvent\n | NetworkControllerNetworkDidChangeEvent\n | TokenListStateChange;\n\nexport type TokenDetectionControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n TokenDetectionControllerActions | AllowedActions,\n TokenDetectionControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Controller that passively polls on a set interval for Tokens auto detection\n * @property intervalId - Polling interval used to fetch new token rates\n * @property chainId - The chain ID of the current network\n * @property selectedAddress - Vault selected address\n * @property networkClientId - The network client ID of the current selected network\n * @property disabled - Boolean to track if network requests are blocked\n * @property isDetectionEnabledFromPreferences - Boolean to track if detection is enabled from PreferencesController\n * @property isDetectionEnabledForNetwork - Boolean to track if detected is enabled for current network\n */\nexport class TokenDetectionController extends StaticIntervalPollingController<\n typeof controllerName,\n TokenDetectionState,\n TokenDetectionControllerMessenger\n> {\n #intervalId?: ReturnType<typeof setTimeout>;\n\n #chainId: Hex;\n\n #selectedAddress: string;\n\n #networkClientId: NetworkClientId;\n\n #disabled: boolean;\n\n #isDetectionEnabledFromPreferences: boolean;\n\n #isDetectionEnabledForNetwork: boolean;\n\n readonly #addDetectedTokens: TokensController['addDetectedTokens'];\n\n readonly #getBalancesInSingleCall: AssetsContractController['getBalancesInSingleCall'];\n\n readonly #getTokensState: () => TokensState;\n\n /**\n * Creates a TokenDetectionController instance.\n *\n * @param options - The controller options.\n * @param options.messenger - The controller messaging system.\n * @param options.disabled - If set to true, all network requests are blocked.\n * @param options.interval - Polling interval used to fetch new token rates\n * @param options.networkClientId - The selected network client ID of the current network\n * @param options.selectedAddress - Vault selected address\n * @param options.onPreferencesStateChange - Allows subscribing to preferences controller state changes.\n * @param options.addDetectedTokens - Add a list of detected tokens.\n * @param options.getBalancesInSingleCall - Gets the balances of a list of tokens for the given address.\n * @param options.getTokensState - Gets the current state of the Tokens controller.\n * @param options.getPreferencesState - Gets the state of the preferences controller.\n */\n constructor({\n networkClientId,\n selectedAddress = '',\n interval = DEFAULT_INTERVAL,\n disabled = true,\n onPreferencesStateChange,\n getBalancesInSingleCall,\n addDetectedTokens,\n getPreferencesState,\n getTokensState,\n messenger,\n }: {\n networkClientId: NetworkClientId;\n selectedAddress?: string;\n interval?: number;\n disabled?: boolean;\n onPreferencesStateChange: (\n listener: (preferencesState: PreferencesState) => void,\n ) => void;\n addDetectedTokens: TokensController['addDetectedTokens'];\n getBalancesInSingleCall: AssetsContractController['getBalancesInSingleCall'];\n getTokensState: () => TokensState;\n getPreferencesState: () => PreferencesState;\n messenger: TokenDetectionControllerMessenger;\n }) {\n const { useTokenDetection: defaultUseTokenDetection } =\n getPreferencesState();\n\n super({\n name: controllerName,\n messenger,\n state: {},\n metadata: {},\n });\n\n this.#disabled = disabled;\n this.setIntervalLength(interval);\n\n this.#networkClientId = networkClientId;\n this.#selectedAddress = selectedAddress;\n this.#chainId = this.#getCorrectChainId(networkClientId);\n\n this.#isDetectionEnabledFromPreferences = defaultUseTokenDetection;\n this.#isDetectionEnabledForNetwork = isTokenDetectionSupportedForNetwork(\n this.#chainId,\n );\n\n this.#addDetectedTokens = addDetectedTokens;\n this.#getBalancesInSingleCall = getBalancesInSingleCall;\n this.#getTokensState = getTokensState;\n\n this.messagingSystem.subscribe(\n 'TokenListController:stateChange',\n async ({ tokenList }) => {\n const hasTokens = Object.keys(tokenList).length;\n\n if (hasTokens) {\n await this.detectTokens();\n }\n },\n );\n\n onPreferencesStateChange(\n async ({ selectedAddress: newSelectedAddress, useTokenDetection }) => {\n const isSelectedAddressChanged =\n this.#selectedAddress !== newSelectedAddress;\n const isDetectionChangedFromPreferences =\n this.#isDetectionEnabledFromPreferences !== useTokenDetection;\n\n this.#selectedAddress = newSelectedAddress;\n this.#isDetectionEnabledFromPreferences = useTokenDetection;\n\n if (\n useTokenDetection &&\n (isSelectedAddressChanged || isDetectionChangedFromPreferences)\n ) {\n await this.detectTokens();\n }\n },\n );\n\n this.messagingSystem.subscribe(\n 'NetworkController:networkDidChange',\n async ({ selectedNetworkClientId }) => {\n this.#networkClientId = selectedNetworkClientId;\n const newChainId = this.#getCorrectChainId(selectedNetworkClientId);\n const isChainIdChanged = this.#chainId !== newChainId;\n this.#chainId = newChainId;\n\n this.#isDetectionEnabledForNetwork =\n isTokenDetectionSupportedForNetwork(newChainId);\n\n if (this.#isDetectionEnabledForNetwork && isChainIdChanged) {\n await this.detectTokens();\n }\n },\n );\n }\n\n /**\n * Allows controller to make active and passive polling requests\n */\n enable() {\n this.#disabled = false;\n }\n\n /**\n * Blocks controller from making network calls\n */\n disable() {\n this.#disabled = true;\n }\n\n /**\n * Start polling for detected tokens.\n */\n async start() {\n this.enable();\n await this.#startPolling();\n }\n\n /**\n * Stop polling for detected tokens.\n */\n stop() {\n this.disable();\n this.#stopPolling();\n }\n\n #stopPolling() {\n if (this.#intervalId) {\n clearInterval(this.#intervalId);\n }\n }\n\n /**\n * Starts a new polling interval.\n */\n async #startPolling(): Promise<void> {\n if (this.#disabled) {\n return;\n }\n this.#stopPolling();\n await this.detectTokens();\n this.#intervalId = setInterval(async () => {\n await this.detectTokens();\n }, this.getIntervalLength());\n }\n\n #getCorrectChainId(networkClientId?: NetworkClientId) {\n const { chainId } =\n this.messagingSystem.call(\n 'NetworkController:getNetworkConfigurationByNetworkClientId',\n networkClientId ?? this.#networkClientId,\n ) ?? {};\n return chainId ?? this.#chainId;\n }\n\n async _executePoll(\n networkClientId: string,\n options: { address: string },\n ): Promise<void> {\n if (this.#disabled) {\n return;\n }\n await this.detectTokens({\n networkClientId,\n accountAddress: options.address,\n });\n }\n\n /**\n * Triggers asset ERC20 token auto detection for each contract address in contract metadata on mainnet.\n *\n * @param options - Options to detect tokens.\n * @param options.networkClientId - The ID of the network client to use.\n * @param options.accountAddress - The account address to use.\n */\n async detectTokens({\n networkClientId,\n accountAddress,\n }: {\n networkClientId?: NetworkClientId;\n accountAddress?: string;\n } = {}): Promise<void> {\n if (\n this.#disabled ||\n !this.#isDetectionEnabledForNetwork ||\n !this.#isDetectionEnabledFromPreferences\n ) {\n return;\n }\n const { tokens } = this.#getTokensState();\n const selectedAddress = accountAddress || this.#selectedAddress;\n const chainId = this.#getCorrectChainId(networkClientId);\n\n const tokensAddresses = tokens.map(\n /* istanbul ignore next*/ (token) => token.address.toLowerCase(),\n );\n const { tokenList } = this.messagingSystem.call(\n 'TokenListController:getState',\n );\n const tokensToDetect: string[] = [];\n for (const address of Object.keys(tokenList)) {\n if (!tokensAddresses.includes(address)) {\n tokensToDetect.push(address);\n }\n }\n const sliceOfTokensToDetect = [];\n sliceOfTokensToDetect[0] = tokensToDetect.slice(0, 1000);\n sliceOfTokensToDetect[1] = tokensToDetect.slice(\n 1000,\n tokensToDetect.length - 1,\n );\n\n /* istanbul ignore else */\n if (!selectedAddress) {\n return;\n }\n\n for (const tokensSlice of sliceOfTokensToDetect) {\n if (tokensSlice.length === 0) {\n break;\n }\n\n await safelyExecute(async () => {\n const balances = await this.#getBalancesInSingleCall(\n selectedAddress,\n tokensSlice,\n );\n const tokensToAdd: Token[] = [];\n for (const tokenAddress of Object.keys(balances)) {\n let ignored;\n /* istanbul ignore else */\n const { ignoredTokens } = this.#getTokensState();\n if (ignoredTokens.length) {\n ignored = ignoredTokens.find(\n (ignoredTokenAddress) =>\n ignoredTokenAddress === toChecksumHexAddress(tokenAddress),\n );\n }\n const caseInsensitiveTokenKey =\n Object.keys(tokenList).find(\n (i) => i.toLowerCase() === tokenAddress.toLowerCase(),\n ) ?? '';\n\n if (ignored === undefined) {\n const { decimals, symbol, aggregators, iconUrl, name } =\n tokenList[caseInsensitiveTokenKey];\n tokensToAdd.push({\n address: tokenAddress,\n decimals,\n symbol,\n aggregators,\n image: iconUrl,\n isERC721: false,\n name,\n });\n }\n }\n\n if (tokensToAdd.length) {\n await this.#addDetectedTokens(tokensToAdd, {\n selectedAddress,\n chainId,\n });\n }\n });\n }\n }\n}\n\nexport default TokenDetectionController;\n"]}
1
+ {"version":3,"file":"TokenDetectionController.js","sourceRoot":"","sources":["../src/TokenDetectionController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,oFAAsD;AACtD,iEAIoC;AAWpC,qEAA+E;AAQ/E,6CAAmE;AASnE,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,MAAgB,EAAE,MAAc;IAChE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;AAC9E,CAAC;AAYY,QAAA,yBAAyB,GAAG,MAAM,CAAC,OAAO,CACrD,2BAAW,CACZ,CAAC,MAAM,CAA0C,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE;IAC1E,MAAM,EAAE,IAAI,KAAuB,QAAQ,EAA1B,aAAa,UAAK,QAAQ,EAArC,QAA0B,CAAW,CAAC;IAC5C,uCACK,GAAG,KACN,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,kCACf,aAAa,KAChB,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,EAC3B,OAAO,EAAE,mBAAmB,IAAI,EAAE,EAClC,WAAW,EAAE,EAAE,OAEjB;AACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AAEM,QAAA,cAAc,GAAG,0BAA0B,CAAC;AAwCzD;;;;;;;;;;GAUG;AACH,MAAa,wBAAyB,SAAQ,oDAI7C;IAiCC;;;;;;;;;;;;;OAaG;IAC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AAmIH,kBAAe,wBAAwB,CAAC","sourcesContent":["import type { AccountsControllerSelectedAccountChangeEvent } from '@metamask/accounts-controller';\nimport type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport contractMap from '@metamask/contract-metadata';\nimport {\n ChainId,\n safelyExecute,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type {\n NetworkClientId,\n NetworkControllerNetworkDidChangeEvent,\n NetworkControllerGetNetworkConfigurationByNetworkClientId,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type {\n PreferencesControllerGetStateAction,\n PreferencesControllerStateChangeEvent,\n} from '@metamask/preferences-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { AssetsContractController } from './AssetsContractController';\nimport { isTokenDetectionSupportedForNetwork } from './assetsUtil';\nimport type {\n GetTokenListState,\n TokenListStateChange,\n TokenListToken,\n} from './TokenListController';\nimport type { Token } from './TokenRatesController';\nimport type { TokensController, TokensState } from './TokensController';\n\nconst DEFAULT_INTERVAL = 180000;\n\n/**\n * Finds a case insensitive match in an array of strings\n * @param source - An array of strings to search.\n * @param target - The target string to search for.\n * @returns The first match that is found.\n */\nfunction findCaseInsensitiveMatch(source: string[], target: string) {\n return source.find((e: string) => e.toLowerCase() === target.toLowerCase());\n}\n\ntype LegacyToken = Omit<\n Token,\n 'aggregators' | 'image' | 'balanceError' | 'isERC721'\n> & {\n name: string;\n logo: string;\n erc20?: boolean;\n erc721?: boolean;\n};\n\nexport const STATIC_MAINNET_TOKEN_LIST = Object.entries<LegacyToken>(\n contractMap,\n).reduce<Record<string, Partial<TokenListToken>>>((acc, [base, contract]) => {\n const { logo, ...tokenMetadata } = contract;\n return {\n ...acc,\n [base.toLowerCase()]: {\n ...tokenMetadata,\n address: base.toLowerCase(),\n iconUrl: `images/contract/${logo}`,\n aggregators: [],\n },\n };\n}, {});\n\nexport const controllerName = 'TokenDetectionController';\n\nexport type TokenDetectionState = Record<never, never>;\n\nexport type TokenDetectionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n TokenDetectionState\n>;\n\nexport type TokenDetectionControllerActions =\n TokenDetectionControllerGetStateAction;\n\nexport type AllowedActions =\n | NetworkControllerGetNetworkConfigurationByNetworkClientId\n | GetTokenListState\n | KeyringControllerGetStateAction\n | PreferencesControllerGetStateAction;\n\nexport type TokenDetectionControllerStateChangeEvent =\n ControllerStateChangeEvent<typeof controllerName, TokenDetectionState>;\n\nexport type TokenDetectionControllerEvents =\n TokenDetectionControllerStateChangeEvent;\n\nexport type AllowedEvents =\n | AccountsControllerSelectedAccountChangeEvent\n | NetworkControllerNetworkDidChangeEvent\n | TokenListStateChange\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n | PreferencesControllerStateChangeEvent;\n\nexport type TokenDetectionControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n TokenDetectionControllerActions | AllowedActions,\n TokenDetectionControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Controller that passively polls on a set interval for Tokens auto detection\n * @property intervalId - Polling interval used to fetch new token rates\n * @property chainId - The chain ID of the current network\n * @property selectedAddress - Vault selected address\n * @property networkClientId - The network client ID of the current selected network\n * @property disabled - Boolean to track if network requests are blocked\n * @property isUnlocked - Boolean to track if the keyring state is unlocked\n * @property isDetectionEnabledFromPreferences - Boolean to track if detection is enabled from PreferencesController\n * @property isDetectionEnabledForNetwork - Boolean to track if detected is enabled for current network\n */\nexport class TokenDetectionController extends StaticIntervalPollingController<\n typeof controllerName,\n TokenDetectionState,\n TokenDetectionControllerMessenger\n> {\n #intervalId?: ReturnType<typeof setTimeout>;\n\n #chainId: Hex;\n\n #selectedAddress: string;\n\n #networkClientId: NetworkClientId;\n\n #disabled: boolean;\n\n #isUnlocked: boolean;\n\n #isDetectionEnabledFromPreferences: boolean;\n\n #isDetectionEnabledForNetwork: boolean;\n\n readonly #addDetectedTokens: TokensController['addDetectedTokens'];\n\n readonly #getBalancesInSingleCall: AssetsContractController['getBalancesInSingleCall'];\n\n readonly #getTokensState: () => TokensState;\n\n readonly #trackMetaMetricsEvent: (options: {\n event: string;\n category: string;\n properties: {\n tokens: string[];\n token_standard: string;\n asset_type: string;\n };\n }) => void;\n\n /**\n * Creates a TokenDetectionController instance.\n *\n * @param options - The controller options.\n * @param options.messenger - The controller messaging system.\n * @param options.disabled - If set to true, all network requests are blocked.\n * @param options.interval - Polling interval used to fetch new token rates\n * @param options.networkClientId - The selected network client ID of the current network\n * @param options.selectedAddress - Vault selected address\n * @param options.addDetectedTokens - Add a list of detected tokens.\n * @param options.getBalancesInSingleCall - Gets the balances of a list of tokens for the given address.\n * @param options.getTokensState - Gets the current state of the Tokens controller.\n * @param options.trackMetaMetricsEvent - Sets options for MetaMetrics event tracking.\n */\n constructor({\n networkClientId,\n selectedAddress = '',\n interval = DEFAULT_INTERVAL,\n disabled = true,\n getBalancesInSingleCall,\n addDetectedTokens,\n getTokensState,\n trackMetaMetricsEvent,\n messenger,\n }: {\n networkClientId: NetworkClientId;\n selectedAddress?: string;\n interval?: number;\n disabled?: boolean;\n addDetectedTokens: TokensController['addDetectedTokens'];\n getBalancesInSingleCall: AssetsContractController['getBalancesInSingleCall'];\n getTokensState: () => TokensState;\n trackMetaMetricsEvent: (options: {\n event: string;\n category: string;\n properties: {\n tokens: string[];\n token_standard: string;\n asset_type: string;\n };\n }) => void;\n messenger: TokenDetectionControllerMessenger;\n }) {\n super({\n name: controllerName,\n messenger,\n state: {},\n metadata: {},\n });\n\n this.#disabled = disabled;\n this.setIntervalLength(interval);\n\n this.#networkClientId = networkClientId;\n this.#selectedAddress = selectedAddress;\n this.#chainId = this.#getCorrectChainId(networkClientId);\n\n const { useTokenDetection: defaultUseTokenDetection } =\n this.messagingSystem.call('PreferencesController:getState');\n this.#isDetectionEnabledFromPreferences = defaultUseTokenDetection;\n this.#isDetectionEnabledForNetwork = isTokenDetectionSupportedForNetwork(\n this.#chainId,\n );\n\n this.#addDetectedTokens = addDetectedTokens;\n this.#getBalancesInSingleCall = getBalancesInSingleCall;\n this.#getTokensState = getTokensState;\n\n this.#trackMetaMetricsEvent = trackMetaMetricsEvent;\n\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.#registerEventListeners();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system subscriptions to controller events.\n */\n #registerEventListeners() {\n this.messagingSystem.subscribe('KeyringController:unlock', async () => {\n this.#isUnlocked = true;\n await this.#restartTokenDetection();\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n this.#stopPolling();\n });\n\n this.messagingSystem.subscribe(\n 'TokenListController:stateChange',\n async ({ tokenList }) => {\n const hasTokens = Object.keys(tokenList).length;\n\n if (hasTokens) {\n await this.#restartTokenDetection();\n }\n },\n );\n\n this.messagingSystem.subscribe(\n 'PreferencesController:stateChange',\n async ({ selectedAddress: newSelectedAddress, useTokenDetection }) => {\n const isSelectedAddressChanged =\n this.#selectedAddress !== newSelectedAddress;\n const isDetectionChangedFromPreferences =\n this.#isDetectionEnabledFromPreferences !== useTokenDetection;\n\n this.#selectedAddress = newSelectedAddress;\n this.#isDetectionEnabledFromPreferences = useTokenDetection;\n\n if (\n useTokenDetection &&\n (isSelectedAddressChanged || isDetectionChangedFromPreferences)\n ) {\n await this.#restartTokenDetection({\n selectedAddress: this.#selectedAddress,\n });\n }\n },\n );\n\n this.messagingSystem.subscribe(\n 'AccountsController:selectedAccountChange',\n async ({ address: newSelectedAddress }) => {\n const isSelectedAddressChanged =\n this.#selectedAddress !== newSelectedAddress;\n if (\n isSelectedAddressChanged &&\n this.#isDetectionEnabledFromPreferences\n ) {\n this.#selectedAddress = newSelectedAddress;\n await this.#restartTokenDetection({\n selectedAddress: this.#selectedAddress,\n });\n }\n },\n );\n\n this.messagingSystem.subscribe(\n 'NetworkController:networkDidChange',\n async ({ selectedNetworkClientId }) => {\n const isNetworkClientIdChanged =\n this.#networkClientId !== selectedNetworkClientId;\n\n const newChainId = this.#getCorrectChainId(selectedNetworkClientId);\n this.#isDetectionEnabledForNetwork =\n isTokenDetectionSupportedForNetwork(newChainId);\n\n if (isNetworkClientIdChanged && this.#isDetectionEnabledForNetwork) {\n this.#networkClientId = selectedNetworkClientId;\n await this.#restartTokenDetection({\n networkClientId: this.#networkClientId,\n });\n }\n },\n );\n }\n\n /**\n * Allows controller to make active and passive polling requests\n */\n enable() {\n this.#disabled = false;\n }\n\n /**\n * Blocks controller from making network calls\n */\n disable() {\n this.#disabled = true;\n }\n\n /**\n * Internal isActive state\n *\n * @type {object}\n */\n get isActive() {\n return !this.#disabled && this.#isUnlocked;\n }\n\n /**\n * Start polling for detected tokens.\n */\n async start() {\n this.enable();\n await this.#startPolling();\n }\n\n /**\n * Stop polling for detected tokens.\n */\n stop() {\n this.disable();\n this.#stopPolling();\n }\n\n #stopPolling() {\n if (this.#intervalId) {\n clearInterval(this.#intervalId);\n }\n }\n\n /**\n * Starts a new polling interval.\n */\n async #startPolling(): Promise<void> {\n if (!this.isActive) {\n return;\n }\n this.#stopPolling();\n await this.detectTokens();\n this.#intervalId = setInterval(async () => {\n await this.detectTokens();\n }, this.getIntervalLength());\n }\n\n #getCorrectChainId(networkClientId?: NetworkClientId) {\n const { chainId } =\n this.messagingSystem.call(\n 'NetworkController:getNetworkConfigurationByNetworkClientId',\n networkClientId ?? this.#networkClientId,\n ) ?? {};\n return chainId ?? this.#chainId;\n }\n\n async _executePoll(\n networkClientId: string,\n options: { address: string },\n ): Promise<void> {\n if (!this.isActive) {\n return;\n }\n await this.detectTokens({\n networkClientId,\n accountAddress: options.address,\n });\n }\n\n /**\n * Restart token detection polling period and call detectNewTokens\n * in case of address change or user session initialization.\n *\n * @param options - Options for restart token detection.\n * @param options.selectedAddress - the selectedAddress against which to detect for token balances\n * @param options.networkClientId - The ID of the network client to use.\n */\n async #restartTokenDetection({\n selectedAddress,\n networkClientId,\n }: { selectedAddress?: string; networkClientId?: string } = {}) {\n await this.detectTokens({\n networkClientId,\n accountAddress: selectedAddress,\n });\n this.setIntervalLength(DEFAULT_INTERVAL);\n }\n\n /**\n * For each token in the token list provided by the TokenListController, checks the token's balance for the selected account address on the active network.\n * On mainnet, if token detection is disabled in preferences, ERC20 token auto detection will be triggered for each contract address in the legacy token list from the @metamask/contract-metadata repo.\n *\n * @param options - Options for token detection.\n * @param options.networkClientId - The ID of the network client to use.\n * @param options.accountAddress - the selectedAddress against which to detect for token balances.\n */\n async detectTokens({\n networkClientId,\n accountAddress,\n }: {\n networkClientId?: NetworkClientId;\n accountAddress?: string;\n } = {}): Promise<void> {\n if (!this.isActive || !this.#isDetectionEnabledForNetwork) {\n return;\n }\n const selectedAddress = accountAddress ?? this.#selectedAddress;\n const chainId = this.#getCorrectChainId(networkClientId);\n\n if (\n !this.#isDetectionEnabledFromPreferences &&\n chainId !== ChainId.mainnet\n ) {\n return;\n }\n const isTokenDetectionInactiveInMainnet =\n !this.#isDetectionEnabledFromPreferences && chainId === ChainId.mainnet;\n const { tokenList } = this.messagingSystem.call(\n 'TokenListController:getState',\n );\n const tokenListUsed = isTokenDetectionInactiveInMainnet\n ? STATIC_MAINNET_TOKEN_LIST\n : tokenList;\n\n const { tokens, detectedTokens } = this.#getTokensState();\n const tokensToDetect: string[] = [];\n\n for (const tokenAddress of Object.keys(tokenListUsed)) {\n if (\n !findCaseInsensitiveMatch(\n tokens.map(({ address }) => address),\n tokenAddress,\n ) &&\n !findCaseInsensitiveMatch(\n detectedTokens.map(({ address }) => address),\n tokenAddress,\n )\n ) {\n tokensToDetect.push(tokenAddress);\n }\n }\n const sliceOfTokensToDetect = [];\n sliceOfTokensToDetect[0] = tokensToDetect.slice(0, 1000);\n sliceOfTokensToDetect[1] = tokensToDetect.slice(\n 1000,\n tokensToDetect.length - 1,\n );\n\n /* istanbul ignore else */\n if (!selectedAddress) {\n return;\n }\n\n for (const tokensSlice of sliceOfTokensToDetect) {\n if (tokensSlice.length === 0) {\n break;\n }\n\n await safelyExecute(async () => {\n const balances = await this.#getBalancesInSingleCall(\n selectedAddress,\n tokensSlice,\n );\n const tokensToAdd: Token[] = [];\n const eventTokensDetails = [];\n for (const tokenAddress of Object.keys(balances)) {\n let ignored;\n /* istanbul ignore else */\n const { ignoredTokens } = this.#getTokensState();\n if (ignoredTokens.length) {\n ignored = ignoredTokens.find(\n (ignoredTokenAddress) =>\n ignoredTokenAddress === toChecksumHexAddress(tokenAddress),\n );\n }\n const caseInsensitiveTokenKey =\n findCaseInsensitiveMatch(\n Object.keys(tokenListUsed),\n tokenAddress,\n ) ?? '';\n\n if (ignored === undefined) {\n const { decimals, symbol, aggregators, iconUrl, name } =\n tokenList[caseInsensitiveTokenKey];\n eventTokensDetails.push(`${symbol} - ${tokenAddress}`);\n tokensToAdd.push({\n address: tokenAddress,\n decimals,\n symbol,\n aggregators,\n image: iconUrl,\n isERC721: false,\n name,\n });\n }\n }\n\n if (tokensToAdd.length) {\n this.#trackMetaMetricsEvent({\n event: 'Token Detected',\n category: 'Wallet',\n properties: {\n tokens: eventTokensDetails,\n token_standard: 'ERC20',\n asset_type: 'TOKEN',\n },\n });\n await this.#addDetectedTokens(tokensToAdd, {\n selectedAddress,\n chainId,\n });\n }\n });\n }\n }\n}\n\nexport default TokenDetectionController;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/assets-controllers",
3
- "version": "25.0.0-preview.8cdddaf",
3
+ "version": "25.0.0-preview.bc4dd941",
4
4
  "description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -36,11 +36,13 @@
36
36
  "@ethersproject/contracts": "^5.7.0",
37
37
  "@ethersproject/providers": "^5.7.0",
38
38
  "@metamask/abi-utils": "^2.0.2",
39
+ "@metamask/accounts-controller": "^10.0.0",
39
40
  "@metamask/approval-controller": "^5.1.2",
40
41
  "@metamask/base-controller": "^4.1.1",
41
42
  "@metamask/contract-metadata": "^2.4.0",
42
43
  "@metamask/controller-utils": "^8.0.2",
43
44
  "@metamask/eth-query": "^4.0.0",
45
+ "@metamask/keyring-controller": "^12.2.0",
44
46
  "@metamask/metamask-eth-abis": "3.0.0",
45
47
  "@metamask/network-controller": "^17.2.0",
46
48
  "@metamask/polling-controller": "^5.0.0",
@@ -58,7 +60,8 @@
58
60
  },
59
61
  "devDependencies": {
60
62
  "@metamask/auto-changelog": "^3.4.4",
61
- "@metamask/ethjs-provider-http": "^0.2.0",
63
+ "@metamask/ethjs-provider-http": "^0.3.0",
64
+ "@metamask/keyring-api": "^3.0.0",
62
65
  "@types/jest": "^27.4.1",
63
66
  "@types/lodash": "^4.14.191",
64
67
  "@types/node": "^16.18.54",
@@ -73,7 +76,9 @@
73
76
  "typescript": "~4.8.4"
74
77
  },
75
78
  "peerDependencies": {
79
+ "@metamask/accounts-controller": "^10.0.0",
76
80
  "@metamask/approval-controller": "^5.1.2",
81
+ "@metamask/keyring-controller": "^12.2.0",
77
82
  "@metamask/network-controller": "^17.2.0",
78
83
  "@metamask/preferences-controller": "^7.0.0"
79
84
  },