@metamask-previews/assets-controller 9.0.2-preview-2a256aff2 → 9.0.2-preview-8633f7f2a

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
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Add `priceFreshnessTtlMs` option to `PriceDataSourceConfig` controlling how long a fetched price is considered fresh before it is re-fetched (defaults to the poll interval, 60 000 ms) ([#9189](https://github.com/MetaMask/core/pull/9189))
13
+ - Add `PriceDataSource.invalidatePriceCache()` to force the next fetch to bypass the freshness cache; `AssetsController` now calls it when the selected currency changes so cached prices in the previous currency are refreshed ([#9189](https://github.com/MetaMask/core/pull/9189))
14
+
15
+ ### Fixed
16
+
17
+ - Deduplicate price fetches in `PriceDataSource` so overlapping triggers (enrichment middleware, subscription polls, and manual refreshes) no longer issue duplicate price API requests for the same asset; assets fetched within the freshness TTL are skipped and concurrent in-flight fetches are joined ([#9189](https://github.com/MetaMask/core/pull/9189))
18
+ - Remove a redundant one-time balance fetch in `AssetsController` when the enabled network list changes, since subscription refresh and the enabled-networks handler already cover those fetches ([#9189](https://github.com/MetaMask/core/pull/9189))
19
+
10
20
  ## [9.0.2]
11
21
 
12
22
  ### Changed
@@ -748,6 +748,8 @@ class AssetsController extends base_controller_1.BaseController {
748
748
  if (!__classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)) {
749
749
  return;
750
750
  }
751
+ // Currency changed — old cached prices are in the wrong currency.
752
+ __classPrivateFieldGet(this, _AssetsController_priceDataSource, "f").invalidatePriceCache();
751
753
  this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this), {
752
754
  forceUpdate: true,
753
755
  dataTypes: ['price'],
@@ -1157,23 +1159,12 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
1157
1159
  const addedChains = activeChains.filter((ch) => !previousSet.has(ch));
1158
1160
  const removedChains = previous.filter((ch) => !activeChains.includes(ch));
1159
1161
  if (addedChains.length > 0 || removedChains.length > 0) {
1160
- // Refresh subscriptions to use updated data source availability
1162
+ // Refresh subscriptions to use updated data source availability.
1163
+ // No one-time fetch needed here — #handleEnabledNetworksChanged
1164
+ // handles fetches when the user enables a network, and
1165
+ // #subscribeAssets re-subscribes with the correct chain assignment.
1161
1166
  __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
1162
1167
  }
1163
- // If chains were added and we have selected accounts, do one-time fetch
1164
- if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).length > 0) {
1165
- const addedEnabledChains = addedChains.filter((chain) => __classPrivateFieldGet(this, _AssetsController_enabledChains, "f").has(chain));
1166
- if (addedEnabledChains.length > 0) {
1167
- log('Fetching balances for newly added chains', { addedEnabledChains });
1168
- this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this), {
1169
- chainIds: addedEnabledChains,
1170
- forceUpdate: true,
1171
- updateMode: 'merge',
1172
- }).catch((error) => {
1173
- log('Failed to fetch balance for added chains', { error });
1174
- });
1175
- }
1176
- }
1177
1168
  }, _AssetsController_executeMiddlewares =
1178
1169
  // ============================================================================
1179
1170
  // MIDDLEWARE EXECUTION