@0xsequence/marketplace-sdk 0.0.1 → 0.2.0

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 (144) hide show
  1. package/.ctirc +32 -0
  2. package/dist/{chunk-TZGLKJRF.js → chunk-4E34HVSA.js} +2 -2
  3. package/dist/chunk-5EOVZAKT.js +1325 -0
  4. package/dist/chunk-5EOVZAKT.js.map +1 -0
  5. package/dist/{chunk-RNUHUVLC.js → chunk-6JWGELXL.js} +1 -1
  6. package/dist/chunk-6JWGELXL.js.map +1 -0
  7. package/dist/{chunk-4PFMUVE4.js → chunk-CSN7YD5Q.js} +2 -2
  8. package/dist/chunk-CSN7YD5Q.js.map +1 -0
  9. package/dist/{chunk-G3D572BT.js → chunk-FCQCNLFZ.js} +24 -1
  10. package/dist/chunk-FCQCNLFZ.js.map +1 -0
  11. package/dist/{chunk-HGBEC3WX.js → chunk-GZIA25G4.js} +1 -1
  12. package/dist/chunk-GZIA25G4.js.map +1 -0
  13. package/dist/{chunk-QOJXWHRZ.js → chunk-LFQB477Y.js} +3 -1
  14. package/dist/chunk-LFQB477Y.js.map +1 -0
  15. package/dist/{chunk-SM7V6ZWI.js → chunk-MD4JHPMH.js} +493 -418
  16. package/dist/chunk-MD4JHPMH.js.map +1 -0
  17. package/dist/{chunk-EDTC7UES.js → chunk-NII6JJGH.js} +9 -4
  18. package/dist/chunk-NII6JJGH.js.map +1 -0
  19. package/dist/{chunk-BBB3XUB4.js → chunk-PE2LLUTJ.js} +1 -1
  20. package/dist/chunk-PE2LLUTJ.js.map +1 -0
  21. package/dist/chunk-Q2BVDQ3G.js +41 -0
  22. package/dist/chunk-Q2BVDQ3G.js.map +1 -0
  23. package/dist/{chunk-3TYUQEFM.js → chunk-VEX7FDL6.js} +2 -2
  24. package/dist/chunk-VEX7FDL6.js.map +1 -0
  25. package/dist/{create-config-Dz0gCiQ0.d.ts → create-config-CgtmCzvb.d.ts} +2 -2
  26. package/dist/index.css +4 -1
  27. package/dist/index.d.ts +3 -2
  28. package/dist/index.js +4 -4
  29. package/dist/{marketplace-config-DZbtyrma.d.ts → marketplace-config-Bbxl-uKX.d.ts} +2 -1
  30. package/dist/react/_internal/api/index.d.ts +1 -1
  31. package/dist/react/_internal/api/index.js +1 -1
  32. package/dist/react/_internal/index.d.ts +5 -4
  33. package/dist/react/_internal/index.js +16 -8
  34. package/dist/react/_internal/wagmi/index.d.ts +3 -3
  35. package/dist/react/_internal/wagmi/index.js +1 -1
  36. package/dist/react/hooks/index.d.ts +1691 -103
  37. package/dist/react/hooks/index.js +34 -22
  38. package/dist/react/index.css +4 -1
  39. package/dist/react/index.css.map +1 -1
  40. package/dist/react/index.d.ts +7 -6
  41. package/dist/react/index.js +43 -31
  42. package/dist/react/ssr/index.d.ts +26 -25
  43. package/dist/react/ssr/index.js +34 -4
  44. package/dist/react/ssr/index.js.map +1 -1
  45. package/dist/react/ui/icons/index.js +2 -2
  46. package/dist/react/ui/index.css +4 -1
  47. package/dist/react/ui/index.css.map +1 -1
  48. package/dist/react/ui/index.d.ts +47 -42
  49. package/dist/react/ui/index.js +10 -10
  50. package/dist/react/ui/modals/_internal/components/actionModal/index.js +4 -4
  51. package/dist/{services-BIwQ1C1c.d.ts → services-Dei25J6_.d.ts} +1 -1
  52. package/dist/styles/index.css +4 -1
  53. package/dist/styles/index.css.map +1 -1
  54. package/dist/styles/index.d.ts +2 -1
  55. package/dist/styles/index.js +4 -4973
  56. package/dist/styles/index.js.map +1 -1
  57. package/dist/types/index.d.ts +2 -1
  58. package/dist/types/index.js +3 -3
  59. package/dist/types-BzZVURNL.d.ts +19 -0
  60. package/dist/utils/abi/clients/index.js +1 -1
  61. package/dist/utils/index.d.ts +2 -1
  62. package/dist/utils/index.js +2 -2
  63. package/package.json +19 -25
  64. package/src/react/_internal/api/marketplace.gen.ts +4 -1
  65. package/src/react/_internal/api/zod-schema.ts +636 -0
  66. package/src/react/_internal/types.ts +33 -9
  67. package/src/react/_internal/wagmi/create-config.ts +9 -3
  68. package/src/react/_internal/wagmi/embedded.ts +1 -1
  69. package/src/react/_internal/wagmi/universal.ts +1 -1
  70. package/src/react/hooks/index.ts +3 -0
  71. package/src/react/hooks/options/marketplaceConfigOptions.ts +2 -2
  72. package/src/react/hooks/useBalanceOfCollectible.tsx +47 -21
  73. package/src/react/hooks/useCheckoutOptions.tsx +63 -0
  74. package/src/react/hooks/useCollectible.tsx +20 -14
  75. package/src/react/hooks/useCollection.tsx +18 -12
  76. package/src/react/hooks/useCountOfCollectables.tsx +77 -0
  77. package/src/react/hooks/useCurrencies.tsx +67 -56
  78. package/src/react/hooks/useFilters.tsx +18 -12
  79. package/src/react/hooks/useFloorOrder.tsx +24 -9
  80. package/src/react/hooks/useGenerateListingTransaction.tsx +8 -7
  81. package/src/react/hooks/useGenerateOfferTransaction.tsx +5 -5
  82. package/src/react/hooks/useGenerateSellTransaction.tsx +19 -12
  83. package/src/react/hooks/useHighestOffer.tsx +26 -16
  84. package/src/react/hooks/useListBalances.tsx +60 -29
  85. package/src/react/hooks/useListCollectibles.tsx +28 -15
  86. package/src/react/hooks/useListOffersForCollectible.tsx +17 -8
  87. package/src/react/hooks/useLowestListing.tsx +26 -17
  88. package/src/react/hooks/useRoyaltyPercentage.tsx +18 -8
  89. package/src/react/hooks/useTransferTokens.tsx +3 -3
  90. package/src/react/provider.tsx +1 -1
  91. package/src/react/ssr/create-ssr-client.ts +1 -1
  92. package/src/react/ui/modals/CreateListingModal/_store.ts +39 -40
  93. package/src/react/ui/modals/CreateListingModal/index.tsx +152 -130
  94. package/src/react/ui/modals/MakeOfferModal/_store.ts +38 -43
  95. package/src/react/ui/modals/MakeOfferModal/index.tsx +39 -28
  96. package/src/react/ui/modals/SellModal/_store.ts +59 -57
  97. package/src/react/ui/modals/SellModal/index.tsx +34 -12
  98. package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +1 -1
  99. package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +14 -14
  100. package/src/react/ui/modals/TransferModal/_store.ts +11 -11
  101. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +92 -89
  102. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +114 -0
  103. package/src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx +0 -96
  104. package/src/react/ui/modals/TransferModal/index.tsx +24 -3
  105. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +1 -1
  106. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +4 -4
  107. package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +4 -3
  108. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +55 -12
  109. package/src/react/ui/modals/_internal/components/priceInput/styles.css.ts +4 -0
  110. package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +3 -2
  111. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +4 -4
  112. package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +4 -4
  113. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +3 -2
  114. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +7 -5
  115. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +6 -6
  116. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +47 -14
  117. package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +14 -6
  118. package/src/types/api-types.ts +2 -2
  119. package/src/types/callbacks.ts +51 -0
  120. package/src/types/marketplace-config.ts +2 -1
  121. package/src/types/types.ts +1 -1
  122. package/src/utils/get-public-rpc-client.ts +1 -1
  123. package/tsconfig.json +24 -0
  124. package/tsconfig.tsbuildinfo +1 -0
  125. package/tsup.config.ts +35 -0
  126. package/README.md +0 -8
  127. package/dist/chunk-3TYUQEFM.js.map +0 -1
  128. package/dist/chunk-4PFMUVE4.js.map +0 -1
  129. package/dist/chunk-BBB3XUB4.js.map +0 -1
  130. package/dist/chunk-EDTC7UES.js.map +0 -1
  131. package/dist/chunk-G3D572BT.js.map +0 -1
  132. package/dist/chunk-HGBEC3WX.js.map +0 -1
  133. package/dist/chunk-QOJXWHRZ.js.map +0 -1
  134. package/dist/chunk-RNUHUVLC.js.map +0 -1
  135. package/dist/chunk-SM7V6ZWI.js.map +0 -1
  136. package/dist/chunk-STO74F2I.js +0 -14
  137. package/dist/chunk-STO74F2I.js.map +0 -1
  138. package/dist/chunk-VPGWEMWL.js +0 -162
  139. package/dist/chunk-VPGWEMWL.js.map +0 -1
  140. package/dist/chunk-ZE2LNX65.js +0 -394
  141. package/dist/chunk-ZE2LNX65.js.map +0 -1
  142. package/dist/types-BrAQ8-w4.d.ts +0 -12
  143. package/src/react/hooks/useCollectionCounts.tsx +0 -61
  144. /package/dist/{chunk-TZGLKJRF.js.map → chunk-4E34HVSA.js.map} +0 -0
