Skip to content

Commit d27d9c4

Browse files
committed
chore: envio-query-migration
1 parent 86ecf36 commit d27d9c4

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

src/utils/get-tokens.ts

Lines changed: 17 additions & 31 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,32 +18,23 @@ 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),
43-
headers: {
44-
'Content-Type': 'application/json',
45-
...(process.env.GRAPH_API_KEY
46-
? { Authorization: `Bearer ${process.env.GRAPH_API_KEY}` }
47-
: {}),
48-
},
4938
})
5039

5140
const { data } = await response.json()
@@ -89,16 +78,13 @@ export default async function getTokens(): Promise<TokenInfo[]> {
8978

9079
const tokens: Map<string, TokenInfo> = new Map()
9180
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')
81+
const caipAddress = token?.props.find((p) => p.label === 'Address')
9882
?.value as string
99-
const logo = token?.metadata?.props.find((p) => p.label === 'Logo')
83+
const name = token?.props.find((p) => p.label === 'Name')?.value as string
84+
const symbol = token?.props.find((p) => p.label === 'Symbol')
10085
?.value as string
101-
const decimals = token?.metadata?.props.find((p) => p.label === 'Decimals')
86+
const logo = token?.props.find((p) => p.label === 'Logo')?.value as string
87+
const decimals = token?.props.find((p) => p.label === 'Decimals')
10288
?.value as string
10389

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

0 commit comments

Comments
 (0)