Skip to content

Commit fbd004f

Browse files
authored
[xc-admin-frontend] Xc admin minor fixes (#968)
* Simplify refresh logic * Bump wormhole-sdk version to include new chain names
1 parent 0e018b4 commit fbd004f

File tree

5 files changed

+884
-121
lines changed

5 files changed

+884
-121
lines changed

governance/xc_admin/packages/xc_admin_common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test": "jest"
2121
},
2222
"dependencies": {
23-
"@certusone/wormhole-sdk": "^0.9.8",
23+
"@certusone/wormhole-sdk": "^0.9.22",
2424
"@coral-xyz/anchor": "^0.26.0",
2525
"@pythnetwork/client": "^2.17.0",
2626
"@pythnetwork/pyth-sdk-solidity": "*",

governance/xc_admin/packages/xc_admin_frontend/components/tabs/Proposals.tsx

Lines changed: 37 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ import {
5353
import { getMappingCluster, isPubkey } from '../InstructionViews/utils'
5454
const ProposalRow = ({
5555
proposal,
56-
setCurrentProposalPubkey,
5756
multisig,
5857
}: {
5958
proposal: TransactionAccount
60-
setCurrentProposalPubkey: Dispatch<SetStateAction<string | undefined>>
6159
multisig: MultisigAccount | undefined
6260
}) => {
6361
const status = getProposalStatus(proposal, multisig)
@@ -67,7 +65,6 @@ const ProposalRow = ({
6765
const handleClickIndividualProposal = useCallback(
6866
(proposalPubkey: string) => {
6967
router.query.proposal = proposalPubkey
70-
setCurrentProposalPubkey(proposalPubkey)
7168
router.push(
7269
{
7370
pathname: router.pathname,
@@ -77,7 +74,7 @@ const ProposalRow = ({
7774
{ scroll: true }
7875
)
7976
},
80-
[setCurrentProposalPubkey, router]
77+
[router]
8178
)
8279
return (
8380
<div
@@ -226,55 +223,35 @@ type ProposalType = 'priceFeed' | 'governance'
226223

227224
const Proposal = ({
228225
proposal,
229-
proposalIndex,
230226
multisig,
231-
proposalType,
232227
}: {
233228
proposal: TransactionAccount | undefined
234-
proposalIndex: number
235229
multisig: MultisigAccount | undefined
236-
proposalType: ProposalType
237230
}) => {
238-
const [currentProposal, setCurrentProposal] = useState<TransactionAccount>()
239231
const [instructions, setInstructions] = useState<MultisigInstruction[]>([])
240232
const [isTransactionLoading, setIsTransactionLoading] = useState(false)
241233
const { cluster } = useContext(ClusterContext)
242234

243235
const {
244236
voteSquads,
245237
isLoading: isMultisigLoading,
246-
setpriceFeedMultisigProposals,
247238
connection,
239+
refreshData,
248240
} = useMultisigContext()
249241
const {
250242
priceAccountKeyToSymbolMapping,
251243
productAccountKeyToSymbolMapping,
252244
publisherKeyToNameMapping,
253-
multisigSignerKeyToNameMapping,
254245
} = usePythContext()
255246
const publisherKeyToNameMappingCluster =
256247
publisherKeyToNameMapping[getMappingCluster(cluster)]
257248
const { publicKey: signerPublicKey } = useWallet()
258249

259-
useEffect(() => {
260-
setCurrentProposal(proposal)
261-
}, [proposal])
262-
263250
const proposalStatus = getProposalStatus(proposal, multisig)
264251

265-
useEffect(() => {
266-
// update the priceFeedMultisigProposals with previous value but replace the current proposal with the updated one at the specific index
267-
if (currentProposal) {
268-
setpriceFeedMultisigProposals((prevProposals: TransactionAccount[]) => {
269-
prevProposals.splice(proposalIndex, 1, currentProposal)
270-
return [...prevProposals]
271-
})
272-
}
273-
}, [currentProposal, setpriceFeedMultisigProposals, proposalIndex])
274-
275252
const verified =
276-
currentProposal &&
277-
Object.keys(currentProposal.status)[0] !== 'draft' &&
253+
proposal &&
254+
Object.keys(proposal.status)[0] !== 'draft' &&
278255
instructions.length > 0 &&
279256
instructions.every(
280257
(ix) =>
@@ -300,27 +277,28 @@ const Proposal = ({
300277
)
301278

302279
const voted =
303-
currentProposal &&
280+
proposal &&
304281
signerPublicKey &&
305-
(currentProposal.approved.some(
282+
(proposal.approved.some(
306283
(p) => p.toBase58() === signerPublicKey.toBase58()
307284
) ||
308-
currentProposal.cancelled.some(
285+
proposal.cancelled.some(
309286
(p) => p.toBase58() === signerPublicKey.toBase58()
310287
) ||
311-
currentProposal.rejected.some(
288+
proposal.rejected.some(
312289
(p) => p.toBase58() === signerPublicKey.toBase58()
313290
))
314291

315292
useEffect(() => {
293+
let isCancelled = false
316294
const fetchInstructions = async () => {
317-
if (currentProposal && connection) {
295+
if (proposal && connection) {
318296
const readOnlySquads = new SquadsMesh({
319297
connection,
320298
wallet: new NodeWallet(new Keypair()),
321299
})
322300
const proposalInstructions = (
323-
await getManyProposalsInstructions(readOnlySquads, [currentProposal])
301+
await getManyProposalsInstructions(readOnlySquads, [proposal])
324302
)[0]
325303
const multisigParser = MultisigParser.fromCluster(
326304
getMultisigCluster(cluster)
@@ -332,13 +310,16 @@ const Proposal = ({
332310
keys: ix.keys as AccountMeta[],
333311
})
334312
)
335-
setInstructions(parsedInstructions)
313+
if (!isCancelled) setInstructions(parsedInstructions)
336314
} else {
337-
setInstructions([])
315+
if (!isCancelled) setInstructions([])
338316
}
339317
}
340318
fetchInstructions().catch(console.error)
341-
}, [cluster, currentProposal, voteSquads, connection])
319+
return () => {
320+
isCancelled = true
321+
}
322+
}, [cluster, proposal, voteSquads, connection])
342323

343324
const handleClick = async (
344325
handler: (squad: SquadsMesh, proposalKey: PublicKey) => any,
@@ -348,19 +329,7 @@ const Proposal = ({
348329
try {
349330
setIsTransactionLoading(true)
350331
await handler(voteSquads, proposal.publicKey)
351-
const proposals = await getProposals(
352-
voteSquads,
353-
proposalType === 'priceFeed'
354-
? PRICE_FEED_MULTISIG[getMultisigCluster(cluster)]
355-
: UPGRADE_MULTISIG[getMultisigCluster(cluster)]
356-
)
357-
setCurrentProposal(
358-
proposals.find(
359-
(proposal) =>
360-
proposal.publicKey.toBase58() ===
361-
currentProposal?.publicKey.toBase58()
362-
)
363-
)
332+
if (refreshData) await refreshData().fetchData()
364333
toast.success(msg)
365334
} catch (e: any) {
366335
toast.error(capitalizeFirstLetter(e.message))
@@ -394,7 +363,7 @@ const Proposal = ({
394363
}, `Cancelled proposal ${proposal?.publicKey.toBase58()}`)
395364
}
396365

397-
return currentProposal !== undefined &&
366+
return proposal !== undefined &&
398367
multisig !== undefined &&
399368
!isMultisigLoading ? (
400369
<div className="grid grid-cols-3 gap-4">
@@ -417,15 +386,15 @@ const Proposal = ({
417386
</div>
418387
<div className="flex justify-between">
419388
<div>Proposal</div>
420-
<CopyPubkey pubkey={currentProposal.publicKey.toBase58()} />
389+
<CopyPubkey pubkey={proposal.publicKey.toBase58()} />
421390
</div>
422391
<div className="flex justify-between">
423392
<div>Creator</div>
424-
<CopyPubkey pubkey={currentProposal.creator.toBase58()} />
393+
<CopyPubkey pubkey={proposal.creator.toBase58()} />
425394
</div>
426395
<div className="flex justify-between">
427396
<div>Multisig</div>
428-
<CopyPubkey pubkey={currentProposal.ms.toBase58()} />
397+
<CopyPubkey pubkey={proposal.ms.toBase58()} />
429398
</div>
430399
</div>
431400
<div className="col-span-3 my-2 space-y-4 bg-[#1E1B2F] p-4 lg:col-span-1">
@@ -434,17 +403,17 @@ const Proposal = ({
434403
<div className="grid grid-cols-3 justify-center gap-4 text-center align-middle">
435404
<div>
436405
<div className="font-bold">Confirmed</div>
437-
<div className="text-lg">{currentProposal.approved.length}</div>
406+
<div className="text-lg">{proposal.approved.length}</div>
438407
</div>
439408
{proposalStatus === 'active' || proposalStatus === 'rejected' ? (
440409
<div>
441410
<div className="font-bold">Rejected</div>
442-
<div className="text-lg">{currentProposal.rejected.length}</div>
411+
<div className="text-lg">{proposal.rejected.length}</div>
443412
</div>
444413
) : (
445414
<div>
446415
<div className="font-bold">Cancelled</div>
447-
<div className="text-lg">{currentProposal.cancelled.length}</div>
416+
<div className="text-lg">{proposal.cancelled.length}</div>
448417
</div>
449418
)}
450419
<div>
@@ -490,17 +459,14 @@ const Proposal = ({
490459
</div>
491460
) : null}
492461
</div>
493-
{currentProposal.approved.length > 0 && (
494-
<AccountList listName="Confirmed" accounts={currentProposal.approved} />
462+
{proposal.approved.length > 0 && (
463+
<AccountList listName="Confirmed" accounts={proposal.approved} />
495464
)}
496-
{currentProposal.rejected.length > 0 && (
497-
<AccountList listName="Rejected" accounts={currentProposal.rejected} />
465+
{proposal.rejected.length > 0 && (
466+
<AccountList listName="Rejected" accounts={proposal.rejected} />
498467
)}
499-
{currentProposal.cancelled.length > 0 && (
500-
<AccountList
501-
listName="Cancelled"
502-
accounts={currentProposal.cancelled}
503-
/>
468+
{proposal.cancelled.length > 0 && (
469+
<AccountList listName="Cancelled" accounts={proposal.cancelled} />
504470
)}
505471
<div className="col-span-3 my-2 space-y-4 bg-[#1E1B2F] p-4">
506472
<h4 className="h4 font-semibold">
@@ -562,11 +528,8 @@ const Proposal = ({
562528
<div>Value</div>
563529
</div>
564530
{Object.keys(instruction.args).map((key, index) => (
565-
<>
566-
<div
567-
key={index}
568-
className="flex justify-between border-t border-beige-300 py-3"
569-
>
531+
<Fragment key={index}>
532+
<div className="flex justify-between border-t border-beige-300 py-3">
570533
<div>{key}</div>
571534
{instruction.args[key] instanceof PublicKey ? (
572535
<CopyPubkey
@@ -597,7 +560,7 @@ const Proposal = ({
597560
pubkey={instruction.args[key].toBase58()}
598561
/>
599562
) : null}
600-
</>
563+
</Fragment>
601564
))}
602565
</div>
603566
) : (
@@ -747,7 +710,6 @@ const Proposals = () => {
747710
const router = useRouter()
748711
const { connected, publicKey: signerPublicKey } = useWallet()
749712
const [currentProposal, setCurrentProposal] = useState<TransactionAccount>()
750-
const [currentProposalIndex, setCurrentProposalIndex] = useState<number>()
751713
const [currentProposalPubkey, setCurrentProposalPubkey] = useState<string>()
752714
const { cluster } = useContext(ClusterContext)
753715
const { statusFilter } = useContext(StatusFilterContext)
@@ -808,14 +770,8 @@ const Proposals = () => {
808770
const currProposal = multisigProposals.find(
809771
(proposal) => proposal.publicKey.toBase58() === currentProposalPubkey
810772
)
811-
const currProposalIndex = multisigProposals.findIndex(
812-
(proposal) => proposal.publicKey.toBase58() === currentProposalPubkey
813-
)
814773
setCurrentProposal(currProposal)
815-
setCurrentProposalIndex(
816-
currProposalIndex === -1 ? undefined : currProposalIndex
817-
)
818-
if (currProposalIndex === -1) {
774+
if (currProposal === undefined) {
819775
const otherProposals =
820776
proposalType !== 'priceFeed'
821777
? priceFeedMultisigProposals
@@ -916,7 +872,6 @@ const Proposals = () => {
916872
<ProposalRow
917873
key={proposal.publicKey.toBase58()}
918874
proposal={proposal}
919-
setCurrentProposalPubkey={setCurrentProposalPubkey}
920875
multisig={multisigAccount}
921876
/>
922877
))}
@@ -931,7 +886,7 @@ const Proposals = () => {
931886
)}
932887
</div>
933888
</>
934-
) : !isMultisigLoading && currentProposalIndex !== undefined ? (
889+
) : !isMultisigLoading && currentProposal !== undefined ? (
935890
<>
936891
<div
937892
className="max-w-fit cursor-pointer bg-darkGray2 p-3 text-xs font-semibold outline-none transition-colors hover:bg-darkGray3 md:text-base"
@@ -940,12 +895,7 @@ const Proposals = () => {
940895
&#8592; back to proposals
941896
</div>
942897
<div className="relative mt-6">
943-
<Proposal
944-
proposal={currentProposal}
945-
proposalIndex={currentProposalIndex}
946-
multisig={multisigAccount}
947-
proposalType={proposalType}
948-
/>
898+
<Proposal proposal={currentProposal} multisig={multisigAccount} />
949899
</div>
950900
</>
951901
) : (

governance/xc_admin/packages/xc_admin_frontend/contexts/MultisigContext.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const MultisigContext = createContext<MultisigHookData>({
1616
voteSquads: undefined,
1717
refreshData: undefined,
1818
connection: undefined,
19-
setpriceFeedMultisigProposals: () => {},
2019
})
2120

2221
export const useMultisigContext = () => useContext(MultisigContext)
@@ -38,7 +37,6 @@ export const MultisigContextProvider: React.FC<
3837
upgradeMultisigProposals,
3938
priceFeedMultisigProposals,
4039
allProposalsIxsParsed,
41-
setpriceFeedMultisigProposals,
4240
refreshData,
4341
connection,
4442
} = useMultisig()
@@ -50,7 +48,6 @@ export const MultisigContextProvider: React.FC<
5048
upgradeMultisigProposals,
5149
priceFeedMultisigProposals,
5250
allProposalsIxsParsed,
53-
setpriceFeedMultisigProposals,
5451
isLoading,
5552
error,
5653
proposeSquads,
@@ -68,7 +65,6 @@ export const MultisigContextProvider: React.FC<
6865
upgradeMultisigProposals,
6966
priceFeedMultisigProposals,
7067
allProposalsIxsParsed,
71-
setpriceFeedMultisigProposals,
7268
refreshData,
7369
connection,
7470
]

0 commit comments

Comments
 (0)