@@ -1,10 +1,12 @@
1
+ import { useMutation } from '@tanstack/react-query';
2
+ import type { SdkConfig } from '../../types';
1
3
  import {
2
4
  type ChainId,
5
+ type CreateReq,
3
6
  type GenerateOfferTransactionArgs,
7
+ type Step,
4
8
  getMarketplaceClient,
5
- } from '@internal';
6
- import { useMutation } from '@tanstack/react-query';
7
- import type { SdkConfig, Step } from '@types';
9
+ } from '../_internal';
8
10
  import { useConfig } from './useConfig';
9
11
 
10
12
  export type UseGenerateOfferTransactionArgs = {
@@ -12,8 +14,6 @@ export type UseGenerateOfferTransactionArgs = {
12
14
  onSuccess?: (data?: Step[]) => void;
13
15
  };
14
16
 
15
- import type { CreateReq } from '@types';
16
-
17
17
  type CreateReqWithDateExpiry = Omit<CreateReq, 'expiry'> & {
18
18
  expiry: Date;
19
19
  };
@@ -1,27 +1,34 @@
1
+ import { useMutation } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import type { SdkConfig } from '../../types';
1
4
  import {
2
5
  type ChainId,
6
+ ChainIdSchema,
3
7
  type GenerateSellTransactionArgs,
4
8
  getMarketplaceClient,
5
- } from '@internal';
6
- import { useMutation } from '@tanstack/react-query';
7
- import type { SdkConfig } from '@types';
9
+ } from '../_internal';
10
+ import { stepSchema } from '../_internal/api/zod-schema';
8
11
  import { useConfig } from './useConfig';
