Skip to content

Commit 5800f16

Browse files
authored
Merge pull request #353 from ava-labs/dev
Fix tokenlist
2 parents 8877289 + 4338cab commit 5800f16

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

src/store/modules/assets/assets.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ import Vue from 'vue'
1818
import AvaAsset from '@/js/AvaAsset'
1919
import { WalletType } from '@/js/wallets/types'
2020
import { AvaNftFamily } from '@/js/AvaNftFamily'
21-
import {
22-
AmountOutput,
23-
UTXOSet as AVMUTXOSet,
24-
UTXO as AVMUTXO,
25-
UTXO,
26-
NFTMintOutput,
27-
} from 'avalanche/dist/apis/avm'
21+
import { AmountOutput, UTXOSet as AVMUTXOSet, UTXO, NFTMintOutput } from 'avalanche/dist/apis/avm'
2822
import { UnixNow } from 'avalanche/dist/utils'
2923
import { BN } from 'avalanche'
3024
import { UTXOSet as PlatformUTXOSet } from 'avalanche/dist/apis/platformvm/utxos'
@@ -33,18 +27,15 @@ import axios from 'axios'
3327
import Erc20Token from '@/js/Erc20Token'
3428
import { AvaNetwork } from '@/js/AvaNetwork'
3529
import { web3 } from '@/evm'
36-
// import ERC721Token from '@/js/ERC721Token'
3730

38-
const TOKEN_LISTS = [
39-
'https://raw.githubusercontent.com/pangolindex/tokenlists/1896f8607efa01c82a273c0012e3f99eee25db81/43114.tokenlist.json',
40-
]
31+
const TOKEN_LISTS: string[] = []
4132

4233
import ERC721Module from './modules/erc721'
43-
import ERC20_TOKEN_LIST from '@/ERC20Tokenlist.json'
4434
import MnemonicWallet from '@/js/wallets/MnemonicWallet'
4535
import { LedgerWallet } from '@/js/wallets/LedgerWallet'
4636
import { getPayloadFromUTXO } from '@/helpers/helper'
4737
import { isUrlBanned } from '@/components/misc/NftPayloadView/blacklist'
38+
import { fetchTokenList } from '@/store/modules/assets/fetchTokenList'
4839

4940
const assets_module: Module<AssetsState, RootState> = {
5041
namespaced: true,
@@ -284,7 +275,7 @@ const assets_module: Module<AssetsState, RootState> = {
284275

285276
async initErc20List({ state, dispatch, commit }) {
286277
// Load default erc20 token contracts
287-
const erc20Tokens = ERC20_TOKEN_LIST as TokenList
278+
const erc20Tokens = await fetchTokenList()
288279
erc20Tokens.readonly = true
289280
erc20Tokens.url = 'Default'
290281
await dispatch('addTokenList', erc20Tokens)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { TokenList } from '@/store/modules/assets/types'
2+
3+
function mapTokenInfo(token: any) {
4+
return { ...token, logoURI: token.logoUri }
5+
}
6+
7+
/**
8+
* Fetch erc20 token information from glacier
9+
*/
10+
export async function fetchTokenList(): Promise<TokenList> {
11+
const res = await fetch(
12+
'https://glacier-api.avax.network/proxy/chain-assets/main/_lists/core-wallet/token-list.erc20.json'
13+
)
14+
const json = await res.json()
15+
16+
const tokensMainnet = json[43114].tokens.map(mapTokenInfo)
17+
const tokensTestnet = json[43113].tokens.map(mapTokenInfo)
18+
19+
return {
20+
name: 'Avalanche (C-Chain)',
21+
logoURI:
22+
'https://glacier-api.avax.network/proxy/chain-assets/3e1b653/chains/43113/token-logo.png',
23+
keywords: [],
24+
timestamp: '',
25+
url: '',
26+
readonly: true,
27+
version: {
28+
major: 1,
29+
minor: 0,
30+
patch: 0,
31+
},
32+
tokens: [...tokensMainnet, ...tokensTestnet],
33+
}
34+
}

0 commit comments

Comments
 (0)