@0xsequence/marketplace-sdk 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 (258) hide show
  1. package/README.md +8 -0
  2. package/dist/chunk-3TYUQEFM.js +115 -0
  3. package/dist/chunk-3TYUQEFM.js.map +1 -0
  4. package/dist/chunk-4ESPWOBV.js +13 -0
  5. package/dist/chunk-4ESPWOBV.js.map +1 -0
  6. package/dist/chunk-4PFMUVE4.js +78 -0
  7. package/dist/chunk-4PFMUVE4.js.map +1 -0
  8. package/dist/chunk-5WRI5ZAA.js +31 -0
  9. package/dist/chunk-5WRI5ZAA.js.map +1 -0
  10. package/dist/chunk-6S4FYXP6.js +43 -0
  11. package/dist/chunk-6S4FYXP6.js.map +1 -0
  12. package/dist/chunk-7OO74L2K.js +41 -0
  13. package/dist/chunk-7OO74L2K.js.map +1 -0
  14. package/dist/chunk-BBB3XUB4.js +213 -0
  15. package/dist/chunk-BBB3XUB4.js.map +1 -0
  16. package/dist/chunk-BCNFYVAL.js +1 -0
  17. package/dist/chunk-BCNFYVAL.js.map +1 -0
  18. package/dist/chunk-D7QQP6MS.js +2 -0
  19. package/dist/chunk-D7QQP6MS.js.map +1 -0
  20. package/dist/chunk-DBFOPEV6.js +23 -0
  21. package/dist/chunk-DBFOPEV6.js.map +1 -0
  22. package/dist/chunk-EDTC7UES.js +176 -0
  23. package/dist/chunk-EDTC7UES.js.map +1 -0
  24. package/dist/chunk-G3D572BT.js +249 -0
  25. package/dist/chunk-G3D572BT.js.map +1 -0
  26. package/dist/chunk-HGBEC3WX.js +1285 -0
  27. package/dist/chunk-HGBEC3WX.js.map +1 -0
  28. package/dist/chunk-MJ4YU7RW.js +2 -0
  29. package/dist/chunk-MJ4YU7RW.js.map +1 -0
  30. package/dist/chunk-NJ2GXOPW.js +2 -0
  31. package/dist/chunk-NJ2GXOPW.js.map +1 -0
  32. package/dist/chunk-O5JXKTWP.js +1029 -0
  33. package/dist/chunk-O5JXKTWP.js.map +1 -0
  34. package/dist/chunk-O642NH7U.js +15 -0
  35. package/dist/chunk-O642NH7U.js.map +1 -0
  36. package/dist/chunk-QOJXWHRZ.js +71 -0
  37. package/dist/chunk-QOJXWHRZ.js.map +1 -0
  38. package/dist/chunk-QVFMD6S2.js +21 -0
  39. package/dist/chunk-QVFMD6S2.js.map +1 -0
  40. package/dist/chunk-RNUHUVLC.js +214 -0
  41. package/dist/chunk-RNUHUVLC.js.map +1 -0
  42. package/dist/chunk-SM7V6ZWI.js +2740 -0
  43. package/dist/chunk-SM7V6ZWI.js.map +1 -0
  44. package/dist/chunk-STO74F2I.js +14 -0
  45. package/dist/chunk-STO74F2I.js.map +1 -0
  46. package/dist/chunk-TZGLKJRF.js +198 -0
  47. package/dist/chunk-TZGLKJRF.js.map +1 -0
  48. package/dist/chunk-UYRQ5MJQ.js +1027 -0
  49. package/dist/chunk-UYRQ5MJQ.js.map +1 -0
  50. package/dist/chunk-VPGWEMWL.js +162 -0
  51. package/dist/chunk-VPGWEMWL.js.map +1 -0
  52. package/dist/chunk-ZE2LNX65.js +394 -0
  53. package/dist/chunk-ZE2LNX65.js.map +1 -0
  54. package/dist/create-config-Dz0gCiQ0.d.ts +8 -0
  55. package/dist/get-query-client-D46hbjk6.d.ts +5 -0
  56. package/dist/index.css +232 -0
  57. package/dist/index.d.ts +16 -0
  58. package/dist/index.js +76 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/marketplace-config-DZbtyrma.d.ts +57 -0
  61. package/dist/marketplace.gen-Ceofb9Cs.d.ts +904 -0
  62. package/dist/react/_internal/api/index.d.ts +51 -0
  63. package/dist/react/_internal/api/index.js +134 -0
  64. package/dist/react/_internal/api/index.js.map +1 -0
  65. package/dist/react/_internal/index.d.ts +22 -0
  66. package/dist/react/_internal/index.js +150 -0
  67. package/dist/react/_internal/index.js.map +1 -0
  68. package/dist/react/_internal/wagmi/index.d.ts +12 -0
  69. package/dist/react/_internal/wagmi/index.js +12 -0
  70. package/dist/react/_internal/wagmi/index.js.map +1 -0
  71. package/dist/react/hooks/index.d.ts +381 -0
  72. package/dist/react/hooks/index.js +82 -0
  73. package/dist/react/hooks/index.js.map +1 -0
  74. package/dist/react/index.css +233 -0
  75. package/dist/react/index.css.map +1 -0
  76. package/dist/react/index.d.ts +27 -0
  77. package/dist/react/index.js +113 -0
  78. package/dist/react/index.js.map +1 -0
  79. package/dist/react/ssr/index.d.ts +94 -0
  80. package/dist/react/ssr/index.js +351 -0
  81. package/dist/react/ssr/index.js.map +1 -0
  82. package/dist/react/ui/icons/index.css +25 -0
  83. package/dist/react/ui/icons/index.css.map +1 -0
  84. package/dist/react/ui/icons/index.d.ts +2 -0
  85. package/dist/react/ui/icons/index.js +12 -0
  86. package/dist/react/ui/icons/index.js.map +1 -0
  87. package/dist/react/ui/index.css +233 -0
  88. package/dist/react/ui/index.css.map +1 -0
  89. package/dist/react/ui/index.d.ts +112 -0
  90. package/dist/react/ui/index.js +34 -0
  91. package/dist/react/ui/index.js.map +1 -0
  92. package/dist/react/ui/modals/_internal/components/actionModal/index.css +44 -0
  93. package/dist/react/ui/modals/_internal/components/actionModal/index.css.map +1 -0
  94. package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +31 -0
  95. package/dist/react/ui/modals/_internal/components/actionModal/index.js +39 -0
  96. package/dist/react/ui/modals/_internal/components/actionModal/index.js.map +1 -0
  97. package/dist/react/ui/styles/index.css +36 -0
  98. package/dist/react/ui/styles/index.css.map +1 -0
  99. package/dist/react/ui/styles/index.d.ts +5 -0
  100. package/dist/react/ui/styles/index.js +13 -0
  101. package/dist/react/ui/styles/index.js.map +1 -0
  102. package/dist/sdk-config-xWkdBdrL.d.ts +24 -0
  103. package/dist/services-BIwQ1C1c.d.ts +20 -0
  104. package/dist/styles/index.css +233 -0
  105. package/dist/styles/index.css.map +1 -0
  106. package/dist/styles/index.d.ts +58 -0
  107. package/dist/styles/index.js +5019 -0
  108. package/dist/styles/index.js.map +1 -0
  109. package/dist/styles.css-BVaTR5nO.d.ts +3 -0
  110. package/dist/types/index.d.ts +12 -0
  111. package/dist/types/index.js +39 -0
  112. package/dist/types/index.js.map +1 -0
  113. package/dist/types-BrAQ8-w4.d.ts +12 -0
  114. package/dist/utils/abi/abi/standard/index.d.ts +25 -0
  115. package/dist/utils/abi/abi/standard/index.js +8 -0
  116. package/dist/utils/abi/abi/standard/index.js.map +1 -0
  117. package/dist/utils/abi/abi/token/index.d.ts +1125 -0
  118. package/dist/utils/abi/abi/token/index.js +13 -0
  119. package/dist/utils/abi/abi/token/index.js.map +1 -0
  120. package/dist/utils/abi/clients/index.d.ts +27 -0
  121. package/dist/utils/abi/clients/index.js +13 -0
  122. package/dist/utils/abi/clients/index.js.map +1 -0
  123. package/dist/utils/index.d.ts +23 -0
  124. package/dist/utils/index.js +37 -0
  125. package/dist/utils/index.js.map +1 -0
  126. package/package.json +74 -0
  127. package/src/consts.ts +2 -0
  128. package/src/index.ts +3 -0
  129. package/src/react/_internal/api/get-query-client.ts +32 -0
  130. package/src/react/_internal/api/index.ts +5 -0
  131. package/src/react/_internal/api/marketplace-api.ts +31 -0
  132. package/src/react/_internal/api/marketplace.gen.ts +1911 -0
  133. package/src/react/_internal/api/query-keys.ts +61 -0
  134. package/src/react/_internal/api/services.ts +101 -0
  135. package/src/react/_internal/consts.ts +1 -0
  136. package/src/react/_internal/get-provider.ts +6 -0
  137. package/src/react/_internal/index.ts +5 -0
  138. package/src/react/_internal/types.ts +13 -0
  139. package/src/react/_internal/wagmi/create-config.ts +62 -0
  140. package/src/react/_internal/wagmi/embedded.ts +87 -0
  141. package/src/react/_internal/wagmi/index.ts +3 -0
  142. package/src/react/_internal/wagmi/universal.ts +82 -0
  143. package/src/react/hooks/index.ts +17 -0
  144. package/src/react/hooks/options/marketplaceConfigOptions.ts +62 -0
  145. package/src/react/hooks/useBalanceOfCollectible.tsx +51 -0
  146. package/src/react/hooks/useCollectible.tsx +47 -0
  147. package/src/react/hooks/useCollection.tsx +42 -0
  148. package/src/react/hooks/useCollectionCounts.tsx +61 -0
  149. package/src/react/hooks/useConfig.tsx +15 -0
  150. package/src/react/hooks/useCurrencies.tsx +76 -0
  151. package/src/react/hooks/useFilters.tsx +39 -0
  152. package/src/react/hooks/useFloorOrder.tsx +28 -0
  153. package/src/react/hooks/useGenerateListingTransaction.tsx +63 -0
  154. package/src/react/hooks/useGenerateOfferTransaction.tsx +60 -0
  155. package/src/react/hooks/useGenerateSellTransaction.tsx +43 -0
  156. package/src/react/hooks/useHighestOffer.tsx +46 -0
  157. package/src/react/hooks/useListBalances.tsx +56 -0
  158. package/src/react/hooks/useListCollectibles.tsx +54 -0
  159. package/src/react/hooks/useListOffersForCollectible.tsx +53 -0
  160. package/src/react/hooks/useLowestListing.tsx +47 -0
  161. package/src/react/hooks/useMarketplaceConfig.tsx +10 -0
  162. package/src/react/hooks/useRoyaltyPercentage.tsx +45 -0
  163. package/src/react/hooks/useTransferTokens.tsx +81 -0
  164. package/src/react/index.ts +5 -0
  165. package/src/react/provider.tsx +24 -0
  166. package/src/react/ssr/create-ssr-client.ts +31 -0
  167. package/src/react/ssr/index.ts +1 -0
  168. package/src/react/ui/icons/ArrowUp.tsx +29 -0
  169. package/src/react/ui/icons/CalendarIcon.tsx +29 -0
  170. package/src/react/ui/icons/InfoIcon.tsx +36 -0
  171. package/src/react/ui/icons/InventoryIcon.tsx +41 -0
  172. package/src/react/ui/icons/MinusIcon.tsx +31 -0
  173. package/src/react/ui/icons/PlusIcon.tsx +29 -0
  174. package/src/react/ui/icons/PositiveCircleIcon.tsx +35 -0
  175. package/src/react/ui/icons/index.ts +7 -0
  176. package/src/react/ui/icons/styles.css.ts +35 -0
  177. package/src/react/ui/index.ts +6 -0
  178. package/src/react/ui/modals/Account/index.tsx +29 -0
  179. package/src/react/ui/modals/CreateListingModal/_store.ts +326 -0
  180. package/src/react/ui/modals/CreateListingModal/_utils/getCreateListingTransactionTitleMessage.ts +30 -0
  181. package/src/react/ui/modals/CreateListingModal/index.tsx +146 -0
  182. package/src/react/ui/modals/MakeOfferModal/_store.ts +296 -0
  183. package/src/react/ui/modals/MakeOfferModal/_utils/getMakeOfferTransactionTitleMessage.ts +28 -0
  184. package/src/react/ui/modals/MakeOfferModal/index.tsx +157 -0
  185. package/src/react/ui/modals/SellModal/_store.ts +274 -0
  186. package/src/react/ui/modals/SellModal/_utils/getSellTransactionTitleMessage.ts +28 -0
  187. package/src/react/ui/modals/SellModal/index.tsx +126 -0
  188. package/src/react/ui/modals/SellModal/utils.ts +38 -0
  189. package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +58 -0
  190. package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +186 -0
  191. package/src/react/ui/modals/SuccessfulPurchaseModal/styles.css.ts +52 -0
  192. package/src/react/ui/modals/TransferModal/_store.ts +58 -0
  193. package/src/react/ui/modals/TransferModal/_utils/getTransferTransactionTitleMessage.ts +28 -0
  194. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +102 -0
  195. package/src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx +130 -0
  196. package/src/react/ui/modals/TransferModal/index.tsx +92 -0
  197. package/src/react/ui/modals/TransferModal/messages.ts +14 -0
  198. package/src/react/ui/modals/TransferModal/styles.css.ts +20 -0
  199. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +94 -0
  200. package/src/react/ui/modals/_internal/components/actionModal/index.ts +3 -0
  201. package/src/react/ui/modals/_internal/components/actionModal/store.ts +19 -0
  202. package/src/react/ui/modals/_internal/components/actionModal/styles.css.ts +15 -0
  203. package/src/react/ui/modals/_internal/components/alertMessage/index.tsx +21 -0
  204. package/src/react/ui/modals/_internal/components/alertMessage/styles.css.ts +22 -0
  205. package/src/react/ui/modals/_internal/components/calendar/index.tsx +59 -0
  206. package/src/react/ui/modals/_internal/components/calendarPopover/index.tsx +41 -0
  207. package/src/react/ui/modals/_internal/components/calendarPopover/styles.css.ts +16 -0
  208. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +76 -0
  209. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/styles.css.ts +33 -0
  210. package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +127 -0
  211. package/src/react/ui/modals/_internal/components/expirationDateSelect/styles.css.ts +25 -0
  212. package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +54 -0
  213. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +72 -0
  214. package/src/react/ui/modals/_internal/components/priceInput/styles.css.ts +23 -0
  215. package/src/react/ui/modals/_internal/components/priceInput/types.ts +4 -0
  216. package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +168 -0
  217. package/src/react/ui/modals/_internal/components/quantityInput/styles.css.ts +30 -0
  218. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +132 -0
  219. package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +41 -0
  220. package/src/react/ui/modals/_internal/components/switchChainModal/styles.css.ts +37 -0
  221. package/src/react/ui/modals/_internal/components/timeAgo/index.tsx +32 -0
  222. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +58 -0
  223. package/src/react/ui/modals/_internal/components/tokenPreview/styles.css.ts +11 -0
  224. package/src/react/ui/modals/_internal/components/transaction-footer/index.tsx +48 -0
  225. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +80 -0
  226. package/src/react/ui/modals/_internal/components/transactionHeader/index.tsx +30 -0
  227. package/src/react/ui/modals/_internal/components/transactionPreview/consts.ts +27 -0
  228. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +111 -0
  229. package/src/react/ui/modals/_internal/components/transactionPreview/useTransactionPreviewTitle.tsx +24 -0
  230. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +123 -0
  231. package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +87 -0
  232. package/src/react/ui/modals/_internal/components/transactionStatusModal/styles.css.ts +15 -0
  233. package/src/react/ui/modals/_internal/stores/accountModal.ts +3 -0
  234. package/src/react/ui/modals/modal-provider.tsx +27 -0
  235. package/src/react/ui/styles/index.ts +1 -0
  236. package/src/react/ui/styles/modal.css.ts +73 -0
  237. package/src/styles/index.ts +18 -0
  238. package/src/types/api-types.ts +48 -0
  239. package/src/types/index.ts +4 -0
  240. package/src/types/marketplace-config.ts +63 -0
  241. package/src/types/messages.ts +43 -0
  242. package/src/types/sdk-config.ts +23 -0
  243. package/src/types/types.ts +6 -0
  244. package/src/utils/abi/abi/standard/EIP2981.ts +15 -0
  245. package/src/utils/abi/abi/standard/index.ts +1 -0
  246. package/src/utils/abi/abi/token/ERC1155.ts +324 -0
  247. package/src/utils/abi/abi/token/ERC20.ts +185 -0
  248. package/src/utils/abi/abi/token/ERC721.ts +506 -0
  249. package/src/utils/abi/abi/token/index.ts +3 -0
  250. package/src/utils/abi/clients/ERC1155.ts +82 -0
  251. package/src/utils/abi/clients/ERC20.ts +101 -0
  252. package/src/utils/abi/clients/ERC721.ts +97 -0
  253. package/src/utils/abi/clients/index.ts +3 -0
  254. package/src/utils/address.ts +26 -0
  255. package/src/utils/get-public-rpc-client.ts +32 -0
  256. package/src/utils/index.ts +6 -0
  257. package/src/utils/network.ts +5 -0
  258. package/src/utils/price.ts +21 -0
