1
1
import { Wallet } from '@coral-xyz/anchor'
2
+ import NodeWallet from '@coral-xyz/anchor/dist/cjs/nodewallet'
2
3
import {
3
4
AccountMeta ,
4
5
Cluster ,
5
6
Connection ,
7
+ Keypair ,
6
8
PublicKey ,
7
9
Transaction ,
8
10
} from '@solana/web3.js'
@@ -60,7 +62,6 @@ const getSortedProposals = async (
60
62
}
61
63
62
64
export const useMultisig = ( wallet : Wallet ) : MultisigHookData => {
63
- const connectionRef = useRef < Connection > ( )
64
65
const { cluster } = useContext ( ClusterContext )
65
66
const [ isLoading , setIsLoading ] = useState ( true )
66
67
const [ error , setError ] = useState ( null )
@@ -85,6 +86,22 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
85
86
setError ( null )
86
87
} , [ urlsIndex , cluster ] )
87
88
89
+ useEffect ( ( ) => {
90
+ const urls = pythClusterApiUrls ( getMultisigCluster ( cluster ) )
91
+ const connection = new Connection ( urls [ urlsIndex ] . rpcUrl , {
92
+ commitment : 'confirmed' ,
93
+ wsEndpoint : urls [ urlsIndex ] . wsUrl ,
94
+ } )
95
+ if ( wallet ) {
96
+ setSquads (
97
+ new SquadsMesh ( {
98
+ connection,
99
+ wallet,
100
+ } )
101
+ )
102
+ }
103
+ } , [ wallet , urlsIndex , cluster ] )
104
+
88
105
useEffect ( ( ) => {
89
106
let cancelled = false
90
107
const urls = pythClusterApiUrls ( getMultisigCluster ( cluster ) )
@@ -93,42 +110,24 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
93
110
wsEndpoint : urls [ urlsIndex ] . wsUrl ,
94
111
} )
95
112
96
- connectionRef . current = connection
97
113
; ( async ( ) => {
98
114
try {
99
115
// mock wallet to allow users to view proposals without connecting their wallet
100
- const signTransaction = ( ) =>
101
- new Promise < Transaction > ( ( resolve ) => {
102
- resolve ( new Transaction ( ) )
103
- } )
104
- const signAllTransactions = ( ) =>
105
- new Promise < Transaction [ ] > ( ( resolve ) => {
106
- resolve ( [ new Transaction ( ) ] )
107
- } )
108
- const squads = wallet
109
- ? new SquadsMesh ( {
110
- connection,
111
- wallet,
112
- } )
113
- : new SquadsMesh ( {
114
- connection,
115
- wallet : {
116
- signTransaction : ( ) => signTransaction ( ) ,
117
- signAllTransactions : ( ) => signAllTransactions ( ) ,
118
- publicKey : new PublicKey ( 0 ) ,
119
- } ,
120
- } )
116
+ const readOnlySquads = new SquadsMesh ( {
117
+ connection,
118
+ wallet : new NodeWallet ( new Keypair ( ) ) ,
119
+ } )
121
120
if ( cancelled ) return
122
121
setUpgradeMultisigAccount (
123
- await squads . getMultisig (
122
+ await readOnlySquads . getMultisig (
124
123
UPGRADE_MULTISIG [ getMultisigCluster ( cluster ) ]
125
124
)
126
125
)
127
126
try {
128
127
if ( cancelled ) return
129
128
// DELETE THIS TRY CATCH ONCE THIS MULTISIG EXISTS EVERYWHERE
130
129
setpriceFeedMultisigAccount (
131
- await squads . getMultisig (
130
+ await readOnlySquads . getMultisig (
132
131
PRICE_FEED_MULTISIG [ getMultisigCluster ( cluster ) ]
133
132
)
134
133
)
@@ -140,19 +139,19 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
140
139
if ( cancelled ) return
141
140
setUpgradeMultisigProposals (
142
141
await getSortedProposals (
143
- squads ,
142
+ readOnlySquads ,
144
143
UPGRADE_MULTISIG [ getMultisigCluster ( cluster ) ]
145
144
)
146
145
)
147
146
try {
148
147
if ( cancelled ) return
149
148
// DELETE THIS TRY CATCH ONCE THIS MULTISIG EXISTS EVERYWHERE
150
149
const sortedPriceFeedMultisigProposals = await getSortedProposals (
151
- squads ,
150
+ readOnlySquads ,
152
151
PRICE_FEED_MULTISIG [ getMultisigCluster ( cluster ) ]
153
152
)
154
153
const allProposalsIxs = await getManyProposalsInstructions (
155
- squads ,
154
+ readOnlySquads ,
156
155
sortedPriceFeedMultisigProposals
157
156
)
158
157
const multisigParser = MultisigParser . fromCluster (
@@ -199,7 +198,6 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
199
198
setpriceFeedMultisigProposals ( [ ] )
200
199
}
201
200
202
- setSquads ( squads )
203
201
setIsLoading ( false )
204
202
} catch ( e ) {
205
203
console . log ( e )
@@ -221,7 +219,7 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
221
219
return ( ) => {
222
220
cancelled = true
223
221
}
224
- } , [ urlsIndex , cluster , wallet ] )
222
+ } , [ urlsIndex , cluster ] )
225
223
226
224
return {
227
225
isLoading,
0 commit comments