@0xsequence/marketplace-sdk 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/dist/chess-tile-6BS5MQT5.png +0 -0
  2. package/dist/chunk-22NLQ3AS.js +3078 -0
  3. package/dist/chunk-22NLQ3AS.js.map +1 -0
  4. package/dist/chunk-3OHM45R3.js +1294 -0
  5. package/dist/chunk-3OHM45R3.js.map +1 -0
  6. package/dist/{chunk-4E34HVSA.js → chunk-4YU2UPYH.js} +29 -74
  7. package/dist/chunk-4YU2UPYH.js.map +1 -0
  8. package/dist/chunk-7NJETFMF.js +21 -0
  9. package/dist/chunk-7NJETFMF.js.map +1 -0
  10. package/dist/{chunk-UYRQ5MJQ.js → chunk-FUM4OGOQ.js} +4 -4
  11. package/dist/chunk-FUM4OGOQ.js.map +1 -0
  12. package/dist/{chunk-FCQCNLFZ.js → chunk-G33554LK.js} +4 -1
  13. package/dist/chunk-G33554LK.js.map +1 -0
  14. package/dist/{chunk-7OO74L2K.js → chunk-GJAKQ5Q3.js} +40 -1
  15. package/dist/chunk-GJAKQ5Q3.js.map +1 -0
  16. package/dist/{chunk-GZIA25G4.js → chunk-GZG2QO64.js} +22 -6
  17. package/dist/chunk-GZG2QO64.js.map +1 -0
  18. package/dist/chunk-MCI3KOSQ.js +2 -0
  19. package/dist/{chunk-5EOVZAKT.js → chunk-O7UQGT43.js} +891 -100
  20. package/dist/chunk-O7UQGT43.js.map +1 -0
  21. package/dist/{chunk-CSN7YD5Q.js → chunk-Q57TEA3Z.js} +20 -2
  22. package/dist/chunk-Q57TEA3Z.js.map +1 -0
  23. package/dist/{chunk-VEX7FDL6.js → chunk-SBVLWSRZ.js} +2 -2
  24. package/dist/{chunk-VEX7FDL6.js.map → chunk-SBVLWSRZ.js.map} +1 -1
  25. package/dist/{chunk-6S4FYXP6.js → chunk-SPW24Y7I.js} +40 -1
  26. package/dist/chunk-SPW24Y7I.js.map +1 -0
  27. package/dist/chunk-UISBTKFF.js +1 -0
  28. package/dist/{chunk-LFQB477Y.js → chunk-WA433WAJ.js} +9 -33
  29. package/dist/chunk-WA433WAJ.js.map +1 -0
  30. package/dist/{chunk-O5JXKTWP.js → chunk-WFE6OCYF.js} +4 -4
  31. package/dist/chunk-WFE6OCYF.js.map +1 -0
  32. package/dist/chunk-XX4EVWBF.js +1292 -0
  33. package/dist/chunk-XX4EVWBF.js.map +1 -0
  34. package/dist/chunk-Y7YO5TLE.js +53 -0
  35. package/dist/chunk-Y7YO5TLE.js.map +1 -0
  36. package/dist/index.css +1 -50
  37. package/dist/index.d.ts +5 -7
  38. package/dist/index.js +158 -73
  39. package/dist/index.js.map +1 -1
  40. package/dist/{marketplace.gen-Ceofb9Cs.d.ts → marketplace.gen-BLP7822q.d.ts} +17 -5
  41. package/dist/react/_internal/api/index.d.ts +4 -2
  42. package/dist/react/_internal/api/index.js +1 -1
  43. package/dist/react/_internal/index.d.ts +3 -3
  44. package/dist/react/_internal/index.js +7 -7
  45. package/dist/react/hooks/index.css +82 -0
  46. package/dist/react/hooks/index.css.map +1 -0
  47. package/dist/react/hooks/index.d.ts +577 -427
  48. package/dist/react/hooks/index.js +39 -7
  49. package/dist/react/index.css +86 -81
  50. package/dist/react/index.css.map +1 -1
  51. package/dist/react/index.d.ts +6 -5
  52. package/dist/react/index.js +49 -16
  53. package/dist/react/ssr/index.js +4 -3
  54. package/dist/react/ssr/index.js.map +1 -1
  55. package/dist/react/ui/components/index.css +241 -0
  56. package/dist/react/ui/components/index.css.map +1 -0
  57. package/dist/react/ui/components/index.d.ts +23 -0
  58. package/dist/react/ui/components/index.js +25 -0
  59. package/dist/react/ui/icons/index.js +3 -2
  60. package/dist/react/ui/icons/index.js.map +1 -1
  61. package/dist/react/ui/index.css +86 -81
  62. package/dist/react/ui/index.css.map +1 -1
  63. package/dist/react/ui/index.d.ts +34 -33
  64. package/dist/react/ui/index.js +17 -12
  65. package/dist/react/ui/modals/_internal/components/actionModal/index.js +6 -17
  66. package/dist/react/ui/modals/_internal/components/actionModal/index.js.map +1 -1
  67. package/dist/react/ui/styles/index.d.ts +1 -1
  68. package/dist/{services-Dei25J6_.d.ts → services-C9-lvWcC.d.ts} +1 -1
  69. package/dist/styles/index.css +1 -50
  70. package/dist/styles/index.css.map +1 -1
  71. package/dist/styles/index.d.ts +1 -5
  72. package/dist/styles/index.js +10 -12
  73. package/dist/types/index.d.ts +2 -2
  74. package/dist/types/index.js +2 -2
  75. package/dist/{types-BzZVURNL.d.ts → types-QqXjNuUP.d.ts} +1 -1
  76. package/dist/utils/abi/index.d.ts +2 -0
  77. package/dist/utils/abi/index.js +21 -0
  78. package/dist/utils/abi/marketplace/index.d.ts +805 -0
  79. package/dist/utils/abi/marketplace/index.js +12 -0
  80. package/dist/utils/abi/{abi/token → token}/index.js +1 -2
  81. package/dist/utils/abi/token/index.js.map +1 -0
  82. package/dist/utils/index.d.ts +7 -7
  83. package/dist/utils/index.js +12 -14
  84. package/package.json +17 -15
  85. package/src/react/_internal/api/get-query-client.ts +3 -3
  86. package/src/react/_internal/api/marketplace.gen.ts +34 -10
  87. package/src/react/_internal/api/query-keys.ts +8 -0
  88. package/src/react/_internal/transaction-machine/execute-transaction.ts +592 -0
  89. package/src/react/_internal/transaction-machine/useTransactionMachine.ts +66 -0
  90. package/src/react/hooks/index.ts +7 -0
  91. package/src/react/hooks/useBuyCollectable.tsx +38 -0
  92. package/src/react/hooks/useCancelOrder.tsx +38 -0
  93. package/src/react/hooks/useCheckoutOptions.tsx +46 -43
  94. package/src/react/hooks/useCountOfCollectables.tsx +52 -52
  95. package/src/react/hooks/useCreateListing.tsx +65 -0
  96. package/src/react/hooks/useCurrencies.tsx +60 -60
  97. package/src/react/hooks/useCurrency.tsx +64 -0
  98. package/src/react/hooks/useGenerateBuyTransaction.tsx +71 -0
  99. package/src/react/hooks/useGenerateCancelTransaction.tsx +50 -0
  100. package/src/react/hooks/useListBalances.tsx +2 -3
  101. package/src/react/hooks/useListCollectibles.tsx +5 -6
  102. package/src/react/hooks/useListCollections.tsx +88 -0
  103. package/src/react/hooks/useListListingsForCollectible.tsx +61 -0
  104. package/src/react/hooks/useListOffersForCollectible.tsx +14 -16
  105. package/src/react/hooks/useMakeOffer.tsx +62 -0
  106. package/src/react/hooks/useRoyaltyPercentage.tsx +1 -1
  107. package/src/react/hooks/useSell.tsx +62 -0
  108. package/src/react/ui/components/_internals/action-button/ActionButton.tsx +156 -0
  109. package/src/react/ui/components/_internals/custom-network-image/CustomNetworkImage.tsx +27 -0
  110. package/src/react/ui/components/_internals/custom-network-image/styles.css.ts +51 -0
  111. package/src/react/ui/components/_internals/custom-select/CustomSelect.tsx +63 -0
  112. package/src/react/ui/components/_internals/custom-select/styles.css.ts +64 -0
  113. package/src/react/ui/components/_internals/pill/Pill.tsx +20 -0
  114. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +191 -0
  115. package/src/react/ui/components/collectible-card/Footer.tsx +128 -0
  116. package/src/react/ui/components/collectible-card/styles.css.ts +62 -0
  117. package/src/react/ui/components/index.ts +1 -0
  118. package/src/react/ui/icons/Bell.tsx +31 -0
  119. package/src/react/ui/icons/DiamondEye.tsx +31 -0
  120. package/src/react/ui/images/chess-tile.png +0 -0
  121. package/src/react/ui/index.ts +4 -0
  122. package/src/react/ui/modals/BuyModal/_store.ts +53 -0
  123. package/src/react/ui/modals/BuyModal/index.tsx +119 -0
  124. package/src/react/ui/modals/CreateListingModal/_store.ts +35 -312
  125. package/src/react/ui/modals/CreateListingModal/index.tsx +216 -157
  126. package/src/react/ui/modals/MakeOfferModal/_store.ts +34 -276
  127. package/src/react/ui/modals/MakeOfferModal/index.tsx +195 -136
  128. package/src/react/ui/modals/SellModal/_store.ts +29 -262
  129. package/src/react/ui/modals/SellModal/index.tsx +156 -122
  130. package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +17 -3
  131. package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +3 -2
  132. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +92 -92
  133. package/src/react/ui/modals/TransferModal/index.tsx +10 -17
  134. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +1 -0
  135. package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +18 -0
  136. package/src/react/ui/modals/_internal/components/actionModal/LoadingModal.tsx +18 -0
  137. package/src/react/ui/modals/_internal/components/calendarPopover/index.tsx +1 -0
  138. package/src/react/ui/modals/_internal/components/calendarPopover/overrides.css +8 -0
  139. package/src/react/ui/modals/_internal/components/calendarPopover/styles.css.ts +10 -4
  140. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +10 -13
  141. package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +23 -9
  142. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +7 -18
  143. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +17 -44
  144. package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +10 -8
  145. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +14 -3
  146. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +4 -2
  147. package/src/react/ui/modals/_internal/components/transactionHeader/index.tsx +4 -4
  148. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +4 -2
  149. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +13 -10
  150. package/src/react/ui/modals/_internal/types.ts +13 -0
  151. package/src/react/ui/modals/modal-provider.tsx +2 -1
  152. package/src/styles/index.ts +0 -2
  153. package/src/types/custom.d.ts +1 -0
  154. package/src/utils/abi/index.ts +2 -0
  155. package/src/utils/abi/marketplace/index.ts +3 -0
  156. package/src/utils/abi/marketplace/sequence-marketplace-v1.ts +463 -0
  157. package/src/utils/abi/marketplace/sequence-marketplace-v2.ts +802 -0
  158. package/src/utils/index.ts +2 -3
  159. package/src/utils/network.ts +4 -2
  160. package/tsconfig.tsbuildinfo +1 -1
  161. package/dist/chunk-4E34HVSA.js.map +0 -1
  162. package/dist/chunk-5EOVZAKT.js.map +0 -1
  163. package/dist/chunk-6JWGELXL.js +0 -214
  164. package/dist/chunk-6JWGELXL.js.map +0 -1
  165. package/dist/chunk-6S4FYXP6.js.map +0 -1
  166. package/dist/chunk-7OO74L2K.js.map +0 -1
  167. package/dist/chunk-BCNFYVAL.js +0 -1
  168. package/dist/chunk-CSN7YD5Q.js.map +0 -1
  169. package/dist/chunk-D7QQP6MS.js +0 -2
  170. package/dist/chunk-DBFOPEV6.js +0 -23
  171. package/dist/chunk-DBFOPEV6.js.map +0 -1
  172. package/dist/chunk-FCQCNLFZ.js.map +0 -1
  173. package/dist/chunk-GZIA25G4.js.map +0 -1
  174. package/dist/chunk-LFQB477Y.js.map +0 -1
  175. package/dist/chunk-MD4JHPMH.js +0 -2815
  176. package/dist/chunk-MD4JHPMH.js.map +0 -1
  177. package/dist/chunk-O5JXKTWP.js.map +0 -1
  178. package/dist/chunk-PE2LLUTJ.js +0 -213
  179. package/dist/chunk-PE2LLUTJ.js.map +0 -1
  180. package/dist/chunk-QVFMD6S2.js +0 -21
  181. package/dist/chunk-QVFMD6S2.js.map +0 -1
  182. package/dist/chunk-UYRQ5MJQ.js.map +0 -1
  183. package/dist/utils/abi/abi/standard/index.d.ts +0 -25
  184. package/dist/utils/abi/abi/standard/index.js +0 -8
  185. package/dist/utils/abi/clients/index.d.ts +0 -27
  186. package/dist/utils/abi/clients/index.js +0 -13
  187. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/styles.css.ts +0 -33
  188. package/src/react/ui/modals/_internal/components/expirationDateSelect/styles.css.ts +0 -25
  189. package/src/utils/abi/abi/standard/index.ts +0 -1
  190. package/src/utils/abi/clients/ERC1155.ts +0 -82
  191. package/src/utils/abi/clients/ERC20.ts +0 -101
  192. package/src/utils/abi/clients/ERC721.ts +0 -97
  193. package/src/utils/abi/clients/index.ts +0 -3
  194. /package/dist/{chunk-BCNFYVAL.js.map → chunk-MCI3KOSQ.js.map} +0 -0
  195. /package/dist/{chunk-D7QQP6MS.js.map → chunk-UISBTKFF.js.map} +0 -0
  196. /package/dist/{utils/abi/abi/standard → react/ui/components}/index.js.map +0 -0
  197. /package/dist/utils/abi/{abi/token/index.js.map → index.js.map} +0 -0
  198. /package/dist/utils/abi/{clients → marketplace}/index.js.map +0 -0
  199. /package/dist/utils/abi/{abi/token → token}/index.d.ts +0 -0
  200. /package/src/utils/abi/{abi/standard → marketplace}/EIP2981.ts +0 -0
  201. /package/src/utils/abi/{abi/token → token}/ERC1155.ts +0 -0
  202. /package/src/utils/abi/{abi/token → token}/ERC20.ts +0 -0
  203. /package/src/utils/abi/{abi/token → token}/ERC721.ts +0 -0
  204. /package/src/utils/abi/{abi/token → token}/index.ts +0 -0
