@0xsequence/marketplace-sdk 0.0.1 → 0.1.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 (93) hide show
  1. package/dist/chunk-7CL54NCX.js +41 -0
  2. package/dist/chunk-7CL54NCX.js.map +1 -0
  3. package/dist/{chunk-G3D572BT.js → chunk-G3YU4NQ2.js} +24 -1
  4. package/dist/chunk-G3YU4NQ2.js.map +1 -0
  5. package/dist/{chunk-SM7V6ZWI.js → chunk-GNB736ZE.js} +226 -208
  6. package/dist/chunk-GNB736ZE.js.map +1 -0
  7. package/dist/chunk-ITJEOCDV.js +1006 -0
  8. package/dist/chunk-ITJEOCDV.js.map +1 -0
  9. package/dist/{chunk-QOJXWHRZ.js → chunk-LFQB477Y.js} +3 -1
  10. package/dist/chunk-LFQB477Y.js.map +1 -0
  11. package/dist/{chunk-VPGWEMWL.js → chunk-M4MXVMAM.js} +134 -25
  12. package/dist/chunk-M4MXVMAM.js.map +1 -0
  13. package/dist/{chunk-4PFMUVE4.js → chunk-SNOEEUPZ.js} +2 -2
  14. package/dist/{create-config-Dz0gCiQ0.d.ts → create-config-Cto2ehcz.d.ts} +1 -1
  15. package/dist/index.css +4 -1
  16. package/dist/index.d.ts +3 -2
  17. package/dist/index.js +1 -1
  18. package/dist/{marketplace-config-DZbtyrma.d.ts → marketplace-config-Bbxl-uKX.d.ts} +2 -1
  19. package/dist/react/_internal/index.d.ts +4 -3
  20. package/dist/react/_internal/index.js +9 -1
  21. package/dist/react/_internal/wagmi/index.d.ts +2 -2
  22. package/dist/react/hooks/index.d.ts +1363 -101
  23. package/dist/react/hooks/index.js +13 -7
  24. package/dist/react/index.css +4 -1
  25. package/dist/react/index.css.map +1 -1
  26. package/dist/react/index.d.ts +6 -5
  27. package/dist/react/index.js +28 -22
  28. package/dist/react/ssr/index.d.ts +2 -1
  29. package/dist/react/ssr/index.js +23 -0
  30. package/dist/react/ssr/index.js.map +1 -1
  31. package/dist/react/ui/index.css +4 -1
  32. package/dist/react/ui/index.css.map +1 -1
  33. package/dist/react/ui/index.d.ts +4 -4
  34. package/dist/react/ui/index.js +5 -5
  35. package/dist/react/ui/modals/_internal/components/actionModal/index.js +2 -2
  36. package/dist/styles/index.css +4 -1
  37. package/dist/styles/index.css.map +1 -1
  38. package/dist/styles/index.d.ts +2 -1
  39. package/dist/styles/index.js +3 -4972
  40. package/dist/styles/index.js.map +1 -1
  41. package/dist/types/index.d.ts +2 -1
  42. package/dist/types/index.js +1 -1
  43. package/dist/types-BzZVURNL.d.ts +19 -0
  44. package/dist/utils/index.d.ts +2 -1
  45. package/dist/utils/index.js +1 -1
  46. package/package.json +3 -2
  47. package/src/react/_internal/api/zod-schema.ts +636 -0
  48. package/src/react/_internal/types.ts +32 -8
  49. package/src/react/hooks/index.ts +1 -0
  50. package/src/react/hooks/useBalanceOfCollectible.tsx +43 -18
  51. package/src/react/hooks/useCollectible.tsx +17 -11
  52. package/src/react/hooks/useCollection.tsx +35 -29
  53. package/src/react/hooks/useCountOfCollectables.tsx +77 -0
  54. package/src/react/hooks/useCurrencies.tsx +23 -12
  55. package/src/react/hooks/useFilters.tsx +15 -9
  56. package/src/react/hooks/useFloorOrder.tsx +23 -8
  57. package/src/react/hooks/useGenerateSellTransaction.tsx +16 -9
  58. package/src/react/hooks/useHighestOffer.tsx +23 -13
  59. package/src/react/hooks/useListBalances.tsx +57 -26
  60. package/src/react/hooks/useListCollectibles.tsx +25 -12
  61. package/src/react/hooks/useListOffersForCollectible.tsx +13 -5
  62. package/src/react/hooks/useLowestListing.tsx +23 -14
  63. package/src/react/hooks/useRoyaltyPercentage.tsx +18 -8
  64. package/src/react/hooks/useTransferTokens.tsx +3 -3
  65. package/src/react/ui/modals/CreateListingModal/_store.ts +5 -5
  66. package/src/react/ui/modals/CreateListingModal/index.tsx +5 -4
  67. package/src/react/ui/modals/MakeOfferModal/_store.ts +6 -9
  68. package/src/react/ui/modals/MakeOfferModal/index.tsx +15 -25
  69. package/src/react/ui/modals/SellModal/_store.ts +28 -23
  70. package/src/react/ui/modals/SellModal/index.tsx +11 -10
  71. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +8 -7
  72. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +2 -1
  73. package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +3 -2
  74. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +55 -12
  75. package/src/react/ui/modals/_internal/components/priceInput/styles.css.ts +4 -0
  76. package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +2 -1
  77. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +2 -1
  78. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
  79. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +4 -4
  80. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +14 -14
  81. package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +5 -5
  82. package/src/types/marketplace-config.ts +2 -1
  83. package/dist/chunk-G3D572BT.js.map +0 -1
  84. package/dist/chunk-QOJXWHRZ.js.map +0 -1
  85. package/dist/chunk-SM7V6ZWI.js.map +0 -1
  86. package/dist/chunk-STO74F2I.js +0 -14
  87. package/dist/chunk-STO74F2I.js.map +0 -1
  88. package/dist/chunk-VPGWEMWL.js.map +0 -1
  89. package/dist/chunk-ZE2LNX65.js +0 -394
  90. package/dist/chunk-ZE2LNX65.js.map +0 -1
  91. package/dist/types-BrAQ8-w4.d.ts +0 -12
  92. package/src/react/hooks/useCollectionCounts.tsx +0 -61
  93. /package/dist/{chunk-4PFMUVE4.js.map → chunk-SNOEEUPZ.js.map} +0 -0
