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