@@ -0,0 +1,38 @@
1
+ import {
2
+ type CancelInput,
3
+ TransactionType,
4
+ } from '../_internal/transaction-machine/execute-transaction';
5
+ import {
6
+ useTransactionMachine,
7
+ type UseTransactionMachineConfig,
8
+ } from '../_internal/transaction-machine/useTransactionMachine';
9
+
10
+ interface UseCancelOrderArgs extends Omit<UseTransactionMachineConfig, 'type'> {
11
+ onSuccess?: (hash: string) => void;
12
+ onError?: (error: Error) => void;
13
+ onTransactionSent?: (hash: string) => void;
14
+ }
15
+
16
+ export const useCancelOrder = ({
17
+ onSuccess,
18
+ onError,
19
+ onTransactionSent,
20
+ ...config
21
+ }: UseCancelOrderArgs) => {
22
+ const machine = useTransactionMachine(
23
+ {
24
+ ...config,
25
+ type: TransactionType.CANCEL,
26
+ },
27
+ onSuccess,
28
+ onError,
29
+ onTransactionSent,
30
+ );
31
+
32
+ return {
33
+ cancel: (props: CancelInput) => machine?.start({ props }),
34
+ onError,
35
+ onSuccess,
36
+ onTransactionSent,
37
+ };
38
+ };
@@ -1,63 +1,66 @@
1
- import { queryOptions, useQuery } from "@tanstack/react-query";
2
- import { z } from "zod";
3
- import type { SdkConfig } from "../../types";
1
+ import { queryOptions, useQuery } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import type { SdkConfig } from '../../types';
4
4
  import {
5
- AddressSchema,
6
- ChainIdSchema,
7
- MarketplaceKind,
8
- QueryArgSchema,
9
- getMarketplaceClient,
10
- } from "../_internal";
11
- import { useConfig } from "./useConfig";
5
+ AddressSchema,
6
+ ChainIdSchema,
7
+ MarketplaceKind,
8
+ QueryArgSchema,
9
+ getMarketplaceClient,
10
+ } from '../_internal';
11
+ import { useConfig } from './useConfig';
12
+ import { useAccount } from 'wagmi';
13
+ import type { Hex } from 'viem';
12
14
 