@@ -1,13 +1,37 @@
1
- import type { ChainId as NetworkChainId } from '@0xsequence/network';
1
+ import { ChainId as NetworkChainId } from '@0xsequence/network';
2
2
  import type { ContractType } from '@types';
3
+ import type { Address } from 'viem';
4
+ import { z } from 'zod';
3
5
 
4
- export type QueryArg = {
5
- query?: {
6
- enabled?: boolean;
7
- //TODO: Add more fields
8
- };
9
- };
6
+ export const QueryArgSchema = z
7
+ .object({
8
+ enabled: z.boolean().optional(),
9
+ })
10
+ .optional();
10
11
 
11
- export type ChainId = string | number | NetworkChainId;
12
+ export type QueryArg = z.infer<typeof QueryArgSchema>;
13
+
14
+ export const CollectableIdSchema = z.string().or(z.number());
15
+
16
+ export const ChainIdSchema = z.union([
17
+ z.string(),
18
+ z.number(),
19
+ z.nativeEnum(NetworkChainId),
20
+ ]);
21
+
22
+ export const AddressSchema = z.string().transform((val, ctx) => {
23
+ const regex = /^0x[a-fA-F0-9]{40}$/;
24
+
25
+ if (!regex.test(val)) {
26
+ ctx.addIssue({
27
+ code: z.ZodIssueCode.custom,
28
+ message: `Invalid Address ${val}`,
29
+ });
30
+ }
31
+
32
+ return val as Address;
33
+ });
34
+
35
+ export type ChainId = z.infer<typeof ChainIdSchema>;
12
36
 
13
37
  export type CollectionType = ContractType.ERC1155 | ContractType.ERC721;
@@ -1,4 +1,5 @@
1
1
  export * from './useBalanceOfCollectible';
