rainbow icon indicating copy to clipboard operation
rainbow copied to clipboard

userAssetsStore refactor

Open benisgold opened this issue 6 months ago • 0 comments

Fixes APP-####

What changed (plus any additional context for devs)

Context

The current implementation of userAssetsStore only caches assets for 1 wallet at a time. This means every time the user switches wallets, this computationally heavy code is executed. This currently isn't that much of a problem, because userAssetsStore is only used within swaps and the user can't switch wallets within the swaps flow.

Problem

This ticket requires userAssetsStore to be used everywhere in the app, which would cause the above issues to become much more evident. For example, when the user switches wallets there would be a delay while waiting for the selected wallet's assets to appear on the WalletScreen.

Solution

The solution implemented in this PR refactors the singular userAssetsStore into a framework for creating & caching multiple per-wallet stores. See createUserAssetsStore, useUserAssetsStore, getOrCreateStore, storeManager in src/state/assets/userAssets.ts.

There is now a store called storeManager (private to userAssets.ts) that stores & persists all these per-wallet userAssetStores. The individual userAssetStores can be accessed externally by passing in the wallet address as the first param to userAssetsStore.getState(), userAssetsStore.setState() and useUserAssetsStore(). All other params that you would normally pass in to these functions can still be passed in after.

Screen recordings / screenshots

What to test

Swaps TF coming

benisgold avatar Aug 19 '24 21:08 benisgold