13
15
  const UseCheckoutOptionsSchema = z.object({
14
- chainId: ChainIdSchema.pipe(z.coerce.string()),
15
- walletAddress: AddressSchema,
16
- orders: z.array(
17
- z.object({
18
- collectionAddress: AddressSchema,
19
- orderId: z.string(),
20
- quantity: z.number(),
21
- marketplace: z.nativeEnum(MarketplaceKind),
22
- })
23
- ),
24
- query: QueryArgSchema,
16
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
17
+ orders: z.array(
18
+ z.object({
19
+ collectionAddress: AddressSchema,
20
+ orderId: z.string(),
21
+ marketplace: z.nativeEnum(MarketplaceKind),
22
+ }),
23
+ ),
24
+ query: QueryArgSchema,
25
25
  });
26
26
 
27
27
  export type UseCheckoutOptionsArgs = z.infer<typeof UseCheckoutOptionsSchema>;
28
28
 
29
29
  export type UseCheckoutOptionsReturn = Awaited<
30
- ReturnType<typeof fetchCheckoutOptions>
30
+ ReturnType<typeof fetchCheckoutOptions>
31
31
  >;
32
32
 
33
33
  const fetchCheckoutOptions = async (
34
- args: UseCheckoutOptionsArgs,
35
- config: SdkConfig
34
+ args: UseCheckoutOptionsArgs & { walletAddress: Hex },
35
+ config: SdkConfig,
36
36
  ) => {
37
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
38
- return marketplaceClient.checkoutOptionsMarketplace({
39
- wallet: args.walletAddress,
40
- orders: args.orders.map((order) => ({
41
- contractAddress: order.collectionAddress,
42
- orderId: order.orderId,
43
- marketplace: order.marketplace,
44
- quantity: order.quantity,
45
- })),
46
- additionalFee: 0, //TODO: add additional fee
47
- });
37
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
38
+ return marketplaceClient.checkoutOptionsMarketplace({
39
+ wallet: args.walletAddress,
40
+ orders: args.orders.map((order) => ({
41
+ contractAddress: order.collectionAddress,
42
+ orderId: order.orderId,
43
+ marketplace: order.marketplace,
44
+ })),
45
+ additionalFee: 0, //TODO: add additional fee
46
+ });
48
47
  };
