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
5 changes: 5 additions & 0 deletions .changeset/new-spoons-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix updateListing date handling
5 changes: 5 additions & 0 deletions packages/thirdweb/src/exports/extensions/erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export {
isApprovedForAll,
type IsApprovedForAllParams,
} from "../../extensions/erc721/__generated__/IERC721A/read/isApprovedForAll.js";
export {
type GetApprovedParams,
isGetApprovedSupported,
getApproved,
} from "../../extensions/erc721/__generated__/IERC721A/read/getApproved.js";
export { getTotalUnclaimedSupply } from "../../extensions/erc721/read/getTotalUnclaimedSupply.js";
export { getTotalClaimedSupply } from "../../extensions/erc721/read/getTotalClaimedSupply.js";
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { getListing } from "./read/getListing.js";
import { isListingValid } from "./utils.js";
import { buyFromListing } from "./write/buyFromListing.js";
import { createListing } from "./write/createListing.js";
import { updateListing } from "./write/updateListing.js";

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

await sendAndConfirmTransaction({
transaction: updateListing({
listingId: listingEvent1155.args.listingId,
contract: marketplaceContract,
assetContractAddress: erc1155Contract.address,
tokenId: 0n,
pricePerToken: "0.05",
quantity: 1n,
}),
account: TEST_ACCOUNT_C,
});

const [
listings1155After,
validListings1155,
Expand Down Expand Up @@ -341,10 +354,10 @@ describe.runIf(process.env.TW_SECRET_KEY)("Marketplace Direct Listings", () => {
expect(secondListing.currencyValuePerToken).toMatchInlineSnapshot(`
{
"decimals": 18,
"displayValue": "0.01",
"displayValue": "0.05",
"name": "Anvil Ether",
"symbol": "ETH",
"value": 10000000000000000n,
"value": 50000000000000000n,
}
`);
expect(secondListing.asset.metadata.name).toBe("erc1155 #0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,25 @@
}

// validate the timestamps
let startTimestamp = BigInt(
Math.floor(
(mergedOptions.startTimestamp ?? new Date()).getTime() / 1000,
),
);
const endTimestamp = BigInt(
Math.floor(
(
mergedOptions.endTimestamp ??
new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1000)
).getTime() / 1000,
),
);
let startTimestamp = mergedOptions.startTimestamp
? BigInt(Math.floor(mergedOptions.startTimestamp.getTime() / 1000))

Check warning on line 124 in packages/thirdweb/src/extensions/marketplace/direct-listings/write/updateListing.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L124 was not covered by tests
: mergedOptions.startTimeInSeconds;

if (startTimestamp <= lastestBlock.timestamp) {
const endTimestamp = mergedOptions.endTimestamp
? BigInt(Math.floor(mergedOptions.endTimestamp.getTime() / 1000))

Check warning on line 128 in packages/thirdweb/src/extensions/marketplace/direct-listings/write/updateListing.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L128 was not covered by tests
: mergedOptions.endTimeInSeconds;

if (
startTimestamp !== mergedOptions.startTimeInSeconds &&
startTimestamp <= lastestBlock.timestamp

Check warning on line 133 in packages/thirdweb/src/extensions/marketplace/direct-listings/write/updateListing.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L133 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be a typo in the variable name lastestBlock which should be latestBlock. This typo occurs in multiple places throughout the conditional checks in the date validation logic.

Suggested change
startTimestamp <= lastestBlock.timestamp
startTimestamp <= latestBlock.timestamp

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

) {
// set the start time to the next block if it is in the past
startTimestamp = lastestBlock.timestamp + 1n;
}
if (startTimestamp >= endTimestamp) {
if (
startTimestamp !== mergedOptions.startTimeInSeconds &&
startTimestamp >= endTimestamp

Check warning on line 140 in packages/thirdweb/src/extensions/marketplace/direct-listings/write/updateListing.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L140 was not covered by tests
) {
throw new Error("Start time must be before end time.");
}

Expand Down