@@ -0,0 +1,2740 @@
1
+ "use client"
2
+ import {
3
+ CalendarIcon_default,
4
+ InfoIcon_default,
5
+ MinusIcon_default,
6
+ PlusIcon_default,
7
+ PositiveCircleIcon_default
8
+ } from "./chunk-TZGLKJRF.js";
9
+ import {
10
+ ActionModal
11
+ } from "./chunk-4PFMUVE4.js";
12
+ import {
13
+ alertMessageBox,
14
+ alertMessageBoxVariants,
15
+ closeButton,
16
+ closeButton2,
17
+ closeButton3,
18
+ collectiblesGrid,
19
+ collectiblesGridImage,
20
+ collectiblesGridImagePale,
21
+ collectiblesGridItem,
22
+ currencySelect,
23
+ dateSelectButton,
24
+ dateSelectPopoverContent,
25
+ dialogContent,
26
+ dialogOverlay,
27
+ dialogOverlay2,
28
+ dialogOverlay3,
29
+ priceInputWrapper,
30
+ quantityInputWrapper,
31
+ rangeSelect,
32
+ switchChainCta,
33
+ switchChainModalContent,
34
+ tokenPreview,
35
+ transferModalContent
36
+ } from "./chunk-QOJXWHRZ.js";
37
+ import {
38
+ useCollectible,
39
+ useCollection,
40
+ useConfig,
41
+ useCurrencies,
42
+ useGenerateListingTransaction,
43
+ useGenerateOfferTransaction,
44
+ useLowestListing,
45
+ useMarketplaceConfig,
46
+ useRoyaltyPercentage,
47
+ useTokenBalances,
48
+ useTransferTokens
49
+ } from "./chunk-ZE2LNX65.js";
50
+ import {
51
+ calculatePriceDifferencePercentage,
52
+ truncateMiddle
53
+ } from "./chunk-6S4FYXP6.js";
54
+ import {
55
+ getMarketplaceClient
56
+ } from "./chunk-HGBEC3WX.js";
57
+
58
+ // src/react/ui/modals/modal-provider.tsx
59
+ import { observer as observer14 } from "@legendapp/state/react";
60
+
61
+ // src/react/ui/modals/_internal/components/switchChainModal/index.tsx
62
+ import { Close, Content, Overlay, Portal, Root } from "@radix-ui/react-dialog";
63
+
64
+ // src/react/ui/modals/_internal/components/switchChainModal/store.ts
65
+ import { observable } from "@legendapp/state";
66
+ var initialState = {
67
+ isOpen: false,
68
+ open: ({ chainIdToSwitchTo, onSwitchChain, messages }) => {
69
+ switchChainModal$.state.set({
70
+ ...switchChainModal$.state.get(),
71
+ chainIdToSwitchTo,
72
+ onSwitchChain,
73
+ messages
74
+ });
75
+ switchChainModal$.isOpen.set(true);
76
+ },
77
+ close: () => {
78
+ switchChainModal$.isOpen.set(false);
79
+ switchChainModal$.state.set({
80
+ ...initialState.state
81
+ });
82
+ },
83
+ state: {
84
+ chainIdToSwitchTo: void 0,
85
+ onSwitchChain: () => {
86
+ },
87
+ isSwitching: false
88
+ }
89
+ };
90
+ var switchChainModal$ = observable(initialState);
91
+
92
+ // src/react/ui/modals/_internal/components/switchChainModal/index.tsx
93
+ import {
94
+ Button,
95
+ CloseIcon,
96
+ IconButton,
97
+ Spinner,
98
+ Text as Text2
99
+ } from "@0xsequence/design-system";
100
+
101
+ // src/react/ui/modals/_internal/components/alertMessage/index.tsx
102
+ import { Box, Text, WarningIcon } from "@0xsequence/design-system";
103
+ import { jsx, jsxs } from "react/jsx-runtime";
104
+ function AlertMessage({ message, type }) {
105
+ return /* @__PURE__ */ jsxs(Box, { className: `${alertMessageBox} ${alertMessageBoxVariants[type]}`, children: [
106
+ /* @__PURE__ */ jsx(Text, { color: "white", fontSize: "normal", fontWeight: "medium", children: message }),
107
+ type === "warning" && /* @__PURE__ */ jsx(WarningIcon, { size: "sm", color: "white" }),
108
+ type === "info" && /* @__PURE__ */ jsx(InfoIcon_default, { size: "sm", color: "white" })
109
+ ] });
110
+ }
111
+
112
+ // src/react/ui/modals/_internal/components/switchChainModal/index.tsx
113
+ import { observer } from "@legendapp/state/react";
114
+ import { useSwitchChain } from "wagmi";
115
+ import { BaseError } from "viem";
116
+
117
+ // src/utils/network.ts
118
+ import { networks } from "@0xsequence/network";
119
+ var getPresentableChainName = (chainId) => {
120
+ return networks[chainId]?.name;
121
+ };
122
+
123
+ // src/react/ui/modals/_internal/components/switchChainModal/index.tsx
124
+ import { UserRejectedRequestError } from "viem";
125
+ import { SwitchChainNotSupportedError } from "wagmi";
126
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
127
+ var useSwitchChainModal = () => {
128
+ return {
129
+ show: (args) => switchChainModal$.open(args),
130
+ close: () => switchChainModal$.close(),
131
+ isSwitching$: switchChainModal$.state.isSwitching
132
+ };
133
+ };
134
+ var SwitchChainModal = observer(() => {
135
+ const chainIdToSwitchTo = switchChainModal$.state.chainIdToSwitchTo.get();
136
+ const isSwitching$ = switchChainModal$.state.isSwitching;
137
+ const chainName = getPresentableChainName(chainIdToSwitchTo);
138
+ const { switchChainAsync } = useSwitchChain();
139
+ const {
140
+ onSwitchingNotSupported,
141
+ onUserRejectedRequest,
142
+ onUnknownError,
143
+ onSuccess
144
+ } = switchChainModal$.state.messages.get() || {};
145
+ async function handleSwitchChain() {
146
+ isSwitching$.set(true);
147
+ try {
148
+ await switchChainAsync({ chainId: chainIdToSwitchTo });
149
+ switchChainModal$.state.onSwitchChain();
150
+ onSuccess && onSuccess();
151
+ switchChainModal$.close();
152
+ } catch (error) {
153
+ if (error instanceof BaseError) {
154
+ const name = error.name;
155
+ switch (name) {
156
+ case SwitchChainNotSupportedError.name:
157
+ onSwitchingNotSupported && onSwitchingNotSupported();
158
+ break;
159
+ case UserRejectedRequestError.name:
160
+ onUserRejectedRequest && onUserRejectedRequest();
161
+ break;
162
+ default:
163
+ onUnknownError && onUnknownError(error);
164
+ break;
165
+ }
166
+ } else {
167
+ onUnknownError && onUnknownError(error);
168
+ }
169
+ } finally {
170
+ isSwitching$.set(false);
171
+ }
172
+ }
173
+ return /* @__PURE__ */ jsx2(Root, { open: switchChainModal$.isOpen.get(), children: /* @__PURE__ */ jsxs2(Portal, { children: [
174
+ /* @__PURE__ */ jsx2(Overlay, { className: dialogOverlay }),
175
+ /* @__PURE__ */ jsxs2(Content, { className: switchChainModalContent, children: [
176
+ /* @__PURE__ */ jsx2(Text2, { fontSize: "large", fontWeight: "bold", color: "text100", children: "Wrong network" }),
177
+ /* @__PURE__ */ jsx2(
178
+ AlertMessage,
179
+ {
180
+ type: "warning",
181
+ message: `You need to switch to ${chainName} network before completing the transaction`
182
+ }
183
+ ),
184
+ /* @__PURE__ */ jsx2(
185
+ Button,
186
+ {
187
+ name: "switch-chain",
188
+ size: "sm",
189
+ label: isSwitching$.get() ? /* @__PURE__ */ jsx2(Spinner, {}) : "Switch Network",
190
+ variant: "primary",
191
+ pending: isSwitching$.get(),
192
+ shape: "square",
193
+ className: isSwitching$.get() ? switchChainCta.pending : switchChainCta.default,
194
+ justifySelf: "flex-end",
195
+ onClick: handleSwitchChain
196
+ }
197
+ ),
198
+ /* @__PURE__ */ jsx2(
199
+ Close,
200
+ {
201
+ onClick: () => {
202
+ switchChainModal$.delete();
203
+ },
204
+ className: closeButton,
205
+ asChild: true,
206
+ children: /* @__PURE__ */ jsx2(IconButton, { size: "xs", "aria-label": "Close modal", icon: CloseIcon })
207
+ }
208
+ )
209
+ ] })
210
+ ] }) });
211
+ });
212
+ var switchChainModal_default = SwitchChainModal;
213
+
214
+ // src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx
215
+ import { observer as observer3 } from "@legendapp/state/react";
216
+
217
+ // src/react/ui/modals/_internal/components/transactionStatusModal/store.ts
218
+ import { observable as observable2 } from "@legendapp/state";
219
+ var initialState2 = {
220
+ isOpen: false,
221
+ open: ({
222
+ hash,
223
+ price,
224
+ collectionAddress,
225
+ chainId,
226
+ tokenId,
227
+ getTitle,
228
+ getMessage: getMessage2,
229
+ type
230
+ }) => {
231
+ transactionStatusModal$.state.set({
232
+ ...transactionStatusModal$.state.get(),
233
+ hash,
234
+ price,
235
+ collectionAddress,
236
+ chainId,
237
+ tokenId,
238
+ getTitle,
239
+ getMessage: getMessage2,
240
+ type
241
+ });
242
+ transactionStatusModal$.isOpen.set(true);
243
+ },
244
+ close: () => {
245
+ transactionStatusModal$.isOpen.set(false);
246
+ transactionStatusModal$.state.set({
247
+ ...initialState2.state
248
+ });
249
+ },
250
+ state: {
251
+ hash: void 0,
252
+ status: "PENDING",
253
+ price: void 0,
254
+ collectionAddress: "",
255
+ chainId: "",
256
+ tokenId: "",
257
+ getTitle: void 0,
258
+ getMessage: void 0,
259
+ type: void 0
260
+ }
261
+ };
262
+ var transactionStatusModal$ = observable2(initialState2);
263
+
264
+ // src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx
265
+ import { Close as Close2, Content as Content2, Overlay as Overlay2, Portal as Portal2, Root as Root2 } from "@radix-ui/react-dialog";
266
+
267
+ // src/react/ui/modals/_internal/components/transactionStatusModal/styles.css.ts
268
+ var closeButton4 = "fyvr11lw fyvr1tc fyvr1mo";
269
+ var dialogOverlay4 = "fyvr1m0 fyvr1o8 fyvr1qg fyvr1so fyvr11xl fyvr11m0 fyvr11rs";
270
+ var transactionStatusModalContent = "modal_dialogContent_wide__1ypl6nt3 modal_dialogContentBase__1ypl6nt1 fyvr11hg fyvr11i4 fyvr11g4 fyvr11gs fyvr11l8 fyvr11wl fyvr11m0 fyvr11rs fyvr1vo fyvr1xs fyvr1zw fyvr1120 fyvr11lc fyvr11mc fyvr11cw";
271
+
272
+ // src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx
273
+ import {
274
+ CloseIcon as CloseIcon2,
275
+ IconButton as IconButton2,
276
+ Skeleton,
277
+ Text as Text6
278
+ } from "@0xsequence/design-system";
279
+
280
+ // src/react/ui/modals/_internal/components/transactionPreview/index.tsx
281
+ import { Box as Box3, Image, NetworkImage, Text as Text4 } from "@0xsequence/design-system";
282
+
283
+ // src/react/ui/modals/_internal/components/timeAgo/index.tsx
284
+ import { Box as Box2, Text as Text3 } from "@0xsequence/design-system";
285
+ import { formatDistanceToNow } from "date-fns";
286
+ import { useState, useEffect } from "react";
287
+ import { jsx as jsx3 } from "react/jsx-runtime";
288
+ function TimeAgo({ date }) {
289
+ const [timeAgo, setTimeAgo] = useState("");
290
+ useEffect(() => {
291
+ const interval = setInterval(() => {
292
+ setTimeAgo(formatDistanceToNow(date));
293
+ }, 1e3);
294
+ return () => clearInterval(interval);
295
+ }, [date]);
296
+ return /* @__PURE__ */ jsx3(
297
+ Box2,
298
+ {
299
+ flexGrow: "1",
300
+ display: "flex",
301
+ alignItems: "center",
302
+ justifyContent: "flex-end",
303
+ children: /* @__PURE__ */ jsx3(Text3, { color: "text50", fontSize: "small", children: timeAgo })
304
+ }
305
+ );
306
+ }
307
+
308
+ // src/react/ui/modals/_internal/components/transactionPreview/index.tsx
309
+ import { observer as observer2 } from "@legendapp/state/react";
310
+
311
+ // src/react/ui/modals/_internal/components/transactionPreview/useTransactionPreviewTitle.tsx
312
+ import { useMemo } from "react";
313
+
314
+ // src/react/ui/modals/_internal/components/transactionPreview/consts.ts
315
+ var TRANSACTION_TITLES = {
316
+ sell: {
317
+ confirming: "Selling",
318
+ confirmed: "Sold",
319
+ failed: "Sale failed"
320
+ },
321
+ createListing: {
322
+ confirming: "Creating listing",
323
+ confirmed: "Listed",
324
+ failed: "Listing failed"
325
+ },
326
+ createOffer: {
327
+ confirming: "Creating offer",
328
+ confirmed: "Offer created",
329
+ failed: "Offer failed"
330
+ },
331
+ buy: {
332
+ confirming: "Buying",
333
+ confirmed: "Bought",
334
+ failed: "Purchase failed"
335
+ },
336
+ transfer: {
337
+ confirming: "Transferring",
338
+ confirmed: "Transferred",
339
+ failed: "Transfer failed"
340
+ }
341
+ };
342
+
343
+ // src/react/ui/modals/_internal/components/transactionPreview/useTransactionPreviewTitle.tsx
344
+ function useTransactionPreviewTitle(status, type) {
345
+ return useMemo(() => {
346
+ if (!type) return "";
347
+ const { isConfirming, isConfirmed, isFailed } = status;
348
+ const titles = TRANSACTION_TITLES[type];
349
+ if (isConfirming) return titles.confirming;
350
+ if (isConfirmed) return titles.confirmed;
351
+ if (isFailed) return titles.failed;
352
+ return "";
353
+ }, [status, type]);
354
+ }
355
+
356
+ // src/react/ui/modals/_internal/components/transactionPreview/index.tsx
357
+ import { formatUnits } from "viem";
358
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
359
+ var TransactionPreview = observer2(
360
+ ({
361
+ price,
362
+ collectionAddress,
363
+ chainId,
364
+ collectible,
365
+ isConfirming,
366
+ isConfirmed,
367
+ isFailed
368
+ }) => {
369
+ const { type } = transactionStatusModal$.state.get();
370
+ const title = useTransactionPreviewTitle(
371
+ { isConfirmed, isConfirming, isFailed },
372
+ type
373
+ );
374
+ const { data: collection } = useCollection({
375
+ collectionAddress,
376
+ chainId
377
+ });
378
+ const collectibleImage = collectible.image;
379
+ const collectibleName = collectible.name;
380
+ const collectionName = collection?.name;
381
+ const priceFormatted = price ? formatUnits(BigInt(price.amountRaw), price.currency.decimals) : void 0;
382
+ return /* @__PURE__ */ jsxs3(Box3, { padding: "3", background: "backgroundSecondary", borderRadius: "md", children: [
383
+ /* @__PURE__ */ jsxs3(Box3, { display: "flex", alignItems: "center", children: [
384
+ /* @__PURE__ */ jsx4(
385
+ Text4,
386
+ {
387
+ color: "text50",
388
+ fontSize: "small",
389
+ fontWeight: "medium",
390
+ marginRight: "1",
391
+ children: title
392
+ }
393
+ ),
394
+ /* @__PURE__ */ jsx4(NetworkImage, { chainId: Number(chainId), size: "xs" }),
395
+ isConfirming && /* @__PURE__ */ jsx4(TimeAgo, { date: /* @__PURE__ */ new Date() })
396
+ ] }),
397
+ /* @__PURE__ */ jsxs3(Box3, { display: "flex", alignItems: "center", marginTop: "2", children: [
398
+ /* @__PURE__ */ jsx4(
399
+ Image,
400
+ {
401
+ src: collectibleImage,
402
+ alt: collectibleName,
403
+ width: "9",
404
+ height: "9",
405
+ borderRadius: "xs",
406
+ marginRight: "3"
407
+ }
408
+ ),
409
+ /* @__PURE__ */ jsxs3(
410
+ Box3,
411
+ {
412
+ display: "flex",
413
+ flexDirection: "column",
414
+ alignItems: "flex-start",
415
+ gap: "0.5",
416
+ children: [
417
+ /* @__PURE__ */ jsx4(Text4, { color: "text80", fontSize: "small", fontWeight: "medium", children: collectibleName }),
418
+ /* @__PURE__ */ jsx4(Text4, { color: "text100", fontSize: "small", children: collectionName })
419
+ ]
420
+ }
421
+ ),
422
+ price && /* @__PURE__ */ jsxs3(
423
+ Box3,
424
+ {
425
+ flexGrow: "1",
426
+ display: "flex",
427
+ alignItems: "center",
428
+ justifyContent: "flex-end",
429
+ gap: "1",
430
+ children: [
431
+ /* @__PURE__ */ jsx4(NetworkImage, { chainId: Number(chainId), size: "xs" }),
432
+ /* @__PURE__ */ jsxs3(Text4, { color: "text80", fontSize: "small", fontWeight: "medium", children: [
433
+ priceFormatted,
434
+ " ",
435
+ price.currency.symbol
436
+ ] })
437
+ ]
438
+ }
439
+ )
440
+ ] })
441
+ ] });
442
+ }
443
+ );
444
+ var transactionPreview_default = TransactionPreview;
445
+
446
+ // src/react/ui/modals/_internal/components/transaction-footer/index.tsx
447
+ import { Box as Box4, Spinner as Spinner2, Text as Text5 } from "@0xsequence/design-system";
448
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
449
+ function TransactionFooter({
450
+ transactionHash,
451
+ isConfirming,
452
+ isConfirmed,
453
+ isFailed
454
+ }) {
455
+ const icon = isConfirming && /* @__PURE__ */ jsx5(Spinner2, { size: "md" }) || isConfirmed && /* @__PURE__ */ jsx5(PositiveCircleIcon_default, { size: "md" });
456
+ const title = isConfirming && "Processing transaction" || isConfirmed && "Transaction complete" || isFailed && "Transaction failed";
457
+ return /* @__PURE__ */ jsxs4(Box4, { display: "flex", alignItems: "center", children: [
458
+ icon,
459
+ /* @__PURE__ */ jsx5(Text5, { color: "text50", fontSize: "normal", fontWeight: "medium", marginLeft: "2", children: title }),
460
+ /* @__PURE__ */ jsx5(
461
+ Text5,
462
+ {
463
+ color: "polygonLight",
464
+ flexGrow: "1",
465
+ textAlign: "right",
466
+ fontSize: "normal",
467
+ fontWeight: "medium",
468
+ marginLeft: "2",
469
+ children: truncateMiddle(transactionHash, 4, 4)
470
+ }
471
+ )
472
+ ] });
473
+ }
474
+
475
+ // src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx
476
+ import { useTransactionReceipt } from "wagmi";
477
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
478
+ var useTransactionStatusModal = () => {
479
+ return {
480
+ show: (args) => transactionStatusModal$.open(args),
481
+ close: () => transactionStatusModal$.close()
482
+ };
483
+ };
484
+ var TransactionStatusModal = observer3(() => {
485
+ const {
486
+ hash,
487
+ price,
488
+ collectionAddress,
489
+ chainId,
490
+ tokenId,
491
+ getTitle,
492
+ getMessage: getMessage2
493
+ } = transactionStatusModal$.state.get();
494
+ const { data: collectible } = useCollectible({
495
+ collectionAddress,
496
+ chainId,
497
+ collectibleId: tokenId
498
+ });
499
+ const {
500
+ isLoading: isConfirming,
501
+ isSuccess: isConfirmed,
502
+ isError: isFailed
503
+ } = useTransactionReceipt({ hash });
504
+ const title = getTitle && getTitle({ isConfirmed, isConfirming, isFailed });
505
+ const message = getMessage2 && getMessage2({ isConfirmed, isConfirming, isFailed });
506
+ return /* @__PURE__ */ jsx6(Root2, { open: transactionStatusModal$.isOpen.get(), children: /* @__PURE__ */ jsxs5(Portal2, { children: [
507
+ /* @__PURE__ */ jsx6(Overlay2, { className: dialogOverlay4 }),
508
+ /* @__PURE__ */ jsxs5(Content2, { className: transactionStatusModalContent, children: [
509
+ title ? /* @__PURE__ */ jsx6(Text6, { fontSize: "large", fontWeight: "bold", color: "text100", children: title }) : /* @__PURE__ */ jsx6(Skeleton, { width: "16", height: "6" }),
510
+ message ? /* @__PURE__ */ jsx6(Text6, { fontSize: "small", color: "text80", children: message }) : /* @__PURE__ */ jsx6(Skeleton, { width: "20", height: "4" }),
511
+ /* @__PURE__ */ jsx6(
512
+ transactionPreview_default,
513
+ {
514
+ price,
515
+ collectionAddress,
516
+ chainId,
517
+ collectible,
518
+ isConfirming,
519
+ isConfirmed,
520
+ isFailed
521
+ }
522
+ ),
523
+ /* @__PURE__ */ jsx6(
524
+ TransactionFooter,
525
+ {
526
+ transactionHash: hash,
527
+ isConfirming,
528
+ isConfirmed,
529
+ isFailed
530
+ }
531
+ ),
532
+ /* @__PURE__ */ jsx6(
533
+ Close2,
534
+ {
535
+ onClick: () => {
536
+ transactionStatusModal$.close();
537
+ },
538
+ className: closeButton4,
539
+ asChild: true,
540
+ children: /* @__PURE__ */ jsx6(IconButton2, { size: "xs", "aria-label": "Close modal", icon: CloseIcon2 })
541
+ }
542
+ )
543
+ ] })
544
+ ] }) });
545
+ });
546
+ var transactionStatusModal_default = TransactionStatusModal;
547
+
548
+ // src/react/ui/modals/Account/index.tsx
549
+ import { Box as Box5, Button as Button2, Modal, Text as Text7 } from "@0xsequence/design-system";
550
+ import { observable as observable3 } from "@legendapp/state";
551
+ import { observer as observer4 } from "@legendapp/state/react";
552
+ import { useAccount } from "wagmi";
553
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
554
+ var accountModalOpen$ = observable3(false);
555
+ var AccountModal = observer4(function AccountModal2() {
556
+ const { address } = useAccount();
557
+ return accountModalOpen$.get() && /* @__PURE__ */ jsxs6(Modal, { children: [
558
+ /* @__PURE__ */ jsxs6(Box5, { children: [
559
+ /* @__PURE__ */ jsx7(Text7, { children: "Wallet address" }),
560
+ /* @__PURE__ */ jsx7(Text7, { children: address })
561
+ ] }),
562
+ /* @__PURE__ */ jsx7(Button2, { label: "Sign out" })
563
+ ] });
564
+ });
565
+
566
+ // src/react/ui/modals/CreateListingModal/index.tsx
567
+ import { Box as Box12 } from "@0xsequence/design-system";
568
+ import { Show, observer as observer8 } from "@legendapp/state/react";
569
+
570
+ // src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx
571
+ import { useState as useState2 } from "react";
572
+ import { Box as Box6, Select, Text as Text8 } from "@0xsequence/design-system";
573
+ import { observer as observer5 } from "@legendapp/state/react";
574
+ import { addDays, isSameDay } from "date-fns";
575
+
576
+ // src/react/ui/modals/_internal/components/calendarPopover/index.tsx
577
+ import { Button as Button3 } from "@0xsequence/design-system";
578
+ import { Content as Content3, Portal as Portal3, Root as Root3, Trigger } from "@radix-ui/react-popover";
579
+ import { format } from "date-fns";
580
+
581
+ // src/react/ui/modals/_internal/components/calendar/index.tsx
582
+ import { DayPicker } from "react-day-picker";
583
+ import "react-day-picker/style.css";
584
+ import { jsx as jsx8 } from "react/jsx-runtime";
585
+ function Calendar({ ...props }) {
586
+ const { selectedDate, setSelectedDate } = props;
587
+ return /* @__PURE__ */ jsx8(
588
+ DayPicker,
589
+ {
590
+ disabled: {
591
+ before: /* @__PURE__ */ new Date()
592
+ },
593
+ selected: selectedDate,
594
+ onDayClick: setSelectedDate,
595
+ defaultMonth: selectedDate,
596
+ modifiersStyles: {
597
+ selected: {
598
+ color: "hsl(var(--foreground))",
599
+ background: "hsl(var(--primary))",
600
+ border: "none"
601
+ }
602
+ },
603
+ styles: {
604
+ root: {
605
+ width: "max-content",
606
+ margin: 0,
607
+ color: "hsl(var(--foreground))",
608
+ background: "hsl(var(--background))",
609
+ border: `1px solid hsl(var(--border))`,
610
+ borderRadius: "var(--radius)",
611
+ padding: "0.5rem",
612
+ position: "relative"
613
+ },
614
+ day: {
615
+ margin: 0,
616
+ width: "1rem",
617
+ height: "1rem"
618
+ },
619
+ day_button: {
620
+ margin: 0,
621
+ width: "1.8rem",
622
+ height: "1.5rem",
623
+ padding: 0,
624
+ border: "none"
625
+ }
626
+ },
627
+ ...props
628
+ }
629
+ );
630
+ }
631
+ Calendar.displayName = "Calendar";
632
+ var calendar_default = Calendar;
633
+
634
+ // src/react/ui/modals/_internal/components/calendarPopover/index.tsx
635
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
636
+ function CalendarPopover({
637
+ selectedDate,
638
+ setSelectedDate
639
+ }) {
640
+ return /* @__PURE__ */ jsxs7(Root3, { children: [
641
+ /* @__PURE__ */ jsx9(Trigger, { asChild: true, children: /* @__PURE__ */ jsx9(
642
+ Button3,
643
+ {
644
+ leftIcon: CalendarIcon_default,
645
+ className: dateSelectButton,
646
+ variant: "ghost",
647
+ label: format(selectedDate, "dd/MM/yyyy HH:mm"),
648
+ shape: "square"
649
+ }
650
+ ) }),
651
+ /* @__PURE__ */ jsx9(Portal3, { children: /* @__PURE__ */ jsx9(Content3, { className: dateSelectPopoverContent, sideOffset: 5, children: /* @__PURE__ */ jsx9(
652
+ calendar_default,
653
+ {
654
+ selectedDate,
655
+ setSelectedDate,
656
+ mode: "single"
657
+ }
658
+ ) }) })
659
+ ] });
660
+ }
661
+
662
+ // src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx
663
+ import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
664
+ var PRESET_RANGES = {
665
+ TODAY: {
666
+ label: "Today",
667
+ value: "today",
668
+ offset: 0
669
+ },
670
+ TOMORROW: {
671
+ label: "Tomorrow",
672
+ value: "tomorrow",
673
+ offset: 1
674
+ },
675
+ IN_3_DAYS: {
676
+ label: "In 3 days",
677
+ value: "3_days",
678
+ offset: 3
679
+ },
680
+ ONE_WEEK: {
681
+ label: "1 week",
682
+ value: "1_week",
683
+ offset: 7
684
+ },
685
+ ONE_MONTH: {
686
+ label: "1 month",
687
+ value: "1_month",
688
+ offset: 30
689
+ }
690
+ };
691
+ var ExpirationDateSelect = observer5(function ExpirationDateSelect2({
692
+ className,
693
+ $date
694
+ }) {
695
+ const [_, setRange] = useState2("1_week");
696
+ function handleSelectPresetRange(range) {
697
+ setRange(range);
698
+ const presetRange = Object.values(PRESET_RANGES).find(
699
+ (preset) => preset.value === range
700
+ );
701
+ if (!presetRange) {
702
+ return;
703
+ }
704
+ const newDate = addDays(/* @__PURE__ */ new Date(), presetRange.offset);
705
+ $date.set(newDate);
706
+ }
707
+ function handleDateValueChange(date) {
708
+ const presetRange = Object.values(PRESET_RANGES).find(
709
+ (preset) => isSameDay(new Date(date), addDays(/* @__PURE__ */ new Date(), preset.offset))
710
+ );
711
+ if (presetRange) {
712
+ setRange(presetRange.value);
713
+ }
714
+ $date.set(date);
715
+ }
716
+ return /* @__PURE__ */ jsxs8(Box6, { width: "full", position: "relative", children: [
717
+ /* @__PURE__ */ jsx10(
718
+ Text8,
719
+ {
720
+ fontSize: "small",
721
+ fontWeight: "medium",
722
+ textAlign: "left",
723
+ width: "full",
724
+ color: "text100",
725
+ children: "Set expiry"
726
+ }
727
+ ),
728
+ /* @__PURE__ */ jsxs8(
729
+ Box6,
730
+ {
731
+ className,
732
+ width: "full",
733
+ display: "flex",
734
+ alignItems: "center",
735
+ gap: "2",
736
+ marginTop: "0.5",
737
+ children: [
738
+ /* @__PURE__ */ jsx10(Box6, { className: rangeSelect, position: "absolute", right: "2", children: /* @__PURE__ */ jsx10(
739
+ Select,
740
+ {
741
+ name: "expirationDate",
742
+ options: Object.values(PRESET_RANGES),
743
+ defaultValue: void 0,
744
+ value: Object.values(PRESET_RANGES).find(
745
+ (preset) => isSameDay(
746
+ new Date($date.get()),
747
+ addDays(/* @__PURE__ */ new Date(), preset.offset)
748
+ )
749
+ )?.value,
750
+ onValueChange: (value) => handleSelectPresetRange(value)
751
+ }
752
+ ) }),
753
+ /* @__PURE__ */ jsx10(
754
+ CalendarPopover,
755
+ {
756
+ selectedDate: $date.get(),
757
+ setSelectedDate: (date) => handleDateValueChange(date)
758
+ }
759
+ )
760
+ ]
761
+ }
762
+ )
763
+ ] });
764
+ });
765
+ var expirationDateSelect_default = ExpirationDateSelect;
766
+
767
+ // src/react/ui/modals/_internal/components/floorPriceText/index.tsx
768
+ import { Text as Text9 } from "@0xsequence/design-system";
769
+ import { jsx as jsx11 } from "react/jsx-runtime";
770
+ function FloorPriceText({
771
+ chainId,
772
+ collectionAddress,
773
+ tokenId,
774
+ price
775
+ }) {
776
+ const { data: listing, isLoading: listingLoading } = useLowestListing({
777
+ tokenId,
778
+ chainId,
779
+ collectionAddress,
780
+ filters: {
781
+ currencies: [price.currency.contractAddress]
782
+ }
783
+ });
784
+ const floorPriceRaw = listing?.order?.priceAmount;
785
+ if (!floorPriceRaw || listingLoading || price.amountRaw === "0") {
786
+ return null;
787
+ }
788
+ const floorPriceDifference = calculatePriceDifferencePercentage({
789
+ inputPriceRaw: BigInt(price.amountRaw),
790
+ basePriceRaw: BigInt(floorPriceRaw),
791
+ decimals: price.currency.decimals
792
+ });
793
+ const floorPriceDifferenceText = floorPriceRaw === price.amountRaw ? "Same as floor price" : `${floorPriceDifference}% ${floorPriceRaw > price.amountRaw ? "below" : "above"} floor price`;
794
+ return /* @__PURE__ */ jsx11(
795
+ Text9,
796
+ {
797
+ fontSize: "small",
798
+ fontWeight: "medium",
799
+ textAlign: "left",
800
+ width: "full",
801
+ color: "text50",
802
+ children: floorPriceDifferenceText
803
+ }
804
+ );
805
+ }
806
+
807
+ // src/react/ui/modals/_internal/components/priceInput/index.tsx
808
+ import { Box as Box8, NumericInput, TokenImage } from "@0xsequence/design-system";
809
+ import { observer as observer7 } from "@legendapp/state/react";
810
+ import { useState as useState4 } from "react";
811
+
812
+ // src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx
813
+ import { Box as Box7, Select as Select2, Skeleton as Skeleton2 } from "@0xsequence/design-system";
814
+ import { observer as observer6 } from "@legendapp/state/react";
815
+ import { useEffect as useEffect2, useState as useState3 } from "react";
816
+ import { jsx as jsx12 } from "react/jsx-runtime";
817
+ var CurrencyOptionsSelect = observer6(function CurrencyOptionsSelect2({
818
+ chainId,
819
+ collectionAddress,
820
+ $selectedCurrency
821
+ }) {
822
+ const [value, setValue] = useState3(null);
823
+ const { data: currencies, isLoading: currenciesLoading } = useCurrencies({
824
+ collectionAddress,
825
+ chainId
826
+ });
827
+ useEffect2(() => {
828
+ if (currencies && currencies.length > 0 && !$selectedCurrency.contractAddress.get()) {
829
+ $selectedCurrency.set(currencies[0]);
830
+ }
831
+ }, [currencies]);
832
+ if (!currencies || currenciesLoading) {
833
+ return /* @__PURE__ */ jsx12(Skeleton2, { borderRadius: "lg", width: "20", height: "7", marginRight: "3" });
834
+ }
835
+ const options = currencies.map(
836
+ (currency) => ({
837
+ label: currency.name,
838
+ value: currency.contractAddress
839
+ })
840
+ );
841
+ const onChange = (value2) => {
842
+ const c = currencies.find(
843
+ (currency) => currency.contractAddress === value2
844
+ );
845
+ setValue(value2);
846
+ $selectedCurrency.set(c);
847
+ };
848
+ return /* @__PURE__ */ jsx12(Box7, { className: currencySelect, children: /* @__PURE__ */ jsx12(
849
+ Select2,
850
+ {
851
+ name: "currencies",
852
+ value: value || options?.[0]?.value,
853
+ onValueChange: (value2) => onChange(value2),
854
+ options
855
+ }
856
+ ) });
857
+ });
858
+ var currencyOptionsSelect_default = CurrencyOptionsSelect;
859
+
860
+ // src/react/ui/modals/_internal/components/priceInput/index.tsx
861
+ import { parseUnits } from "viem";
862
+ import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
863
+ var PriceInput = observer7(function PriceInput2({
864
+ chainId,
865
+ collectionAddress,
866
+ $listingPrice,
867
+ error
868
+ }) {
869
+ const [inputPrice, setInputPrice] = useState4("");
870
+ const changeListingPrice = (value) => {
871
+ setInputPrice(value);
872
+ const parsedAmount = parseUnits(
873
+ value,
874
+ Number($listingPrice.currency.decimals.get())
875
+ );
876
+ $listingPrice.amountRaw.set(parsedAmount.toString());
877
+ };
878
+ return /* @__PURE__ */ jsxs9(Box8, { className: priceInputWrapper, position: "relative", children: [
879
+ /* @__PURE__ */ jsx13(
880
+ Box8,
881
+ {
882
+ position: "absolute",
883
+ bottom: "3",
884
+ left: "2",
885
+ display: "flex",
886
+ alignItems: "center",
887
+ children: /* @__PURE__ */ jsx13(TokenImage, { src: $listingPrice.currency.imageUrl.get(), size: "xs" })
888
+ }
889
+ ),
890
+ /* @__PURE__ */ jsx13(
891
+ NumericInput,
892
+ {
893
+ name: "listingPrice",
894
+ decimals: $listingPrice?.currency.decimals.get(),
895
+ label: "Enter price",
896
+ labelLocation: "top",
897
+ placeholder: "0.00",
898
+ controls: /* @__PURE__ */ jsx13(
899
+ currencyOptionsSelect_default,
900
+ {
901
+ $selectedCurrency: $listingPrice?.currency,
902
+ collectionAddress,
903
+ chainId
904
+ }
905
+ ),
906
+ numeric: true,
907
+ value: inputPrice,
908
+ onChange: (event) => changeListingPrice(event.target.value),
909
+ width: "full"
910
+ }
911
+ ),
912
+ error && /* @__PURE__ */ jsx13(Box8, { color: "negative", fontSize: "small", children: error })
913
+ ] });
914
+ });
915
+ var priceInput_default = PriceInput;
916
+
917
+ // src/react/ui/modals/_internal/components/quantityInput/index.tsx
918
+ import { Box as Box9, IconButton as IconButton3, NumericInput as NumericInput2 } from "@0xsequence/design-system";
919
+ import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
920
+ function QuantityInput({
921
+ $quantity,
922
+ chainId,
923
+ collectionAddress,
924
+ collectibleId
925
+ }) {
926
+ const { data: collectable, isLoading: collectableLoading } = useCollectible({
927
+ chainId,
928
+ collectionAddress,
929
+ collectibleId
930
+ });
931
+ const quantityDecimals = collectable && (collectable.decimals || 0);
932
+ function handleChangeQuantity(value) {
933
+ if (!isValidInput(value)) return;
934
+ const formattedValue = formatQuantity(value);
935
+ if (formattedValue !== null) {
936
+ $quantity.set(formattedValue);
937
+ }
938
+ }
939
+ function handleIncrement() {
940
+ if (!isValidInput()) return;
941
+ const newQuantity = incrementQuantity();
942
+ if (newQuantity !== null) {
943
+ $quantity.set(newQuantity);
944
+ }
945
+ }
946
+ function handleDecrement() {
947
+ if (!isValidInput()) return;
948
+ const newQuantity = decrementQuantity();
949
+ if (newQuantity !== null) {
950
+ $quantity.set(newQuantity);
951
+ }
952
+ }
953
+ function isValidInput(value) {
954
+ return collectable !== void 0 && quantityDecimals !== void 0 && (value === void 0 || value !== "");
955
+ }
956
+ function formatQuantity(value) {
957
+ if (quantityDecimals === 0 && value.includes(".")) {
958
+ return null;
959
+ }
960
+ if (quantityDecimals && quantityDecimals > 0) {
961
+ const decimalIndex = value.indexOf(".");
962
+ if (decimalIndex !== -1 && value.length - decimalIndex > quantityDecimals + 1) {
963
+ return null;
964
+ }
965
+ }
966
+ return value;
967
+ }
968
+ const quantity = $quantity.get();
969
+ function incrementQuantity() {
970
+ if (!isValidInput()) return null;
971
+ if (!quantity) {
972
+ return quantityDecimals === 0 ? "1" : `1.${"0".repeat(quantityDecimals)}`;
973
+ }
974
+ const newValue = quantityDecimals === 0 ? (Number.parseInt(quantity) + 1).toString() : (Number.parseFloat(quantity) + 1).toFixed(quantityDecimals);
975
+ return newValue;
976
+ }
977
+ function decrementQuantity() {
978
+ if (!quantity) {
979
+ return "1";
980
+ }
981
+ const newValue = Number.parseFloat(quantity) - 1;
982
+ if (newValue < 0) {
983
+ return null;
984
+ }
985
+ return quantityDecimals === 0 ? newValue.toString() : newValue.toFixed(quantityDecimals);
986
+ }
987
+ function getPlaceholder(decimals) {
988
+ if (decimals === 0) {
989
+ return "0";
990
+ } else {
991
+ return "0." + "0".repeat(decimals);
992
+ }
993
+ }
994
+ if (collectableLoading) {
995
+ return null;
996
+ }
997
+ return /* @__PURE__ */ jsx14(Box9, { className: quantityInputWrapper, children: /* @__PURE__ */ jsx14(
998
+ NumericInput2,
999
+ {
1000
+ name: "quantity",
1001
+ decimals: quantityDecimals || 0,
1002
+ paddingLeft: "1",
1003
+ label: "Enter quantity",
1004
+ labelLocation: "top",
1005
+ placeholder: getPlaceholder(quantityDecimals || 0),
1006
+ controls: /* @__PURE__ */ jsxs10(
1007
+ Box9,
1008
+ {
1009
+ display: "flex",
1010
+ alignItems: "center",
1011
+ gap: "1",
1012
+ marginRight: "2",
1013
+ children: [
1014
+ /* @__PURE__ */ jsx14(
1015
+ IconButton3,
1016
+ {
1017
+ disabled: Number.parseFloat(quantity) === 0 || !quantity,
1018
+ onClick: handleDecrement,
1019
+ background: "buttonGlass",
1020
+ size: "xs",
1021
+ icon: MinusIcon_default
1022
+ }
1023
+ ),
1024
+ /* @__PURE__ */ jsx14(
1025
+ IconButton3,
1026
+ {
1027
+ onClick: handleIncrement,
1028
+ background: "buttonGlass",
1029
+ size: "xs",
1030
+ icon: PlusIcon_default
1031
+ }
1032
+ )
1033
+ ]
1034
+ }
1035
+ ),
1036
+ numeric: true,
1037
+ value: $quantity.get(),
1038
+ onChange: (e) => handleChangeQuantity(e.target.value),
1039
+ width: "full"
1040
+ }
1041
+ ) });
1042
+ }
1043
+
1044
+ // src/react/ui/modals/_internal/components/tokenPreview/index.tsx
1045
+ import { Box as Box10, Image as Image2, Skeleton as Skeleton3, Text as Text10 } from "@0xsequence/design-system";
1046
+ import { jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
1047
+ function TokenPreview({
1048
+ collectionName,
1049
+ collectionAddress,
1050
+ collectibleId,
1051
+ chainId
1052
+ }) {
1053
+ const { data: collectable, isLoading: collectibleLoading } = useCollectible({
1054
+ chainId,
1055
+ collectionAddress,
1056
+ collectibleId
1057
+ });
1058
+ if (collectibleLoading) {
1059
+ return /* @__PURE__ */ jsxs11(Box10, { display: "flex", alignItems: "center", gap: "3", width: "full", children: [
1060
+ /* @__PURE__ */ jsx15(Skeleton3, { width: "9", height: "9", borderRadius: "xs" }),
1061
+ /* @__PURE__ */ jsxs11(Box10, { display: "flex", flexGrow: "1", gap: "1", flexDirection: "column", children: [
1062
+ /* @__PURE__ */ jsx15(Skeleton3, { width: "1/3", height: "3" }),
1063
+ /* @__PURE__ */ jsx15(Skeleton3, { width: "1/2", height: "3" })
1064
+ ] })
1065
+ ] });
1066
+ }
1067
+ return /* @__PURE__ */ jsxs11(Box10, { className: tokenPreview, children: [
1068
+ /* @__PURE__ */ jsx15(
1069
+ Image2,
1070
+ {
1071
+ src: collectable?.image,
1072
+ alt: collectable?.name,
1073
+ width: "9",
1074
+ height: "9",
1075
+ borderRadius: "xs"
1076
+ }
1077
+ ),
1078
+ /* @__PURE__ */ jsxs11(Box10, { display: "flex", flexDirection: "column", marginLeft: "3", children: [
1079
+ /* @__PURE__ */ jsx15(Text10, { fontSize: "small", color: "text80", fontWeight: "medium", children: collectionName }),
1080
+ /* @__PURE__ */ jsx15(Text10, { fontSize: "small", fontWeight: "bold", color: "text100", children: collectable?.name })
1081
+ ] })
1082
+ ] });
1083
+ }
1084
+
1085
+ // src/react/ui/modals/_internal/components/transactionDetails/index.tsx
1086
+ import { Box as Box11, NetworkImage as NetworkImage2, Skeleton as Skeleton4, Text as Text11 } from "@0xsequence/design-system";
1087
+ import { formatUnits as formatUnits2 } from "viem";
1088
+ import { jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
1089
+ var DEFAULT_MARKETPLACE_FEE_PERCENTAGE = 2.5;
1090
+ function TransactionDetails({
1091
+ collectibleId,
1092
+ collectionAddress,
1093
+ chainId,
1094
+ price
1095
+ }) {
1096
+ const { data, isLoading: marketplaceConfigLoading } = useMarketplaceConfig();
1097
+ const marketplaceFeePercentage = data?.collections.find(
1098
+ (collection) => collection.collectionAddress === collectionAddress
1099
+ )?.marketplaceFeePercentage || DEFAULT_MARKETPLACE_FEE_PERCENTAGE;
1100
+ const { data: royaltyPercentage, isLoading: royaltyPercentageLoading } = useRoyaltyPercentage({
1101
+ chainId,
1102
+ collectionAddress,
1103
+ collectibleId
1104
+ });
1105
+ const priceLoading = !price || marketplaceConfigLoading || royaltyPercentageLoading;
1106
+ let formattedAmount = price && formatUnits2(BigInt(price.amountRaw), price.currency.decimals);
1107
+ if (royaltyPercentage !== void 0 && formattedAmount) {
1108
+ formattedAmount = (Number.parseFloat(formattedAmount) - Number.parseFloat(formattedAmount) * Number(royaltyPercentage) / 100).toString();
1109
+ }
1110
+ if (marketplaceFeePercentage !== void 0 && formattedAmount) {
1111
+ formattedAmount = (Number.parseFloat(formattedAmount) - Number.parseFloat(formattedAmount) * marketplaceFeePercentage / 100).toString();
1112
+ }
1113
+ return /* @__PURE__ */ jsxs12(
1114
+ Box11,
1115
+ {
1116
+ width: "full",
1117
+ display: "flex",
1118
+ justifyContent: "space-between",
1119
+ alignItems: "center",
1120
+ children: [
1121
+ /* @__PURE__ */ jsx16(Text11, { fontSize: "small", color: "text50", children: "Total earnings" }),
1122
+ /* @__PURE__ */ jsxs12(Box11, { display: "flex", alignItems: "center", gap: "2", children: [
1123
+ /* @__PURE__ */ jsx16(NetworkImage2, { chainId: Number(chainId), size: "xs" }),
1124
+ priceLoading ? /* @__PURE__ */ jsx16(Skeleton4, { width: "16", height: "4" }) : /* @__PURE__ */ jsxs12(Text11, { fontSize: "small", color: "text100", children: [
1125
+ formattedAmount,
1126
+ " ",
1127
+ price.currency.symbol
1128
+ ] })
1129
+ ] })
1130
+ ]
1131
+ }
1132
+ );
1133
+ }
1134
+
1135
+ // src/react/ui/modals/CreateListingModal/_store.ts
1136
+ import { observable as observable4, when } from "@legendapp/state";
1137
+ import { useMount, useSelector } from "@legendapp/state/react";
1138
+ import { addDays as addDays2 } from "date-fns/addDays";
1139
+ import { useAccount as useAccount2, useSendTransaction } from "wagmi";
1140
+
1141
+ // src/react/ui/modals/CreateListingModal/_utils/getCreateListingTransactionTitleMessage.ts
1142
+ var getCreateListingTransactionTitle = (params) => {
1143
+ if (params.isConfirmed) {
1144
+ return "Listing has processed";
1145
+ }
1146
+ if (params.isFailed) {
1147
+ return "Listing has failed";
1148
+ }
1149
+ return "Listing is processing";
1150
+ };
1151
+ var getCreateListingTransactionMessage = (params, collectibleName) => {
1152
+ if (params.isConfirmed) {
1153
+ return `You just listed ${collectibleName}. It\u2019s been confirmed on the blockchain!`;
1154
+ }
1155
+ if (params.isFailed) {
1156
+ return `Your listing of ${collectibleName} has failed. Please try again.`;
1157
+ }
1158
+ return `You just listed ${collectibleName}. It should be confirmed on the blockchain shortly.`;
1159
+ };
1160
+
1161
+ // src/react/ui/modals/CreateListingModal/_store.ts
1162
+ var initialState3 = {
1163
+ isOpen: false,
1164
+ open: ({
1165
+ collectionAddress,
1166
+ chainId,
1167
+ collectibleId,
1168
+ messages
1169
+ }) => {
1170
+ createListingModal$.state.set({
1171
+ ...createListingModal$.state.get(),
1172
+ collectionAddress,
1173
+ chainId,
1174
+ collectibleId,
1175
+ messages
1176
+ });
1177
+ createListingModal$.isOpen.set(true);
1178
+ },
1179
+ close: () => {
1180
+ createListingModal$.isOpen.set(false);
1181
+ },
1182
+ state: {
1183
+ collectionName: "",
1184
+ listingPrice: {
1185
+ amountRaw: "0",
1186
+ currency: {}
1187
+ },
1188
+ quantity: "1",
1189
+ expiry: new Date(addDays2(/* @__PURE__ */ new Date(), 7).toJSON()),
1190
+ collectionType: void 0,
1191
+ collectionAddress: "",
1192
+ chainId: "",
1193
+ collectibleId: ""
1194
+ },
1195
+ steps: {
1196
+ isLoading: () => !!createListingModal$.steps.stepsData.get(),
1197
+ stepsData: void 0,
1198
+ _currentStep: null,
1199
+ tokenApproval: {},
1200
+ createListing: {}
1201
+ },
1202
+ hash: void 0
1203
+ };
1204
+ var createListingModal$ = observable4(initialState3);
1205
+ var exp = new Date(addDays2(/* @__PURE__ */ new Date(), 7).toJSON());
1206
+ var useHydrate = () => {
1207
+ const chainId = useSelector(createListingModal$.state.chainId);
1208
+ const collectionAddress = useSelector(
1209
+ createListingModal$.state.collectionAddress
1210
+ );
1211
+ const collectionType = useSelector(createListingModal$.state.collectionType);
1212
+ const { data: collection, isSuccess: isSuccessCollection } = useCollection({
1213
+ chainId,
1214
+ collectionAddress
1215
+ });
1216
+ when(isSuccessCollection, () => {
1217
+ createListingModal$.state.collectionName.set(collection.name);
1218
+ createListingModal$.state.collectionType.set(
1219
+ collection.type
1220
+ );
1221
+ });
1222
+ useTokenApprovalHandler(chainId);
1223
+ useCreateListingHandler(chainId);
1224
+ useShowTransactionStatusModal();
1225
+ const onListingSuccess = (data) => {
1226
+ createListingModal$.steps.stepsData.set(data);
1227
+ };
1228
+ const { generateListingTransactionAsync } = useGenerateListingTransaction({
1229
+ chainId,
1230
+ onSuccess: onListingSuccess
1231
+ });
1232
+ const { connector, address: userAddress } = useAccount2();
1233
+ useMount(() => {
1234
+ const setSteps = async () => {
1235
+ const createListingTransactionSteps = await generateListingTransactionAsync({
1236
+ collectionAddress,
1237
+ orderbook: "sequence_marketplace_v1" /* sequence_marketplace_v1 */,
1238
+ listing: {
1239
+ tokenId: "1",
1240
+ quantity: "1",
1241
+ expiry: exp,
1242
+ currencyAddress: createListingModal$.state.listingPrice.currency.contractAddress.get(),
1243
+ pricePerToken: createListingModal$.state.listingPrice.amountRaw.get() || "1"
1244
+ },
1245
+ contractType: collectionType,
1246
+ walletType: connector?.id,
1247
+ owner: userAddress
1248
+ });
1249
+ createListingModal$.steps.stepsData.set(createListingTransactionSteps);
1250
+ };
1251
+ when(isSuccessCollection && collectionType, setSteps);
1252
+ });
1253
+ };
1254
+ var useTokenApprovalHandler = (chainId) => {
1255
+ const { sendTransactionAsync, isPending, isSuccess } = useSendTransaction();
1256
+ const {
1257
+ onUnknownError,
1258
+ onSuccess
1259
+ } = createListingModal$.state.get().messages?.approveToken || {};
1260
+ createListingModal$.steps.tokenApproval.set({
1261
+ isNeeded: () => !!createListingModal$.steps.tokenApproval.getStep(),
1262
+ getStep: () => createListingModal$.steps.stepsData?.get()?.find((s) => s.id === "tokenApproval" /* tokenApproval */),
1263
+ pending: createListingModal$.steps._currentStep.get() === "tokenApproval" && isPending,
1264
+ execute: () => {
1265
+ const step = createListingModal$.steps.tokenApproval.getStep();
1266
+ if (!step) return;
1267
+ createListingModal$.steps._currentStep.set("tokenApproval");
1268
+ try {
1269
+ sendTransactionAsync({
1270
+ to: step.to,
1271
+ chainId: Number(chainId),
1272
+ data: step.data,
1273
+ value: BigInt(step.value || "0")
1274
+ });
1275
+ onSuccess && onSuccess();
1276
+ } catch (error) {
1277
+ onUnknownError && onUnknownError(error);
1278
+ }
1279
+ }
1280
+ });
1281
+ if (isSuccess && createListingModal$.steps._currentStep.get() === "tokenApproval") {
1282
+ createListingModal$.steps._currentStep.set(null);
1283
+ }
1284
+ };
1285
+ var useCreateListingHandler = (chainId) => {
1286
+ const { collectibleId, collectionAddress } = createListingModal$.state.get();
1287
+ const { connector, address } = useAccount2();
1288
+ const {
1289
+ generateListingTransactionAsync,
1290
+ isPending: generateListingTransactionPending,
1291
+ error: generateListingTransactionError
1292
+ } = useGenerateListingTransaction({ chainId });
1293
+ const { data: collectible } = useCollectible({
1294
+ chainId,
1295
+ collectionAddress,
1296
+ collectibleId
1297
+ });
1298
+ const {
1299
+ onUnknownError,
1300
+ onSuccess
1301
+ } = createListingModal$.state.get().messages?.sellCollectible || {};
1302
+ const { sendTransactionAsync, isPending: sendTransactionPending } = useSendTransaction();
1303
+ const { show: showTransactionStatusModal } = useTransactionStatusModal();
1304
+ createListingModal$.steps.createListing.set({
1305
+ pending: createListingModal$.steps._currentStep.get() === "createListing" && (generateListingTransactionPending || sendTransactionPending),
1306
+ execute: () => {
1307
+ createListingModal$.steps._currentStep.set("createListing");
1308
+ generateListingTransactionAsync({
1309
+ collectionAddress: createListingModal$.state.collectionAddress.get(),
1310
+ contractType: createListingModal$.state.collectionType.get(),
1311
+ orderbook: "sequence_marketplace_v1" /* sequence_marketplace_v1 */,
1312
+ walletType: connector?.id,
1313
+ listing: {
1314
+ tokenId: createListingModal$.state.collectibleId.get(),
1315
+ quantity: createListingModal$.state.quantity.get(),
1316
+ expiry: createListingModal$.state.expiry.get(),
1317
+ currencyAddress: createListingModal$.state.listingPrice.currency.contractAddress.get(),
1318
+ pricePerToken: createListingModal$.state.listingPrice.amountRaw.get() || "1"
1319
+ },
1320
+ owner: address
1321
+ }).then(async (steps) => {
1322
+ const step = steps.find((s) => s.id === "createListing" /* createListing */);
1323
+ if (!step) throw new Error("No steps found");
1324
+ const hash = await sendTransactionAsync({
1325
+ to: step.to,
1326
+ chainId: Number(chainId),
1327
+ data: step.data,
1328
+ value: BigInt(step.value || "0")
1329
+ });
1330
+ createListingModal$.hash.set(hash);
1331
+ createListingModal$.steps._currentStep.set(null);
1332
+ showTransactionStatusModal({
1333
+ hash,
1334
+ price: createListingModal$.state.listingPrice.get(),
1335
+ collectionAddress,
1336
+ chainId,
1337
+ tokenId: collectibleId,
1338
+ getTitle: getCreateListingTransactionTitle,
1339
+ getMessage: (params) => getCreateListingTransactionMessage(
1340
+ params,
1341
+ collectible?.name || ""
1342
+ ),
1343
+ type: "transfer"
1344
+ });
1345
+ createListingModal$.close();
1346
+ onSuccess && onSuccess();
1347
+ }).catch((error) => {
1348
+ onUnknownError && onUnknownError(error);
1349
+ });
1350
+ }
1351
+ });
1352
+ if (generateListingTransactionError) {
1353
+ onUnknownError && onUnknownError(generateListingTransactionError);
1354
+ }
1355
+ };
1356
+ var useShowTransactionStatusModal = () => {
1357
+ const { hash } = createListingModal$.get();
1358
+ const { collectibleId, chainId, collectionAddress } = createListingModal$.state.get();
1359
+ const { data: collectible } = useCollectible({
1360
+ collectionAddress,
1361
+ chainId,
1362
+ collectibleId
1363
+ });
1364
+ const { show: showTransactionStatusModal } = useTransactionStatusModal();
1365
+ when(!!hash, () => {
1366
+ showTransactionStatusModal({
1367
+ hash,
1368
+ collectionAddress,
1369
+ chainId,
1370
+ price: createListingModal$.state.listingPrice.get(),
1371
+ tokenId: collectibleId,
1372
+ getTitle: getCreateListingTransactionTitle,
1373
+ getMessage: (params) => getCreateListingTransactionMessage(params, collectible?.name || ""),
1374
+ type: "createListing" /* createListing */
1375
+ });
1376
+ });
1377
+ };
1378
+
1379
+ // src/react/ui/modals/CreateListingModal/index.tsx
1380
+ import { useAccount as useAccount3 } from "wagmi";
1381
+ import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
1382
+ var useCreateListingModal = () => {
1383
+ const { chainId: accountChainId } = useAccount3();
1384
+ const { show: showSwitchNetworkModal } = useSwitchChainModal();
1385
+ const openModal = (args) => {
1386
+ createListingModal$.open(args);
1387
+ };
1388
+ const handleShowModal = (args) => {
1389
+ const isSameChain = accountChainId === Number(args.chainId);
1390
+ if (!isSameChain) {
1391
+ showSwitchNetworkModal({
1392
+ chainIdToSwitchTo: Number(args.chainId),
1393
+ onSwitchChain: () => openModal(args),
1394
+ messages: args.messages?.switchChain
1395
+ });
1396
+ return;
1397
+ }
1398
+ openModal(args);
1399
+ };
1400
+ return {
1401
+ show: handleShowModal,
1402
+ close: () => createListingModal$.close()
1403
+ };
1404
+ };
1405
+ var CreateListingModal = () => {
1406
+ return /* @__PURE__ */ jsx17(Show, { if: createListingModal$.isOpen, children: /* @__PURE__ */ jsx17(Modal2, {}) });
1407
+ };
1408
+ var Modal2 = () => {
1409
+ useHydrate();
1410
+ return /* @__PURE__ */ jsx17(ModalContent, {});
1411
+ };
1412
+ var ModalContent = observer8(() => {
1413
+ const {
1414
+ chainId,
1415
+ collectionAddress,
1416
+ collectibleId,
1417
+ collectionName,
1418
+ collectionType,
1419
+ listingPrice
1420
+ } = createListingModal$.state.get();
1421
+ const { steps } = createListingModal$.get();
1422
+ const ctas = [
1423
+ {
1424
+ label: "Approve TOKEN",
1425
+ onClick: steps.tokenApproval.execute,
1426
+ hidden: !steps.tokenApproval.isNeeded(),
1427
+ pending: steps.tokenApproval.pending,
1428
+ variant: "glass"
1429
+ },
1430
+ {
1431
+ label: "List item for sale",
1432
+ onClick: steps.createListing.execute,
1433
+ pending: steps.createListing.pending,
1434
+ disabled: steps.tokenApproval.isNeeded() || listingPrice.amountRaw === "0"
1435
+ }
1436
+ ];
1437
+ return /* @__PURE__ */ jsxs13(
1438
+ ActionModal,
1439
+ {
1440
+ store: createListingModal$,
1441
+ onClose: () => createListingModal$.close(),
1442
+ title: "List item for sale",
1443
+ ctas,
1444
+ children: [
1445
+ /* @__PURE__ */ jsx17(
1446
+ TokenPreview,
1447
+ {
1448
+ collectionName,
1449
+ collectionAddress,
1450
+ collectibleId,
1451
+ chainId
1452
+ }
1453
+ ),
1454
+ /* @__PURE__ */ jsxs13(Box12, { display: "flex", flexDirection: "column", width: "full", gap: "1", children: [
1455
+ /* @__PURE__ */ jsx17(
1456
+ priceInput_default,
1457
+ {
1458
+ chainId,
1459
+ collectionAddress,
1460
+ $listingPrice: createListingModal$.state.listingPrice
1461
+ }
1462
+ ),
1463
+ !!listingPrice && /* @__PURE__ */ jsx17(
1464
+ FloorPriceText,
1465
+ {
1466
+ tokenId: collectibleId,
1467
+ chainId,
1468
+ collectionAddress,
1469
+ price: listingPrice
1470
+ }
1471
+ )
1472
+ ] }),
1473
+ collectionType === "ERC1155" /* ERC1155 */ && /* @__PURE__ */ jsx17(
1474
+ QuantityInput,
1475
+ {
1476
+ chainId,
1477
+ collectionAddress,
1478
+ collectibleId,
1479
+ $quantity: createListingModal$.state.quantity
1480
+ }
1481
+ ),
1482
+ /* @__PURE__ */ jsx17(expirationDateSelect_default, { $date: createListingModal$.state.expiry }),
1483
+ /* @__PURE__ */ jsx17(
1484
+ TransactionDetails,
1485
+ {
1486
+ collectibleId,
1487
+ collectionAddress,
1488
+ chainId,
1489
+ price: createListingModal$.state.listingPrice.get()
1490
+ }
1491
+ )
1492
+ ]
1493
+ }
1494
+ );
1495
+ });
1496
+
1497
+ // src/react/ui/modals/MakeOfferModal/index.tsx
1498
+ import { Show as Show2, observer as observer9 } from "@legendapp/state/react";
1499
+ import { erc20Abi, parseUnits as parseUnits3 } from "viem";
1500
+ import { useAccount as useAccount5, useReadContract } from "wagmi";
1501
+
1502
+ // src/react/ui/modals/MakeOfferModal/_store.ts
1503
+ import { observable as observable5, when as when2 } from "@legendapp/state";
1504
+ import { useMount as useMount2, useSelector as useSelector2 } from "@legendapp/state/react";
1505
+ import { addDays as addDays3 } from "date-fns/addDays";
1506
+ import { parseUnits as parseUnits2 } from "viem";
1507
+ import { useAccount as useAccount4, useSendTransaction as useSendTransaction2 } from "wagmi";
1508
+
1509
+ // src/react/ui/modals/MakeOfferModal/_utils/getMakeOfferTransactionTitleMessage.ts
1510
+ var getMakeOfferTransactionTitle = (params) => {
1511
+ if (params.isConfirmed) {
1512
+ return "Your offer has processed";
1513
+ }
1514
+ if (params.isFailed) {
1515
+ return "Your offer has failed";
1516
+ }
1517
+ return "Your offer is processing";
1518
+ };
1519
+ var getMakeOfferTransactionMessage = (params, collectibleName) => {
1520
+ if (params.isConfirmed) {
1521
+ return `You just made offer for ${collectibleName}. It\u2019s been confirmed on the blockchain!`;
1522
+ }
1523
+ if (params.isFailed) {
1524
+ return `Your offer for ${collectibleName} has failed. Please try again.`;
1525
+ }
1526
+ return `You just made offer for ${collectibleName}. It should be confirmed on the blockchain shortly.`;
1527
+ };
1528
+
1529
+ // src/react/ui/modals/MakeOfferModal/_store.ts
1530
+ var initialState4 = {
1531
+ isOpen: false,
1532
+ open: ({
1533
+ collectionAddress,
1534
+ chainId,
1535
+ collectibleId,
1536
+ messages
1537
+ }) => {
1538
+ makeOfferModal$.state.set({
1539
+ ...makeOfferModal$.state.get(),
1540
+ collectionAddress,
1541
+ chainId,
1542
+ collectibleId,
1543
+ messages
1544
+ });
1545
+ makeOfferModal$.isOpen.set(true);
1546
+ },
1547
+ close: () => {
1548
+ makeOfferModal$.isOpen.set(false);
1549
+ },
1550
+ state: {
1551
+ collectionName: "",
1552
+ offerPrice: {
1553
+ amountRaw: "0",
1554
+ currency: {}
1555
+ },
1556
+ quantity: "1",
1557
+ expiry: new Date(addDays3(/* @__PURE__ */ new Date(), 7).toJSON()),
1558
+ collectionType: void 0,
1559
+ collectionAddress: "",
1560
+ chainId: "",
1561
+ collectibleId: ""
1562
+ },
1563
+ steps: {
1564
+ isLoading: () => !!makeOfferModal$.steps.stepsData.get(),
1565
+ stepsData: void 0,
1566
+ _currentStep: null,
1567
+ tokenApproval: {},
1568
+ createOffer: {}
1569
+ },
1570
+ hash: void 0
1571
+ };
1572
+ var makeOfferModal$ = observable5(initialState4);
1573
+ var exp2 = new Date(addDays3(/* @__PURE__ */ new Date(), 7).toJSON());
1574
+ var useHydrate2 = () => {
1575
+ const chainId = useSelector2(makeOfferModal$.state.chainId);
1576
+ const collectionAddress = useSelector2(
1577
+ makeOfferModal$.state.collectionAddress
1578
+ );
1579
+ const currencyAddress = useSelector2(
1580
+ makeOfferModal$.state.offerPrice.currency.contractAddress
1581
+ );
1582
+ const collectionType = useSelector2(makeOfferModal$.state.collectionType);
1583
+ const { data: collection, isSuccess: isSuccessCollection } = useCollection({
1584
+ chainId,
1585
+ collectionAddress
1586
+ });
1587
+ when2(isSuccessCollection, () => {
1588
+ makeOfferModal$.state.collectionName.set(collection.name);
1589
+ makeOfferModal$.state.collectionType.set(
1590
+ collection.type
1591
+ );
1592
+ });
1593
+ useTokenApprovalHandler2(chainId);
1594
+ useCreateOfferHandler(chainId);
1595
+ const onOfferSuccess = (data) => {
1596
+ makeOfferModal$.steps.stepsData.set(data);
1597
+ };
1598
+ const { generateOfferTransactionAsync } = useGenerateOfferTransaction({
1599
+ chainId,
1600
+ onSuccess: onOfferSuccess
1601
+ });
1602
+ const { connector, address: userAddress } = useAccount4();
1603
+ useMount2(() => {
1604
+ const setSteps = async () => {
1605
+ const makeOfferTransactionData = await generateOfferTransactionAsync({
1606
+ collectionAddress,
1607
+ orderbook: "sequence_marketplace_v1" /* sequence_marketplace_v1 */,
1608
+ offer: {
1609
+ tokenId: "1",
1610
+ quantity: "1",
1611
+ expiry: exp2,
1612
+ currencyAddress,
1613
+ pricePerToken: makeOfferModal$.state.offerPrice.amountRaw.get() || "1"
1614
+ },
1615
+ maker: userAddress,
1616
+ contractType: collectionType,
1617
+ walletType: connector?.id
1618
+ });
1619
+ makeOfferModal$.steps.stepsData.set(makeOfferTransactionData);
1620
+ };
1621
+ when2(isSuccessCollection && collectionType && currencyAddress, setSteps);
1622
+ });
1623
+ };
1624
+ var useTokenApprovalHandler2 = (chainId) => {
1625
+ const { sendTransactionAsync, isPending, isSuccess } = useSendTransaction2();
1626
+ const {
1627
+ onUnknownError,
1628
+ onSuccess
1629
+ } = makeOfferModal$.state.get().messages?.approveToken || {};
1630
+ makeOfferModal$.steps.tokenApproval.set({
1631
+ isNeeded: () => !!makeOfferModal$.steps.tokenApproval.getStep(),
1632
+ getStep: () => makeOfferModal$.steps.stepsData?.get()?.find((s) => s.id === "tokenApproval" /* tokenApproval */),
1633
+ pending: makeOfferModal$.steps._currentStep.get() === "tokenApproval" && isPending,
1634
+ execute: () => {
1635
+ const step = makeOfferModal$.steps.tokenApproval.getStep();
1636
+ if (!step) return;
1637
+ makeOfferModal$.steps._currentStep.set("tokenApproval");
1638
+ try {
1639
+ sendTransactionAsync({
1640
+ to: step.to,
1641
+ chainId: Number(chainId),
1642
+ data: step.data,
1643
+ value: BigInt(step.value || "0")
1644
+ });
1645
+ onSuccess && onSuccess();
1646
+ } catch (error) {
1647
+ onUnknownError && onUnknownError(error);
1648
+ }
1649
+ }
1650
+ });
1651
+ if (isSuccess && makeOfferModal$.steps._currentStep.get() === "tokenApproval") {
1652
+ makeOfferModal$.steps._currentStep.set(null);
1653
+ }
1654
+ };
1655
+ var useCreateOfferHandler = (chainId) => {
1656
+ const { collectibleId, collectionAddress } = makeOfferModal$.state.get();
1657
+ const { connector, address } = useAccount4();
1658
+ const {
1659
+ generateOfferTransactionAsync,
1660
+ isPending: generateOfferTransactionPending,
1661
+ error: generateOfferTransactionError
1662
+ } = useGenerateOfferTransaction({ chainId });
1663
+ const { data: collectible } = useCollectible({
1664
+ chainId,
1665
+ collectionAddress,
1666
+ collectibleId
1667
+ });
1668
+ const {
1669
+ onUnknownError,
1670
+ onSuccess
1671
+ } = makeOfferModal$.state.get().messages?.sellCollectible || {};
1672
+ const { sendTransactionAsync, isPending: sendTransactionPending } = useSendTransaction2();
1673
+ const { show: showTransactionStatusModal } = useTransactionStatusModal();
1674
+ makeOfferModal$.steps.createOffer.set({
1675
+ pending: makeOfferModal$.steps._currentStep.get() === "createOffer" && (generateOfferTransactionPending || sendTransactionPending),
1676
+ execute: () => {
1677
+ makeOfferModal$.steps._currentStep.set("createOffer");
1678
+ generateOfferTransactionAsync({
1679
+ collectionAddress: makeOfferModal$.state.collectionAddress.get(),
1680
+ maker: address,
1681
+ contractType: makeOfferModal$.state.collectionType.get(),
1682
+ orderbook: "sequence_marketplace_v1" /* sequence_marketplace_v1 */,
1683
+ walletType: connector?.id,
1684
+ offer: {
1685
+ tokenId: makeOfferModal$.state.collectibleId.get(),
1686
+ quantity: makeOfferModal$.state.quantity.get(),
1687
+ expiry: makeOfferModal$.state.expiry.get(),
1688
+ currencyAddress: makeOfferModal$.state.offerPrice.currency.contractAddress.get(),
1689
+ pricePerToken: parseUnits2(
1690
+ makeOfferModal$.state.offerPrice.amountRaw.get(),
1691
+ makeOfferModal$.state.offerPrice.currency.decimals.get()
1692
+ ).toString()
1693
+ }
1694
+ }).then(async (steps) => {
1695
+ const step = steps.find((s) => s.id === "createOffer" /* createOffer */);
1696
+ if (!step) throw new Error("No steps found");
1697
+ const hash = await sendTransactionAsync({
1698
+ to: step.to,
1699
+ chainId: Number(chainId),
1700
+ data: step.data,
1701
+ value: BigInt(step.value || "0")
1702
+ });
1703
+ makeOfferModal$.hash.set(hash);
1704
+ makeOfferModal$.steps._currentStep.set(null);
1705
+ showTransactionStatusModal({
1706
+ hash,
1707
+ price: makeOfferModal$.state.offerPrice.get(),
1708
+ collectionAddress,
1709
+ chainId,
1710
+ tokenId: collectibleId,
1711
+ getTitle: getMakeOfferTransactionTitle,
1712
+ getMessage: (params) => getMakeOfferTransactionMessage(params, collectible?.name || ""),
1713
+ type: "createOffer" /* createOffer */
1714
+ });
1715
+ makeOfferModal$.close();
1716
+ onSuccess && onSuccess();
1717
+ }).catch((error) => {
1718
+ onUnknownError && onUnknownError(error);
1719
+ });
1720
+ }
1721
+ });
1722
+ if (generateOfferTransactionError) {
1723
+ onUnknownError && onUnknownError(generateOfferTransactionError);
1724
+ }
1725
+ };
1726
+
1727
+ // src/react/ui/modals/MakeOfferModal/index.tsx
1728
+ import { jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
1729
+ var useMakeOfferModal = () => {
1730
+ const { chainId: accountChainId } = useAccount5();
1731
+ const { show: showSwitchNetworkModal } = useSwitchChainModal();
1732
+ const openModal = (args) => {
1733
+ makeOfferModal$.open(args);
1734
+ };
1735
+ const handleShowModal = (args) => {
1736
+ const isSameChain = accountChainId === Number(args.chainId);
1737
+ if (!isSameChain) {
1738
+ showSwitchNetworkModal({
1739
+ chainIdToSwitchTo: Number(args.chainId),
1740
+ onSwitchChain: () => openModal(args),
1741
+ messages: args.messages?.switchChain
1742
+ });
1743
+ return;
1744
+ }
1745
+ openModal(args);
1746
+ };
1747
+ return {
1748
+ show: handleShowModal,
1749
+ close: () => makeOfferModal$.close()
1750
+ };
1751
+ };
1752
+ var MakeOfferModal = () => {
1753
+ return /* @__PURE__ */ jsx18(Show2, { if: makeOfferModal$.isOpen, children: /* @__PURE__ */ jsx18(Modal3, {}) });
1754
+ };
1755
+ var Modal3 = () => {
1756
+ useHydrate2();
1757
+ return /* @__PURE__ */ jsx18(ModalContent2, {});
1758
+ };
1759
+ var ModalContent2 = observer9(() => {
1760
+ const {
1761
+ chainId,
1762
+ collectionAddress,
1763
+ collectibleId,
1764
+ collectionName,
1765
+ collectionType,
1766
+ offerPrice
1767
+ } = makeOfferModal$.state.get();
1768
+ const { steps } = makeOfferModal$.get();
1769
+ const { address: accountAddress } = useAccount5();
1770
+ const { data: balance, isSuccess: isBalanceSuccess } = useReadContract({
1771
+ address: makeOfferModal$.state.offerPrice.currency.contractAddress.get(),
1772
+ abi: erc20Abi,
1773
+ functionName: "balanceOf",
1774
+ args: [accountAddress]
1775
+ });
1776
+ let balanceError = "";
1777
+ if (isBalanceSuccess && parseUnits3(offerPrice.amountRaw, offerPrice.currency.decimals) > (balance || 0)) {
1778
+ balanceError = "Insufficient balance";
1779
+ }
1780
+ const ctas = [
1781
+ {
1782
+ label: "Approve TOKEN",
1783
+ onClick: steps.tokenApproval.execute,
1784
+ hidden: !steps.tokenApproval.isNeeded(),
1785
+ pending: steps.tokenApproval.pending,
1786
+ variant: "glass"
1787
+ },
1788
+ {
1789
+ label: "Make offer",
1790
+ onClick: steps.createOffer.execute,
1791
+ pending: steps.createOffer.pending,
1792
+ disabled: steps.tokenApproval.isNeeded() || offerPrice.amountRaw === "0"
1793
+ }
1794
+ ];
1795
+ return /* @__PURE__ */ jsxs14(
1796
+ ActionModal,
1797
+ {
1798
+ store: makeOfferModal$,
1799
+ onClose: () => {
1800
+ makeOfferModal$.close();
1801
+ },
1802
+ title: "Make an offer",
1803
+ ctas,
1804
+ children: [
1805
+ /* @__PURE__ */ jsx18(
1806
+ TokenPreview,
1807
+ {
1808
+ collectionName,
1809
+ collectionAddress,
1810
+ collectibleId,
1811
+ chainId
1812
+ }
1813
+ ),
1814
+ /* @__PURE__ */ jsx18(
1815
+ priceInput_default,
1816
+ {
1817
+ chainId,
1818
+ collectionAddress,
1819
+ $listingPrice: makeOfferModal$.state.offerPrice,
1820
+ error: balanceError
1821
+ }
1822
+ ),
1823
+ collectionType === "ERC1155" /* ERC1155 */ && /* @__PURE__ */ jsx18(
1824
+ QuantityInput,
1825
+ {
1826
+ chainId,
1827
+ $quantity: makeOfferModal$.state.quantity,
1828
+ collectionAddress,
1829
+ collectibleId
1830
+ }
1831
+ ),
1832
+ !!offerPrice && /* @__PURE__ */ jsx18(
1833
+ FloorPriceText,
1834
+ {
1835
+ tokenId: collectibleId,
1836
+ chainId,
1837
+ collectionAddress,
1838
+ price: offerPrice
1839
+ }
1840
+ ),
1841
+ /* @__PURE__ */ jsx18(expirationDateSelect_default, { $date: makeOfferModal$.state.expiry })
1842
+ ]
1843
+ }
1844
+ );
1845
+ });
1846
+
1847
+ // src/react/ui/modals/SellModal/_store.ts
1848
+ import { observable as observable6, when as when3 } from "@legendapp/state";
1849
+ import { useMount as useMount3, useSelector as useSelector3 } from "@legendapp/state/react";
1850
+
1851
+ // src/react/hooks/useGenerateSellTransaction.tsx
1852
+ import { useMutation } from "@tanstack/react-query";
1853
+ var generateSellTransaction = async (args, config, chainId) => {
1854
+ console.log("generateSellTransaction");
1855
+ console.log(args);
1856
+ console.log(chainId);
1857
+ const marketplaceClient = getMarketplaceClient(chainId, config);
1858
+ return marketplaceClient.generateSellTransaction(args);
1859
+ };
1860
+ var useGenerateSellTransaction = (params) => {
1861
+ const config = useConfig();
1862
+ const { mutate, mutateAsync, ...result } = useMutation({
1863
+ onSuccess: params.onSuccess,
1864
+ mutationFn: (args) => generateSellTransaction(args, config, params.chainId)
1865
+ });
1866
+ return {
1867
+ ...result,
1868
+ generateSellTransaction: mutate,
1869
+ generateSellTransactionAsync: mutateAsync
1870
+ };
1871
+ };
1872
+
1873
+ // src/react/ui/modals/SellModal/_store.ts
1874
+ import { useAccount as useAccount6, useSendTransaction as useSendTransaction3 } from "wagmi";
1875
+
1876
+ // src/react/ui/modals/SellModal/_utils/getSellTransactionTitleMessage.ts
1877
+ var getSellTransactionTitle = (params) => {
1878
+ if (params.isConfirmed) {
1879
+ return "Your sale has processed";
1880
+ }
1881
+ if (params.isFailed) {
1882
+ return "Your sale has failed";
1883
+ }
1884
+ return "Your sale is processing";
1885
+ };
1886
+ var getSellTransactionMessage = (params, collectibleName) => {
1887
+ if (params.isConfirmed) {
1888
+ return `You just sold ${collectibleName}. It\u2019s been confirmed on the blockchain!`;
1889
+ }
1890
+ if (params.isFailed) {
1891
+ return `Your sale of ${collectibleName} has failed. Please try again.`;
1892
+ }
1893
+ return `You just sold ${collectibleName}. It should be confirmed on the blockchain shortly.`;
1894
+ };
1895
+
1896
+ // src/react/ui/modals/SellModal/_store.ts
1897
+ var initialState5 = {
1898
+ isOpen: false,
1899
+ open: ({
1900
+ collectionAddress,
1901
+ chainId,
1902
+ tokenId,
1903
+ order,
1904
+ messages
1905
+ }) => {
1906
+ sellModal$.state.set({
1907
+ ...sellModal$.state.get(),
1908
+ collectionAddress,
1909
+ chainId,
1910
+ tokenId,
1911
+ order,
1912
+ messages
1913
+ });
1914
+ sellModal$.isOpen.set(true);
1915
+ },
1916
+ close: () => {
1917
+ sellModal$.isOpen.set(false);
1918
+ sellModal$.state.set({
1919
+ ...initialState5.state
1920
+ });
1921
+ },
1922
+ state: {
1923
+ collectionAddress: "",
1924
+ chainId: "",
1925
+ tokenId: "",
1926
+ order: void 0
1927
+ },
1928
+ steps: {
1929
+ isLoading: () => !!sellModal$.steps.stepsData.get(),
1930
+ stepsData: void 0,
1931
+ _currentStep: null,
1932
+ tokenApproval: {},
1933
+ sell: {}
1934
+ },
1935
+ hash: void 0
1936
+ };
1937
+ var sellModal$ = observable6(initialState5);
1938
+ var useHydrate3 = () => {
1939
+ const chainId = useSelector3(sellModal$.state.chainId);
1940
+ const collectionAddress = useSelector3(sellModal$.state.collectionAddress);
1941
+ const order = useSelector3(sellModal$.state.order);
1942
+ useTokenApprovalHandler3(chainId);
1943
+ useSellHandler(chainId);
1944
+ const { generateSellTransactionAsync } = useGenerateSellTransaction({
1945
+ chainId
1946
+ });
1947
+ const { connector, address } = useAccount6();
1948
+ useMount3(() => {
1949
+ const setSteps = async () => {
1950
+ const sellTransactionData = await generateSellTransactionAsync({
1951
+ walletType: connector?.walletType,
1952
+ collectionAddress,
1953
+ seller: address,
1954
+ marketplace: "sequence_marketplace_v1" /* sequence_marketplace_v1 */,
1955
+ ordersData: [
1956
+ {
1957
+ ...order,
1958
+ orderId: order.orderId,
1959
+ quantity: "1"
1960
+ }
1961
+ ],
1962
+ additionalFees: []
1963
+ });
1964
+ sellModal$.steps.stepsData.set(sellTransactionData.steps);
1965
+ };
1966
+ when3(() => !!order && !!connector, setSteps);
1967
+ });
1968
+ };
1969
+ var useTokenApprovalHandler3 = (chainId) => {
1970
+ const { sendTransactionAsync, isPending, isSuccess } = useSendTransaction3();
1971
+ const {
1972
+ onUnknownError,
1973
+ onSuccess
1974
+ } = sellModal$.state.get().messages?.approveToken || {};
1975
+ sellModal$.steps.tokenApproval.set({
1976
+ isNeeded: () => !!sellModal$.steps.tokenApproval.getStep(),
1977
+ getStep: () => sellModal$.steps.stepsData?.get()?.find((s) => s.id === "tokenApproval" /* tokenApproval */),
1978
+ pending: sellModal$.steps._currentStep.get() === "tokenApproval" && isPending,
1979
+ execute: async () => {
1980
+ const step = sellModal$.steps.tokenApproval.getStep();
1981
+ if (!step) return;
1982
+ sellModal$.steps._currentStep.set("tokenApproval");
1983
+ try {
1984
+ await sendTransactionAsync({
1985
+ to: step.to,
1986
+ chainId: Number(chainId),
1987
+ data: step.data,
1988
+ value: BigInt(step.value || "0")
1989
+ });
1990
+ onSuccess && onSuccess();
1991
+ } catch (error) {
1992
+ onUnknownError && onUnknownError(error);
1993
+ }
1994
+ }
1995
+ });
1996
+ if (isSuccess && sellModal$.steps._currentStep.get() === "tokenApproval") {
1997
+ sellModal$.steps._currentStep.set(null);
1998
+ }
1999
+ };
2000
+ var useSellHandler = (chainId) => {
2001
+ const { address } = useAccount6();
2002
+ const { tokenId, collectionAddress } = sellModal$.state.get();
2003
+ const {
2004
+ generateSellTransactionAsync,
2005
+ isPending: generateSellTransactionPending,
2006
+ error: generateSellTransactionError
2007
+ } = useGenerateSellTransaction({
2008
+ chainId
2009
+ });
2010
+ const { data: collectible } = useCollectible({
2011
+ chainId,
2012
+ collectibleId: tokenId,
2013
+ collectionAddress
2014
+ });
2015
+ const { data: currencies } = useCurrencies({ chainId });
2016
+ const {
2017
+ onUnknownError,
2018
+ onSuccess
2019
+ } = sellModal$.state.get().messages?.sellCollectible || {};
2020
+ const { sendTransactionAsync, isPending: sendTransactionPending } = useSendTransaction3();
2021
+ const { show: showTransactionStatusModal } = useTransactionStatusModal();
2022
+ function setSellStep() {
2023
+ sellModal$.steps.sell.set({
2024
+ pending: sellModal$.steps._currentStep.get() === "sell" && (generateSellTransactionPending || sendTransactionPending),
2025
+ execute: () => {
2026
+ sellModal$.steps._currentStep.set("sell");
2027
+ const { collectionAddress: collectionAddress2, order } = sellModal$.state.get();
2028
+ generateSellTransactionAsync({
2029
+ collectionAddress: collectionAddress2,
2030
+ seller: address,
2031
+ marketplace: order.marketplace,
2032
+ ordersData: [
2033
+ {
2034
+ ...order,
2035
+ quantity: "1"
2036
+ }
2037
+ ],
2038
+ additionalFees: [
2039
+ {
2040
+ amount: String(order.feeBps),
2041
+ receiver: order.feeBreakdown[0].recipientAddress
2042
+ }
2043
+ ]
2044
+ }).then(async (response) => {
2045
+ const step = response.steps.find((s) => s.id === "sell" /* sell */);
2046
+ if (!step) throw new Error("No steps found");
2047
+ try {
2048
+ const hash = await sendTransactionAsync({
2049
+ to: step.to,
2050
+ chainId: Number(chainId),
2051
+ data: step.data,
2052
+ value: BigInt(step.value || "0")
2053
+ });
2054
+ sellModal$.hash.set(hash);
2055
+ sellModal$.steps._currentStep.set(null);
2056
+ showTransactionStatusModal({
2057
+ hash,
2058
+ price: {
2059
+ amountRaw: order.priceAmount,
2060
+ currency: currencies.find(
2061
+ (currency) => currency.contractAddress === order.priceCurrencyAddress
2062
+ )
2063
+ },
2064
+ collectionAddress: collectionAddress2,
2065
+ chainId,
2066
+ tokenId,
2067
+ getTitle: getSellTransactionTitle,
2068
+ getMessage: (params) => getSellTransactionMessage(params, collectible?.name || ""),
2069
+ type: "sell" /* sell */
2070
+ });
2071
+ sellModal$.close();
2072
+ onSuccess && onSuccess();
2073
+ } catch (error) {
2074
+ }
2075
+ }).catch((error) => {
2076
+ onUnknownError && onUnknownError(error);
2077
+ });
2078
+ }
2079
+ });
2080
+ }
2081
+ when3(currencies && collectible, setSellStep);
2082
+ if (generateSellTransactionError) {
2083
+ onUnknownError && onUnknownError(generateSellTransactionError);
2084
+ }
2085
+ };
2086
+
2087
+ // src/react/ui/modals/SellModal/index.tsx
2088
+ import { observer as observer10, Show as Show3 } from "@legendapp/state/react";
2089
+
2090
+ // src/react/ui/modals/_internal/components/transactionHeader/index.tsx
2091
+ import { Box as Box13, NetworkImage as NetworkImage3, Skeleton as Skeleton5, Text as Text12 } from "@0xsequence/design-system";
2092
+ import { formatDistanceToNow as formatDistanceToNow2 } from "date-fns";
2093
+ import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
2094
+ function TransactionHeader({
2095
+ title,
2096
+ chainId,
2097
+ date
2098
+ }) {
2099
+ return /* @__PURE__ */ jsxs15(Box13, { display: "flex", alignItems: "center", width: "full", children: [
2100
+ /* @__PURE__ */ jsx19(Text12, { fontSize: "small", fontWeight: "medium", color: "text80", marginRight: "1", children: title }),
2101
+ /* @__PURE__ */ jsx19(NetworkImage3, { size: "xs", chainId }),
2102
+ date && /* @__PURE__ */ jsxs15(Text12, { fontSize: "small", color: "text50", flexGrow: "1", textAlign: "right", children: [
2103
+ formatDistanceToNow2(date),
2104
+ " ago"
2105
+ ] }) || /* @__PURE__ */ jsx19(Skeleton5, { width: "8", height: "4" })
2106
+ ] });
2107
+ }
2108
+
2109
+ // src/react/ui/modals/SellModal/index.tsx
2110
+ import { useAccount as useAccount7 } from "wagmi";
2111
+ import { jsx as jsx20, jsxs as jsxs16 } from "react/jsx-runtime";
2112
+ var useSellModal = () => {
2113
+ const { chainId: accountChainId } = useAccount7();
2114
+ const { show: showSwitchNetworkModal } = useSwitchChainModal();
2115
+ const openModal = (args) => {
2116
+ sellModal$.open(args);
2117
+ };
2118
+ const handleShowModal = (args) => {
2119
+ const isSameChain = accountChainId === Number(args.chainId);
2120
+ if (!isSameChain) {
2121
+ showSwitchNetworkModal({
2122
+ chainIdToSwitchTo: Number(args.chainId),
2123
+ onSwitchChain: () => openModal(args),
2124
+ messages: args.messages?.switchChain
2125
+ });
2126
+ return;
2127
+ }
2128
+ openModal(args);
2129
+ };
2130
+ return {
2131
+ show: handleShowModal,
2132
+ close: () => sellModal$.close()
2133
+ };
2134
+ };
2135
+ var SellModal = () => {
2136
+ return /* @__PURE__ */ jsx20(Show3, { if: sellModal$.isOpen, children: /* @__PURE__ */ jsx20(Modal4, {}) });
2137
+ };
2138
+ var Modal4 = () => {
2139
+ useHydrate3();
2140
+ return /* @__PURE__ */ jsx20(ModalContent3, {});
2141
+ };
2142
+ var ModalContent3 = observer10(() => {
2143
+ const modalState = sellModal$.state.get();
2144
+ const { collectionAddress, chainId, tokenId, order } = modalState;
2145
+ const { steps } = sellModal$.get();
2146
+ const { data: collection } = useCollection({ chainId, collectionAddress });
2147
+ const { data: currencies } = useCurrencies({ chainId, collectionAddress });
2148
+ const currency = currencies?.find(
2149
+ (currency2) => currency2.contractAddress === order?.priceCurrencyAddress
2150
+ );
2151
+ const ctas = [
2152
+ {
2153
+ label: "Approve TOKEN",
2154
+ onClick: steps.tokenApproval.execute,
2155
+ hidden: !steps.tokenApproval.isNeeded(),
2156
+ pending: steps.tokenApproval.pending,
2157
+ variant: "glass"
2158
+ },
2159
+ {
2160
+ label: "Accept",
2161
+ onClick: steps.sell.execute,
2162
+ pending: steps.sell.pending,
2163
+ disabled: steps.tokenApproval.isNeeded()
2164
+ }
2165
+ ];
2166
+ return /* @__PURE__ */ jsxs16(
2167
+ ActionModal,
2168
+ {
2169
+ store: sellModal$,
2170
+ onClose: () => sellModal$.close(),
2171
+ title: "You have an offer",
2172
+ ctas,
2173
+ children: [
2174
+ /* @__PURE__ */ jsx20(
2175
+ TransactionHeader,
2176
+ {
2177
+ title: "Offer received",
2178
+ chainId: Number(chainId),
2179
+ date: order && new Date(order.createdAt)
2180
+ }
2181
+ ),
2182
+ /* @__PURE__ */ jsx20(
2183
+ TokenPreview,
2184
+ {
2185
+ collectionName: collection?.name,
2186
+ collectionAddress,
2187
+ collectibleId: tokenId,
2188
+ chainId
2189
+ }
2190
+ ),
2191
+ /* @__PURE__ */ jsx20(
2192
+ TransactionDetails,
2193
+ {
2194
+ collectibleId: tokenId,
2195
+ collectionAddress,
2196
+ chainId,
2197
+ price: currency ? { amountRaw: order?.priceAmount, currency } : void 0
2198
+ }
2199
+ )
2200
+ ]
2201
+ }
2202
+ );
2203
+ });
2204
+
2205
+ // src/react/ui/modals/SuccessfulPurchaseModal/_store.ts
2206
+ import { observable as observable7 } from "@legendapp/state";
2207
+ var initialState6 = {
2208
+ isOpen: false,
2209
+ open: ({
2210
+ collectibles,
2211
+ totalPrice,
2212
+ explorerName,
2213
+ explorerUrl,
2214
+ ctaOptions
2215
+ }) => {
2216
+ successfulPurchaseModal$.state.set({
2217
+ ...successfulPurchaseModal$.state.get(),
2218
+ collectibles,
2219
+ totalPrice,
2220
+ explorerName,
2221
+ explorerUrl,
2222
+ ctaOptions
2223
+ });
2224
+ successfulPurchaseModal$.isOpen.set(true);
2225
+ },
2226
+ close: () => {
2227
+ successfulPurchaseModal$.isOpen.set(false);
2228
+ successfulPurchaseModal$.state.set({
2229
+ ...initialState6.state
2230
+ });
2231
+ },
2232
+ state: {
2233
+ collectibles: [],
2234
+ totalPrice: "0",
2235
+ explorerName: "",
2236
+ explorerUrl: "",
2237
+ ctaOptions: void 0
2238
+ }
2239
+ };
2240
+ var successfulPurchaseModal$ = observable7(initialState6);
2241
+
2242
+ // src/react/ui/modals/SuccessfulPurchaseModal/index.tsx
2243
+ import {
2244
+ Box as Box14,
2245
+ Button as Button4,
2246
+ CloseIcon as CloseIcon3,
2247
+ ExternalLinkIcon,
2248
+ IconButton as IconButton4,
2249
+ Image as Image3,
2250
+ Text as Text13
2251
+ } from "@0xsequence/design-system";
2252
+ import { observer as observer11 } from "@legendapp/state/react";
2253
+ import { Close as Close3, Content as Content4, Overlay as Overlay3, Portal as Portal4, Root as Root4 } from "@radix-ui/react-dialog";
2254
+ import { jsx as jsx21, jsxs as jsxs17 } from "react/jsx-runtime";
2255
+ var useSuccessfulPurchaseModal = () => {
2256
+ return {
2257
+ show: (args) => successfulPurchaseModal$.open(args),
2258
+ close: () => successfulPurchaseModal$.close()
2259
+ };
2260
+ };
2261
+ var SuccessfulPurchaseModal = observer11(() => {
2262
+ return /* @__PURE__ */ jsx21(Root4, { open: successfulPurchaseModal$.isOpen.get(), children: /* @__PURE__ */ jsxs17(Portal4, { children: [
2263
+ /* @__PURE__ */ jsx21(Overlay3, { className: dialogOverlay2 }),
2264
+ /* @__PURE__ */ jsxs17(Content4, { className: dialogContent.narrow, children: [
2265
+ /* @__PURE__ */ jsxs17(Box14, { display: "flex", flexDirection: "column", gap: "4", width: "full", children: [
2266
+ /* @__PURE__ */ jsx21(
2267
+ Text13,
2268
+ {
2269
+ textAlign: "center",
2270
+ fontSize: "medium",
2271
+ fontWeight: "bold",
2272
+ color: "text100",
2273
+ children: "Successful purchase!"
2274
+ }
2275
+ ),
2276
+ /* @__PURE__ */ jsx21(
2277
+ CollectiblesGrid,
2278
+ {
2279
+ collectibles: successfulPurchaseModal$.state.get().collectibles
2280
+ }
2281
+ ),
2282
+ /* @__PURE__ */ jsxs17(Box14, { display: "flex", alignItems: "center", gap: "1", children: [
2283
+ /* @__PURE__ */ jsx21(Text13, { fontSize: "normal", fontWeight: "medium", color: "text80", children: "You bought" }),
2284
+ /* @__PURE__ */ jsx21(Text13, { fontSize: "normal", fontWeight: "medium", color: "text100", children: successfulPurchaseModal$.state.get().collectibles.length }),
2285
+ /* @__PURE__ */ jsx21(Text13, { fontSize: "normal", fontWeight: "medium", color: "text80", children: "items for" }),
2286
+ /* @__PURE__ */ jsx21(Text13, { fontSize: "normal", fontWeight: "medium", color: "text100", children: successfulPurchaseModal$.state.get().totalPrice })
2287
+ ] }),
2288
+ /* @__PURE__ */ jsx21(SuccessfulPurchaseActions, {})
2289
+ ] }),
2290
+ /* @__PURE__ */ jsx21(
2291
+ Close3,
2292
+ {
2293
+ onClick: () => {
2294
+ successfulPurchaseModal$.close();
2295
+ },
2296
+ className: closeButton2,
2297
+ asChild: true,
2298
+ children: /* @__PURE__ */ jsx21(IconButton4, { size: "xs", "aria-label": "Close modal", icon: CloseIcon3 })
2299
+ }
2300
+ )
2301
+ ] })
2302
+ ] }) });
2303
+ });
2304
+ function SuccessfulPurchaseActions() {
2305
+ return /* @__PURE__ */ jsxs17(Box14, { display: "flex", flexDirection: "column", gap: "2", children: [
2306
+ successfulPurchaseModal$.state.ctaOptions.get() && /* @__PURE__ */ jsx21(
2307
+ Button4,
2308
+ {
2309
+ shape: "square",
2310
+ leftIcon: successfulPurchaseModal$.state.ctaOptions.ctaIcon.get() || void 0,
2311
+ label: successfulPurchaseModal$.state.ctaOptions.ctaLabel.get(),
2312
+ width: "full",
2313
+ onClick: successfulPurchaseModal$.state.ctaOptions.ctaOnClick.get() || void 0
2314
+ }
2315
+ ),
2316
+ /* @__PURE__ */ jsx21(
2317
+ Button4,
2318
+ {
2319
+ as: "a",
2320
+ href: successfulPurchaseModal$.state.explorerUrl.get(),
2321
+ target: "_blank",
2322
+ rel: "noopener noreferrer",
2323
+ shape: "square",
2324
+ leftIcon: ExternalLinkIcon,
2325
+ label: `View on ${successfulPurchaseModal$.state.explorerName.get()}`,
2326
+ width: "full"
2327
+ }
2328
+ )
2329
+ ] });
2330
+ }
2331
+ function CollectiblesGrid({ collectibles }) {
2332
+ const total = collectibles.length;
2333
+ const shownCollectibles = total > 4 ? collectibles.slice(0, 4) : collectibles;
2334
+ return /* @__PURE__ */ jsx21(Box14, { className: collectiblesGrid, display: "grid", gap: "2", children: shownCollectibles.map((collectible) => {
2335
+ const showPlus = total > 4 && collectibles.indexOf(collectible) === 3;
2336
+ return /* @__PURE__ */ jsxs17(
2337
+ Box14,
2338
+ {
2339
+ className: collectiblesGridItem,
2340
+ position: "relative",
2341
+ children: [
2342
+ /* @__PURE__ */ jsx21(
2343
+ Image3,
2344
+ {
2345
+ src: collectible.image,
2346
+ alt: collectible.name,
2347
+ className: showPlus ? collectiblesGridImagePale : collectiblesGridImage,
2348
+ aspectRatio: "1/1",
2349
+ background: "backgroundSecondary",
2350
+ borderRadius: "sm"
2351
+ }
2352
+ ),
2353
+ showPlus && /* @__PURE__ */ jsx21(
2354
+ Box14,
2355
+ {
2356
+ position: "absolute",
2357
+ top: "0",
2358
+ left: "0",
2359
+ right: "0",
2360
+ bottom: "0",
2361
+ display: "flex",
2362
+ alignItems: "center",
2363
+ justifyContent: "center",
2364
+ background: "backgroundOverlay",
2365
+ backdropFilter: "blur",
2366
+ children: /* @__PURE__ */ jsxs17(
2367
+ Text13,
2368
+ {
2369
+ fontSize: "small",
2370
+ fontWeight: "medium",
2371
+ color: "text80",
2372
+ paddingX: "2",
2373
+ paddingY: "1.5",
2374
+ borderRadius: "sm",
2375
+ background: "backgroundSecondary",
2376
+ backdropFilter: "blur",
2377
+ children: [
2378
+ total,
2379
+ " TOTAL"
2380
+ ]
2381
+ }
2382
+ )
2383
+ }
2384
+ )
2385
+ ]
2386
+ },
2387
+ collectible.tokenId
2388
+ );
2389
+ }) });
2390
+ }
2391
+ var SuccessfulPurchaseModal_default = SuccessfulPurchaseModal;
2392
+
2393
+ // src/react/ui/modals/TransferModal/_store.ts
2394
+ import { observable as observable8 } from "@legendapp/state";
2395
+ var initialState7 = {
2396
+ isOpen: false,
2397
+ open: ({
2398
+ chainId,
2399
+ collectionAddress,
2400
+ tokenId,
2401
+ messages
2402
+ }) => {
2403
+ transferModal$.state.set({
2404
+ ...transferModal$.state.get(),
2405
+ chainId,
2406
+ collectionAddress,
2407
+ tokenId,
2408
+ messages
2409
+ });
2410
+ transferModal$.isOpen.set(true);
2411
+ },
2412
+ close: () => {
2413
+ transferModal$.isOpen.set(false);
2414
+ transferModal$.state.set({
2415
+ ...initialState7.state
2416
+ });
2417
+ },
2418
+ state: {
2419
+ receiverAddress: "",
2420
+ collectionAddress: "0x",
2421
+ chainId: "",
2422
+ tokenId: "",
2423
+ quantity: "1"
2424
+ },
2425
+ view: "enterReceiverAddress",
2426
+ hash: void 0
2427
+ };
2428
+ var transferModal$ = observable8(initialState7);
2429
+
2430
+ // src/react/ui/modals/TransferModal/index.tsx
2431
+ import { CloseIcon as CloseIcon4, IconButton as IconButton5 } from "@0xsequence/design-system";
2432
+ import { observer as observer13, Show as Show4 } from "@legendapp/state/react";
2433
+ import { Close as Close4, Content as Content5, Overlay as Overlay4, Portal as Portal5, Root as Root5 } from "@radix-ui/react-dialog";
2434
+ import { useAccount as useAccount9 } from "wagmi";
2435
+
2436
+ // src/react/ui/modals/TransferModal/messages.ts
2437
+ var baseMessages = {
2438
+ enterReceiverAddress: "Items sent to the wrong wallet address can't be recovered!",
2439
+ followWalletInstructions: "Follow your wallet's instructions to submit a transaction to transfer your assets."
2440
+ };
2441
+ function getMessage(key) {
2442
+ return baseMessages[key];
2443
+ }
2444
+
2445
+ // src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx
2446
+ import { Box as Box15, Button as Button5, Text as Text14, TextInput } from "@0xsequence/design-system";
2447
+ import { isAddress } from "viem";
2448
+ import { useAccount as useAccount8 } from "wagmi";
2449
+ import { Fragment, jsx as jsx22, jsxs as jsxs18 } from "react/jsx-runtime";
2450
+ var EnterWalletAddressView = () => {
2451
+ const { address } = useAccount8();
2452
+ const { collectionAddress, chainId, tokenId, collectionType } = transferModal$.state.get();
2453
+ const $quantity = transferModal$.state.quantity;
2454
+ const isWalletAddressValid = isAddress(
2455
+ transferModal$.state.receiverAddress.get()
2456
+ );
2457
+ const { data: tokenBalance } = useTokenBalances({
2458
+ chainId,
2459
+ contractAddress: collectionAddress,
2460
+ tokenId,
2461
+ accountAddress: address
2462
+ });
2463
+ const balanceAmount = tokenBalance?.pages[0].balances[0].balance;
2464
+ const { data: collection } = useCollection({
2465
+ collectionAddress,
2466
+ chainId
2467
+ });
2468
+ transferModal$.state.collectionType.set(
2469
+ collection?.type
2470
+ );
2471
+ const insufficientBalance = $quantity.get() > balanceAmount;
2472
+ function handleChangeWalletAddress(event) {
2473
+ transferModal$.state.receiverAddress.set(event.target.value);
2474
+ }
2475
+ function handleChangeView() {
2476
+ transferModal$.view.set("followWalletInstructions");
2477
+ }
2478
+ return /* @__PURE__ */ jsxs18(Box15, { display: "grid", gap: "6", flexGrow: "1", children: [
2479
+ /* @__PURE__ */ jsx22(Text14, { color: "white", fontSize: "large", fontWeight: "bold", children: "Transfer your item" }),
2480
+ /* @__PURE__ */ jsxs18(Box15, { display: "flex", flexDirection: "column", gap: "3", children: [
2481
+ /* @__PURE__ */ jsx22(
2482
+ AlertMessage,
2483
+ {
2484
+ message: getMessage("enterReceiverAddress"),
2485
+ type: "warning"
2486
+ }
2487
+ ),
2488
+ /* @__PURE__ */ jsx22(
2489
+ TextInput,
2490
+ {
2491
+ label: "Wallet address",
2492
+ labelLocation: "top",
2493
+ value: transferModal$.state.receiverAddress.get(),
2494
+ onChange: handleChangeWalletAddress,
2495
+ name: "walletAddress",
2496
+ placeholder: "Enter wallet address of recipient"
2497
+ }
2498
+ ),
2499
+ collectionType === "ERC1155" /* ERC1155 */ && balanceAmount && /* @__PURE__ */ jsxs18(Fragment, { children: [
2500
+ /* @__PURE__ */ jsx22(
2501
+ QuantityInput,
2502
+ {
2503
+ $quantity,
2504
+ chainId,
2505
+ collectionAddress,
2506
+ collectibleId: tokenId
2507
+ }
2508
+ ),
2509
+ /* @__PURE__ */ jsx22(
2510
+ Text14,
2511
+ {
2512
+ color: insufficientBalance ? "negative" : "text50",
2513
+ fontSize: "small",
2514
+ fontWeight: "medium",
2515
+ children: `You have ${balanceAmount} of this item`
2516
+ }
2517
+ )
2518
+ ] })
2519
+ ] }),
2520
+ /* @__PURE__ */ jsx22(
2521
+ Button5,
2522
+ {
2523
+ onClick: handleChangeView,
2524
+ disabled: !isWalletAddressValid || insufficientBalance,
2525
+ title: "Transfer",
2526
+ label: "Transfer",
2527
+ variant: "primary",
2528
+ shape: "square",
2529
+ size: "sm",
2530
+ justifySelf: "flex-end",
2531
+ paddingX: "10"
2532
+ }
2533
+ )
2534
+ ] });
2535
+ };
2536
+ var enterWalletAddress_default = EnterWalletAddressView;
2537
+
2538
+ // src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx
2539
+ import { observer as observer12 } from "@legendapp/state/react";
2540
+ import { Box as Box16, Button as Button6, Text as Text15 } from "@0xsequence/design-system";
2541
+
2542
+ // src/react/ui/modals/TransferModal/_utils/getTransferTransactionTitleMessage.ts
2543
+ var getTransferTransactionTitle = (params) => {
2544
+ if (params.isConfirmed) {
2545
+ return "Transfer has processed";
2546
+ }
2547
+ if (params.isFailed) {
2548
+ return "Transfer has failed";
2549
+ }
2550
+ return "Transfer is processing";
2551
+ };
2552
+ var getTransferTransactionMessage = (params, collectibleName) => {
2553
+ if (params.isConfirmed) {
2554
+ return `You just tranferred ${collectibleName}. It\u2019s been confirmed on the blockchain!`;
2555
+ }
2556
+ if (params.isFailed) {
2557
+ return `Transferring ${collectibleName} has failed. Please try again.`;
2558
+ }
2559
+ return `You just transferred ${collectibleName}. It should be confirmed on the blockchain shortly.`;
2560
+ };
2561
+
2562
+ // src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx
2563
+ import { useEffect as useEffect3 } from "react";
2564
+ import { jsx as jsx23, jsxs as jsxs19 } from "react/jsx-runtime";
2565
+ var FollowWalletInstructionsView = observer12(() => {
2566
+ const {
2567
+ receiverAddress,
2568
+ collectionAddress,
2569
+ tokenId,
2570
+ quantity,
2571
+ chainId,
2572
+ messages
2573
+ } = transferModal$.state.get();
2574
+ const { transferTokensAsync, hash } = useTransferTokens();
2575
+ const { show: showTransactionStatusModal } = useTransactionStatusModal();
2576
+ const { data: collection, isSuccess: collectionSuccess } = useCollection({
2577
+ collectionAddress,
2578
+ chainId
2579
+ });
2580
+ const { data: collectible, isSuccess: collectibleSuccess } = useCollectible({
2581
+ collectionAddress,
2582
+ collectibleId: tokenId,
2583
+ chainId
2584
+ });
2585
+ useEffect3(() => {
2586
+ if (!hash && collectionSuccess) {
2587
+ transfer();
2588
+ }
2589
+ }, [collectionSuccess, collectibleSuccess, hash]);
2590
+ async function transfer() {
2591
+ if (collection.type === "ERC721" /* ERC721 */) {
2592
+ try {
2593
+ const hash2 = await transferTokensAsync({
2594
+ receiverAddress,
2595
+ collectionAddress,
2596
+ tokenId,
2597
+ chainId,
2598
+ contractType: "ERC721" /* ERC721 */
2599
+ });
2600
+ transferModal$.close();
2601
+ showTransactionStatusModal({
2602
+ hash: hash2,
2603
+ collectionAddress,
2604
+ chainId,
2605
+ tokenId,
2606
+ price: void 0,
2607
+ getTitle: getTransferTransactionTitle,
2608
+ getMessage: (params) => getTransferTransactionMessage(params, collectible.name),
2609
+ type: "transfer"
2610
+ });
2611
+ } catch (error) {
2612
+ messages?.transferCollectibles?.onUnknownError && messages.transferCollectibles.onUnknownError(error);
2613
+ }
2614
+ }
2615
+ try {
2616
+ const hash2 = await transferTokensAsync({
2617
+ receiverAddress,
2618
+ collectionAddress,
2619
+ tokenId,
2620
+ chainId,
2621
+ contractType: "ERC1155" /* ERC1155 */,
2622
+ quantity: String(quantity)
2623
+ });
2624
+ transferModal$.close();
2625
+ showTransactionStatusModal({
2626
+ hash: hash2,
2627
+ collectionAddress,
2628
+ chainId,
2629
+ tokenId,
2630
+ price: void 0,
2631
+ getTitle: getTransferTransactionTitle,
2632
+ getMessage: (params) => getTransferTransactionMessage(params, collectible.name),
2633
+ type: "transfer"
2634
+ });
2635
+ } catch (error) {
2636
+ messages?.transferCollectibles?.onUnknownError && messages.transferCollectibles.onUnknownError(error);
2637
+ }
2638
+ }
2639
+ return /* @__PURE__ */ jsxs19(Box16, { display: "grid", gap: "6", flexGrow: "1", children: [
2640
+ /* @__PURE__ */ jsx23(Text15, { color: "white", fontSize: "large", fontWeight: "bold", children: "Transfer your item" }),
2641
+ /* @__PURE__ */ jsx23(Box16, { display: "flex", flexDirection: "column", gap: "3", children: /* @__PURE__ */ jsx23(
2642
+ AlertMessage,
2643
+ {
2644
+ message: getMessage("followWalletInstructions"),
2645
+ type: "info"
2646
+ }
2647
+ ) }),
2648
+ /* @__PURE__ */ jsx23(
2649
+ Button6,
2650
+ {
2651
+ disabled: true,
2652
+ title: "Transfer",
2653
+ label: "Transfer",
2654
+ variant: "primary",
2655
+ shape: "square",
2656
+ size: "sm",
2657
+ justifySelf: "flex-end",
2658
+ paddingX: "10"
2659
+ }
2660
+ )
2661
+ ] });
2662
+ });
2663
+ var followWalletInstructions_default = FollowWalletInstructionsView;
2664
+
2665
+ // src/react/ui/modals/TransferModal/index.tsx
2666
+ import { jsx as jsx24, jsxs as jsxs20 } from "react/jsx-runtime";
2667
+ var useTransferModal = () => {
2668
+ const { chainId: accountChainId } = useAccount9();
2669
+ const { show: showSwitchNetworkModal } = useSwitchChainModal();
2670
+ const openModal = (args) => {
2671
+ transferModal$.open(args);
2672
+ };
2673
+ const handleShowModal = (args) => {
2674
+ const isSameChain = accountChainId === Number(args.chainId);
2675
+ if (!isSameChain) {
2676
+ showSwitchNetworkModal({
2677
+ chainIdToSwitchTo: Number(args.chainId),
2678
+ onSwitchChain: () => openModal(args),
2679
+ messages: args.messages?.switchChain
2680
+ });
2681
+ return;
2682
+ }
2683
+ openModal(args);
2684
+ };
2685
+ return {
2686
+ show: handleShowModal,
2687
+ close: () => transferModal$.close()
2688
+ };
2689
+ };
2690
+ var TransferModal = () => {
2691
+ return /* @__PURE__ */ jsx24(Show4, { if: transferModal$.isOpen, children: /* @__PURE__ */ jsx24(Modal5, {}) });
2692
+ };
2693
+ var Modal5 = () => {
2694
+ return /* @__PURE__ */ jsx24(ModalContent4, {});
2695
+ };
2696
+ var ModalContent4 = observer13(() => {
2697
+ return /* @__PURE__ */ jsx24(Root5, { open: true, children: /* @__PURE__ */ jsxs20(Portal5, { children: [
2698
+ /* @__PURE__ */ jsx24(Overlay4, { className: dialogOverlay3 }),
2699
+ /* @__PURE__ */ jsxs20(Content5, { className: transferModalContent, children: [
2700
+ /* @__PURE__ */ jsx24(TransactionModalView, {}),
2701
+ /* @__PURE__ */ jsx24(Close4, { onClick: transferModal$.close, className: closeButton3, asChild: true, children: /* @__PURE__ */ jsx24(IconButton5, { size: "xs", "aria-label": "Close modal", icon: CloseIcon4 }) })
2702
+ ] })
2703
+ ] }) });
2704
+ });
2705
+ var TransactionModalView = observer13(() => {
2706
+ const { view } = transferModal$.get();
2707
+ switch (view) {
2708
+ case "enterReceiverAddress":
2709
+ return /* @__PURE__ */ jsx24(enterWalletAddress_default, {});
2710
+ case "followWalletInstructions":
2711
+ return /* @__PURE__ */ jsx24(followWalletInstructions_default, {});
2712
+ default:
2713
+ return null;
2714
+ }
2715
+ });
2716
+
2717
+ // src/react/ui/modals/modal-provider.tsx
2718
+ import { Fragment as Fragment2, jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
2719
+ var ModalProvider = observer14(() => {
2720
+ return /* @__PURE__ */ jsxs21(Fragment2, { children: [
2721
+ /* @__PURE__ */ jsx25(AccountModal, {}),
2722
+ /* @__PURE__ */ jsx25(CreateListingModal, {}),
2723
+ /* @__PURE__ */ jsx25(MakeOfferModal, {}),
2724
+ /* @__PURE__ */ jsx25(TransferModal, {}),
2725
+ /* @__PURE__ */ jsx25(SellModal, {}),
2726
+ /* @__PURE__ */ jsx25(SuccessfulPurchaseModal_default, {}),
2727
+ /* @__PURE__ */ jsx25(switchChainModal_default, {}),
2728
+ /* @__PURE__ */ jsx25(transactionStatusModal_default, {})
2729
+ ] });
2730
+ });
2731
+
2732
+ export {
2733
+ useCreateListingModal,
2734
+ useMakeOfferModal,
2735
+ useSellModal,
2736
+ useSuccessfulPurchaseModal,
2737
+ useTransferModal,
2738
+ ModalProvider
2739
+ };
2740
+ //# sourceMappingURL=chunk-SM7V6ZWI.js.map