49
48
 
50
49
  export const checkoutOptionsOptions = (
51
- args: UseCheckoutOptionsArgs,
52
- config: SdkConfig
50
+ args: UseCheckoutOptionsArgs & { walletAddress: Hex },
51
+ config: SdkConfig,
53
52
  ) => {
54
- return queryOptions({
55
- queryKey: ["checkoutOptions", args],
56
- queryFn: () => fetchCheckoutOptions(args, config),
57
- });
53
+ return queryOptions({
54
+ queryKey: ['checkoutOptions', args],
55
+ queryFn: () => fetchCheckoutOptions(args, config),
56
+ });
58
57
  };
59
58
 
60
59
  export const useCheckoutOptions = (args: UseCheckoutOptionsArgs) => {
61
- const config = useConfig();
62
- return useQuery(checkoutOptionsOptions(args, config));
60
+ const { address } = useAccount();
61
+ const config = useConfig();
62
+ return useQuery(
63
+ // biome-ignore lint/style/noNonNullAssertion: <explanation>
64
+ checkoutOptionsOptions({ walletAddress: address!, ...args }, config),
65
+ );
63
66
  };
@@ -1,77 +1,77 @@
1
- import { queryOptions, useQuery } from "@tanstack/react-query";
2
- import { z } from "zod";
3
- import type { SdkConfig } from "../../types";
1
+ import { queryOptions, useQuery } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import type { SdkConfig } from '../../types';
4
4
  import {
5
- AddressSchema,
6
- ChainIdSchema,
7
- OrderSide,
8
- QueryArgSchema,
9
- collectableKeys,
10
- getMarketplaceClient,
11
- } from "../_internal";
12
- import { collectiblesFilterSchema } from "../_internal/api/zod-schema";
13
- import { useConfig } from "./useConfig";
5
+ AddressSchema,
6
+ ChainIdSchema,
7
+ OrderSide,
8
+ QueryArgSchema,
9
+ collectableKeys,
10
+ getMarketplaceClient,
11
+ } from '../_internal';
12
+ import { collectiblesFilterSchema } from '../_internal/api/zod-schema';
13
+ import { useConfig } from './useConfig';
14
14
 
