Skip to content

Commit

Permalink
Add API wrapper to fetch token token list
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Jun 16, 2023
1 parent 6327820 commit dfca051
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/oasis-indexer/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ declare module './generated/api' {
ticker: NativeTicker
tokenBalances: Record<EvmTokenType, generated.RuntimeEvmBalance[]>
}

export interface EvmToken {
network: Network
layer: Layer
}
}

export const isAccountEmpty = (account: RuntimeAccount) => {
Expand Down Expand Up @@ -569,3 +574,37 @@ export const useGetRuntimeEvents: typeof _f14 = (network, runtime, params, optio
},
})
}

const _f15 = wrapWithNetwork(generated.useGetRuntimeEvmTokens)

export const useGetRuntimeEvmTokens: typeof _f15 = (network, runtime, params, options) => {
return generated.useGetRuntimeEvmTokens(runtime, params, {
...options,
query: {
...options?.query,
queryKey: [network, ...generated.getGetRuntimeEvmTokensQueryKey(runtime, params)],
},
axios: {
...options?.axios,
...getBaseUrlParamFor(network),
transformResponse: [
...arrayify(axios.defaults.transformResponse),
(data: generated.EvmTokenList, headers, status) => {
if (status !== 200) return data
return {
...data,
evm_tokens: data.evm_tokens.map(token => {
return {
...token,
evm_contract_addr: `0x${token.evm_contract_addr}`,
layer: runtime,
network,
}
}),
}
},
...arrayify(options?.axios?.transformResponse),
],
},
})
}

0 comments on commit dfca051

Please sign in to comment.