@m3000/market 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/blocks/auction/Auction.d.ts +49 -0
  3. package/dist/components/blocks/auction/Auction.js +44 -0
  4. package/dist/components/blocks/auction/AuctionBidForm.d.ts +11 -0
  5. package/dist/components/blocks/auction/AuctionBidForm.js +88 -0
  6. package/dist/components/blocks/auction/AuctionBidInput.d.ts +9 -0
  7. package/dist/components/blocks/auction/AuctionBidInput.js +99 -0
  8. package/dist/components/blocks/auction/AuctionContext.d.ts +71 -0
  9. package/dist/components/blocks/auction/AuctionContext.js +228 -0
  10. package/dist/components/blocks/auction/AuctionInfo.d.ts +9 -0
  11. package/dist/components/blocks/auction/AuctionInfo.js +37 -0
  12. package/dist/components/blocks/auction/AuctionLayout.d.ts +63 -0
  13. package/dist/components/blocks/auction/AuctionLayout.js +80 -0
  14. package/dist/components/blocks/auction/AuctionRankings.d.ts +16 -0
  15. package/dist/components/blocks/auction/AuctionRankings.js +334 -0
  16. package/dist/components/blocks/auction/AuctionStatusTag.d.ts +15 -0
  17. package/dist/components/blocks/auction/AuctionStatusTag.js +60 -0
  18. package/dist/components/blocks/auction/AuctionSuggestedBids.d.ts +38 -0
  19. package/dist/components/blocks/auction/AuctionSuggestedBids.js +116 -0
  20. package/dist/components/blocks/auction/AuctionYourBidCard.d.ts +27 -0
  21. package/dist/components/blocks/auction/AuctionYourBidCard.js +94 -0
  22. package/dist/components/blocks/auction/AuctionYourBids.d.ts +9 -0
  23. package/dist/components/blocks/auction/AuctionYourBids.js +49 -0
  24. package/dist/components/blocks/auction/index.d.ts +12 -0
  25. package/dist/components/blocks/index.d.ts +12 -0
  26. package/dist/components/index.d.ts +28 -0
  27. package/dist/components/primitives/Button.d.ts +31 -0
  28. package/dist/components/primitives/Button.js +117 -0
  29. package/dist/components/primitives/Drawer.d.ts +43 -0
  30. package/dist/components/primitives/Drawer.js +51 -0
  31. package/dist/components/primitives/Feedback.d.ts +28 -0
  32. package/dist/components/primitives/Feedback.js +147 -0
  33. package/dist/components/primitives/MorphDialog.d.ts +39 -0
  34. package/dist/components/primitives/MorphDialog.js +87 -0
  35. package/dist/components/primitives/Price.d.ts +84 -0
  36. package/dist/components/primitives/Price.js +255 -0
  37. package/dist/components/primitives/PriceInput.d.ts +33 -0
  38. package/dist/components/primitives/PriceInput.js +25 -0
  39. package/dist/components/primitives/Receipt.d.ts +164 -0
  40. package/dist/components/primitives/Receipt.js +344 -0
  41. package/dist/components/primitives/Scale.d.ts +67 -0
  42. package/dist/components/primitives/Scale.js +132 -0
  43. package/dist/components/primitives/Separator.d.ts +22 -0
  44. package/dist/components/primitives/Separator.js +62 -0
  45. package/dist/components/primitives/Skeleton.d.ts +14 -0
  46. package/dist/components/primitives/Skeleton.js +20 -0
  47. package/dist/components/primitives/SteppedInput.d.ts +94 -0
  48. package/dist/components/primitives/SteppedInput.js +154 -0
  49. package/dist/components/primitives/Tabs.d.ts +37 -0
  50. package/dist/components/primitives/Tabs.js +99 -0
  51. package/dist/components/primitives/Tag.d.ts +24 -0
  52. package/dist/components/primitives/Tag.js +22 -0
  53. package/dist/components/primitives/Text.d.ts +32 -0
  54. package/dist/components/primitives/Text.js +65 -0
  55. package/dist/components/primitives/countdown/Countdown.d.ts +24 -0
  56. package/dist/components/primitives/countdown/Countdown.js +22 -0
  57. package/dist/components/primitives/framed-image/FramedImage.d.ts +13 -0
  58. package/dist/components/primitives/framed-image/FramedImage.js +37 -0
  59. package/dist/components/primitives/index.d.ts +17 -0
  60. package/dist/components/primitives/ranked-list/Ranking.d.ts +117 -0
  61. package/dist/components/primitives/ranked-list/Ranking.js +219 -0
  62. package/dist/components/primitives/ranked-list/index.d.ts +1 -0
  63. package/dist/hooks/useCountdown.d.ts +20 -0
  64. package/dist/hooks/useCountdown.js +75 -0
  65. package/dist/index.d.ts +36 -0
  66. package/dist/index.js +36 -0
  67. package/dist/lib/cn.d.ts +6 -0
  68. package/dist/lib/cn.js +75 -0
  69. package/dist/lib/motion.d.ts +19 -0
  70. package/dist/lib/motion.js +43 -0
  71. package/dist/types/index.d.ts +120 -0
  72. package/dist/utils/format.d.ts +38 -0
  73. package/dist/utils/format.js +103 -0
  74. package/dist/utils/rank-utils.d.ts +34 -0
  75. package/dist/utils/rank-utils.js +80 -0
  76. package/dist/utils/tick-validation.d.ts +22 -0
  77. package/dist/utils/tick-validation.js +40 -0
  78. package/package.json +92 -0
  79. package/src/components/blocks/auction/Auction.tsx +74 -0
  80. package/src/components/blocks/auction/AuctionArtwork.tsx +4 -0
  81. package/src/components/blocks/auction/AuctionBidForm.tsx +138 -0
  82. package/src/components/blocks/auction/AuctionBidInput.tsx +166 -0
  83. package/src/components/blocks/auction/AuctionContext.tsx +401 -0
  84. package/src/components/blocks/auction/AuctionInfo.tsx +36 -0
  85. package/src/components/blocks/auction/AuctionLayout.tsx +200 -0
  86. package/src/components/blocks/auction/AuctionRankings.tsx +435 -0
  87. package/src/components/blocks/auction/AuctionStatusTag.tsx +98 -0
  88. package/src/components/blocks/auction/AuctionSuggestedBids.tsx +203 -0
  89. package/src/components/blocks/auction/AuctionYourBidCard.tsx +125 -0
  90. package/src/components/blocks/auction/AuctionYourBids.tsx +61 -0
  91. package/src/components/blocks/auction/index.ts +42 -0
  92. package/src/components/blocks/index.ts +1 -0
  93. package/src/components/index.ts +2 -0
  94. package/src/components/primitives/Button.tsx +183 -0
  95. package/src/components/primitives/Drawer.tsx +125 -0
  96. package/src/components/primitives/Feedback.tsx +185 -0
  97. package/src/components/primitives/MorphDialog.tsx +160 -0
  98. package/src/components/primitives/Price.tsx +394 -0
  99. package/src/components/primitives/PriceInput.tsx +48 -0
  100. package/src/components/primitives/Receipt.tsx +711 -0
  101. package/src/components/primitives/Scale.tsx +287 -0
  102. package/src/components/primitives/Separator.tsx +87 -0
  103. package/src/components/primitives/Skeleton.tsx +33 -0
  104. package/src/components/primitives/SteppedInput.tsx +313 -0
  105. package/src/components/primitives/Tabs.tsx +161 -0
  106. package/src/components/primitives/Tag.tsx +48 -0
  107. package/src/components/primitives/Text.tsx +102 -0
  108. package/src/components/primitives/countdown/Countdown.tsx +43 -0
  109. package/src/components/primitives/countdown/index.ts +2 -0
  110. package/src/components/primitives/framed-image/FramedImage.tsx +51 -0
  111. package/src/components/primitives/framed-image/index.ts +1 -0
  112. package/src/components/primitives/index.ts +42 -0
  113. package/src/components/primitives/ranked-list/RankedList.tsx +9 -0
  114. package/src/components/primitives/ranked-list/Ranking.tsx +454 -0
  115. package/src/components/primitives/ranked-list/index.ts +8 -0
  116. package/src/hooks/index.ts +1 -0
  117. package/src/hooks/useCountdown.ts +91 -0
  118. package/src/index.ts +130 -0
  119. package/src/lib/cn.ts +81 -0
  120. package/src/lib/index.ts +2 -0
  121. package/src/lib/motion.ts +55 -0
  122. package/src/public/lea-83-time-walk.png +0 -0
  123. package/src/public/lea-83-time-walk.webp +0 -0
  124. package/src/stories/Auction.stories.tsx +658 -0
  125. package/src/stories/AuctionLayout.stories.tsx +313 -0
  126. package/src/stories/AuctionStatusTag.stories.tsx +166 -0
  127. package/src/stories/AuctionYourBidCard.stories.tsx +257 -0
  128. package/src/stories/Button.stories.tsx +306 -0
  129. package/src/stories/Countdown.stories.tsx +158 -0
  130. package/src/stories/Feedback.stories.tsx +80 -0
  131. package/src/stories/FramedImage.stories.tsx +46 -0
  132. package/src/stories/MorphDialog.stories.tsx +88 -0
  133. package/src/stories/Price.stories.tsx +292 -0
  134. package/src/stories/RankedList.stories.tsx +190 -0
  135. package/src/stories/Receipt.stories.tsx +221 -0
  136. package/src/stories/Scale.stories.tsx +578 -0
  137. package/src/stories/Separator.stories.tsx +188 -0
  138. package/src/stories/Skeleton.stories.tsx +138 -0
  139. package/src/stories/SteppedInput.stories.tsx +321 -0
  140. package/src/stories/Tabs.stories.tsx +215 -0
  141. package/src/stories/Tag.stories.tsx +138 -0
  142. package/src/stories/Text.stories.tsx +245 -0
  143. package/src/styles/globals.css +39 -0
  144. package/src/styles/index.css +4 -0
  145. package/src/styles/theme/animation.css +11 -0
  146. package/src/styles/theme/color.css +185 -0
  147. package/src/styles/theme/index.css +3 -0
  148. package/src/styles/theme/typography.css +3 -0
  149. package/src/styles/utility.css +8 -0
  150. package/src/types/index.ts +149 -0
  151. package/src/utils/format.ts +130 -0
  152. package/src/utils/index.ts +16 -0
  153. package/src/utils/rank-utils.ts +131 -0
  154. package/src/utils/tick-validation.ts +65 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,49 @@
