reservoirprotocol / marketplace-v1

An open source NFT marketplace built on Reservoir.
https://www.reservoir.market
MIT License
173 stars 254 forks source link

When configured for a single collection, UserTokensGrid.tsx shows all NFTs for a split second #573

Open Andriy1221 opened 1 year ago

Andriy1221 commented 1 year ago

Description: I noticed that when the marketplace is configured to show only one collection and you open a wallet page (pages/address/[address].tsx) to see which NFTs the person owns, the UserTokensGrid.tsx component first shows all NFTs and then filters to show only the NFTs from the configured collection. This happens quickly but the first unfiltered result is visible for a split second which I think should be avoided.

Suggestion: As far as I understand, the UseUserTokens hook from reservoir0x/reservoir-kit-ui returns an object that is saved as userTokens in UserTokensGrid.tsx with the method mutate(). Initially userTokens includes all tokens, and then in an useEffect hook mutate() is called to filter the results, which creates a new userTokens object that only includes NFTs from the configured collection.

I suggest to use a state to check whether the mutate function was already called and only show the results after that. Maybe there is a cleaner solution though. I will open a PR to address this issue.

For reference

https://user-images.githubusercontent.com/70953497/199428697-2847700e-d4b6-4179-b172-cf7a65d8a6d2.mov