Skip to content

Commit 451f099

Browse files
Merge pull request #20 from tractorss/chore/envio-query-migration
chore: envio-query-migration
2 parents 86ecf36 + 8399734 commit 451f099

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

src/utils/get-tokens.ts

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ export interface Prop {
88
}
99

1010
export interface Item {
11-
metadata: {
12-
props: Prop[]
13-
} | null
11+
props: Prop[]
1412
id: string
1513
}
1614

@@ -20,31 +18,25 @@ const fetchTokensBatch = async (id: string): Promise<Item[]> => {
2018
}
2119
const subgraphQuery = {
2220
query: `
23-
{
24-
litems(where: {
25-
registryAddress: "${process.env.KLEROS_TOKENS_REGISTRY_ADDRESS}",
26-
status_in: [Registered, ClearingRequested],
27-
id_gt: "${id}"
28-
}, first: 1000) {
29-
id
30-
metadata {
31-
props {
32-
label
33-
value
34-
}
35-
}
36-
}
21+
{
22+
litems: LItem(
23+
where: {registryAddress: {_eq: "${process.env.KLEROS_TOKENS_REGISTRY_ADDRESS}"}, status: {_in: [Registered, ClearingRequested]}, id: {_gt: "${id}}"}}
24+
limit: 1000
25+
) {
26+
id
27+
props {
28+
label
29+
value
3730
}
31+
}
32+
}
3833
`,
3934
}
4035
const response = await fetch(process.env.CURATE_GRAPH_URL, {
4136
method: 'POST',
4237
body: JSON.stringify(subgraphQuery),
4338
headers: {
4439
'Content-Type': 'application/json',
45-
...(process.env.GRAPH_API_KEY
46-
? { Authorization: `Bearer ${process.env.GRAPH_API_KEY}` }
47-
: {}),
4840
},
4941
})
5042

@@ -89,16 +81,13 @@ export default async function getTokens(): Promise<TokenInfo[]> {
8981

9082
const tokens: Map<string, TokenInfo> = new Map()
9183
for (const token of tokensFromSubgraph) {
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')
96-
?.value as string
97-
const symbol = token?.metadata?.props.find((p) => p.label === 'Symbol')
84+
const caipAddress = token?.props.find((p) => p.label === 'Address')
9885
?.value as string
99-
const logo = token?.metadata?.props.find((p) => p.label === 'Logo')
86+
const name = token?.props.find((p) => p.label === 'Name')?.value as string
87+
const symbol = token?.props.find((p) => p.label === 'Symbol')
10088
?.value as string
101-
const decimals = token?.metadata?.props.find((p) => p.label === 'Decimals')
89+
const logo = token?.props.find((p) => p.label === 'Logo')?.value as string
90+
const decimals = token?.props.find((p) => p.label === 'Decimals')
10291
?.value as string
10392

10493
if (!caipAddress || !name || !symbol || !decimals) {

0 commit comments

Comments
 (0)