Skip to content

Commit

Permalink
Fix multiple CATs in imported offer
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Dec 21, 2024
1 parent a1be3ae commit 361c628
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
6 changes: 3 additions & 3 deletions crates/sage-database/src/offers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (?, ?, ?, ?)
Expand All @@ -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`
Expand Down Expand Up @@ -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`
)
Expand Down
37 changes: 37 additions & 0 deletions migrations/0003_offer_fix.sql
Original file line number Diff line number Diff line change
@@ -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`);
2 changes: 1 addition & 1 deletion src/components/OfferCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function Assets({ assets }: AssetsProps) {
</div>
<div className='text-sm font-medium whitespace-nowrap'>
{toDecimal(BigNumber(cat.amount).plus(cat.royalty).toString(), 3)}{' '}
{cat.name}
{cat.name ?? cat.ticker ?? 'Unknown'}
</div>
</div>

Expand Down
4 changes: 4 additions & 0 deletions src/pages/MakeOffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}}
>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Offers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function AssetPreview({ label, assets }: AssetPreviewProps) {

<div className='text-sm text-muted-foreground truncate'>
{toDecimal(BigNumber(cat.amount).plus(cat.royalty).toString(), 3)}{' '}
{cat.name ?? cat.ticker}
{cat.name ?? cat.ticker ?? 'Unknown'}
</div>
</div>
))}
Expand All @@ -307,7 +307,7 @@ function AssetPreview({ label, assets }: AssetPreviewProps) {
/>

<div className='text-sm text-muted-foreground truncate'>
{nft.name}
{nft.name ?? 'Unknown'}
</div>
</div>
))}
Expand Down

0 comments on commit 361c628

Please sign in to comment.