1
+ import { AuctionData, AuctionFormatters, AuctionUserBid, RankableBid } from "../../../types/index.js";
2
+ import { useAuctionContext } from "./AuctionContext.js";
3
+ import { ReactNode } from "react";
4
+
5
+ //#region src/components/blocks/auction/Auction.d.ts
6
+ interface AuctionProps {
7
+ auction: AuctionData;
8
+ bids: RankableBid[];
9
+ userBids: AuctionUserBid[];
10
+ onPlaceBid: (price: bigint, quantity: bigint) => Promise<boolean>;
11
+ onTopUpBid: (bidId: bigint, newPrice: bigint, additionalValue: bigint) => Promise<boolean>;
12
+ onClaimEdition?: (bidId: string) => Promise<boolean>;
13
+ formatters?: AuctionFormatters;
14
+ children: ReactNode;
15
+ className?: string;
16
+ }
17
+ /**
18
+ * Root component for an auction interface.
19
+ * Provides context and orchestrates the layout of child components.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * <Auction
24
+ * auction={auctionData}
25
+ * bids={bids}
26
+ * userBids={myBids}
27
+ * onPlaceBid={async (price, qty) => { /* wagmi call *\/ }}
28
+ * onTopUpBid={async (bidId, newPrice, value) => { /* wagmi call *\/ }}
29
+ * >
30
+ * <AuctionInfo />
31
+ * <AuctionBidInput />
32
+ * <AuctionRankings />
33
+ * <AuctionYourBids />
34
+ * </Auction>
35
+ * ```
36
+ */
37
+ declare function Auction({
38
+ auction,
39
+ bids,
40
+ userBids,
41
+ onPlaceBid,
42
+ onTopUpBid,
43
+ onClaimEdition,
44
+ formatters,
45
+ children,
46
+ className
47
+ }: AuctionProps): React.ReactElement;
48
+ //#endregion
49
+ export { Auction, AuctionProps };
@@ -0,0 +1,44 @@
1
+ "use client";
2
+
3
+ import { AuctionProvider, useAuctionContext } from "./AuctionContext.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+
6
+ //#region src/components/blocks/auction/Auction.tsx
7
+ /**
8
+ * Root component for an auction interface.
9
+ * Provides context and orchestrates the layout of child components.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * <Auction
14
+ * auction={auctionData}
15
+ * bids={bids}
16
+ * userBids={myBids}
17
+ * onPlaceBid={async (price, qty) => { /* wagmi call *\/ }}
18
+ * onTopUpBid={async (bidId, newPrice, value) => { /* wagmi call *\/ }}
19
+ * >
20
+ * <AuctionInfo />
21
+ * <AuctionBidInput />
22
+ * <AuctionRankings />
23
+ * <AuctionYourBids />
24
+ * </Auction>
25
+ * ```
26
+ */
27
+ function Auction({ auction, bids, userBids, onPlaceBid, onTopUpBid, onClaimEdition, formatters, children, className }) {
28
+ return /* @__PURE__ */ jsx(AuctionProvider, {
29
+ auction,
30
+ bids,
31
+ userBids,
32
+ onPlaceBid,
33
+ onTopUpBid,
34
+ onClaimEdition,
35
+ formatters,
36
+ children: /* @__PURE__ */ jsx("div", {
37
+ className,
38
+ children
39
+ })
40
+ });
41
+ }
42
+
43
+ //#endregion
44
+ export { Auction };
@@ -0,0 +1,11 @@
1
+ //#region src/components/blocks/auction/AuctionBidForm.d.ts
2
+ declare function AuctionBidFormRoot({
3
+ className
4
+ }: {
5
+ className?: string;
6
+ }): React.ReactElement;
7
+ declare const AuctionBidForm: {
8
+ Root: typeof AuctionBidFormRoot;
9
+ };
10
+ //#endregion
11
+ export { AuctionBidForm };
@@ -0,0 +1,88 @@
1
+ "use client";
2
+
3
+ import { useAuctionContext } from "./AuctionContext.js";
4
+ import { cn } from "../../../lib/cn.js";
5
+ import { Button } from "../../primitives/Button.js";
6
+ import { CursorGrowIcon, SteppedInput } from "../../primitives/SteppedInput.js";
7
+ import { Text } from "../../primitives/Text.js";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+
10
+ //#region src/components/blocks/auction/AuctionBidForm.tsx
11
+ function AuctionBidFormRoot({ className }) {
12
+ const { isAuctionEnded, minBidValue, tickConfig, tickSize, lockedBid, placeBidOperation, topUpOperation, handlePlaceBid, handleTopUp, bidValue, setBidValue, formatPrice, currencySymbol, inputDecimals, cancelBidding } = useAuctionContext();
13
+ const effectiveMinBid = lockedBid !== null && lockedBid.priceValue > minBidValue ? lockedBid.priceValue : minBidValue;
14
+ const getTickSize = (currentValue) => {
15
+ if (!tickConfig) return tickSize;
16
+ return currentValue > tickConfig.threshold ? tickConfig.largeTickSize : tickConfig.smallTickSize;
17
+ };
18
+ const activeOperation = lockedBid !== null ? topUpOperation : placeBidOperation;
19
+ const status = activeOperation.status;
20
+ const errorMessage = activeOperation.error;
21
+ const handleSubmit = async () => {
22
+ if (lockedBid !== null ? await handleTopUp(bidValue.toString()) : await handlePlaceBid(bidValue.toString())) setBidValue(effectiveMinBid);
23
+ };
24
+ const isLoading = status === "pending" || status === "confirming" || status === "indexing";
25
+ return /* @__PURE__ */ jsxs("div", {
26
+ className: cn("flex flex-col gap-4", className),
27
+ children: [status === "error" ? /* @__PURE__ */ jsx("div", {
28
+ className: "rounded-xs bg-destructive-muted p-2 text-destructive",
29
+ children: /* @__PURE__ */ jsx(Text, {
30
+ size: "1",
31
+ children: errorMessage
32
+ })
33
+ }) : null, /* @__PURE__ */ jsxs("fieldset", {
34
+ disabled: isAuctionEnded,
35
+ className: "flex w-full flex-col gap-4",
36
+ children: [
37
+ lockedBid !== null ? /* @__PURE__ */ jsx(Text, {
38
+ size: "1",
39
+ children: "Update your bid. You will pay the difference between the new bid amount and the existing bid."
40
+ }) : /* @__PURE__ */ jsx(Text, {
41
+ size: "1",
42
+ children: "Place a new bid to participate in the auction."
43
+ }),
44
+ /* @__PURE__ */ jsx(SteppedInput.Root, {
45
+ value: bidValue,
46
+ onChange: setBidValue,
47
+ min: effectiveMinBid,
48
+ getTickSize,
49
+ decimals: inputDecimals,
50
+ disabled: isAuctionEnded,
51
+ snapToTick: "nearest",
52
+ children: /* @__PURE__ */ jsxs(SteppedInput.Group, { children: [
53
+ /* @__PURE__ */ jsx(SteppedInput.Decrement, {}),
54
+ /* @__PURE__ */ jsxs(SteppedInput.ScrubArea, { children: [/* @__PURE__ */ jsx(SteppedInput.ScrubAreaCursor, { children: /* @__PURE__ */ jsx(CursorGrowIcon, {}) }), /* @__PURE__ */ jsx(SteppedInput.Value, { children: ({ value }) => `${formatPrice(value)} ${currencySymbol}` })] }),
55
+ /* @__PURE__ */ jsx(SteppedInput.Increment, {})
56
+ ] })
57
+ }),
58
+ /* @__PURE__ */ jsxs("div", {
59
+ className: "flex w-full gap-2",
60
+ children: [/* @__PURE__ */ jsx(Button, {
61
+ type: "button",
62
+ color: "tertiary",
63
+ className: "grow whitespace-nowrap",
64
+ onClick: cancelBidding,
65
+ children: "Cancel"
66
+ }), /* @__PURE__ */ jsx(Button, {
67
+ className: "grow",
68
+ type: "button",
69
+ loading: isLoading,
70
+ disabled: isAuctionEnded || !!lockedBid && bidValue - lockedBid.priceValue === 0n,
71
+ onClick: handleSubmit,
72
+ children: lockedBid !== null ? /* @__PURE__ */ jsxs("span", { children: [
73
+ "Update bid (+",
74
+ formatPrice(bidValue - lockedBid.priceValue),
75
+ " ",
76
+ currencySymbol,
77
+ ")"
78
+ ] }) : /* @__PURE__ */ jsx("span", { children: "Place bid" })
79
+ })]
80
+ })
81
+ ]
82
+ })]
83
+ });
84
+ }
85
+ const AuctionBidForm = { Root: AuctionBidFormRoot };
86
+
87
+ //#endregion
88
+ export { AuctionBidForm };
@@ -0,0 +1,9 @@
1
+ //#region src/components/blocks/auction/AuctionBidInput.d.ts
2
+ interface AuctionBidInputProps {
3
+ className?: string;
4
+ }
5
+ declare function AuctionBidInput({
6
+ className
7
+ }: AuctionBidInputProps): React.ReactElement;
8
+ //#endregion
9
+ export { AuctionBidInput, AuctionBidInputProps };
@@ -0,0 +1,99 @@
1
+ "use client";
2
+
3
+ import { useAuctionContext } from "./AuctionContext.js";
4
+ import { transitions } from "../../../lib/motion.js";
5
+ import { Button } from "../../primitives/Button.js";
6
+ import { CursorGrowIcon, SteppedInput } from "../../primitives/SteppedInput.js";
7
+ import { Text } from "../../primitives/Text.js";
8
+ import { useCallback, useEffect } from "react";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ import { AnimatePresence, motion } from "motion/react";
11
+
12
+ //#region src/components/blocks/auction/AuctionBidInput.tsx
13
+ function AuctionBidInput({ className }) {
14
+ const { isAuctionEnded, minBidValue, tickConfig, tickSize, lockedBid, setLockedBid, placeBidOperation, topUpOperation, handlePlaceBid, handleTopUp, getProjectedRank, bidValue, setBidValue, formatPrice, currencySymbol, inputDecimals } = useAuctionContext();
15
+ const effectiveMinBid = lockedBid !== null && lockedBid.priceValue > minBidValue ? lockedBid.priceValue : minBidValue;
16
+ useEffect(() => {
17
+ setBidValue((prev) => prev < effectiveMinBid ? effectiveMinBid : prev);
18
+ }, [effectiveMinBid, setBidValue]);
19
+ const getTickSize = useCallback((currentValue) => {
20
+ if (!tickConfig) return tickSize;
21
+ return currentValue > tickConfig.threshold ? tickConfig.largeTickSize : tickConfig.smallTickSize;
22
+ }, [tickConfig, tickSize]);
23
+ const activeOperation = lockedBid !== null ? topUpOperation : placeBidOperation;
24
+ const status = activeOperation.status;
25
+ const errorMessage = activeOperation.error;
26
+ const { rank: projectedRank, isWinning: isProjectedWinning } = getProjectedRank(bidValue);
27
+ const bidDisplay = `${formatPrice(bidValue)} ${currencySymbol}`;
28
+ const primaryCtaLabel = lockedBid !== null ? projectedRank != null && !isAuctionEnded ? `Top up to rank #${projectedRank}${!isProjectedWinning ? " (outside winning range)" : ""}` : "Top up" : projectedRank != null && !isAuctionEnded ? `Bid ${bidDisplay} and get rank #${projectedRank}${!isProjectedWinning ? " (outside winning range)" : ""}` : `Bid ${bidDisplay}`;
29
+ const handleSubmit = useCallback(async () => {
30
+ if (lockedBid !== null ? await handleTopUp(bidValue.toString()) : await handlePlaceBid(bidValue.toString())) setBidValue(effectiveMinBid);
31
+ }, [
32
+ bidValue,
33
+ effectiveMinBid,
34
+ lockedBid,
35
+ handlePlaceBid,
36
+ handleTopUp,
37
+ setBidValue
38
+ ]);
39
+ const isLoading = status === "pending" || status === "confirming" || status === "indexing";
40
+ return /* @__PURE__ */ jsxs("div", {
41
+ className,
42
+ children: [status === "error" ? /* @__PURE__ */ jsx("div", {
43
+ className: "bg-error/10 text-error mb-2 rounded-xs p-2",
44
+ children: /* @__PURE__ */ jsx(Text, {
45
+ size: "1",
46
+ children: errorMessage
47
+ })
48
+ }) : null, /* @__PURE__ */ jsxs("fieldset", {
49
+ disabled: isAuctionEnded,
50
+ className: "flex w-full flex-col gap-2",
51
+ children: [/* @__PURE__ */ jsx(SteppedInput.Root, {
52
+ value: bidValue,
53
+ onChange: setBidValue,
54
+ min: effectiveMinBid,
55
+ getTickSize,
56
+ decimals: inputDecimals,
57
+ disabled: isAuctionEnded,
58
+ snapToTick: "nearest",
59
+ children: /* @__PURE__ */ jsxs(SteppedInput.Group, { children: [
60
+ /* @__PURE__ */ jsx(SteppedInput.Decrement, {}),
61
+ /* @__PURE__ */ jsxs(SteppedInput.ScrubArea, { children: [/* @__PURE__ */ jsx(SteppedInput.ScrubAreaCursor, { children: /* @__PURE__ */ jsx(CursorGrowIcon, {}) }), /* @__PURE__ */ jsx(SteppedInput.Value, { children: ({ value }) => `${formatPrice(value)} ${currencySymbol}` })] }),
62
+ /* @__PURE__ */ jsx(SteppedInput.Increment, {})
63
+ ] })
64
+ }), /* @__PURE__ */ jsxs("div", {
65
+ className: "flex flex-row gap-2",
66
+ children: [/* @__PURE__ */ jsx(AnimatePresence, {
67
+ mode: "popLayout",
68
+ children: lockedBid !== null && /* @__PURE__ */ jsx(motion.div, {
69
+ initial: { opacity: 0 },
70
+ animate: { opacity: 1 },
71
+ exit: { opacity: 0 },
72
+ transition: transitions.fade,
73
+ className: "flex-1",
74
+ children: /* @__PURE__ */ jsx(Button, {
75
+ type: "button",
76
+ color: "tertiary",
77
+ className: "w-full whitespace-nowrap",
78
+ onClick: () => setLockedBid(null),
79
+ children: "Cancel top up"
80
+ })
81
+ }, "cancel-button")
82
+ }), /* @__PURE__ */ jsx("div", {
83
+ className: "min-w-0 flex-1",
84
+ children: /* @__PURE__ */ jsx(Button, {
85
+ type: "button",
86
+ loading: isLoading,
87
+ disabled: isAuctionEnded,
88
+ onClick: handleSubmit,
89
+ className: "w-full whitespace-nowrap",
90
+ children: primaryCtaLabel
91
+ })
92
+ })]
93
+ })]
94
+ })]
95
+ });
96
+ }
97
+
98
+ //#endregion
99
+ export { AuctionBidInput };
@@ -0,0 +1,71 @@
1
+ import { AuctionData, AuctionFormatters, AuctionTickConfig, AuctionUserBid, OperationState, RankableBid } from "../../../types/index.js";
2
+
3
+ //#region src/components/blocks/auction/AuctionContext.d.ts
4
+ interface AuctionContextValue {
5
+ auction: AuctionData;
6
+ isAuctionEnded: boolean;
7
+ bids: RankableBid[];
8
+ userBids: AuctionUserBid[];
9
+ maxTotalItems: number;
10
+ bidValue: bigint;
11
+ setBidValue: (value: bigint | ((prev: bigint) => bigint)) => void;
12
+ minBidValue: bigint;
13
+ reservePriceValue: bigint;
14
+ tickReferencePrice: bigint;
15
+ tickConfig: AuctionTickConfig | undefined;
16
+ tickSize: bigint;
17
+ placeBidOperation: OperationState;
18
+ topUpOperation: OperationState;
19
+ lockedBid: {
20
+ bidId: bigint;
21
+ priceValue: bigint;
22
+ } | null;
23
+ mergedForRank: RankableBid[];
24
+ getRankForBid: (bidId: string) => number | null;
25
+ getProjectedRank: (priceValue: bigint) => {
26
+ rank: number | null;
27
+ isWinning: boolean;
28
+ };
29
+ getSuggestedBids: () => bigint[];
30
+ showBidPreview: boolean;
31
+ setShowBidPreview: (show: boolean) => void;
32
+ isBiddingActive: boolean;
33
+ setIsBiddingActive: (active: boolean) => void;
34
+ startBidding: () => void;
35
+ cancelBidding: () => void;
36
+ setLockedBid: (bid: {
37
+ bidId: bigint;
38
+ priceValue: bigint;
39
+ } | null) => void;
40
+ handlePlaceBid: (price: string) => Promise<boolean>;
41
+ handleTopUp: (newPrice: string) => Promise<boolean>;
42
+ handleClaimEdition?: (bidId: string) => Promise<boolean>;
43
+ resetOperations: () => void;
44
+ formatPrice: (priceValue: bigint) => string;
45
+ formatTime: (date: Date) => string;
46
+ currencySymbol: string;
47
+ inputDecimals: number;
48
+ }
49
+ declare function useAuctionContext(): AuctionContextValue;
50
+ interface AuctionProviderProps {
51
+ auction: AuctionData;
52
+ bids: RankableBid[];
53
+ userBids: AuctionUserBid[];
54
+ onPlaceBid: (price: bigint, quantity: bigint) => Promise<boolean>;
55
+ onTopUpBid: (bidId: bigint, newPrice: bigint, additionalValue: bigint) => Promise<boolean>;
56
+ onClaimEdition?: (bidId: string) => Promise<boolean>;
57
+ formatters?: AuctionFormatters;
58
+ children: React.ReactNode;
59
+ }
60
+ declare function AuctionProvider({
61
+ auction,
62
+ bids,
63
+ userBids,
64
+ onPlaceBid,
65
+ onTopUpBid,
66
+ onClaimEdition,
67
+ formatters,
68
+ children
69
+ }: AuctionProviderProps): React.ReactElement;
70
+ //#endregion
71
+ export { AuctionProvider, AuctionProviderProps, useAuctionContext };
@@ -0,0 +1,228 @@
1
+ "use client";
2
+
3
+ import { getProjectedRankForPrice, getSuggestedBidPrices } from "../../../utils/rank-utils.js";
4
+ import { createContext, useCallback, useContext, useMemo, useState } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+
7
+ //#region src/components/blocks/auction/AuctionContext.tsx
8
+ const AuctionContext = createContext(null);
9
+ function useAuctionContext() {
10
+ const ctx = useContext(AuctionContext);
11
+ if (!ctx) throw new Error("useAuctionContext must be used within an Auction provider");
12
+ return ctx;
13
+ }
14
+ function AuctionProvider({ auction, bids, userBids, onPlaceBid, onTopUpBid, onClaimEdition, formatters, children }) {
15
+ const defaultFormatPrice = (priceValue) => {
16
+ return (Number(priceValue) / 0xde0b6b3a7640000).toLocaleString("en-US", {
17
+ minimumFractionDigits: 3,
18
+ maximumFractionDigits: 3
19
+ });
20
+ };
21
+ const defaultFormatTime = (date) => {
22
+ const now = Date.now();
23
+ const diff = date.getTime() - now;
24
+ const isPast = diff < 0;
25
+ const absMs = Math.abs(diff);
26
+ const seconds = Math.floor(absMs / 1e3);
27
+ const minutes = Math.floor(seconds / 60);
28
+ const hours = Math.floor(minutes / 60);
29
+ const days = Math.floor(hours / 24);
30
+ if (days > 0) return `${days}d ${hours % 24}h ${isPast ? "ago" : ""}`;
31
+ if (hours > 0) return `${hours}h ${minutes % 60}m ${isPast ? "ago" : ""}`;
32
+ if (minutes > 0) return `${minutes}m ${seconds % 60}s ${isPast ? "ago" : ""}`;
33
+ return `${seconds}s ${isPast ? "ago" : ""}`;
34
+ };
35
+ const formatPrice = formatters?.formatPrice ?? defaultFormatPrice;
36
+ const formatTime = formatters?.formatTime ?? defaultFormatTime;
37
+ const currencySymbol = formatters?.currencySymbol ?? "USD";
38
+ const inputDecimals = formatters?.inputDecimals ?? 18;
39
+ const isAuctionEnded = auction.endsAt ? Date.now() > auction.endsAt.getTime() : false;
40
+ const reservePriceValue = auction.reservePrice;
41
+ const tickConfig = auction.tickConfig;
42
+ const activeBids = bids.filter((b) => {
43
+ const bid = userBids.find((ub) => ub.id === b.id);
44
+ return !bid || bid.status === "active";
45
+ });
46
+ const totalActiveQty = BigInt(activeBids.length);
47
+ const mergedForRank = useMemo(() => {
48
+ const cutoffIds = new Set(bids.map((b) => b.id));
49
+ const myBidsNotInCutoff = userBids.filter((bid) => bid.status === "active" && !cutoffIds.has(bid.id)).map((bid) => ({
50
+ id: bid.id,
51
+ price: bid.price.toString(),
52
+ created_at: bid.createdAt.toISOString()
53
+ }));
54
+ return [...bids, ...myBidsNotInCutoff].sort((a, b) => {
55
+ const pa = BigInt(a.price);
56
+ const pb = BigInt(b.price);
57
+ if (pa !== pb) return pb > pa ? 1 : -1;
58
+ return new Date(a.created_at).getTime() - new Date(b.created_at).getTime();
59
+ });
60
+ }, [bids, userBids]);
61
+ const minBidValue = useMemo(() => {
62
+ if (totalActiveQty >= BigInt(auction.maxTotalItems)) {
63
+ const winningBids = mergedForRank.slice(0, auction.maxTotalItems);
64
+ if (winningBids.length > 0) {
65
+ const lastWinning = winningBids[winningBids.length - 1];
66
+ const tickSize = tickConfig ? BigInt(lastWinning.price) > tickConfig.threshold ? tickConfig.largeTickSize : tickConfig.smallTickSize : BigInt(lastWinning.price);
67
+ return BigInt(lastWinning.price) + tickSize;
68
+ }
69
+ }
70
+ return reservePriceValue;
71
+ }, [
72
+ reservePriceValue,
73
+ totalActiveQty,
74
+ auction.maxTotalItems,
75
+ mergedForRank,
76
+ tickConfig
77
+ ]);
78
+ const tickReferencePrice = minBidValue;
79
+ const tickSize = useMemo(() => {
80
+ if (!tickConfig) return minBidValue;
81
+ return BigInt(minBidValue) > tickConfig.threshold ? tickConfig.largeTickSize : tickConfig.smallTickSize;
82
+ }, [tickConfig, minBidValue]);
83
+ const getRankForBid = useCallback((bidId) => {
84
+ const idx = mergedForRank.findIndex((b) => b.id === bidId);
85
+ return idx >= 0 ? idx + 1 : null;
86
+ }, [mergedForRank]);
87
+ const getProjectedRank = useCallback((priceValue) => {
88
+ return getProjectedRankForPrice(priceValue, mergedForRank, auction.maxTotalItems);
89
+ }, [mergedForRank, auction.maxTotalItems]);
90
+ const getSuggestedBids = useCallback(() => {
91
+ return getSuggestedBidPrices({
92
+ mergedForRank,
93
+ maxTotalItems: auction.maxTotalItems,
94
+ minBidValue,
95
+ reservePriceValue,
96
+ tickConfig,
97
+ tickSize
98
+ });
99
+ }, [
100
+ mergedForRank,
101
+ auction.maxTotalItems,
102
+ minBidValue,
103
+ reservePriceValue,
104
+ tickConfig,
105
+ tickSize
106
+ ]);
107
+ const [placeBidOperation, setPlaceBidOperation] = useState({ status: "idle" });
108
+ const [topUpOperation, setTopUpOperation] = useState({ status: "idle" });
109
+ const [lockedBid, setLockedBid] = useState(null);
110
+ const [showBidPreview, setShowBidPreview] = useState(false);
111
+ const [isBiddingActive, setIsBiddingActive] = useState(false);
112
+ const startBidding = useCallback(() => {
113
+ setIsBiddingActive(true);
114
+ setShowBidPreview(true);
115
+ }, []);
116
+ const cancelBidding = useCallback(() => {
117
+ setIsBiddingActive(false);
118
+ setShowBidPreview(false);
119
+ setLockedBid(null);
120
+ }, []);
121
+ const setLockedBidAndActivate = useCallback((bid) => {
122
+ setLockedBid(bid);
123
+ if (bid !== null) {
124
+ setIsBiddingActive(true);
125
+ setShowBidPreview(true);
126
+ }
127
+ }, []);
128
+ const [bidValue, setBidValue] = useState(minBidValue);
129
+ const resetOperations = useCallback(() => {
130
+ setPlaceBidOperation({ status: "idle" });
131
+ setTopUpOperation({ status: "idle" });
132
+ }, []);
133
+ const handlePlaceBid = useCallback(async (price) => {
134
+ const priceValue = BigInt(price);
135
+ setPlaceBidOperation({ status: "pending" });
136
+ try {
137
+ if (await onPlaceBid(priceValue, 1n)) {
138
+ setPlaceBidOperation({ status: "success" });
139
+ setShowBidPreview(false);
140
+ return true;
141
+ } else {
142
+ setPlaceBidOperation({
143
+ status: "error",
144
+ error: "Transaction failed"
145
+ });
146
+ return false;
147
+ }
148
+ } catch (err) {
149
+ setPlaceBidOperation({
150
+ status: "error",
151
+ error: err instanceof Error ? err.message : "Unknown error"
152
+ });
153
+ return false;
154
+ }
155
+ }, [onPlaceBid]);
156
+ const handleTopUp = useCallback(async (newPrice) => {
157
+ if (!lockedBid) return false;
158
+ const newPriceValue = BigInt(newPrice);
159
+ const additionalValue = newPriceValue - lockedBid.priceValue;
160
+ setTopUpOperation({ status: "pending" });
161
+ try {
162
+ if (await onTopUpBid(lockedBid.bidId, newPriceValue, additionalValue)) {
163
+ setTopUpOperation({ status: "success" });
164
+ setLockedBid(null);
165
+ return true;
166
+ } else {
167
+ setTopUpOperation({
168
+ status: "error",
169
+ error: "Transaction failed"
170
+ });
171
+ return false;
172
+ }
173
+ } catch (err) {
174
+ setTopUpOperation({
175
+ status: "error",
176
+ error: err instanceof Error ? err.message : "Unknown error"
177
+ });
178
+ return false;
179
+ }
180
+ }, [lockedBid, onTopUpBid]);
181
+ const handleClaimEdition = useCallback(async (bidId) => {
182
+ if (!onClaimEdition) return false;
183
+ return onClaimEdition(bidId);
184
+ }, [onClaimEdition]);
185
+ const value = {
186
+ auction,
187
+ isAuctionEnded,
188
+ bids,
189
+ userBids,
190
+ maxTotalItems: auction.maxTotalItems,
191
+ bidValue,
192
+ setBidValue,
193
+ minBidValue,
194
+ reservePriceValue,
195
+ tickReferencePrice,
196
+ tickConfig,
197
+ tickSize,
198
+ placeBidOperation,
199
+ topUpOperation,
200
+ lockedBid,
201
+ mergedForRank,
202
+ getRankForBid,
203
+ getProjectedRank,
204
+ getSuggestedBids,
205
+ showBidPreview,
206
+ setShowBidPreview,
207
+ isBiddingActive,
208
+ setIsBiddingActive,
209
+ startBidding,
210
+ cancelBidding,
211
+ setLockedBid: setLockedBidAndActivate,
212
+ handlePlaceBid,
213
+ handleTopUp,
214
+ handleClaimEdition,
215
+ resetOperations,
216
+ formatPrice,
217
+ formatTime,
218
+ currencySymbol,
219
+ inputDecimals
220
+ };
221
+ return /* @__PURE__ */ jsx(AuctionContext.Provider, {
222
+ value,
223
+ children
224
+ });
225
+ }
226
+
227
+ //#endregion
228
+ export { AuctionProvider, useAuctionContext };
@@ -0,0 +1,9 @@
1
+ //#region src/components/blocks/auction/AuctionInfo.d.ts
2
+ interface AuctionInfoProps {
3
+ className?: string;
4
+ }
5
+ declare function AuctionInfo({
6
+ className
7
+ }: AuctionInfoProps): React.ReactElement;
8
+ //#endregion
9
+ export { AuctionInfo, AuctionInfoProps };
@@ -0,0 +1,37 @@
1
+ "use client";
2
+
3
+ import { useAuctionContext } from "./AuctionContext.js";
4
+ import { Text } from "../../primitives/Text.js";
5
+ import { AuctionStatusTag } from "./AuctionStatusTag.js";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+
8
+ //#region src/components/blocks/auction/AuctionInfo.tsx
9
+ function AuctionInfo({ className }) {
10
+ const { auction, isAuctionEnded, maxTotalItems } = useAuctionContext();
11
+ const editionsLabel = maxTotalItems === 1 ? "1 item" : `${maxTotalItems} items`;
12
+ return /* @__PURE__ */ jsxs("div", {
13
+ className,
14
+ children: [/* @__PURE__ */ jsx("div", {
15
+ className: "flex flex-wrap items-center gap-2",
16
+ children: /* @__PURE__ */ jsx(AuctionStatusTag, {
17
+ opensAt: auction.opensAt,
18
+ endsAt: auction.endsAt,
19
+ background: "transparent"
20
+ })
21
+ }), !isAuctionEnded ? /* @__PURE__ */ jsxs(Text, {
22
+ size: "2",
23
+ color: "tertiary",
24
+ className: "mt-2",
25
+ children: [
26
+ "Bid on one of ",
27
+ editionsLabel,
28
+ ". Top ",
29
+ maxTotalItems,
30
+ " bidders win and pay the lowest winning bid."
31
+ ]
32
+ }) : null]
33
+ });
34
+ }
35
+
36
+ //#endregion
37
+ export { AuctionInfo };