@0xsequence/marketplace-sdk 0.5.1 → 0.5.3

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 (164) hide show
  1. package/dist/builder-types-wOwfTJpd.d.ts +73 -0
  2. package/dist/{chunk-FCF57DZI.js → chunk-7FN62HOP.js} +5 -9
  3. package/dist/chunk-7FN62HOP.js.map +1 -0
  4. package/dist/{chunk-F4E3WJ2K.js → chunk-BVXIRVEC.js} +261 -249
  5. package/dist/chunk-BVXIRVEC.js.map +1 -0
  6. package/dist/{chunk-XP3WY5AX.js → chunk-BZD2LDJJ.js} +2 -2
  7. package/dist/{chunk-XP3WY5AX.js.map → chunk-BZD2LDJJ.js.map} +1 -1
  8. package/dist/chunk-DZKPDV63.js +27 -0
  9. package/dist/chunk-DZKPDV63.js.map +1 -0
  10. package/dist/{chunk-I37CRQ4S.js → chunk-H5YWG6WN.js} +128 -88
  11. package/dist/chunk-H5YWG6WN.js.map +1 -0
  12. package/dist/{chunk-ZUEQGPLO.js → chunk-J6F5QOW5.js} +2 -2
  13. package/dist/{chunk-ZUEQGPLO.js.map → chunk-J6F5QOW5.js.map} +1 -1
  14. package/dist/{chunk-LJAB3S6U.js → chunk-TFRAOS7F.js} +22 -13
  15. package/dist/chunk-TFRAOS7F.js.map +1 -0
  16. package/dist/{chunk-5NORRVPM.js → chunk-UZIAX32Y.js} +1 -1
  17. package/dist/{chunk-5NORRVPM.js.map → chunk-UZIAX32Y.js.map} +1 -1
  18. package/dist/{chunk-MKGSGTQC.js → chunk-Y7YTLAO2.js} +3 -3
  19. package/dist/{create-config-BXvwUh55.d.ts → create-config-Bltg8Enl.d.ts} +1 -1
  20. package/dist/index.css +1 -1
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +10 -6
  23. package/dist/react/_internal/index.d.ts +3 -3
  24. package/dist/react/_internal/index.js +1 -1
  25. package/dist/react/_internal/wagmi/index.d.ts +2 -3
  26. package/dist/react/_internal/wagmi/index.js +1 -1
  27. package/dist/react/hooks/index.d.ts +72 -20
  28. package/dist/react/hooks/index.js +5 -7
  29. package/dist/react/index.css +1 -1
  30. package/dist/react/index.css.map +1 -1
  31. package/dist/react/index.d.ts +4 -4
  32. package/dist/react/index.js +8 -10
  33. package/dist/react/ssr/index.d.ts +54 -41
  34. package/dist/react/ssr/index.js +5 -9
  35. package/dist/react/ssr/index.js.map +1 -1
  36. package/dist/react/ui/components/collectible-card/index.css +1 -1
  37. package/dist/react/ui/components/collectible-card/index.css.map +1 -1
  38. package/dist/react/ui/components/collectible-card/index.d.ts +2 -2
  39. package/dist/react/ui/components/collectible-card/index.js +8 -8
  40. package/dist/react/ui/index.css +1 -1
  41. package/dist/react/ui/index.css.map +1 -1
  42. package/dist/react/ui/index.d.ts +2 -2
  43. package/dist/react/ui/index.js +8 -8
  44. package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +2 -2
  45. package/dist/react/ui/modals/_internal/components/actionModal/index.js +6 -6
  46. package/dist/styles/index.css +1 -1
  47. package/dist/styles/index.css.map +1 -1
  48. package/dist/styles/index.js +1 -1
  49. package/dist/types/index.d.ts +1 -3
  50. package/dist/types/index.js +9 -5
  51. package/dist/{types-Yto6KrTN.d.ts → types-BY3husBh.d.ts} +1 -1
  52. package/dist/utils/index.d.ts +2 -2
  53. package/dist/utils/index.js +4 -4
  54. package/package.json +11 -10
  55. package/src/react/_internal/api/__mocks__/indexer.msw.ts +197 -0
  56. package/src/react/_internal/api/__mocks__/marketplace.msw.ts +140 -1
  57. package/src/react/_internal/api/__mocks__/metadata.msw.ts +162 -0
  58. package/src/react/_internal/test/mocks/publicClient.ts +39 -0
  59. package/src/react/_internal/test/mocks/wagmi.ts +61 -0
  60. package/src/react/_internal/test/mocks/wallet.ts +61 -0
  61. package/src/react/_internal/test/setup.ts +28 -0
  62. package/src/react/_internal/test-utils.tsx +31 -2
  63. package/src/react/_internal/wagmi/__tests__/create-config.test.ts +53 -20
  64. package/src/react/_internal/wagmi/create-config.ts +3 -4
  65. package/src/react/_internal/wagmi/embedded.ts +1 -4
  66. package/src/react/_internal/wagmi/universal.ts +1 -4
  67. package/src/react/_internal/wallet/wallet.ts +1 -0
  68. package/src/react/hooks/__tests__/useAutoSelectFeeOption.test.tsx +314 -0
  69. package/src/react/hooks/__tests__/useBalanceOfCollectible.test.tsx +148 -0
  70. package/src/react/hooks/__tests__/useCancelOrder.test.tsx +410 -0
  71. package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +269 -0
  72. package/src/react/hooks/__tests__/useCollectible.test.tsx +120 -0
  73. package/src/react/hooks/__tests__/useCollection.test.tsx +101 -0
  74. package/src/react/hooks/__tests__/useCollectionBalanceDetails.test.tsx +175 -0
  75. package/src/react/hooks/__tests__/useCollectionDetails.test.tsx +82 -0
  76. package/src/react/hooks/__tests__/useCollectionDetailsPolling.test.tsx +133 -0
  77. package/src/react/hooks/__tests__/useCountListingsForCollectible.test.tsx +108 -0
  78. package/src/react/hooks/__tests__/useCountOfCollectables.test.tsx +129 -0
  79. package/src/react/hooks/__tests__/useCountOffersForCollectible.test.tsx +108 -0
  80. package/src/react/hooks/__tests__/useCurrencies.test.tsx +176 -0
  81. package/src/react/hooks/__tests__/useCurrency.test.tsx +153 -0
  82. package/src/react/hooks/__tests__/useCurrencyBalance.test.tsx +111 -0
  83. package/src/react/hooks/__tests__/useFilters.test.tsx +127 -0
  84. package/src/react/hooks/__tests__/useFloorOrder.test.tsx +101 -0
  85. package/src/react/hooks/__tests__/useGenerateBuyTransaction.test.tsx +173 -0
  86. package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +207 -0
  87. package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +207 -0
  88. package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +205 -0
  89. package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +181 -0
  90. package/src/react/hooks/__tests__/useHighestOffer.test.tsx +118 -0
  91. package/src/react/hooks/__tests__/useListBalances.test.tsx +136 -0
  92. package/src/react/hooks/__tests__/useListCollectibleActivities.test.tsx +200 -0
  93. package/src/react/hooks/__tests__/useListCollectibles.test.tsx +232 -0
  94. package/src/react/hooks/__tests__/useListCollectionActivities.test.tsx +235 -0
  95. package/src/react/hooks/__tests__/useListCollections.test.tsx +296 -0
  96. package/src/react/hooks/__tests__/useListListingsForCollectible.test.tsx +140 -0
  97. package/src/react/hooks/__tests__/useListOffersForCollectible.test.tsx +140 -0
  98. package/src/react/hooks/__tests__/useLowestListing.test.tsx +148 -0
  99. package/src/react/hooks/__tests__/useMarketplaceConfig.test.tsx +106 -0
  100. package/src/react/hooks/__tests__/useRoyaltyPercentage.test.tsx +129 -0
  101. package/src/react/hooks/index.ts +0 -1
  102. package/src/react/hooks/options/__mocks__/marketplaceConfig.msw.ts +66 -10
  103. package/src/react/hooks/options/__tests__/marketplaceConfigOptions.test.tsx +2 -11
  104. package/src/react/hooks/options/marketplaceConfigOptions.ts +8 -3
  105. package/src/react/hooks/useAutoSelectFeeOption.tsx +4 -3
  106. package/src/react/hooks/useCancelTransactionSteps.tsx +17 -9
  107. package/src/react/hooks/useCollectionDetailsPolling.tsx +1 -1
  108. package/src/react/hooks/useCurrencies.tsx +29 -28
  109. package/src/react/hooks/useFilters.tsx +69 -2
  110. package/src/react/hooks/useGenerateBuyTransaction.tsx +13 -5
  111. package/src/react/hooks/useListCollectibleActivities.tsx +1 -0
  112. package/src/react/hooks/useListCollectibles.tsx +1 -0
  113. package/src/react/hooks/useListCollectionActivities.tsx +1 -0
  114. package/src/react/hooks/useListCollections.tsx +2 -2
  115. package/src/react/ui/components/_internals/custom-select/__tests__/CustomSelect.test.tsx +6 -2
  116. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +1 -1
  117. package/src/react/ui/components/collectible-card/Footer.tsx +9 -5
  118. package/src/react/ui/modals/BuyModal/Modal.tsx +9 -4
  119. package/src/react/ui/modals/BuyModal/__tests__/Modal.test.tsx +0 -1
  120. package/src/react/ui/modals/BuyModal/__tests__/store.test.ts +4 -2
  121. package/src/react/ui/modals/BuyModal/hooks/__tests__/useBuyCollectable.test.tsx +1 -24
  122. package/src/react/ui/modals/BuyModal/hooks/__tests__/useCheckoutOptions.test.tsx +152 -210
  123. package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +19 -49
  124. package/src/react/ui/modals/BuyModal/hooks/useFees.ts +6 -6
  125. package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +4 -2
  126. package/src/react/ui/modals/BuyModal/modals/__tests__/Modal1155.test.tsx +161 -52
  127. package/src/react/ui/modals/BuyModal/store.ts +7 -0
  128. package/src/react/ui/modals/CreateListingModal/Modal.tsx +1 -3
  129. package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +59 -227
  130. package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +2 -1
  131. package/src/react/ui/modals/CreateListingModal/hooks/useGetTokenApproval.ts +8 -2
  132. package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +9 -5
  133. package/src/react/ui/modals/MakeOfferModal/Modal.tsx +1 -8
  134. package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +41 -118
  135. package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +2 -1
  136. package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +9 -5
  137. package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +4 -3
  138. package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +33 -31
  139. package/src/react/ui/modals/SellModal/hooks/useSell.tsx +1 -0
  140. package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +9 -5
  141. package/src/react/ui/modals/SuccessfulPurchaseModal/__tests__/Modal.test.tsx +0 -1
  142. package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +4 -2
  143. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +129 -57
  144. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +1 -3
  145. package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +1 -3
  146. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
  147. package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +8 -8
  148. package/src/react/ui/modals/_internal/components/transactionStatusModal/hooks/useTransactionStatus.ts +1 -0
  149. package/src/types/builder-types.ts +79 -0
  150. package/src/types/index.ts +1 -1
  151. package/src/utils/__tests__/get-public-rpc-client.test.ts +2 -0
  152. package/src/utils/getMarketplaceDetails.ts +2 -2
  153. package/tsconfig.tsbuildinfo +1 -1
  154. package/vitest.config.js +2 -1
  155. package/dist/chunk-F4E3WJ2K.js.map +0 -1
  156. package/dist/chunk-FCF57DZI.js.map +0 -1
  157. package/dist/chunk-I37CRQ4S.js.map +0 -1
  158. package/dist/chunk-LJAB3S6U.js.map +0 -1
  159. package/dist/chunk-RK6KYMZM.js +0 -18
  160. package/dist/chunk-RK6KYMZM.js.map +0 -1
  161. package/dist/marketplace-config-znEu4L0K.d.ts +0 -60
  162. package/src/react/hooks/useCurrencyOptions.tsx +0 -16
  163. package/src/types/marketplace-config.ts +0 -67
  164. /package/dist/{chunk-MKGSGTQC.js.map → chunk-Y7YTLAO2.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,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
+ });