From 361c62889ed032f84b650e6a2dbd4e207f076ce7 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Fri, 20 Dec 2024 22:57:02 -0500 Subject: [PATCH] Fix multiple CATs in imported offer --- crates/sage-database/src/offers.rs | 6 ++--- migrations/0003_offer_fix.sql | 37 ++++++++++++++++++++++++++++++ src/components/OfferCard.tsx | 2 +- src/pages/MakeOffer.tsx | 4 ++++ src/pages/Offers.tsx | 4 ++-- 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 migrations/0003_offer_fix.sql diff --git a/crates/sage-database/src/offers.rs b/crates/sage-database/src/offers.rs index 3d9682ed..8ddaa143 100644 --- a/crates/sage-database/src/offers.rs +++ b/crates/sage-database/src/offers.rs @@ -136,7 +136,7 @@ async fn insert_offer_xch(conn: impl SqliteExecutor<'_>, row: OfferXchRow) -> Re sqlx::query!( " - INSERT OR IGNORE INTO `offer_xch` ( + INSERT INTO `offer_xch` ( `offer_id`, `requested`, `amount`, `royalty` ) VALUES (?, ?, ?, ?) @@ -159,7 +159,7 @@ async fn insert_offer_nft(conn: impl SqliteExecutor<'_>, row: OfferNftRow) -> Re sqlx::query!( " - INSERT OR IGNORE INTO `offer_nfts` ( + INSERT INTO `offer_nfts` ( `offer_id`, `requested`, `launcher_id`, `royalty_puzzle_hash`, `royalty_ten_thousandths`, `name`, `thumbnail`, `thumbnail_mime_type` @@ -191,7 +191,7 @@ async fn insert_offer_cat(conn: impl SqliteExecutor<'_>, row: OfferCatRow) -> Re sqlx::query!( " - INSERT OR IGNORE INTO `offer_cats` ( + INSERT INTO `offer_cats` ( `offer_id`, `requested`, `asset_id`, `amount`, `royalty`, `name`, `ticker`, `icon` ) diff --git a/migrations/0003_offer_fix.sql b/migrations/0003_offer_fix.sql new file mode 100644 index 00000000..a374661b --- /dev/null +++ b/migrations/0003_offer_fix.sql @@ -0,0 +1,37 @@ +CREATE TABLE `offer_nfts_2` ( + `offer_id` BLOB NOT NULL, + `requested` BOOLEAN NOT NULL, + `launcher_id` BLOB NOT NULL, + `royalty_puzzle_hash` BLOB NOT NULL, + `royalty_ten_thousandths` INTEGER NOT NULL, + `name` TEXT, + `thumbnail` BLOB, + `thumbnail_mime_type` TEXT, + PRIMARY KEY (`offer_id`, `launcher_id`, `requested`), + FOREIGN KEY (`offer_id`) REFERENCES `offers`(`offer_id`) ON DELETE CASCADE +); + +CREATE TABLE `offer_cats_2` ( + `offer_id` BLOB NOT NULL, + `requested` BOOLEAN NOT NULL, + `asset_id` BLOB NOT NULL, + `amount` BLOB NOT NULL, + `royalty` BLOB NOT NULL, + `name` TEXT, + `ticker` TEXT, + `icon` TEXT, + PRIMARY KEY (`offer_id`, `asset_id`, `requested`), + FOREIGN KEY (`offer_id`) REFERENCES `offers`(`offer_id`) ON DELETE CASCADE +); + +INSERT INTO `offer_nfts_2` SELECT * FROM `offer_nfts`; +INSERT INTO `offer_cats_2` SELECT * FROM `offer_cats`; + +DROP TABLE `offer_nfts`; +DROP TABLE `offer_cats`; + +ALTER TABLE `offer_nfts_2` RENAME TO `offer_nfts`; +ALTER TABLE `offer_cats_2` RENAME TO `offer_cats`; + +CREATE INDEX `nft_offer_id` ON `offer_nfts` (`offer_id`); +CREATE INDEX `cat_offer_id` ON `offer_cats` (`offer_id`); diff --git a/src/components/OfferCard.tsx b/src/components/OfferCard.tsx index 86d2700d..b9247d48 100644 --- a/src/components/OfferCard.tsx +++ b/src/components/OfferCard.tsx @@ -130,7 +130,7 @@ function Assets({ assets }: AssetsProps) {
{toDecimal(BigNumber(cat.amount).plus(cat.royalty).toString(), 3)}{' '} - {cat.name} + {cat.name ?? cat.ticker ?? 'Unknown'}
diff --git a/src/pages/MakeOffer.tsx b/src/pages/MakeOffer.tsx index f5319f91..ef30d63b 100644 --- a/src/pages/MakeOffer.tsx +++ b/src/pages/MakeOffer.tsx @@ -380,6 +380,10 @@ function AssetSelector({ size='icon' className='border-l-0 rounded-l-none flex-shrink-0 flex-grow-0' onClick={() => { + setAssets({ + ...assets, + xch: '0', + }); setIncludeAmount(false); }} > diff --git a/src/pages/Offers.tsx b/src/pages/Offers.tsx index 05dd7108..076cdbf1 100644 --- a/src/pages/Offers.tsx +++ b/src/pages/Offers.tsx @@ -295,7 +295,7 @@ function AssetPreview({ label, assets }: AssetPreviewProps) {
{toDecimal(BigNumber(cat.amount).plus(cat.royalty).toString(), 3)}{' '} - {cat.name ?? cat.ticker} + {cat.name ?? cat.ticker ?? 'Unknown'}
))} @@ -307,7 +307,7 @@ function AssetPreview({ label, assets }: AssetPreviewProps) { />
- {nft.name} + {nft.name ?? 'Unknown'}
))}