@0xsequence/marketplace-sdk 0.7.0 → 0.8.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 (227) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +11 -0
  3. package/.changeset/seven-doors-taste.md +5 -0
  4. package/CHANGELOG.md +13 -0
  5. package/dist/{chunk-MPBN3E54.js → chunk-2VHHJNXY.js} +3 -3
  6. package/dist/{chunk-FBUMNJQ4.js → chunk-3II5GLHE.js} +2 -2
  7. package/dist/chunk-3JU7SQVE.js +182 -0
  8. package/dist/chunk-3JU7SQVE.js.map +1 -0
  9. package/dist/{chunk-XTGMMNV5.js → chunk-A5ACY5YV.js} +2 -2
  10. package/dist/chunk-ABSYNRT5.js +128 -0
  11. package/dist/chunk-ABSYNRT5.js.map +1 -0
  12. package/dist/{chunk-XNA64MZQ.js → chunk-BCO4CYE4.js} +2 -2
  13. package/dist/{chunk-HTFORA4Q.js → chunk-BN36GABQ.js} +1883 -1010
  14. package/dist/chunk-BN36GABQ.js.map +1 -0
  15. package/dist/{chunk-4XK7XNJ7.js → chunk-BNAUZXPV.js} +73 -2
  16. package/dist/chunk-BNAUZXPV.js.map +1 -0
  17. package/dist/{chunk-Q5URKSC4.js → chunk-FMEEJFAF.js} +1 -1
  18. package/dist/{chunk-BBASZVT3.js → chunk-GBQVYNCD.js} +5 -6
  19. package/dist/chunk-GBQVYNCD.js.map +1 -0
  20. package/dist/{chunk-3AKOPSON.js → chunk-IZ44XPBH.js} +2 -9
  21. package/dist/chunk-IZ44XPBH.js.map +1 -0
  22. package/dist/{chunk-EAJ5K7QV.js → chunk-Q5RKAMYF.js} +3 -4
  23. package/dist/chunk-Q5RKAMYF.js.map +1 -0
  24. package/dist/{chunk-RBEPPVLT.js → chunk-X3QNSQER.js} +145 -355
  25. package/dist/chunk-X3QNSQER.js.map +1 -0
  26. package/dist/{index-CzTANLaA.d.ts → index-CnaFSNE9.d.ts} +6 -7
  27. package/dist/index.css +113 -31
  28. package/dist/index.css.map +1 -1
  29. package/dist/index.d.ts +2 -4
  30. package/dist/index.js +4 -4
  31. package/dist/listCollectibles-B0tbqnRd.d.ts +155 -0
  32. package/dist/react/_internal/api/index.d.ts +28 -2
  33. package/dist/react/_internal/api/index.js +3 -1
  34. package/dist/react/_internal/databeat/index.js +10 -9
  35. package/dist/react/_internal/index.d.ts +2 -3
  36. package/dist/react/_internal/index.js +4 -4
  37. package/dist/react/_internal/wagmi/index.js +2 -2
  38. package/dist/react/hooks/index.d.ts +259 -674
  39. package/dist/react/hooks/index.js +11 -20
  40. package/dist/react/hooks/options/index.d.ts +1 -2
  41. package/dist/react/hooks/options/index.js +4 -4
  42. package/dist/react/index.d.ts +7 -7
  43. package/dist/react/index.js +15 -24
  44. package/dist/react/queries/index.d.ts +25 -0
  45. package/dist/react/queries/index.js +48 -0
  46. package/dist/react/queries/index.js.map +1 -0
  47. package/dist/react/ssr/index.js +3 -3
  48. package/dist/react/ui/components/collectible-card/index.d.ts +1 -6
  49. package/dist/react/ui/components/collectible-card/index.js +13 -12
  50. package/dist/react/ui/components/marketplace-logos/index.js +1 -1
  51. package/dist/react/ui/icons/index.js +6 -6
  52. package/dist/react/ui/index.d.ts +18 -22
  53. package/dist/react/ui/index.js +13 -12
  54. package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +6 -11
  55. package/dist/react/ui/modals/_internal/components/actionModal/index.js +10 -9
  56. package/dist/types/index.js +2 -2
  57. package/dist/{types-Ct1uCT3M.d.ts → types-o_pKUpQG.d.ts} +2 -5
  58. package/dist/utils/index.d.ts +1 -5
  59. package/dist/utils/index.js +4 -4
  60. package/package.json +22 -16
  61. package/src/react/_internal/api/__mocks__/indexer.msw.ts +3 -1
  62. package/src/react/_internal/api/__mocks__/marketplace.msw.ts +1 -1
  63. package/src/react/_internal/api/__mocks__/metadata.msw.ts +14 -12
  64. package/src/react/_internal/api/index.ts +1 -0
  65. package/src/react/_internal/api/laos-api.ts +103 -0
  66. package/src/react/_internal/api/zod-schema.ts +3 -3
  67. package/src/react/_internal/types.ts +1 -10
  68. package/src/react/_internal/wallet/__tests__/wallet.test.ts +43 -0
  69. package/src/react/_internal/wallet/useWallet.ts +6 -3
  70. package/src/react/hooks/__tests__/useAutoSelectFeeOption.test.tsx +1 -1
  71. package/src/react/hooks/__tests__/useCancelOrder.test.tsx +1 -1
  72. package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +1 -1
  73. package/src/react/hooks/__tests__/useCollectible.test.tsx +2 -2
  74. package/src/react/hooks/__tests__/useCollection.test.tsx +2 -2
  75. package/src/react/hooks/__tests__/useComparePrices.test.tsx +1 -1
  76. package/src/react/hooks/__tests__/useConvertPriceToUSD.test.tsx +1 -1
  77. package/src/react/hooks/__tests__/useCountListingsForCollectible.test.tsx +1 -1
  78. package/src/react/hooks/__tests__/useCountOfCollectables.test.tsx +2 -2
  79. package/src/react/hooks/__tests__/useCountOffersForCollectible.test.tsx +1 -1
  80. package/src/react/hooks/__tests__/useCurrencies.test.tsx +2 -2
  81. package/src/react/hooks/__tests__/useCurrency.test.tsx +2 -2
  82. package/src/react/hooks/__tests__/useFilters.test.tsx +2 -2
  83. package/src/react/hooks/__tests__/useFloorOrder.test.tsx +2 -2
  84. package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +1 -1
  85. package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +1 -1
  86. package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +1 -1
  87. package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +1 -1
  88. package/src/react/hooks/__tests__/useListCollectibleActivities.test.tsx +2 -2
  89. package/src/react/hooks/__tests__/useListCollectibles.test.tsx +3 -2
  90. package/src/react/hooks/__tests__/useListCollectiblesPaginated.test.tsx +1 -1
  91. package/src/react/hooks/__tests__/useListCollectionActivities.test.tsx +1 -1
  92. package/src/react/hooks/__tests__/useListListingsForCollectible.test.tsx +1 -1
  93. package/src/react/hooks/__tests__/useListOffersForCollectible.test.tsx +1 -1
  94. package/src/react/hooks/__tests__/useLowestListing.test.tsx +1 -1
  95. package/src/react/hooks/__tests__/useRoyalty.test.tsx +1 -2
  96. package/src/react/hooks/index.ts +0 -1
  97. package/src/react/hooks/options/collectionOptions.ts +2 -3
  98. package/src/react/hooks/useAutoSelectFeeOption.tsx +1 -1
  99. package/src/react/hooks/useCancelOrder.tsx +3 -3
  100. package/src/react/hooks/useCancelTransactionSteps.tsx +1 -1
  101. package/src/react/hooks/useCheckoutOptions.tsx +1 -2
  102. package/src/react/hooks/useCollectible.tsx +2 -3
  103. package/src/react/hooks/useCollectionBalanceDetails.tsx +1 -2
  104. package/src/react/hooks/useComparePrices.tsx +2 -9
  105. package/src/react/hooks/useConvertPriceToUSD.tsx +1 -4
  106. package/src/react/hooks/useCountListingsForCollectible.tsx +1 -2
  107. package/src/react/hooks/useCountOfCollectables.tsx +1 -2
  108. package/src/react/hooks/useCountOffersForCollectible.tsx +1 -2
  109. package/src/react/hooks/useCurrencies.tsx +1 -4
  110. package/src/react/hooks/useCurrency.tsx +3 -8
  111. package/src/react/hooks/useFilters.tsx +5 -4
  112. package/src/react/hooks/useFloorOrder.tsx +1 -2
  113. package/src/react/hooks/useGenerateCancelTransaction.tsx +3 -6
  114. package/src/react/hooks/useGenerateListingTransaction.tsx +2 -3
  115. package/src/react/hooks/useGenerateOfferTransaction.tsx +2 -3
  116. package/src/react/hooks/useGenerateSellTransaction.tsx +3 -6
  117. package/src/react/hooks/useHighestOffer.tsx +1 -1
  118. package/src/react/hooks/useListCollectibles.tsx +33 -61
  119. package/src/react/hooks/useListCollectiblesPaginated.tsx +2 -6
  120. package/src/react/hooks/useListListingsForCollectible.tsx +1 -2
  121. package/src/react/hooks/useListOffersForCollectible.tsx +1 -2
  122. package/src/react/hooks/useLowestListing.tsx +1 -2
  123. package/src/react/hooks/useRoyalty.tsx +3 -8
  124. package/src/react/hooks/useTransferTokens.tsx +2 -2
  125. package/src/react/queries/balanceOfCollectible.ts +9 -32
  126. package/src/react/queries/getTokenSupplies.ts +38 -0
  127. package/src/react/queries/index.ts +5 -0
  128. package/src/react/queries/listCollectibles.ts +96 -0
  129. package/src/react/ui/components/_internals/action-button/ActionButton.tsx +1 -1
  130. package/src/react/ui/components/_internals/action-button/__tests__/ActionButton.test.tsx +1 -1
  131. package/src/react/ui/components/_internals/action-button/components/NonOwnerActions.tsx +4 -3
  132. package/src/react/ui/components/_internals/action-button/components/OwnerActions.tsx +1 -1
  133. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +2 -3
  134. package/src/react/ui/components/collectible-card/__tests__/CollectibleCard.test.tsx +1 -1
  135. package/src/react/ui/modals/BuyModal/ERC1155QuantityModal.tsx +127 -0
  136. package/src/react/ui/modals/BuyModal/Modal.tsx +70 -85
  137. package/src/react/ui/modals/BuyModal/__tests__/Modal.test.tsx +85 -226
  138. package/src/react/ui/modals/BuyModal/__tests__/Modal1155.test.tsx +140 -0
  139. package/src/react/ui/modals/BuyModal/__tests__/store.test.ts +67 -76
  140. package/src/react/ui/modals/BuyModal/hooks/__tests__/useCheckoutOptions.test.tsx +1 -60
  141. package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +1 -1
  142. package/src/react/ui/modals/BuyModal/hooks/useCheckoutOptions.ts +29 -13
  143. package/src/react/ui/modals/BuyModal/hooks/useLoadData.ts +26 -21
  144. package/src/react/ui/modals/BuyModal/hooks/usePaymentModalParams.ts +200 -0
  145. package/src/react/ui/modals/BuyModal/index.tsx +4 -14
  146. package/src/react/ui/modals/BuyModal/store.ts +71 -76
  147. package/src/react/ui/modals/CreateListingModal/Modal.tsx +71 -7
  148. package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +2 -2
  149. package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +1 -1
  150. package/src/react/ui/modals/CreateListingModal/hooks/useGetTokenApproval.ts +1 -1
  151. package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +9 -5
  152. package/src/react/ui/modals/CreateListingModal/store.ts +7 -2
  153. package/src/react/ui/modals/MakeOfferModal/Modal.tsx +103 -6
  154. package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +1 -1
  155. package/src/react/ui/modals/MakeOfferModal/hooks/useGetTokenApproval.tsx +1 -1
  156. package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +1 -1
  157. package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +8 -4
  158. package/src/react/ui/modals/MakeOfferModal/store.ts +5 -3
  159. package/src/react/ui/modals/SellModal/Modal.tsx +76 -4
  160. package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +1 -1
  161. package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +1 -1
  162. package/src/react/ui/modals/SellModal/hooks/useSell.tsx +1 -1
  163. package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +16 -8
  164. package/src/react/ui/modals/SellModal/store.ts +5 -3
  165. package/src/react/ui/modals/TransferModal/_store.ts +15 -3
  166. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TokenQuantityInput.tsx +58 -0
  167. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TransferButton.tsx +56 -0
  168. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/WalletAddressInput.tsx +50 -0
  169. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +94 -66
  170. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +22 -14
  171. package/src/react/ui/modals/TransferModal/index.tsx +72 -38
  172. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +43 -42
  173. package/src/react/ui/modals/_internal/components/actionModal/store.ts +1 -2
  174. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +2 -2
  175. package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +9 -1
  176. package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +27 -12
  177. package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +1 -1
  178. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +19 -3
  179. package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +3 -0
  180. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/_components/ActionButtons.tsx +60 -0
  181. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/_components/BalanceIndicator.tsx +30 -0
  182. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/index.tsx +126 -0
  183. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/store.ts +25 -0
  184. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/useWaasFeeOptionManager.tsx +74 -0
  185. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +1 -2
  186. package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +1 -2
  187. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +1 -1
  188. package/src/react/ui/modals/_internal/components/transaction-footer/index.tsx +4 -7
  189. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +1 -1
  190. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +1 -1
  191. package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +1 -1
  192. package/src/react/ui/modals/_internal/components/transactionStatusModal/hooks/useTransactionStatus.ts +1 -1
  193. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +6 -1
  194. package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +2 -2
  195. package/src/react/ui/modals/_internal/components/waasFeeOptionsSelect/WaasFeeOptionsSelect.tsx +10 -31
  196. package/src/react/ui/modals/_internal/hooks/useSelectWaasFeeOptions.ts +53 -0
  197. package/src/react/ui/modals/_internal/types.ts +2 -1
  198. package/src/types/waas-types.ts +38 -0
  199. package/src/utils/network.ts +2 -4
  200. package/test/const.ts +1 -1
  201. package/test/setup.ts +10 -0
  202. package/test/test-utils.tsx +31 -5
  203. package/tsconfig.tsbuildinfo +1 -1
  204. package/dist/chunk-3AKOPSON.js.map +0 -1
  205. package/dist/chunk-4XK7XNJ7.js.map +0 -1
  206. package/dist/chunk-BBASZVT3.js.map +0 -1
  207. package/dist/chunk-EAJ5K7QV.js.map +0 -1
  208. package/dist/chunk-HTFORA4Q.js.map +0 -1
  209. package/dist/chunk-OFY7OFTL.js +0 -458
  210. package/dist/chunk-OFY7OFTL.js.map +0 -1
  211. package/dist/chunk-RBEPPVLT.js.map +0 -1
  212. package/src/react/hooks/__tests__/useGenerateBuyTransaction.test.tsx +0 -172
  213. package/src/react/hooks/useGenerateBuyTransaction.tsx +0 -80
  214. package/src/react/ui/modals/BuyModal/hooks/__tests__/useBuyCollectable.test.tsx +0 -349
  215. package/src/react/ui/modals/BuyModal/hooks/__tests__/useLoadData.test.tsx +0 -185
  216. package/src/react/ui/modals/BuyModal/hooks/useBuyCollectable.ts +0 -170
  217. package/src/react/ui/modals/BuyModal/modals/CheckoutModal.tsx +0 -47
  218. package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +0 -140
  219. package/src/react/ui/modals/BuyModal/modals/__tests__/CheckoutModal.test.tsx +0 -162
  220. package/src/react/ui/modals/BuyModal/modals/__tests__/Modal1155.test.tsx +0 -327
  221. package/src/react/ui/modals/_internal/components/waasFeeOptionsBox/index.tsx +0 -124
  222. package/src/react/ui/modals/_internal/components/waasFeeOptionsBox/store.ts +0 -12
  223. /package/dist/{chunk-MPBN3E54.js.map → chunk-2VHHJNXY.js.map} +0 -0
  224. /package/dist/{chunk-FBUMNJQ4.js.map → chunk-3II5GLHE.js.map} +0 -0
  225. /package/dist/{chunk-XTGMMNV5.js.map → chunk-A5ACY5YV.js.map} +0 -0
  226. /package/dist/{chunk-XNA64MZQ.js.map → chunk-BCO4CYE4.js.map} +0 -0
  227. /package/dist/{chunk-Q5URKSC4.js.map → chunk-FMEEJFAF.js.map} +0 -0
