Skip to content

Commit ba79d2d

Browse files
Fix updateListing date handling in marketplace direct listings
1 parent 5faaf1b commit ba79d2d

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-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/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: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ export function updateListing(
9494
asyncParams: async () => {
9595
const { contract, listingId, ...updateParams } = options;
9696

97+
console.log("listingId", listingId);
98+
console.log("updateParams", updateParams);
99+
97100
const existingListing = await getListing({
98101
contract: options.contract,
99102
listingId: options.listingId,
100103
});
101104

102105
const mergedOptions = { ...existingListing, ...updateParams };
103106

107+
console.log("mergedOptions", mergedOptions);
104108
const assetContract = getContract({
105109
...contract,
106110
address: mergedOptions.assetContractAddress,
@@ -120,25 +124,25 @@ export function updateListing(
120124
}
121125

122126
// 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-
);
127+
let startTimestamp = mergedOptions.startTimestamp
128+
? BigInt(Math.floor(mergedOptions.startTimestamp.getTime() / 1000))
129+
: mergedOptions.startTimeInSeconds;
130+
131+
const endTimestamp = mergedOptions.endTimestamp
132+
? BigInt(Math.floor(mergedOptions.endTimestamp.getTime() / 1000))
133+
: mergedOptions.endTimeInSeconds;
136134

137-
if (startTimestamp <= lastestBlock.timestamp) {
135+
if (
136+
startTimestamp !== mergedOptions.startTimeInSeconds &&
137+
startTimestamp <= lastestBlock.timestamp
138+
) {
138139
// set the start time to the next block if it is in the past
139140
startTimestamp = lastestBlock.timestamp + 1n;
140141
}
141-
if (startTimestamp >= endTimestamp) {
142+
if (
143+
startTimestamp !== mergedOptions.startTimeInSeconds &&
144+
startTimestamp >= endTimestamp
145+
) {
142146
throw new Error("Start time must be before end time.");
143147
}
144148

0 commit comments

Comments
 (0)