-
Notifications
You must be signed in to change notification settings - Fork 4
fix: remove dead 1inch IPFS token list and make fetching resilient #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fernandomg
wants to merge
1
commit into
develop
Choose a base branch
from
fix/token-list-ipfs-504
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,8 @@ | |
| * @dev Here you can add the list of tokens you want to use in the app | ||
| * The list follow the standard from: https://tokenlists.org/ | ||
| * | ||
| * Token list must complain with the Schema defined in /src/token.ts | ||
| * Token list must comply with the Schema defined in /src/token.ts | ||
| */ | ||
| export const tokenLists = { | ||
| '1INCH': 'https://ipfs.io/ipns/tokens.1inch.eth', | ||
| COINGECKO: 'https://tokens.coingecko.com/uniswap/all.json', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we know about some other alternatives we could add here? Just in case this one dies too. |
||
| } as const | ||
This file contains hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,8 +63,8 @@ export const useTokenLists = (): TokensMap => { | |
| queries: tokenListUrls.map<UseSuspenseQueryOptions<TokenList>>((url) => ({ | ||
| queryKey: ['tokens-list', url], | ||
| queryFn: () => fetchTokenList(url), | ||
| staleTime: Number.POSITIVE_INFINITY, | ||
| gcTime: Number.POSITIVE_INFINITY, | ||
| staleTime: 60 * 60 * 1000, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super minor, but maybe put these in a |
||
| gcTime: 60 * 60 * 1000, | ||
| })), | ||
| combine: combineTokenLists, | ||
| }) | ||
|
|
@@ -145,26 +145,48 @@ function combineTokenLists(results: Array<UseSuspenseQueryResult<TokenList>>): T | |
| return tokensMap | ||
| } | ||
|
|
||
| const emptyTokenList: TokenList = { | ||
| name: '', | ||
| timestamp: '', | ||
| version: { major: 0, minor: 0, patch: 0 }, | ||
| tokens: [], | ||
| } | ||
|
|
||
| /** | ||
| * A wrapper around fetch, to return the parsed JSON or throw an error if something goes wrong | ||
| * Fetches a token list from a URL. Returns an empty token list on failure | ||
| * instead of throwing, so one broken source doesn't block the entire app. | ||
| * | ||
| * @param url - a link to a list of tokens or 'default' to use the list added as a dependency to the project | ||
| * @returns {Promise<TokenList>} a token list | ||
| * @param url - a link to a list of tokens or 'default' to use the bundled list | ||
| * @returns a token list (empty on failure) | ||
| */ | ||
| async function fetchTokenList(url: string): Promise<TokenList> { | ||
| export async function fetchTokenList(url: string): Promise<TokenList> { | ||
| if (url === 'default') { | ||
| return defaultTokens as TokenList | ||
| } | ||
|
|
||
| const result = await fetch(url) | ||
| try { | ||
| const result = await fetch(url) | ||
|
|
||
| if (!result.ok) { | ||
| console.warn(`Token list fetch failed for ${url}: HTTP ${result.status} ${result.statusText}`) | ||
| return emptyTokenList | ||
| } | ||
|
|
||
| if (!result.ok) { | ||
| throw new Error( | ||
| `Something went wrong. HTTP status code: ${result.status}. Status Message: ${result.statusText}`, | ||
| const data = await result.json() | ||
|
|
||
| if (!data || typeof data !== 'object' || !Array.isArray(data.tokens)) { | ||
| console.warn(`Token list fetch for ${url} returned invalid schema; expected a tokens array.`) | ||
| return emptyTokenList | ||
| } | ||
fernandomg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return data as TokenList | ||
| } catch (error) { | ||
| console.warn( | ||
| `Token list fetch failed for ${url}:`, | ||
| error instanceof Error ? error.message : error, | ||
| ) | ||
| return emptyTokenList | ||
| } | ||
|
|
||
| return result.json() | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🤣