11import { Wallet } from '@coral-xyz/anchor'
22import { 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'
44import SquadsMesh from '@sqds/mesh'
55import { TransactionAccount } from '@sqds/mesh/lib/types'
66import { 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