Skip to content

Commit

Permalink
fix undefined plugin issue (#2389)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShuk authored Jul 23, 2024
1 parent c04bfb7 commit 8e540e9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
7 changes: 5 additions & 2 deletions ParclVotePlugin/ParclVoterWeightPluginClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ export class ParclVoterWeightPluginClient extends Client<any> {
return null;
}

private async getStakeAccount(voter: PublicKey): Promise<StakeAccount> {
private async getStakeAccount(voter: PublicKey): Promise<StakeAccount | null> {
return queryClient.fetchQuery({
queryKey: ['parcl getStakeAccount', voter],
queryFn: () => this.client.getMainAccount(voter),
queryFn: async() => {
const account = await this.client.getMainAccount(voter)
return account !== undefined ? account : null
},
})
}

Expand Down
57 changes: 33 additions & 24 deletions VoterWeightPlugins/hooks/usePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,41 @@ export const usePlugins = (args: Args): UseQueryResult<VoterWeightPlugins, unkno
voterWeight: [],
maxVoterWeight: []
};
// Load the voter weight plugins associated with the realm and governance
const voterWeightPluginsPromise = getPlugins({
...(args as Required<Args>),
provider,
type: 'voterWeight',
wallets: args.walletPublicKeys,
signer
});
// Load the max voter weight plugins associated with the realm and governance
const maxVoterWeightPluginsPromise = getPlugins({
...(args as Required<Args>),
provider,
type: 'maxVoterWeight',
wallets: args.walletPublicKeys,
signer
});

const [voterWeightPlugins, maxVoterWeightPlugins] = await Promise.all([
voterWeightPluginsPromise,
maxVoterWeightPluginsPromise
]);
try {
// Load the voter weight plugins associated with the realm and governance
const voterWeightPluginsPromise = getPlugins({
...(args as Required<Args>),
provider,
type: 'voterWeight',
wallets: args.walletPublicKeys,
signer
});
// Load the max voter weight plugins associated with the realm and governance
const maxVoterWeightPluginsPromise = getPlugins({
...(args as Required<Args>),
provider,
type: 'maxVoterWeight',
wallets: args.walletPublicKeys,
signer
});

return {
voterWeight: voterWeightPlugins,
maxVoterWeight: maxVoterWeightPlugins
};
const [voterWeightPlugins, maxVoterWeightPlugins] = await Promise.all([
voterWeightPluginsPromise,
maxVoterWeightPluginsPromise
]);

return {
voterWeight: voterWeightPlugins,
maxVoterWeight: maxVoterWeightPlugins
};
} catch {
return {
voterWeight: [],
maxVoterWeight: []
};
}

},
{
enabled: argsAreSet(args),
Expand Down

0 comments on commit 8e540e9

Please sign in to comment.