9
12
 
10
- export type UseGenerateSellTransactionArgs = {
11
- chainId: ChainId;
12
- onSuccess?: () => void | Promise<void>;
13
- };
13
+ const UserGeneratSellTransactionArgsSchema = z.object({
14
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
15
+ onSuccess: z.function().args(stepSchema.array().optional()).optional(),
16
+ });
17
+
18
+ type UseGenerateSellTransactionArgs = z.infer<
19
+ typeof UserGeneratSellTransactionArgsSchema
20
+ >;
14
21
 
15
22
  export const generateSellTransaction = async (
16
23
  args: GenerateSellTransactionArgs,
17
24
  config: SdkConfig,
18
25
  chainId: ChainId,
19
26
  ) => {
20
- console.log('generateSellTransaction');
21
- console.log(args);
22
- console.log(chainId);
23
- const marketplaceClient = getMarketplaceClient(chainId, config);
24
- return marketplaceClient.generateSellTransaction(args);
27
+ const parsedChainId = ChainIdSchema.pipe(z.coerce.string()).parse(chainId);
28
+ const marketplaceClient = getMarketplaceClient(parsedChainId, config);
29
+ return marketplaceClient
30
+ .generateSellTransaction(args)
31
+ .then((data) => data.steps);
25
32
  };
26
33
 
27
34
  export const useGenerateSellTransaction = (
@@ -1,31 +1,41 @@
1
+ import { queryOptions, useQuery } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import type { SdkConfig } from '../../types';
1
4
  import {
2
- type GetCollectibleHighestOfferArgs,
3
- type QueryArg,
5
+ AddressSchema,
6
+ ChainIdSchema,
7
+ QueryArgSchema,
4
8
  collectableKeys,
5
9
  getMarketplaceClient,
6
- } from '@internal';
7
- import { queryOptions, useQuery } from '@tanstack/react-query';
8
- import type { SdkConfig } from '@types';
10
+ } from '../_internal';
11
+ import { getCollectibleHighestOfferArgsSchema } from '../_internal/api/zod-schema';
9
12
  import { useConfig } from './useConfig';
10
13
 
11
- export type UseHighestOfferArgs = Omit<
12
- GetCollectibleHighestOfferArgs,
13
- 'contractAddress'
14
- > & {
15
- collectionAddress: string;
16
- chainId: string;
17
- } & QueryArg;
14
+ const UseHighestOfferArgsSchema = getCollectibleHighestOfferArgsSchema
15
+ .omit({
16
+ contractAddress: true,
17
+ })
18
+ .extend({
19
+ collectionAddress: AddressSchema,
20
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
21
+ query: QueryArgSchema,
22
+ });
23
+
24
+ export type UseHighestOfferArgs = z.infer<typeof UseHighestOfferArgsSchema>;
18
25
 