2
+ export * from './useCountOfCollectables';
2
3
  export * from './useCollectible';
3
4
  export * from './useCollection';
4
5
  export * from './useConfig';
@@ -1,51 +1,76 @@
1
1
  import {
2
- type ChainId,
3
- type QueryArg,
2
+ AddressSchema,
3
+ ChainIdSchema,
4
+ CollectableIdSchema,
5
+ type QueryArgSchema,
4
6
  collectableKeys,
5
7
  getIndexerClient,
6
8
  } from '@internal';
7
- import { queryOptions, useQuery } from '@tanstack/react-query';
9
+ import { queryOptions, skipToken, useQuery } from '@tanstack/react-query';
8
10
  import type { SdkConfig } from '@types';
11
+ import type { Hex } from 'viem';
12
+ import { z } from 'zod';
9
13
  import { useConfig } from './useConfig';
10
14
 
11
- export type UseBalanceOfCollectibleArgs = {
12
- collectionAddress: string;
13
- userAddress: string;
14
- tokenId: string;
15
- chainId: ChainId;
16
- } & QueryArg;
15
+ const fetchBalanceOfCollectibleSchema = z.object({
16
+ collectionAddress: AddressSchema,
17
+ collectableId: CollectableIdSchema.pipe(z.coerce.string()),
18
+ userAddress: AddressSchema,
19
+ chainId: ChainIdSchema.pipe(z.coerce.number()),
20
+ });
21
+
22
+ type FetchBalanceOfCollectibleArgs = z.input<
23
+ typeof fetchBalanceOfCollectibleSchema
24
+ >;
17
25
 
18
26
  const fetchBalanceOfCollectible = async (
19
- args: UseBalanceOfCollectibleArgs,
27
+ args: FetchBalanceOfCollectibleArgs,
20
28
  config: SdkConfig,
21
29
  ) => {
22
- const indexerClient = getIndexerClient(args.chainId, config);
30
+ const parsedArgs = fetchBalanceOfCollectibleSchema.parse(args);
31
+ const indexerClient = getIndexerClient(parsedArgs.chainId, config);
23
32
  return indexerClient
24
33
  .getTokenBalances({
25
- accountAddress: args.userAddress,
26
- contractAddress: args.collectionAddress,
27
- tokenID: args.tokenId,
34
+ accountAddress: parsedArgs.userAddress,
35
+ contractAddress: parsedArgs.collectionAddress,
36
+ tokenID: parsedArgs.collectableId,
28
37
  includeMetadata: false,
29
38
  metadataOptions: {
30
39
  verifiedOnly: true,
31
- includeContracts: [args.collectionAddress],
40
+ includeContracts: [parsedArgs.collectionAddress],
32
41
  },
33
42
  })
34
43
  .then((res) => res.balances[0] || null);
35
44
  };
36
45
 
46
+ interface BalanceOfCollectibleOptions
47
+ extends Omit<FetchBalanceOfCollectibleArgs, 'userAddress'> {
48
+ userAddress?: Hex;
49
+ query?: z.infer<typeof QueryArgSchema>;
50
+ }
37
51
  export const balanceOfCollectibleOptions = (
38
- args: UseBalanceOfCollectibleArgs,
52
+ args: BalanceOfCollectibleOptions,
39
53
  config: SdkConfig,
40
54
  ) => {
41
55
  return queryOptions({
42
56
  ...args.query,
43
57
  queryKey: [...collectableKeys.userBalances, args, config],
44
- queryFn: () => fetchBalanceOfCollectible(args, config),
58
+ queryFn: args.userAddress
59
+ ? () =>
60
+ fetchBalanceOfCollectible(
61
+ {
62
+ ...args,
63
+ // biome-ignore lint/style/noNonNullAssertion: this is guaranteed by the userAddress check above
64
+ userAddress: args.userAddress!,
65
+ },
66
+ config,
67
+ )
68
+ : skipToken,
69
+ enabled: !!args.userAddress || args.query?.enabled,
45
70
  });
46
71
  };
47
72
 
