mirror of
https://github.com/alexgo-io/alex-sdk.git
synced 2026-01-12 22:12:16 +08:00
feat: add ability to fetch token list
This commit is contained in:
@@ -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
17
src/utils/tokenlist.ts
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user