@metamask-previews/assets-controller 14.0.2-preview-f8cb83dcd → 14.0.2-preview-e68ab1498

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.
@@ -1337,10 +1337,11 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
1337
1337
  __classPrivateFieldSet(this, _AssetsController_uiOpen, isUiOpen, "f");
1338
1338
  __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
1339
1339
  }, client_controller_1.clientControllerSelectors.selectIsUiOpen);
1340
- this.messenger.subscribe('KeyringController:unlock', () => {
1340
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
1341
+ this.messenger.subscribe('KeyringController:unlock', async () => {
1341
1342
  __classPrivateFieldSet(this, _AssetsController_keyringUnlocked, true, "f");
1342
- __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_runSpamCleanup).call(this).catch((error) => {
1343
- log('Failed to run spam cleanup', { error });
1343
+ await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_runSpamCleanup).call(this).catch(() => {
1344
+ /* Do nothing */
1344
1345
  });
1345
1346
  __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
1346
1347
  });
@@ -1413,24 +1414,25 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
1413
1414
  log('Failed to refresh assets after transaction confirmed', { error });
1414
1415
  });
1415
1416
  }, _AssetsController_runSpamCleanup = async function _AssetsController_runSpamCleanup() {
1416
- if (!__classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)) {
1417
+ const shouldRun = __classPrivateFieldGet(this, _AssetsController_keyringUnlocked, "f") && __classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this);
1418
+ if (!shouldRun) {
1417
1419
  return;
1418
1420
  }
1419
1421
  try {
1420
- const nextState = await (0, healAssetsInfoMetadata_js_1.cleanSpamAssets)({
1421
- state: this.state,
1422
+ const originalState = this.state;
1423
+ const result = await (0, healAssetsInfoMetadata_js_1.cleanSpamAssets)({
1424
+ state: originalState,
1422
1425
  apiClient: __classPrivateFieldGet(this, _AssetsController_queryApiClient, "f"),
1423
1426
  captureException: __classPrivateFieldGet(this, _AssetsController_captureException, "f"),
1424
1427
  });
1425
- if (nextState !== this.state) {
1426
- this.update((state) => {
1427
- return {
1428
- ...state,
1429
- assetsInfo: nextState.assetsInfo,
1430
- assetsBalance: nextState.assetsBalance,
1431
- };
1432
- });
1428
+ if (!result) {
1429
+ return;
1433
1430
  }
1431
+ this.update((state) => {
1432
+ result.applyPatch(state, {
1433
+ spamAssetIds: result.spamAssetIds,
1434
+ });
1435
+ });
1434
1436
  }
1435
1437
  catch (error) {
1436
1438
  log('Failed to run spam cleanup', { error });