19
- export type UseHighestOfferReturn = ReturnType<typeof fetchHighestOffer>;
26
+ export type UseHighestOfferReturn = Awaited<
27
+ ReturnType<typeof fetchHighestOffer>
28
+ >;
20
29
 
21
30
  const fetchHighestOffer = async (
22
31
  args: UseHighestOfferArgs,
23
32
  config: SdkConfig,
24
33
  ) => {
25
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
34
+ const parsedArgs = UseHighestOfferArgsSchema.parse(args);
35
+ const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
26
36
  return marketplaceClient.getCollectibleHighestOffer({
27
- ...args,
28
- contractAddress: args.collectionAddress,
37
+ ...parsedArgs,
38
+ contractAddress: parsedArgs.collectionAddress,
29
39
  });
30
40
  };
31
41
 
@@ -1,56 +1,87 @@
1
- import type { MetadataOptions, Page } from '@0xsequence/indexer';
1
+ import { type Page, SortOrder } from '@0xsequence/indexer';
2
+ import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
3
+ import { z } from 'zod';
4
+ import type { SdkConfig } from '../../types';
2
5
  import {
3
- type ChainId,
4
- type QueryArg,
6
+ AddressSchema,
7
+ ChainIdSchema,
8
+ QueryArgSchema,
5
9
  balanceQueries,
6
10
  getIndexerClient,
7
- } from '@internal';
8
- import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
9
- import type { SdkConfig } from '@types';
11
+ } from '../_internal';
10
12
  import { useConfig } from './useConfig';
11
13
 