48
- export const useBalanceOfCollectible = (args: UseBalanceOfCollectibleArgs) => {
73
+ export const useBalanceOfCollectible = (args: BalanceOfCollectibleOptions) => {
49
74
  const config = useConfig();
50
75
  return useQuery(balanceOfCollectibleOptions(args, config));
51
76
  };
@@ -1,31 +1,37 @@
1
1
  import {
2
- type ChainId,
3
- type QueryArg,
2
+ AddressSchema,
3
+ ChainIdSchema,
4
+ QueryArgSchema,
4
5
  collectableKeys,
5
6
  getMetadataClient,
6
7
  } from '@internal';
7
8
  import { queryOptions, useQuery } from '@tanstack/react-query';
8
9
  import type { SdkConfig } from '@types';
10
+ import { z } from 'zod';
9
11
  import { useConfig } from './useConfig';
10
12
 
11
- export type UseCollectibleArgs = {
12
- chainId: ChainId;
13
- collectionAddress: string;
14
- collectibleId: string;
15
- } & QueryArg;
13
+ const UseCollectibleSchema = z.object({
14
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
15
+ collectionAddress: AddressSchema,
16
+ collectibleId: z.string(),
17
+ query: QueryArgSchema,
18
+ });
16
19
 
17
- export type UseCollectibleReturn = ReturnType<typeof fetchCollectible>;
20
+ export type UseCollectibleArgs = z.infer<typeof UseCollectibleSchema>;
21
+
22
+ export type UseCollectibleReturn = Awaited<ReturnType<typeof fetchCollectible>>;
18
23
 
19
24
  const fetchCollectible = async (
20
25
  args: UseCollectibleArgs,
21
26
  config: SdkConfig,
22
27
  ) => {
28
+ const parsedArgs = UseCollectibleSchema.parse(args);
23
29
  const metadataClient = getMetadataClient(config);
24
30
  return metadataClient
25
31
  .getTokenMetadata({
26
- chainID: String(args.chainId),
27
- contractAddress: args.collectionAddress,
28
- tokenIDs: [args.collectibleId],
32
+ chainID: parsedArgs.chainId,
33
+ contractAddress: parsedArgs.collectionAddress,
34
+ tokenIDs: [parsedArgs.collectibleId],
29
35
  })
30
36
  .then((resp) => resp.tokenMetadata[0]);
31
37
  };
@@ -1,42 +1,48 @@
1
1
  import {
2
- type ChainId,
3
- type QueryArg,
4
- collectionKeys,
5
- getMetadataClient,
6
- } from '@internal';
7
- import { queryOptions, useQuery } from '@tanstack/react-query';
8
- import type { SdkConfig } from '@types';
9
- import { useConfig } from './useConfig';
2
+ AddressSchema,
3
+ ChainIdSchema,
4
+ QueryArgSchema,
5
+ collectionKeys,
6
+ getMetadataClient,
7
+ } from "@internal";
8
+ import { queryOptions, useQuery } from "@tanstack/react-query";
9
+ import type { SdkConfig } from "@types";
10
+ import { z } from "zod";
11
+ import { useConfig } from "./useConfig";
10
12
 
11
- export type UseCollectionArgs = {
12
- chainId: ChainId;
13
- collectionAddress: string;
14
- } & QueryArg;
13
+ const UseCollectionSchema = z.object({
14
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
15
+ collectionAddress: AddressSchema,
16
+ query: QueryArgSchema,
17
+ });
15
18
 
16
- export type UseCollectionReturn = ReturnType<typeof fetchCollection>;
19
+ export type UseCollectionArgs = z.input<typeof UseCollectionSchema>;
20
+
21
+ export type UseCollectionReturn = Awaited<ReturnType<typeof fetchCollection>>;
17
22
 
