🐛 Allow > 10 accounts (#505)
This commit is contained in:
parent
308ec7dba4
commit
d0ce3eea45
@ -1,14 +1,29 @@
|
||||
import { getAccountNftQueryClient } from 'api/cosmwasm-client'
|
||||
import { ITEM_LIMIT_PER_QUERY } from 'constants/query'
|
||||
|
||||
export default async function getAccountIds(address?: string): Promise<string[]> {
|
||||
if (!address) return []
|
||||
const accountNftQueryClient = await getAccountNftQueryClient()
|
||||
export default async function getAccountIds(
|
||||
address?: string,
|
||||
previousResults?: string[],
|
||||
): Promise<string[]> {
|
||||
try {
|
||||
if (!address) return []
|
||||
const accountNftQueryClient = await getAccountNftQueryClient()
|
||||
|
||||
const data = await accountNftQueryClient.tokens({ owner: address })
|
||||
const lastItem = previousResults && previousResults.at(-1)
|
||||
const results = await accountNftQueryClient.tokens({
|
||||
limit: ITEM_LIMIT_PER_QUERY,
|
||||
startAfter: lastItem,
|
||||
owner: address,
|
||||
})
|
||||
|
||||
if (data.tokens) {
|
||||
return data.tokens.sort((a, b) => Number(a) - Number(b))
|
||||
const accumulated = (previousResults ?? []).concat(results.tokens)
|
||||
|
||||
if (results.tokens.length < ITEM_LIMIT_PER_QUERY) {
|
||||
return accumulated.sort((a, b) => parseInt(a) - parseInt(b))
|
||||
}
|
||||
|
||||
return await getAccountIds(address, accumulated)
|
||||
} catch {
|
||||
return new Promise((_, reject) => reject('No data'))
|
||||
}
|
||||
|
||||
return new Promise((_, reject) => reject('No data'))
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { ENV } from 'constants/env'
|
||||
|
||||
import { NETWORK } from 'types/enums/network'
|
||||
|
||||
export const MARS_MAINNET_DENOM =
|
||||
|
Loading…
Reference in New Issue
Block a user