Skip to content

Commit 95a8753

Browse files
[SDK] Fix updateListing date handling in marketplace direct listings (#6628)
1 parent 5faaf1b commit 95a8753

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

.changeset/new-spoons-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix updateListing date handling

packages/thirdweb/src/exports/extensions/erc721.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export {
5050
isApprovedForAll,
5151
type IsApprovedForAllParams,
5252
} from "../../extensions/erc721/__generated__/IERC721A/read/isApprovedForAll.js";
53+
export {
54+
type GetApprovedParams,
55+
isGetApprovedSupported,
56+
getApproved,
57+
} from "../../extensions/erc721/__generated__/IERC721A/read/getApproved.js";
5358
export { getTotalUnclaimedSupply } from "../../extensions/erc721/read/getTotalUnclaimedSupply.js";
5459
export { getTotalClaimedSupply } from "../../extensions/erc721/read/getTotalClaimedSupply.js";
5560
export {

packages/thirdweb/src/extensions/marketplace/direct-listings/direct-listings.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { getListing } from "./read/getListing.js";
3434
import { isListingValid } from "./utils.js";
3535
import { buyFromListing } from "./write/buyFromListing.js";
3636
import { createListing } from "./write/createListing.js";
37+
import { updateListing } from "./write/updateListing.js";
3738

3839
const chain = ANVIL_CHAIN;
3940
const client = TEST_CLIENT;
@@ -302,6 +303,18 @@ describe.runIf(process.env.TW_SECRET_KEY)("Marketplace Direct Listings", () => {
302303
expect(listingEvent1155.args.listingCreator).toBe(TEST_ACCOUNT_C.address);
303304
expect(listingEvent1155.args.assetContract).toBe(erc1155Contract.address);
304305

306+
await sendAndConfirmTransaction({
307+
transaction: updateListing({
308+
listingId: listingEvent1155.args.listingId,
309+
contract: marketplaceContract,
310+
assetContractAddress: erc1155Contract.address,
311+
tokenId: 0n,
312+
pricePerToken: "0.05",
313+
quantity: 1n,
314+
}),
315+
account: TEST_ACCOUNT_C,
316+
});
317+
305318
const [
306319
listings1155After,
307320
validListings1155,
@@ -341,10 +354,10 @@ describe.runIf(process.env.TW_SECRET_KEY)("Marketplace Direct Listings", () => {
341354
expect(secondListing.currencyValuePerToken).toMatchInlineSnapshot(`
342355
{
343356
"decimals": 18,
344-
"displayValue": "0.01",
357+
"displayValue": "0.05",
345358
"name": "Anvil Ether",
346359
"symbol": "ETH",
347-
"value": 10000000000000000n,
360+
"value": 50000000000000000n,
348361
}
349362
`);
350363
expect(secondListing.asset.metadata.name).toBe("erc1155 #0");

packages/thirdweb/src/extensions/marketplace/direct-listings/write/updateListing.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,25 @@ export function updateListing(
120120
}
121121

122122
// validate the timestamps
123-
let startTimestamp = BigInt(
124-
Math.floor(
125-
(mergedOptions.startTimestamp ?? new Date()).getTime() / 1000,
126-
),
127-
);
128-
const endTimestamp = BigInt(
129-
Math.floor(
130-
(
131-
mergedOptions.endTimestamp ??
132-
new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1000)
133-
).getTime() / 1000,
134-
),
135-
);
123+
let startTimestamp = mergedOptions.startTimestamp
124+
? BigInt(Math.floor(mergedOptions.startTimestamp.getTime() / 1000))
125+
: mergedOptions.startTimeInSeconds;
136126

137-
if (startTimestamp <= lastestBlock.timestamp) {
127+
const endTimestamp = mergedOptions.endTimestamp
128+
? BigInt(Math.floor(mergedOptions.endTimestamp.getTime() / 1000))
129+
: mergedOptions.endTimeInSeconds;
130+
131+
if (
132+
startTimestamp !== mergedOptions.startTimeInSeconds &&
133+
startTimestamp <= lastestBlock.timestamp
134+
) {
138135
// set the start time to the next block if it is in the past
139136
startTimestamp = lastestBlock.timestamp + 1n;
140137
}
141-
if (startTimestamp >= endTimestamp) {
138+
if (
139+
startTimestamp !== mergedOptions.startTimeInSeconds &&
140+
startTimestamp >= endTimestamp
141+
) {
142142
throw new Error("Start time must be before end time.");
143143
}
144144

0 commit comments

Comments
 (0)