18
23
  const fetchCollection = async (args: UseCollectionArgs, config: SdkConfig) => {
19
- const metadataClient = getMetadataClient(config);
20
- return metadataClient
21
- .getContractInfo({
22
- chainID: String(args.chainId),
23
- contractAddress: args.collectionAddress,
24
- })
25
- .then((resp) => resp.contractInfo);
24
+ const parsedArgs = UseCollectionSchema.parse(args);
25
+ const metadataClient = getMetadataClient(config);
26
+ return metadataClient
27
+ .getContractInfo({
28
+ chainID: parsedArgs.chainId,
29
+ contractAddress: parsedArgs.collectionAddress,
30
+ })
31
+ .then((resp) => resp.contractInfo);
26
32
  };
27
33
 
28
34
  export const collectionOptions = (
29
- args: UseCollectionArgs,
30
- config: SdkConfig,
35
+ args: UseCollectionArgs,
36
+ config: SdkConfig
31
37
  ) => {
32
- return queryOptions({
33
- ...args.query,
34
- queryKey: [...collectionKeys.detail, args, config],
35
- queryFn: () => fetchCollection(args, config),
36
- });
38
+ return queryOptions({
39
+ ...args.query,
40
+ queryKey: [...collectionKeys.detail, args, config],
41
+ queryFn: () => fetchCollection(args, config),
42
+ });
37
43
  };
38
44
 
39
45
  export const useCollection = (args: UseCollectionArgs) => {
40
- const config = useConfig();
41
- return useQuery(collectionOptions(args, config));
46
+ const config = useConfig();
47
+ return useQuery(collectionOptions(args, config));
42
48
  };