15
15
  const BaseSchema = z.object({
16
- chainId: ChainIdSchema.pipe(z.coerce.string()),
17
- collectionAddress: AddressSchema,
18
- query: QueryArgSchema,
16
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
17
+ collectionAddress: AddressSchema,
18
+ query: QueryArgSchema,
19
19
  });
20
20
 
21
21
  const UseCountOfCollectableSchema = BaseSchema.extend({
22
- filter: collectiblesFilterSchema,
23
- side: z.nativeEnum(OrderSide),
22
+ filter: collectiblesFilterSchema,
23
+ side: z.nativeEnum(OrderSide),
24
24
  }).or(
25
- BaseSchema.extend({
26
- filter: z.undefined(),
27
- side: z.undefined(),
28
- })
25
+ BaseSchema.extend({
26
+ filter: z.undefined(),
27
+ side: z.undefined(),
28
+ }),
29
29
  );
30
30
 
31
31
  export type UseCountOfCollectablesArgs = z.infer<
32
- typeof UseCountOfCollectableSchema
32
+ typeof UseCountOfCollectableSchema
33
33
  >;
34
34
 
35
35
  export type UseContOfCollectableReturn = Awaited<
36
- ReturnType<typeof fetchCountOfCollectables>
36
+ ReturnType<typeof fetchCountOfCollectables>
37
37
  >;
38
38
 
39
39
  const fetchCountOfCollectables = async (
40
- args: UseCountOfCollectablesArgs,
41
- config: SdkConfig
40
+ args: UseCountOfCollectablesArgs,
41
+ config: SdkConfig,
42
42
  ) => {
43
- const parsedArgs = UseCountOfCollectableSchema.parse(args);
44
- const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
45
- if (parsedArgs.filter) {
46
- return marketplaceClient
47
- .getCountOfFilteredCollectibles({
48
- ...parsedArgs,
49
- contractAddress: parsedArgs.collectionAddress,
50
- // biome-ignore lint/style/noNonNullAssertion: safe to assert here, as it's validated
51
- side: parsedArgs.side!,
52
- })
53
- .then((resp) => resp.count);
54
- }
55
- return marketplaceClient
56
- .getCountOfAllCollectibles({
57
- ...parsedArgs,
58
- contractAddress: parsedArgs.collectionAddress,
59
- })
60
- .then((resp) => resp.count);
43
+ const parsedArgs = UseCountOfCollectableSchema.parse(args);
44
+ const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
45
+ if (parsedArgs.filter) {
46
+ return marketplaceClient
47
+ .getCountOfFilteredCollectibles({
48
+ ...parsedArgs,
49
+ contractAddress: parsedArgs.collectionAddress,
50
+ // biome-ignore lint/style/noNonNullAssertion: safe to assert here, as it's validated
51
+ side: parsedArgs.side!,
52
+ })
53
+ .then((resp) => resp.count);
54
+ }
55
+ return marketplaceClient
56
+ .getCountOfAllCollectibles({
57
+ ...parsedArgs,
58
+ contractAddress: parsedArgs.collectionAddress,
59
+ })
60
+ .then((resp) => resp.count);
61
61
  };
62
62
 
63
63
  export const countOfCollectablesOptions = (
64
- args: UseCountOfCollectablesArgs,
65
- config: SdkConfig
64
+ args: UseCountOfCollectablesArgs,
65
+ config: SdkConfig,
66
66
  ) => {
67
- return queryOptions({
68
- ...args.query,
69
- queryKey: [...collectableKeys.counts, args],
70
- queryFn: () => fetchCountOfCollectables(args, config),
71
- });
67
+ return queryOptions({
68
+ ...args.query,
69
+ queryKey: [...collectableKeys.counts, args],
70
+ queryFn: () => fetchCountOfCollectables(args, config),
71
+ });
72
72
  };
73
73
 
74
74
  export const useCountOfCollectables = (args: UseCountOfCollectablesArgs) => {
75
- const config = useConfig();
76
- return useQuery(countOfCollectablesOptions(args, config));
75
+ const config = useConfig();
76
+ return useQuery(countOfCollectablesOptions(args, config));
77
77
  };
