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

Commit

Permalink
Merge pull request #2080 from solana-labs:agrippa/bonkedao-issue
Browse files Browse the repository at this point in the history
paginate DAS queries
  • Loading branch information
asktree authored Jan 24, 2024
2 parents 40bd6e2 + d8c0afb commit 41aaf73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
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

1 comment on commit 41aaf73

@vercel
Copy link

@vercel vercel bot commented on 41aaf73 Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

governance-ui – ./

app.realms.today
governance-ui-git-main-solana-labs.vercel.app
governance-ui-solana-labs.vercel.app

Please sign in to comment.