@@ -0,0 +1,77 @@
1
+ import {
2
+ AddressSchema,
3
+ ChainIdSchema,
4
+ OrderSide,
5
+ QueryArgSchema,
6
+ collectableKeys,
7
+ getMarketplaceClient,
8
+ } from '@internal';
9
+ import { queryOptions, useQuery } from '@tanstack/react-query';
10
+ import type { SdkConfig } from '@types';
11
+ import { z } from 'zod';
12
+ import { collectiblesFilterSchema } from '../_internal/api/zod-schema';
13
+ import { useConfig } from './useConfig';
14
+
15
+ const BaseSchema = z.object({
16
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
17
+ collectionAddress: AddressSchema,
18
+ query: QueryArgSchema,
19
+ });
20
+
21
+ const UseCountOfCollectableSchema = BaseSchema.extend({
22
+ filter: collectiblesFilterSchema,
23
+ side: z.nativeEnum(OrderSide),
24
+ }).or(
25
+ BaseSchema.extend({
26
+ filter: z.undefined(),
27
+ side: z.undefined(),
28
+ }),
29
+ );
30
+
31
+ export type UseCountOfCollectablesArgs = z.infer<
32
+ typeof UseCountOfCollectableSchema
33
+ >;
34
+
35
+ export type UseContOfCollectableReturn = Awaited<
36
+ ReturnType<typeof fetchCountOfCollectables>
37
+ >;
38
+
39
+ const fetchCountOfCollectables = async (
40
+ args: UseCountOfCollectablesArgs,
41
+ config: SdkConfig,
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);
61
+ };
62
+
63
+ export const countOfCollectablesOptions = (
64
+ args: UseCountOfCollectablesArgs,
65
+ config: SdkConfig,
66
+ ) => {
67
+ return queryOptions({
68
+ ...args.query,
69
+ queryKey: [...collectableKeys.counts, args],
70
+ queryFn: () => fetchCountOfCollectables(args, config),
71
+ });
72
+ };
73
+
74
+ export const useCountOfCollectables = (args: UseCountOfCollectablesArgs) => {
75
+ const config = useConfig();
76
+ return useQuery(countOfCollectablesOptions(args, config));
77
+ };
@@ -1,7 +1,9 @@
1
1
  import {
2
+ AddressSchema,
2
3
  type ChainId,
4
+ ChainIdSchema,
3
5
  type Currency,
4
- type QueryArg,
6
+ QueryArgSchema,
5
7
  configKeys,
6
8
  currencyKeys,
7
9
  getMarketplaceClient,
@@ -9,31 +11,40 @@ import {
9
11
  } from '@internal';
10
12
  import { queryOptions, useQuery } from '@tanstack/react-query';
11
13
  import type { MarketplaceConfig, SdkConfig } from '@types';
14
+ import { z } from 'zod';
12
15
  import { useConfig } from './useConfig';
13
16
 
14
- export type UseCurrenciesArgs = {
15
- chainId: ChainId;
16
- collectionAddress?: string;
17
- includeNativeCurrency?: boolean;
18
- } & QueryArg;
17
+ const ChainIdCoerce = ChainIdSchema.transform((val) => val.toString());
19
18
 
20
- export type UseCurrenciesReturn = ReturnType<typeof fetchCurrencies>;
19
+ const UseCurrenciesArgsSchema = z.object({
20
+ chainId: ChainIdCoerce,
21
+ collectionAddress: AddressSchema.optional(),
22
+ includeNativeCurrency: z.boolean().optional(),
23
+ query: QueryArgSchema,
24
+ });
25
+
26
+ type UseCurrenciesArgs = z.input<typeof UseCurrenciesArgsSchema>;
27
+
28
+ export type UseCurrenciesReturn = Awaited<ReturnType<typeof fetchCurrencies>>;
21
29
 
22
30
  const fetchCurrencies = async (chainId: ChainId, config: SdkConfig) => {
23
- const marketplaceClient = getMarketplaceClient(chainId, config);
31
+ const parsedChainId = ChainIdCoerce.parse(chainId);
32
+ const marketplaceClient = getMarketplaceClient(parsedChainId, config);
24
33
  return marketplaceClient.listCurrencies().then((resp) => resp.currencies);
25
34
  };
26
35
 
27
36
  const selectCurrencies = (data: Currency[], args: UseCurrenciesArgs) => {
37
+ const argsParsed = UseCurrenciesArgsSchema.parse(args);
28
38
  // if collectionAddress is passed, filter currencies based on collection currency options
29
- if (args.collectionAddress) {
39
+ if (argsParsed.collectionAddress) {
30
40
  const queryClient = getQueryClient();
31
41
  const marketplaceConfigCache = queryClient.getQueriesData({
32
42
  queryKey: configKeys.marketplace,
33
43
  })[0][1] as MarketplaceConfig;
34
44
 
35
45
  const collection = marketplaceConfigCache?.collections.find(
36
- (collection) => collection.collectionAddress === args.collectionAddress,
46
+ (collection) =>
47
+ collection.collectionAddress === argsParsed.collectionAddress,
37
48
  );
38
49
 
39
50
  if (!collection) {
@@ -44,12 +55,12 @@ const selectCurrencies = (data: Currency[], args: UseCurrenciesArgs) => {
44
55
  (currency) =>
45
56
  collection.currencyOptions?.includes(currency.contractAddress) ||
46
57
  // biome-ignore lint/suspicious/noDoubleEquals: <explanation>
47
- currency.nativeCurrency == args.includeNativeCurrency ||
58
+ currency.nativeCurrency == argsParsed.includeNativeCurrency ||
48
59
  currency.defaultChainCurrency,
49
60
  );
50
61
  }
51
62
  // if includeNativeCurrency is true, return all currencies
52
- if (args.includeNativeCurrency) {
63
+ if (argsParsed.includeNativeCurrency) {
53
64
  return data;
54
65
  }
55
66
 
@@ -1,26 +1,32 @@
1
1
  import {
2
- type ChainId,
3
- type QueryArg,
2
+ AddressSchema,
3
+ ChainIdSchema,
4
+ QueryArgSchema,
4
5
  collectableKeys,
5
6
  getMetadataClient,
6
7
  } from '@internal';
7
8
  import { queryOptions, useQuery } from '@tanstack/react-query';
8
9
  import type { SdkConfig } from '@types';
10
+ import { z } from 'zod';
9
11
  import { useConfig } from './useConfig';
10
12
 
11
- export type UseFiltersArgs = {
12
- chainId: ChainId;
13
- collectionAddress: string;
14
- } & QueryArg;
13
+ const UseFiltersSchema = z.object({
14
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
15
+ collectionAddress: AddressSchema,
16
+ query: QueryArgSchema,
17
+ });
15
18
 
16
- export type UseFilterReturn = ReturnType<typeof fetchFilters>;
19
+ export type UseFiltersArgs = z.infer<typeof UseFiltersSchema>;
20
+
21
+ export type UseFilterReturn = Awaited<ReturnType<typeof fetchFilters>>;
17
22
 
18
23
  export const fetchFilters = async (args: UseFiltersArgs, config: SdkConfig) => {
24
+ const parsedArgs = UseFiltersSchema.parse(args);
19
25
  const metadataClient = getMetadataClient(config);
20
26
  return metadataClient
21
27
  .tokenCollectionFilters({
22
- chainID: String(args.chainId),
23
- contractAddress: args.collectionAddress,
28
+ chainID: parsedArgs.chainId,
29
+ contractAddress: parsedArgs.collectionAddress,
24
30
  })
25
31
  .then((resp) => resp.filters);
26
32
  };
@@ -1,28 +1,43 @@
1
- import { collectableKeys, getMarketplaceClient } from '@internal';
1
+ import {
2
+ AddressSchema,
3
+ ChainIdSchema,
4
+ QueryArgSchema,
5
+ collectableKeys,
6
+ getMarketplaceClient,
7
+ } from '@internal';
2
8
  import { queryOptions, useQuery } from '@tanstack/react-query';
3
9
  import type { SdkConfig } from '@types';
10
+ import { z } from 'zod';
4
11
  import { useConfig } from './useConfig';
5
12
 
6
- export type UseFloorOrder = {
7
- chainId: string;
8
- collectionAddress: string;
9
- };
13
+ const UseFloorOrderSchema = z.object({
14
+ chainId: ChainIdSchema.pipe(z.coerce.string()),
15
+ collectionAddress: AddressSchema,
16
+ query: QueryArgSchema,
17
+ });
18
+
19
+ export type UseFloorOrderArgs = z.infer<typeof UseFloorOrderSchema>;
20
+
21
+ export type UseFloorOrderReturn = Awaited<ReturnType<typeof fetchFloorOrder>>;
10
22
 
11
- const fetchFloorOrder = async (args: UseFloorOrder, config: SdkConfig) => {
23
+ const fetchFloorOrder = async (args: UseFloorOrderArgs, config: SdkConfig) => {
12
24
  const marketplaceClient = getMarketplaceClient(args.chainId, config);
13
25
  return marketplaceClient
14
26
  .getFloorOrder({ contractAddress: args.collectionAddress })
15
27
  .then((data) => data.collectible);
16
28
  };
17
29
 
18
- export const floorOrderOptions = (args: UseFloorOrder, config: SdkConfig) => {
30
+ export const floorOrderOptions = (
31
+ args: UseFloorOrderArgs,
32
+ config: SdkConfig,
33
+ ) => {
19
34
  return queryOptions({
20
35
  queryKey: [...collectableKeys.floorOrders, args, config],
21
36
  queryFn: () => fetchFloorOrder(args, config),
22
37
  });
23
38
  };
24
39
 
25
- export const useFloorOrder = (args: UseFloorOrder) => {
40
+ export const useFloorOrder = (args: UseFloorOrderArgs) => {
26
41
  const config = useConfig();
27
42
  return useQuery(floorOrderOptions(args, config));
28
43
  };
@@ -1,27 +1,34 @@
1
1
  import {
2
2
  type ChainId,
3
+ ChainIdSchema,
3
4
  type GenerateSellTransactionArgs,
4
5
  getMarketplaceClient,
5
6
  } from '@internal';
6
7
  import { useMutation } from '@tanstack/react-query';
7
8
  import type { SdkConfig } from '@types';
9
+ import { z } from 'zod';
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
1
  import {
2
- type GetCollectibleHighestOfferArgs,
3
- type QueryArg,
2
+ AddressSchema,
3
+ ChainIdSchema,
4
+ QueryArgSchema,
4
5
  collectableKeys,
5
6
  getMarketplaceClient,
6
7
  } from '@internal';
7
8
  import { queryOptions, useQuery } from '@tanstack/react-query';
8
9
  import type { SdkConfig } from '@types';
10
+ import { z } from 'zod';
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