@0xsequence/marketplace-sdk 0.5.2 → 0.5.4

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 (184) hide show
  1. package/dist/builder-types-Jl3Ymws8.d.ts +73 -0
  2. package/dist/{chunk-XP3WY5AX.js → chunk-7C7ADZ2H.js} +3 -3
  3. package/dist/{chunk-XP3WY5AX.js.map → chunk-7C7ADZ2H.js.map} +1 -1
  4. package/dist/{chunk-FCF57DZI.js → chunk-7FN62HOP.js} +5 -9
  5. package/dist/chunk-7FN62HOP.js.map +1 -0
  6. package/dist/chunk-DZKPDV63.js +27 -0
  7. package/dist/chunk-DZKPDV63.js.map +1 -0
  8. package/dist/{chunk-ZUEQGPLO.js → chunk-J6F5QOW5.js} +2 -2
  9. package/dist/{chunk-ZUEQGPLO.js.map → chunk-J6F5QOW5.js.map} +1 -1
  10. package/dist/{chunk-I37CRQ4S.js → chunk-JWNONWD6.js} +259 -173
  11. package/dist/chunk-JWNONWD6.js.map +1 -0
  12. package/dist/{chunk-LJAB3S6U.js → chunk-TFRAOS7F.js} +22 -13
  13. package/dist/chunk-TFRAOS7F.js.map +1 -0
  14. package/dist/{chunk-MKGSGTQC.js → chunk-TLNRD4BQ.js} +3 -3
  15. package/dist/{chunk-5NORRVPM.js → chunk-UZIAX32Y.js} +1 -1
  16. package/dist/{chunk-5NORRVPM.js.map → chunk-UZIAX32Y.js.map} +1 -1
  17. package/dist/chunk-WGGZEQHL.js +56 -0
  18. package/dist/chunk-WGGZEQHL.js.map +1 -0
  19. package/dist/{chunk-MWDG7UTB.js → chunk-ZBLU3Q22.js} +1 -1
  20. package/dist/{chunk-MSTTVFVQ.js → chunk-ZGVCOQ4I.js} +383 -283
  21. package/dist/chunk-ZGVCOQ4I.js.map +1 -0
  22. package/dist/{create-config-BXvwUh55.d.ts → create-config-DOUq8Day.d.ts} +2 -2
  23. package/dist/index.css +1 -1
  24. package/dist/index.d.ts +5 -4
  25. package/dist/index.js +10 -6
  26. package/dist/{sdk-config-B32_2bG3.d.ts → marketplace.gen-D0ADxbfH.d.ts} +1 -24
  27. package/dist/react/_internal/api/index.d.ts +3 -2
  28. package/dist/react/_internal/databeat/index.css +82 -0
  29. package/dist/react/_internal/databeat/index.css.map +1 -0
  30. package/dist/react/_internal/databeat/index.d.ts +68 -0
  31. package/dist/react/_internal/databeat/index.js +26 -0
  32. package/dist/react/_internal/databeat/index.js.map +1 -0
  33. package/dist/react/_internal/index.d.ts +6 -5
  34. package/dist/react/_internal/index.js +6 -6
  35. package/dist/react/_internal/wagmi/index.d.ts +4 -4
  36. package/dist/react/_internal/wagmi/index.js +1 -1
  37. package/dist/react/hooks/index.d.ts +367 -22
  38. package/dist/react/hooks/index.js +9 -7
  39. package/dist/react/index.css +1 -1
  40. package/dist/react/index.css.map +1 -1
  41. package/dist/react/index.d.ts +7 -6
  42. package/dist/react/index.js +15 -12
  43. package/dist/react/ssr/index.d.ts +54 -41
  44. package/dist/react/ssr/index.js +5 -9
  45. package/dist/react/ssr/index.js.map +1 -1
  46. package/dist/react/ui/components/collectible-card/index.css +1 -1
  47. package/dist/react/ui/components/collectible-card/index.css.map +1 -1
  48. package/dist/react/ui/components/collectible-card/index.d.ts +4 -3
  49. package/dist/react/ui/components/collectible-card/index.js +9 -8
  50. package/dist/react/ui/components/marketplace-logos/index.js +1 -1
  51. package/dist/react/ui/index.css +1 -1
  52. package/dist/react/ui/index.css.map +1 -1
  53. package/dist/react/ui/index.d.ts +4 -3
  54. package/dist/react/ui/index.js +9 -8
  55. package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +4 -3
  56. package/dist/react/ui/modals/_internal/components/actionModal/index.js +6 -6
  57. package/dist/react/ui/styles/index.d.ts +1 -1
  58. package/dist/sdk-config-xWkdBdrL.d.ts +24 -0
  59. package/dist/{services-BRBVE0mm.d.ts → services-Dd2MoBTM.d.ts} +2 -1
  60. package/dist/styles/index.css +1 -1
  61. package/dist/styles/index.css.map +1 -1
  62. package/dist/styles/index.d.ts +1 -1
  63. package/dist/styles/index.js +1 -1
  64. package/dist/types/index.d.ts +4 -5
  65. package/dist/types/index.js +9 -5
  66. package/dist/{types-Yto6KrTN.d.ts → types-vOfhbBkR.d.ts} +3 -2
  67. package/dist/utils/index.d.ts +4 -3
  68. package/dist/utils/index.js +4 -4
  69. package/package.json +12 -10
  70. package/src/react/_internal/api/__mocks__/indexer.msw.ts +197 -0
  71. package/src/react/_internal/api/__mocks__/marketplace.msw.ts +140 -1
  72. package/src/react/_internal/api/__mocks__/metadata.msw.ts +162 -0
  73. package/src/react/_internal/databeat/index.ts +63 -0
  74. package/src/react/_internal/databeat/types.ts +70 -0
  75. package/src/react/_internal/test/mocks/publicClient.ts +39 -0
  76. package/src/react/_internal/test/mocks/wagmi.ts +61 -0
  77. package/src/react/_internal/test/mocks/wallet.ts +61 -0
  78. package/src/react/_internal/test/setup.ts +28 -0
  79. package/src/react/_internal/test-utils.tsx +31 -2
  80. package/src/react/_internal/wagmi/__tests__/create-config.test.ts +53 -20
  81. package/src/react/_internal/wagmi/create-config.ts +3 -4
  82. package/src/react/_internal/wagmi/embedded.ts +1 -4
  83. package/src/react/_internal/wagmi/universal.ts +1 -4
  84. package/src/react/_internal/wallet/wallet.ts +1 -0
  85. package/src/react/hooks/__tests__/useAutoSelectFeeOption.test.tsx +314 -0
  86. package/src/react/hooks/__tests__/useBalanceOfCollectible.test.tsx +148 -0
  87. package/src/react/hooks/__tests__/useCancelOrder.test.tsx +410 -0
  88. package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +269 -0
  89. package/src/react/hooks/__tests__/useCollectible.test.tsx +120 -0
  90. package/src/react/hooks/__tests__/useCollection.test.tsx +101 -0
  91. package/src/react/hooks/__tests__/useCollectionBalanceDetails.test.tsx +175 -0
  92. package/src/react/hooks/__tests__/useCollectionDetails.test.tsx +82 -0
  93. package/src/react/hooks/__tests__/useCollectionDetailsPolling.test.tsx +133 -0
  94. package/src/react/hooks/__tests__/useCountListingsForCollectible.test.tsx +108 -0
  95. package/src/react/hooks/__tests__/useCountOfCollectables.test.tsx +129 -0
  96. package/src/react/hooks/__tests__/useCountOffersForCollectible.test.tsx +108 -0
  97. package/src/react/hooks/__tests__/useCurrencies.test.tsx +176 -0
  98. package/src/react/hooks/__tests__/useCurrency.test.tsx +153 -0
  99. package/src/react/hooks/__tests__/useCurrencyBalance.test.tsx +111 -0
  100. package/src/react/hooks/__tests__/useFilters.test.tsx +127 -0
  101. package/src/react/hooks/__tests__/useFloorOrder.test.tsx +101 -0
  102. package/src/react/hooks/__tests__/useGenerateBuyTransaction.test.tsx +173 -0
  103. package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +207 -0
  104. package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +207 -0
  105. package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +205 -0
  106. package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +181 -0
  107. package/src/react/hooks/__tests__/useHighestOffer.test.tsx +118 -0
  108. package/src/react/hooks/__tests__/useListBalances.test.tsx +136 -0
  109. package/src/react/hooks/__tests__/useListCollectibleActivities.test.tsx +200 -0
  110. package/src/react/hooks/__tests__/useListCollectibles.test.tsx +232 -0
  111. package/src/react/hooks/__tests__/useListCollectiblesPaginated.test.tsx +217 -0
  112. package/src/react/hooks/__tests__/useListCollectionActivities.test.tsx +235 -0
  113. package/src/react/hooks/__tests__/useListCollections.test.tsx +296 -0
  114. package/src/react/hooks/__tests__/useListListingsForCollectible.test.tsx +140 -0
  115. package/src/react/hooks/__tests__/useListOffersForCollectible.test.tsx +140 -0
  116. package/src/react/hooks/__tests__/useLowestListing.test.tsx +148 -0
  117. package/src/react/hooks/__tests__/useMarketplaceConfig.test.tsx +106 -0
  118. package/src/react/hooks/__tests__/useRoyaltyPercentage.test.tsx +129 -0
  119. package/src/react/hooks/index.ts +1 -1
  120. package/src/react/hooks/options/__mocks__/marketplaceConfig.msw.ts +66 -10
  121. package/src/react/hooks/options/__tests__/marketplaceConfigOptions.test.tsx +2 -11
  122. package/src/react/hooks/options/marketplaceConfigOptions.ts +8 -3
  123. package/src/react/hooks/useAutoSelectFeeOption.tsx +4 -3
  124. package/src/react/hooks/useCancelTransactionSteps.tsx +17 -9
  125. package/src/react/hooks/useCollectionDetailsPolling.tsx +1 -1
  126. package/src/react/hooks/useCurrencies.tsx +29 -28
  127. package/src/react/hooks/useFilters.tsx +75 -2
  128. package/src/react/hooks/useGenerateBuyTransaction.tsx +13 -5
  129. package/src/react/hooks/useListCollectibleActivities.tsx +1 -0
  130. package/src/react/hooks/useListCollectibles.tsx +1 -0
  131. package/src/react/hooks/useListCollectiblesPaginated.tsx +78 -0
  132. package/src/react/hooks/useListCollectionActivities.tsx +1 -0
  133. package/src/react/hooks/useListCollections.tsx +2 -2
  134. package/src/react/ui/components/_internals/custom-select/__tests__/CustomSelect.test.tsx +6 -2
  135. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +1 -1
  136. package/src/react/ui/components/collectible-card/Footer.tsx +9 -5
  137. package/src/react/ui/modals/BuyModal/Modal.tsx +9 -4
  138. package/src/react/ui/modals/BuyModal/__tests__/Modal.test.tsx +0 -1
  139. package/src/react/ui/modals/BuyModal/__tests__/store.test.ts +4 -2
  140. package/src/react/ui/modals/BuyModal/hooks/__tests__/useBuyCollectable.test.tsx +1 -24
  141. package/src/react/ui/modals/BuyModal/hooks/__tests__/useCheckoutOptions.test.tsx +152 -210
  142. package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +19 -49
  143. package/src/react/ui/modals/BuyModal/hooks/useFees.ts +6 -6
  144. package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +4 -2
  145. package/src/react/ui/modals/BuyModal/modals/__tests__/Modal1155.test.tsx +161 -52
  146. package/src/react/ui/modals/BuyModal/store.ts +7 -0
  147. package/src/react/ui/modals/CreateListingModal/Modal.tsx +1 -3
  148. package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +59 -227
  149. package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +2 -1
  150. package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +47 -7
  151. package/src/react/ui/modals/MakeOfferModal/Modal.tsx +1 -8
  152. package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +41 -118
  153. package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +2 -1
  154. package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +34 -6
  155. package/src/react/ui/modals/SellModal/Modal.tsx +3 -1
  156. package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +4 -3
  157. package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +33 -31
  158. package/src/react/ui/modals/SellModal/hooks/useSell.tsx +11 -7
  159. package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +58 -16
  160. package/src/react/ui/modals/SuccessfulPurchaseModal/__tests__/Modal.test.tsx +0 -1
  161. package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +4 -2
  162. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +129 -57
  163. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +1 -3
  164. package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +1 -3
  165. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
  166. package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +8 -8
  167. package/src/react/ui/modals/_internal/components/transactionStatusModal/hooks/useTransactionStatus.ts +1 -0
  168. package/src/types/builder-types.ts +79 -0
  169. package/src/types/index.ts +1 -1
  170. package/src/utils/__tests__/get-public-rpc-client.test.ts +2 -0
  171. package/src/utils/getMarketplaceDetails.ts +2 -2
  172. package/tsconfig.tsbuildinfo +1 -1
  173. package/vitest.config.js +2 -1
  174. package/dist/chunk-FCF57DZI.js.map +0 -1
  175. package/dist/chunk-I37CRQ4S.js.map +0 -1
  176. package/dist/chunk-LJAB3S6U.js.map +0 -1
  177. package/dist/chunk-MSTTVFVQ.js.map +0 -1
  178. package/dist/chunk-RK6KYMZM.js +0 -18
  179. package/dist/chunk-RK6KYMZM.js.map +0 -1
  180. package/dist/marketplace-config-znEu4L0K.d.ts +0 -60
  181. package/src/react/hooks/useCurrencyOptions.tsx +0 -16
  182. package/src/types/marketplace-config.ts +0 -67
  183. /package/dist/{chunk-MKGSGTQC.js.map → chunk-TLNRD4BQ.js.map} +0 -0
  184. /package/dist/{chunk-MWDG7UTB.js.map → chunk-ZBLU3Q22.js.map} +0 -0