@@ -2,7 +2,6 @@ import { useMutation } from '@tanstack/react-query';
2
2
  import type { SdkConfig } from '../../types';
3
3
  import { dateToUnixTime } from '../../utils/date';
4
4
  import {
5
- type ChainId,
6
5
  type CreateReq,
7
6
  type GenerateOfferTransactionArgs,
8
7
  type Step,
@@ -11,7 +10,7 @@ import {
11
10
  import { useConfig } from './useConfig';
12
11
 
13
12
  export type UseGenerateOfferTransactionArgs = {
14
- chainId: ChainId;
13
+ chainId: number;
15
14
  onSuccess?: (data?: Step[]) => void;
16
15
  };
17
16
 
@@ -29,7 +28,7 @@ export type GenerateOfferTransactionProps = Omit<
29
28
  export const generateOfferTransaction = async (
30
29
  params: GenerateOfferTransactionProps,
31
30
  config: SdkConfig,
32
- chainId: ChainId,
31
+ chainId: number,
33
32
  ) => {
34
33
  const args = {
35
34
  ...params,
@@ -2,8 +2,6 @@ import { useMutation } from '@tanstack/react-query';
2
2
  import { z } from 'zod';
3
3
  import type { SdkConfig } from '../../types';
4
4
  import {
5
- type ChainId,
6
- ChainIdSchema,
7
5
  type GenerateSellTransactionArgs,
8
6
  getMarketplaceClient,
9
7
  } from '../_internal';
@@ -11,7 +9,7 @@ import { stepSchema } from '../_internal/api/zod-schema';
11
9
  import { useConfig } from './useConfig';
12
10
 
13
11
  const UserGeneratSellTransactionArgsSchema = z.object({
14
- chainId: ChainIdSchema.pipe(z.coerce.string()),
12
+ chainId: z.number(),
15
13
  onSuccess: z.function().args(stepSchema.array().optional()).optional(),
16
14
  });
17
15
 
@@ -22,10 +20,9 @@ type UseGenerateSellTransactionArgs = z.infer<
22
20
  export const generateSellTransaction = async (
23
21
  args: GenerateSellTransactionArgs,
24
22
  config: SdkConfig,
25
- chainId: ChainId,
23
+ chainId: number,
26
24
  ) => {
27
- const parsedChainId = ChainIdSchema.pipe(z.coerce.string()).parse(chainId);
28
- const marketplaceClient = getMarketplaceClient(parsedChainId, config);
25
+ const marketplaceClient = getMarketplaceClient(chainId, config);
29
26
  return marketplaceClient
30
27
  .generateSellTransaction(args)
31
28
  .then((data) => data.steps);
@@ -32,7 +32,7 @@ export type UseHighestOfferArgs = {
32
32
  * const { data, isLoading, error } = useHighestOffer({
33
33
  * collectionAddress: '0x123...',
34
34
  * tokenId: '1',
35
- * chainId: '1',
35
+ * chainId: 1,
36
36
  * query: {
37
37
  * enabled: true,
38
38
  * refetchInterval: 10000,
@@ -1,67 +1,39 @@
1
- import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
2
- import { z } from 'zod';
3
- import type { Page, SdkConfig } from '../../types';
4
- import {
5
- AddressSchema,
6
- ChainIdSchema,
7
- type ListCollectiblesArgs,
8
- QueryArgSchema,
9
- collectableKeys,
10
- getMarketplaceClient,
11
- } from '../_internal';
12
- import { listCollectiblesArgsSchema } from '../_internal/api/zod-schema';
1
+ import { useInfiniteQuery } from '@tanstack/react-query';
2
+ import { listCollectiblesOptions } from '../queries/listCollectibles';
3
+ import type { UseListCollectiblesArgs } from '../queries/listCollectibles';
13
4
  import { useConfig } from './useConfig';
5
+ import { useMarketplaceConfig } from './useMarketplaceConfig';
14
6
 
15
- const UseListCollectiblesArgsSchema = listCollectiblesArgsSchema
16
- .omit({
17
- contractAddress: true,
18
- })
19
- .extend({
20
- collectionAddress: AddressSchema,
21
- chainId: ChainIdSchema.pipe(z.coerce.string()),
22
- query: QueryArgSchema,
23
- });
24
-
25
- export type UseListCollectiblesArgs = z.infer<
26
- typeof UseListCollectiblesArgsSchema
27
- >;
28
-
29
- export type UseListCollectiblesReturn = Awaited<
30
- ReturnType<typeof fetchCollectibles>
31
- >;
32
-
33
- const fetchCollectibles = async (
34
- args: UseListCollectiblesArgs,
35
- marketplaceClient: Awaited<ReturnType<typeof getMarketplaceClient>>,
36
- page: Page,
37
- ) => {
38
- const parsedArgs = UseListCollectiblesArgsSchema.parse(args);
39
- const arg = {
40
- ...parsedArgs,
41
- contractAddress: parsedArgs.collectionAddress,
42
- page: page,
43
- } satisfies ListCollectiblesArgs;
7
+ /**
8
+ * Hook to fetch a list of collectibles with pagination support
9
+ *
10
+ * @param args - The arguments for fetching the collectibles
11
+ * @returns Infinite query result containing the collectibles data including orders
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const { data, isLoading, error, fetchNextPage } = useListCollectibles({
16
+ * chainId: 1,
17
+ * collectionAddress: '0x123...',
18
+ * includeMetadata: true,
19
+ * query: {
20
+ * enabled: true,
21
+ * refetchInterval: 10000,
22
+ * }
23
+ * });
24
+ * ```
25
+ */
26
+ export function useListCollectibles(args: UseListCollectiblesArgs) {
27
+ const config = useConfig();
28
+ const { data: marketplaceConfig } = useMarketplaceConfig();
44
29
 
45
- return marketplaceClient.listCollectibles(arg);
46
- };
30
+ const isLaos721 = marketplaceConfig?.collections.find(
31
+ (collection) => collection.address === args.collectionAddress,
32
+ )?.isLAOSERC721;
47
33
 
48
- export const listCollectiblesOptions = (
49
- args: UseListCollectiblesArgs,
50
- config: SdkConfig,
51
- ) => {
52
- const marketplaceClient = getMarketplaceClient(args.chainId, config);
53
- return infiniteQueryOptions({
54
- queryKey: [...collectableKeys.lists, args],
55
- queryFn: ({ pageParam }) =>
56
- fetchCollectibles(args, marketplaceClient, pageParam),
57
- initialPageParam: { page: 1, pageSize: 30 },
58
- getNextPageParam: (lastPage) =>
59
- lastPage.page?.more ? lastPage.page : undefined,
60
- enabled: args.query?.enabled ?? true,
61
- });
62
- };
34
+ if (isLaos721) {
35
+ args.isLaos721 = true;
36
+ }
63
37
 
64
- export const useListCollectibles = (args: UseListCollectiblesArgs) => {
65
- const config = useConfig();
66
38
  return useInfiniteQuery(listCollectiblesOptions(args, config));
67
- };
39
+ }
@@ -3,7 +3,6 @@ import { z } from 'zod';
3
3
  import type { Page, SdkConfig } from '../../types';
4
4
  import {
5
5
  AddressSchema,
6
- ChainIdSchema,
7
6
  type ListCollectiblesArgs,
8
7
  collectableKeys,
9
8
  getMarketplaceClient,
@@ -17,7 +16,7 @@ const UseListCollectiblesPaginatedArgsSchema = listCollectiblesArgsSchema
17
16
  })
18
17
  .extend({
19
18
  collectionAddress: AddressSchema,
20
- chainId: ChainIdSchema.pipe(z.coerce.string()),
19
+ chainId: z.number(),
21
20
  query: z
22
21
  .object({
23
22
  enabled: z.boolean().optional(),
@@ -59,10 +58,7 @@ export const listCollectiblesPaginatedOptions = (
59
58
  args: UseListCollectiblesPaginatedArgs,
60
59
  config: SdkConfig,
61
60
  ) => {
62
- const marketplaceClient = getMarketplaceClient(
63
- args.chainId as string,
64
- config,
65
- );
61
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
66
62
  return queryOptions({
67
63
  queryKey: [...collectableKeys.lists, 'paginated', args],
68
64
  queryFn: () => fetchCollectiblesPaginated(args, marketplaceClient),
@@ -2,7 +2,6 @@ import { queryOptions, useQuery } from '@tanstack/react-query';
2
2
  import { z } from 'zod';
3
3
  import type { SdkConfig } from '../../types';
4
4
  import {
5
- ChainIdSchema,
6
5
  type ListListingsForCollectibleArgs,
7
6
  collectableKeys,
8
7
  getMarketplaceClient,
@@ -13,7 +12,7 @@ import { useConfig } from './useConfig';
13
12
  const UseListListingsForCollectibleArgsSchema =
14
13
  listListingsForCollectibleArgsSchema
15
14
  .extend({
16
- chainId: ChainIdSchema.pipe(z.coerce.string()),
15
+ chainId: z.number(),
17
16
  collectionAddress: z.string(),
18
17
  collectibleId: z.string(),
19
18
  })
@@ -2,7 +2,6 @@ import { queryOptions, useQuery } from '@tanstack/react-query';
2
2
  import { z } from 'zod';
3
3
  import type { SdkConfig } from '../../types';
4
4
  import {
5
- ChainIdSchema,
6
5
  type ListOffersForCollectibleArgs,
7
6
  collectableKeys,
8
7
  getMarketplaceClient,
@@ -12,7 +11,7 @@ import { useConfig } from './useConfig';
12
11
 
13
12
  const UseListOffersForCollectibleArgsSchema = listOffersForCollectibleArgsSchema
14
13
  .extend({
15
- chainId: ChainIdSchema.pipe(z.coerce.string()),
14
+ chainId: z.number(),
16
15
  collectionAddress: z.string(),
17
16
  collectibleId: z.string(),
18
17
  })
@@ -3,7 +3,6 @@ import { z } from 'zod';
3
3
  import type { SdkConfig } from '../../types';
4
4
  import {
5
5
  AddressSchema,
6
- ChainIdSchema,
7
6
  QueryArgSchema,
8
7
  collectableKeys,
9
8
  getMarketplaceClient,
@@ -17,7 +16,7 @@ const UseLowestListingSchema = getCollectibleLowestListingArgsSchema
17
16
  })
18
17
  .extend({
19
18
  collectionAddress: AddressSchema,
20
- chainId: ChainIdSchema.pipe(z.coerce.string()),
19
+ chainId: z.number(),
21
20
  query: QueryArgSchema,
22
21
  });
23
22
 
@@ -1,15 +1,10 @@
1
1
  import { useReadContract } from 'wagmi';
2
2
  import { z } from 'zod';
3
3
  import { EIP2981_ABI } from '../../utils';
4
- import {
5
- AddressSchema,
6
- ChainIdSchema,
7
- QueryArgSchema,
8
- collectableKeys,
9
- } from '../_internal';
4
+ import { AddressSchema, QueryArgSchema, collectableKeys } from '../_internal';
10
5
 
11
6
  const UseRoyaltySchema = z.object({
12
- chainId: ChainIdSchema.pipe(z.coerce.string()),
7
+ chainId: z.number(),
13
8
  collectionAddress: AddressSchema,
14
9
  collectibleId: z.string(),
15
10
  query: QueryArgSchema.optional(),
@@ -27,7 +22,7 @@ export const useRoyalty = (args: UseRoyaltyArgs) => {
27
22
  address: collectionAddress,
28
23
  functionName: 'royaltyInfo',
29
24
  args: [BigInt(collectibleId), BigInt(100)],
30
- chainId: Number(chainId),
25
+ chainId,
31
26
  query: query,
32
27
  });
33
28
 
@@ -2,10 +2,10 @@ import { type Abi, type Address, type Hex, erc721Abi } from 'viem';
2
2
  import { useAccount, useWriteContract } from 'wagmi';
3
3
  import { ERC1155_ABI } from '../../utils';
4
4
  import { NoWalletConnectedError } from '../../utils/_internal/error/transaction';
5
- import type { ChainId, ContractType } from '../_internal';
5
+ import type { ContractType } from '../_internal';
6
6
 
7
7
  interface BaseTransferParams {
8
- chainId: ChainId;
8
+ chainId: number;
9
9
  collectionAddress: Hex;
10
10
  tokenId: string;
11
11
  receiverAddress: Address;
@@ -1,9 +1,8 @@
1
- import type { GetTokenBalancesReturn } from '@0xsequence/indexer';
2
1
  import { queryOptions, skipToken } from '@tanstack/react-query';
3
2
  import type { Hex } from 'viem';
4
3
  import type { UseQueryParameters } from 'wagmi/query';
5
4
  import type { SdkConfig } from '../../types';
6
- import { collectableKeys, getIndexerClient } from '../_internal';
5
+ import { LaosAPI, collectableKeys, getIndexerClient } from '../_internal';
7
6
 
8
7
  export type UseBalanceOfCollectibleArgs = {
9
8
  collectionAddress: Hex;
@@ -22,40 +21,18 @@ export type UseBalanceOfCollectibleArgs = {
22
21
  * @returns The balance data
23
22
  */
24
23
  export async function fetchBalanceOfCollectible(
25
- args: UseBalanceOfCollectibleArgs,
24
+ args: Omit<UseBalanceOfCollectibleArgs, 'userAddress'> & { userAddress: Hex },
26
25
  config: SdkConfig,
27
26
  ) {
28
27
  if (args.isLaos721) {
29
- const response = await fetch(
30
- 'https://extensions.api.laosnetwork.io/token/GetTokenBalances',
31
- {
32
- method: 'POST',
33
- headers: {
34
- 'Content-Type': 'application/json',
35
- },
36
- body: JSON.stringify({
37
- chainId: args.chainId.toString(),
38
- accountAddress: args.userAddress,
39
- includeMetadata: true,
40
- page: {
41
- sort: [
42
- {
43
- column: 'CREATED_AT',
44
- order: 'DESC',
45
- },
46
- ],
47
- },
48
- }),
49
- },
50
- );
51
-
52
- if (!response.ok) {
53
- throw new Error(`Laos API request failed with status ${response.status}`);
54
- }
28
+ const laosApi = new LaosAPI();
29
+ const response = await laosApi.getTokenBalances({
30
+ chainId: args.chainId.toString(),
31
+ accountAddress: args.userAddress,
32
+ includeMetadata: true,
33
+ });
55
34
 
56
- // TODO: This is pritty unsafe, we should validate the response
57
- const data = (await response.json()) as GetTokenBalancesReturn;
58
- return data.balances[0] || null;
35
+ return response.balances[0] || null;
59
36
  }
60
37
 
61
38
  const indexerClient = getIndexerClient(args.chainId, config);
@@ -0,0 +1,38 @@
1
+ import { queryOptions } from '@tanstack/react-query';
2
+ import type { SdkConfig } from '../../types';
3
+ //TODO: This is not complete, there is no hook for this,
4
+ // add it if we need it in the future
5
+ import { LaosAPI, getIndexerClient } from '../_internal';
6
+
7
+ export type UseGetTokenSuppliesArgs = {
8
+ chainId: number;
9
+ contractAddress: string;
10
+ tokenId: string;
11
+ isLaos721?: boolean;
12
+ };
13
+
14
+ export async function getTokenSupplies(
15
+ args: UseGetTokenSuppliesArgs,
16
+ config: SdkConfig,
17
+ ) {
18
+ if (args.isLaos721) {
19
+ const laosApi = new LaosAPI();
20
+ return laosApi.getTokenSupplies({
21
+ chainId: args.chainId.toString(),
22
+ contractAddress: args.contractAddress,
23
+ });
24
+ }
25
+
26
+ const indexerClient = getIndexerClient(args.chainId, config);
27
+ return await indexerClient.getTokenSupplies(args);
28
+ }
29
+
30
+ export function getTokenSuppliesOptions(
31
+ args: UseGetTokenSuppliesArgs,
32
+ config: SdkConfig,
33
+ ) {
34
+ return queryOptions({
35
+ queryKey: ['getTokenSupplies', args],
36
+ queryFn: () => getTokenSupplies(args, config),
37
+ });
38
+ }
@@ -0,0 +1,5 @@
1
+ export * from './balanceOfCollectible';
2
+ export * from './getTokenSupplies';
3
+ export * from './listCollectibles';
4
+ export * from './highestOffer';
5
+ export * from './listBalances';
@@ -0,0 +1,96 @@
1
+ import { infiniteQueryOptions } from '@tanstack/react-query';
2
+ import type { Hex } from 'viem';
3
+ import type { Page, SdkConfig } from '../../types';
4
+ import type {
5
+ CollectibleOrder,
6
+ CollectiblesFilter,
7
+ ListCollectiblesArgs,
8
+ ListCollectiblesReturn,
9
+ } from '../_internal';
10
+ import { OrderSide, collectableKeys, getMarketplaceClient } from '../_internal';
11
+ import { fetchBalances } from './listBalances';
12
+ export type UseListCollectiblesArgs = {
13
+ collectionAddress: Hex;
14
+ chainId: number;
15
+ side: OrderSide;
16
+ filter?: CollectiblesFilter;
17
+ isLaos721?: boolean;
18
+ query?: {
19
+ enabled?: boolean;
20
+ };
21
+ };
22
+
23
+ /**
24
+ * Fetches a list of collectibles with pagination support
25
+ *
26
+ * @param args - Arguments for the API call
27
+ * @param config - SDK configuration
28
+ * @param page - Page parameters for pagination
29
+ * @returns The collectibles data
30
+ */
31
+ export async function fetchCollectibles(
32
+ args: UseListCollectiblesArgs,
33
+ config: SdkConfig,
34
+ page: Page,
35
+ ): Promise<ListCollectiblesReturn> {
36
+ const marketplaceClient = getMarketplaceClient(args.chainId, config);
37
+ const parsedArgs = {
38
+ ...args,
39
+ contractAddress: args.collectionAddress,
40
+ page: page,
41
+ side: args.side,
42
+ } satisfies ListCollectiblesArgs;
43
+
44
+ if (args.isLaos721 && args.side === OrderSide.listing) {
45
+ try {
46
+ const balances = await fetchBalances(args, config, page);
47
+ const collectibles: CollectibleOrder[] = balances.balances.map(
48
+ (balance) => {
49
+ if (!balance.tokenMetadata)
50
+ throw new Error('Token metadata not found');
51
+ return {
52
+ metadata: {
53
+ tokenId: balance.tokenID ?? '',
54
+ attributes: balance.tokenMetadata.attributes,
55
+ image: balance.tokenMetadata.image,
56
+ name: balance.tokenMetadata.name,
57
+ description: balance.tokenMetadata.description,
58
+ video: balance.tokenMetadata.video,
59
+ audio: balance.tokenMetadata.audio,
60
+ },
61
+ };
62
+ },
63
+ );
64
+ return {
65
+ collectibles: collectibles,
66
+ //@ts-expect-error
67
+ page: balances.page,
68
+ };
69
+ } catch (error) {
70
+ // If the request fails, ignore the error and return the collectibles from our indexer
71
+ console.error(error);
72
+ }
73
+ }
74
+ return await marketplaceClient.listCollectibles(parsedArgs);
75
+ }
76
+
77
+ /**
78
+ * Creates a tanstack infinite query options object for the collectibles query
79
+ *
80
+ * @param args - The query arguments
81
+ * @param config - SDK configuration
82
+ * @returns Query options configuration
83
+ */
84
+ export function listCollectiblesOptions(
85
+ args: UseListCollectiblesArgs,
86
+ config: SdkConfig,
87
+ ) {
88
+ return infiniteQueryOptions({
89
+ ...args.query,
90
+ queryKey: [...collectableKeys.lists, args, config],
91
+ queryFn: ({ pageParam }) => fetchCollectibles(args, config, pageParam),
92
+ initialPageParam: { page: 1, pageSize: 30 } as Page,
93
+ getNextPageParam: (lastPage) =>
94
+ lastPage.page?.more ? lastPage.page : undefined,
95
+ });
96
+ }
@@ -9,7 +9,7 @@ import { useActionButtonLogic } from './hooks/useActionButtonLogic';
9
9
  import type { CollectibleCardAction } from './types';
10
10
 
11
11
  type ActionButtonProps = {
12
- chainId: string;
12
+ chainId: number;
13
13
  collectionAddress: Hex;
14
14
  tokenId: string;
15
15
  orderbookKind?: OrderbookKind;
@@ -12,7 +12,7 @@ import { CollectibleCardAction } from '../types';
12
12
 
13
13
  describe.skip('ActionButton', () => {
14
14
  const defaultProps = {
15
- chainId: '1',
15
+ chainId: 1,
16
16
  collectionAddress: '0x123' as Hex,
17
17
  tokenId: '1',
18
18
  action: CollectibleCardAction.BUY,
@@ -13,7 +13,7 @@ type NonOwnerActionsProps = {
13
13
  action: CollectibleCardAction;
14
14
  tokenId: string;
15
15
  collectionAddress: Hex;
16
- chainId: string;
16
+ chainId: number;
17
17
  orderbookKind?: OrderbookKind;
18
18
  lowestListing?: Order;
19
19
  };
@@ -43,8 +43,9 @@ export function NonOwnerActions({
43
43
  showBuyModal({
44
44
  collectionAddress,
45
45
  chainId,
46
- tokenId,
47
- order: lowestListing,
46
+ collectibleId: tokenId,
47
+ orderId: lowestListing.orderId,
48
+ marketplace: lowestListing.marketplace,
48
49
  })
49
50
  }
50
51
  icon={SvgCartIcon}
@@ -12,7 +12,7 @@ type OwnerActionsProps = {
12
12
  action: CollectibleCardAction;
13
13
  tokenId: string;
14
14
  collectionAddress: Hex;
15
- chainId: string;
15
+ chainId: number;
16
16
  orderbookKind?: OrderbookKind;
17
17
  highestOffer?: Order;
18
18
  };
@@ -3,7 +3,6 @@
3
3
  import { Skeleton } from '@0xsequence/design-system';
4
4
  import type { Hex } from 'viem';
5
5
  import type {
6
- ChainId,
7
6
  CollectibleOrder,
8
7
  ContractType,
9
8
  Order,
@@ -37,7 +36,7 @@ function CollectibleSkeleton() {
37
36
 
38
37
  type CollectibleCardProps = {
39
38
  collectibleId: string;
40
- chainId: ChainId;
39
+ chainId: number;
41
40
  collectionAddress: Hex;
42
41
  orderbookKind?: OrderbookKind;
43
42
  collectionType?: ContractType;
@@ -142,7 +141,7 @@ export function CollectibleCard({
142
141
  {(highestOffer || lowestListing) && (
143
142
  <div className="-bottom-action-offset absolute flex w-full items-center justify-center bg-overlay-light p-2 backdrop-blur transition-transform duration-200 ease-in-out group-hover:translate-y-[-44px]">
144
143
  <ActionButton
145
- chainId={String(chainId)}
144
+ chainId={chainId}
146
145
  collectionAddress={collectionAddress}
147
146
  tokenId={collectibleId}
148
147
  orderbookKind={orderbookKind}
@@ -37,7 +37,7 @@ describe.skip('CollectibleCard', () => {
37
37
  // };
38
38
  // const defaultProps = {
39
39
  // collectibleId: '123',
40
- // chainId: '1',
40
+ // chainId: 1,
41
41
  // collectionAddress:
42
42
  // '0x1234567890123456789012345678901234567890' as `0x${string}`,
43
43
  // lowestListing: {