@0xsequence/marketplace-sdk 0.8.10 → 0.8.11

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 (166) hide show
  1. package/.changeset/fluffy-jokes-lay.md +5 -0
  2. package/.changeset/wise-bugs-boil.md +8 -0
  3. package/CHANGELOG.md +16 -3
  4. package/dist/{chunk-DWTLVJAW.js → chunk-6OPMUCGX.js} +1 -1
  5. package/dist/chunk-6OPMUCGX.js.map +1 -0
  6. package/dist/{chunk-O34GCB47.js → chunk-L6KWLCER.js} +4 -4
  7. package/dist/chunk-L6KWLCER.js.map +1 -0
  8. package/dist/{chunk-Y2HJO2VY.js → chunk-LAP2CKLN.js} +56 -3
  9. package/dist/chunk-LAP2CKLN.js.map +1 -0
  10. package/dist/{chunk-Y63BOO6M.js → chunk-LECCEZAO.js} +1 -1
  11. package/dist/{chunk-WH5BZC7W.js → chunk-N7SQWS2R.js} +3 -3
  12. package/dist/{chunk-7F27CJZW.js → chunk-OAOONM4S.js} +682 -439
  13. package/dist/chunk-OAOONM4S.js.map +1 -0
  14. package/dist/chunk-QY52UADF.js +107 -0
  15. package/dist/chunk-QY52UADF.js.map +1 -0
  16. package/dist/{chunk-UJSF7PSC.js → chunk-TNAR3XEF.js} +3766 -765
  17. package/dist/chunk-TNAR3XEF.js.map +1 -0
  18. package/dist/chunk-XABYNWXO.js +549 -0
  19. package/dist/chunk-XABYNWXO.js.map +1 -0
  20. package/dist/chunk-YB5UUF2G.js +11 -0
  21. package/dist/chunk-YB5UUF2G.js.map +1 -0
  22. package/dist/{chunk-M6NJ73Y5.js → chunk-YWGFI4PN.js} +87 -24
  23. package/dist/chunk-YWGFI4PN.js.map +1 -0
  24. package/dist/{create-config-CAQcvjl6.d.ts → create-config-DLMvMTkZ.d.ts} +2 -2
  25. package/dist/index.css +1 -1
  26. package/dist/index.css.map +1 -1
  27. package/dist/index.d.ts +7 -6
  28. package/dist/index.js +14 -15
  29. package/dist/{listTokenMetadata-DO4ChDjn.d.ts → marketCurrencies-enNVYwBk.d.ts} +77 -3
  30. package/dist/{marketplace.gen-DQzWciwC.d.ts → marketplace.gen-D24veUQs.d.ts} +3 -2
  31. package/dist/marketplaceConfig-BwNAbLPw.d.ts +21 -0
  32. package/dist/new-marketplace-types-BCw19X9S.d.ts +102 -0
  33. package/dist/react/_internal/api/index.d.ts +3 -3
  34. package/dist/react/_internal/api/index.js +1 -1
  35. package/dist/react/_internal/databeat/index.css +2764 -0
  36. package/dist/react/_internal/databeat/index.css.map +1 -0
  37. package/dist/react/_internal/databeat/index.d.ts +1 -1
  38. package/dist/react/_internal/databeat/index.js +12 -12
  39. package/dist/react/_internal/index.d.ts +61 -9
  40. package/dist/react/_internal/index.js +3 -3
  41. package/dist/react/_internal/wagmi/index.d.ts +5 -6
  42. package/dist/react/_internal/wagmi/index.js +1 -1
  43. package/dist/react/hooks/index.css +2764 -0
  44. package/dist/react/hooks/index.css.map +1 -0
  45. package/dist/react/hooks/index.d.ts +71 -222
  46. package/dist/react/hooks/index.js +16 -20
  47. package/dist/react/hooks/options/index.d.ts +5 -4
  48. package/dist/react/hooks/options/index.js +9 -7
  49. package/dist/react/index.css +1 -1
  50. package/dist/react/index.css.map +1 -1
  51. package/dist/react/index.d.ts +9 -9
  52. package/dist/react/index.js +28 -34
  53. package/dist/react/queries/index.d.ts +3 -3
  54. package/dist/react/queries/index.js +15 -4
  55. package/dist/react/ssr/index.d.ts +3 -3
  56. package/dist/react/ssr/index.js +6 -5
  57. package/dist/react/ssr/index.js.map +1 -1
  58. package/dist/react/ui/components/collectible-card/index.css +1 -1
  59. package/dist/react/ui/components/collectible-card/index.css.map +1 -1
  60. package/dist/react/ui/components/collectible-card/index.d.ts +3 -2
  61. package/dist/react/ui/components/collectible-card/index.js +12 -17
  62. package/dist/react/ui/icons/index.js +6 -6
  63. package/dist/react/ui/index.css +1 -1
  64. package/dist/react/ui/index.css.map +1 -1
  65. package/dist/react/ui/index.d.ts +1 -1
  66. package/dist/react/ui/index.js +12 -17
  67. package/dist/react/ui/modals/_internal/components/actionModal/index.css +2764 -0
  68. package/dist/react/ui/modals/_internal/components/actionModal/index.css.map +1 -0
  69. package/dist/react/ui/modals/_internal/components/actionModal/index.js +12 -12
  70. package/dist/sdk-config-qorA0TgF.d.ts +165 -0
  71. package/dist/{services-CMSb9ipU.d.ts → services-WrshxCqc.d.ts} +2 -2
  72. package/dist/types/index.d.ts +5 -4
  73. package/dist/types/index.js +7 -7
  74. package/dist/{index-MlUK9AQE.d.ts → useCollection-YAdXfVO7.d.ts} +1 -2
  75. package/dist/utils/abi/index.js +4 -4
  76. package/dist/utils/index.d.ts +1 -1
  77. package/dist/utils/index.js +8 -7
  78. package/package.json +15 -15
  79. package/src/react/_internal/api/__mocks__/builder.msw.ts +157 -80
  80. package/src/react/_internal/api/builder-api.ts +2 -2
  81. package/src/react/_internal/api/builder.gen.ts +667 -112
  82. package/src/react/_internal/api/marketplace.gen.ts +1981 -1316
  83. package/src/react/_internal/types.ts +1 -13
  84. package/src/react/_internal/wagmi/__tests__/create-config.test.ts +99 -84
  85. package/src/react/_internal/wagmi/create-config.ts +8 -4
  86. package/src/react/_internal/wagmi/get-connectors.ts +24 -19
  87. package/src/react/hooks/__tests__/__snapshots__/useListCollections.test.tsx.snap +114 -0
  88. package/src/react/hooks/__tests__/__snapshots__/useMarketplaceConfig.test.tsx.snap +85 -83
  89. package/src/react/hooks/__tests__/useFilters.test.tsx +0 -16
  90. package/src/react/hooks/__tests__/useInventory.test.tsx +16 -16
  91. package/src/react/hooks/__tests__/useListCollections.test.tsx +23 -56
  92. package/src/react/hooks/__tests__/{useCurrencies.test.tsx → useMarketCurrencies.test.tsx} +21 -15
  93. package/src/react/hooks/__tests__/useMarketplaceConfig.test.tsx +2 -59
  94. package/src/react/hooks/index.ts +2 -1
  95. package/src/react/hooks/useBalanceOfCollectible.tsx +5 -3
  96. package/src/react/hooks/useConvertPriceToUSD.tsx +1 -1
  97. package/src/react/hooks/useFilters.tsx +14 -22
  98. package/src/react/hooks/useGetTokenSuppliesMap.ts +28 -0
  99. package/src/react/hooks/useInventory.tsx +4 -3
  100. package/src/react/hooks/useListBalances.tsx +5 -3
  101. package/src/react/hooks/useListCollectibles.tsx +5 -3
  102. package/src/react/hooks/useListCollections.tsx +14 -76
  103. package/src/react/hooks/useMarketCurrencies.tsx +8 -0
  104. package/src/react/hooks/useMarketplaceConfig.tsx +0 -2
  105. package/src/react/queries/index.ts +1 -0
  106. package/src/react/queries/inventory.ts +1 -1
  107. package/src/react/queries/listCollections.ts +118 -0
  108. package/src/react/queries/marketCurrencies.ts +77 -0
  109. package/src/react/queries/marketplaceConfig.ts +83 -55
  110. package/src/react/ssr/__tests__/__snapshots__/create-ssr-client.test.ts.snap +85 -83
  111. package/src/react/ui/components/collectible-card/__tests__/Media.test.tsx +41 -1
  112. package/src/react/ui/components/collectible-card/media/Media.tsx +11 -6
  113. package/src/react/ui/components/collectible-card/media/MediaSkeleton.tsx +1 -1
  114. package/src/react/ui/components/collectible-card/media/types.ts +1 -0
  115. package/src/react/ui/modals/BuyModal/ERC1155QuantityModal.tsx +9 -3
  116. package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +31 -21
  117. package/src/react/ui/modals/BuyModal/hooks/useFees.ts +3 -2
  118. package/src/react/ui/modals/CreateListingModal/Modal.tsx +3 -5
  119. package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +5 -3
  120. package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +2 -2
  121. package/src/react/ui/modals/MakeOfferModal/Modal.tsx +2 -3
  122. package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +4 -3
  123. package/src/react/ui/modals/SellModal/Modal.tsx +0 -1
  124. package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +2 -2
  125. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +0 -1
  126. package/src/react/ui/modals/TransferModal/index.tsx +0 -1
  127. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +2 -2
  128. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +7 -6
  129. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/__tests__/SelectWaasFeeOptions.test.tsx +13 -7
  130. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/index.tsx +3 -5
  131. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/useWaasFeeOptionManager.tsx +5 -3
  132. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
  133. package/src/react/ui/modals/_internal/hooks/useSelectWaasFeeOptions.ts +2 -12
  134. package/src/types/index.ts +1 -6
  135. package/src/types/new-marketplace-types.ts +119 -0
  136. package/src/types/sdk-config.ts +18 -2
  137. package/src/types/types.ts +1 -0
  138. package/tsconfig.tsbuildinfo +1 -1
  139. package/dist/chunk-7F27CJZW.js.map +0 -1
  140. package/dist/chunk-A7BVFBWB.js +0 -81
  141. package/dist/chunk-A7BVFBWB.js.map +0 -1
  142. package/dist/chunk-D7RVSZAQ.js +0 -332
  143. package/dist/chunk-D7RVSZAQ.js.map +0 -1
  144. package/dist/chunk-DWTLVJAW.js.map +0 -1
  145. package/dist/chunk-FGM57QUU.js +0 -128
  146. package/dist/chunk-FGM57QUU.js.map +0 -1
  147. package/dist/chunk-JKCF7HEA.js +0 -1
  148. package/dist/chunk-JKCF7HEA.js.map +0 -1
  149. package/dist/chunk-KTST7ORH.js +0 -53
  150. package/dist/chunk-KTST7ORH.js.map +0 -1
  151. package/dist/chunk-M6NJ73Y5.js.map +0 -1
  152. package/dist/chunk-N7BPFK46.js +0 -1
  153. package/dist/chunk-N7BPFK46.js.map +0 -1
  154. package/dist/chunk-O34GCB47.js.map +0 -1
  155. package/dist/chunk-RVIUUJTP.js +0 -76
  156. package/dist/chunk-RVIUUJTP.js.map +0 -1
  157. package/dist/chunk-SXVUTSMT.js +0 -2895
  158. package/dist/chunk-SXVUTSMT.js.map +0 -1
  159. package/dist/chunk-UJSF7PSC.js.map +0 -1
  160. package/dist/chunk-Y2HJO2VY.js.map +0 -1
  161. package/dist/marketplaceConfig-D0MXemEl.d.ts +0 -17
  162. package/dist/sdk-config-onSPBxJj.d.ts +0 -134
  163. package/dist/types-B8xzPEKX.d.ts +0 -68
  164. package/src/react/hooks/useCurrencies.tsx +0 -77
  165. /package/dist/{chunk-Y63BOO6M.js.map → chunk-LECCEZAO.js.map} +0 -0
  166. /package/dist/{chunk-WH5BZC7W.js.map → chunk-N7SQWS2R.js.map} +0 -0
