Skip to content

Commit

Permalink
optimize TOR fetch for council-only display (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShuk authored Jun 19, 2024
1 parent b043b58 commit 6f282aa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hooks/queries/tokenOwnerRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import useLegacyConnectionContext from '@hooks/useLegacyConnectionContext'
import useWalletOnePointOh from '@hooks/useWalletOnePointOh'
import queryClient from './queryClient'
import mainnetBetaRealms from 'public/realms/mainnet-beta.json'
import { determineVotingPowerType } from './governancePower'

export const tokenOwnerRecordQueryKeys = {
all: (endpoint: string) => [endpoint, 'TokenOwnerRecord'],
Expand Down Expand Up @@ -107,11 +108,19 @@ export const useTokenOwnerRecordsForRealmQuery = () => {
const filter = pubkeyFilter(1, realm.pubkey)
if (!filter) throw new Error() // unclear why this would ever happen, probably it just cannot

const votingType = await determineVotingPowerType(connection.current, realm.pubkey, "community")
const councilOnly = !(votingType === 'vanilla' || votingType === 'NFT')
const councilMint = realm.account.config.councilMint

const mintFilter = councilOnly && councilMint ?
pubkeyFilter(33, councilMint) :
null

const results = await getGovernanceAccounts(
connection.current,
realm.owner,
TokenOwnerRecord,
[filter]
mintFilter ? [filter, mintFilter] : [filter]
)

// This may or may not be resource intensive for big DAOs, and is not too useful
Expand Down

0 comments on commit 6f282aa

Please sign in to comment.