@@ -0,0 +1,65 @@
1
+ import { useState, useCallback } from 'react';
2
+ import type { Hash } from 'viem';
3
+ import {
4
+ type ListingInput,
5
+ TransactionType,
6
+ type TransactionSteps,
7
+ } from '../_internal/transaction-machine/execute-transaction';
8
+ import {
9
+ useTransactionMachine,
10
+ type UseTransactionMachineConfig,
11
+ } from '../_internal/transaction-machine/useTransactionMachine';
12
+
13
+ interface UseCreateListingArgs
14
+ extends Omit<UseTransactionMachineConfig, 'type'> {
15
+ onSuccess?: (hash: Hash) => void;
16
+ onError?: (error: Error) => void;
17
+ onTransactionSent?: (hash: Hash) => void;
18
+ }
19
+
20
+ export const useCreateListing = ({
21
+ onSuccess,
22
+ onError,
23
+ onTransactionSent,
24
+ ...config
25
+ }: UseCreateListingArgs) => {
26
+ const [isLoading, setIsLoading] = useState(false);
27
+ const [steps, setSteps] = useState<TransactionSteps | null>(null);
28
+
29
+ const machine = useTransactionMachine(
30
+ {
31
+ ...config,
32
+ type: TransactionType.LISTING,
33
+ },
34
+ onSuccess,
35
+ onError,
36
+ onTransactionSent,
37
+ );
38
+
39
+ const loadSteps = useCallback(
40
+ async (props: ListingInput) => {
41
+ if (!machine) return;
42
+ setIsLoading(true);
43
+ try {
44
+ const generatedSteps = await machine.getTransactionSteps(props);
45
+ setSteps(generatedSteps);
46
+ } catch (error) {
47
+ onError?.(error as Error);
48
+ } finally {
49
+ setIsLoading(false);
50
+ }
51
+ },
52
+ [machine, onError],
53
+ );
54
+
55
+ return {
56
+ createListing: (props: ListingInput) => machine?.start({ props }),
57
+ getListingSteps: (props: ListingInput) => ({
58
+ isLoading,
59
+ steps,
60
+ refreshSteps: () => loadSteps(props),
61
+ }),
62
+ onError,
63
+ onSuccess,
64
+ };
65
+ };
@@ -1,26 +1,26 @@
1
- import { queryOptions, useQuery } from "@tanstack/react-query";
2
- import { z } from "zod";
3
- import { useConfig } from "./useConfig";
1
+ import { queryOptions, useQuery } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import { useConfig } from './useConfig';
4
4
  import {
5
- ChainIdSchema,
6
- AddressSchema,
7
- QueryArgSchema,
8
- getMarketplaceClient,
9
- type Currency,
10
- getQueryClient,
11
- configKeys,
12
- currencyKeys,
13
- ChainId,
14
- } from "../_internal";
15
- import { SdkConfig, MarketplaceConfig } from "../../types";
5
+ ChainIdSchema,
6
+ AddressSchema,
7
+ QueryArgSchema,
8
+ getMarketplaceClient,
9
+ type Currency,
10
+ getQueryClient,
11
+ configKeys,
12
+ currencyKeys,
13
+ type ChainId,
14
+ } from '../_internal';
15
+ import type { SdkConfig, MarketplaceConfig } from '../../types';
16
16
 
17
17
  const ChainIdCoerce = ChainIdSchema.transform((val) => val.toString());
18
18
 
19
19
  const UseCurrenciesArgsSchema = z.object({
20
- chainId: ChainIdCoerce,
21
- collectionAddress: AddressSchema.optional(),
22
- includeNativeCurrency: z.boolean().optional(),
23
- query: QueryArgSchema,
20
+ chainId: ChainIdCoerce,
21
+ collectionAddress: AddressSchema.optional(),
22
+ includeNativeCurrency: z.boolean().optional(),
23
+ query: QueryArgSchema,
24
24
  });
25
25
 
26
26
  type UseCurrenciesArgs = z.input<typeof UseCurrenciesArgsSchema>;
@@ -28,60 +28,60 @@ type UseCurrenciesArgs = z.input<typeof UseCurrenciesArgsSchema>;
28
28
  export type UseCurrenciesReturn = Awaited<ReturnType<typeof fetchCurrencies>>;
29
29
 
30
30
  const fetchCurrencies = async (chainId: ChainId, config: SdkConfig) => {
31
- const parsedChainId = ChainIdCoerce.parse(chainId);
32
- const marketplaceClient = getMarketplaceClient(parsedChainId, config);
33
- return marketplaceClient.listCurrencies().then((resp) => resp.currencies);
31
+ const parsedChainId = ChainIdCoerce.parse(chainId);
32
+ const marketplaceClient = getMarketplaceClient(parsedChainId, config);
33
+ return marketplaceClient.listCurrencies().then((resp) => resp.currencies);
34
34
  };
35
35
 
