@@ -197,6 +197,13 @@ const General = () => {
197
197
changes [ symbol ] . new = { ...fileDataParsed [ symbol ] }
198
198
}
199
199
} )
200
+ // check if any existing symbols are not in uploaded json
201
+ Object . keys ( data ) . forEach ( ( symbol ) => {
202
+ if ( ! fileDataParsed [ symbol ] ) {
203
+ changes [ symbol ] = { prev : { } }
204
+ changes [ symbol ] . prev = { ...data [ symbol ] }
205
+ }
206
+ } )
200
207
setDataChanges ( changes )
201
208
openModal ( )
202
209
}
@@ -342,6 +349,30 @@ const General = () => {
342
349
. instruction ( )
343
350
)
344
351
}
352
+ } else if ( ! newChanges ) {
353
+ // if new is undefined, it means that the symbol is deleted
354
+ // create delete price account instruction
355
+ instructions . push (
356
+ await pythProgramClient . methods
357
+ . delPrice ( )
358
+ . accounts ( {
359
+ fundingAccount,
360
+ productAccount : new PublicKey ( prev . address ) ,
361
+ priceAccount : new PublicKey ( prev . priceAccounts [ 0 ] . address ) ,
362
+ } )
363
+ . instruction ( )
364
+ )
365
+ // create delete product account instruction
366
+ instructions . push (
367
+ await pythProgramClient . methods
368
+ . delProduct ( )
369
+ . accounts ( {
370
+ fundingAccount,
371
+ mappingAccount : rawConfig . mappingAccounts [ 0 ] . address ,
372
+ productAccount : new PublicKey ( prev . address ) ,
373
+ } )
374
+ . instruction ( )
375
+ )
345
376
} else {
346
377
// check if metadata has changed
347
378
if (
@@ -433,14 +464,13 @@ const General = () => {
433
464
}
434
465
435
466
const MetadataChangesRows = ( { changes } : { changes : any } ) => {
436
- const addNewPriceFeed =
437
- changes . prev === undefined && changes . new !== undefined
467
+ const addPriceFeed = changes . prev === undefined && changes . new !== undefined
438
468
439
469
return (
440
470
< >
441
471
{ Object . keys ( changes . new ) . map (
442
472
( metadataKey ) =>
443
- ( addNewPriceFeed ||
473
+ ( addPriceFeed ||
444
474
changes . prev [ metadataKey ] !== changes . new [ metadataKey ] ) && (
445
475
< tr key = { metadataKey } >
446
476
< td className = "base16 py-4 pl-6 pr-2 lg:pl-6" >
@@ -451,7 +481,7 @@ const General = () => {
451
481
</ td >
452
482
453
483
< td className = "base16 py-4 pl-1 pr-2 lg:pl-6" >
454
- { ! addNewPriceFeed ? (
484
+ { ! addPriceFeed ? (
455
485
< >
456
486
< s > { changes . prev [ metadataKey ] } </ s >
457
487
< br /> { ' ' }
@@ -467,14 +497,13 @@ const General = () => {
467
497
}
468
498
469
499
const PriceAccountsChangesRows = ( { changes } : { changes : any } ) => {
470
- const addNewPriceFeed =
471
- changes . prev === undefined && changes . new !== undefined
500
+ const addPriceFeed = changes . prev === undefined && changes . new !== undefined
472
501
return (
473
502
< >
474
503
{ changes . new . map ( ( priceAccount : any , index : number ) =>
475
504
Object . keys ( priceAccount ) . map ( ( priceAccountKey ) =>
476
505
priceAccountKey === 'publishers' ? (
477
- addNewPriceFeed ? (
506
+ addPriceFeed ? (
478
507
< PublisherKeysChangesRows
479
508
key = { priceAccountKey }
480
509
changes = { {
@@ -494,7 +523,7 @@ const General = () => {
494
523
)
495
524
)
496
525
) : (
497
- ( addNewPriceFeed ||
526
+ ( addPriceFeed ||
498
527
changes . prev [ index ] [ priceAccountKey ] !==
499
528
priceAccount [ priceAccountKey ] ) && (
500
529
< tr key = { priceAccountKey } >
@@ -505,7 +534,7 @@ const General = () => {
505
534
. join ( ' ' ) }
506
535
</ td >
507
536
< td className = "base16 py-4 pl-1 pr-2 lg:pl-6" >
508
- { ! addNewPriceFeed ? (
537
+ { ! addPriceFeed ? (
509
538
< >
510
539
< s > { changes . prev [ index ] [ priceAccountKey ] } </ s >
511
540
< br />
@@ -523,14 +552,13 @@ const General = () => {
523
552
}
524
553
525
554
const PublisherKeysChangesRows = ( { changes } : { changes : any } ) => {
526
- const addNewPriceFeed =
527
- changes . prev === undefined && changes . new !== undefined
528
- const publisherKeysToAdd = addNewPriceFeed
555
+ const addPriceFeed = changes . prev === undefined && changes . new !== undefined
556
+ const publisherKeysToAdd = addPriceFeed
529
557
? changes . new
530
558
: changes . new . filter (
531
559
( newPublisher : string ) => ! changes . prev . includes ( newPublisher )
532
560
)
533
- const publisherKeysToRemove = addNewPriceFeed
561
+ const publisherKeysToRemove = addPriceFeed
534
562
? [ ]
535
563
: changes . prev . filter (
536
564
( prevPublisher : string ) => ! changes . new . includes ( prevPublisher )
@@ -580,6 +608,19 @@ const General = () => {
580
608
)
581
609
}
582
610
611
+ const OldPriceFeedsRows = ( { priceFeedData } : { priceFeedData : any } ) => {
612
+ return (
613
+ < >
614
+ < tr key = { priceFeedData . metadata . symbol } >
615
+ < td className = "base16 py-4 pl-6 pr-2 lg:pl-6" > Symbol</ td >
616
+ < td className = "base16 py-4 pl-1 pr-2 lg:pl-6" >
617
+ { priceFeedData . metadata . symbol }
618
+ </ td >
619
+ </ tr >
620
+ </ >
621
+ )
622
+ }
623
+
583
624
const ModalContent = ( { changes } : { changes : any } ) => {
584
625
return (
585
626
< >
@@ -588,26 +629,36 @@ const General = () => {
588
629
{ /* compare changes.prev and changes.new and display the fields that are different */ }
589
630
{ Object . keys ( changes ) . map ( ( key ) => {
590
631
const { prev, new : newChanges } = changes [ key ]
591
- const addNewPriceFeed =
632
+ const addPriceFeed =
592
633
prev === undefined && newChanges !== undefined
593
- const diff = addNewPriceFeed
594
- ? [ ]
595
- : Object . keys ( prev ) . filter (
596
- ( k ) =>
597
- JSON . stringify ( prev [ k ] ) !== JSON . stringify ( newChanges [ k ] )
598
- )
634
+ const deletePriceFeed =
635
+ prev !== undefined && newChanges === undefined
636
+ const diff =
637
+ addPriceFeed || deletePriceFeed
638
+ ? [ ]
639
+ : Object . keys ( prev ) . filter (
640
+ ( k ) =>
641
+ JSON . stringify ( prev [ k ] ) !==
642
+ JSON . stringify ( newChanges [ k ] )
643
+ )
599
644
return (
600
645
< tbody key = { key } >
601
646
< tr >
602
647
< td
603
648
className = "base16 py-4 pl-6 pr-2 font-bold lg:pl-6"
604
649
colSpan = { 2 }
605
650
>
606
- { addNewPriceFeed ? 'Add New Price Feed' : key }
651
+ { addPriceFeed
652
+ ? 'Add New Price Feed'
653
+ : deletePriceFeed
654
+ ? 'Delete Old Price Feed'
655
+ : key }
607
656
</ td >
608
657
</ tr >
609
- { addNewPriceFeed ? (
658
+ { addPriceFeed ? (
610
659
< NewPriceFeedsRows key = { key } priceFeedData = { newChanges } />
660
+ ) : deletePriceFeed ? (
661
+ < OldPriceFeedsRows key = { key } priceFeedData = { prev } />
611
662
) : (
612
663
diff . map ( ( k ) =>
613
664
k === 'metadata' ? (
0 commit comments