12
- export type UseTokenBalancesArgs = {
13
- chainId: ChainId;
14
- accountAddress?: string;
15
- contractAddress?: string;
16
- tokenId?: string;
17
- includeMetadata?: boolean;
18
- metadataOptions?: MetadataOptions;
19
- includeCollectionTokens?: boolean;
20
- page?: Page;
21
- } & QueryArg;
22
-
23
- export type UseFetchTokenBalancesReturn = ReturnType<typeof fetchTokenBalances>;
24
-
25
- const fetchTokenBalances = async (
26
- args: UseTokenBalancesArgs,
14
+ export const metadataOptionsSchema = z.object({
15
+ verifiedOnly: z.boolean().optional(),
16
+ unverifiedOnly: z.boolean().optional(),
17
+ includeContracts: z.array(z.string()).optional(),
18
+ });
19
+
20
+ const sortOrderSchema = z.nativeEnum(SortOrder);
21
+
22
+ const sortBySchema = z.object({
23
+ column: z.string(),
24
+ order: sortOrderSchema,
25
+ });
26
+
27
+ const pageSchema = z.object({
28
+ page: z.number().optional(),
29
+ column: z.string().optional(),
30
+ before: z.any().optional(),
31
+ after: z.any().optional(),
32
+ sort: z.array(sortBySchema).optional(),
33
+ pageSize: z.number().optional(),
34
+ more: z.boolean().optional(),
35
+ });
36
+
37
+ const useListBalancesArgsSchema = z.object({
38
+ chainId: ChainIdSchema.pipe(z.coerce.number()),
39
+ accountAddress: AddressSchema.optional(),
40
+ contractAddress: AddressSchema.optional(),
41
+ tokenId: z.string().optional(),
42
+ includeMetadata: z.boolean().optional(),
43
+ metadataOptions: metadataOptionsSchema.optional(),
44
+ includeCollectionTokens: z.boolean().optional(),
45
+ page: pageSchema.optional(),
46
+ query: QueryArgSchema,
47
+ });
48
+
49
+ export type UseFetchTokenBalancesReturn = Awaited<
50
+ ReturnType<typeof fetchBalances>
51
+ >;
52
+
53
+ export type UseListBalancesArgs = z.input<typeof useListBalancesArgsSchema>;
54
+
55
+ const fetchBalances = async (
56
+ args: UseListBalancesArgs,
27
57
  page: Page,
28
58
  config: SdkConfig,
29
59
  ) => {
30
- const indexerClient = getIndexerClient(args.chainId, config);
60
+ const parsedArgs = useListBalancesArgsSchema.parse(args);
61
+ const indexerClient = getIndexerClient(parsedArgs.chainId, config);
31
62
 
32
63
  return indexerClient.getTokenBalances({
33
- ...args,
34
- tokenID: args.tokenId,
64
+ ...parsedArgs,
65
+ tokenID: parsedArgs.tokenId,
35
66
  page: page,
36
67
  });
37
68
  };
38
69
 
39
- export const tokenBalancesOptions = (
40
- args: UseTokenBalancesArgs,
70
+ export const listBalancesOptions = (
71
+ args: UseListBalancesArgs,
41
72
  config: SdkConfig,
42
73
  ) => {
43
74
  return infiniteQueryOptions({
44
75
  ...args.query,
45
76
  queryKey: [...balanceQueries.lists, args, config],
46
77
  queryFn: ({ pageParam }: { pageParam: Page }) =>
47
- fetchTokenBalances(args, pageParam, config),
78
+ fetchBalances(args, pageParam, config),
48
79
  initialPageParam: { page: 1, pageSize: 30 } as Page,
49
80
  getNextPageParam: (lastPage) => lastPage.page.after,
50
81
  });
51
82
  };
52
83
 
53
- export const useTokenBalances = (args: UseTokenBalancesArgs) => {
84
+ export const useListBalances = (args: UseListBalancesArgs) => {
54
85
  const config = useConfig();
55
- return useInfiniteQuery(tokenBalancesOptions(args, config));
86
+ return useInfiniteQuery(listBalancesOptions(args, config));
56
87
  };
@@ -1,32 +1,45 @@
1
+ import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import type { SdkConfig } from '../../types';
1
4
  import {
2
- type ChainId,
5
+ AddressSchema,
6
+ ChainIdSchema,
3
7
  type ListCollectiblesArgs,
4
8
  type Page,
9
+ QueryArgSchema,
5
10
  collectableKeys,
6
11
  getMarketplaceClient,
7
- } from '@internal';
8
- import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
9
- import type { SdkConfig } from '@types';
12
+ } from '../_internal';
13
+ import { listCollectiblesArgsSchema } from '../_internal/api/zod-schema';
10
14
  import { useConfig } from './useConfig';
11
15
 
12
- export type UseListCollectiblesArgs = Omit<
13
- ListCollectiblesArgs,
14
- 'contractAddress'
15
- > & {
16
- collectionAddress: string;
17
- chainId: ChainId;
18
- };
16
+ const UseListCollectiblesArgsSchema = listCollectiblesArgsSchema
17
+ .omit({
18
+ contractAddress: true,
19
+ })
20
+ .extend({
21
+ collectionAddress: AddressSchema,
22
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
23
+ query: QueryArgSchema,
24
+ });
25
+
26
+ export type UseListCollectiblesArgs = z.infer<
27
+ typeof UseListCollectiblesArgsSchema
28
+ >;
19
29
 
20
- export type UseListCollectiblesReturn = ReturnType<typeof fetchCollectibles>;
30
+ export type UseListCollectiblesReturn = Awaited<
31
+ ReturnType<typeof fetchCollectibles>
32
+ >;
21
33
 
22
34
  const fetchCollectibles = async (
23
35
  args: UseListCollectiblesArgs,
24
36
  page: Page,
25
- marketplaceClient: ReturnType<typeof getMarketplaceClient>,
37
+ marketplaceClient: Awaited<ReturnType<typeof getMarketplaceClient>>,
26
38
  ) => {
39
+ const parsedArgs = UseListCollectiblesArgsSchema.parse(args);
27
40
  const arg = {
28
- ...args,
29
- contractAddress: args.collectionAddress,
41
+ ...parsedArgs,
42
+ contractAddress: parsedArgs.collectionAddress,
30
43
  page,
31
44
  } satisfies ListCollectiblesArgs;
32
45
 
@@ -1,18 +1,27 @@
1
+ import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import type { SdkConfig } from '../../types';
1
4
  import {
5
+ ChainIdSchema,
2
6
  type ListOffersForCollectibleArgs,
7
+ type Page,
3
8
  collectableKeys,
4
9
  getMarketplaceClient,
5
- } from '@internal';
6
- import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
7
- import type { Page, SdkConfig } from '@types';
10
+ } from '../_internal';
11
+ import { listOffersForCollectibleArgsSchema } from '../_internal/api/zod-schema';
8
12
  import { useConfig } from './useConfig';
9
13
 
10
- export type UseListOffersForCollectibleArgs = ListOffersForCollectibleArgs & {
11
- chainId: string;
12
- };
14
+ const UseListOffersForCollectibleArgsSchema =
15
+ listOffersForCollectibleArgsSchema.extend({
16
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
17
+ });
18
+
19
+ type UseListOffersForCollectibleArgs = z.infer<
20
+ typeof UseListOffersForCollectibleArgsSchema
21
+ >;
13
22
 
14
- export type UseListOffersForCollectible = ReturnType<
15
- typeof fetchListOffersForCollectible
23
+ export type UseListOffersForCollectibleReturn = Awaited<
24
+ ReturnType<typeof fetchListOffersForCollectible>
16
25
  >;
17
26
 
18
27
  const fetchListOffersForCollectible = async (
@@ -1,32 +1,41 @@
1
+ import { queryOptions, useQuery } from '@tanstack/react-query';
2
+ import { z } from 'zod';
3
+ import type { SdkConfig } from '../../types';
1
4
  import {
2
- type ChainId,
3
- type GetCollectibleLowestListingArgs,
4
- type QueryArg,
5
+ AddressSchema,
6
+ ChainIdSchema,
7
+ QueryArgSchema,
5
8
  collectableKeys,
6
9
  getMarketplaceClient,
7
- } from '@internal';
8
- import { queryOptions, useQuery } from '@tanstack/react-query';
9
- import type { SdkConfig } from '@types';
10
+ } from '../_internal';
11
+ import { getCollectibleLowestListingArgsSchema } from '../_internal/api/zod-schema';
10
12
  import { useConfig } from './useConfig';
11
13
 
12
- export type UseLowestListingArgs = Omit<
13
- GetCollectibleLowestListingArgs,
14
- 'contractAddress'
15
- > & {
16
- collectionAddress: string;
17
- chainId: ChainId;
18
- } & QueryArg;
14
+ const UseLowestListingSchema = getCollectibleLowestListingArgsSchema
15
+ .omit({
16
+ contractAddress: true,
17
+ })
18
+ .extend({
19
+ collectionAddress: AddressSchema,
20
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
21
+ query: QueryArgSchema,
22
+ });
23
+
24
+ export type UseLowestListingArgs = z.infer<typeof UseLowestListingSchema>;
19
25
 
20
- export type UseLowestListingReturn = ReturnType<typeof fetchLowestListing>;
26
+ export type UseLowestListingReturn = Awaited<
27
+ ReturnType<typeof fetchLowestListing>
28
+ >;
21
29
 
22
30
  const fetchLowestListing = async (
23
31
  args: UseLowestListingArgs,
24
32
  config: SdkConfig,
25
33
  ) => {
26
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
34
+ const parsedArgs = UseLowestListingSchema.parse(args);
35
+ const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
27
36
  return marketplaceClient.getCollectibleLowestListing({
28
- ...args,
29
- contractAddress: args.collectionAddress,
37
+ ...parsedArgs,
38
+ contractAddress: parsedArgs.collectionAddress,
30
39
  });
31
40
  };
32
41
 
@@ -1,21 +1,31 @@
1
- import { type ChainId, type QueryArg, collectableKeys } from '@internal';
2
1
  import { queryOptions, useQuery } from '@tanstack/react-query';
3
2
  import type { Hex } from 'viem';
4
3
  import { getContract } from 'viem';
4
+ import { z } from 'zod';
5
5
  import { EIP2981_ABI } from '../../utils/abi/abi/standard/EIP2981';
6
6
  import { getPublicRpcClient } from '../../utils/get-public-rpc-client';
7
+ import {
8
+ AddressSchema,
9
+ ChainIdSchema,
10
+ QueryArgSchema,
11
+ collectableKeys,
12
+ } from '../_internal';
7
13
 
8
- type UseRoyaletyPercentageArgs = {
9
- chainId: ChainId;
10
- collectionAddress: string;
11
- collectibleId: string;
12
- } & QueryArg;
14
+ const UseRoyaletyPercentageSchema = z.object({
15
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
16
+ collectionAddress: AddressSchema,
17
+ collectibleId: z.string(),
18
+ query: QueryArgSchema,
19
+ });
20
+
21
+ type UseRoyaletyPercentageArgs = z.infer<typeof UseRoyaletyPercentageSchema>;
13
22
 
14
23
  const fetchRoyaletyPercentage = async (args: UseRoyaletyPercentageArgs) => {
15
- const publicClient = getPublicRpcClient(args.chainId);
24
+ const parsedArgs = UseRoyaletyPercentageSchema.parse(args);
25
+ const publicClient = getPublicRpcClient(parsedArgs.chainId);
16
26
 
17
27
  const contract = getContract({
18
- address: args.collectionAddress as Hex,
28
+ address: parsedArgs.collectionAddress as Hex,
19
29
  abi: EIP2981_ABI,
20
30
  client: publicClient,
21
31
  });
@@ -1,7 +1,7 @@
1
- import type { ContractType, ChainId } from '@internal';
2
- import { ERC1155_ABI } from '../../utils';
3
- import { type Abi, erc721Abi, type Address, type Hex } from 'viem';
1
+ import { type Abi, type Address, type Hex, erc721Abi } from 'viem';
4
2
  import { useAccount, useWriteContract } from 'wagmi';
3
+ import { ERC1155_ABI } from '../../utils';
4
+ import type { ChainId, ContractType } from '../_internal';
5
5
 
6
6
  interface BaseTransferParams {
7
7
  chainId: ChainId;
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { createContext } from 'react';
4
4
  import '@0xsequence/design-system/styles.css';
5
- import type { SdkConfig } from '@types';
5
+ import type { SdkConfig } from '../types';
6
6
  import { PROVIDER_ID } from './_internal/get-provider';
7
7
 
8
8
  export const MarketplaceSdkContext = createContext({} as SdkConfig);
@@ -2,7 +2,7 @@ import { type State, cookieToInitialState } from 'wagmi';
2
2
  import type { SdkConfig } from '../../types/sdk-config';
3
3
  import { getQueryClient } from '../_internal/api/get-query-client';
4
4
  import { createWagmiConfig } from '../_internal/wagmi/create-config';
5
- import { marketplaceConfigOptions } from '../hooks/options/marketplaceConfigOptions.ts';
5
+ import { marketplaceConfigOptions } from '../hooks/options/marketplaceConfigOptions';
6
6
 
7
7
  type InitSSRClientArgs = {
8
8
  cookie: string;
@@ -1,27 +1,34 @@
1
1
  import { observable, when } from '@legendapp/state';
2
2
  import { useMount, useSelector } from '@legendapp/state/react';
3
- import { useCollection } from '@react-hooks/useCollection';
4
- import { useGenerateListingTransaction } from '@react-hooks/useGenerateListingTransaction';
3
+ import type { QueryKey } from '@tanstack/react-query';
4
+ import { addDays } from 'date-fns/addDays';
5
+ import type { Hex } from 'viem';
6
+ import { useAccount, useSendTransaction } from 'wagmi';
7
+ import type { ShowCreateListingModalArgs } from '.';
8
+ import type { Price } from '../../../../types';
9
+ import type {
10
+ CreateListingErrorCallbacks,
11
+ CreateListingSuccessCallbacks,
12
+ } from '../../../../types/callbacks';
5
13
  import {
14
+ type CollectionType,
6
15
  type Currency,
7
16
  OrderbookKind,
8
- type Price,
9
17
  type Step,
10
18
  StepType,
11
19
  type WalletKind,
12
- } from '@types';
13
- import { addDays } from 'date-fns/addDays';
14
- import type { Hex } from 'viem';
15
- import { useAccount, useSendTransaction } from 'wagmi';
16
- import type { ShowCreateListingModalArgs } from '.';
17
- import type { Messages } from '../../../../types/messages';
20
+ collectableKeys,
21
+ } from '../../../_internal';
22
+ import {
23
+ useCollectible,
24
+ useCollection,
25
+ useGenerateListingTransaction,
26
+ } from '../../../hooks';
18
27
  import { useTransactionStatusModal } from '../_internal/components/transactionStatusModal';
19
28
  import {
20
29
  getCreateListingTransactionMessage,
21
30
  getCreateListingTransactionTitle,
22
31
  } from './_utils/getCreateListingTransactionTitleMessage';
23
- import { useCollectible } from '@react-hooks/useCollectible';
24
- import type { CollectionType } from '@internal';
25
32
 
26
33
  export interface CreateListingModalState {
27
34
  isOpen: boolean;
@@ -32,11 +39,12 @@ export interface CreateListingModalState {
32
39
  collectionType: CollectionType | undefined;
33
40
  listingPrice: Price;
34
41
  quantity: string;
35
- collectionAddress: string;
42
+ collectionAddress: Hex;
36
43
  chainId: string;
37
44
  collectibleId: string;
38
45
  expiry: Date;
39
- messages?: Messages;
46
+ errorCallbacks?: CreateListingErrorCallbacks;
47
+ successCallbacks?: CreateListingSuccessCallbacks;
40
48
  };
41
49
  steps: {
42
50
  isLoading: () => boolean;
@@ -62,14 +70,12 @@ export const initialState: CreateListingModalState = {
62
70
  collectionAddress,
63
71
  chainId,
64
72
  collectibleId,
65
- messages,
66
73
  }: ShowCreateListingModalArgs) => {
67
74
  createListingModal$.state.set({
68
75
  ...createListingModal$.state.get(),
69
76
  collectionAddress,
70
77
  chainId,
71
78
  collectibleId,
72
- messages,
73
79
  });
74
80
  createListingModal$.isOpen.set(true);
75
81
  },
@@ -85,7 +91,7 @@ export const initialState: CreateListingModalState = {
85
91
  quantity: '1',
86
92
  expiry: new Date(addDays(new Date(), 7).toJSON()),
87
93
  collectionType: undefined,
88
- collectionAddress: '',
94
+ collectionAddress: '' as Hex,
89
95
  chainId: '',
90
96
  collectibleId: '',
91
97
  },
@@ -165,11 +171,10 @@ export const useHydrate = () => {
165
171
 
166
172
  const useTokenApprovalHandler = (chainId: string) => {
167
173
  const { sendTransactionAsync, isPending, isSuccess } = useSendTransaction();
168
- const {
169
- onUnknownError,
170
- onSuccess,
171
- }: { onUnknownError?: Function; onSuccess?: Function } =
172
- createListingModal$.state.get().messages?.approveToken || {};
174
+ const onError =
175
+ createListingModal$.state.get().errorCallbacks?.onApproveTokenError;
176
+ const onSuccess: (() => void) | undefined =
177
+ createListingModal$.state.get().successCallbacks?.onApproveTokenSuccess;
173
178
 
174
179
  createListingModal$.steps.tokenApproval.set({
175
180
  isNeeded: () => !!createListingModal$.steps.tokenApproval.getStep(),
@@ -180,13 +185,13 @@ const useTokenApprovalHandler = (chainId: string) => {
180
185
  pending:
181
186
  createListingModal$.steps._currentStep.get() === 'tokenApproval' &&
182
187
  isPending,
183
- execute: () => {
188
+ execute: async () => {
184
189
  const step = createListingModal$.steps.tokenApproval.getStep();
185
190
  if (!step) return;
186
191
  createListingModal$.steps._currentStep.set('tokenApproval');
187
192
 
188
193
  try {
189
- sendTransactionAsync({
194
+ await sendTransactionAsync({
190
195
  to: step.to as Hex,
191
196
  chainId: Number(chainId),
192
197
  data: step.data as Hex,
@@ -195,7 +200,7 @@ const useTokenApprovalHandler = (chainId: string) => {
195
200
 
196
201
  onSuccess && onSuccess();
197
202
  } catch (error) {
198
- onUnknownError && onUnknownError(error);
203
+ onError && onError(error);
199
204
  }
200
205
  },
201
206
  });
@@ -209,23 +214,18 @@ const useTokenApprovalHandler = (chainId: string) => {
209
214
  };
210
215
 
211
216
  const useCreateListingHandler = (chainId: string) => {
212
- const { collectibleId, collectionAddress } = createListingModal$.state.get();
217
+ const { collectibleId, collectionAddress, errorCallbacks, successCallbacks } =
218
+ createListingModal$.state.get();
213
219
  const { connector, address } = useAccount();
214
220
  const {
215
221
  generateListingTransactionAsync,
216
222
  isPending: generateListingTransactionPending,
217
- error: generateListingTransactionError,
218
223
  } = useGenerateListingTransaction({ chainId });
219
224
  const { data: collectible } = useCollectible({
220
225
  chainId,
221
226
  collectionAddress,
222
227
  collectibleId,
223
228
  });
224
- const {
225
- onUnknownError,
226
- onSuccess,
227
- }: { onUnknownError?: Function; onSuccess?: Function } =
228
- createListingModal$.state.get().messages?.sellCollectible || {};
229
229
 
230
230
  const { sendTransactionAsync, isPending: sendTransactionPending } =
231
231
  useSendTransaction();
@@ -268,6 +268,8 @@ const useCreateListingHandler = (chainId: string) => {
268
268
 
269
269
  createListingModal$.steps._currentStep.set(null);
270
270
 
271
+ createListingModal$.close();
272
+
271
273
  showTransactionStatusModal({
272
274
  hash: hash!,
273
275
  price: createListingModal$.state.listingPrice.get(),
@@ -281,21 +283,18 @@ const useCreateListingHandler = (chainId: string) => {
281
283
  collectible?.name || '',
282
284
  ),
283
285
  type: 'transfer',
286
+ callbacks: {
287
+ onSuccess: successCallbacks?.onCreateListingSuccess,
288
+ onUnknownError: errorCallbacks?.onCreateListingError,
289
+ },
290
+ queriesToInvalidate: collectableKeys.all as unknown as QueryKey[],
284
291
  });
285
-
286
- createListingModal$.close();
287
-
288
- onSuccess && onSuccess();
289
292
  })
290
293
  .catch((error) => {
291
- onUnknownError && onUnknownError(error);
294
+ errorCallbacks?.onCreateListingError?.(error);
292
295
  });
293
296
  },
294
297
  });
295
-
296
- if (generateListingTransactionError) {
297
- onUnknownError && onUnknownError(generateListingTransactionError);
298
- }
299
298
  };
300
299
 
301
300
  const useShowTransactionStatusModal = () => {