@@ -0,0 +1,232 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { useListCollectibles } from '../useListCollectibles';
3
+ import { renderHook, waitFor } from '../../_internal/test-utils';
4
+ import { zeroAddress } from 'viem';
5
+ import type { UseListCollectiblesArgs } from '../useListCollectibles';
6
+ import { http, HttpResponse } from 'msw';
7
+ import {
8
+ mockCollectibleOrder,
9
+ mockMarketplaceEndpoint,
10
+ } from '../../_internal/api/__mocks__/marketplace.msw';
11
+ import { server } from '../../_internal/test/setup';
12
+ import {
13
+ MarketplaceKind,
14
+ OrderSide,
15
+ } from '../../_internal/api/marketplace.gen';
16
+ import type { ListCollectiblesArgs } from '../../_internal';
17
+
18
+ describe('useListCollectibles', () => {
19
+ const defaultArgs: UseListCollectiblesArgs = {
20
+ chainId: '1',
21
+ collectionAddress: zeroAddress,
22
+ side: OrderSide.listing,
23
+ query: {
24
+ enabled: true,
25
+ },
26
+ };
27
+
28
+ it('should fetch collectibles successfully', async () => {
29
+ // Set up the default success handler
30
+ server.use(
31
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
32
+ return HttpResponse.json({
33
+ collectibles: [mockCollectibleOrder],
34
+ page: { page: 1, pageSize: 30, more: false },
35
+ });
36
+ }),
37
+ );
38
+
39
+ const { result } = renderHook(() => useListCollectibles(defaultArgs));
40
+
41
+ // Initially loading
42
+ expect(result.current.isLoading).toBe(true);
43
+ expect(result.current.data).toBeUndefined();
44
+
45
+ // Wait for data to be loaded
46
+ await waitFor(() => {
47
+ expect(result.current.isLoading).toBe(false);
48
+ });
49
+
50
+ // Verify the data matches our mock
51
+ expect(result.current.data?.pages[0]).toEqual({
52
+ collectibles: [mockCollectibleOrder],
53
+ page: { page: 1, pageSize: 30, more: false },
54
+ });
55
+ expect(result.current.error).toBeNull();
56
+ });
57
+
58
+ it('should handle error states', async () => {
59
+ // Override the handler for this test to return an error
60
+ server.use(
61
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
62
+ return HttpResponse.json(
63
+ { error: { message: 'Failed to fetch collectibles' } },
64
+ { status: 500 },
65
+ );
66
+ }),
67
+ );
68
+
69
+ const { result } = renderHook(() => useListCollectibles(defaultArgs));
70
+
71
+ await waitFor(() => {
72
+ expect(result.current.isError).toBe(true);
73
+ });
74
+
75
+ expect(result.current.error).toBeDefined();
76
+ expect(result.current.data).toBeUndefined();
77
+ });
78
+
79
+ it('should handle infinite pagination correctly', async () => {
80
+ // Mock responses for different pages
81
+ const pages = [
82
+ {
83
+ collectibles: [mockCollectibleOrder],
84
+ page: { page: 1, pageSize: 30, more: true },
85
+ },
86
+ {
87
+ collectibles: [{ ...mockCollectibleOrder, tokenId: '2' }],
88
+ page: { page: 2, pageSize: 30, more: false },
89
+ },
90
+ ];
91
+
92
+ let currentPage = 0;
93
+ server.use(
94
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
95
+ const response = pages[currentPage];
96
+ currentPage = Math.min(currentPage + 1, pages.length - 1);
97
+ return HttpResponse.json(response);
98
+ }),
99
+ );
100
+
101
+ const { result } = renderHook(() => useListCollectibles(defaultArgs));
102
+
103
+ // Wait for initial data
104
+ await waitFor(() => {
105
+ expect(result.current.isLoading).toBe(false);
106
+ });
107
+
108
+ // Verify first page
109
+ expect(result.current.data?.pages[0]).toEqual(pages[0]);
110
+ expect(result.current.hasNextPage).toBe(true);
111
+
112
+ // Fetch next page
113
+ await result.current.fetchNextPage();
114
+
115
+ // Wait for second page to load
116
+ await waitFor(() => {
117
+ expect(result.current.isFetchingNextPage).toBe(false);
118
+ });
119
+
120
+ // Verify both pages are present
121
+ expect(result.current.data?.pages).toHaveLength(2);
122
+ expect(result.current.data?.pages[1]).toEqual(pages[1]);
123
+ expect(result.current.hasNextPage).toBe(false);
124
+ });
125
+
126
+ it('should handle disabled queries', async () => {
127
+ // Set up a mock handler to ensure no requests are made
128
+ let requestMade = false;
129
+ server.use(
130
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
131
+ requestMade = true;
132
+ return HttpResponse.json({
133
+ collectibles: [mockCollectibleOrder],
134
+ page: { page: 1, pageSize: 30, more: false },
135
+ });
136
+ }),
137
+ );
138
+
139
+ const disabledArgs: UseListCollectiblesArgs = {
140
+ ...defaultArgs,
141
+ query: {
142
+ enabled: false,
143
+ },
144
+ };
145
+
146
+ const { result } = renderHook(() => useListCollectibles(disabledArgs));
147
+
148
+ // For disabled queries, we expect no loading state and no data
149
+ expect(result.current.isLoading).toBe(false);
150
+ expect(result.current.data).toBeUndefined();
151
+ expect(result.current.error).toBeNull();
152
+ expect(requestMade).toBe(false);
153
+ });
154
+
155
+ it('should refetch when args change', async () => {
156
+ // Set up the success handler
157
+ server.use(
158
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
159
+ return HttpResponse.json({
160
+ collectibles: [mockCollectibleOrder],
161
+ page: { page: 1, pageSize: 30, more: false },
162
+ });
163
+ }),
164
+ );
165
+
166
+ let currentArgs = defaultArgs;
167
+ const { result, rerender } = renderHook(() =>
168
+ useListCollectibles(currentArgs),
169
+ );
170
+
171
+ // Wait for initial data
172
+ await waitFor(() => {
173
+ expect(result.current.isLoading).toBe(false);
174
+ });
175
+
176
+ // Change args and rerender
177
+ currentArgs = {
178
+ ...defaultArgs,
179
+ collectionAddress:
180
+ '0x1234567890123456789012345678901234567890' as `0x${string}`,
181
+ };
182
+
183
+ rerender();
184
+
185
+ // Wait for new data
186
+ await waitFor(() => {
187
+ expect(result.current.data?.pages[0]).toBeDefined();
188
+ });
189
+
190
+ // Verify that the query was refetched with new args
191
+ expect(result.current.data?.pages[0]).toBeDefined();
192
+ expect(result.current.isSuccess).toBe(true);
193
+ });
194
+
195
+ it('should handle filter parameters', async () => {
196
+ const argsWithFilter: UseListCollectiblesArgs = {
197
+ ...defaultArgs,
198
+ filter: {
199
+ includeEmpty: true,
200
+ searchText: 'test',
201
+ marketplaces: [MarketplaceKind.sequence_marketplace_v2],
202
+ },
203
+ };
204
+
205
+ let requestArgs: ListCollectiblesArgs | undefined;
206
+ server.use(
207
+ http.post(
208
+ mockMarketplaceEndpoint('ListCollectibles'),
209
+ async ({ request }) => {
210
+ requestArgs = (await request.json()) as ListCollectiblesArgs;
211
+ return HttpResponse.json({
212
+ collectibles: [mockCollectibleOrder],
213
+ page: { page: 1, pageSize: 30, more: false },
214
+ });
215
+ },
216
+ ),
217
+ );
218
+
219
+ const { result } = renderHook(() => useListCollectibles(argsWithFilter));
220
+
221
+ await waitFor(() => {
222
+ expect(result.current.isLoading).toBe(false);
223
+ });
224
+
225
+ // Verify that filter parameters were passed correctly
226
+ expect(requestArgs?.filter).toEqual({
227
+ includeEmpty: true,
228
+ searchText: 'test',
229
+ marketplaces: [MarketplaceKind.sequence_marketplace_v2],
230
+ });
231
+ });
232
+ });
@@ -0,0 +1,217 @@
1
+ import { waitFor } from '@testing-library/react';
2
+ import { http, HttpResponse } from 'msw';
3
+ import { zeroAddress } from 'viem';
4
+ import { describe, expect, it } from 'vitest';
5
+ import {
6
+ mockCollectibleOrder,
7
+ mockMarketplaceEndpoint,
8
+ } from '../../_internal/api/__mocks__/marketplace.msw';
9
+ import { OrderSide } from '../../_internal/api/marketplace.gen';
10
+ import { renderHook } from '../../_internal/test-utils';
11
+ import { server } from '../../_internal/test/setup';
12
+ import { useListCollectiblesPaginated } from '../useListCollectiblesPaginated';
13
+ import type { UseListCollectiblesPaginatedArgs } from '../useListCollectiblesPaginated';
14
+
15
+ describe('useListCollectiblesPaginated', () => {
16
+ const defaultArgs: UseListCollectiblesPaginatedArgs = {
17
+ chainId: '1',
18
+ collectionAddress: zeroAddress,
19
+ side: OrderSide.listing,
20
+ query: {
21
+ enabled: true,
22
+ page: 1,
23
+ pageSize: 30,
24
+ },
25
+ };
26
+
27
+ it('should fetch collectibles successfully', async () => {
28
+ // Set up mock response
29
+ server.use(
30
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
31
+ return HttpResponse.json({
32
+ collectibles: [mockCollectibleOrder],
33
+ page: { page: 1, pageSize: 30, more: false },
34
+ });
35
+ }),
36
+ );
37
+
38
+ const { result } = renderHook(() =>
39
+ useListCollectiblesPaginated(defaultArgs),
40
+ );
41
+
42
+ // Wait for the query to complete
43
+ await waitFor(() => {
44
+ expect(result.current.isSuccess).toBe(true);
45
+ });
46
+
47
+ // Verify the data
48
+ expect(result.current.data?.collectibles).toEqual([mockCollectibleOrder]);
49
+ expect(result.current.data?.page).toEqual({
50
+ page: 1,
51
+ pageSize: 30,
52
+ more: false,
53
+ });
54
+ });
55
+
56
+ it('should handle error states', async () => {
57
+ // Override the handler to return an error
58
+ server.use(
59
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
60
+ return HttpResponse.json(
61
+ { error: { message: 'Failed to fetch collectibles' } },
62
+ { status: 500 },
63
+ );
64
+ }),
65
+ );
66
+
67
+ const { result } = renderHook(() =>
68
+ useListCollectiblesPaginated(defaultArgs),
69
+ );
70
+
71
+ // Wait for the error state
72
+ await waitFor(() => {
73
+ expect(result.current.isError).toBe(true);
74
+ });
75
+
76
+ expect(result.current.error).toBeDefined();
77
+ expect(result.current.data).toBeUndefined();
78
+ });
79
+
80
+ it('should handle pagination correctly', async () => {
81
+ // Set up mock response for page 2
82
+ const modifiedCollectibleOrder = {
83
+ ...mockCollectibleOrder,
84
+ metadata: {
85
+ ...mockCollectibleOrder.metadata,
86
+ tokenId: '2',
87
+ },
88
+ };
89
+
90
+ server.use(
91
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
92
+ return HttpResponse.json({
93
+ collectibles: [modifiedCollectibleOrder],
94
+ page: { page: 2, pageSize: 20, more: false },
95
+ });
96
+ }),
97
+ );
98
+
99
+ const paginatedArgs: UseListCollectiblesPaginatedArgs = {
100
+ ...defaultArgs,
101
+ query: {
102
+ enabled: true,
103
+ page: 2,
104
+ pageSize: 20,
105
+ },
106
+ };
107
+
108
+ const { result } = renderHook(() =>
109
+ useListCollectiblesPaginated(paginatedArgs),
110
+ );
111
+
112
+ // Wait for the query to complete
113
+ await waitFor(() => {
114
+ expect(result.current.isSuccess).toBe(true);
115
+ });
116
+
117
+ // Verify the data for page 2
118
+ expect(result.current.data?.collectibles[0].metadata.tokenId).toBe('2');
119
+ expect(result.current.data?.page).toEqual({
120
+ page: 2,
121
+ pageSize: 20,
122
+ more: false,
123
+ });
124
+ });
125
+
126
+ it('should refetch when args change', async () => {
127
+ // Set up initial mock response
128
+ server.use(
129
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
130
+ return HttpResponse.json({
131
+ collectibles: [mockCollectibleOrder],
132
+ page: { page: 1, pageSize: 30, more: true },
133
+ });
134
+ }),
135
+ );
136
+
137
+ let currentArgs = defaultArgs;
138
+ const { result, rerender } = renderHook(() =>
139
+ useListCollectiblesPaginated(currentArgs),
140
+ );
141
+
142
+ // Wait for initial data
143
+ await waitFor(() => {
144
+ expect(result.current.isSuccess).toBe(true);
145
+ });
146
+
147
+ // Change args and rerender
148
+ currentArgs = {
149
+ ...defaultArgs,
150
+ query: {
151
+ ...defaultArgs.query,
152
+ page: 2,
153
+ },
154
+ };
155
+
156
+ // Set up mock response for page 2
157
+ const modifiedCollectibleOrder = {
158
+ ...mockCollectibleOrder,
159
+ metadata: {
160
+ ...mockCollectibleOrder.metadata,
161
+ tokenId: '2',
162
+ },
163
+ };
164
+
165
+ server.use(
166
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
167
+ return HttpResponse.json({
168
+ collectibles: [modifiedCollectibleOrder],
169
+ page: { page: 2, pageSize: 30, more: false },
170
+ });
171
+ }),
172
+ );
173
+
174
+ rerender();
175
+
176
+ // Wait for new data
177
+ await waitFor(() => {
178
+ expect(result.current.data?.page?.page).toBe(2);
179
+ });
180
+
181
+ // Verify new data
182
+ expect(result.current.data?.collectibles[0].metadata.tokenId).toBe('2');
183
+ });
184
+
185
+ it('should not fetch when enabled is false', async () => {
186
+ // Set up a mock handler to ensure no requests are made
187
+ let requestMade = false;
188
+ server.use(
189
+ http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
190
+ requestMade = true;
191
+ return HttpResponse.json({
192
+ collectibles: [mockCollectibleOrder],
193
+ page: { page: 1, pageSize: 30, more: false },
194
+ });
195
+ }),
196
+ );
197
+
198
+ const disabledArgs: UseListCollectiblesPaginatedArgs = {
199
+ ...defaultArgs,
200
+ query: {
201
+ enabled: false,
202
+ page: 1,
203
+ pageSize: 30,
204
+ },
205
+ };
206
+
207
+ const { result } = renderHook(() =>
208
+ useListCollectiblesPaginated(disabledArgs),
209
+ );
210
+
211
+ // For disabled queries, we expect no loading state and no data
212
+ expect(result.current.isLoading).toBe(false);
213
+ expect(result.current.data).toBeUndefined();
214
+ expect(result.current.error).toBeNull();
215
+ expect(requestMade).toBe(false);
216
+ });
217
+ });
@@ -0,0 +1,235 @@
1
+ import { describe, expect, it, beforeEach } from 'vitest';
2
+ import { useListCollectionActivities } from '../useListCollectionActivities';
3
+ import { renderHook, waitFor } from '../../_internal/test-utils';
4
+ import { zeroAddress } from 'viem';
5
+ import type { UseListCollectionActivitiesArgs } from '../useListCollectionActivities';
6
+ import { http, HttpResponse } from 'msw';
7
+ import {
8
+ mockActivity,
9
+ mockMarketplaceEndpoint,
10
+ } from '../../_internal/api/__mocks__/marketplace.msw';
11
+ import { server } from '../../_internal/test/setup';
12
+ import { SortOrder } from '../../_internal/api/marketplace.gen';
13
+ import type { ListCollectionActivitiesArgs } from '../../_internal/api/marketplace.gen';
14
+
15
+ describe('useListCollectionActivities', () => {
16
+ const defaultArgs: UseListCollectionActivitiesArgs = {
17
+ chainId: '1',
18
+ collectionAddress: zeroAddress,
19
+ query: {
20
+ enabled: true,
21
+ page: 1,
22
+ pageSize: 10,
23
+ },
24
+ };
25
+
26
+ // Reset handlers before each test
27
+ beforeEach(() => {
28
+ server.resetHandlers();
29
+ });
30
+
31
+ it('should fetch collection activities successfully', async () => {
32
+ // Set up the default success handler
33
+ server.use(
34
+ http.post(mockMarketplaceEndpoint('ListCollectionActivities'), () => {
35
+ return HttpResponse.json({
36
+ activities: [mockActivity],
37
+ page: { page: 1, pageSize: 10, more: false },
38
+ });
39
+ }),
40
+ );
41
+
42
+ const { result } = renderHook(() =>
43
+ useListCollectionActivities(defaultArgs),
44
+ );
45
+
46
+ // Initially loading
47
+ expect(result.current.isLoading).toBe(true);
48
+ expect(result.current.data).toBeUndefined();
49
+
50
+ // Wait for data to be loaded
51
+ await waitFor(() => {
52
+ expect(result.current.isLoading).toBe(false);
53
+ });
54
+
55
+ // Verify the data matches our mock
56
+ expect(result.current.data).toEqual({
57
+ activities: [mockActivity],
58
+ page: { page: 1, pageSize: 10, more: false },
59
+ });
60
+ expect(result.current.error).toBeNull();
61
+ });
62
+
63
+ it('should handle error states', async () => {
64
+ // Override the handler for this test to return an error
65
+ server.use(
66
+ http.post(mockMarketplaceEndpoint('ListCollectionActivities'), () => {
67
+ return HttpResponse.json(
68
+ { error: { message: 'Failed to fetch activities' } },
69
+ { status: 500 },
70
+ );
71
+ }),
72
+ );
73
+
74
+ const { result } = renderHook(() =>
75
+ useListCollectionActivities(defaultArgs),
76
+ );
77
+
78
+ await waitFor(() => {
79
+ expect(result.current.isError).toBe(true);
80
+ });
81
+
82
+ expect(result.current.error).toBeDefined();
83
+ expect(result.current.data).toBeUndefined();
84
+ });
85
+
86
+ it('should handle disabled queries', async () => {
87
+ // Set up a mock handler to ensure no requests are made
88
+ let requestMade = false;
89
+ server.use(
90
+ http.post(mockMarketplaceEndpoint('ListCollectionActivities'), () => {
91
+ requestMade = true;
92
+ return HttpResponse.json({
93
+ activities: [mockActivity],
94
+ page: { page: 1, pageSize: 10, more: false },
95
+ });
96
+ }),
97
+ );
98
+
99
+ const disabledArgs: UseListCollectionActivitiesArgs = {
100
+ ...defaultArgs,
101
+ query: {
102
+ enabled: false,
103
+ page: 1,
104
+ pageSize: 10,
105
+ },
106
+ };
107
+
108
+ const { result } = renderHook(() =>
109
+ useListCollectionActivities(disabledArgs),
110
+ );
111
+
112
+ // For disabled queries, we expect no loading state and no data
113
+ expect(result.current.isLoading).toBe(false);
114
+ expect(result.current.data).toBeUndefined();
115
+ expect(result.current.error).toBeNull();
116
+ expect(requestMade).toBe(false);
117
+ });
118
+
119
+ it('should refetch when args change', async () => {
120
+ // Set up the success handler
121
+ server.use(
122
+ http.post(mockMarketplaceEndpoint('ListCollectionActivities'), () => {
123
+ return HttpResponse.json({
124
+ activities: [mockActivity],
125
+ page: { page: 1, pageSize: 10, more: false },
126
+ });
127
+ }),
128
+ );
129
+
130
+ let currentArgs = defaultArgs;
131
+ const { result, rerender } = renderHook(() =>
132
+ useListCollectionActivities(currentArgs),
133
+ );
134
+
135
+ // Wait for initial data
136
+ await waitFor(() => {
137
+ expect(result.current.isLoading).toBe(false);
138
+ });
139
+
140
+ // Change args and rerender
141
+ currentArgs = {
142
+ ...defaultArgs,
143
+ collectionAddress:
144
+ '0x1234567890123456789012345678901234567890' as `0x${string}`,
145
+ };
146
+
147
+ rerender();
148
+
149
+ // Wait for new data
150
+ await waitFor(() => {
151
+ expect(result.current.data).toBeDefined();
152
+ });
153
+
154
+ // Verify that the query was refetched with new args
155
+ expect(result.current.data).toBeDefined();
156
+ expect(result.current.isSuccess).toBe(true);
157
+ });
158
+
159
+ it('should handle sorting parameters', async () => {
160
+ const argsWithSort: UseListCollectionActivitiesArgs = {
161
+ ...defaultArgs,
162
+ query: {
163
+ enabled: true,
164
+ page: 1,
165
+ pageSize: 10,
166
+ sort: [{ column: 'createdAt', order: SortOrder.DESC }],
167
+ },
168
+ };
169
+
170
+ let requestArgs: ListCollectionActivitiesArgs | null = null;
171
+
172
+ server.use(
173
+ http.post(
174
+ mockMarketplaceEndpoint('ListCollectionActivities'),
175
+ async ({ request }) => {
176
+ requestArgs = (await request.json()) as ListCollectionActivitiesArgs;
177
+ return HttpResponse.json({
178
+ activities: [mockActivity],
179
+ page: { page: 1, pageSize: 10, more: false },
180
+ });
181
+ },
182
+ ),
183
+ );
184
+
185
+ const { result } = renderHook(() =>
186
+ useListCollectionActivities(argsWithSort),
187
+ );
188
+
189
+ await waitFor(() => {
190
+ expect(result.current.isLoading).toBe(false);
191
+ });
192
+
193
+ await waitFor(() => {
194
+ expect(requestArgs).not.toBeNull();
195
+ expect(requestArgs?.page?.sort).toEqual([
196
+ { column: 'createdAt', order: SortOrder.DESC },
197
+ ]);
198
+ });
199
+ });
200
+
201
+ it('should handle pagination correctly', async () => {
202
+ // Override the handler for this test to return paginated data
203
+ server.use(
204
+ http.post(mockMarketplaceEndpoint('ListCollectionActivities'), () => {
205
+ return HttpResponse.json({
206
+ activities: [mockActivity],
207
+ page: { page: 2, pageSize: 20, more: false },
208
+ });
209
+ }),
210
+ );
211
+
212
+ const paginatedArgs: UseListCollectionActivitiesArgs = {
213
+ ...defaultArgs,
214
+ query: {
215
+ enabled: true,
216
+ page: 2,
217
+ pageSize: 20,
218
+ },
219
+ };
220
+
221
+ const { result } = renderHook(() =>
222
+ useListCollectionActivities(paginatedArgs),
223
+ );
224
+
225
+ await waitFor(() => {
226
+ expect(result.current.isLoading).toBe(false);
227
+ });
228
+
229
+ expect(result.current.data?.page).toEqual({
230
+ page: 2,
231
+ pageSize: 20,
232
+ more: false,
233
+ });
234
+ });
235
+ });