@@ -53,11 +53,9 @@ import {
53
53
import { getMappingCluster , isPubkey } from '../InstructionViews/utils'
54
54
const ProposalRow = ( {
55
55
proposal,
56
- setCurrentProposalPubkey,
57
56
multisig,
58
57
} : {
59
58
proposal : TransactionAccount
60
- setCurrentProposalPubkey : Dispatch < SetStateAction < string | undefined > >
61
59
multisig : MultisigAccount | undefined
62
60
} ) => {
63
61
const status = getProposalStatus ( proposal , multisig )
@@ -67,7 +65,6 @@ const ProposalRow = ({
67
65
const handleClickIndividualProposal = useCallback (
68
66
( proposalPubkey : string ) => {
69
67
router . query . proposal = proposalPubkey
70
- setCurrentProposalPubkey ( proposalPubkey )
71
68
router . push (
72
69
{
73
70
pathname : router . pathname ,
@@ -77,7 +74,7 @@ const ProposalRow = ({
77
74
{ scroll : true }
78
75
)
79
76
} ,
80
- [ setCurrentProposalPubkey , router ]
77
+ [ router ]
81
78
)
82
79
return (
83
80
< div
@@ -226,55 +223,35 @@ type ProposalType = 'priceFeed' | 'governance'
226
223
227
224
const Proposal = ( {
228
225
proposal,
229
- proposalIndex,
230
226
multisig,
231
- proposalType,
232
227
} : {
233
228
proposal : TransactionAccount | undefined
234
- proposalIndex : number
235
229
multisig : MultisigAccount | undefined
236
- proposalType : ProposalType
237
230
} ) => {
238
- const [ currentProposal , setCurrentProposal ] = useState < TransactionAccount > ( )
239
231
const [ instructions , setInstructions ] = useState < MultisigInstruction [ ] > ( [ ] )
240
232
const [ isTransactionLoading , setIsTransactionLoading ] = useState ( false )
241
233
const { cluster } = useContext ( ClusterContext )
242
234
243
235
const {
244
236
voteSquads,
245
237
isLoading : isMultisigLoading ,
246
- setpriceFeedMultisigProposals,
247
238
connection,
239
+ refreshData,
248
240
} = useMultisigContext ( )
249
241
const {
250
242
priceAccountKeyToSymbolMapping,
251
243
productAccountKeyToSymbolMapping,
252
244
publisherKeyToNameMapping,
253
- multisigSignerKeyToNameMapping,
254
245
} = usePythContext ( )
255
246
const publisherKeyToNameMappingCluster =
256
247
publisherKeyToNameMapping [ getMappingCluster ( cluster ) ]
257
248
const { publicKey : signerPublicKey } = useWallet ( )
258
249
259
- useEffect ( ( ) => {
260
- setCurrentProposal ( proposal )
261
- } , [ proposal ] )
262
-
263
250
const proposalStatus = getProposalStatus ( proposal , multisig )
264
251
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
-
275
252
const verified =
276
- currentProposal &&
277
- Object . keys ( currentProposal . status ) [ 0 ] !== 'draft' &&
253
+ proposal &&
254
+ Object . keys ( proposal . status ) [ 0 ] !== 'draft' &&
278
255
instructions . length > 0 &&
279
256
instructions . every (
280
257
( ix ) =>
@@ -300,27 +277,28 @@ const Proposal = ({
300
277
)
301
278
302
279
const voted =
303
- currentProposal &&
280
+ proposal &&
304
281
signerPublicKey &&
305
- ( currentProposal . approved . some (
282
+ ( proposal . approved . some (
306
283
( p ) => p . toBase58 ( ) === signerPublicKey . toBase58 ( )
307
284
) ||
308
- currentProposal . cancelled . some (
285
+ proposal . cancelled . some (
309
286
( p ) => p . toBase58 ( ) === signerPublicKey . toBase58 ( )
310
287
) ||
311
- currentProposal . rejected . some (
288
+ proposal . rejected . some (
312
289
( p ) => p . toBase58 ( ) === signerPublicKey . toBase58 ( )
313
290
) )
314
291
315
292
useEffect ( ( ) => {
293
+ let isCancelled = false
316
294
const fetchInstructions = async ( ) => {
317
- if ( currentProposal && connection ) {
295
+ if ( proposal && connection ) {
318
296
const readOnlySquads = new SquadsMesh ( {
319
297
connection,
320
298
wallet : new NodeWallet ( new Keypair ( ) ) ,
321
299
} )
322
300
const proposalInstructions = (
323
- await getManyProposalsInstructions ( readOnlySquads , [ currentProposal ] )
301
+ await getManyProposalsInstructions ( readOnlySquads , [ proposal ] )
324
302
) [ 0 ]
325
303
const multisigParser = MultisigParser . fromCluster (
326
304
getMultisigCluster ( cluster )
@@ -332,13 +310,16 @@ const Proposal = ({
332
310
keys : ix . keys as AccountMeta [ ] ,
333
311
} )
334
312
)
335
- setInstructions ( parsedInstructions )
313
+ if ( ! isCancelled ) setInstructions ( parsedInstructions )
336
314
} else {
337
- setInstructions ( [ ] )
315
+ if ( ! isCancelled ) setInstructions ( [ ] )
338
316
}
339
317
}
340
318
fetchInstructions ( ) . catch ( console . error )
341
- } , [ cluster , currentProposal , voteSquads , connection ] )
319
+ return ( ) => {
320
+ isCancelled = true
321
+ }
322
+ } , [ cluster , proposal , voteSquads , connection ] )
342
323
343
324
const handleClick = async (
344
325
handler : ( squad : SquadsMesh , proposalKey : PublicKey ) => any ,
@@ -348,19 +329,7 @@ const Proposal = ({
348
329
try {
349
330
setIsTransactionLoading ( true )
350
331
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 ( )
364
333
toast . success ( msg )
365
334
} catch ( e : any ) {
366
335
toast . error ( capitalizeFirstLetter ( e . message ) )
@@ -394,7 +363,7 @@ const Proposal = ({
394
363
} , `Cancelled proposal ${ proposal ?. publicKey . toBase58 ( ) } ` )
395
364
}
396
365
397
- return currentProposal !== undefined &&
366
+ return proposal !== undefined &&
398
367
multisig !== undefined &&
399
368
! isMultisigLoading ? (
400
369
< div className = "grid grid-cols-3 gap-4" >
@@ -417,15 +386,15 @@ const Proposal = ({
417
386
</ div >
418
387
< div className = "flex justify-between" >
419
388
< div > Proposal</ div >
420
- < CopyPubkey pubkey = { currentProposal . publicKey . toBase58 ( ) } />
389
+ < CopyPubkey pubkey = { proposal . publicKey . toBase58 ( ) } />
421
390
</ div >
422
391
< div className = "flex justify-between" >
423
392
< div > Creator</ div >
424
- < CopyPubkey pubkey = { currentProposal . creator . toBase58 ( ) } />
393
+ < CopyPubkey pubkey = { proposal . creator . toBase58 ( ) } />
425
394
</ div >
426
395
< div className = "flex justify-between" >
427
396
< div > Multisig</ div >
428
- < CopyPubkey pubkey = { currentProposal . ms . toBase58 ( ) } />
397
+ < CopyPubkey pubkey = { proposal . ms . toBase58 ( ) } />
429
398
</ div >
430
399
</ div >
431
400
< div className = "col-span-3 my-2 space-y-4 bg-[#1E1B2F] p-4 lg:col-span-1" >
@@ -434,17 +403,17 @@ const Proposal = ({
434
403
< div className = "grid grid-cols-3 justify-center gap-4 text-center align-middle" >
435
404
< div >
436
405
< div className = "font-bold" > Confirmed</ div >
437
- < div className = "text-lg" > { currentProposal . approved . length } </ div >
406
+ < div className = "text-lg" > { proposal . approved . length } </ div >
438
407
</ div >
439
408
{ proposalStatus === 'active' || proposalStatus === 'rejected' ? (
440
409
< div >
441
410
< div className = "font-bold" > Rejected</ div >
442
- < div className = "text-lg" > { currentProposal . rejected . length } </ div >
411
+ < div className = "text-lg" > { proposal . rejected . length } </ div >
443
412
</ div >
444
413
) : (
445
414
< div >
446
415
< div className = "font-bold" > Cancelled</ div >
447
- < div className = "text-lg" > { currentProposal . cancelled . length } </ div >
416
+ < div className = "text-lg" > { proposal . cancelled . length } </ div >
448
417
</ div >
449
418
) }
450
419
< div >
@@ -490,17 +459,14 @@ const Proposal = ({
490
459
</ div >
491
460
) : null }
492
461
</ 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 } />
495
464
) }
496
- { currentProposal . rejected . length > 0 && (
497
- < AccountList listName = "Rejected" accounts = { currentProposal . rejected } />
465
+ { proposal . rejected . length > 0 && (
466
+ < AccountList listName = "Rejected" accounts = { proposal . rejected } />
498
467
) }
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 } />
504
470
) }
505
471
< div className = "col-span-3 my-2 space-y-4 bg-[#1E1B2F] p-4" >
506
472
< h4 className = "h4 font-semibold" >
@@ -562,11 +528,8 @@ const Proposal = ({
562
528
< div > Value</ div >
563
529
</ div >
564
530
{ 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" >
570
533
< div > { key } </ div >
571
534
{ instruction . args [ key ] instanceof PublicKey ? (
572
535
< CopyPubkey
@@ -597,7 +560,7 @@ const Proposal = ({
597
560
pubkey = { instruction . args [ key ] . toBase58 ( ) }
598
561
/>
599
562
) : null }
600
- </ >
563
+ </ Fragment >
601
564
) ) }
602
565
</ div >
603
566
) : (
@@ -747,7 +710,6 @@ const Proposals = () => {
747
710
const router = useRouter ( )
748
711
const { connected, publicKey : signerPublicKey } = useWallet ( )
749
712
const [ currentProposal , setCurrentProposal ] = useState < TransactionAccount > ( )
750
- const [ currentProposalIndex , setCurrentProposalIndex ] = useState < number > ( )
751
713
const [ currentProposalPubkey , setCurrentProposalPubkey ] = useState < string > ( )
752
714
const { cluster } = useContext ( ClusterContext )
753
715
const { statusFilter } = useContext ( StatusFilterContext )
@@ -808,14 +770,8 @@ const Proposals = () => {
808
770
const currProposal = multisigProposals . find (
809
771
( proposal ) => proposal . publicKey . toBase58 ( ) === currentProposalPubkey
810
772
)
811
- const currProposalIndex = multisigProposals . findIndex (
812
- ( proposal ) => proposal . publicKey . toBase58 ( ) === currentProposalPubkey
813
- )
814
773
setCurrentProposal ( currProposal )
815
- setCurrentProposalIndex (
816
- currProposalIndex === - 1 ? undefined : currProposalIndex
817
- )
818
- if ( currProposalIndex === - 1 ) {
774
+ if ( currProposal === undefined ) {
819
775
const otherProposals =
820
776
proposalType !== 'priceFeed'
821
777
? priceFeedMultisigProposals
@@ -916,7 +872,6 @@ const Proposals = () => {
916
872
< ProposalRow
917
873
key = { proposal . publicKey . toBase58 ( ) }
918
874
proposal = { proposal }
919
- setCurrentProposalPubkey = { setCurrentProposalPubkey }
920
875
multisig = { multisigAccount }
921
876
/>
922
877
) ) }
@@ -931,7 +886,7 @@ const Proposals = () => {
931
886
) }
932
887
</ div >
933
888
</ >
934
- ) : ! isMultisigLoading && currentProposalIndex !== undefined ? (
889
+ ) : ! isMultisigLoading && currentProposal !== undefined ? (
935
890
< >
936
891
< div
937
892
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 = () => {
940
895
← back to proposals
941
896
</ div >
942
897
< 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 } />
949
899
</ div >
950
900
</ >
951
901
) : (
0 commit comments