Skip to content

Commit 5c16987

Browse files
authored
[xc-admin] delete product (#651)
* add delete product feature * fix delete product bug * refactor * fix precommit
1 parent 35a2fb6 commit 5c16987

File tree

2 files changed

+74
-23
lines changed

2 files changed

+74
-23
lines changed

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

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ const General = () => {
197197
changes[symbol].new = { ...fileDataParsed[symbol] }
198198
}
199199
})
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+
})
200207
setDataChanges(changes)
201208
openModal()
202209
}
@@ -342,6 +349,30 @@ const General = () => {
342349
.instruction()
343350
)
344351
}
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+
)
345376
} else {
346377
// check if metadata has changed
347378
if (
@@ -433,14 +464,13 @@ const General = () => {
433464
}
434465

435466
const MetadataChangesRows = ({ changes }: { changes: any }) => {
436-
const addNewPriceFeed =
437-
changes.prev === undefined && changes.new !== undefined
467+
const addPriceFeed = changes.prev === undefined && changes.new !== undefined
438468

439469
return (
440470
<>
441471
{Object.keys(changes.new).map(
442472
(metadataKey) =>
443-
(addNewPriceFeed ||
473+
(addPriceFeed ||
444474
changes.prev[metadataKey] !== changes.new[metadataKey]) && (
445475
<tr key={metadataKey}>
446476
<td className="base16 py-4 pl-6 pr-2 lg:pl-6">
@@ -451,7 +481,7 @@ const General = () => {
451481
</td>
452482

453483
<td className="base16 py-4 pl-1 pr-2 lg:pl-6">
454-
{!addNewPriceFeed ? (
484+
{!addPriceFeed ? (
455485
<>
456486
<s>{changes.prev[metadataKey]}</s>
457487
<br />{' '}
@@ -467,14 +497,13 @@ const General = () => {
467497
}
468498

469499
const PriceAccountsChangesRows = ({ changes }: { changes: any }) => {
470-
const addNewPriceFeed =
471-
changes.prev === undefined && changes.new !== undefined
500+
const addPriceFeed = changes.prev === undefined && changes.new !== undefined
472501
return (
473502
<>
474503
{changes.new.map((priceAccount: any, index: number) =>
475504
Object.keys(priceAccount).map((priceAccountKey) =>
476505
priceAccountKey === 'publishers' ? (
477-
addNewPriceFeed ? (
506+
addPriceFeed ? (
478507
<PublisherKeysChangesRows
479508
key={priceAccountKey}
480509
changes={{
@@ -494,7 +523,7 @@ const General = () => {
494523
)
495524
)
496525
) : (
497-
(addNewPriceFeed ||
526+
(addPriceFeed ||
498527
changes.prev[index][priceAccountKey] !==
499528
priceAccount[priceAccountKey]) && (
500529
<tr key={priceAccountKey}>
@@ -505,7 +534,7 @@ const General = () => {
505534
.join(' ')}
506535
</td>
507536
<td className="base16 py-4 pl-1 pr-2 lg:pl-6">
508-
{!addNewPriceFeed ? (
537+
{!addPriceFeed ? (
509538
<>
510539
<s>{changes.prev[index][priceAccountKey]}</s>
511540
<br />
@@ -523,14 +552,13 @@ const General = () => {
523552
}
524553

525554
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
529557
? changes.new
530558
: changes.new.filter(
531559
(newPublisher: string) => !changes.prev.includes(newPublisher)
532560
)
533-
const publisherKeysToRemove = addNewPriceFeed
561+
const publisherKeysToRemove = addPriceFeed
534562
? []
535563
: changes.prev.filter(
536564
(prevPublisher: string) => !changes.new.includes(prevPublisher)
@@ -580,6 +608,19 @@ const General = () => {
580608
)
581609
}
582610

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+
583624
const ModalContent = ({ changes }: { changes: any }) => {
584625
return (
585626
<>
@@ -588,26 +629,36 @@ const General = () => {
588629
{/* compare changes.prev and changes.new and display the fields that are different */}
589630
{Object.keys(changes).map((key) => {
590631
const { prev, new: newChanges } = changes[key]
591-
const addNewPriceFeed =
632+
const addPriceFeed =
592633
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+
)
599644
return (
600645
<tbody key={key}>
601646
<tr>
602647
<td
603648
className="base16 py-4 pl-6 pr-2 font-bold lg:pl-6"
604649
colSpan={2}
605650
>
606-
{addNewPriceFeed ? 'Add New Price Feed' : key}
651+
{addPriceFeed
652+
? 'Add New Price Feed'
653+
: deletePriceFeed
654+
? 'Delete Old Price Feed'
655+
: key}
607656
</td>
608657
</tr>
609-
{addNewPriceFeed ? (
658+
{addPriceFeed ? (
610659
<NewPriceFeedsRows key={key} priceFeedData={newChanges} />
660+
) : deletePriceFeed ? (
661+
<OldPriceFeedsRows key={key} priceFeedData={prev} />
611662
) : (
612663
diff.map((k) =>
613664
k === 'metadata' ? (

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ const Proposal = ({
402402
</button>
403403
</div>
404404
) : proposalStatus === 'executeReady' ? (
405-
<div className="flex items-center justify-between px-8 pt-3">
405+
<div className="flex items-center justify-center space-x-8 pt-3">
406406
<button
407407
className="action-btn text-base"
408408
onClick={handleClickExecute}

0 commit comments

Comments
 (0)