Skip to content
This repository has been archived by the owner on Feb 9, 2025. It is now read-only.

paginate DAS queries #2080

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
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
45 changes: 28 additions & 17 deletions hooks/queries/digitalAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,35 @@ const dasByOwnerQueryFn = async (network: Network, owner: PublicKey) => {

// https://docs.helius.xyz/solana-compression/digital-asset-standard-das-api/get-assets-by-owner

const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 'Realms user',
method: 'getAssetsByOwner',
params: {
ownerAddress: owner.toString(),
page: 1, // Starts at 1
limit: 1000, // TODO support having >1k nfts
const PAGE_LIMIT = 1000
const items: DasNftObject[] = []
let moreNftsRemaining = true
let page = 1

while (moreNftsRemaining) {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
}),
})
const { result } = await response.json()
return result.items as DasNftObject[]
body: JSON.stringify({
jsonrpc: '2.0',
id: 'Realms user',
method: 'getAssetsByOwner',
params: {
ownerAddress: owner.toString(),
page, // Starts at 1
limit: PAGE_LIMIT,
},
}),
})
const { result } = await response.json()
const pageItems = result.items as DasNftObject[]
items.push(...pageItems)
page++
if (pageItems.length < PAGE_LIMIT) moreNftsRemaining = false
}
return items
}

export const fetchDigitalAssetsByOwner = (network: Network, owner: PublicKey) =>
Expand Down
1 change: 1 addition & 0 deletions hooks/queries/plugins/nftVoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const useVotingNfts = (ownerPk: PublicKey | undefined) => {
const { connection } = useConnection()
const realmPk = useSelectedRealmPubkey()
const { data: nfts } = useDigitalAssetsByOwner(ownerPk)
console.log('nfts', nfts)

const registrar = useQuery(nftRegistrarQuery(connection, realmPk)).data
?.result
Expand Down
Loading