feat: add ability to fetch token list

This commit is contained in:
Kyle Fang
2023-08-23 16:55:47 +08:00
parent a93db219f4
commit 59fb1a99dc
2 changed files with 22 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ import {
broadcastSponsoredTx,
isSponsoredSwapEnabled,
} from './utils/sponsoredTx';
import { fetchTokenList, TokenInfo } from './utils/tokenlist';
export { SponsoredTxError, SponsoredTxErrorCode } from './utils/sponsoredTx';
export class AlexSDK {
@@ -109,4 +110,8 @@ export class AlexSDK {
isSponsoredSwapEnabled(): Promise<boolean> {
return isSponsoredSwapEnabled().catch(() => false);
}
fetchTokenList(): Promise<TokenInfo[]> {
return fetchTokenList()
}
}

17
src/utils/tokenlist.ts Normal file
View File

@@ -0,0 +1,17 @@
export type TokenInfo = {
type: 'fungibleToken',
id: string,
displayPrecision: number,
icon: string,
availableInSwap: boolean,
contractAddress: string,
decimals: number
}
export function fetchTokenList(): Promise<TokenInfo[]> {
return fetch('https://token-list.alexlab.co', {
mode: 'cors'
})
.then(res => res.json())
.then(data => data.tokens)
}