36
36
  const selectCurrencies = (data: Currency[], args: UseCurrenciesArgs) => {
37
- const argsParsed = UseCurrenciesArgsSchema.parse(args);
38
- // if collectionAddress is passed, filter currencies based on collection currency options
39
- if (argsParsed.collectionAddress) {
40
- const queryClient = getQueryClient();
41
- const marketplaceConfigCache = queryClient.getQueriesData({
42
- queryKey: configKeys.marketplace,
43
- })[0][1] as MarketplaceConfig;
37
+ const argsParsed = UseCurrenciesArgsSchema.parse(args);
38
+ // if collectionAddress is passed, filter currencies based on collection currency options
39
+ if (argsParsed.collectionAddress) {
40
+ const queryClient = getQueryClient();
41
+ const marketplaceConfigCache = queryClient.getQueriesData({
42
+ queryKey: configKeys.marketplace,
43
+ })[0][1] as MarketplaceConfig;
44
44
 
45
- const collection = marketplaceConfigCache?.collections.find(
46
- (collection) =>
47
- collection.collectionAddress === argsParsed.collectionAddress
48
- );
45
+ const collection = marketplaceConfigCache?.collections.find(
46
+ (collection) =>
47
+ collection.collectionAddress === argsParsed.collectionAddress,
48
+ );
49
49
 
50
- if (!collection) {
51
- throw new Error("Collection doesn't exist");
52
- }
50
+ if (!collection) {
51
+ throw new Error("Collection doesn't exist");
52
+ }
53
53
 
54
- return data.filter(
55
- (currency) =>
56
- collection.currencyOptions?.includes(currency.contractAddress) ||
57
- // biome-ignore lint/suspicious/noDoubleEquals: <explanation>
58
- currency.nativeCurrency == argsParsed.includeNativeCurrency ||
59
- currency.defaultChainCurrency
60
- );
61
- }
62
- // if includeNativeCurrency is true, return all currencies
63
- if (argsParsed.includeNativeCurrency) {
64
- return data;
65
- }
54
+ return data.filter(
55
+ (currency) =>
56
+ collection.currencyOptions?.includes(currency.contractAddress) ||
57
+ // biome-ignore lint/suspicious/noDoubleEquals: <explanation>
58
+ currency.nativeCurrency == argsParsed.includeNativeCurrency ||
59
+ currency.defaultChainCurrency,
60
+ );
61
+ }
62
+ // if includeNativeCurrency is true, return all currencies
63
+ if (argsParsed.includeNativeCurrency) {
64
+ return data;
65
+ }
66
66
 
67
- // if includeNativeCurrency is false or undefined, filter out native currencies
68
- return data.filter((currency) => !currency.nativeCurrency);
67
+ // if includeNativeCurrency is false or undefined, filter out native currencies
68
+ return data.filter((currency) => !currency.nativeCurrency);
69
69
  };
70
70
 
71
71
  export const currenciesOptions = (
72
- args: UseCurrenciesArgs,
73
- config: SdkConfig
72
+ args: UseCurrenciesArgs,
73
+ config: SdkConfig,
74
74
  ) => {
75
- return queryOptions({
76
- ...args.query,
77
- queryKey: [...currencyKeys.lists, args.chainId],
78
- queryFn: () => fetchCurrencies(args.chainId, config),
79
- select: (data) => selectCurrencies(data, args),
80
- enabled: args.query?.enabled,
81
- });
75
+ return queryOptions({
76
+ ...args.query,
77
+ queryKey: [...currencyKeys.lists, args.chainId],
78
+ queryFn: () => fetchCurrencies(args.chainId, config),
79
+ select: (data) => selectCurrencies(data, args),
80
+ enabled: args.query?.enabled,
81
+ });
82
82
  };
83
83
 
84
84
  export const useCurrencies = (args: UseCurrenciesArgs) => {
85
- const config = useConfig();
86
- return useQuery(currenciesOptions(args, config));
85
+ const config = useConfig();
86
+ return useQuery(currenciesOptions(args, config));
87
87
  };
