Skip to content

Commit

Permalink
Merge pull request #52 from pyth-network/feedback
Browse files Browse the repository at this point in the history
Address some feedback
  • Loading branch information
Dev Kalra authored Nov 28, 2023
2 parents 64c9447 + 352ef9d commit e7140f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
21 changes: 15 additions & 6 deletions hooks/useVotingPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function useVotingPlugins() {
handleSetNftRegistrar,
handleSetGatewayRegistrar,
handleSetCurrentRealmVotingClient,
handleSetPythClient
handleSetPythClient,
} = useVotePluginsClientStore()

const [
Expand All @@ -69,7 +69,7 @@ export function useVotingPlugins() {
nftClient,
nftMintRegistrar,
heliumVsrClient,
pythClient
pythClient,
] = useVotePluginsClientStore((s) => [
s.state.currentRealmVotingClient,
s.state.vsrClient,
Expand Down Expand Up @@ -132,6 +132,18 @@ export function useVotingPlugins() {
[usedCollectionsPks]
)

// initialise pyth plugin
useEffect(() => {
if (
wallet &&
connection &&
currentPluginPk &&
PYTH_PLUGIN_PK.includes(currentPluginPk.toBase58())
) {
handleSetPythClient(wallet, connection)
}
}, [connection, currentPluginPk, handleSetPythClient, wallet])

useEffect(() => {
if (wallet && connection) {
if (currentPluginPk) {
Expand All @@ -141,9 +153,6 @@ export function useVotingPlugins() {
if (HELIUM_VSR_PLUGINS_PKS.includes(currentPluginPk.toBase58())) {
handleSetHeliumVsrClient(wallet, connection, currentPluginPk)
}
if (PYTH_PLUGIN_PK.includes(currentPluginPk.toBase58())) {
handleSetPythClient(wallet, connection)
}
}
handleSetNftClient(wallet, connection)
handleSetGatewayClient(wallet, connection)
Expand All @@ -155,7 +164,6 @@ export function useVotingPlugins() {
handleSetHeliumVsrClient,
handleSetNftClient,
handleSetVsrClient,
handleSetPythClient,
wallet,
])

Expand Down Expand Up @@ -280,6 +288,7 @@ export function useVotingPlugins() {
voterPk,
realm,
vsrClient,
pythClient,
])

const handleMaxVoterWeight = useCallback(async () => {
Expand Down
24 changes: 14 additions & 10 deletions utils/uiTypes/VotePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class VotingClient {
tokenOwnerRecord: PublicKey,
type: UpdateVoterWeightRecordTypes,
createNftActionTicketIxs?: TransactionInstruction[],
voterWeightTarget?: PublicKey
pythVoterWeightTarget?: PublicKey
): Promise<ProgramAddresses | undefined> => {
if (this.noClient) return

Expand Down Expand Up @@ -215,7 +215,11 @@ export class VotingClient {
)

for (const pos of this.heliumVsrVotingPositions) {
const tokenAccount = await getAssociatedTokenAddress(pos.mint, walletPk, true)
const tokenAccount = await getAssociatedTokenAddress(
pos.mint,
walletPk,
true
)

remainingAccounts.push(
new AccountData(tokenAccount),
Expand Down Expand Up @@ -325,9 +329,7 @@ export class VotingClient {
return { voterWeightPk, maxVoterWeightRecord: undefined }
}
if (this.client instanceof PythClient) {
const stakeAccount = await this.client!.getMainAccount(
walletPk
)
const stakeAccount = await this.client!.getMainAccount(walletPk)

const {
voterWeightAccount,
Expand All @@ -336,7 +338,7 @@ export class VotingClient {
instructions,
stakeAccount!,
{ [type]: {} },
voterWeightTarget
pythVoterWeightTarget
)

return {
Expand Down Expand Up @@ -424,7 +426,11 @@ export class VotingClient {

for (let i = 0; i < unusedPositions.length; i++) {
const pos = unusedPositions[i]
const tokenAccount = await getAssociatedTokenAddress(pos.mint, walletPk, true)
const tokenAccount = await getAssociatedTokenAddress(
pos.mint,
walletPk,
true
)
const [nftVoteRecord] = nftVoteRecordKey(
proposal.pubkey,
pos.mint,
Expand Down Expand Up @@ -463,9 +469,7 @@ export class VotingClient {
}

if (this.client instanceof PythClient) {
const stakeAccount = await this.client!.getMainAccount(
walletPk
)
const stakeAccount = await this.client!.getMainAccount(walletPk)

const {
voterWeightAccount,
Expand Down

0 comments on commit e7140f9

Please sign in to comment.