@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.
- package/dist/builder-types-Jl3Ymws8.d.ts +73 -0
- package/dist/{chunk-XP3WY5AX.js → chunk-7C7ADZ2H.js} +3 -3
- package/dist/{chunk-XP3WY5AX.js.map → chunk-7C7ADZ2H.js.map} +1 -1
- package/dist/{chunk-FCF57DZI.js → chunk-7FN62HOP.js} +5 -9
- package/dist/chunk-7FN62HOP.js.map +1 -0
- package/dist/chunk-DZKPDV63.js +27 -0
- package/dist/chunk-DZKPDV63.js.map +1 -0
- package/dist/{chunk-ZUEQGPLO.js → chunk-J6F5QOW5.js} +2 -2
- package/dist/{chunk-ZUEQGPLO.js.map → chunk-J6F5QOW5.js.map} +1 -1
- package/dist/{chunk-I37CRQ4S.js → chunk-JWNONWD6.js} +259 -173
- package/dist/chunk-JWNONWD6.js.map +1 -0
- package/dist/{chunk-LJAB3S6U.js → chunk-TFRAOS7F.js} +22 -13
- package/dist/chunk-TFRAOS7F.js.map +1 -0
- package/dist/{chunk-MKGSGTQC.js → chunk-TLNRD4BQ.js} +3 -3
- package/dist/{chunk-5NORRVPM.js → chunk-UZIAX32Y.js} +1 -1
- package/dist/{chunk-5NORRVPM.js.map → chunk-UZIAX32Y.js.map} +1 -1
- package/dist/chunk-WGGZEQHL.js +56 -0
- package/dist/chunk-WGGZEQHL.js.map +1 -0
- package/dist/{chunk-MWDG7UTB.js → chunk-ZBLU3Q22.js} +1 -1
- package/dist/{chunk-MSTTVFVQ.js → chunk-ZGVCOQ4I.js} +383 -283
- package/dist/chunk-ZGVCOQ4I.js.map +1 -0
- package/dist/{create-config-BXvwUh55.d.ts → create-config-DOUq8Day.d.ts} +2 -2
- package/dist/index.css +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +10 -6
- package/dist/{sdk-config-B32_2bG3.d.ts → marketplace.gen-D0ADxbfH.d.ts} +1 -24
- package/dist/react/_internal/api/index.d.ts +3 -2
- package/dist/react/_internal/databeat/index.css +82 -0
- package/dist/react/_internal/databeat/index.css.map +1 -0
- package/dist/react/_internal/databeat/index.d.ts +68 -0
- package/dist/react/_internal/databeat/index.js +26 -0
- package/dist/react/_internal/databeat/index.js.map +1 -0
- package/dist/react/_internal/index.d.ts +6 -5
- package/dist/react/_internal/index.js +6 -6
- package/dist/react/_internal/wagmi/index.d.ts +4 -4
- package/dist/react/_internal/wagmi/index.js +1 -1
- package/dist/react/hooks/index.d.ts +367 -22
- package/dist/react/hooks/index.js +9 -7
- package/dist/react/index.css +1 -1
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +7 -6
- package/dist/react/index.js +15 -12
- package/dist/react/ssr/index.d.ts +54 -41
- package/dist/react/ssr/index.js +5 -9
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/components/collectible-card/index.css +1 -1
- package/dist/react/ui/components/collectible-card/index.css.map +1 -1
- package/dist/react/ui/components/collectible-card/index.d.ts +4 -3
- package/dist/react/ui/components/collectible-card/index.js +9 -8
- package/dist/react/ui/components/marketplace-logos/index.js +1 -1
- package/dist/react/ui/index.css +1 -1
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +4 -3
- package/dist/react/ui/index.js +9 -8
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +4 -3
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +6 -6
- package/dist/react/ui/styles/index.d.ts +1 -1
- package/dist/sdk-config-xWkdBdrL.d.ts +24 -0
- package/dist/{services-BRBVE0mm.d.ts → services-Dd2MoBTM.d.ts} +2 -1
- package/dist/styles/index.css +1 -1
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/index.d.ts +1 -1
- package/dist/styles/index.js +1 -1
- package/dist/types/index.d.ts +4 -5
- package/dist/types/index.js +9 -5
- package/dist/{types-Yto6KrTN.d.ts → types-vOfhbBkR.d.ts} +3 -2
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +4 -4
- package/package.json +12 -10
- package/src/react/_internal/api/__mocks__/indexer.msw.ts +197 -0
- package/src/react/_internal/api/__mocks__/marketplace.msw.ts +140 -1
- package/src/react/_internal/api/__mocks__/metadata.msw.ts +162 -0
- package/src/react/_internal/databeat/index.ts +63 -0
- package/src/react/_internal/databeat/types.ts +70 -0
- package/src/react/_internal/test/mocks/publicClient.ts +39 -0
- package/src/react/_internal/test/mocks/wagmi.ts +61 -0
- package/src/react/_internal/test/mocks/wallet.ts +61 -0
- package/src/react/_internal/test/setup.ts +28 -0
- package/src/react/_internal/test-utils.tsx +31 -2
- package/src/react/_internal/wagmi/__tests__/create-config.test.ts +53 -20
- package/src/react/_internal/wagmi/create-config.ts +3 -4
- package/src/react/_internal/wagmi/embedded.ts +1 -4
- package/src/react/_internal/wagmi/universal.ts +1 -4
- package/src/react/_internal/wallet/wallet.ts +1 -0
- package/src/react/hooks/__tests__/useAutoSelectFeeOption.test.tsx +314 -0
- package/src/react/hooks/__tests__/useBalanceOfCollectible.test.tsx +148 -0
- package/src/react/hooks/__tests__/useCancelOrder.test.tsx +410 -0
- package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +269 -0
- package/src/react/hooks/__tests__/useCollectible.test.tsx +120 -0
- package/src/react/hooks/__tests__/useCollection.test.tsx +101 -0
- package/src/react/hooks/__tests__/useCollectionBalanceDetails.test.tsx +175 -0
- package/src/react/hooks/__tests__/useCollectionDetails.test.tsx +82 -0
- package/src/react/hooks/__tests__/useCollectionDetailsPolling.test.tsx +133 -0
- package/src/react/hooks/__tests__/useCountListingsForCollectible.test.tsx +108 -0
- package/src/react/hooks/__tests__/useCountOfCollectables.test.tsx +129 -0
- package/src/react/hooks/__tests__/useCountOffersForCollectible.test.tsx +108 -0
- package/src/react/hooks/__tests__/useCurrencies.test.tsx +176 -0
- package/src/react/hooks/__tests__/useCurrency.test.tsx +153 -0
- package/src/react/hooks/__tests__/useCurrencyBalance.test.tsx +111 -0
- package/src/react/hooks/__tests__/useFilters.test.tsx +127 -0
- package/src/react/hooks/__tests__/useFloorOrder.test.tsx +101 -0
- package/src/react/hooks/__tests__/useGenerateBuyTransaction.test.tsx +173 -0
- package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +207 -0
- package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +207 -0
- package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +205 -0
- package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +181 -0
- package/src/react/hooks/__tests__/useHighestOffer.test.tsx +118 -0
- package/src/react/hooks/__tests__/useListBalances.test.tsx +136 -0
- package/src/react/hooks/__tests__/useListCollectibleActivities.test.tsx +200 -0
- package/src/react/hooks/__tests__/useListCollectibles.test.tsx +232 -0
- package/src/react/hooks/__tests__/useListCollectiblesPaginated.test.tsx +217 -0
- package/src/react/hooks/__tests__/useListCollectionActivities.test.tsx +235 -0
- package/src/react/hooks/__tests__/useListCollections.test.tsx +296 -0
- package/src/react/hooks/__tests__/useListListingsForCollectible.test.tsx +140 -0
- package/src/react/hooks/__tests__/useListOffersForCollectible.test.tsx +140 -0
- package/src/react/hooks/__tests__/useLowestListing.test.tsx +148 -0
- package/src/react/hooks/__tests__/useMarketplaceConfig.test.tsx +106 -0
- package/src/react/hooks/__tests__/useRoyaltyPercentage.test.tsx +129 -0
- package/src/react/hooks/index.ts +1 -1
- package/src/react/hooks/options/__mocks__/marketplaceConfig.msw.ts +66 -10
- package/src/react/hooks/options/__tests__/marketplaceConfigOptions.test.tsx +2 -11
- package/src/react/hooks/options/marketplaceConfigOptions.ts +8 -3
- package/src/react/hooks/useAutoSelectFeeOption.tsx +4 -3
- package/src/react/hooks/useCancelTransactionSteps.tsx +17 -9
- package/src/react/hooks/useCollectionDetailsPolling.tsx +1 -1
- package/src/react/hooks/useCurrencies.tsx +29 -28
- package/src/react/hooks/useFilters.tsx +75 -2
- package/src/react/hooks/useGenerateBuyTransaction.tsx +13 -5
- package/src/react/hooks/useListCollectibleActivities.tsx +1 -0
- package/src/react/hooks/useListCollectibles.tsx +1 -0
- package/src/react/hooks/useListCollectiblesPaginated.tsx +78 -0
- package/src/react/hooks/useListCollectionActivities.tsx +1 -0
- package/src/react/hooks/useListCollections.tsx +2 -2
- package/src/react/ui/components/_internals/custom-select/__tests__/CustomSelect.test.tsx +6 -2
- package/src/react/ui/components/collectible-card/CollectibleCard.tsx +1 -1
- package/src/react/ui/components/collectible-card/Footer.tsx +9 -5
- package/src/react/ui/modals/BuyModal/Modal.tsx +9 -4
- package/src/react/ui/modals/BuyModal/__tests__/Modal.test.tsx +0 -1
- package/src/react/ui/modals/BuyModal/__tests__/store.test.ts +4 -2
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useBuyCollectable.test.tsx +1 -24
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useCheckoutOptions.test.tsx +152 -210
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +19 -49
- package/src/react/ui/modals/BuyModal/hooks/useFees.ts +6 -6
- package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +4 -2
- package/src/react/ui/modals/BuyModal/modals/__tests__/Modal1155.test.tsx +161 -52
- package/src/react/ui/modals/BuyModal/store.ts +7 -0
- package/src/react/ui/modals/CreateListingModal/Modal.tsx +1 -3
- package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +59 -227
- package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +2 -1
- package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +47 -7
- package/src/react/ui/modals/MakeOfferModal/Modal.tsx +1 -8
- package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +41 -118
- package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +2 -1
- package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +34 -6
- package/src/react/ui/modals/SellModal/Modal.tsx +3 -1
- package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +4 -3
- package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +33 -31
- package/src/react/ui/modals/SellModal/hooks/useSell.tsx +11 -7
- package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +58 -16
- package/src/react/ui/modals/SuccessfulPurchaseModal/__tests__/Modal.test.tsx +0 -1
- package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +4 -2
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +129 -57
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +1 -3
- package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +1 -3
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
- package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +8 -8
- package/src/react/ui/modals/_internal/components/transactionStatusModal/hooks/useTransactionStatus.ts +1 -0
- package/src/types/builder-types.ts +79 -0
- package/src/types/index.ts +1 -1
- package/src/utils/__tests__/get-public-rpc-client.test.ts +2 -0
- package/src/utils/getMarketplaceDetails.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.js +2 -1
- package/dist/chunk-FCF57DZI.js.map +0 -1
- package/dist/chunk-I37CRQ4S.js.map +0 -1
- package/dist/chunk-LJAB3S6U.js.map +0 -1
- package/dist/chunk-MSTTVFVQ.js.map +0 -1
- package/dist/chunk-RK6KYMZM.js +0 -18
- package/dist/chunk-RK6KYMZM.js.map +0 -1
- package/dist/marketplace-config-znEu4L0K.d.ts +0 -60
- package/src/react/hooks/useCurrencyOptions.tsx +0 -16
- package/src/types/marketplace-config.ts +0 -67
- /package/dist/{chunk-MKGSGTQC.js.map → chunk-TLNRD4BQ.js.map} +0 -0
- /package/dist/{chunk-MWDG7UTB.js.map → chunk-ZBLU3Q22.js.map} +0 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach } from 'vitest';
|
|
2
|
+
import { useListCollections } from '../useListCollections';
|
|
3
|
+
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
4
|
+
import { http, HttpResponse } from 'msw';
|
|
5
|
+
import { mockContractInfo } from '../../_internal/api/__mocks__/metadata.msw';
|
|
6
|
+
import { server } from '../../_internal/test/setup';
|
|
7
|
+
import { ResourceStatus } from '@0xsequence/metadata';
|
|
8
|
+
import {
|
|
9
|
+
createConfigHandler,
|
|
10
|
+
createStylesHandler,
|
|
11
|
+
mockConfig,
|
|
12
|
+
} from '../options/__mocks__/marketplaceConfig.msw';
|
|
13
|
+
import { MarketplaceType, OrderbookKind } from '../../../types';
|
|
14
|
+
|
|
15
|
+
describe('useListCollections', () => {
|
|
16
|
+
const defaultArgs = {
|
|
17
|
+
query: {
|
|
18
|
+
enabled: true,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Reset handlers before each test
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
server.resetHandlers();
|
|
25
|
+
// Set up default handlers for config and styles
|
|
26
|
+
server.use(createConfigHandler(), createStylesHandler());
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should fetch collections successfully', async () => {
|
|
30
|
+
// Mock marketplace config with collection
|
|
31
|
+
server.use(
|
|
32
|
+
createConfigHandler({
|
|
33
|
+
...mockConfig,
|
|
34
|
+
collections: [
|
|
35
|
+
{
|
|
36
|
+
chainId: 1,
|
|
37
|
+
address:
|
|
38
|
+
'0x1234567890123456789012345678901234567890' as `0x${string}`,
|
|
39
|
+
feePercentage: 2.5,
|
|
40
|
+
marketplaceType: MarketplaceType.ORDERBOOK,
|
|
41
|
+
currencyOptions: [],
|
|
42
|
+
exchanges: [],
|
|
43
|
+
bannerUrl: '',
|
|
44
|
+
destinationMarketplace: OrderbookKind.sequence_marketplace_v2,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
}),
|
|
48
|
+
http.post('*/rpc/Metadata/GetContractInfoBatch', () => {
|
|
49
|
+
return HttpResponse.json({
|
|
50
|
+
contractInfoMap: {
|
|
51
|
+
'0x1234567890123456789012345678901234567890': mockContractInfo,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const { result } = renderHook(() => useListCollections(defaultArgs));
|
|
58
|
+
|
|
59
|
+
// Wait for data to be loaded
|
|
60
|
+
await waitFor(() => {
|
|
61
|
+
expect(result.current.data).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Verify the data matches our mock
|
|
65
|
+
expect(result.current.data).toEqual([mockContractInfo]);
|
|
66
|
+
expect(result.current.error).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should handle empty collections', async () => {
|
|
70
|
+
// Mock marketplace config with empty collections
|
|
71
|
+
server.use(
|
|
72
|
+
createConfigHandler({
|
|
73
|
+
...mockConfig,
|
|
74
|
+
collections: [],
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const { result } = renderHook(() => useListCollections(defaultArgs));
|
|
79
|
+
|
|
80
|
+
await waitFor(() => {
|
|
81
|
+
expect(result.current.data).toBeDefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(result.current.data).toEqual([]);
|
|
85
|
+
expect(result.current.error).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should handle error states', async () => {
|
|
89
|
+
// Mock marketplace config with collection
|
|
90
|
+
server.use(
|
|
91
|
+
createConfigHandler({
|
|
92
|
+
...mockConfig,
|
|
93
|
+
collections: [
|
|
94
|
+
{
|
|
95
|
+
chainId: 1,
|
|
96
|
+
address:
|
|
97
|
+
'0x1234567890123456789012345678901234567890' as `0x${string}`,
|
|
98
|
+
feePercentage: 2.5,
|
|
99
|
+
marketplaceType: MarketplaceType.ORDERBOOK,
|
|
100
|
+
currencyOptions: [],
|
|
101
|
+
exchanges: [],
|
|
102
|
+
bannerUrl: '',
|
|
103
|
+
destinationMarketplace: OrderbookKind.sequence_marketplace_v2,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
}),
|
|
107
|
+
http.post('*/rpc/Metadata/GetContractInfoBatch', () => {
|
|
108
|
+
return new HttpResponse(
|
|
109
|
+
JSON.stringify({ error: { message: 'Failed to fetch collections' } }),
|
|
110
|
+
{ status: 500 },
|
|
111
|
+
);
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const { result } = renderHook(() => useListCollections(defaultArgs));
|
|
116
|
+
|
|
117
|
+
await waitFor(() => {
|
|
118
|
+
expect(result.current.isError).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
expect(result.current.error).toBeDefined();
|
|
122
|
+
expect(result.current.data).toBeUndefined();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should handle disabled queries', async () => {
|
|
126
|
+
let requestMade = false;
|
|
127
|
+
|
|
128
|
+
// Mock marketplace config with collection
|
|
129
|
+
server.use(
|
|
130
|
+
createConfigHandler({
|
|
131
|
+
...mockConfig,
|
|
132
|
+
collections: [
|
|
133
|
+
{
|
|
134
|
+
chainId: 1,
|
|
135
|
+
address:
|
|
136
|
+
'0x1234567890123456789012345678901234567890' as `0x${string}`,
|
|
137
|
+
feePercentage: 2.5,
|
|
138
|
+
marketplaceType: MarketplaceType.ORDERBOOK,
|
|
139
|
+
currencyOptions: [],
|
|
140
|
+
exchanges: [],
|
|
141
|
+
bannerUrl: '',
|
|
142
|
+
destinationMarketplace: OrderbookKind.sequence_marketplace_v2,
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
}),
|
|
146
|
+
http.post('*/rpc/Metadata/GetContractInfoBatch', () => {
|
|
147
|
+
requestMade = true;
|
|
148
|
+
return HttpResponse.json({
|
|
149
|
+
contractInfoMap: {
|
|
150
|
+
'0x1234567890123456789012345678901234567890': mockContractInfo,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const disabledArgs = {
|
|
157
|
+
query: {
|
|
158
|
+
enabled: false,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const { result } = renderHook(() => useListCollections(disabledArgs));
|
|
163
|
+
|
|
164
|
+
// For disabled queries, we expect no loading state and no data
|
|
165
|
+
expect(result.current.isLoading).toBe(false);
|
|
166
|
+
expect(result.current.data).toBeUndefined();
|
|
167
|
+
expect(result.current.error).toBeNull();
|
|
168
|
+
expect(requestMade).toBe(false);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('should handle multiple collections from different chains', async () => {
|
|
172
|
+
const mockContractInfo2 = {
|
|
173
|
+
...mockContractInfo,
|
|
174
|
+
address: '0x1234567890123456789012345678901234567890' as `0x${string}`,
|
|
175
|
+
chainId: 137, // Different chain (Polygon)
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// Mock marketplace config with multiple collections
|
|
179
|
+
server.use(
|
|
180
|
+
createConfigHandler({
|
|
181
|
+
...mockConfig,
|
|
182
|
+
collections: [
|
|
183
|
+
{
|
|
184
|
+
chainId: 1,
|
|
185
|
+
address:
|
|
186
|
+
'0x1234567890123456789012345678901234567890' as `0x${string}`,
|
|
187
|
+
feePercentage: 2.5,
|
|
188
|
+
marketplaceType: MarketplaceType.ORDERBOOK,
|
|
189
|
+
currencyOptions: [],
|
|
190
|
+
exchanges: [],
|
|
191
|
+
bannerUrl: '',
|
|
192
|
+
destinationMarketplace: OrderbookKind.sequence_marketplace_v2,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
chainId: 137,
|
|
196
|
+
address: mockContractInfo2.address,
|
|
197
|
+
feePercentage: 2.5,
|
|
198
|
+
marketplaceType: MarketplaceType.ORDERBOOK,
|
|
199
|
+
currencyOptions: [],
|
|
200
|
+
exchanges: [],
|
|
201
|
+
bannerUrl: '',
|
|
202
|
+
destinationMarketplace: OrderbookKind.sequence_marketplace_v2,
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
}),
|
|
206
|
+
http.post('*/rpc/Metadata/GetContractInfoBatch', async ({ request }) => {
|
|
207
|
+
const body = (await request.json()) as { chainID: string };
|
|
208
|
+
if (body.chainID === '1') {
|
|
209
|
+
return HttpResponse.json({
|
|
210
|
+
contractInfoMap: {
|
|
211
|
+
'0x1234567890123456789012345678901234567890': mockContractInfo,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return HttpResponse.json({
|
|
216
|
+
contractInfoMap: {
|
|
217
|
+
[mockContractInfo2.address]: mockContractInfo2,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}),
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const { result } = renderHook(() => useListCollections(defaultArgs));
|
|
224
|
+
|
|
225
|
+
await waitFor(() => {
|
|
226
|
+
expect(result.current.data).toBeDefined();
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
expect(result.current.data).toHaveLength(2);
|
|
230
|
+
expect(result.current.data).toEqual(
|
|
231
|
+
expect.arrayContaining([mockContractInfo, mockContractInfo2]),
|
|
232
|
+
);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('should handle collections with different resource statuses', async () => {
|
|
236
|
+
const mockUnavailableContract = {
|
|
237
|
+
...mockContractInfo,
|
|
238
|
+
address: '0x9876543210987654321098765432109876543210' as `0x${string}`,
|
|
239
|
+
status: ResourceStatus.NOT_AVAILABLE,
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// Mock marketplace config with multiple collections
|
|
243
|
+
server.use(
|
|
244
|
+
createConfigHandler({
|
|
245
|
+
...mockConfig,
|
|
246
|
+
collections: [
|
|
247
|
+
{
|
|
248
|
+
chainId: 1,
|
|
249
|
+
address:
|
|
250
|
+
'0x1234567890123456789012345678901234567890' as `0x${string}`,
|
|
251
|
+
feePercentage: 2.5,
|
|
252
|
+
marketplaceType: MarketplaceType.ORDERBOOK,
|
|
253
|
+
currencyOptions: [],
|
|
254
|
+
exchanges: [],
|
|
255
|
+
bannerUrl: '',
|
|
256
|
+
destinationMarketplace: OrderbookKind.sequence_marketplace_v2,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
chainId: 1,
|
|
260
|
+
address: mockUnavailableContract.address,
|
|
261
|
+
feePercentage: 2.5,
|
|
262
|
+
marketplaceType: MarketplaceType.ORDERBOOK,
|
|
263
|
+
currencyOptions: [],
|
|
264
|
+
exchanges: [],
|
|
265
|
+
bannerUrl: '',
|
|
266
|
+
destinationMarketplace: OrderbookKind.sequence_marketplace_v2,
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
}),
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
// Mock metadata response for both contracts
|
|
273
|
+
server.use(
|
|
274
|
+
http.post('*/rpc/Metadata/GetContractInfoBatch', () => {
|
|
275
|
+
return HttpResponse.json({
|
|
276
|
+
contractInfoMap: {
|
|
277
|
+
'0x1234567890123456789012345678901234567890': mockContractInfo,
|
|
278
|
+
'0x9876543210987654321098765432109876543210':
|
|
279
|
+
mockUnavailableContract,
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const { result } = renderHook(() => useListCollections(defaultArgs));
|
|
286
|
+
|
|
287
|
+
await waitFor(() => {
|
|
288
|
+
expect(result.current.data).toBeDefined();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
expect(result.current.data).toHaveLength(2);
|
|
292
|
+
expect(result.current.data).toEqual(
|
|
293
|
+
expect.arrayContaining([mockContractInfo, mockUnavailableContract]),
|
|
294
|
+
);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { useListListingsForCollectible } from '../useListListingsForCollectible';
|
|
3
|
+
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
4
|
+
import { zeroAddress } from 'viem';
|
|
5
|
+
import { MarketplaceKind } from '../../_internal/api/marketplace.gen';
|
|
6
|
+
import { http, HttpResponse } from 'msw';
|
|
7
|
+
import {
|
|
8
|
+
mockOrder,
|
|
9
|
+
mockMarketplaceEndpoint,
|
|
10
|
+
} from '../../_internal/api/__mocks__/marketplace.msw';
|
|
11
|
+
import { server } from '../../_internal/test/setup';
|
|
12
|
+
|
|
13
|
+
describe('useListListingsForCollectible', () => {
|
|
14
|
+
const defaultArgs = {
|
|
15
|
+
chainId: '1',
|
|
16
|
+
collectionAddress: zeroAddress,
|
|
17
|
+
collectibleId: '1',
|
|
18
|
+
page: {
|
|
19
|
+
page: 1,
|
|
20
|
+
pageSize: 10,
|
|
21
|
+
},
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
it('should fetch listings data successfully', async () => {
|
|
25
|
+
const { result } = renderHook(() =>
|
|
26
|
+
useListListingsForCollectible(defaultArgs),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// Initially loading
|
|
30
|
+
expect(result.current.isLoading).toBe(true);
|
|
31
|
+
expect(result.current.data).toBeUndefined();
|
|
32
|
+
|
|
33
|
+
// Wait for data to be loaded
|
|
34
|
+
await waitFor(() => {
|
|
35
|
+
expect(result.current.isLoading).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Verify the data matches our mock
|
|
39
|
+
expect(result.current.data).toBeDefined();
|
|
40
|
+
expect(result.current.data?.listings).toEqual([mockOrder]);
|
|
41
|
+
expect(result.current.error).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should handle error states', async () => {
|
|
45
|
+
// Override the handler for this test to return an error
|
|
46
|
+
server.use(
|
|
47
|
+
http.post(mockMarketplaceEndpoint('ListCollectibleListings'), () => {
|
|
48
|
+
return HttpResponse.json(
|
|
49
|
+
{ error: { message: 'Failed to fetch listings' } },
|
|
50
|
+
{ status: 500 },
|
|
51
|
+
);
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const { result } = renderHook(() =>
|
|
56
|
+
useListListingsForCollectible(defaultArgs),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
await waitFor(() => {
|
|
60
|
+
expect(result.current.isError).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(result.current.error).toBeDefined();
|
|
64
|
+
expect(result.current.data).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should refetch when args change', async () => {
|
|
68
|
+
const { result, rerender } = renderHook(() =>
|
|
69
|
+
useListListingsForCollectible(defaultArgs),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// Wait for initial data
|
|
73
|
+
await waitFor(() => {
|
|
74
|
+
expect(result.current.isLoading).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Change args and rerender
|
|
78
|
+
const newArgs = {
|
|
79
|
+
...defaultArgs,
|
|
80
|
+
collectibleId: '2',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
rerender(() => useListListingsForCollectible(newArgs));
|
|
84
|
+
|
|
85
|
+
// Wait for new data
|
|
86
|
+
await waitFor(() => {
|
|
87
|
+
expect(result.current.data).toBeDefined();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Verify that the query was refetched with new args
|
|
91
|
+
expect(result.current.data?.listings).toEqual([mockOrder]);
|
|
92
|
+
expect(result.current.isSuccess).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should handle pagination correctly', async () => {
|
|
96
|
+
const paginatedArgs = {
|
|
97
|
+
...defaultArgs,
|
|
98
|
+
page: {
|
|
99
|
+
page: 2,
|
|
100
|
+
pageSize: 20,
|
|
101
|
+
},
|
|
102
|
+
} as const;
|
|
103
|
+
|
|
104
|
+
const { result } = renderHook(() =>
|
|
105
|
+
useListListingsForCollectible(paginatedArgs),
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
await waitFor(() => {
|
|
109
|
+
expect(result.current.isLoading).toBe(false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(result.current.data?.page).toBeDefined();
|
|
113
|
+
expect(result.current.data?.page?.page).toBe(1);
|
|
114
|
+
expect(result.current.data?.page?.pageSize).toBe(10);
|
|
115
|
+
expect(result.current.data?.page?.more).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should handle optional filter parameter', async () => {
|
|
119
|
+
const argsWithFilter = {
|
|
120
|
+
...defaultArgs,
|
|
121
|
+
filter: {
|
|
122
|
+
marketplace: [
|
|
123
|
+
MarketplaceKind.sequence_marketplace_v2,
|
|
124
|
+
] as MarketplaceKind[],
|
|
125
|
+
currencies: [zeroAddress] as string[],
|
|
126
|
+
},
|
|
127
|
+
} as const;
|
|
128
|
+
|
|
129
|
+
const { result } = renderHook(() =>
|
|
130
|
+
useListListingsForCollectible(argsWithFilter),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
await waitFor(() => {
|
|
134
|
+
expect(result.current.isLoading).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(result.current.data?.listings).toEqual([mockOrder]);
|
|
138
|
+
expect(result.current.isSuccess).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { useListOffersForCollectible } from '../useListOffersForCollectible';
|
|
3
|
+
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
4
|
+
import { zeroAddress } from 'viem';
|
|
5
|
+
import { MarketplaceKind } from '../../_internal/api/marketplace.gen';
|
|
6
|
+
import { http, HttpResponse } from 'msw';
|
|
7
|
+
import {
|
|
8
|
+
mockOrder,
|
|
9
|
+
mockMarketplaceEndpoint,
|
|
10
|
+
} from '../../_internal/api/__mocks__/marketplace.msw';
|
|
11
|
+
import { server } from '../../_internal/test/setup';
|
|
12
|
+
|
|
13
|
+
describe('useListOffersForCollectible', () => {
|
|
14
|
+
const defaultArgs = {
|
|
15
|
+
chainId: '1',
|
|
16
|
+
collectionAddress: zeroAddress,
|
|
17
|
+
collectibleId: '1',
|
|
18
|
+
page: {
|
|
19
|
+
page: 1,
|
|
20
|
+
pageSize: 10,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
it('should fetch offers data successfully', async () => {
|
|
25
|
+
const { result } = renderHook(() =>
|
|
26
|
+
useListOffersForCollectible(defaultArgs),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// Initially loading
|
|
30
|
+
expect(result.current.isLoading).toBe(true);
|
|
31
|
+
expect(result.current.data).toBeUndefined();
|
|
32
|
+
|
|
33
|
+
// Wait for data to be loaded
|
|
34
|
+
await waitFor(() => {
|
|
35
|
+
expect(result.current.isLoading).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Verify the data matches our mock
|
|
39
|
+
expect(result.current.data).toBeDefined();
|
|
40
|
+
expect(result.current.data?.offers).toEqual([mockOrder]);
|
|
41
|
+
expect(result.current.error).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should handle error states', async () => {
|
|
45
|
+
// Override the handler for this test to return an error
|
|
46
|
+
server.use(
|
|
47
|
+
http.post(mockMarketplaceEndpoint('ListCollectibleOffers'), () => {
|
|
48
|
+
return HttpResponse.json(
|
|
49
|
+
{ error: { message: 'Failed to fetch offers' } },
|
|
50
|
+
{ status: 500 },
|
|
51
|
+
);
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const { result } = renderHook(() =>
|
|
56
|
+
useListOffersForCollectible(defaultArgs),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
await waitFor(() => {
|
|
60
|
+
expect(result.current.isError).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(result.current.error).toBeDefined();
|
|
64
|
+
expect(result.current.data).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should refetch when args change', async () => {
|
|
68
|
+
const { result, rerender } = renderHook(() =>
|
|
69
|
+
useListOffersForCollectible(defaultArgs),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// Wait for initial data
|
|
73
|
+
await waitFor(() => {
|
|
74
|
+
expect(result.current.isLoading).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Change args and rerender
|
|
78
|
+
const newArgs = {
|
|
79
|
+
...defaultArgs,
|
|
80
|
+
collectibleId: '2',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
rerender(() => useListOffersForCollectible(newArgs));
|
|
84
|
+
|
|
85
|
+
// Wait for new data
|
|
86
|
+
await waitFor(() => {
|
|
87
|
+
expect(result.current.data).toBeDefined();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Verify that the query was refetched with new args
|
|
91
|
+
expect(result.current.data?.offers).toEqual([mockOrder]);
|
|
92
|
+
expect(result.current.isSuccess).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should handle pagination correctly', async () => {
|
|
96
|
+
const paginatedArgs = {
|
|
97
|
+
...defaultArgs,
|
|
98
|
+
page: {
|
|
99
|
+
page: 2,
|
|
100
|
+
pageSize: 20,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const { result } = renderHook(() =>
|
|
105
|
+
useListOffersForCollectible(paginatedArgs),
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
await waitFor(() => {
|
|
109
|
+
expect(result.current.isLoading).toBe(false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(result.current.data?.page).toBeDefined();
|
|
113
|
+
expect(result.current.data?.page?.page).toBe(1);
|
|
114
|
+
expect(result.current.data?.page?.pageSize).toBe(10);
|
|
115
|
+
expect(result.current.data?.page?.more).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should handle optional filter parameter', async () => {
|
|
119
|
+
const argsWithFilter = {
|
|
120
|
+
...defaultArgs,
|
|
121
|
+
filter: {
|
|
122
|
+
marketplace: [
|
|
123
|
+
MarketplaceKind.sequence_marketplace_v2,
|
|
124
|
+
] as MarketplaceKind[],
|
|
125
|
+
currencies: [zeroAddress] as string[],
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const { result } = renderHook(() =>
|
|
130
|
+
useListOffersForCollectible(argsWithFilter),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
await waitFor(() => {
|
|
134
|
+
expect(result.current.isLoading).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(result.current.data?.offers).toEqual([mockOrder]);
|
|
138
|
+
expect(result.current.isSuccess).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
});
|