Skip to content

Commit 4331452

Browse files
committed
[wip] fix multisig hook
1 parent 4d60406 commit 4331452

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

governance/xc-admin/packages/xc-admin-frontend/components/tabs/UpdatePermissions.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ const UpdatePermissions = () => {
9292
const [pubkeyChanges, setPubkeyChanges] = useState<PubkeyChanges>({})
9393
const [editable, setEditable] = useState(false)
9494
const { cluster, setCluster } = useContext(ClusterContext)
95+
const anchorWallet = useAnchorWallet()
9596
const {
9697
isLoading: isMultisigLoading,
9798
error,
9899
squads,
99100
proposals,
100-
} = useMultisig()
101+
} = useMultisig(anchorWallet as Wallet)
101102
const { rawConfig, dataIsLoading, connection } = usePythContext()
102-
const anchorWallet = useAnchorWallet()
103103
const { publicKey, connected } = useWallet()
104104
const [pythProgramClient, setPythProgramClient] =
105105
useState<Program<PythOracle>>()
@@ -129,10 +129,6 @@ const UpdatePermissions = () => {
129129
}
130130
}, [dataIsLoading, rawConfig])
131131

132-
// useEffect(() => {
133-
// console.log(pubkeyChanges)
134-
// }, [pubkeyChanges])
135-
136132
const table = useReactTable({
137133
data,
138134
columns,
@@ -189,7 +185,7 @@ const UpdatePermissions = () => {
189185
}
190186
})
191187
}
192-
console.log(newPubkeyChanges['Master Authority'])
188+
console.log(newPubkeyChanges)
193189
pythProgramClient?.methods
194190
.updPermissions(
195191
new PublicKey(newPubkeyChanges['Master Authority'].newPubkey),

governance/xc-admin/packages/xc-admin-frontend/hooks/useMultisig.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Wallet } from '@coral-xyz/anchor'
22
import { PythCluster } from '@pythnetwork/client/lib/cluster'
3-
import { Cluster, Connection, Keypair, PublicKey } from '@solana/web3.js'
3+
import { Cluster, Connection, PublicKey } from '@solana/web3.js'
44
import SquadsMesh from '@sqds/mesh'
55
import { TransactionAccount } from '@sqds/mesh/lib/types'
66
import { useContext, useEffect, useRef, useState } from 'react'
@@ -33,7 +33,7 @@ interface MultisigHookData {
3333
proposals: TransactionAccount[]
3434
}
3535

36-
export const useMultisig = (): MultisigHookData => {
36+
export const useMultisig = (wallet: Wallet): MultisigHookData => {
3737
const connectionRef = useRef<Connection>()
3838
const { cluster } = useContext(ClusterContext)
3939
const [isLoading, setIsLoading] = useState(true)
@@ -57,37 +57,41 @@ export const useMultisig = (): MultisigHookData => {
5757

5858
connectionRef.current = connection
5959
;(async () => {
60-
try {
61-
const squads = new SquadsMesh({
62-
connection,
63-
wallet: new Keypair() as unknown as Wallet,
64-
})
65-
setProposals(
66-
await getProposals(
67-
squads,
68-
UPGRADE_MUTLTISIG[getMultisigCluster(cluster)]
60+
if (wallet) {
61+
try {
62+
const squads = new SquadsMesh({
63+
connection,
64+
wallet,
65+
})
66+
setProposals(
67+
await getProposals(
68+
squads,
69+
UPGRADE_MUTLTISIG[getMultisigCluster(cluster)]
70+
)
6971
)
70-
)
71-
setSquads(squads)
72-
setIsLoading(false)
73-
} catch (e) {
74-
if (cancelled) return
75-
if (urlsIndex === urls.length - 1) {
76-
// @ts-ignore
77-
setError(e)
72+
setSquads(squads)
7873
setIsLoading(false)
79-
console.warn(`Failed to fetch accounts`)
80-
} else if (urlsIndex < urls.length - 1) {
81-
setUrlsIndex((urlsIndex) => urlsIndex + 1)
82-
console.warn(
83-
`Failed with ${urls[urlsIndex]}, trying with ${urls[urlsIndex + 1]}`
84-
)
74+
} catch (e) {
75+
if (cancelled) return
76+
if (urlsIndex === urls.length - 1) {
77+
// @ts-ignore
78+
setError(e)
79+
setIsLoading(false)
80+
console.warn(`Failed to fetch accounts`)
81+
} else if (urlsIndex < urls.length - 1) {
82+
setUrlsIndex((urlsIndex) => urlsIndex + 1)
83+
console.warn(
84+
`Failed with ${urls[urlsIndex]}, trying with ${
85+
urls[urlsIndex + 1]
86+
}`
87+
)
88+
}
8589
}
8690
}
8791
})()
8892

8993
return () => {}
90-
}, [urlsIndex, cluster])
94+
}, [urlsIndex, cluster, wallet])
9195

9296
return {
9397
isLoading,

0 commit comments

Comments
 (0)