Skip to content

Conversation

infiniteflower
Copy link
Contributor

@infiniteflower infiniteflower commented Mar 27, 2025

Explanation

This PR removes state.topAssetsLastFetched, and allows the immediate fetching of top assets without relying on a 'NetworkController:networkDidChange' event. We rely on the state.chainCache[chainId].topAssetsLastFetched instead of the previous state.topAssetsLastFetched now to determine if we can fetch or just read from the cache.

Currently in Mobile the way we wipe the state.topAssetsLastFetched is by the user exiting the Swaps app, and switching networks.

this.messagingSystem.subscribe(
      'NetworkController:networkDidChange',
      (networkControllerState) => {
        const chainId = this.#getChainId(
          networkControllerState.selectedNetworkClientId,
        );
        this.#restoreFromChainCacheOrClear(chainId);
      },
    );

The use case is for the Mobile Bridge, specifically the situation where a user is switching back and forth between destination chain filters but without actually changing their app network.

state.topAssetsLastFetched was never used by Mobile, only in test mocks for the background state.

References

Related to MetaMask/metamask-mobile#14258

Changelog

@metamask/swaps-controller

  • BREAKING: state.topAssetsLastFetched removed
  • CHANGED: Rely on state.chainCache[chainId].topAssetsLastFetched to determine cache threshold. This allows for immediate fetching of top assets from a different chain without actually changing the MM app's network. Previously if we fetched top assets for Chain A and then immediately we want to fetch for Chain B, this would be impossible without actually switching networks. This is needed to fetch top destination tokens for Bridge transactions.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@infiniteflower infiniteflower marked this pull request as ready for review March 28, 2025 20:53
@infiniteflower infiniteflower requested a review from a team March 28, 2025 20:53
@infiniteflower infiniteflower merged commit 50a9479 into main Mar 31, 2025
11 checks passed
@infiniteflower infiniteflower deleted the feat/fetch-top-tokens-by-chain branch March 31, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants