@0xsequence/marketplace-sdk 0.8.10 → 0.8.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/.changeset/fluffy-jokes-lay.md +5 -0
  2. package/.changeset/wise-bugs-boil.md +8 -0
  3. package/CHANGELOG.md +16 -3
  4. package/dist/{chunk-DWTLVJAW.js → chunk-6OPMUCGX.js} +1 -1
  5. package/dist/chunk-6OPMUCGX.js.map +1 -0
  6. package/dist/{chunk-O34GCB47.js → chunk-L6KWLCER.js} +4 -4
  7. package/dist/chunk-L6KWLCER.js.map +1 -0
  8. package/dist/{chunk-Y2HJO2VY.js → chunk-LAP2CKLN.js} +56 -3
  9. package/dist/chunk-LAP2CKLN.js.map +1 -0
  10. package/dist/{chunk-Y63BOO6M.js → chunk-LECCEZAO.js} +1 -1
  11. package/dist/{chunk-WH5BZC7W.js → chunk-N7SQWS2R.js} +3 -3
  12. package/dist/{chunk-7F27CJZW.js → chunk-OAOONM4S.js} +682 -439
  13. package/dist/chunk-OAOONM4S.js.map +1 -0
  14. package/dist/chunk-QY52UADF.js +107 -0
  15. package/dist/chunk-QY52UADF.js.map +1 -0
  16. package/dist/{chunk-UJSF7PSC.js → chunk-TNAR3XEF.js} +3766 -765
  17. package/dist/chunk-TNAR3XEF.js.map +1 -0
  18. package/dist/chunk-XABYNWXO.js +549 -0
  19. package/dist/chunk-XABYNWXO.js.map +1 -0
  20. package/dist/chunk-YB5UUF2G.js +11 -0
  21. package/dist/chunk-YB5UUF2G.js.map +1 -0
  22. package/dist/{chunk-M6NJ73Y5.js → chunk-YWGFI4PN.js} +87 -24
  23. package/dist/chunk-YWGFI4PN.js.map +1 -0
  24. package/dist/{create-config-CAQcvjl6.d.ts → create-config-DLMvMTkZ.d.ts} +2 -2
  25. package/dist/index.css +1 -1
  26. package/dist/index.css.map +1 -1
  27. package/dist/index.d.ts +7 -6
  28. package/dist/index.js +14 -15
  29. package/dist/{listTokenMetadata-DO4ChDjn.d.ts → marketCurrencies-enNVYwBk.d.ts} +77 -3
  30. package/dist/{marketplace.gen-DQzWciwC.d.ts → marketplace.gen-D24veUQs.d.ts} +3 -2
  31. package/dist/marketplaceConfig-BwNAbLPw.d.ts +21 -0
  32. package/dist/new-marketplace-types-BCw19X9S.d.ts +102 -0
  33. package/dist/react/_internal/api/index.d.ts +3 -3
  34. package/dist/react/_internal/api/index.js +1 -1
  35. package/dist/react/_internal/databeat/index.css +2764 -0
  36. package/dist/react/_internal/databeat/index.css.map +1 -0
  37. package/dist/react/_internal/databeat/index.d.ts +1 -1
  38. package/dist/react/_internal/databeat/index.js +12 -12
  39. package/dist/react/_internal/index.d.ts +61 -9
  40. package/dist/react/_internal/index.js +3 -3
  41. package/dist/react/_internal/wagmi/index.d.ts +5 -6
  42. package/dist/react/_internal/wagmi/index.js +1 -1
  43. package/dist/react/hooks/index.css +2764 -0
  44. package/dist/react/hooks/index.css.map +1 -0
  45. package/dist/react/hooks/index.d.ts +71 -222
  46. package/dist/react/hooks/index.js +16 -20
  47. package/dist/react/hooks/options/index.d.ts +5 -4
  48. package/dist/react/hooks/options/index.js +9 -7
  49. package/dist/react/index.css +1 -1
  50. package/dist/react/index.css.map +1 -1
  51. package/dist/react/index.d.ts +9 -9
  52. package/dist/react/index.js +28 -34
  53. package/dist/react/queries/index.d.ts +3 -3
  54. package/dist/react/queries/index.js +15 -4
  55. package/dist/react/ssr/index.d.ts +3 -3
  56. package/dist/react/ssr/index.js +6 -5
  57. package/dist/react/ssr/index.js.map +1 -1
  58. package/dist/react/ui/components/collectible-card/index.css +1 -1
  59. package/dist/react/ui/components/collectible-card/index.css.map +1 -1
  60. package/dist/react/ui/components/collectible-card/index.d.ts +3 -2
  61. package/dist/react/ui/components/collectible-card/index.js +12 -17
  62. package/dist/react/ui/icons/index.js +6 -6
  63. package/dist/react/ui/index.css +1 -1
  64. package/dist/react/ui/index.css.map +1 -1
  65. package/dist/react/ui/index.d.ts +1 -1
  66. package/dist/react/ui/index.js +12 -17
  67. package/dist/react/ui/modals/_internal/components/actionModal/index.css +2764 -0
  68. package/dist/react/ui/modals/_internal/components/actionModal/index.css.map +1 -0
  69. package/dist/react/ui/modals/_internal/components/actionModal/index.js +12 -12
  70. package/dist/sdk-config-qorA0TgF.d.ts +165 -0
  71. package/dist/{services-CMSb9ipU.d.ts → services-WrshxCqc.d.ts} +2 -2
  72. package/dist/types/index.d.ts +5 -4
  73. package/dist/types/index.js +7 -7
  74. package/dist/{index-MlUK9AQE.d.ts → useCollection-YAdXfVO7.d.ts} +1 -2
  75. package/dist/utils/abi/index.js +4 -4
  76. package/dist/utils/index.d.ts +1 -1
  77. package/dist/utils/index.js +8 -7
  78. package/package.json +15 -15
  79. package/src/react/_internal/api/__mocks__/builder.msw.ts +157 -80
  80. package/src/react/_internal/api/builder-api.ts +2 -2
  81. package/src/react/_internal/api/builder.gen.ts +667 -112
  82. package/src/react/_internal/api/marketplace.gen.ts +1981 -1316
  83. package/src/react/_internal/types.ts +1 -13
  84. package/src/react/_internal/wagmi/__tests__/create-config.test.ts +99 -84
  85. package/src/react/_internal/wagmi/create-config.ts +8 -4
  86. package/src/react/_internal/wagmi/get-connectors.ts +24 -19
  87. package/src/react/hooks/__tests__/__snapshots__/useListCollections.test.tsx.snap +114 -0
  88. package/src/react/hooks/__tests__/__snapshots__/useMarketplaceConfig.test.tsx.snap +85 -83
  89. package/src/react/hooks/__tests__/useFilters.test.tsx +0 -16
  90. package/src/react/hooks/__tests__/useInventory.test.tsx +16 -16
  91. package/src/react/hooks/__tests__/useListCollections.test.tsx +23 -56
  92. package/src/react/hooks/__tests__/{useCurrencies.test.tsx → useMarketCurrencies.test.tsx} +21 -15
  93. package/src/react/hooks/__tests__/useMarketplaceConfig.test.tsx +2 -59
  94. package/src/react/hooks/index.ts +2 -1
  95. package/src/react/hooks/useBalanceOfCollectible.tsx +5 -3
  96. package/src/react/hooks/useConvertPriceToUSD.tsx +1 -1
  97. package/src/react/hooks/useFilters.tsx +14 -22
  98. package/src/react/hooks/useGetTokenSuppliesMap.ts +28 -0
  99. package/src/react/hooks/useInventory.tsx +4 -3
  100. package/src/react/hooks/useListBalances.tsx +5 -3
  101. package/src/react/hooks/useListCollectibles.tsx +5 -3
  102. package/src/react/hooks/useListCollections.tsx +14 -76
  103. package/src/react/hooks/useMarketCurrencies.tsx +8 -0
  104. package/src/react/hooks/useMarketplaceConfig.tsx +0 -2
  105. package/src/react/queries/index.ts +1 -0
  106. package/src/react/queries/inventory.ts +1 -1
  107. package/src/react/queries/listCollections.ts +118 -0
  108. package/src/react/queries/marketCurrencies.ts +77 -0
  109. package/src/react/queries/marketplaceConfig.ts +83 -55
  110. package/src/react/ssr/__tests__/__snapshots__/create-ssr-client.test.ts.snap +85 -83
  111. package/src/react/ui/components/collectible-card/__tests__/Media.test.tsx +41 -1
  112. package/src/react/ui/components/collectible-card/media/Media.tsx +11 -6
  113. package/src/react/ui/components/collectible-card/media/MediaSkeleton.tsx +1 -1
  114. package/src/react/ui/components/collectible-card/media/types.ts +1 -0
  115. package/src/react/ui/modals/BuyModal/ERC1155QuantityModal.tsx +9 -3
  116. package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +31 -21
  117. package/src/react/ui/modals/BuyModal/hooks/useFees.ts +3 -2
  118. package/src/react/ui/modals/CreateListingModal/Modal.tsx +3 -5
  119. package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +5 -3
  120. package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +2 -2
  121. package/src/react/ui/modals/MakeOfferModal/Modal.tsx +2 -3
  122. package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +4 -3
  123. package/src/react/ui/modals/SellModal/Modal.tsx +0 -1
  124. package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +2 -2
  125. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +0 -1
  126. package/src/react/ui/modals/TransferModal/index.tsx +0 -1
  127. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +2 -2
  128. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +7 -6
  129. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/__tests__/SelectWaasFeeOptions.test.tsx +13 -7
  130. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/index.tsx +3 -5
  131. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/useWaasFeeOptionManager.tsx +5 -3
  132. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
  133. package/src/react/ui/modals/_internal/hooks/useSelectWaasFeeOptions.ts +2 -12
  134. package/src/types/index.ts +1 -6
  135. package/src/types/new-marketplace-types.ts +119 -0
  136. package/src/types/sdk-config.ts +18 -2
  137. package/src/types/types.ts +1 -0
  138. package/tsconfig.tsbuildinfo +1 -1
  139. package/dist/chunk-7F27CJZW.js.map +0 -1
  140. package/dist/chunk-A7BVFBWB.js +0 -81
  141. package/dist/chunk-A7BVFBWB.js.map +0 -1
  142. package/dist/chunk-D7RVSZAQ.js +0 -332
  143. package/dist/chunk-D7RVSZAQ.js.map +0 -1
  144. package/dist/chunk-DWTLVJAW.js.map +0 -1
  145. package/dist/chunk-FGM57QUU.js +0 -128
  146. package/dist/chunk-FGM57QUU.js.map +0 -1
  147. package/dist/chunk-JKCF7HEA.js +0 -1
  148. package/dist/chunk-JKCF7HEA.js.map +0 -1
  149. package/dist/chunk-KTST7ORH.js +0 -53
  150. package/dist/chunk-KTST7ORH.js.map +0 -1
  151. package/dist/chunk-M6NJ73Y5.js.map +0 -1
  152. package/dist/chunk-N7BPFK46.js +0 -1
  153. package/dist/chunk-N7BPFK46.js.map +0 -1
  154. package/dist/chunk-O34GCB47.js.map +0 -1
  155. package/dist/chunk-RVIUUJTP.js +0 -76
  156. package/dist/chunk-RVIUUJTP.js.map +0 -1
  157. package/dist/chunk-SXVUTSMT.js +0 -2895
  158. package/dist/chunk-SXVUTSMT.js.map +0 -1
  159. package/dist/chunk-UJSF7PSC.js.map +0 -1
  160. package/dist/chunk-Y2HJO2VY.js.map +0 -1
  161. package/dist/marketplaceConfig-D0MXemEl.d.ts +0 -17
  162. package/dist/sdk-config-onSPBxJj.d.ts +0 -134
  163. package/dist/types-B8xzPEKX.d.ts +0 -68
  164. package/src/react/hooks/useCurrencies.tsx +0 -77
  165. /package/dist/{chunk-Y63BOO6M.js.map → chunk-LECCEZAO.js.map} +0 -0
  166. /package/dist/{chunk-WH5BZC7W.js.map → chunk-N7SQWS2R.js.map} +0 -0
@@ -1,39 +1,36 @@
1
1
  import type { PropertyFilter } from '@0xsequence/metadata';
2
2
  import { queryOptions, useQuery } from '@tanstack/react-query';
3
- import { z } from 'zod';
4
3
  import { FilterCondition, type SdkConfig } from '../../types';
5
4
  import { compareAddress } from '../../utils';
6
5
  import {
7
- AddressSchema,
8
- QueryArgSchema,
9
6
  collectableKeys,
10
7
  getMetadataClient,
11
8
  getQueryClient,
12
9
  } from '../_internal';
10
+ import { marketplaceConfigOptions } from '../queries/marketplaceConfig';
13
11
  import { useConfig } from './useConfig';
14
- import { marketplaceConfigOptions } from './useMarketplaceConfig';
15
12
 
16
- const UseFiltersSchema = z.object({
17
- chainId: z.number(),
18
- collectionAddress: AddressSchema,
19
- showAllFilters: z.boolean().default(false).optional(),
20
- query: QueryArgSchema,
21
- excludePropertyValues: z.boolean().default(false).optional(),
22
- });
23
-
24
- export type UseFiltersArgs = z.infer<typeof UseFiltersSchema>;
13
+ export type UseFiltersArgs = {
14
+ chainId: number;
15
+ collectionAddress: string;
16
+ showAllFilters?: boolean;
17
+ excludePropertyValues?: boolean;
18
+ query?: {
19
+ enabled?: boolean;
20
+ };
21
+ };
25
22
 