@@ -1,2895 +0,0 @@
1
- 'use client';
2
-
3
- import {
4
- collectionOptions
5
- } from "./chunk-WH5BZC7W.js";
6
- import {
7
- InfoIcon_default
8
- } from "./chunk-RVIUUJTP.js";
9
- import {
10
- SEQUENCE_MARKET_V1_ADDRESS,
11
- SEQUENCE_MARKET_V2_ADDRESS
12
- } from "./chunk-Y63BOO6M.js";
13
- import {
14
- compareAddress,
15
- getPresentableChainName
16
- } from "./chunk-5O44EPXZ.js";
17
- import {
18
- ERC1155_ABI
19
- } from "./chunk-FUM4OGOQ.js";
20
- import {
21
- EIP2981_ABI
22
- } from "./chunk-XX4EVWBF.js";
23
- import {
24
- balanceOfCollectibleOptions,
25
- highestOfferOptions,
26
- inventoryOptions,
27
- listBalancesOptions,
28
- listCollectiblesOptions,
29
- lowestListingOptions,
30
- tokenMetadataOptions
31
- } from "./chunk-Y2HJO2VY.js";
32
- import {
33
- marketplaceConfigOptions
34
- } from "./chunk-A7BVFBWB.js";
35
- import {
36
- AddressSchema,
37
- CollectableIdSchema,
38
- PROVIDER_ID,
39
- QueryArgSchema
40
- } from "./chunk-DWTLVJAW.js";
41
- import {
42
- CollectibleStatus,
43
- CollectionStatus,
44
- ContractType,
45
- MarketplaceKind,
46
- OrderSide,
47
- OrderStatus,
48
- OrderbookKind,
49
- ProjectStatus,
50
- PropertyType,
51
- SortOrder,
52
- SourceKind,
53
- StepType,
54
- TransactionCrypto,
55
- TransactionNFTCheckoutProvider,
56
- TransactionOnRampProvider,
57
- TransactionSwapProvider,
58
- WalletKind,
59
- balanceQueries,
60
- collectableKeys,
61
- collectionKeys,
62
- currencyKeys,
63
- getIndexerClient,
64
- getMarketplaceClient,
65
- getMetadataClient,
66
- getQueryClient
67
- } from "./chunk-7F27CJZW.js";
68
- import {
69
- BaseError,
70
- ChainSwitchError,
71
- ChainSwitchUserRejectedError,
72
- NoWalletConnectedError,
73
- TransactionConfirmationError,
74
- TransactionExecutionError,
75
- TransactionSignatureError,
76
- UserRejectedRequestError,
77
- WalletInstanceNotFoundError
78
- } from "./chunk-NX52D7NX.js";
79
-
80
- // src/react/hooks/useAutoSelectFeeOption.tsx
81
- import { zeroAddress } from "viem";
82
- import { useChain } from "@0xsequence/connect";
83
- import { useCallback, useEffect } from "react";
84
- import { useAccount } from "wagmi";
85
-
86
- // src/react/hooks/useCollectionBalanceDetails.tsx
87
- import { queryOptions, useQuery } from "@tanstack/react-query";
88
- import { z } from "zod";
89
-
90
- // src/react/hooks/useConfig.tsx
91
- import { useContext } from "react";
92
-
93
- // src/utils/_internal/error/context.ts
94
- var MarketplaceSdkProviderNotFoundError = class extends BaseError {
95
- name = "MarketplaceSDKProviderNotFoundError";
96
- constructor() {
97
- super("`useConfig` must be used within `MarketplaceSdkProvider`.");
98
- }
99
- };
100
-
101
- // src/react/provider.tsx
102
- import { QueryClientProvider } from "@tanstack/react-query";
103
- import { createContext } from "react";
104
-
105
- // src/utils/_internal/error/config.ts
106
- var ConfigError = class extends BaseError {
107
- name = "ConfigError";
108
- };
109
- var InvalidProjectAccessKeyError = class extends ConfigError {
110
- name = "InvalidProjectAccessKeyError";
111
- constructor(projectAccessKey) {
112
- super(`Invalid project access key: ${projectAccessKey}`);
113
- }
114
- };
115
-
116
- // src/react/provider.tsx
117
- import { jsx } from "react/jsx-runtime";
118
- var MarketplaceSdkContext = createContext({});
119
- function MarketplaceQueryClientProvider({
120
- children
121
- }) {
122
- const queryClient = getQueryClient();
123
- return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children });
124
- }
125
- function MarketplaceProvider({
126
- config,
127
- children
128
- }) {
129
- if (config.projectAccessKey === "" || !config.projectAccessKey) {
130
- throw new InvalidProjectAccessKeyError(config.projectAccessKey);
131
- }
132
- return /* @__PURE__ */ jsx(MarketplaceQueryClientProvider, { children: /* @__PURE__ */ jsx(MarketplaceSdkContext.Provider, { value: config, children: /* @__PURE__ */ jsx("div", { id: PROVIDER_ID, children }) }) });
133
- }
134
-
135
- // src/react/hooks/useConfig.tsx
136
- function useConfig() {
137
- const context = useContext(MarketplaceSdkContext);
138
- if (!context) {
139
- throw new MarketplaceSdkProviderNotFoundError();
140
- }
141
- return context;
142
- }
143
-
144
- // src/react/hooks/useCollectionBalanceDetails.tsx
145
- var filterSchema = z.object({
146
- accountAddresses: z.array(AddressSchema),
147
- contractWhitelist: z.array(AddressSchema).optional(),
148
- omitNativeBalances: z.boolean()
149
- });
150
- var useCollectionBalanceDetailsArgsSchema = z.object({
151
- chainId: z.number(),
152
- filter: filterSchema,
153
- query: QueryArgSchema.optional()
154
- });
155
- var fetchCollectionBalanceDetails = async (args, indexerClient) => {
156
- const promises = args.filter.accountAddresses.map(
157
- (accountAddress) => indexerClient.getTokenBalancesDetails({
158
- filter: {
159
- accountAddresses: [accountAddress],
160
- contractWhitelist: args.filter.contractWhitelist,
161
- omitNativeBalances: args.filter.omitNativeBalances
162
- }
163
- })
164
- );
165
- const responses = await Promise.all(promises);
166
- const mergedResponse = responses.reduce(
167
- (acc, curr) => {
168
- if (!curr) return acc;
169
- return {
170
- page: curr.page,
171
- nativeBalances: [
172
- ...acc.nativeBalances || [],
173
- ...curr.nativeBalances || []
174
- ],
175
- balances: [...acc.balances || [], ...curr.balances || []]
176
- };
177
- },
178
- { page: {}, nativeBalances: [], balances: [] }
179
- );
180
- if (!mergedResponse) {
181
- throw new Error("Failed to fetch collection balance details");
182
- }
183
- return mergedResponse;
184
- };
185
- var collectionBalanceDetailsOptions = (args, config) => {
186
- const parsedArgs = useCollectionBalanceDetailsArgsSchema.parse(args);
187
- const indexerClient = getIndexerClient(parsedArgs.chainId, config);
188
- return queryOptions({
189
- queryKey: [...balanceQueries.collectionBalanceDetails, args, config],
190
- queryFn: () => fetchCollectionBalanceDetails(parsedArgs, indexerClient),
191
- ...args.query
192
- });
193
- };
194
- var useCollectionBalanceDetails = (args) => {
195
- const config = useConfig();
196
- return useQuery(collectionBalanceDetailsOptions(args, config));
197
- };
198
-
199
- // src/react/hooks/useAutoSelectFeeOption.tsx
200
- function useAutoSelectFeeOption({
201
- pendingFeeOptionConfirmation,
202
- enabled
203
- }) {
204
- const { address: userAddress } = useAccount();
205
- const contractWhitelist = pendingFeeOptionConfirmation.options?.map(
206
- (option) => option.token.contractAddress === null ? zeroAddress : option.token.contractAddress
207
- );
208
- const {
209
- data: balanceDetails,
210
- isLoading: isBalanceDetailsLoading,
211
- isError: isBalanceDetailsError
212
- } = useCollectionBalanceDetails({
213
- chainId: pendingFeeOptionConfirmation.chainId,
214
- filter: {
215
- accountAddresses: userAddress ? [userAddress] : [],
216
- contractWhitelist,
217
- omitNativeBalances: false
218
- },
219
- query: {
220
- enabled: !!pendingFeeOptionConfirmation.options && !!userAddress && enabled
221
- }
222
- });
223
- const chain = useChain(pendingFeeOptionConfirmation.chainId);
224
- const combinedBalances = balanceDetails && [
225
- ...balanceDetails.nativeBalances.map((b) => ({
226
- chainId: pendingFeeOptionConfirmation.chainId,
227
- balance: b.balance,
228
- symbol: chain?.nativeCurrency.symbol,
229
- contractAddress: zeroAddress
230
- })),
231
- ...balanceDetails.balances.map((b) => ({
232
- chainId: b.chainId,
233
- balance: b.balance,
234
- symbol: b.contractInfo?.symbol,
235
- contractAddress: b.contractAddress
236
- }))
237
- ];
238
- useEffect(() => {
239
- if (combinedBalances) {
240
- console.debug("currency balances", combinedBalances);
241
- }
242
- }, [combinedBalances]);
243
- const autoSelectedOption = useCallback(async () => {
244
- if (!userAddress) {
245
- return {
246
- selectedOption: null,
247
- error: "User not connected" /* UserNotConnected */
248
- };
249
- }
250
- if (!pendingFeeOptionConfirmation.options) {
251
- return {
252
- selectedOption: null,
253
- error: "No options provided" /* NoOptionsProvided */
254
- };
255
- }
256
- if (isBalanceDetailsLoading) {
257
- return { selectedOption: null, error: null, isLoading: true };
258
- }
259
- if (isBalanceDetailsError || !combinedBalances) {
260
- return {
261
- selectedOption: null,
262
- error: "Failed to check balances" /* FailedToCheckBalances */
263
- };
264
- }
265
- const selectedOption = pendingFeeOptionConfirmation.options.find(
266
- (option) => {
267
- const tokenBalance = combinedBalances.find(
268
- (balance) => balance.contractAddress.toLowerCase() === (option.token.contractAddress === null ? zeroAddress : option.token.contractAddress).toLowerCase()
269
- );
270
- if (!tokenBalance) return false;
271
- return BigInt(tokenBalance.balance) >= BigInt(option.value);
272
- }
273
- );
274
- if (!selectedOption) {
275
- return {
276
- selectedOption: null,
277
- error: "Insufficient balance for any fee option" /* InsufficientBalanceForAnyFeeOption */
278
- };
279
- }
280
- console.debug("auto selected option", selectedOption);
281
- return { selectedOption, error: null };
282
- }, [
283
- userAddress,
284
- pendingFeeOptionConfirmation.options,
285
- isBalanceDetailsLoading,
286
- isBalanceDetailsError,
287
- combinedBalances
288
- ]);
289
- return autoSelectedOption();
290
- }
291
-
292
- // src/react/hooks/useBalanceOfCollectible.tsx
293
- import { useQuery as useQuery3 } from "@tanstack/react-query";
294
-
295
- // src/react/hooks/useMarketplaceConfig.tsx
296
- import { useQuery as useQuery2 } from "@tanstack/react-query";
297
- var useMarketplaceConfig = () => {
298
- const config = useConfig();
299
- return useQuery2(marketplaceConfigOptions(config));
300
- };
301
-
302
- // src/react/hooks/useBalanceOfCollectible.tsx
303
- function useBalanceOfCollectible(args) {
304
- const config = useConfig();
305
- const { data: marketplaceConfig } = useMarketplaceConfig();
306
- const isLaos721 = marketplaceConfig?.collections.find(
307
- (collection) => collection.address === args.collectionAddress
308
- )?.isLAOSERC721;
309
- if (isLaos721) {
310
- args.isLaos721 = true;
311
- }
312
- return useQuery3(balanceOfCollectibleOptions(args, config));
313
- }
314
-
315
- // src/react/hooks/useCountOfCollectables.tsx
316
- import { queryOptions as queryOptions2, useQuery as useQuery4 } from "@tanstack/react-query";
317
- import { z as z3 } from "zod";
318
-
319
- // src/react/_internal/api/zod-schema.ts
320
- import { z as z2 } from "zod";
321
- var assetSchema = z2.object({
322
- id: z2.number(),
323
- collectionId: z2.number(),
324
- tokenId: z2.string(),
325
- url: z2.string().optional(),
326
- metadataField: z2.string(),
327
- name: z2.string().optional(),
328
- filesize: z2.number().optional(),
329
- mimeType: z2.string().optional(),
330
- width: z2.number().optional(),
331
- height: z2.number().optional(),
332
- updatedAt: z2.string().optional()
333
- });
334
- var sortOrderSchema = z2.nativeEnum(SortOrder);
335
- var propertyTypeSchema = z2.nativeEnum(PropertyType);
336
- var marketplaceKindSchema = z2.nativeEnum(MarketplaceKind);
337
- var orderbookKindSchema = z2.nativeEnum(OrderbookKind);
338
- var sourceKindSchema = z2.nativeEnum(SourceKind);
339
- var orderSideSchema = z2.nativeEnum(OrderSide);
340
- var orderStatusSchema = z2.nativeEnum(OrderStatus);
341
- var contractTypeSchema = z2.nativeEnum(ContractType);
342
- var collectionStatusSchema = z2.nativeEnum(CollectionStatus);
343
- var projectStatusSchema = z2.nativeEnum(ProjectStatus);
344
- var collectibleStatusSchema = z2.nativeEnum(CollectibleStatus);
345
- var walletKindSchema = z2.nativeEnum(WalletKind);
346
- var stepTypeSchema = z2.nativeEnum(StepType);
347
- var transactionCryptoSchema = z2.nativeEnum(TransactionCrypto);
348
- var transactionNFTCheckoutProviderSchema = z2.nativeEnum(
349
- TransactionNFTCheckoutProvider
350
- );
351
- var transactionOnRampProviderSchema = z2.nativeEnum(
352
- TransactionOnRampProvider
353
- );
354
- var transactionSwapProviderSchema = z2.nativeEnum(
355
- TransactionSwapProvider
356
- );
357
- var sortBySchema = z2.object({
358
- column: z2.string(),
359
- order: sortOrderSchema
360
- });
361
- var propertyFilterSchema = z2.object({
362
- name: z2.string(),
363
- type: propertyTypeSchema,
364
- min: z2.number().optional(),
365
- max: z2.number().optional(),
366
- values: z2.array(z2.any()).optional()
367
- });
368
- var collectiblesFilterSchema = z2.object({
369
- includeEmpty: z2.boolean(),
370
- searchText: z2.string().optional(),
371
- properties: z2.array(propertyFilterSchema).optional(),
372
- marketplaces: z2.array(marketplaceKindSchema).optional(),
373
- inAccounts: z2.array(z2.string()).optional(),
374
- notInAccounts: z2.array(z2.string()).optional(),
375
- ordersCreatedBy: z2.array(z2.string()).optional(),
376
- ordersNotCreatedBy: z2.array(z2.string()).optional()
377
- });
378
- var feeBreakdownSchema = z2.object({
379
- kind: z2.string(),
380
- recipientAddress: z2.string(),
381
- bps: z2.number()
382
- });
383
- var orderFilterSchema = z2.object({
384
- createdBy: z2.array(z2.string()).optional(),
385
- marketplace: z2.array(marketplaceKindSchema).optional(),
386
- currencies: z2.array(z2.string()).optional()
387
- });
388
- var collectionLastSyncedSchema = z2.object({
389
- allOrders: z2.string(),
390
- newOrders: z2.string()
391
- });
392
- var projectSchema = z2.object({
393
- projectId: z2.number(),
394
- chainId: z2.number(),
395
- contractAddress: z2.string(),
396
- status: projectStatusSchema,
397
- createdAt: z2.string(),
398
- updatedAt: z2.string(),
399
- deletedAt: z2.string().optional()
400
- });
401
- var collectibleSchema = z2.object({
402
- chainId: z2.number(),
403
- contractAddress: z2.string(),
404
- status: collectibleStatusSchema,
405
- tokenId: z2.string(),
406
- createdAt: z2.string(),
407
- updatedAt: z2.string(),
408
- deletedAt: z2.string().optional()
409
- });
410
- var currencySchema = z2.object({
411
- chainId: z2.number(),
412
- contractAddress: z2.string(),
413
- name: z2.string(),
414
- symbol: z2.string(),
415
- decimals: z2.number(),
416
- imageUrl: z2.string(),
417
- exchangeRate: z2.number(),
418
- defaultChainCurrency: z2.boolean(),
419
- nativeCurrency: z2.boolean(),
420
- createdAt: z2.string(),
421
- updatedAt: z2.string(),
422
- deletedAt: z2.string().optional()
423
- });
424
- var orderDataSchema = z2.object({
425
- orderId: z2.string(),
426
- quantity: z2.string()
427
- });
428
- var additionalFeeSchema = z2.object({
429
- amount: z2.string(),
430
- receiver: z2.string()
431
- });
432
- var postRequestSchema = z2.object({
433
- endpoint: z2.string(),
434
- method: z2.string(),
435
- body: z2.any()
436
- });
437
- var createReqSchema = z2.object({
438
- tokenId: z2.string(),
439
- quantity: z2.string(),
440
- expiry: z2.string(),
441
- currencyAddress: z2.string(),
442
- pricePerToken: z2.string()
443
- });
444
- var getOrdersInputSchema = z2.object({
445
- contractAddress: z2.string(),
446
- orderId: z2.string(),
447
- marketplace: marketplaceKindSchema
448
- });
449
- var domainSchema = z2.object({
450
- name: z2.string(),
451
- version: z2.string(),
452
- chainId: z2.number(),
453
- verifyingContract: z2.string()
454
- });
455
- var checkoutOptionsMarketplaceOrderSchema = z2.object({
456
- contractAddress: z2.string(),
457
- orderId: z2.string(),
458
- marketplace: marketplaceKindSchema
459
- });
460
- var checkoutOptionsItemSchema = z2.object({
461
- tokenId: z2.string(),
462
- quantity: z2.string()
463
- });
464
- var checkoutOptionsSchema = z2.object({
465
- crypto: transactionCryptoSchema,
466
- swap: z2.array(transactionSwapProviderSchema),
467
- nftCheckout: z2.array(transactionNFTCheckoutProviderSchema),
468
- onRamp: z2.array(transactionOnRampProviderSchema)
469
- });
470
- var listCurrenciesArgsSchema = z2.object({});
471
- var listCurrenciesReturnSchema = z2.object({
472
- currencies: z2.array(currencySchema)
473
- });
474
- var getCollectibleArgsSchema = z2.object({
475
- contractAddress: z2.string(),
476
- tokenId: z2.string()
477
- });
478
- var getLowestPriceOfferForCollectibleArgsSchema = z2.object({
479
- contractAddress: z2.string(),
480
- tokenId: z2.string(),
481
- filter: orderFilterSchema.optional()
482
- });
483
- var getHighestPriceOfferForCollectibleArgsSchema = z2.object({
484
- contractAddress: z2.string(),
485
- tokenId: z2.string(),
486
- filter: orderFilterSchema.optional()
487
- });
488
- var getLowestPriceListingForCollectibleArgsSchema = z2.object({
489
- contractAddress: z2.string(),
490
- tokenId: z2.string(),
491
- filter: orderFilterSchema.optional()
492
- });
493
- var getHighestPriceListingForCollectibleArgsSchema = z2.object({
494
- contractAddress: z2.string(),
495
- tokenId: z2.string(),
496
- filter: orderFilterSchema.optional()
497
- });
498
- var getCollectibleLowestOfferArgsSchema = z2.object({
499
- contractAddress: z2.string(),
500
- tokenId: z2.string(),
501
- filter: orderFilterSchema.optional()
502
- });
503
- var getCollectibleHighestOfferArgsSchema = z2.object({
504
- contractAddress: z2.string(),
505
- tokenId: z2.string(),
506
- filter: orderFilterSchema.optional()
507
- });
508
- var getCollectibleLowestListingArgsSchema = z2.object({
509
- contractAddress: z2.string(),
510
- tokenId: z2.string(),
511
- filters: orderFilterSchema.optional()
512
- });
513
- var getCollectibleHighestListingArgsSchema = z2.object({
514
- contractAddress: z2.string(),
515
- tokenId: z2.string(),
516
- filter: orderFilterSchema.optional()
517
- });
518
- var generateBuyTransactionArgsSchema = z2.object({
519
- collectionAddress: z2.string(),
520
- buyer: z2.string(),
521
- marketplace: marketplaceKindSchema,
522
- ordersData: z2.array(orderDataSchema),
523
- additionalFees: z2.array(additionalFeeSchema),
524
- walletType: walletKindSchema.optional()
525
- });
526
- var generateSellTransactionArgsSchema = z2.object({
527
- collectionAddress: z2.string(),
528
- seller: z2.string(),
529
- marketplace: marketplaceKindSchema,
530
- ordersData: z2.array(orderDataSchema),
531
- additionalFees: z2.array(additionalFeeSchema),
532
- walletType: walletKindSchema.optional()
533
- });
534
- var generateListingTransactionArgsSchema = z2.object({
535
- collectionAddress: z2.string(),
536
- owner: z2.string(),
537
- contractType: contractTypeSchema,
538
- orderbook: orderbookKindSchema,
539
- listing: createReqSchema,
540
- walletType: walletKindSchema.optional()
541
- });
542
- var generateOfferTransactionArgsSchema = z2.object({
543
- collectionAddress: z2.string(),
544
- maker: z2.string(),
545
- contractType: contractTypeSchema,
546
- orderbook: orderbookKindSchema,
547
- offer: createReqSchema,
548
- walletType: walletKindSchema.optional()
549
- });
550
- var getCountOfAllCollectiblesArgsSchema = z2.object({
551
- contractAddress: z2.string()
552
- });
553
- var getCountOfAllCollectiblesReturnSchema = z2.object({
554
- count: z2.number()
555
- });
556
- var getCountOfFilteredCollectiblesArgsSchema = z2.object({
557
- side: orderSideSchema,
558
- contractAddress: z2.string(),
559
- filter: collectiblesFilterSchema.optional()
560
- });
561
- var getCountOfFilteredCollectiblesReturnSchema = z2.object({
562
- count: z2.number()
563
- });
564
- var getFloorOrderArgsSchema = z2.object({
565
- contractAddress: z2.string(),
566
- filter: collectiblesFilterSchema.optional()
567
- });
568
- var syncOrderReturnSchema = z2.object({});
569
- var syncOrdersReturnSchema = z2.object({});
570
- var checkoutOptionsMarketplaceArgsSchema = z2.object({
571
- wallet: z2.string(),
572
- orders: z2.array(checkoutOptionsMarketplaceOrderSchema),
573
- additionalFee: z2.number()
574
- });
575
- var checkoutOptionsMarketplaceReturnSchema = z2.object({
576
- options: checkoutOptionsSchema
577
- });
578
- var checkoutOptionsSalesContractArgsSchema = z2.object({
579
- wallet: z2.string(),
580
- contractAddress: z2.string(),
581
- collectionAddress: z2.string(),
582
- items: z2.array(checkoutOptionsItemSchema)
583
- });
584
- var checkoutOptionsSalesContractReturnSchema = z2.object({
585
- options: checkoutOptionsSchema
586
- });
587
- var countListingsForCollectibleArgsSchema = z2.object({
588
- contractAddress: z2.string(),
589
- tokenId: z2.string(),
590
- filter: orderFilterSchema.optional()
591
- });
592
- var countListingsForCollectibleReturnSchema = z2.object({
593
- count: z2.number()
594
- });
595
- var countOffersForCollectibleArgsSchema = z2.object({
596
- contractAddress: z2.string(),
597
- tokenId: z2.string(),
598
- filter: orderFilterSchema.optional()
599
- });
600
- var countOffersForCollectibleReturnSchema = z2.object({
601
- count: z2.number()
602
- });
603
- var tokenMetadataSchema = z2.object({
604
- tokenId: z2.string(),
605
- name: z2.string(),
606
- description: z2.string().optional(),
607
- image: z2.string().optional(),
608
- video: z2.string().optional(),
609
- audio: z2.string().optional(),
610
- properties: z2.record(z2.any()).optional(),
611
- attributes: z2.array(z2.record(z2.any())),
612
- image_data: z2.string().optional(),
613
- external_url: z2.string().optional(),
614
- background_color: z2.string().optional(),
615
- animation_url: z2.string().optional(),
616
- decimals: z2.number().optional(),
617
- updatedAt: z2.string().optional(),
618
- assets: z2.array(assetSchema).optional()
619
- });
620
- var pageSchema = z2.object({
621
- page: z2.number(),
622
- pageSize: z2.number(),
623
- more: z2.boolean().optional(),
624
- sort: z2.array(sortBySchema).optional()
625
- });
626
- var filterSchema2 = z2.object({
627
- text: z2.string().optional(),
628
- properties: z2.array(propertyFilterSchema).optional()
629
- });
630
- var orderSchema = z2.object({
631
- orderId: z2.string(),
632
- marketplace: marketplaceKindSchema,
633
- side: orderSideSchema,
634
- status: orderStatusSchema,
635
- chainId: z2.number(),
636
- collectionContractAddress: z2.string(),
637
- tokenId: z2.string(),
638
- createdBy: z2.string(),
639
- priceAmount: z2.string(),
640
- priceAmountFormatted: z2.string(),
641
- priceAmountNet: z2.string(),
642
- priceAmountNetFormatted: z2.string(),
643
- priceCurrencyAddress: z2.string(),
644
- priceDecimals: z2.number(),
645
- priceUSD: z2.number(),
646
- quantityInitial: z2.string(),
647
- quantityInitialFormatted: z2.string(),
648
- quantityRemaining: z2.string(),
649
- quantityRemainingFormatted: z2.string(),
650
- quantityAvailable: z2.string(),
651
- quantityAvailableFormatted: z2.string(),
652
- quantityDecimals: z2.number(),
653
- feeBps: z2.number(),
654
- feeBreakdown: z2.array(feeBreakdownSchema),
655
- validFrom: z2.string(),
656
- validUntil: z2.string(),
657
- blockNumber: z2.number(),
658
- orderCreatedAt: z2.string().optional(),
659
- orderUpdatedAt: z2.string().optional(),
660
- createdAt: z2.string(),
661
- updatedAt: z2.string(),
662
- deletedAt: z2.string().optional()
663
- });
664
- var collectibleOrderSchema = z2.object({
665
- metadata: tokenMetadataSchema,
666
- order: orderSchema.optional()
667
- });
668
- var activitySchema = z2.object({
669
- type: z2.string(),
670
- fromAddress: z2.string(),
671
- toAddress: z2.string(),
672
- txHash: z2.string(),
673
- timestamp: z2.number(),
674
- tokenId: z2.string(),
675
- tokenImage: z2.string(),
676
- tokenName: z2.string(),
677
- currency: currencySchema.optional()
678
- });
679
- var collectionConfigSchema = z2.object({
680
- lastSynced: z2.record(collectionLastSyncedSchema),
681
- collectiblesSynced: z2.string()
682
- });
683
- var signatureSchema = z2.object({
684
- domain: domainSchema,
685
- types: z2.any(),
686
- primaryType: z2.string(),
687
- value: z2.any()
688
- });
689
- var getCollectibleReturnSchema = z2.object({
690
- metadata: tokenMetadataSchema
691
- });
692
- var getLowestPriceOfferForCollectibleReturnSchema = z2.object({
693
- order: orderSchema
694
- });
695
- var getHighestPriceOfferForCollectibleReturnSchema = z2.object({
696
- order: orderSchema
697
- });
698
- var getLowestPriceListingForCollectibleReturnSchema = z2.object({
699
- order: orderSchema
700
- });
701
- var getHighestPriceListingForCollectibleReturnSchema = z2.object({
702
- order: orderSchema
703
- });
704
- var listListingsForCollectibleArgsSchema = z2.object({
705
- contractAddress: z2.string(),
706
- tokenId: z2.string(),
707
- filter: orderFilterSchema.optional(),
708
- page: pageSchema.optional()
709
- });
710
- var listListingsForCollectibleReturnSchema = z2.object({
711
- listings: z2.array(orderSchema),
712
- page: pageSchema.optional()
713
- });
714
- var listOffersForCollectibleArgsSchema = z2.object({
715
- contractAddress: z2.string(),
716
- tokenId: z2.string(),
717
- filter: orderFilterSchema.optional(),
718
- page: pageSchema.optional()
719
- });
720
- var listOffersForCollectibleReturnSchema = z2.object({
721
- offers: z2.array(orderSchema),
722
- page: pageSchema.optional()
723
- });
724
- var getListCollectibleActivitiesArgsSchema = z2.object({
725
- chainId: z2.number(),
726
- collectionAddress: AddressSchema,
727
- tokenId: CollectableIdSchema.pipe(z2.coerce.string()),
728
- query: pageSchema.extend({
729
- enabled: z2.boolean().optional()
730
- }).optional()
731
- });
732
- var getListCollectibleActivitiesReturnSchema = z2.object({
733
- activities: z2.array(activitySchema),
734
- page: pageSchema.optional()
735
- });
736
- var getListCollectionActivitiesArgsSchema = z2.object({
737
- chainId: z2.number(),
738
- collectionAddress: AddressSchema,
739
- query: pageSchema.extend({
740
- enabled: z2.boolean().optional()
741
- }).optional()
742
- });
743
- var getListCollectionActivitiesReturnSchema = z2.object({
744
- activities: z2.array(activitySchema),
745
- page: pageSchema.optional()
746
- });
747
- var getCollectibleLowestOfferReturnSchema = z2.object({
748
- order: orderSchema.optional()
749
- });
750
- var getCollectibleHighestOfferReturnSchema = z2.object({
751
- order: orderSchema.optional()
752
- });
753
- var getCollectibleLowestListingReturnSchema = z2.object({
754
- order: orderSchema.optional()
755
- });
756
- var getCollectibleHighestListingReturnSchema = z2.object({
757
- order: orderSchema.optional()
758
- });
759
- var listCollectibleListingsArgsSchema = z2.object({
760
- contractAddress: z2.string(),
761
- tokenId: z2.string(),
762
- filter: orderFilterSchema.optional(),
763
- page: pageSchema.optional()
764
- });
765
- var listCollectibleListingsReturnSchema = z2.object({
766
- listings: z2.array(orderSchema),
767
- page: pageSchema.optional()
768
- });
769
- var listCollectibleOffersArgsSchema = z2.object({
770
- contractAddress: z2.string(),
771
- tokenId: z2.string(),
772
- filter: orderFilterSchema.optional(),
773
- page: pageSchema.optional()
774
- });
775
- var listCollectibleOffersReturnSchema = z2.object({
776
- offers: z2.array(orderSchema),
777
- page: pageSchema.optional()
778
- });
779
- var listCollectiblesArgsSchema = z2.object({
780
- side: orderSideSchema,
781
- contractAddress: z2.string(),
782
- filter: collectiblesFilterSchema.optional(),
783
- page: pageSchema.optional()
784
- });
785
- var listCollectiblesReturnSchema = z2.object({
786
- collectibles: z2.array(collectibleOrderSchema),
787
- page: pageSchema.optional()
788
- });
789
- var getFloorOrderReturnSchema = z2.object({
790
- collectible: collectibleOrderSchema
791
- });
792
- var listCollectiblesWithLowestListingArgsSchema = z2.object({
793
- contractAddress: z2.string(),
794
- filter: collectiblesFilterSchema.optional(),
795
- page: pageSchema.optional()
796
- });
797
- var listCollectiblesWithLowestListingReturnSchema = z2.object({
798
- collectibles: z2.array(collectibleOrderSchema),
799
- page: pageSchema.optional()
800
- });
801
- var listCollectiblesWithHighestOfferArgsSchema = z2.object({
802
- contractAddress: z2.string(),
803
- filter: collectiblesFilterSchema.optional(),
804
- page: pageSchema.optional()
805
- });
806
- var listCollectiblesWithHighestOfferReturnSchema = z2.object({
807
- collectibles: z2.array(collectibleOrderSchema),
808
- page: pageSchema.optional()
809
- });
810
- var syncOrderArgsSchema = z2.object({
811
- order: orderSchema
812
- });
813
- var syncOrdersArgsSchema = z2.object({
814
- orders: z2.array(orderSchema)
815
- });
816
- var getOrdersArgsSchema = z2.object({
817
- input: z2.array(getOrdersInputSchema),
818
- page: pageSchema.optional()
819
- });
820
- var getOrdersReturnSchema = z2.object({
821
- orders: z2.array(orderSchema),
822
- page: pageSchema.optional()
823
- });
824
- var collectionSchema = z2.object({
825
- status: collectionStatusSchema,
826
- chainId: z2.number(),
827
- contractAddress: z2.string(),
828
- contractType: contractTypeSchema,
829
- tokenQuantityDecimals: z2.number(),
830
- config: collectionConfigSchema,
831
- createdAt: z2.string(),
832
- updatedAt: z2.string(),
833
- deletedAt: z2.string().optional()
834
- });
835
- var stepSchema = z2.object({
836
- id: z2.nativeEnum(StepType),
837
- data: z2.string().optional(),
838
- to: z2.string().optional(),
839
- value: z2.string().optional(),
840
- price: z2.string().optional(),
841
- signature: signatureSchema.optional(),
842
- post: postRequestSchema.optional(),
843
- method: z2.string().optional(),
844
- endpoint: z2.string().optional()
845
- });
846
- var generateBuyTransactionReturnSchema = z2.object({
847
- steps: z2.array(stepSchema)
848
- });
849
- var generateSellTransactionReturnSchema = z2.object({
850
- steps: z2.array(stepSchema)
851
- });
852
- var generateListingTransactionReturnSchema = z2.object({
853
- steps: z2.array(stepSchema)
854
- });
855
- var generateOfferTransactionReturnSchema = z2.object({
856
- steps: z2.array(stepSchema)
857
- });
858
-
859
- // src/react/hooks/useCountOfCollectables.tsx
860
- var BaseSchema = z3.object({
861
- chainId: z3.number(),
862
- collectionAddress: AddressSchema,
863
- query: QueryArgSchema
864
- });
865
- var UseCountOfCollectableSchema = BaseSchema.extend({
866
- filter: collectiblesFilterSchema,
867
- side: z3.nativeEnum(OrderSide)
868
- }).or(
869
- BaseSchema.extend({
870
- filter: z3.undefined(),
871
- side: z3.undefined()
872
- })
873
- );
874
- var fetchCountOfCollectables = async (args, config) => {
875
- const parsedArgs = UseCountOfCollectableSchema.parse(args);
876
- const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
877
- if (parsedArgs.filter) {
878
- return marketplaceClient.getCountOfFilteredCollectibles({
879
- ...parsedArgs,
880
- contractAddress: parsedArgs.collectionAddress,
881
- // biome-ignore lint/style/noNonNullAssertion: safe to assert here, as it's validated
882
- side: parsedArgs.side
883
- }).then((resp) => resp.count);
884
- }
885
- return marketplaceClient.getCountOfAllCollectibles({
886
- ...parsedArgs,
887
- contractAddress: parsedArgs.collectionAddress
888
- }).then((resp) => resp.count);
889
- };
890
- var countOfCollectablesOptions = (args, config) => {
891
- return queryOptions2({
892
- ...args.query,
893
- queryKey: [...collectableKeys.counts, args],
894
- queryFn: () => fetchCountOfCollectables(args, config)
895
- });
896
- };
897
- var useCountOfCollectables = (args) => {
898
- const config = useConfig();
899
- return useQuery4(countOfCollectablesOptions(args, config));
900
- };
901
-
902
- // src/react/hooks/useCollectible.tsx
903
- import { queryOptions as queryOptions3, useQuery as useQuery5 } from "@tanstack/react-query";
904
- import { z as z4 } from "zod";
905
- var UseCollectibleSchema = z4.object({
906
- chainId: z4.number(),
907
- collectionAddress: AddressSchema,
908
- collectibleId: z4.string().optional(),
909
- query: QueryArgSchema
910
- });
911
- var fetchCollectible = async (args, config) => {
912
- const parsedArgs = UseCollectibleSchema.parse(args);
913
- const metadataClient = getMetadataClient(config);
914
- const tokenIds = parsedArgs.collectibleId ? [parsedArgs.collectibleId] : [];
915
- return metadataClient.getTokenMetadata({
916
- chainID: parsedArgs.chainId.toString(),
917
- contractAddress: parsedArgs.collectionAddress,
918
- tokenIDs: tokenIds
919
- }).then((resp) => resp.tokenMetadata[0]);
920
- };
921
- var collectibleOptions = (args, config) => {
922
- return queryOptions3({
923
- ...args.query,
924
- queryKey: [...collectableKeys.details, args, config],
925
- queryFn: () => fetchCollectible(args, config)
926
- });
927
- };
928
- var useCollectible = (args) => {
929
- const config = useConfig();
930
- return useQuery5(collectibleOptions(args, config));
931
- };
932
-
933
- // src/react/hooks/useCollection.tsx
934
- import { useQuery as useQuery6 } from "@tanstack/react-query";
935
- var useCollection = (args) => {
936
- const config = useConfig();
937
- return useQuery6(collectionOptions(args, config));
938
- };
939
-
940
- // src/react/hooks/useComparePrices.tsx
941
- import { queryOptions as queryOptions6, useQuery as useQuery9 } from "@tanstack/react-query";
942
- import { z as z7 } from "zod";
943
-
944
- // src/react/hooks/useConvertPriceToUSD.tsx
945
- import { queryOptions as queryOptions5, useQuery as useQuery8 } from "@tanstack/react-query";
946
- import { formatUnits } from "viem";
947
- import { z as z6 } from "zod";
948
-
949
- // src/react/hooks/useCurrencies.tsx
950
- import { queryOptions as queryOptions4, useQuery as useQuery7 } from "@tanstack/react-query";
951
- import { zeroAddress as zeroAddress2 } from "viem";
952
- import { z as z5 } from "zod";
953
- var UseCurrenciesArgsSchema = z5.object({
954
- chainId: z5.number(),
955
- includeNativeCurrency: z5.boolean().optional().default(true),
956
- collectionAddress: AddressSchema.optional(),
957
- query: QueryArgSchema
958
- });
959
- var fetchCurrencies = async (args, config) => {
960
- const parsedArgs = UseCurrenciesArgsSchema.parse(args);
961
- const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
962
- let currencies = await marketplaceClient.listCurrencies().then(
963
- (resp) => resp.currencies.map((currency) => ({
964
- ...currency,
965
- contractAddress: currency.contractAddress || zeroAddress2
966
- }))
967
- );
968
- if (parsedArgs.collectionAddress) {
969
- const queryClient = getQueryClient();
970
- const marketplaceConfig = await queryClient.fetchQuery(
971
- marketplaceConfigOptions(config)
972
- );
973
- const currenciesOptions2 = marketplaceConfig.collections.find(
974
- (collection) => collection.address === args.collectionAddress
975
- )?.currencyOptions;
976
- if (currenciesOptions2) {
977
- currencies = currencies.filter(
978
- (currency) => currenciesOptions2.includes(currency.contractAddress)
979
- );
980
- }
981
- }
982
- if (!parsedArgs.includeNativeCurrency) {
983
- currencies = currencies.filter((currency) => !currency.nativeCurrency);
984
- }
985
- return currencies;
986
- };
987
- var currenciesOptions = (args, config) => {
988
- return queryOptions4({
989
- ...args.query,
990
- queryKey: [...currencyKeys.lists, args],
991
- queryFn: () => fetchCurrencies(args, config),
992
- enabled: args.query?.enabled
993
- });
994
- };
995
- var useCurrencies = (args) => {
996
- const config = useConfig();
997
- return useQuery7(currenciesOptions(args, config));
998
- };
999
-
1000
- // src/react/hooks/useConvertPriceToUSD.tsx
1001
- var UseConvertPriceToUSDArgsSchema = z6.object({
1002
- chainId: z6.number(),
1003
- currencyAddress: AddressSchema,
1004
- amountRaw: z6.string(),
1005
- query: QueryArgSchema
1006
- });
1007
- var convertPriceToUSD = async (args, config) => {
1008
- const parsedArgs = UseConvertPriceToUSDArgsSchema.parse(args);
1009
- const queryClient = getQueryClient();
1010
- const currencies = await queryClient.fetchQuery(
1011
- currenciesOptions(
1012
- {
1013
- chainId: parsedArgs.chainId
1014
- },
1015
- config
1016
- )
1017
- );
1018
- const currencyDetails = currencies.find(
1019
- (c) => c.contractAddress.toLowerCase() === parsedArgs.currencyAddress.toLowerCase()
1020
- );
1021
- if (!currencyDetails) {
1022
- throw new Error("Currency not found");
1023
- }
1024
- const amountDecimal = Number(
1025
- formatUnits(BigInt(parsedArgs.amountRaw), currencyDetails.decimals)
1026
- );
1027
- const usdAmount = amountDecimal * currencyDetails.exchangeRate;
1028
- return {
1029
- usdAmount,
1030
- usdAmountFormatted: usdAmount.toFixed(2)
1031
- };
1032
- };
1033
- var convertPriceToUSDOptions = (args, config) => {
1034
- return queryOptions5({
1035
- ...args.query,
1036
- queryKey: [
1037
- ...currencyKeys.conversion,
1038
- args.chainId,
1039
- args.currencyAddress,
1040
- args.amountRaw
1041
- ],
1042
- queryFn: () => convertPriceToUSD(args, config)
1043
- });
1044
- };
1045
- var useConvertPriceToUSD = (args) => {
1046
- const config = useConfig();
1047
- return useQuery8(convertPriceToUSDOptions(args, config));
1048
- };
1049
-
1050
- // src/react/hooks/useComparePrices.tsx
1051
- var UseComparePricesArgsSchema = z7.object({
1052
- chainId: z7.number(),
1053
- // First price details
1054
- priceAmountRaw: z7.string(),
1055
- priceCurrencyAddress: AddressSchema,
1056
- // Second price details (to compare against)
1057
- compareToPriceAmountRaw: z7.string(),
1058
- compareToPriceCurrencyAddress: AddressSchema,
1059
- query: QueryArgSchema
1060
- });
1061
- var comparePrices = async (args, config) => {
1062
- const parsedArgs = UseComparePricesArgsSchema.parse(args);
1063
- const [priceUSD, compareToPriceUSD] = await Promise.all([
1064
- convertPriceToUSD(
1065
- {
1066
- chainId: parsedArgs.chainId,
1067
- currencyAddress: parsedArgs.priceCurrencyAddress,
1068
- amountRaw: parsedArgs.priceAmountRaw,
1069
- query: {}
1070
- },
1071
- config
1072
- ),
1073
- convertPriceToUSD(
1074
- {
1075
- chainId: parsedArgs.chainId,
1076
- currencyAddress: parsedArgs.compareToPriceCurrencyAddress,
1077
- amountRaw: parsedArgs.compareToPriceAmountRaw,
1078
- query: {}
1079
- },
1080
- config
1081
- )
1082
- ]);
1083
- const difference = priceUSD.usdAmount - compareToPriceUSD.usdAmount;
1084
- if (compareToPriceUSD.usdAmount === 0) {
1085
- throw new Error("Cannot compare to zero price");
1086
- }
1087
- const percentageDifference = difference / compareToPriceUSD.usdAmount * 100;
1088
- const isAbove = percentageDifference > 0;
1089
- const isSame = percentageDifference === 0;
1090
- return {
1091
- percentageDifference,
1092
- percentageDifferenceFormatted: Math.abs(percentageDifference).toFixed(2),
1093
- status: isAbove ? "above" : isSame ? "same" : "below"
1094
- };
1095
- };
1096
- var comparePricesOptions = (args, config) => {
1097
- return queryOptions6({
1098
- ...args.query,
1099
- queryKey: [...currencyKeys.conversion, "compare", args],
1100
- queryFn: () => comparePrices(args, config)
1101
- });
1102
- };
1103
- var useComparePrices = (args) => {
1104
- const config = useConfig();
1105
- return useQuery9(comparePricesOptions(args, config));
1106
- };
1107
-
1108
- // src/react/hooks/useCurrency.tsx
1109
- import { queryOptions as queryOptions7, skipToken, useQuery as useQuery10 } from "@tanstack/react-query";
1110
- import { z as z8 } from "zod";
1111
- var UseCurrencyArgsSchema = z8.object({
1112
- chainId: z8.number(),
1113
- currencyAddress: AddressSchema.optional(),
1114
- query: QueryArgSchema
1115
- });
1116
- var fetchCurrency = async (chainId, currencyAddress, config) => {
1117
- const queryClient = getQueryClient();
1118
- let currencies = queryClient.getQueryData([...currencyKeys.lists, chainId]);
1119
- if (!currencies) {
1120
- const marketplaceClient = getMarketplaceClient(chainId, config);
1121
- currencies = await marketplaceClient.listCurrencies().then((resp) => resp.currencies);
1122
- }
1123
- if (!currencies?.length) {
1124
- throw new Error("No currencies returned");
1125
- }
1126
- const currency = currencies.find(
1127
- (currency2) => currency2.contractAddress.toLowerCase() === currencyAddress.toLowerCase()
1128
- );
1129
- if (!currency) {
1130
- throw new Error("Currency not found");
1131
- }
1132
- return currency;
1133
- };
1134
- var currencyOptions = (args, config) => {
1135
- const { chainId, currencyAddress } = args;
1136
- return queryOptions7({
1137
- ...args.query,
1138
- queryKey: [...currencyKeys.details, args.chainId, args.currencyAddress],
1139
- queryFn: chainId && currencyAddress ? () => fetchCurrency(chainId, currencyAddress, config) : skipToken
1140
- });
1141
- };
1142
- var useCurrency = (args) => {
1143
- const config = useConfig();
1144
- return useQuery10(currencyOptions(args, config));
1145
- };
1146
-
1147
- // src/react/hooks/useFilters.tsx
1148
- import { queryOptions as queryOptions8, useQuery as useQuery11 } from "@tanstack/react-query";
1149
- import { z as z9 } from "zod";
1150
- var UseFiltersSchema = z9.object({
1151
- chainId: z9.number(),
1152
- collectionAddress: AddressSchema,
1153
- showAllFilters: z9.boolean().default(false).optional(),
1154
- query: QueryArgSchema,
1155
- excludePropertyValues: z9.boolean().default(false).optional()
1156
- });
1157
- var fetchFilters = async (args, config) => {
1158
- const parsedArgs = UseFiltersSchema.parse(args);
1159
- const metadataClient = getMetadataClient(config);
1160
- const filters = await metadataClient.getTokenMetadataPropertyFilters({
1161
- chainID: parsedArgs.chainId.toString(),
1162
- contractAddress: parsedArgs.collectionAddress,
1163
- excludeProperties: [],
1164
- // TODO: We can leverage this for some of the exclusion logic
1165
- excludePropertyValues: parsedArgs.excludePropertyValues
1166
- }).then((resp) => resp.filters);
1167
- if (args.showAllFilters) return filters;
1168
- const queryClient = getQueryClient();
1169
- const marketplaceConfig = await queryClient.fetchQuery(
1170
- marketplaceConfigOptions(config)
1171
- );
1172
- const collectionFilters = marketplaceConfig.collections.find(
1173
- (c) => compareAddress(c.address, parsedArgs.collectionAddress)
1174
- )?.filterSettings;
1175
- if (!collectionFilters?.exclusions || collectionFilters.exclusions.length === 0 || !collectionFilters.filterOrder || collectionFilters.filterOrder.length === 0)
1176
- return filters;
1177
- const { filterOrder, exclusions } = collectionFilters;
1178
- const sortedFilters = filters.toSorted((a, b) => {
1179
- const aIndex = filterOrder.indexOf(a.name) > -1 ? filterOrder.indexOf(a.name) : filterOrder.length;
1180
- const bIndex = filterOrder.indexOf(b.name) > -1 ? filterOrder.indexOf(b.name) : filterOrder.length;
1181
- return aIndex - bIndex;
1182
- });
1183
- const filteredResults = sortedFilters.reduce(
1184
- (acc, filter) => {
1185
- const exclusionRule = exclusions.find((rule) => rule.key === filter.name);
1186
- if (!exclusionRule) {
1187
- acc.push(filter);
1188
- return acc;
1189
- }
1190
- if (exclusionRule.condition === "ENTIRE_KEY" /* ENTIRE_KEY */) {
1191
- return acc;
1192
- }
1193
- if (exclusionRule.condition === "SPECIFIC_VALUE" /* SPECIFIC_VALUE */ && exclusionRule.value) {
1194
- const filteredValues = filter.values?.filter((value) => value !== exclusionRule.value) || [];
1195
- if (filteredValues.length > 0) {
1196
- acc.push({ ...filter, values: filteredValues });
1197
- }
1198
- }
1199
- return acc;
1200
- },
1201
- []
1202
- );
1203
- return filteredResults;
1204
- };
1205
- var filtersOptions = (args, config) => {
1206
- return queryOptions8({
1207
- ...args.query,
1208
- queryKey: [...collectableKeys.filter, args, config],
1209
- queryFn: () => fetchFilters(args, config)
1210
- });
1211
- };
1212
- var useFilters = (args) => {
1213
- const config = useConfig();
1214
- return useQuery11(filtersOptions(args, config));
1215
- };
1216
- var useFiltersProgressive = (args) => {
1217
- const config = useConfig();
1218
- const namesQuery = useQuery11(
1219
- filtersOptions({ ...args, excludePropertyValues: true }, config)
1220
- );
1221
- const fullQuery = useQuery11({
1222
- ...filtersOptions(args, config),
1223
- placeholderData: namesQuery.data
1224
- });
1225
- const isLoadingNames = namesQuery.isLoading;
1226
- const isFetchingValues = fullQuery.isPlaceholderData && fullQuery.isFetching;
1227
- return {
1228
- ...fullQuery,
1229
- isFetchingValues,
1230
- isLoadingNames
1231
- };
1232
- };
1233
-
1234
- // src/react/hooks/useFilterState.tsx
1235
- import { useMemo } from "react";
1236
- import {
1237
- createSerializer,
1238
- parseAsBoolean,
1239
- parseAsJson,
1240
- parseAsString,
1241
- useQueryState
1242
- } from "nuqs";
1243
- var validateFilters = (value) => {
1244
- if (!Array.isArray(value)) return [];
1245
- return value.filter(
1246
- (f) => typeof f === "object" && typeof f.name === "string" && Object.values(PropertyType).includes(f.type)
1247
- );
1248
- };
1249
- var filtersParser = parseAsJson(validateFilters).withDefault([]);
1250
- var searchParser = parseAsString.withDefault("");
1251
- var listedOnlyParser = parseAsBoolean.withDefault(false);
1252
- var serialize = createSerializer(
1253
- {
1254
- filters: filtersParser,
1255
- search: searchParser,
1256
- listedOnly: listedOnlyParser
1257
- },
1258
- {
1259
- urlKeys: {
1260
- filters: "f",
1261
- search: "q",
1262
- listedOnly: "l"
1263
- }
1264
- }
1265
- );
1266
- function useFilterState() {
1267
- const [filterOptions, setFilterOptions] = useQueryState(
1268
- "filters",
1269
- filtersParser
1270
- );
1271
- const [searchText, setSearchText] = useQueryState("search", searchParser);
1272
- const [showListedOnly, setShowListedOnly] = useQueryState(
1273
- "listedOnly",
1274
- listedOnlyParser
1275
- );
1276
- const helpers = useMemo(
1277
- () => ({
1278
- getFilter: (name) => {
1279
- return filterOptions?.find((f) => f.name === name);
1280
- },
1281
- getFilterValues: (name) => {
1282
- const filter = filterOptions?.find((f) => f.name === name);
1283
- if (!filter) return void 0;
1284
- if (filter.type === "INT" /* INT */) {
1285
- return {
1286
- type: "INT" /* INT */,
1287
- min: filter.min ?? 0,
1288
- max: filter.max ?? 0
1289
- };
1290
- }
1291
- return {
1292
- type: "STRING" /* STRING */,
1293
- values: filter.values ?? []
1294
- };
1295
- },
1296
- isFilterActive: (name) => {
1297
- return !!filterOptions?.find((f) => f.name === name);
1298
- },
1299
- isStringValueSelected: (name, value) => {
1300
- const filter = filterOptions?.find((f) => f.name === name);
1301
- if (!filter || filter.type !== "STRING" /* STRING */) return false;
1302
- return filter.values?.includes(value) ?? false;
1303
- },
1304
- isIntFilterActive: (name) => {
1305
- const filter = filterOptions?.find((f) => f.name === name);
1306
- return !!filter && filter.type === "INT" /* INT */;
1307
- },
1308
- getIntFilterRange: (name) => {
1309
- const filter = filterOptions?.find((f) => f.name === name);
1310
- if (!filter || filter.type !== "INT" /* INT */) return void 0;
1311
- return [filter.min ?? 0, filter.max ?? 0];
1312
- },
1313
- deleteFilter: (name) => {
1314
- const otherFilters = filterOptions?.filter((f) => !(f.name === name)) ?? [];
1315
- setFilterOptions(otherFilters);
1316
- },
1317
- toggleStringFilterValue: (name, value) => {
1318
- const otherFilters = filterOptions?.filter((f) => !(f.name === name)) ?? [];
1319
- const filter = filterOptions?.find((f) => f.name === name);
1320
- const existingValues = filter?.type === "STRING" /* STRING */ ? filter.values ?? [] : [];
1321
- if (existingValues.includes(value)) {
1322
- const newValues = existingValues.filter((v) => v !== value);
1323
- if (newValues.length === 0) {
1324
- setFilterOptions(otherFilters);
1325
- return;
1326
- }
1327
- setFilterOptions([
1328
- ...otherFilters,
1329
- { name, type: "STRING" /* STRING */, values: newValues }
1330
- ]);
1331
- } else {
1332
- setFilterOptions([
1333
- ...otherFilters,
1334
- {
1335
- name,
1336
- type: "STRING" /* STRING */,
1337
- values: [...existingValues, value]
1338
- }
1339
- ]);
1340
- }
1341
- },
1342
- setIntFilterValue: (name, min, max) => {
1343
- if (min === max && min === 0) {
1344
- const otherFilters2 = filterOptions?.filter((f) => !(f.name === name)) ?? [];
1345
- setFilterOptions(otherFilters2);
1346
- return;
1347
- }
1348
- const otherFilters = filterOptions?.filter((f) => !(f.name === name)) ?? [];
1349
- setFilterOptions([
1350
- ...otherFilters,
1351
- { name, type: "INT" /* INT */, min, max }
1352
- ]);
1353
- },
1354
- clearAllFilters: () => {
1355
- void setShowListedOnly(false);
1356
- void setFilterOptions([]);
1357
- void setSearchText("");
1358
- }
1359
- }),
1360
- [filterOptions, setFilterOptions, setShowListedOnly, setSearchText]
1361
- );
1362
- return {
1363
- filterOptions,
1364
- searchText,
1365
- showListedOnly,
1366
- setFilterOptions,
1367
- setSearchText,
1368
- setShowListedOnly,
1369
- ...helpers,
1370
- serialize
1371
- };
1372
- }
1373
-
1374
- // src/react/hooks/useFloorOrder.tsx
1375
- import { queryOptions as queryOptions9, useQuery as useQuery12 } from "@tanstack/react-query";
1376
- import { z as z10 } from "zod";
1377
- var UseFloorOrderSchema = z10.object({
1378
- chainId: z10.number(),
1379
- collectionAddress: AddressSchema,
1380
- query: QueryArgSchema
1381
- });
1382
- var fetchFloorOrder = async (args, config) => {
1383
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
1384
- return marketplaceClient.getFloorOrder({ contractAddress: args.collectionAddress }).then((data) => data.collectible);
1385
- };
1386
- var floorOrderOptions = (args, config) => {
1387
- return queryOptions9({
1388
- queryKey: [...collectableKeys.floorOrders, args, config],
1389
- queryFn: () => fetchFloorOrder(args, config)
1390
- });
1391
- };
1392
- var useFloorOrder = (args) => {
1393
- const config = useConfig();
1394
- return useQuery12(floorOrderOptions(args, config));
1395
- };
1396
-
1397
- // src/react/hooks/useHighestOffer.tsx
1398
- import { useQuery as useQuery13 } from "@tanstack/react-query";
1399
- function useHighestOffer(args) {
1400
- const config = useConfig();
1401
- return useQuery13(highestOfferOptions(args, config));
1402
- }
1403
-
1404
- // src/react/hooks/useInventory.tsx
1405
- import { useInfiniteQuery } from "@tanstack/react-query";
1406
- function useInventory(args) {
1407
- const config = useConfig();
1408
- const marketplaceConfig = useMarketplaceConfig();
1409
- const isLaos721 = marketplaceConfig.data?.collections.find(
1410
- (c) => c.address === args.collectionAddress
1411
- )?.isLAOSERC721 ?? false;
1412
- return useInfiniteQuery(inventoryOptions({ ...args, isLaos721 }, config));
1413
- }
1414
-
1415
- // src/react/hooks/useListBalances.tsx
1416
- import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
1417
- function useListBalances(args) {
1418
- const config = useConfig();
1419
- const { data: marketplaceConfig } = useMarketplaceConfig();
1420
- const isLaos721 = marketplaceConfig?.collections.find(
1421
- (collection) => collection.address === args.contractAddress
1422
- )?.isLAOSERC721;
1423
- if (isLaos721) {
1424
- args.isLaos721 = true;
1425
- }
1426
- return useInfiniteQuery2(listBalancesOptions(args, config));
1427
- }
1428
-
1429
- // src/react/hooks/useListCollectibleActivities.tsx
1430
- import { queryOptions as queryOptions10, useQuery as useQuery14 } from "@tanstack/react-query";
1431
- var fetchCollectibleActivities = async (args, config) => {
1432
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
1433
- return marketplaceClient.listCollectibleActivities({
1434
- contractAddress: args.collectionAddress,
1435
- tokenId: args.tokenId,
1436
- page: args.query?.enabled ? {
1437
- page: args.query.page ?? 1,
1438
- pageSize: args.query.pageSize ?? 10,
1439
- sort: args.query.sort
1440
- } : void 0
1441
- }).then((data) => ({
1442
- activities: data.activities,
1443
- page: data.page
1444
- }));
1445
- };
1446
- var listCollectibleActivitiesOptions = (args, config) => {
1447
- return queryOptions10({
1448
- queryKey: [...collectableKeys.collectibleActivities, args, config],
1449
- queryFn: () => fetchCollectibleActivities(args, config),
1450
- enabled: args.query?.enabled ?? true
1451
- });
1452
- };
1453
- var useListCollectibleActivities = (args) => {
1454
- const config = useConfig();
1455
- return useQuery14(listCollectibleActivitiesOptions(args, config));
1456
- };
1457
-
1458
- // src/react/hooks/useListCollectibles.tsx
1459
- import { useInfiniteQuery as useInfiniteQuery3 } from "@tanstack/react-query";
1460
- function useListCollectibles(args) {
1461
- const config = useConfig();
1462
- const { data: marketplaceConfig } = useMarketplaceConfig();
1463
- const isLaos721 = marketplaceConfig?.collections.find(
1464
- (collection) => collection.address === args.collectionAddress
1465
- )?.isLAOSERC721;
1466
- if (isLaos721) {
1467
- args.isLaos721 = true;
1468
- }
1469
- return useInfiniteQuery3(listCollectiblesOptions(args, config));
1470
- }
1471
-
1472
- // src/react/hooks/useListCollectiblesPaginated.tsx
1473
- import { queryOptions as queryOptions11, useQuery as useQuery15 } from "@tanstack/react-query";
1474
- import { z as z11 } from "zod";
1475
- var UseListCollectiblesPaginatedArgsSchema = listCollectiblesArgsSchema.omit({
1476
- contractAddress: true
1477
- }).extend({
1478
- collectionAddress: AddressSchema,
1479
- chainId: z11.number(),
1480
- query: z11.object({
1481
- enabled: z11.boolean().optional(),
1482
- page: z11.number().optional().default(1),
1483
- pageSize: z11.number().optional().default(30)
1484
- }).optional().default({})
1485
- });
1486
- var fetchCollectiblesPaginated = async (args, marketplaceClient) => {
1487
- const parsedArgs = UseListCollectiblesPaginatedArgsSchema.parse(args);
1488
- const page = {
1489
- page: parsedArgs.query?.page ?? 1,
1490
- pageSize: parsedArgs.query?.pageSize ?? 30
1491
- };
1492
- const arg = {
1493
- ...parsedArgs,
1494
- contractAddress: parsedArgs.collectionAddress,
1495
- page
1496
- };
1497
- return marketplaceClient.listCollectibles(arg);
1498
- };
1499
- var listCollectiblesPaginatedOptions = (args, config) => {
1500
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
1501
- return queryOptions11({
1502
- queryKey: [...collectableKeys.lists, "paginated", args],
1503
- queryFn: () => fetchCollectiblesPaginated(args, marketplaceClient),
1504
- enabled: args.query?.enabled ?? true
1505
- });
1506
- };
1507
- var useListCollectiblesPaginated = (args) => {
1508
- const config = useConfig();
1509
- return useQuery15(listCollectiblesPaginatedOptions(args, config));
1510
- };
1511
-
1512
- // src/react/hooks/useListCollectionActivities.tsx
1513
- import { queryOptions as queryOptions12, useQuery as useQuery16 } from "@tanstack/react-query";
1514
- var fetchListCollectionActivities = async (args, config) => {
1515
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
1516
- return marketplaceClient.listCollectionActivities({
1517
- contractAddress: args.collectionAddress,
1518
- page: args.query?.enabled ? {
1519
- page: args.query.page ?? 1,
1520
- pageSize: args.query.pageSize ?? 10,
1521
- sort: args.query.sort
1522
- } : void 0
1523
- }).then((data) => ({
1524
- activities: data.activities,
1525
- page: data.page
1526
- }));
1527
- };
1528
- var listCollectionActivitiesOptions = (args, config) => {
1529
- return queryOptions12({
1530
- queryKey: [...collectionKeys.collectionActivities, args, config],
1531
- queryFn: () => fetchListCollectionActivities(args, config),
1532
- enabled: args.query?.enabled ?? true
1533
- });
1534
- };
1535
- var useListCollectionActivities = (args) => {
1536
- const config = useConfig();
1537
- return useQuery16(listCollectionActivitiesOptions(args, config));
1538
- };
1539
-
1540
- // src/react/hooks/useListOffersForCollectible.tsx
1541
- import { queryOptions as queryOptions13, useQuery as useQuery17 } from "@tanstack/react-query";
1542
- import { z as z12 } from "zod";
1543
- var UseListOffersForCollectibleArgsSchema = listOffersForCollectibleArgsSchema.extend({
1544
- chainId: z12.number(),
1545
- collectionAddress: z12.string(),
1546
- collectibleId: z12.string()
1547
- }).omit({ contractAddress: true, tokenId: true });
1548
- var fetchListOffersForCollectible = async (config, args) => {
1549
- const arg = {
1550
- contractAddress: args.collectionAddress,
1551
- tokenId: args.collectibleId,
1552
- filter: args.filter,
1553
- page: args.page
1554
- };
1555
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
1556
- return marketplaceClient.listCollectibleOffers(arg);
1557
- };
1558
- var listOffersForCollectibleOptions = (args, config) => {
1559
- return queryOptions13({
1560
- queryKey: [...collectableKeys.offers, args, config],
1561
- queryFn: () => fetchListOffersForCollectible(config, args)
1562
- });
1563
- };
1564
- var useListOffersForCollectible = (args) => {
1565
- const config = useConfig();
1566
- return useQuery17(listOffersForCollectibleOptions(args, config));
1567
- };
1568
-
1569
- // src/react/hooks/useCountOffersForCollectible.tsx
1570
- import { queryOptions as queryOptions14, useQuery as useQuery18 } from "@tanstack/react-query";
1571
- import { z as z13 } from "zod";
1572
- var UseCountOffersForCollectibleArgsSchema = countOffersForCollectibleArgsSchema.omit({
1573
- contractAddress: true,
1574
- tokenId: true
1575
- }).extend({
1576
- collectionAddress: AddressSchema,
1577
- collectibleId: z13.string(),
1578
- chainId: z13.number(),
1579
- query: QueryArgSchema
1580
- });
1581
- var fetchCountOffersForCollectible = async (args, config) => {
1582
- const parsedArgs = UseCountOffersForCollectibleArgsSchema.parse(args);
1583
- const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
1584
- return marketplaceClient.getCountOfOffersForCollectible({
1585
- ...parsedArgs,
1586
- contractAddress: parsedArgs.collectionAddress,
1587
- tokenId: parsedArgs.collectibleId
1588
- });
1589
- };
1590
- var countOffersForCollectibleOptions = (args, config) => {
1591
- return queryOptions14({
1592
- ...args.query,
1593
- queryKey: [...collectableKeys.offersCount, args, config],
1594
- queryFn: () => fetchCountOffersForCollectible(args, config)
1595
- });
1596
- };
1597
- var useCountOffersForCollectible = (args) => {
1598
- const config = useConfig();
1599
- return useQuery18(countOffersForCollectibleOptions(args, config));
1600
- };
1601
-
1602
- // src/react/hooks/useListListingsForCollectible.tsx
1603
- import { queryOptions as queryOptions15, useQuery as useQuery19 } from "@tanstack/react-query";
1604
- import { z as z14 } from "zod";
1605
- var UseListListingsForCollectibleArgsSchema = listListingsForCollectibleArgsSchema.extend({
1606
- chainId: z14.number(),
1607
- collectionAddress: z14.string(),
1608
- collectibleId: z14.string()
1609
- }).omit({ contractAddress: true, tokenId: true });
1610
- var fetchListListingsForCollectible = async (config, args) => {
1611
- const arg = {
1612
- contractAddress: args.collectionAddress,
1613
- tokenId: args.collectibleId,
1614
- filter: args.filter,
1615
- page: args.page
1616
- };
1617
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
1618
- return marketplaceClient.listCollectibleListings(arg);
1619
- };
1620
- var listListingsForCollectibleOptions = (args, config) => {
1621
- return queryOptions15({
1622
- queryKey: [...collectableKeys.listings, args, config],
1623
- queryFn: () => fetchListListingsForCollectible(config, args)
1624
- });
1625
- };
1626
- var useListListingsForCollectible = (args) => {
1627
- const config = useConfig();
1628
- return useQuery19(listListingsForCollectibleOptions(args, config));
1629
- };
1630
-
1631
- // src/react/hooks/useCountListingsForCollectible.tsx
1632
- import { queryOptions as queryOptions16, useQuery as useQuery20 } from "@tanstack/react-query";
1633
- import { z as z15 } from "zod";
1634
- var UseCountListingsForCollectibleArgsSchema = countListingsForCollectibleArgsSchema.omit({
1635
- contractAddress: true,
1636
- tokenId: true
1637
- }).extend({
1638
- collectionAddress: AddressSchema,
1639
- collectibleId: z15.string(),
1640
- chainId: z15.number(),
1641
- query: QueryArgSchema
1642
- });
1643
- var fetchCountListingsForCollectible = async (args, config) => {
1644
- const parsedArgs = UseCountListingsForCollectibleArgsSchema.parse(args);
1645
- const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
1646
- return marketplaceClient.getCountOfListingsForCollectible({
1647
- ...parsedArgs,
1648
- contractAddress: parsedArgs.collectionAddress,
1649
- tokenId: parsedArgs.collectibleId
1650
- });
1651
- };
1652
- var countListingsForCollectibleOptions = (args, config) => {
1653
- return queryOptions16({
1654
- ...args.query,
1655
- queryKey: [...collectableKeys.listingsCount, args, config],
1656
- queryFn: () => fetchCountListingsForCollectible(args, config)
1657
- });
1658
- };
1659
- var useCountListingsForCollectible = (args) => {
1660
- const config = useConfig();
1661
- return useQuery20(countListingsForCollectibleOptions(args, config));
1662
- };
1663
-
1664
- // src/react/hooks/useLowestListing.tsx
1665
- import { useQuery as useQuery21 } from "@tanstack/react-query";
1666
- function useLowestListing(args) {
1667
- const config = useConfig();
1668
- return useQuery21(lowestListingOptions(args, config));
1669
- }
1670
-
1671
- // src/react/hooks/useRoyalty.tsx
1672
- import { useReadContract } from "wagmi";
1673
- import { z as z16 } from "zod";
1674
- var UseRoyaltySchema = z16.object({
1675
- chainId: z16.number(),
1676
- collectionAddress: AddressSchema,
1677
- collectibleId: z16.string(),
1678
- query: QueryArgSchema.optional()
1679
- });
1680
- var useRoyalty = (args) => {
1681
- const { chainId, collectionAddress, collectibleId, query } = args;
1682
- const scopeKey = `${collectableKeys.royaltyPercentage.join(".")}-${chainId}-${collectionAddress}-${collectibleId}`;
1683
- const contractResult = useReadContract({
1684
- scopeKey,
1685
- abi: EIP2981_ABI,
1686
- address: collectionAddress,
1687
- functionName: "royaltyInfo",
1688
- args: [BigInt(collectibleId), BigInt(100)],
1689
- chainId,
1690
- query
1691
- });
1692
- const [recipient, percentage] = contractResult.data ?? [];
1693
- const formattedData = recipient && percentage ? {
1694
- percentage,
1695
- recipient
1696
- } : null;
1697
- return {
1698
- ...contractResult,
1699
- data: formattedData
1700
- };
1701
- };
1702
-
1703
- // src/react/hooks/useGenerateListingTransaction.tsx
1704
- import { useMutation } from "@tanstack/react-query";
1705
-
1706
- // src/utils/date.ts
1707
- var dateToUnixTime = (date) => Math.floor(date.getTime() / 1e3).toString();
1708
-
1709
- // src/react/hooks/useGenerateListingTransaction.tsx
1710
- var generateListingTransaction = async (params, config, chainId) => {
1711
- const args = {
1712
- ...params,
1713
- listing: {
1714
- ...params.listing,
1715
- expiry: dateToUnixTime(params.listing.expiry)
1716
- }
1717
- };
1718
- const marketplaceClient = getMarketplaceClient(chainId, config);
1719
- return (await marketplaceClient.generateListingTransaction(args)).steps;
1720
- };
1721
- var useGenerateListingTransaction = (params) => {
1722
- const config = useConfig();
1723
- const { mutate, mutateAsync, ...result } = useMutation({
1724
- onSuccess: params.onSuccess,
1725
- mutationFn: (args) => generateListingTransaction(args, config, params.chainId)
1726
- });
1727
- return {
1728
- ...result,
1729
- generateListingTransaction: mutate,
1730
- generateListingTransactionAsync: mutateAsync
1731
- };
1732
- };
1733
-
1734
- // src/react/hooks/useGenerateOfferTransaction.tsx
1735
- import { useMutation as useMutation2 } from "@tanstack/react-query";
1736
-
1737
- // src/react/_internal/wallet/useWallet.ts
1738
- import { skipToken as skipToken2, useQuery as useQuery22 } from "@tanstack/react-query";
1739
- import {
1740
- useAccount as useAccount2,
1741
- useChainId,
1742
- usePublicClient,
1743
- useSwitchChain,
1744
- useWalletClient
1745
- } from "wagmi";
1746
-
1747
- // src/react/_internal/wallet/wallet.ts
1748
- import {
1749
- BaseError as BaseError2,
1750
- TransactionReceiptNotFoundError,
1751
- UserRejectedRequestError as ViemUserRejectedRequestError,
1752
- WaitForTransactionReceiptTimeoutError,
1753
- custom,
1754
- erc20Abi,
1755
- erc721Abi,
1756
- hexToBigInt,
1757
- isHex
1758
- } from "viem";
1759
-
1760
- // src/react/_internal/logger.ts
1761
- var TransactionLogger = class {
1762
- constructor(context, enabled = true) {
1763
- this.context = context;
1764
- this.enabled = enabled;
1765
- }
1766
- formatData(data) {
1767
- if (data instanceof Error) {
1768
- return {
1769
- name: data.name,
1770
- message: data.message,
1771
- cause: data.cause instanceof Error ? this.formatData(data.cause) : data.cause,
1772
- stack: data.stack?.split("\n").slice(0, 3)
1773
- };
1774
- }
1775
- if (Array.isArray(data)) {
1776
- return data.map((item) => this.formatData(item));
1777
- }
1778
- if (typeof data === "object" && data !== null) {
1779
- return Object.fromEntries(
1780
- Object.entries(data).map(([key, value]) => [
1781
- key,
1782
- this.formatData(value)
1783
- ])
1784
- );
1785
- }
1786
- return data;
1787
- }
1788
- log(level, message, data) {
1789
- if (!this.enabled) return;
1790
- console[level](
1791
- `[${this.context}] ${message}`,
1792
- data ? this.formatData(data) : ""
1793
- );
1794
- }
1795
- debug(message, data) {
1796
- this.log("debug", message, data);
1797
- }
1798
- error(message, error) {
1799
- this.log("error", message, error);
1800
- }
1801
- info(message, data) {
1802
- this.log("info", message, data);
1803
- }
1804
- state(from, to) {
1805
- this.info(`State transition: ${from} -> ${to}`);
1806
- }
1807
- };
1808
- var createLogger = (context, enabled = true) => new TransactionLogger(context, enabled);
1809
-
1810
- // src/react/_internal/wallet/wallet.ts
1811
- var isSequenceWallet = (connector) => connector.id === "sequence" || connector.id === "sequence-waas";
1812
- var wallet = ({
1813
- wallet: wallet2,
1814
- chains,
1815
- connector,
1816
- sdkConfig,
1817
- publicClient
1818
- }) => {
1819
- const logger = createLogger("Wallet");
1820
- const walletInstance = {
1821
- transport: custom(wallet2.transport),
1822
- isWaaS: connector.id.endsWith("waas"),
1823
- walletKind: isSequenceWallet(connector) ? "sequence" /* sequence */ : "unknown" /* unknown */,
1824
- getChainId: wallet2.getChainId,
1825
- address: async () => {
1826
- let address = wallet2.account?.address;
1827
- if (!address) {
1828
- [address] = await wallet2.getAddresses();
1829
- }
1830
- return address;
1831
- },
1832
- switchChain: async (chainId) => {
1833
- logger.debug("Switching chain", { targetChainId: chainId });
1834
- try {
1835
- await wallet2.switchChain({
1836
- id: chainId
1837
- });
1838
- logger.info("Chain switch successful", { chainId });
1839
- return;
1840
- } catch (e) {
1841
- const error = e;
1842
- logger.error("Chain switch failed", error);
1843
- switch (error.name) {
1844
- case "SwitchChainNotSupportedError":
1845
- throw new ChainSwitchError(await wallet2.getChainId(), chainId);
1846
- case "UserRejectedRequestError":
1847
- throw new UserRejectedRequestError();
1848
- case "ChainNotConfiguredError":
1849
- return;
1850
- default:
1851
- throw new ChainSwitchError(await wallet2.getChainId(), chainId);
1852
- }
1853
- }
1854
- },
1855
- handleSignMessageStep: async (stepItem) => {
1856
- try {
1857
- if (stepItem.id === "signEIP191" /* signEIP191 */) {
1858
- logger.debug("Signing with EIP-191", { data: stepItem.data });
1859
- const message = isHex(stepItem.data) ? { raw: stepItem.data } : stepItem.data;
1860
- return await wallet2.signMessage({
1861
- account: wallet2.account,
1862
- message
1863
- });
1864
- } else if (stepItem.id === "signEIP712" /* signEIP712 */) {
1865
- logger.debug("Signing with EIP-712", {
1866
- domain: stepItem.domain,
1867
- types: stepItem.signature?.types
1868
- });
1869
- return await wallet2.signTypedData({
1870
- account: wallet2.account,
1871
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
1872
- domain: stepItem.signature.domain,
1873
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
1874
- types: stepItem.signature.types,
1875
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
1876
- primaryType: stepItem.signature.primaryType,
1877
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
1878
- message: stepItem.signature.value
1879
- });
1880
- }
1881
- } catch (e) {
1882
- const error = e;
1883
- logger.error("Signature failed", error);
1884
- if (error.cause instanceof BaseError2) {
1885
- const viemError = error.cause;
1886
- if (viemError instanceof ViemUserRejectedRequestError) {
1887
- throw new UserRejectedRequestError();
1888
- }
1889
- }
1890
- throw new TransactionSignatureError(stepItem.id, error);
1891
- }
1892
- },
1893
- handleSendTransactionStep: async (chainId, stepItem) => {
1894
- logger.debug("Sending transaction", {
1895
- chainId,
1896
- to: stepItem.to,
1897
- value: stepItem.value
1898
- });
1899
- const chain = chains.find((chain2) => chain2.id === chainId);
1900
- try {
1901
- return await wallet2.sendTransaction({
1902
- chain,
1903
- data: stepItem.data,
1904
- account: wallet2.account,
1905
- to: stepItem.to,
1906
- value: hexToBigInt(stepItem.value || "0x0"),
1907
- ...stepItem.maxFeePerGas && {
1908
- maxFeePerGas: hexToBigInt(stepItem.maxFeePerGas)
1909
- },
1910
- ...stepItem.maxPriorityFeePerGas && {
1911
- maxPriorityFeePerGas: hexToBigInt(stepItem.maxPriorityFeePerGas)
1912
- },
1913
- ...stepItem.gas && {
1914
- gas: hexToBigInt(stepItem.gas)
1915
- }
1916
- });
1917
- } catch (e) {
1918
- const error = e;
1919
- logger.error("Transaction failed", error);
1920
- if (error.cause instanceof BaseError2) {
1921
- const viemError = error.cause;
1922
- if (viemError instanceof ViemUserRejectedRequestError) {
1923
- throw new UserRejectedRequestError();
1924
- }
1925
- }
1926
- throw new TransactionExecutionError(stepItem.id, error);
1927
- }
1928
- },
1929
- handleConfirmTransactionStep: async (txHash, chainId) => {
1930
- logger.debug("Confirming transaction", { txHash, chainId });
1931
- try {
1932
- const receipt = await awaitTransactionReceipt({
1933
- txHash,
1934
- chainId,
1935
- sdkConfig
1936
- });
1937
- logger.info("Transaction confirmed", { txHash, receipt });
1938
- return receipt;
1939
- } catch (error) {
1940
- logger.error("Transaction confirmation failed", error);
1941
- throw new TransactionConfirmationError(txHash, error);
1942
- }
1943
- },
1944
- hasTokenApproval: async ({
1945
- tokenType,
1946
- contractAddress,
1947
- spender
1948
- }) => {
1949
- const walletAddress = await walletInstance.address();
1950
- const spenderAddress = spender === "sequenceMarketV1" ? SEQUENCE_MARKET_V1_ADDRESS : spender === "sequenceMarketV2" ? SEQUENCE_MARKET_V2_ADDRESS : spender;
1951
- switch (tokenType) {
1952
- case "ERC20":
1953
- return await publicClient.readContract({
1954
- address: contractAddress,
1955
- abi: erc20Abi,
1956
- functionName: "allowance",
1957
- args: [walletAddress, spenderAddress]
1958
- });
1959
- case "ERC721":
1960
- return await publicClient.readContract({
1961
- address: contractAddress,
1962
- abi: erc721Abi,
1963
- functionName: "isApprovedForAll",
1964
- args: [walletAddress, spenderAddress]
1965
- });
1966
- case "ERC1155":
1967
- return await publicClient.readContract({
1968
- address: contractAddress,
1969
- abi: ERC1155_ABI,
1970
- functionName: "isApprovedForAll",
1971
- args: [walletAddress, spenderAddress]
1972
- });
1973
- default:
1974
- throw new Error("Unsupported contract type for approval checking");
1975
- }
1976
- },
1977
- publicClient
1978
- };
1979
- return walletInstance;
1980
- };
1981
- var ONE_MIN = 60 * 1e3;
1982
- var THREE_MIN = 3 * ONE_MIN;
1983
- var awaitTransactionReceipt = async ({
1984
- txHash,
1985
- chainId,
1986
- sdkConfig,
1987
- timeout = THREE_MIN
1988
- }) => {
1989
- const indexer = getIndexerClient(chainId, sdkConfig);
1990
- return Promise.race([
1991
- new Promise((resolve, reject) => {
1992
- indexer.subscribeReceipts(
1993
- {
1994
- filter: {
1995
- txnHash: txHash
1996
- }
1997
- },
1998
- {
1999
- onMessage: ({ receipt }) => {
2000
- resolve(receipt);
2001
- },
2002
- onError: () => {
2003
- reject(TransactionReceiptNotFoundError);
2004
- }
2005
- }
2006
- );
2007
- }),
2008
- new Promise((_, reject) => {
2009
- setTimeout(() => {
2010
- reject(WaitForTransactionReceiptTimeoutError);
2011
- }, timeout);
2012
- })
2013
- ]);
2014
- };
2015
-
2016
- // src/react/_internal/wallet/useWallet.ts
2017
- var useWallet = () => {
2018
- const { chains } = useSwitchChain();
2019
- const {
2020
- data: walletClient,
2021
- isLoading: wagmiWalletIsLoading,
2022
- isError: wagmiWalletIsError
2023
- } = useWalletClient();
2024
- const { connector, isConnected, isConnecting } = useAccount2();
2025
- const sdkConfig = useConfig();
2026
- const chainId = useChainId();
2027
- const publicClient = usePublicClient();
2028
- const { data, isLoading, isError } = useQuery22({
2029
- queryKey: ["wallet", chainId, connector?.uid],
2030
- queryFn: walletClient && connector && isConnected && publicClient ? () => {
2031
- return wallet({
2032
- wallet: walletClient,
2033
- chains,
2034
- connector,
2035
- sdkConfig,
2036
- publicClient
2037
- });
2038
- } : skipToken2,
2039
- staleTime: Number.POSITIVE_INFINITY
2040
- });
2041
- return {
2042
- wallet: data,
2043
- isLoading: isLoading || isConnecting || wagmiWalletIsLoading,
2044
- isError: isError || wagmiWalletIsError
2045
- };
2046
- };
2047
-
2048
- // src/react/hooks/useGenerateOfferTransaction.tsx
2049
- var generateOfferTransaction = async (params, config, chainId, walletKind) => {
2050
- const args = {
2051
- ...params,
2052
- offer: { ...params.offer, expiry: dateToUnixTime(params.offer.expiry) },
2053
- walletType: walletKind
2054
- };
2055
- const marketplaceClient = getMarketplaceClient(chainId, config);
2056
- return (await marketplaceClient.generateOfferTransaction(args)).steps;
2057
- };
2058
- var useGenerateOfferTransaction = (params) => {
2059
- const config = useConfig();
2060
- const { wallet: wallet2 } = useWallet();
2061
- const { mutate, mutateAsync, ...result } = useMutation2({
2062
- onSuccess: params.onSuccess,
2063
- mutationFn: (args) => generateOfferTransaction(
2064
- args,
2065
- config,
2066
- params.chainId,
2067
- wallet2?.walletKind
2068
- )
2069
- });
2070
- return {
2071
- ...result,
2072
- generateOfferTransaction: mutate,
2073
- generateOfferTransactionAsync: mutateAsync
2074
- };
2075
- };
2076
-
2077
- // src/react/hooks/useGenerateSellTransaction.tsx
2078
- import { useMutation as useMutation3 } from "@tanstack/react-query";
2079
- import { z as z17 } from "zod";
2080
- var UserGeneratSellTransactionArgsSchema = z17.object({
2081
- chainId: z17.number(),
2082
- onSuccess: z17.function().args(stepSchema.array().optional()).optional()
2083
- });
2084
- var generateSellTransaction = async (args, config, chainId) => {
2085
- const marketplaceClient = getMarketplaceClient(chainId, config);
2086
- return marketplaceClient.generateSellTransaction(args).then((data) => data.steps);
2087
- };
2088
- var useGenerateSellTransaction = (params) => {
2089
- const config = useConfig();
2090
- const { mutate, mutateAsync, ...result } = useMutation3({
2091
- onSuccess: params.onSuccess,
2092
- mutationFn: (args) => generateSellTransaction(args, config, params.chainId)
2093
- });
2094
- return {
2095
- ...result,
2096
- generateSellTransaction: mutate,
2097
- generateSellTransactionAsync: mutateAsync
2098
- };
2099
- };
2100
-
2101
- // src/react/hooks/useGenerateCancelTransaction.tsx
2102
- import { useMutation as useMutation4 } from "@tanstack/react-query";
2103
- import { z as z18 } from "zod";
2104
- var UserGenerateCancelTransactionArgsSchema = z18.object({
2105
- chainId: z18.number(),
2106
- onSuccess: z18.function().args(stepSchema.array().optional()).optional()
2107
- });
2108
- var generateCancelTransaction = async (args, config, chainId) => {
2109
- const marketplaceClient = getMarketplaceClient(chainId, config);
2110
- return marketplaceClient.generateCancelTransaction(args).then((data) => data.steps);
2111
- };
2112
- var useGenerateCancelTransaction = (params) => {
2113
- const config = useConfig();
2114
- const { mutate, mutateAsync, ...result } = useMutation4({
2115
- onSuccess: params.onSuccess,
2116
- mutationFn: (args) => generateCancelTransaction(args, config, params.chainId)
2117
- });
2118
- return {
2119
- ...result,
2120
- generateCancelTransaction: mutate,
2121
- generateCancelTransactionAsync: mutateAsync
2122
- };
2123
- };
2124
-
2125
- // src/react/hooks/useTransferTokens.tsx
2126
- import { erc721Abi as erc721Abi2 } from "viem";
2127
- import { useAccount as useAccount3, useWriteContract } from "wagmi";
2128
- var prepareTransferConfig = (params, accountAddress) => {
2129
- if (params.contractType === "ERC721") {
2130
- return {
2131
- abi: erc721Abi2,
2132
- address: params.collectionAddress,
2133
- functionName: "safeTransferFrom",
2134
- args: [
2135
- accountAddress,
2136
- params.receiverAddress,
2137
- BigInt(params.tokenId)
2138
- ]
2139
- };
2140
- }
2141
- return {
2142
- abi: ERC1155_ABI,
2143
- address: params.collectionAddress,
2144
- functionName: "safeTransferFrom",
2145
- args: [
2146
- accountAddress,
2147
- params.receiverAddress,
2148
- BigInt(params.tokenId),
2149
- params.quantity,
2150
- "0x"
2151
- // data
2152
- ]
2153
- };
2154
- };
2155
- var useTransferTokens = () => {
2156
- const { address: accountAddress } = useAccount3();
2157
- const {
2158
- writeContractAsync,
2159
- data: hash,
2160
- isPending,
2161
- isError,
2162
- isSuccess
2163
- } = useWriteContract();
2164
- const transferTokensAsync = async (params) => {
2165
- if (!accountAddress) {
2166
- throw new NoWalletConnectedError();
2167
- }
2168
- const config = prepareTransferConfig(params, accountAddress);
2169
- return await writeContractAsync(config);
2170
- };
2171
- return {
2172
- transferTokensAsync,
2173
- hash,
2174
- transferring: isPending,
2175
- transferFailed: isError,
2176
- transferSuccess: isSuccess
2177
- };
2178
- };
2179
-
2180
- // src/react/hooks/useCheckoutOptions.tsx
2181
- import { queryOptions as queryOptions17, useQuery as useQuery23 } from "@tanstack/react-query";
2182
- import { useAccount as useAccount4 } from "wagmi";
2183
- import { z as z19 } from "zod";
2184
- var UseCheckoutOptionsSchema = z19.object({
2185
- chainId: z19.number(),
2186
- orders: z19.array(
2187
- z19.object({
2188
- collectionAddress: AddressSchema,
2189
- orderId: z19.string(),
2190
- marketplace: z19.nativeEnum(MarketplaceKind)
2191
- })
2192
- ),
2193
- query: QueryArgSchema
2194
- });
2195
- var fetchCheckoutOptions = async (args, config) => {
2196
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
2197
- return marketplaceClient.checkoutOptionsMarketplace({
2198
- wallet: args.walletAddress,
2199
- orders: args.orders.map((order) => ({
2200
- contractAddress: order.collectionAddress,
2201
- orderId: order.orderId,
2202
- marketplace: order.marketplace
2203
- })),
2204
- additionalFee: 0
2205
- //TODO: add additional fee
2206
- });
2207
- };
2208
- var checkoutOptionsOptions = (args, config) => {
2209
- return queryOptions17({
2210
- queryKey: ["checkoutOptions", args],
2211
- queryFn: () => fetchCheckoutOptions(args, config)
2212
- });
2213
- };
2214
- var useCheckoutOptions = (args) => {
2215
- const { address } = useAccount4();
2216
- const config = useConfig();
2217
- return useQuery23(
2218
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
2219
- checkoutOptionsOptions({ walletAddress: address, ...args }, config)
2220
- );
2221
- };
2222
-
2223
- // src/react/hooks/useListCollections.tsx
2224
- import { queryOptions as queryOptions18, useQuery as useQuery24 } from "@tanstack/react-query";
2225
- import { z as z20 } from "zod";
2226
- var UseListCollectionsSchema = z20.object({
2227
- query: QueryArgSchema.optional().default({})
2228
- });
2229
- var fetchListCollections = async ({ marketplaceConfig }, config) => {
2230
- const metadataClient = getMetadataClient(config);
2231
- if (!marketplaceConfig?.collections?.length) {
2232
- return [];
2233
- }
2234
- const collectionsByChain = marketplaceConfig.collections.reduce((acc, curr) => {
2235
- const { chainId, address } = curr;
2236
- if (!acc[chainId]) {
2237
- acc[chainId] = [];
2238
- }
2239
- acc[chainId].push(address);
2240
- return acc;
2241
- }, {});
2242
- const promises = Object.entries(collectionsByChain).map(
2243
- ([chainId, addresses]) => metadataClient.getContractInfoBatch({
2244
- chainID: chainId,
2245
- contractAddresses: addresses
2246
- }).then((resp) => Object.values(resp.contractInfoMap))
2247
- );
2248
- const results = await Promise.all(promises);
2249
- return results.flat();
2250
- };
2251
- var listCollectionsOptions = (args, config) => {
2252
- return queryOptions18({
2253
- ...args.query,
2254
- queryKey: [...collectionKeys.list],
2255
- queryFn: () => fetchListCollections(args, config)
2256
- });
2257
- };
2258
- var useListCollections = (args = {}) => {
2259
- const config = useConfig();
2260
- const { data: marketplaceConfig, isLoading: isLoadingConfig } = useMarketplaceConfig();
2261
- return useQuery24({
2262
- ...listCollectionsOptions(
2263
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
2264
- { marketplaceConfig, query: args.query },
2265
- config
2266
- ),
2267
- enabled: !isLoadingConfig && !!marketplaceConfig
2268
- });
2269
- };
2270
-
2271
- // src/react/hooks/useCancelOrder.tsx
2272
- import { useWaasFeeOptions } from "@0xsequence/connect";
2273
- import { useEffect as useEffect2, useState } from "react";
2274
-
2275
- // src/react/ui/modals/_internal/components/switchChainModal/index.tsx
2276
- import { Button, Modal, Spinner, Text as Text2 } from "@0xsequence/design-system";
2277
- import { observer } from "@legendapp/state/react";
2278
- import { useSwitchChain as useSwitchChain2 } from "wagmi";
2279
-
2280
- // src/react/ui/modals/_internal/components/alertMessage/index.tsx
2281
- import { Text, WarningIcon } from "@0xsequence/design-system";
2282
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
2283
- function AlertMessage({ message, type }) {
2284
- return /* @__PURE__ */ jsxs(
2285
- "div",
2286
- {
2287
- className: `flex items-center justify-between gap-3 rounded-xl p-4 ${type === "warning" ? "bg-[hsla(39,71%,40%,0.3)]" : "bg-[hsla(247,100%,75%,0.3)]"}`,
2288
- children: [
2289
- /* @__PURE__ */ jsx2(Text, { className: "font-body text-sm", color: "white", fontWeight: "medium", children: message }),
2290
- type === "warning" && /* @__PURE__ */ jsx2(WarningIcon, { size: "sm", color: "white" }),
2291
- type === "info" && /* @__PURE__ */ jsx2(InfoIcon_default, { size: "sm", color: "white" })
2292
- ]
2293
- }
2294
- );
2295
- }
2296
-
2297
- // src/react/ui/modals/_internal/components/consts.ts
2298
- var MODAL_WIDTH = "360px";
2299
- var MODAL_OVERLAY_PROPS = {
2300
- style: {
2301
- background: "hsla(0, 0%, 15%, 0.9)"
2302
- }
2303
- };
2304
- var MODAL_CONTENT_PROPS = {
2305
- style: {
2306
- width: MODAL_WIDTH,
2307
- height: "auto"
2308
- }
2309
- };
2310
-
2311
- // src/react/ui/modals/_internal/components/switchChainModal/store.ts
2312
- import { observable } from "@legendapp/state";
2313
- var initialState = {
2314
- isOpen: false,
2315
- open: ({ chainIdToSwitchTo, onError, onSuccess, onClose }) => {
2316
- switchChainModal$.state.set({
2317
- ...switchChainModal$.state.get(),
2318
- chainIdToSwitchTo,
2319
- onError,
2320
- onSuccess,
2321
- onClose
2322
- });
2323
- switchChainModal$.isOpen.set(true);
2324
- },
2325
- close: () => {
2326
- switchChainModal$.isOpen.set(false);
2327
- },
2328
- state: {
2329
- chainIdToSwitchTo: void 0,
2330
- onError: void 0,
2331
- onSuccess: void 0,
2332
- onClose: void 0,
2333
- isSwitching: false
2334
- }
2335
- };
2336
- var switchChainModal$ = observable(initialState);
2337
-
2338
- // src/react/ui/modals/_internal/components/switchChainModal/index.tsx
2339
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
2340
- var useSwitchChainModal = () => {
2341
- return {
2342
- show: (args) => switchChainModal$.open(args),
2343
- close: () => switchChainModal$.delete(),
2344
- isSwitching$: switchChainModal$.state.isSwitching
2345
- };
2346
- };
2347
- var SwitchChainModal = observer(() => {
2348
- const chainIdToSwitchTo = switchChainModal$.state.chainIdToSwitchTo.get();
2349
- const isSwitching$ = switchChainModal$.state.isSwitching;
2350
- const chainName = chainIdToSwitchTo ? getPresentableChainName(chainIdToSwitchTo) : "";
2351
- const { switchChainAsync } = useSwitchChain2();
2352
- async function handleSwitchChain() {
2353
- isSwitching$.set(true);
2354
- try {
2355
- if (!chainIdToSwitchTo) return;
2356
- await switchChainAsync({ chainId: Number(chainIdToSwitchTo) });
2357
- if (switchChainModal$.state.onSuccess.get() && typeof switchChainModal$.state.onSuccess.get() === "function") {
2358
- switchChainModal$.state.onSuccess();
2359
- }
2360
- switchChainModal$.delete();
2361
- } catch (error) {
2362
- if (error instanceof Error && switchChainModal$.state.onError.get() && typeof switchChainModal$.state.onError.get() === "function") {
2363
- switchChainModal$.state.onError.get()?.(error);
2364
- }
2365
- } finally {
2366
- isSwitching$.set(false);
2367
- }
2368
- }
2369
- const handleClose = () => {
2370
- if (switchChainModal$.state.onClose && typeof switchChainModal$.state.onClose === "function") {
2371
- switchChainModal$.state.onClose();
2372
- }
2373
- switchChainModal$.delete();
2374
- };
2375
- if (!chainIdToSwitchTo) return null;
2376
- return /* @__PURE__ */ jsx3(
2377
- Modal,
2378
- {
2379
- isDismissible: true,
2380
- onClose: handleClose,
2381
- disableAnimation: true,
2382
- size: "sm",
2383
- overlayProps: MODAL_OVERLAY_PROPS,
2384
- children: /* @__PURE__ */ jsxs2("div", { className: "grid flex-col gap-6 p-7", children: [
2385
- /* @__PURE__ */ jsx3(Text2, { className: "text-xl", fontWeight: "bold", color: "text100", children: "Wrong network" }),
2386
- /* @__PURE__ */ jsx3(
2387
- AlertMessage,
2388
- {
2389
- type: "warning",
2390
- message: `You need to switch to ${chainName} network before completing the transaction`
2391
- }
2392
- ),
2393
- /* @__PURE__ */ jsx3(
2394
- Button,
2395
- {
2396
- className: `${isSwitching$.get() ? "flex w-[147px] items-center justify-center [&>div]:justify-center" : "w-[147px]"} flex justify-self-end`,
2397
- name: "switch-chain",
2398
- id: "switch-chain-button",
2399
- size: "sm",
2400
- label: isSwitching$.get() ? /* @__PURE__ */ jsx3("div", { "data-testid": "switch-chain-spinner", children: /* @__PURE__ */ jsx3(Spinner, { className: "spinner" }) }) : "Switch Network",
2401
- variant: "primary",
2402
- pending: isSwitching$.get(),
2403
- shape: "square",
2404
- onClick: handleSwitchChain,
2405
- "data-testid": "switch-chain-button"
2406
- }
2407
- )
2408
- ] })
2409
- }
2410
- );
2411
- });
2412
- var switchChainModal_default = SwitchChainModal;
2413
-
2414
- // src/react/hooks/util/optimisticCancelUpdates.ts
2415
- var SECOND = 1e3;
2416
- var updateQueriesOnCancel = ({
2417
- orderId,
2418
- queryClient
2419
- }) => {
2420
- queryClient.setQueriesData(
2421
- { queryKey: collectableKeys.offersCount, exact: false },
2422
- (oldData) => {
2423
- if (!oldData) return { count: 0 };
2424
- return { count: Math.max(0, oldData.count - 1) };
2425
- }
2426
- );
2427
- console.log("query client ", queryClient, "orderId", orderId);
2428
- queryClient.setQueriesData(
2429
- { queryKey: collectableKeys.offers, exact: false },
2430
- (oldData) => {
2431
- if (!oldData || !oldData.offers) return oldData;
2432
- return {
2433
- ...oldData,
2434
- offers: oldData.offers.filter((offer) => offer.orderId !== orderId)
2435
- };
2436
- }
2437
- );
2438
- setTimeout(() => {
2439
- queryClient.invalidateQueries({
2440
- queryKey: collectableKeys.highestOffers,
2441
- exact: false
2442
- });
2443
- }, 2 * SECOND);
2444
- queryClient.setQueriesData(
2445
- { queryKey: collectableKeys.listingsCount, exact: false },
2446
- (oldData) => {
2447
- if (!oldData) return { count: 0 };
2448
- return { count: Math.max(0, oldData.count - 1) };
2449
- }
2450
- );
2451
- queryClient.setQueriesData(
2452
- { queryKey: collectableKeys.listings, exact: false },
2453
- (oldData) => {
2454
- if (!oldData || !oldData.listings) return oldData;
2455
- return {
2456
- ...oldData,
2457
- listings: oldData.listings.filter(
2458
- (listing) => listing.orderId !== orderId
2459
- )
2460
- };
2461
- }
2462
- );
2463
- setTimeout(() => {
2464
- queryClient.invalidateQueries({
2465
- queryKey: collectableKeys.lowestListings,
2466
- exact: false
2467
- });
2468
- }, 2 * SECOND);
2469
- };
2470
- var invalidateQueriesOnCancel = ({
2471
- queryClient
2472
- }) => {
2473
- queryClient.invalidateQueries({
2474
- queryKey: collectableKeys.offers,
2475
- exact: false
2476
- });
2477
- queryClient.invalidateQueries({
2478
- queryKey: collectableKeys.offersCount,
2479
- exact: false
2480
- });
2481
- queryClient.invalidateQueries({
2482
- queryKey: collectableKeys.listings,
2483
- exact: false
2484
- });
2485
- queryClient.invalidateQueries({
2486
- queryKey: collectableKeys.listingsCount,
2487
- exact: false
2488
- });
2489
- queryClient.invalidateQueries({
2490
- queryKey: collectableKeys.highestOffers,
2491
- exact: false
2492
- });
2493
- queryClient.invalidateQueries({
2494
- queryKey: collectableKeys.lowestListings,
2495
- exact: false
2496
- });
2497
- };
2498
-
2499
- // src/react/hooks/useCancelTransactionSteps.tsx
2500
- var useCancelTransactionSteps = ({
2501
- collectionAddress,
2502
- chainId,
2503
- callbacks,
2504
- setSteps,
2505
- onSuccess,
2506
- onError
2507
- }) => {
2508
- const { show: showSwitchChainModal } = useSwitchChainModal();
2509
- const { wallet: wallet2, isLoading, isError } = useWallet();
2510
- const walletIsInitialized = wallet2 && !isLoading && !isError;
2511
- const sdkConfig = useConfig();
2512
- const marketplaceClient = getMarketplaceClient(chainId, sdkConfig);
2513
- const { generateCancelTransactionAsync } = useGenerateCancelTransaction({
2514
- chainId
2515
- });
2516
- const getWalletChainId = async () => {
2517
- return await wallet2?.getChainId();
2518
- };
2519
- const switchChain = async () => {
2520
- await wallet2?.switchChain(Number(chainId));
2521
- };
2522
- const checkAndSwitchChain = async () => {
2523
- const walletChainId = await getWalletChainId();
2524
- const isWaaS = wallet2?.isWaaS;
2525
- const chainIdMismatch = walletChainId !== Number(chainId);
2526
- return new Promise((resolve, reject) => {
2527
- if (chainIdMismatch) {
2528
- if (isWaaS) {
2529
- switchChain().then(resolve).catch(reject);
2530
- } else {
2531
- showSwitchChainModal({
2532
- chainIdToSwitchTo: chainId,
2533
- onSuccess: () => resolve({ chainId }),
2534
- onError: (error) => reject(error),
2535
- onClose: () => reject(new ChainSwitchUserRejectedError())
2536
- });
2537
- }
2538
- } else {
2539
- resolve({ chainId });
2540
- }
2541
- });
2542
- };
2543
- const getCancelSteps = async ({
2544
- orderId,
2545
- marketplace
2546
- }) => {
2547
- try {
2548
- const address = await wallet2?.address();
2549
- if (!address) {
2550
- throw new Error("Wallet address not found");
2551
- }
2552
- const steps = await generateCancelTransactionAsync({
2553
- collectionAddress,
2554
- maker: address,
2555
- marketplace,
2556
- orderId
2557
- });
2558
- return steps;
2559
- } catch (error) {
2560
- if (callbacks?.onError) {
2561
- callbacks.onError(error);
2562
- } else {
2563
- console.debug("onError callback not provided:", error);
2564
- }
2565
- }
2566
- };
2567
- const cancelOrder = async ({
2568
- orderId,
2569
- marketplace
2570
- }) => {
2571
- const queryClient = getQueryClient();
2572
- if (!walletIsInitialized) {
2573
- throw new WalletInstanceNotFoundError();
2574
- }
2575
- try {
2576
- await checkAndSwitchChain();
2577
- setSteps((prev) => ({
2578
- ...prev,
2579
- isExecuting: true
2580
- }));
2581
- const cancelSteps = await getCancelSteps({
2582
- orderId,
2583
- marketplace
2584
- });
2585
- const transactionStep = cancelSteps?.find(
2586
- (step) => step.id === "cancel" /* cancel */
2587
- );
2588
- const signatureStep = cancelSteps?.find(
2589
- (step) => step.id === "signEIP712" /* signEIP712 */
2590
- );
2591
- console.debug("transactionStep", transactionStep);
2592
- console.debug("signatureStep", signatureStep);
2593
- if (!transactionStep && !signatureStep) {
2594
- throw new Error("No transaction or signature step found");
2595
- }
2596
- let hash;
2597
- let reservoirOrderId;
2598
- if (transactionStep && wallet2) {
2599
- hash = await executeTransaction({ transactionStep });
2600
- if (hash) {
2601
- await wallet2.handleConfirmTransactionStep(hash, Number(chainId));
2602
- if (onSuccess && typeof onSuccess === "function") {
2603
- onSuccess({ hash });
2604
- updateQueriesOnCancel({
2605
- orderId,
2606
- queryClient
2607
- });
2608
- }
2609
- setSteps((prev) => ({
2610
- ...prev,
2611
- isExecuting: false
2612
- }));
2613
- }
2614
- }
2615
- if (signatureStep) {
2616
- reservoirOrderId = await executeSignature({ signatureStep });
2617
- if (onSuccess && typeof onSuccess === "function") {
2618
- onSuccess({ orderId: reservoirOrderId });
2619
- updateQueriesOnCancel({
2620
- orderId: reservoirOrderId,
2621
- queryClient
2622
- });
2623
- }
2624
- setSteps((prev) => ({
2625
- ...prev,
2626
- isExecuting: false
2627
- }));
2628
- }
2629
- } catch (error) {
2630
- invalidateQueriesOnCancel({
2631
- queryClient
2632
- });
2633
- setSteps((prev) => ({
2634
- ...prev,
2635
- isExecuting: false
2636
- }));
2637
- if (onError && typeof onError === "function") {
2638
- onError(error);
2639
- }
2640
- }
2641
- };
2642
- const executeTransaction = async ({
2643
- transactionStep
2644
- }) => {
2645
- const hash = await wallet2?.handleSendTransactionStep(
2646
- Number(chainId),
2647
- transactionStep
2648
- );
2649
- return hash;
2650
- };
2651
- const executeSignature = async ({
2652
- signatureStep
2653
- }) => {
2654
- const signature = await wallet2?.handleSignMessageStep(
2655
- signatureStep
2656
- );
2657
- const result = await marketplaceClient.execute({
2658
- signature,
2659
- method: signatureStep.post?.method,
2660
- endpoint: signatureStep.post?.endpoint,
2661
- body: signatureStep.post?.body
2662
- });
2663
- return result.orderId;
2664
- };
2665
- return {
2666
- cancelOrder
2667
- };
2668
- };
2669
-
2670
- // src/react/hooks/useCancelOrder.tsx
2671
- var useCancelOrder = ({
2672
- collectionAddress,
2673
- chainId,
2674
- onSuccess,
2675
- onError
2676
- }) => {
2677
- const [steps, setSteps] = useState({
2678
- exist: false,
2679
- isExecuting: false,
2680
- execute: () => Promise.resolve()
2681
- });
2682
- const [cancellingOrderId, setCancellingOrderId] = useState(
2683
- null
2684
- );
2685
- const [pendingFeeOptionConfirmation, confirmPendingFeeOption] = useWaasFeeOptions();
2686
- const autoSelectOptionPromise = useAutoSelectFeeOption({
2687
- pendingFeeOptionConfirmation: pendingFeeOptionConfirmation ? {
2688
- id: pendingFeeOptionConfirmation.id,
2689
- options: pendingFeeOptionConfirmation.options?.map((opt) => ({
2690
- ...opt,
2691
- token: {
2692
- ...opt.token,
2693
- contractAddress: opt.token.contractAddress || null,
2694
- decimals: opt.token.decimals || 0,
2695
- tokenID: opt.token.tokenID || null
2696
- }
2697
- })),
2698
- chainId
2699
- } : {
2700
- id: "",
2701
- options: void 0,
2702
- chainId
2703
- },
2704
- enabled: !!pendingFeeOptionConfirmation
2705
- });
2706
- useEffect2(() => {
2707
- autoSelectOptionPromise.then((res) => {
2708
- if (pendingFeeOptionConfirmation?.id && res.selectedOption) {
2709
- confirmPendingFeeOption(
2710
- pendingFeeOptionConfirmation.id,
2711
- res.selectedOption.token.contractAddress
2712
- );
2713
- }
2714
- });
2715
- }, [
2716
- autoSelectOptionPromise,
2717
- confirmPendingFeeOption,
2718
- pendingFeeOptionConfirmation
2719
- ]);
2720
- const { cancelOrder: cancelOrderBase } = useCancelTransactionSteps({
2721
- collectionAddress,
2722
- chainId,
2723
- onSuccess: (result) => {
2724
- setCancellingOrderId(null);
2725
- onSuccess?.(result);
2726
- },
2727
- onError: (error) => {
2728
- setCancellingOrderId(null);
2729
- onError?.(error);
2730
- },
2731
- setSteps
2732
- });
2733
- const cancelOrder = async (params) => {
2734
- setCancellingOrderId(params.orderId);
2735
- return cancelOrderBase(params);
2736
- };
2737
- return {
2738
- cancelOrder,
2739
- isExecuting: steps.isExecuting,
2740
- cancellingOrderId
2741
- };
2742
- };
2743
-
2744
- // src/react/hooks/useCollectionDetails.tsx
2745
- import { queryOptions as queryOptions19, useQuery as useQuery25 } from "@tanstack/react-query";
2746
- var fetchCollectionDetails = async (args, marketplaceClient) => {
2747
- const { collection } = await marketplaceClient.getCollectionDetail({
2748
- contractAddress: args.collectionAddress
2749
- });
2750
- return collection;
2751
- };
2752
- var collectionDetailsOptions = (args, config) => {
2753
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
2754
- return queryOptions19({
2755
- queryKey: ["collectionDetails", args],
2756
- queryFn: () => fetchCollectionDetails(args, marketplaceClient)
2757
- });
2758
- };
2759
- var useCollectionDetails = (args) => {
2760
- const config = useConfig();
2761
- return useQuery25(collectionDetailsOptions(args, config));
2762
- };
2763
-
2764
- // src/react/hooks/useCollectionDetailsPolling.tsx
2765
- import { queryOptions as queryOptions20, useQuery as useQuery26 } from "@tanstack/react-query";
2766
- var INITIAL_POLLING_INTERVAL = 2e3;
2767
- var MAX_POLLING_INTERVAL = 3e4;
2768
- var MAX_ATTEMPTS = 30;
2769
- var isTerminalState = (status) => {
2770
- return [
2771
- "active" /* active */,
2772
- "failed" /* failed */,
2773
- "inactive" /* inactive */,
2774
- "incompatible_type" /* incompatible_type */
2775
- ].includes(status);
2776
- };
2777
- var collectionDetailsPollingOptions = (args, config) => {
2778
- return queryOptions20({
2779
- ...collectionDetailsOptions(args, config),
2780
- refetchInterval: (query) => {
2781
- const data = query.state.data;
2782
- if (data && isTerminalState(data.status)) {
2783
- return false;
2784
- }
2785
- const currentAttempt = (query.state.dataUpdateCount || 0) + 1;
2786
- if (currentAttempt >= MAX_ATTEMPTS) {
2787
- return false;
2788
- }
2789
- const interval = Math.min(
2790
- INITIAL_POLLING_INTERVAL * 1.5 ** currentAttempt,
2791
- MAX_POLLING_INTERVAL
2792
- );
2793
- return interval;
2794
- },
2795
- refetchOnWindowFocus: false,
2796
- retry: false
2797
- });
2798
- };
2799
- var useCollectionDetailsPolling = (args) => {
2800
- const config = useConfig();
2801
- return useQuery26(collectionDetailsPollingOptions(args, config));
2802
- };
2803
-
2804
- // src/react/hooks/useListTokenMetadata.ts
2805
- import { useQuery as useQuery27 } from "@tanstack/react-query";
2806
- var useListTokenMetadata = (args) => {
2807
- const config = useConfig();
2808
- const { chainId, contractAddress, tokenIds, query } = args;
2809
- return useQuery27({
2810
- ...tokenMetadataOptions(
2811
- { chainId, contractAddress, tokenIds, query },
2812
- config
2813
- )
2814
- });
2815
- };
2816
-
2817
- export {
2818
- MarketplaceSdkContext,
2819
- MarketplaceQueryClientProvider,
2820
- MarketplaceProvider,
2821
- useConfig,
2822
- collectionBalanceDetailsOptions,
2823
- useCollectionBalanceDetails,
2824
- useAutoSelectFeeOption,
2825
- useMarketplaceConfig,
2826
- useBalanceOfCollectible,
2827
- countOfCollectablesOptions,
2828
- useCountOfCollectables,
2829
- collectibleOptions,
2830
- useCollectible,
2831
- useCollection,
2832
- currenciesOptions,
2833
- useCurrencies,
2834
- convertPriceToUSD,
2835
- convertPriceToUSDOptions,
2836
- useConvertPriceToUSD,
2837
- comparePricesOptions,
2838
- useComparePrices,
2839
- currencyOptions,
2840
- useCurrency,
2841
- fetchFilters,
2842
- filtersOptions,
2843
- useFilters,
2844
- useFiltersProgressive,
2845
- useFilterState,
2846
- floorOrderOptions,
2847
- useFloorOrder,
2848
- useHighestOffer,
2849
- useInventory,
2850
- useListBalances,
2851
- listCollectibleActivitiesOptions,
2852
- useListCollectibleActivities,
2853
- useListCollectibles,
2854
- listCollectiblesPaginatedOptions,
2855
- useListCollectiblesPaginated,
2856
- listCollectionActivitiesOptions,
2857
- useListCollectionActivities,
2858
- listOffersForCollectibleOptions,
2859
- useListOffersForCollectible,
2860
- countOffersForCollectibleOptions,
2861
- useCountOffersForCollectible,
2862
- listListingsForCollectibleOptions,
2863
- useListListingsForCollectible,
2864
- countListingsForCollectibleOptions,
2865
- useCountListingsForCollectible,
2866
- useLowestListing,
2867
- useRoyalty,
2868
- dateToUnixTime,
2869
- generateListingTransaction,
2870
- useGenerateListingTransaction,
2871
- useWallet,
2872
- generateOfferTransaction,
2873
- useGenerateOfferTransaction,
2874
- generateSellTransaction,
2875
- useGenerateSellTransaction,
2876
- generateCancelTransaction,
2877
- useGenerateCancelTransaction,
2878
- useTransferTokens,
2879
- checkoutOptionsOptions,
2880
- useCheckoutOptions,
2881
- listCollectionsOptions,
2882
- useListCollections,
2883
- AlertMessage,
2884
- MODAL_OVERLAY_PROPS,
2885
- MODAL_CONTENT_PROPS,
2886
- useSwitchChainModal,
2887
- switchChainModal_default,
2888
- useCancelOrder,
2889
- collectionDetailsOptions,
2890
- useCollectionDetails,
2891
- collectionDetailsPollingOptions,
2892
- useCollectionDetailsPolling,
2893
- useListTokenMetadata
2894
- };
2895
- //# sourceMappingURL=chunk-SXVUTSMT.js.map