Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 17 additions & 31 deletions src/utils/get-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ export interface Prop {
}

export interface Item {
metadata: {
props: Prop[]
} | null
props: Prop[]
id: string
}

Expand All @@ -20,32 +18,23 @@ const fetchTokensBatch = async (id: string): Promise<Item[]> => {
}
const subgraphQuery = {
query: `
{
litems(where: {
registryAddress: "${process.env.KLEROS_TOKENS_REGISTRY_ADDRESS}",
status_in: [Registered, ClearingRequested],
id_gt: "${id}"
}, first: 1000) {
id
metadata {
props {
label
value
}
}
}
{
litems: LItem(
where: {registryAddress: {_eq: "${process.env.KLEROS_TOKENS_REGISTRY_ADDRESS}"}, status: {_in: [Registered, ClearingRequested]}, id: {_gt: "${id}}"}}
limit: 1000
) {
id
props {
label
value
}
}
}
`,
}
const response = await fetch(process.env.CURATE_GRAPH_URL, {
method: 'POST',
body: JSON.stringify(subgraphQuery),
headers: {
'Content-Type': 'application/json',
...(process.env.GRAPH_API_KEY
? { Authorization: `Bearer ${process.env.GRAPH_API_KEY}` }
: {}),
},
})

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

const tokens: Map<string, TokenInfo> = new Map()
for (const token of tokensFromSubgraph) {
const caipAddress = token?.metadata?.props.find(
(p) => p.label === 'Address',
)?.value as string
const name = token?.metadata?.props.find((p) => p.label === 'Name')
?.value as string
const symbol = token?.metadata?.props.find((p) => p.label === 'Symbol')
const caipAddress = token?.props.find((p) => p.label === 'Address')
?.value as string
const logo = token?.metadata?.props.find((p) => p.label === 'Logo')
const name = token?.props.find((p) => p.label === 'Name')?.value as string
const symbol = token?.props.find((p) => p.label === 'Symbol')
?.value as string
const decimals = token?.metadata?.props.find((p) => p.label === 'Decimals')
const logo = token?.props.find((p) => p.label === 'Logo')?.value as string
const decimals = token?.props.find((p) => p.label === 'Decimals')
?.value as string

if (!caipAddress || !name || !symbol || !decimals) {
Expand Down