1+ import { TokenInfo } from '@uniswap/token-lists'
12import { ethers } from 'ethers'
23import fetch from 'node-fetch'
3- import { TokenInfo } from '@uniswap/token-lists'
44
55export interface Prop {
66 label : string
77 value : string
88}
99
1010export interface Item {
11- metadata : {
11+ metadata : {
1212 props : Prop [ ]
1313 } | null
1414 id : string
1515}
1616
1717const fetchTokensBatch = async ( id : string ) : Promise < Item [ ] > => {
18+ if ( ! process . env . CURATE_GRAPH_URL ) {
19+ throw new Error ( 'CURATE_GRAPH_URL environment variable is not set' )
20+ }
1821 const subgraphQuery = {
1922 query : `
2023 {
@@ -34,16 +37,16 @@ const fetchTokensBatch = async (id: string): Promise<Item[]> => {
3437 }
3538 ` ,
3639 }
37- const response = await fetch (
38- 'https://api.studio.thegraph.com/query/61738/legacy-curate-gnosis/version/latest ',
39- {
40- method : 'POST' ,
41- body : JSON . stringify ( subgraphQuery ) ,
42- headers : {
43- 'Content-Type' : 'application/json' ,
44- } ,
40+ const response = await fetch ( process . env . CURATE_GRAPH_URL , {
41+ method : 'POST ',
42+ body : JSON . stringify ( subgraphQuery ) ,
43+ headers : {
44+ 'Content-Type' : 'application/json' ,
45+ ... ( process . env . GRAPH_API_KEY
46+ ? { Authorization : `Bearer ${ process . env . GRAPH_API_KEY } ` }
47+ : { } ) ,
4548 } ,
46- )
49+ } )
4750
4851 const { data } = await response . json ( )
4952 const tags : Item [ ] = data . litems
@@ -86,19 +89,22 @@ export default async function getTokens(): Promise<TokenInfo[]> {
8689
8790 const tokens : Map < string , TokenInfo > = new Map ( )
8891 for ( const token of tokensFromSubgraph ) {
89- const caipAddress = token ?. metadata ?. props . find ( ( p ) => p . label === 'Address' )
92+ const caipAddress = token ?. metadata ?. props . find (
93+ ( p ) => p . label === 'Address' ,
94+ ) ?. value as string
95+ const name = token ?. metadata ?. props . find ( ( p ) => p . label === 'Name' )
9096 ?. value as string
91- const name = token ?. metadata ?. props . find ( ( p ) => p . label === 'Name' ) ?. value as string
9297 const symbol = token ?. metadata ?. props . find ( ( p ) => p . label === 'Symbol' )
9398 ?. value as string
94- const logo = token ?. metadata ?. props . find ( ( p ) => p . label === 'Logo' ) ?. value as string
99+ const logo = token ?. metadata ?. props . find ( ( p ) => p . label === 'Logo' )
100+ ?. value as string
95101 const decimals = token ?. metadata ?. props . find ( ( p ) => p . label === 'Decimals' )
96102 ?. value as string
97103
98104 if ( ! caipAddress || ! name || ! symbol || ! decimals ) {
99105 continue
100106 }
101-
107+
102108 const [ namespace ] = caipAddress . split ( ':' )
103109 if ( namespace !== 'eip155' ) {
104110 nonEvmTokens . push ( caipAddress )
0 commit comments