-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove token registry dependency (#281)
This PR removes and replaces the `@solana/spl-token-registry` dependency, which was by far the largest dependency and was pulling in an >3MB outdated JSON file on every page. It should improve performance across the board, especially on slower networks. Token data will also be much more up to date, and tokens created since we deprecated the token registry will be represented correctly. The main replacement for this dependency is [Solflare's Unified Token List (UTL) SDK](https://github.com/solflare-wallet/utl-sdk). This is a typescript SDK that provides information about a token. It's got great performance and covers most use cases we have really well. It has some tradeoffs: - It's quite a heavy dependency, mostly because of its `metaplex-foundation/js` dependency which allows it to fetch on-chain data for tokens that aren't in its API/CDN already. For this reason I've used the underlying API directly for the search bar, to avoid pulling the SDK into the root layout. This is actually the same behaviour as the SDK has for search anyway, since falling back to an on-chain query can't be done for search. - It doesn't have all the per-token data from the old token registry, specifically for extensions it only has the coingecko one, and is missing eg bridge contracts and websites. We only use these on the token address page. Longer term we might want to remove these since we don't have a way to get this data for new tokens. But for now I'm using a CDN version of our last token list to fetch the token info including these legacy fields. For tokens that aren't in that list I use the SDK as a fallback, and just return the data without those extensions. Other than these cases, we now use the SDK for all token info. Some specific implementation decisions: - The address/[address] page fetches token info once (using the legacy CDN, then API fallback), and uses prop drilling for child components. - `useAccountOwnedTokens` now returns tokens with the fetched name/logo/symbol for each, fetched from the UTL SDK. - The `<Address>` component used to search the token registry in all cases, like it does with programs etc. This is no longer the case since we no longer have the entire token list on every page. A new prop `tokenListInfo` can be used to pass known token info in. This is used for example when rendering the user's owned tokens. Alternatively `fetchTokenLabelInfo` can be used to asynchronously fetch the token for the address, and update the address to display it after fetching. This should be used for addresses that might be a token, for example transaction accounts. This is the equivalent of `useMetadata` which fetches NFT metadata. - I've used SWR in a few places where we fetch token info as an enhancement, usually just to display the symbol for a token as a suffix for a count, eg 5 USDC. In these cases I use the loading state of SWR to distinguish between data not fetched yet (we display no suffix) and no data available (we typically add the 'tokens' suffix) The result of all this is that the huge tokenlist file which dominated our bundle is gone: Master: <img width="2386" alt="master-all-min" src="https://github.com/solana-labs/explorer/assets/1711350/335135f5-7750-4962-8149-5fe542dd3cbd"> This branch: <img width="2387" alt="rtr-all-min" src="https://github.com/solana-labs/explorer/assets/1711350/da3b5c42-65fd-4121-8cf7-e2a8bc858047"> Looking at just the layout shared by all pages, the effect is even more drastic. Master: <img width="2388" alt="master-layout-min" src="https://github.com/solana-labs/explorer/assets/1711350/3e843dd0-7fc4-4c21-9a57-36b95bb393d8"> This branch: <img width="2388" alt="rtr-layout-min" src="https://github.com/solana-labs/explorer/assets/1711350/748f6fdc-d16f-4600-b840-6b72848e3ff6"> Closes #201 --------- Co-authored-by: steveluscher <[email protected]>
- Loading branch information
1 parent
9639bef
commit 450736d
Showing
23 changed files
with
2,783 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
450736d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
explorer – ./
explorer-git-master-solana-labs.vercel.app
explorer.solana.com
explorer-solana-labs.vercel.app