26
23
  export type UseFilterReturn = Awaited<ReturnType<typeof fetchFilters>>;
27
24
 
28
25
  export const fetchFilters = async (args: UseFiltersArgs, config: SdkConfig) => {
29
- const parsedArgs = UseFiltersSchema.parse(args);
26
+ const parsedArgs = args;
30
27
  const metadataClient = getMetadataClient(config);
31
28
 
32
29
  const filters = await metadataClient
33
30
  .getTokenMetadataPropertyFilters({
34
31
  chainID: parsedArgs.chainId.toString(),
35
32
  contractAddress: parsedArgs.collectionAddress,
36
- excludeProperties: [], // TODO: We can leverage this for some of the exclusion logic
33
+ excludeProperties: [],
37
34
  excludePropertyValues: parsedArgs.excludePropertyValues,
38
35
  })
39
36
  .then((resp) => resp.filters);
@@ -44,8 +41,8 @@ export const fetchFilters = async (args: UseFiltersArgs, config: SdkConfig) => {
44
41
  const marketplaceConfig = await queryClient.fetchQuery(
45
42
  marketplaceConfigOptions(config),
46
43
  );
47
- const collectionFilters = marketplaceConfig.collections.find((c) =>
48
- compareAddress(c.address, parsedArgs.collectionAddress),
44
+ const collectionFilters = marketplaceConfig.market.collections.find((c) =>
45
+ compareAddress(c.itemsAddress, parsedArgs.collectionAddress),
49
46
  )?.filterSettings;
50
47
 
51
48
  if (
@@ -58,7 +55,6 @@ export const fetchFilters = async (args: UseFiltersArgs, config: SdkConfig) => {
58
55
 
59
56
  const { filterOrder, exclusions } = collectionFilters;
60
57
 
61
- // Sort the filters based on the filterOrder, the filters that are not in the filterOrder are at the end
62
58
  const sortedFilters = filters.toSorted((a, b) => {
63
59
  const aIndex =
64
60
  filterOrder.indexOf(a.name) > -1
@@ -73,17 +69,14 @@ export const fetchFilters = async (args: UseFiltersArgs, config: SdkConfig) => {
73
69
 
74
70
  const filteredResults = sortedFilters.reduce<PropertyFilter[]>(
75
71
  (acc, filter) => {
76
- // Check if this filter should be excluded
77
72
  const exclusionRule = exclusions.find((rule) => rule.key === filter.name);
78
73
 
79
74
  if (!exclusionRule) {
80
- // No exclusion rule, include the filter
81
75
  acc.push(filter);
82
76
  return acc;
83
77
  }
84
78
 
85
79
  if (exclusionRule.condition === FilterCondition.ENTIRE_KEY) {
86
- // Skip this filter entirely
87
80
  return acc;
88
81
  }
89
82
 
@@ -91,7 +84,6 @@ export const fetchFilters = async (args: UseFiltersArgs, config: SdkConfig) => {
91
84
  exclusionRule.condition === FilterCondition.SPECIFIC_VALUE &&
92
85
  exclusionRule.value
93
86
  ) {
94
- // Filter out specific values while keeping the filter
95
87
  const filteredValues =
96
88
  filter.values?.filter((value) => value !== exclusionRule.value) || [];
97
89
  if (filteredValues.length > 0) {
@@ -0,0 +1,28 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+
3
+ import { useConfig } from '..';
4
+ import { getIndexerClient } from '../_internal';
5
+
6
+ export const useGetTokenSuppliesMap = ({
7
+ chainId,
8
+ tokenIds,
9
+ collectionAddress,
10
+ }: {
11
+ chainId: number;
12
+ tokenIds: string[];
13
+ collectionAddress: string;
14
+ }) => {
15
+ const config = useConfig();
16
+ const indexerClient = getIndexerClient(chainId, config);
17
+ return useQuery({
18
+ queryKey: ['indexer-tokenSupplies', tokenIds, collectionAddress, chainId],
19
+ queryFn: () => {
20
+ return indexerClient.getTokenSuppliesMap({
21
+ tokenMap: {
22
+ [collectionAddress]: tokenIds,
23
+ },
24
+ includeMetadata: false,
25
+ });
26
+ },
27
+ });
28
+ };
@@ -1,4 +1,5 @@
1
1
  import { useInfiniteQuery } from '@tanstack/react-query';
2
+ import { ContractType } from '../../types/api-types';
2
3
  import { type UseInventoryArgs, inventoryOptions } from '../queries/inventory';
3
4
  import { useConfig } from './useConfig';
4
5
  import { useMarketplaceConfig } from './useMarketplaceConfig';
@@ -7,9 +8,9 @@ export function useInventory(args: UseInventoryArgs) {
7
8
  const config = useConfig();
8
9
  const marketplaceConfig = useMarketplaceConfig();
9
10
  const isLaos721 =
10
- marketplaceConfig.data?.collections.find(
11
- (c) => c.address === args.collectionAddress,
12
- )?.isLAOSERC721 ?? false;
11
+ marketplaceConfig.data?.market.collections.find(
12
+ (c) => c.itemsAddress === args.collectionAddress,
13
+ )?.contractType === ContractType.LAOSERC721;
13
14
 
14
15
  return useInfiniteQuery(inventoryOptions({ ...args, isLaos721 }, config));
15
16
  }
@@ -1,4 +1,5 @@
1
1
  import { useInfiniteQuery } from '@tanstack/react-query';
2
+ import { ContractType } from '../../types/api-types';
2
3
  import { listBalancesOptions } from '../queries/listBalances';
3
4
  import type { UseListBalancesArgs } from '../queries/listBalances';
4
5
  import { useConfig } from './useConfig';
@@ -27,9 +28,10 @@ export function useListBalances(args: UseListBalancesArgs) {
27
28
  const config = useConfig();
28
29
  const { data: marketplaceConfig } = useMarketplaceConfig();
29
30
 
30
- const isLaos721 = marketplaceConfig?.collections.find(
31
- (collection) => collection.address === args.contractAddress,
32
- )?.isLAOSERC721;
31
+ const isLaos721 =
32
+ marketplaceConfig?.market.collections.find(
33
+ (collection) => collection.itemsAddress === args.contractAddress,
34
+ )?.contractType === ContractType.LAOSERC721;
33
35
 
34
36
  if (isLaos721) {
35
37
  args.isLaos721 = true;
@@ -1,4 +1,5 @@
1
1
  import { useInfiniteQuery } from '@tanstack/react-query';
2
+ import { ContractType } from '../../types/api-types';
2
3
  import { listCollectiblesOptions } from '../queries/listCollectibles';
3
4
  import type { UseListCollectiblesArgs } from '../queries/listCollectibles';
4
5
  import { useConfig } from './useConfig';
@@ -27,9 +28,10 @@ export function useListCollectibles(args: UseListCollectiblesArgs) {
27
28
  const config = useConfig();
28
29
  const { data: marketplaceConfig } = useMarketplaceConfig();
29
30
 
30
- const isLaos721 = marketplaceConfig?.collections.find(
31
- (collection) => collection.address === args.collectionAddress,
32
- )?.isLAOSERC721;
31
+ const isLaos721 =
32
+ marketplaceConfig?.market.collections.find(
33
+ (collection) => collection.itemsAddress === args.collectionAddress,
34
+ )?.contractType === ContractType.LAOSERC721;
33
35
 
34
36
  if (isLaos721) {
35
37
  args.isLaos721 = true;
@@ -1,88 +1,26 @@
1
- import { queryOptions, useQuery } from '@tanstack/react-query';
2
- import { z } from 'zod';
3
- import type { MarketplaceConfig, SdkConfig } from '../../types';
4
- import {
5
- QueryArgSchema,
6
- collectionKeys,
7
- getMetadataClient,
8
- } from '../_internal';
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import type { MarketplaceType } from '../../types/new-marketplace-types';
3
+ import { listCollectionsOptions } from '../queries/listCollections';
9
4
  import { useConfig } from './useConfig';
10
5
  import { useMarketplaceConfig } from './useMarketplaceConfig';
11
6
 
12
- const UseListCollectionsSchema = z.object({
13
- query: QueryArgSchema.optional().default({}),
14
- });
15
-
16
- export type UseListCollectionsArgs = z.input<typeof UseListCollectionsSchema>;
17
-
18
- export type UseListCollectionsReturn = Awaited<
19
- ReturnType<typeof fetchListCollections>
20
- >;
21
-
22
- type FetchListCollectionsArgs = {
23
- marketplaceConfig: MarketplaceConfig;
24
- query?: z.infer<typeof QueryArgSchema>;
25
- };
26
-
27
- const fetchListCollections = async (
28
- { marketplaceConfig }: FetchListCollectionsArgs,
29
- config: SdkConfig,
30
- ) => {
31
- const metadataClient = getMetadataClient(config);
32
-
33
- if (!marketplaceConfig?.collections?.length) {
34
- return [];
35
- }
36
-
37
- // Group collections by chainId
38
- const collectionsByChain = marketplaceConfig.collections.reduce<
39
- Record<string, string[]>
40
- >((acc, curr) => {
41
- const { chainId, address } = curr;
42
- if (!acc[chainId]) {
43
- acc[chainId] = [];
44
- }
45
- acc[chainId].push(address);
46
- return acc;
47
- }, {});
48
-
49
- // Fetch collections for each chain
50
- const promises = Object.entries(collectionsByChain).map(
51
- ([chainId, addresses]) =>
52
- metadataClient
53
- .getContractInfoBatch({
54
- chainID: chainId,
55
- contractAddresses: addresses,
56
- })
57
- .then((resp) => Object.values(resp.contractInfoMap)),
58
- );
59
-
60
- const results = await Promise.all(promises);
61
- return results.flat();
62
- };
63
-
64
- export const listCollectionsOptions = (
65
- args: FetchListCollectionsArgs,
66
- config: SdkConfig,
67
- ) => {
68
- return queryOptions({
69
- ...args.query,
70
- queryKey: [...collectionKeys.list],
71
- queryFn: () => fetchListCollections(args, config),
72
- });
7
+ type UseListCollectionsArgs = {
8
+ marketplaceType?: MarketplaceType;
9
+ query?: {
10
+ enabled?: boolean;
11
+ };
73
12
  };
74
13
 
75
14
  export const useListCollections = (args: UseListCollectionsArgs = {}) => {
76
15
  const config = useConfig();
77
- const { data: marketplaceConfig, isLoading: isLoadingConfig } =
78
- useMarketplaceConfig();
16
+ const { data: marketplaceConfig } = useMarketplaceConfig();
79
17
 
80
18
  return useQuery({
81
- ...listCollectionsOptions(
82
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
83
- { marketplaceConfig: marketplaceConfig!, query: args.query },
19
+ ...args.query,
20
+ ...listCollectionsOptions({
21
+ marketplaceType: args.marketplaceType,
22
+ marketplaceConfig,
84
23
  config,
85
- ),
86
- enabled: !isLoadingConfig && !!marketplaceConfig,
24
+ }),
87
25
  });
88
26
  };
@@ -0,0 +1,8 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { type UseMarketCurrenciesArgs, currenciesOptions } from '../queries';
3
+ import { useConfig } from './useConfig';
4
+
5
+ export const useMarketCurrencies = (args: UseMarketCurrenciesArgs) => {
6
+ const config = useConfig();
7
+ return useQuery(currenciesOptions(args, config));
8
+ };
@@ -2,8 +2,6 @@ import { useQuery } from '@tanstack/react-query';
2
2
  import { marketplaceConfigOptions } from '../queries/marketplaceConfig';
3
3
  import { useConfig } from './useConfig';
4
4
 
5
- export * from '../queries/marketplaceConfig';
6
-
7
5
  export const useMarketplaceConfig = () => {
8
6
  const config = useConfig();
9
7
  return useQuery(marketplaceConfigOptions(config));
@@ -6,3 +6,4 @@ export * from './highestOffer';
6
6
  export * from './listBalances';
7
7
  export * from './lowestListing';
8
8
  export * from './listTokenMetadata';
9
+ export * from './marketCurrencies';
@@ -82,7 +82,7 @@ function collectibleFromTokenBalance(
82
82
  audio: token.tokenMetadata?.audio,
83
83
  },
84
84
  contractInfo: token.contractInfo,
85
- contractType: token.contractType as
85
+ contractType: token.contractType as unknown as
86
86
  | ContractType.ERC1155
87
87
  | ContractType.ERC721,
88
88
  balance: token.balance,
@@ -0,0 +1,118 @@
1
+ import type { ContractInfo } from '@0xsequence/metadata';
2
+ import { queryOptions, skipToken } from '@tanstack/react-query';
3
+ import type { SdkConfig } from '../../types';
4
+ import type {
5
+ MarketCollection,
6
+ MarketplaceConfig,
7
+ MarketplaceType,
8
+ ShopCollection,
9
+ } from '../../types/new-marketplace-types';
10
+ import { compareAddress } from '../../utils';
11
+ import { collectionKeys, getMetadataClient } from '../_internal';
12
+
13
+ const allCollections = (marketplaceConfig: MarketplaceConfig) => {
14
+ return [
15
+ ...marketplaceConfig.market.collections,
16
+ ...marketplaceConfig.shop.collections,
17
+ ];
18
+ };
19
+
20
+ const fetchListCollections = async ({
21
+ marketplaceType,
22
+ marketplaceConfig,
23
+ config,
24
+ }: {
25
+ marketplaceType?: MarketplaceType;
26
+ marketplaceConfig: MarketplaceConfig;
27
+ config: SdkConfig;
28
+ }) => {
29
+ const metadataClient = getMetadataClient(config);
30
+
31
+ let collections = allCollections(marketplaceConfig);
32
+
33
+ if (!collections?.length) {
34
+ return [];
35
+ }
36
+
37
+ if (marketplaceType) {
38
+ collections = collections.filter(
39
+ (collection) => collection.marketplaceType === marketplaceType,
40
+ );
41
+ }
42
+
43
+ // Group collections by chainId
44
+ const collectionsByChain = collections.reduce<Record<string, string[]>>(
45
+ (acc, curr) => {
46
+ const { chainId, itemsAddress } = curr;
47
+ if (!acc[chainId]) {
48
+ acc[chainId] = [];
49
+ }
50
+ acc[chainId].push(itemsAddress);
51
+ return acc;
52
+ },
53
+ {},
54
+ );
55
+
56
+ // Fetch collections for each chain
57
+ const promises = Object.entries(collectionsByChain).map(
58
+ ([chainId, addresses]) =>
59
+ metadataClient
60
+ .getContractInfoBatch({
61
+ chainID: chainId,
62
+ contractAddresses: addresses,
63
+ })
64
+ .then((resp) => Object.values(resp.contractInfoMap)),
65
+ );
66
+
67
+ const settled = await Promise.allSettled(promises);
68
+ const results = settled
69
+ .filter(
70
+ (r): r is PromiseFulfilledResult<ContractInfo[]> =>
71
+ r.status === 'fulfilled',
72
+ )
73
+ .flatMap((r) => r.value);
74
+
75
+ const collectionsWithMetadata = collections
76
+ .map((collection) => {
77
+ const metadata = results.find((result) =>
78
+ compareAddress(result.address, collection.itemsAddress),
79
+ );
80
+ return { collection, metadata };
81
+ })
82
+ .filter(
83
+ (
84
+ item,
85
+ ): item is {
86
+ collection: MarketCollection | ShopCollection;
87
+ metadata: ContractInfo;
88
+ } => item.metadata !== undefined,
89
+ )
90
+ .map(({ collection, metadata }) => ({
91
+ ...collection,
92
+ ...metadata,
93
+ }));
94
+
95
+ return collectionsWithMetadata;
96
+ };
97
+
98
+ export const listCollectionsOptions = ({
99
+ marketplaceType,
100
+ marketplaceConfig,
101
+ config,
102
+ }: {
103
+ marketplaceType?: MarketplaceType;
104
+ marketplaceConfig: MarketplaceConfig | undefined;
105
+ config: SdkConfig;
106
+ }) => {
107
+ return queryOptions({
108
+ queryKey: [...collectionKeys.list, marketplaceType],
109
+ queryFn: marketplaceConfig
110
+ ? () =>
111
+ fetchListCollections({
112
+ marketplaceType,
113
+ marketplaceConfig,
114
+ config,
115
+ })
116
+ : skipToken,
117
+ });
118
+ };
@@ -0,0 +1,77 @@
1
+ import { queryOptions } from '@tanstack/react-query';
2
+ import { type Address, zeroAddress } from 'viem';
3
+ import type { SdkConfig } from '../../types';
4
+ import { compareAddress } from '../../utils';
5
+ import {
6
+ currencyKeys,
7
+ getMarketplaceClient,
8
+ getQueryClient,
9
+ } from '../_internal';
10
+ import { marketplaceConfigOptions } from './marketplaceConfig';
11
+
12
+ type QueryArg = {
13
+ enabled?: boolean;
14
+ };
15
+
16
+ export interface UseMarketCurrenciesArgs {
17
+ chainId: number;
18
+ includeNativeCurrency?: boolean;
19
+ collectionAddress?: Address;
20
+ query?: QueryArg;
21
+ }
22
+
23
+ const fetchMarketCurrencies = async (
24
+ args: UseMarketCurrenciesArgs,
25
+ config: SdkConfig,
26
+ ) => {
27
+ const includeNativeCurrency = args.includeNativeCurrency ?? true;
28
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
29
+
30
+ let currencies = await marketplaceClient.listCurrencies().then((resp) =>
31
+ resp.currencies.map((currency) => ({
32
+ ...currency,
33
+ contractAddress: currency.contractAddress || zeroAddress,
34
+ })),
35
+ );
36
+
37
+ if (args.collectionAddress) {
38
+ const queryClient = getQueryClient();
39
+ const marketplaceConfig = await queryClient.fetchQuery(
40
+ marketplaceConfigOptions(config),
41
+ );
42
+
43
+ const currenciesOptions = marketplaceConfig.market.collections.find(
44
+ (collection) =>
45
+ compareAddress(collection.itemsAddress, args.collectionAddress),
46
+ )?.currencyOptions;
47
+
48
+ // Filter currencies based on collection currency options
49
+ if (currenciesOptions) {
50
+ currencies = currencies.filter((currency) =>
51
+ currenciesOptions.includes(currency.contractAddress),
52
+ );
53
+ }
54
+ }
55
+
56
+ if (!includeNativeCurrency) {
57
+ currencies = currencies.filter((currency) => !currency.nativeCurrency);
58
+ }
59
+
60
+ return currencies;
61
+ };
62
+
63
+ export const currenciesOptions = (
64
+ args: UseMarketCurrenciesArgs,
65
+ config: SdkConfig,
66
+ ) => {
67
+ return queryOptions({
68
+ ...args.query,
69
+ queryKey: [
70
+ ...currencyKeys.lists,
71
+ args.chainId,
72
+ args.includeNativeCurrency ?? true,
73
+ args.collectionAddress,
74
+ ],
75
+ queryFn: () => fetchMarketCurrencies(args, config),
76
+ });
77
+ };