Skip to content

Commit 590d5b0

Browse files
authored
[xc-admin-frontend] Stop reloading proposals when you connect a wallet (#670)
* Make wallet simpler * Fix
1 parent 64255d4 commit 590d5b0

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

governance/xc_admin/packages/xc_admin_frontend/hooks/useMultisig.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Wallet } from '@coral-xyz/anchor'
2+
import NodeWallet from '@coral-xyz/anchor/dist/cjs/nodewallet'
23
import {
34
AccountMeta,
45
Cluster,
56
Connection,
7+
Keypair,
68
PublicKey,
79
Transaction,
810
} from '@solana/web3.js'
@@ -60,7 +62,6 @@ const getSortedProposals = async (
6062
}
6163

6264
export const useMultisig = (wallet: Wallet): MultisigHookData => {
63-
const connectionRef = useRef<Connection>()
6465
const { cluster } = useContext(ClusterContext)
6566
const [isLoading, setIsLoading] = useState(true)
6667
const [error, setError] = useState(null)
@@ -85,6 +86,22 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
8586
setError(null)
8687
}, [urlsIndex, cluster])
8788

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+
88105
useEffect(() => {
89106
let cancelled = false
90107
const urls = pythClusterApiUrls(getMultisigCluster(cluster))
@@ -93,42 +110,24 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
93110
wsEndpoint: urls[urlsIndex].wsUrl,
94111
})
95112

96-
connectionRef.current = connection
97113
;(async () => {
98114
try {
99115
// 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+
})
121120
if (cancelled) return
122121
setUpgradeMultisigAccount(
123-
await squads.getMultisig(
122+
await readOnlySquads.getMultisig(
124123
UPGRADE_MULTISIG[getMultisigCluster(cluster)]
125124
)
126125
)
127126
try {
128127
if (cancelled) return
129128
// DELETE THIS TRY CATCH ONCE THIS MULTISIG EXISTS EVERYWHERE
130129
setpriceFeedMultisigAccount(
131-
await squads.getMultisig(
130+
await readOnlySquads.getMultisig(
132131
PRICE_FEED_MULTISIG[getMultisigCluster(cluster)]
133132
)
134133
)
@@ -140,19 +139,19 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
140139
if (cancelled) return
141140
setUpgradeMultisigProposals(
142141
await getSortedProposals(
143-
squads,
142+
readOnlySquads,
144143
UPGRADE_MULTISIG[getMultisigCluster(cluster)]
145144
)
146145
)
147146
try {
148147
if (cancelled) return
149148
// DELETE THIS TRY CATCH ONCE THIS MULTISIG EXISTS EVERYWHERE
150149
const sortedPriceFeedMultisigProposals = await getSortedProposals(
151-
squads,
150+
readOnlySquads,
152151
PRICE_FEED_MULTISIG[getMultisigCluster(cluster)]
153152
)
154153
const allProposalsIxs = await getManyProposalsInstructions(
155-
squads,
154+
readOnlySquads,
156155
sortedPriceFeedMultisigProposals
157156
)
158157
const multisigParser = MultisigParser.fromCluster(
@@ -199,7 +198,6 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
199198
setpriceFeedMultisigProposals([])
200199
}
201200

202-
setSquads(squads)
203201
setIsLoading(false)
204202
} catch (e) {
205203
console.log(e)
@@ -221,7 +219,7 @@ export const useMultisig = (wallet: Wallet): MultisigHookData => {
221219
return () => {
222220
cancelled = true
223221
}
224-
}, [urlsIndex, cluster, wallet])
222+
}, [urlsIndex, cluster])
225223

226224
return {
227225
isLoading,

0 commit comments

Comments
 (0)