@@ -0,0 +1,64 @@
1
+ import { queryOptions, useQuery } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import { useConfig } from './useConfig';
4
+ import {
5
+ ChainIdSchema,
6
+ AddressSchema,
7
+ QueryArgSchema,
8
+ getMarketplaceClient,
9
+ type Currency,
10
+ currencyKeys,
11
+ type ChainId,
12
+ getQueryClient,
13
+ } from '../_internal';
14
+ import type { SdkConfig } from '../../types';
15
+
16
+ const ChainIdCoerce = ChainIdSchema.transform((val) => val.toString());
17
+
18
+ const UseCurrencyArgsSchema = z.object({
19
+ chainId: ChainIdCoerce,
20
+ currencyAddress: AddressSchema,
21
+ query: QueryArgSchema,
22
+ });
23
+
24
+ type UseCurrencyArgs = z.input<typeof UseCurrencyArgsSchema>;
25
+
26
+ export type UseCurrencyReturn = Currency | undefined;
27
+
28
+ const fetchCurrency = async (
29
+ chainId: ChainId,
30
+ currencyAddress: string,
31
+ config: SdkConfig,
32
+ ): Promise<Currency | undefined> => {
33
+ const parsedChainId = ChainIdCoerce.parse(chainId);
34
+
35
+ const queryClient = getQueryClient();
36
+ let currencies = queryClient.getQueryData([...currencyKeys.lists, chainId]) as
37
+ | Currency[]
38
+ | undefined;
39
+
40
+ if (!currencies) {
41
+ const marketplaceClient = getMarketplaceClient(parsedChainId, config);
42
+ currencies = await marketplaceClient
43
+ .listCurrencies()
44
+ .then((resp) => resp.currencies);
45
+ }
46
+
47
+ return currencies?.find(
48
+ (currency) =>
49
+ currency.contractAddress.toLowerCase() === currencyAddress.toLowerCase(),
50
+ );
51
+ };
52
+
53
+ export const currencyOptions = (args: UseCurrencyArgs, config: SdkConfig) => {
54
+ return queryOptions({
55
+ ...args.query,
56
+ queryKey: [...currencyKeys.details, args.chainId, args.currencyAddress],
57
+ queryFn: () => fetchCurrency(args.chainId, args.currencyAddress, config),
58
+ });
59
+ };
60
+
61
+ export const useCurrency = (args: UseCurrencyArgs) => {
62
+ const config = useConfig();
63
+ return useQuery(currencyOptions(args, config));
64
+ };
@@ -0,0 +1,71 @@
1
+ import { queryOptions, useQuery } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import type { SdkConfig } from '../../types';
4
+ import {
5
+ AddressSchema,
6
+ ChainIdSchema,
7
+ getMarketplaceClient,
8
+ MarketplaceKind,
9
+ QueryArgSchema,
10
+ WalletKind,
11
+ } from '../_internal';
12
+ import { useConfig } from './useConfig';
13
+ import { useAccount } from 'wagmi';
14
+ import type { Hex } from 'viem';
15
+
16
+ export const UseGenerateBuyTransactionArgsSchema = z.object({
17
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
18
+ collectionAddress: AddressSchema,
19
+ marketplace: z.nativeEnum(MarketplaceKind),
20
+ ordersData: z.array(
21
+ z.object({
22
+ orderId: z.string(),
23
+ quantity: z.string(),
24
+ marketplace: z.string(),
25
+ }),
26
+ ),
27
+ walletType: z.nativeEnum(WalletKind).optional(),
28
+ query: QueryArgSchema,
29
+ });
30
+
31
+ type UseGenerateBuyTransactionArgs = z.infer<
32
+ typeof UseGenerateBuyTransactionArgsSchema
33
+ >;
34
+
35
+ export const fetchGenerateBuyTransaction = async (
36
+ args: UseGenerateBuyTransactionArgs & { buyer: Hex },
37
+ config: SdkConfig,
38
+ ) => {
39
+ const parsedArgs = UseGenerateBuyTransactionArgsSchema.parse(args);
40
+ const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
41
+
42
+ return marketplaceClient
43
+ .generateBuyTransaction({
44
+ ...parsedArgs,
45
+ buyer: args.buyer,
46
+ additionalFees: [], // TODO: Add additional fees
47
+ })
48
+ .then((data) => data.steps);
49
+ };
50
+
51
+ export const generateBuyTransactionOptions = (
52
+ args: UseGenerateBuyTransactionArgs & { buyer: Hex },
53
+ config: SdkConfig,
54
+ ) => {
55
+ return queryOptions({
56
+ queryKey: ['generateBuyTransaction', args],
57
+ queryFn: () => fetchGenerateBuyTransaction(args, config),
58
+ ...args.query,
59
+ });
60
+ };
61
+
62
+ export const useGenerateBuyTransaction = (
63
+ args: UseGenerateBuyTransactionArgs,
64
+ ) => {
65
+ const { address } = useAccount();
66
+ const config = useConfig();
67
+ return useQuery(
68
+ // biome-ignore lint/style/noNonNullAssertion: <explanation>
69
+ generateBuyTransactionOptions({ buyer: address!, ...args }, config),
70
+ );
71
+ };
@@ -0,0 +1,50 @@
1
+ import { useMutation } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import type { SdkConfig } from '../../types';
4
+ import {
5
+ type ChainId,
6
+ ChainIdSchema,
7
+ type GenerateCancelTransactionArgs,
8
+ getMarketplaceClient,
9
+ } from '../_internal';
10
+ import { stepSchema } from '../_internal/api/zod-schema';
11
+ import { useConfig } from './useConfig';
12
+
13
+ const UserGenerateCancelTransactionArgsSchema = z.object({
14
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
15
+ onSuccess: z.function().args(stepSchema.array().optional()).optional(),
16
+ });
17
+
18
+ type UseGenerateCancelTransactionArgs = z.infer<
19
+ typeof UserGenerateCancelTransactionArgsSchema
20
+ >;
21
+
22
+ export const generateCancelTransaction = async (
23
+ args: GenerateCancelTransactionArgs,
24
+ config: SdkConfig,
25
+ chainId: ChainId,
26
+ ) => {
27
+ const parsedChainId = ChainIdSchema.pipe(z.coerce.string()).parse(chainId);
28
+ const marketplaceClient = getMarketplaceClient(parsedChainId, config);
29
+ return marketplaceClient
30
+ .generateCancelTransaction(args)
31
+ .then((data) => data.steps);
32
+ };
33
+
34
+ export const useGenerateCancelTransaction = (
35
+ params: UseGenerateCancelTransactionArgs,
36
+ ) => {
37
+ const config = useConfig();
38
+
39
+ const { mutate, mutateAsync, ...result } = useMutation({
40
+ onSuccess: params.onSuccess,
41
+ mutationFn: (args: GenerateCancelTransactionArgs) =>
42
+ generateCancelTransaction(args, config, params.chainId),
43
+ });
44
+
45
+ return {
46
+ ...result,
47
+ generateCancelTransaction: mutate,
48
+ generateCancelTransactionAsync: mutateAsync,
49
+ };
50
+ };