-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from helius-labs/i/search-by-token-symbol
[Feature] Add Search By Token Symbol Functionality
- Loading branch information
Showing
5 changed files
with
70 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { JupiterToken, TokenMap } from "$lib/types"; | ||
import { recognizedTokens } from "./recognized-tokens"; | ||
|
||
const getJupiterTokens = async (): Promise<TokenMap> => { | ||
try { | ||
const data = await fetch(`https://token.jup.ag/all`); | ||
const jsonData = await data.json(); | ||
|
||
if (!Array.isArray(jsonData)) { | ||
throw new Error("Unexpected data format from Jupiter API"); | ||
} | ||
|
||
const tokens: JupiterToken[] = jsonData as JupiterToken[]; | ||
const tokenMap = tokens.reduce((acc: TokenMap, token: JupiterToken) => { | ||
if ( | ||
(recognizedTokens[token.symbol] && | ||
recognizedTokens[token.symbol] === token.address) || | ||
!recognizedTokens[token.symbol] | ||
) { | ||
acc[token.symbol] = token.address; | ||
} | ||
return acc; | ||
}, {}); | ||
|
||
return tokenMap; | ||
} catch (error: any) { | ||
throw new Error( | ||
`Failed to fetch tokens from Jupiter with error: ${error}` | ||
); | ||
} | ||
}; | ||
|
||
export default getJupiterTokens; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { RecognizedTokens } from "$lib/types"; | ||
|
||
export const recognizedTokens: RecognizedTokens = { | ||
FOXY: "FoXyMu5xwXre7zEoSvzViRk3nGawHUp9kUh97y2NDhcq", | ||
USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", | ||
}; |
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