Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ const General = () => {
changes[symbol].new = { ...fileDataParsed[symbol] }
}
})
// check if any existing symbols are not in uploaded json
Object.keys(data).forEach((symbol) => {
if (!fileDataParsed[symbol]) {
changes[symbol] = { prev: {} }
changes[symbol].prev = { ...data[symbol] }
}
})
setDataChanges(changes)
openModal()
}
Expand Down Expand Up @@ -342,6 +349,30 @@ const General = () => {
.instruction()
)
}
} else if (!newChanges) {
// if new is undefined, it means that the symbol is deleted
// create delete price account instruction
instructions.push(
await pythProgramClient.methods
.delPrice()
.accounts({
fundingAccount,
productAccount: new PublicKey(prev.address),
priceAccount: new PublicKey(prev.priceAccounts[0].address),
})
.instruction()
)
// create delete product account instruction
instructions.push(
await pythProgramClient.methods
.delProduct()
.accounts({
fundingAccount,
mappingAccount: rawConfig.mappingAccounts[0].address,
productAccount: new PublicKey(prev.address),
})
.instruction()
)
} else {
// check if metadata has changed
if (
Expand Down Expand Up @@ -433,14 +464,13 @@ const General = () => {
}

const MetadataChangesRows = ({ changes }: { changes: any }) => {
const addNewPriceFeed =
changes.prev === undefined && changes.new !== undefined
const addPriceFeed = changes.prev === undefined && changes.new !== undefined

return (
<>
{Object.keys(changes.new).map(
(metadataKey) =>
(addNewPriceFeed ||
(addPriceFeed ||
changes.prev[metadataKey] !== changes.new[metadataKey]) && (
<tr key={metadataKey}>
<td className="base16 py-4 pl-6 pr-2 lg:pl-6">
Expand All @@ -451,7 +481,7 @@ const General = () => {
</td>

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

const PriceAccountsChangesRows = ({ changes }: { changes: any }) => {
const addNewPriceFeed =
changes.prev === undefined && changes.new !== undefined
const addPriceFeed = changes.prev === undefined && changes.new !== undefined
return (
<>
{changes.new.map((priceAccount: any, index: number) =>
Object.keys(priceAccount).map((priceAccountKey) =>
priceAccountKey === 'publishers' ? (
addNewPriceFeed ? (
addPriceFeed ? (
<PublisherKeysChangesRows
key={priceAccountKey}
changes={{
Expand All @@ -494,7 +523,7 @@ const General = () => {
)
)
) : (
(addNewPriceFeed ||
(addPriceFeed ||
changes.prev[index][priceAccountKey] !==
priceAccount[priceAccountKey]) && (
<tr key={priceAccountKey}>
Expand All @@ -505,7 +534,7 @@ const General = () => {
.join(' ')}
</td>
<td className="base16 py-4 pl-1 pr-2 lg:pl-6">
{!addNewPriceFeed ? (
{!addPriceFeed ? (
<>
<s>{changes.prev[index][priceAccountKey]}</s>
<br />
Expand All @@ -523,14 +552,13 @@ const General = () => {
}

const PublisherKeysChangesRows = ({ changes }: { changes: any }) => {
const addNewPriceFeed =
changes.prev === undefined && changes.new !== undefined
const publisherKeysToAdd = addNewPriceFeed
const addPriceFeed = changes.prev === undefined && changes.new !== undefined
const publisherKeysToAdd = addPriceFeed
? changes.new
: changes.new.filter(
(newPublisher: string) => !changes.prev.includes(newPublisher)
)
const publisherKeysToRemove = addNewPriceFeed
const publisherKeysToRemove = addPriceFeed
? []
: changes.prev.filter(
(prevPublisher: string) => !changes.new.includes(prevPublisher)
Expand Down Expand Up @@ -580,6 +608,19 @@ const General = () => {
)
}

const OldPriceFeedsRows = ({ priceFeedData }: { priceFeedData: any }) => {
return (
<>
<tr key={priceFeedData.metadata.symbol}>
<td className="base16 py-4 pl-6 pr-2 lg:pl-6">Symbol</td>
<td className="base16 py-4 pl-1 pr-2 lg:pl-6">
{priceFeedData.metadata.symbol}
</td>
</tr>
</>
)
}

const ModalContent = ({ changes }: { changes: any }) => {
return (
<>
Expand All @@ -588,26 +629,36 @@ const General = () => {
{/* compare changes.prev and changes.new and display the fields that are different */}
{Object.keys(changes).map((key) => {
const { prev, new: newChanges } = changes[key]
const addNewPriceFeed =
const addPriceFeed =
prev === undefined && newChanges !== undefined
const diff = addNewPriceFeed
? []
: Object.keys(prev).filter(
(k) =>
JSON.stringify(prev[k]) !== JSON.stringify(newChanges[k])
)
const deletePriceFeed =
prev !== undefined && newChanges === undefined
const diff =
addPriceFeed || deletePriceFeed
? []
: Object.keys(prev).filter(
(k) =>
JSON.stringify(prev[k]) !==
JSON.stringify(newChanges[k])
)
return (
<tbody key={key}>
<tr>
<td
className="base16 py-4 pl-6 pr-2 font-bold lg:pl-6"
colSpan={2}
>
{addNewPriceFeed ? 'Add New Price Feed' : key}
{addPriceFeed
? 'Add New Price Feed'
: deletePriceFeed
? 'Delete Old Price Feed'
: key}
</td>
</tr>
{addNewPriceFeed ? (
{addPriceFeed ? (
<NewPriceFeedsRows key={key} priceFeedData={newChanges} />
) : deletePriceFeed ? (
<OldPriceFeedsRows key={key} priceFeedData={prev} />
) : (
diff.map((k) =>
k === 'metadata' ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ const Proposal = ({
</button>
</div>
) : proposalStatus === 'executeReady' ? (
<div className="flex items-center justify-between px-8 pt-3">
<div className="flex items-center justify-center space-x-8 pt-3">
<button
className="action-btn text-base"
onClick={handleClickExecute}
Expand Down