@0xsequence/marketplace-sdk 0.5.6 → 0.5.7
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/{chunk-J6F5QOW5.js → chunk-3OU7BADC.js} +9 -75
- package/dist/chunk-3OU7BADC.js.map +1 -0
- package/dist/{chunk-Y75XGZOB.js → chunk-5O3ZAEEX.js} +4 -2
- package/dist/chunk-5O3ZAEEX.js.map +1 -0
- package/dist/{chunk-4YR6AIXG.js → chunk-G2T7HCWE.js} +5 -7
- package/dist/chunk-G2T7HCWE.js.map +1 -0
- package/dist/chunk-GFADBQPX.js +2 -0
- package/dist/chunk-GFADBQPX.js.map +1 -0
- package/dist/{chunk-E2V2BMF6.js → chunk-L2K4DBH2.js} +152 -89
- package/dist/chunk-L2K4DBH2.js.map +1 -0
- package/dist/{chunk-7C7ADZ2H.js → chunk-OMCWTRBR.js} +9 -42
- package/dist/chunk-OMCWTRBR.js.map +1 -0
- package/dist/{chunk-7FN62HOP.js → chunk-UMYRZJVY.js} +11 -3
- package/dist/chunk-UMYRZJVY.js.map +1 -0
- package/dist/{chunk-UZIAX32Y.js → chunk-Y56IIYDF.js} +6 -4
- package/dist/{chunk-UZIAX32Y.js.map → chunk-Y56IIYDF.js.map} +1 -1
- package/dist/{chunk-AIGFG26L.js → chunk-YA3DWLDC.js} +32 -28
- package/dist/chunk-YA3DWLDC.js.map +1 -0
- package/dist/{chunk-RIGIV5XT.js → chunk-YYBU45PK.js} +10 -4
- package/dist/chunk-YYBU45PK.js.map +1 -0
- package/dist/{create-config-CtFGrwXc.d.ts → create-config-CILyA_Hy.d.ts} +1 -1
- package/dist/index.css +12 -6
- package/dist/index.d.ts +6 -5
- package/dist/index.js +13 -10
- package/dist/react/_internal/api/index.d.ts +2 -2
- package/dist/react/_internal/databeat/index.css.map +1 -1
- package/dist/react/_internal/databeat/index.js +7 -7
- package/dist/react/_internal/index.d.ts +4 -4
- package/dist/react/_internal/index.js +1 -1
- package/dist/react/_internal/wagmi/index.d.ts +2 -2
- package/dist/react/_internal/wagmi/index.js +1 -1
- package/dist/react/hooks/index.css.map +1 -1
- package/dist/react/hooks/index.d.ts +8 -15
- package/dist/react/hooks/index.js +6 -6
- package/dist/react/index.css +12 -6
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +11 -10
- package/dist/react/ssr/index.d.ts +1 -0
- package/dist/react/ssr/index.js +10 -2
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/components/collectible-card/index.css +12 -6
- package/dist/react/ui/components/collectible-card/index.css.map +1 -1
- package/dist/react/ui/components/collectible-card/index.d.ts +2 -2
- package/dist/react/ui/components/collectible-card/index.js +11 -10
- package/dist/react/ui/icons/index.css.map +1 -1
- package/dist/react/ui/index.css +12 -6
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +2 -2
- package/dist/react/ui/index.js +11 -10
- package/dist/react/ui/modals/_internal/components/actionModal/index.css.map +1 -1
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +7 -7
- package/dist/react/ui/styles/index.css.map +1 -1
- package/dist/{sdk-config-xWkdBdrL.d.ts → sdk-config-Bs3H_le_.d.ts} +1 -0
- package/dist/{services-Cled3TJr.d.ts → services-C3lzi1sL.d.ts} +1 -1
- package/dist/styles/index.css +12 -6
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/index.d.ts +3 -2
- package/dist/styles/index.js +4 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/{types-C4oGsbnK.d.ts → types-BVD42zE_.d.ts} +1 -1
- package/dist/utils/abi/index.js +5 -5
- package/dist/utils/index.d.ts +5 -6
- package/dist/utils/index.js +9 -9
- package/package.json +14 -14
- package/src/consts.ts +2 -0
- package/src/react/_internal/databeat/index.ts +11 -3
- package/src/react/_internal/wagmi/create-config.ts +11 -2
- package/src/react/_internal/wallet/__tests__/wallet.test.ts +343 -0
- package/src/react/_internal/wallet/useWallet.ts +22 -15
- package/src/react/_internal/wallet/wallet.ts +11 -9
- package/src/react/hooks/__tests__/useBalanceOfCollectible.test.tsx +6 -14
- package/src/react/hooks/__tests__/useCancelOrder.test.tsx +51 -154
- package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +21 -19
- package/src/react/hooks/__tests__/useCollectionBalanceDetails.test.tsx +5 -14
- package/src/react/hooks/__tests__/useCollectionDetailsPolling.test.tsx +5 -10
- package/src/react/hooks/__tests__/useCurrencyBalance.test.tsx +69 -80
- package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +12 -67
- package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +7 -17
- package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +7 -16
- package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +8 -17
- package/src/react/hooks/__tests__/useListBalances.test.tsx +3 -8
- package/src/react/hooks/__tests__/useListCollectibleActivities.test.tsx +5 -10
- package/src/react/hooks/__tests__/useListCollectionActivities.test.tsx +6 -11
- package/src/react/hooks/__tests__/useListCollections.test.tsx +5 -13
- package/src/react/hooks/__tests__/useMarketplaceConfig.test.tsx +5 -13
- package/src/react/hooks/__tests__/useRoyaltyPercentage.test.tsx +46 -78
- package/src/react/hooks/options/__mocks__/marketplaceConfig.msw.ts +9 -4
- package/src/react/hooks/useCurrencyBalance.tsx +4 -5
- package/src/react/hooks/useRoyaltyPercentage.tsx +16 -8
- package/src/react/ssr/__tests__/create-ssr-client.test.ts +118 -0
- package/src/react/ui/components/collectible-card/CollectibleCard.tsx +25 -6
- package/src/react/ui/components/collectible-card/Footer.tsx +46 -7
- package/src/react/ui/components/collectible-card/styles.css.ts +26 -2
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useCheckoutOptions.test.tsx +10 -28
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useLoadData.test.tsx +9 -36
- package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +16 -5
- package/src/react/ui/modals/CreateListingModal/Modal.tsx +3 -2
- package/src/react/ui/modals/SellModal/Modal.tsx +1 -0
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +8 -7
- package/src/types/sdk-config.ts +1 -0
- package/src/utils/index.ts +0 -1
- package/src/utils/price.ts +11 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/chunk-4YR6AIXG.js.map +0 -1
- package/dist/chunk-7C7ADZ2H.js.map +0 -1
- package/dist/chunk-7FN62HOP.js.map +0 -1
- package/dist/chunk-AIGFG26L.js.map +0 -1
- package/dist/chunk-E2V2BMF6.js.map +0 -1
- package/dist/chunk-J6F5QOW5.js.map +0 -1
- package/dist/chunk-RIGIV5XT.js.map +0 -1
- package/dist/chunk-Y75XGZOB.js.map +0 -1
- package/src/react/_internal/test/mocks/publicClient.ts +0 -39
- package/src/react/_internal/test/mocks/wagmi.ts +0 -61
- package/src/utils/__tests__/get-public-rpc-client.test.ts +0 -111
- package/src/utils/get-public-rpc-client.ts +0 -41
|
@@ -1,59 +1,20 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
3
|
-
import { useCancelOrder } from '../useCancelOrder';
|
|
4
|
-
import { MarketplaceKind } from '../../../types';
|
|
5
|
-
import { server } from '../../_internal/test/setup';
|
|
6
1
|
import { http, HttpResponse } from 'msw';
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { MarketplaceKind } from '../../../types';
|
|
7
4
|
import { mockMarketplaceEndpoint } from '../../_internal/api/__mocks__/marketplace.msw';
|
|
8
|
-
import {
|
|
5
|
+
import { StepType } from '../../_internal/api/marketplace.gen';
|
|
6
|
+
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
9
7
|
import {
|
|
10
|
-
createMockWallet,
|
|
11
8
|
commonWalletMocks,
|
|
9
|
+
createMockWallet,
|
|
12
10
|
} from '../../_internal/test/mocks/wallet';
|
|
13
|
-
import {
|
|
11
|
+
import { server } from '../../_internal/test/setup';
|
|
12
|
+
import { useWallet } from '../../_internal/wallet/useWallet';
|
|
13
|
+
import { useCancelOrder } from '../useCancelOrder';
|
|
14
14
|
|
|
15
15
|
// Mock useWallet hook
|
|
16
16
|
vi.mock('../../_internal/wallet/useWallet');
|
|
17
17
|
|
|
18
|
-
// Mock @0xsequence/kit
|
|
19
|
-
vi.mock('@0xsequence/kit', () => ({
|
|
20
|
-
useWaasFeeOptions: () => [null, vi.fn()],
|
|
21
|
-
useChain: () => ({
|
|
22
|
-
id: 1,
|
|
23
|
-
name: 'Ethereum',
|
|
24
|
-
nativeCurrency: {
|
|
25
|
-
name: 'Ether',
|
|
26
|
-
symbol: 'ETH',
|
|
27
|
-
decimals: 18,
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
// Mock wagmi
|
|
33
|
-
vi.mock('wagmi', () => ({
|
|
34
|
-
useAccount: () => ({
|
|
35
|
-
address: '0x1234567890123456789012345678901234567890',
|
|
36
|
-
isConnected: true,
|
|
37
|
-
}),
|
|
38
|
-
createConfig: () => ({
|
|
39
|
-
chains: [
|
|
40
|
-
{
|
|
41
|
-
id: 1,
|
|
42
|
-
name: 'Ethereum',
|
|
43
|
-
nativeCurrency: {
|
|
44
|
-
name: 'Ether',
|
|
45
|
-
symbol: 'ETH',
|
|
46
|
-
decimals: 18,
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
connectors: [],
|
|
51
|
-
transports: {},
|
|
52
|
-
}),
|
|
53
|
-
http: () => ({}),
|
|
54
|
-
WagmiProvider: ({ children }: { children: React.ReactNode }) => children,
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
18
|
describe('useCancelOrder', () => {
|
|
58
19
|
const defaultProps = {
|
|
59
20
|
collectionAddress: '0x1234567890123456789012345678901234567890',
|
|
@@ -77,55 +38,12 @@ describe('useCancelOrder', () => {
|
|
|
77
38
|
});
|
|
78
39
|
|
|
79
40
|
beforeEach(() => {
|
|
80
|
-
vi.clearAllMocks();
|
|
81
|
-
|
|
82
41
|
// Set up the mock implementation for useWallet
|
|
83
42
|
vi.mocked(useWallet).mockReturnValue({
|
|
84
43
|
wallet: mockWallet,
|
|
85
44
|
isLoading: false,
|
|
86
45
|
isError: false,
|
|
87
46
|
});
|
|
88
|
-
|
|
89
|
-
// Mock default steps response
|
|
90
|
-
server.use(
|
|
91
|
-
http.post(mockMarketplaceEndpoint('GenerateCancelTransaction'), () => {
|
|
92
|
-
return HttpResponse.json({
|
|
93
|
-
steps: [
|
|
94
|
-
{
|
|
95
|
-
id: StepType.cancel,
|
|
96
|
-
data: '0x...',
|
|
97
|
-
to: defaultProps.collectionAddress,
|
|
98
|
-
value: '0',
|
|
99
|
-
executeType: 'order',
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
});
|
|
103
|
-
}),
|
|
104
|
-
http.post(mockMarketplaceEndpoint('Execute'), () => {
|
|
105
|
-
return HttpResponse.json({
|
|
106
|
-
orderId: mockOrderId,
|
|
107
|
-
hash: mockTxHash,
|
|
108
|
-
});
|
|
109
|
-
}),
|
|
110
|
-
http.post('*/GetTokenBalancesDetails', () => {
|
|
111
|
-
return HttpResponse.json({
|
|
112
|
-
page: { page: 1, pageSize: 10, more: false },
|
|
113
|
-
balances: [],
|
|
114
|
-
nativeBalances: [
|
|
115
|
-
{
|
|
116
|
-
balance: '2000000000000000000', // 2 ETH
|
|
117
|
-
blockHash: '0x1234',
|
|
118
|
-
blockNumber: 1234567,
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
});
|
|
122
|
-
}),
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
afterEach(() => {
|
|
127
|
-
server.resetHandlers();
|
|
128
|
-
vi.clearAllMocks();
|
|
129
47
|
});
|
|
130
48
|
|
|
131
49
|
it('should initialize with default state', () => {
|
|
@@ -263,15 +181,32 @@ describe('useCancelOrder', () => {
|
|
|
263
181
|
it('should handle transaction confirmation failure', async () => {
|
|
264
182
|
const onError = vi.fn();
|
|
265
183
|
|
|
184
|
+
// Mock the GenerateCancelTransaction endpoint to return a valid transaction step
|
|
185
|
+
server.use(
|
|
186
|
+
http.post(mockMarketplaceEndpoint('GenerateCancelTransaction'), () => {
|
|
187
|
+
return HttpResponse.json({
|
|
188
|
+
steps: [
|
|
189
|
+
{
|
|
190
|
+
id: StepType.cancel,
|
|
191
|
+
data: '0x1234',
|
|
192
|
+
to: defaultProps.collectionAddress,
|
|
193
|
+
value: '0',
|
|
194
|
+
executeType: 'order',
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
});
|
|
198
|
+
}),
|
|
199
|
+
);
|
|
200
|
+
|
|
266
201
|
// Mock wallet with failed transaction confirmation
|
|
267
202
|
const mockWalletWithFailedConfirmation = createMockWallet({
|
|
268
203
|
...commonWalletMocks,
|
|
269
204
|
getChainId: vi.fn().mockResolvedValue(1),
|
|
270
|
-
handleSendTransactionStep: vi
|
|
271
|
-
handleSignMessageStep: vi.fn().mockResolvedValue('0xsignature'),
|
|
272
|
-
handleConfirmTransactionStep: vi
|
|
205
|
+
handleSendTransactionStep: vi
|
|
273
206
|
.fn()
|
|
274
|
-
.mockRejectedValue(new Error('Transaction
|
|
207
|
+
.mockRejectedValue(new Error('Transaction sending failed')),
|
|
208
|
+
handleSignMessageStep: vi.fn().mockResolvedValue('0xsignature'),
|
|
209
|
+
handleConfirmTransactionStep: vi.fn().mockResolvedValue(undefined),
|
|
275
210
|
isWaaS: true,
|
|
276
211
|
});
|
|
277
212
|
|
|
@@ -300,7 +235,7 @@ describe('useCancelOrder', () => {
|
|
|
300
235
|
await waitFor(() => {
|
|
301
236
|
expect(onError).toHaveBeenCalledWith(expect.any(Error));
|
|
302
237
|
expect(
|
|
303
|
-
mockWalletWithFailedConfirmation.
|
|
238
|
+
mockWalletWithFailedConfirmation.handleSendTransactionStep,
|
|
304
239
|
).toHaveBeenCalled();
|
|
305
240
|
expect(result.current.cancellingOrderId).toBeNull();
|
|
306
241
|
expect(result.current.isExecuting).toBe(false);
|
|
@@ -310,28 +245,20 @@ describe('useCancelOrder', () => {
|
|
|
310
245
|
it('should successfully cancel an order', async () => {
|
|
311
246
|
const onSuccess = vi.fn();
|
|
312
247
|
|
|
313
|
-
// Mock successful responses for all steps
|
|
248
|
+
// Mock successful responses for all steps - make the response immediate
|
|
314
249
|
server.use(
|
|
315
250
|
http.post(mockMarketplaceEndpoint('GenerateCancelTransaction'), () => {
|
|
316
|
-
return
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
executeType: 'order',
|
|
328
|
-
},
|
|
329
|
-
],
|
|
330
|
-
}),
|
|
331
|
-
),
|
|
332
|
-
50,
|
|
333
|
-
),
|
|
334
|
-
);
|
|
251
|
+
return HttpResponse.json({
|
|
252
|
+
steps: [
|
|
253
|
+
{
|
|
254
|
+
id: StepType.cancel,
|
|
255
|
+
data: '0x1234',
|
|
256
|
+
to: defaultProps.collectionAddress,
|
|
257
|
+
value: '0',
|
|
258
|
+
executeType: 'order',
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
});
|
|
335
262
|
}),
|
|
336
263
|
http.post(mockMarketplaceEndpoint('Execute'), () => {
|
|
337
264
|
return HttpResponse.json({
|
|
@@ -362,49 +289,19 @@ describe('useCancelOrder', () => {
|
|
|
362
289
|
}),
|
|
363
290
|
);
|
|
364
291
|
|
|
365
|
-
// Start the cancellation
|
|
366
|
-
result.current.cancelOrder({
|
|
292
|
+
// Start the cancellation and wait for it to complete
|
|
293
|
+
await result.current.cancelOrder({
|
|
367
294
|
orderId: mockOrderId,
|
|
368
295
|
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
369
296
|
});
|
|
370
297
|
|
|
371
|
-
//
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
},
|
|
376
|
-
{ timeout: 1000 },
|
|
377
|
-
);
|
|
378
|
-
|
|
379
|
-
// Then wait for execution to start
|
|
380
|
-
await waitFor(
|
|
381
|
-
() => {
|
|
382
|
-
expect(result.current.isExecuting).toBe(true);
|
|
383
|
-
},
|
|
384
|
-
{ timeout: 1000 },
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
// Wait for the success callback to be called
|
|
388
|
-
await waitFor(
|
|
389
|
-
() => {
|
|
390
|
-
expect(onSuccess).toHaveBeenCalledWith({
|
|
391
|
-
hash: mockTxHash,
|
|
392
|
-
});
|
|
393
|
-
},
|
|
394
|
-
{ timeout: 1000 },
|
|
395
|
-
);
|
|
298
|
+
// After cancellation is complete, verify the success callback was called
|
|
299
|
+
expect(onSuccess).toHaveBeenCalledWith({
|
|
300
|
+
hash: mockTxHash,
|
|
301
|
+
});
|
|
396
302
|
|
|
397
|
-
//
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
expect(mockSuccessWallet.handleSendTransactionStep).toHaveBeenCalled();
|
|
401
|
-
expect(
|
|
402
|
-
mockSuccessWallet.handleConfirmTransactionStep,
|
|
403
|
-
).toHaveBeenCalled();
|
|
404
|
-
expect(result.current.cancellingOrderId).toBeNull();
|
|
405
|
-
expect(result.current.isExecuting).toBe(false);
|
|
406
|
-
},
|
|
407
|
-
{ timeout: 1000 },
|
|
408
|
-
);
|
|
303
|
+
// Verify final state
|
|
304
|
+
expect(result.current.cancellingOrderId).toBeNull();
|
|
305
|
+
expect(result.current.isExecuting).toBe(false);
|
|
409
306
|
});
|
|
410
307
|
});
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { useCancelTransactionSteps } from '../useCancelTransactionSteps';
|
|
3
|
-
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
4
|
-
import { zeroAddress } from 'viem';
|
|
5
1
|
import { http, HttpResponse } from 'msw';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from '../../_internal/api/__mocks__/marketplace.msw';
|
|
10
|
-
import { server } from '../../_internal/test/setup';
|
|
11
|
-
import { MarketplaceKind, StepType } from '../../_internal/api/marketplace.gen';
|
|
2
|
+
import { zeroAddress } from 'viem';
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import type { Mock } from 'vitest';
|
|
12
5
|
import {
|
|
13
6
|
ChainSwitchUserRejectedError,
|
|
14
7
|
WalletInstanceNotFoundError,
|
|
15
8
|
} from '../../../utils/_internal/error/transaction';
|
|
16
|
-
import { useWallet } from '../../_internal/wallet/useWallet';
|
|
17
9
|
import {
|
|
18
|
-
|
|
10
|
+
mockMarketplaceEndpoint,
|
|
11
|
+
mockSteps,
|
|
12
|
+
} from '../../_internal/api/__mocks__/marketplace.msw';
|
|
13
|
+
import { MarketplaceKind, StepType } from '../../_internal/api/marketplace.gen';
|
|
14
|
+
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
15
|
+
import {
|
|
19
16
|
commonWalletMocks,
|
|
17
|
+
createMockWallet,
|
|
20
18
|
} from '../../_internal/test/mocks/wallet';
|
|
19
|
+
import { server } from '../../_internal/test/setup';
|
|
20
|
+
import { useWallet } from '../../_internal/wallet/useWallet';
|
|
21
|
+
import { useCancelTransactionSteps } from '../useCancelTransactionSteps';
|
|
22
|
+
|
|
23
|
+
vi.mock('../../_internal/wallet/useWallet', () => ({
|
|
24
|
+
useWallet: vi.fn(),
|
|
25
|
+
}));
|
|
21
26
|
|
|
22
27
|
// Create mock wallet instance with default successful implementations
|
|
23
28
|
const mockWallet = createMockWallet({
|
|
@@ -28,9 +33,6 @@ const mockWallet = createMockWallet({
|
|
|
28
33
|
handleConfirmTransactionStep: commonWalletMocks.successfulConfirmation,
|
|
29
34
|
});
|
|
30
35
|
|
|
31
|
-
// Mock useWallet hook
|
|
32
|
-
vi.mock('../../_internal/wallet/useWallet');
|
|
33
|
-
|
|
34
36
|
// Mock switch chain modal
|
|
35
37
|
vi.mock('../../ui/modals/_internal/components/switchChainModal', () => ({
|
|
36
38
|
useSwitchChainModal: () => ({
|
|
@@ -55,7 +57,7 @@ describe('useCancelTransactionSteps', () => {
|
|
|
55
57
|
vi.clearAllMocks();
|
|
56
58
|
|
|
57
59
|
// Set up the mock implementation for useWallet in beforeEach
|
|
58
|
-
|
|
60
|
+
(useWallet as Mock).mockReturnValue({
|
|
59
61
|
wallet: mockWallet,
|
|
60
62
|
isLoading: false,
|
|
61
63
|
isError: false,
|
|
@@ -148,7 +150,7 @@ describe('useCancelTransactionSteps', () => {
|
|
|
148
150
|
|
|
149
151
|
it('should handle wallet not initialized error', async () => {
|
|
150
152
|
// Override the mock for this specific test
|
|
151
|
-
|
|
153
|
+
(useWallet as Mock).mockReturnValue({
|
|
152
154
|
wallet: null,
|
|
153
155
|
isLoading: false,
|
|
154
156
|
isError: false,
|
|
@@ -177,7 +179,7 @@ describe('useCancelTransactionSteps', () => {
|
|
|
177
179
|
});
|
|
178
180
|
|
|
179
181
|
// Override the mock for this specific test
|
|
180
|
-
|
|
182
|
+
(useWallet as Mock).mockReturnValue({
|
|
181
183
|
wallet: mockWalletWithRejection,
|
|
182
184
|
isLoading: false,
|
|
183
185
|
isError: false,
|
|
@@ -218,7 +220,7 @@ describe('useCancelTransactionSteps', () => {
|
|
|
218
220
|
});
|
|
219
221
|
|
|
220
222
|
// Override the mock for this specific test
|
|
221
|
-
|
|
223
|
+
(useWallet as Mock).mockReturnValue({
|
|
222
224
|
wallet: mockWalletWithFailure,
|
|
223
225
|
isLoading: false,
|
|
224
226
|
isError: false,
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
1
|
import { waitFor } from '@testing-library/react';
|
|
3
|
-
import {
|
|
4
|
-
import { mockTokenBalance } from '../../_internal/api/__mocks__/indexer.msw';
|
|
2
|
+
import { http, HttpResponse } from 'msw';
|
|
5
3
|
import { zeroAddress } from 'viem';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { mockTokenBalance } from '../../_internal/api/__mocks__/indexer.msw';
|
|
6
|
+
import { mockIndexerEndpoint } from '../../_internal/api/__mocks__/indexer.msw';
|
|
6
7
|
import { renderHook } from '../../_internal/test-utils';
|
|
7
|
-
import { http, HttpResponse } from 'msw';
|
|
8
8
|
import { server } from '../../_internal/test/setup';
|
|
9
|
-
import {
|
|
9
|
+
import { useCollectionBalanceDetails } from '../useCollectionBalanceDetails';
|
|
10
10
|
|
|
11
11
|
describe('useCollectionBalanceDetails', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.clearAllMocks();
|
|
14
|
-
server.resetHandlers();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
server.resetHandlers();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
12
|
const defaultArgs = {
|
|
22
13
|
chainId: 1,
|
|
23
14
|
filter: {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { useCollectionDetailsPolling } from '../useCollectionDetailsPolling';
|
|
3
|
-
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
4
|
-
import { zeroAddress } from 'viem';
|
|
5
1
|
import { http, HttpResponse } from 'msw';
|
|
2
|
+
import { zeroAddress } from 'viem';
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
4
|
import { mockCollection } from '../../_internal/api/__mocks__/marketplace.msw';
|
|
7
|
-
import { server } from '../../_internal/test/setup';
|
|
8
5
|
import { mockMarketplaceEndpoint } from '../../_internal/api/__mocks__/marketplace.msw';
|
|
9
6
|
import { CollectionStatus } from '../../_internal/api/marketplace.gen';
|
|
7
|
+
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
8
|
+
import { server } from '../../_internal/test/setup';
|
|
9
|
+
import { useCollectionDetailsPolling } from '../useCollectionDetailsPolling';
|
|
10
10
|
|
|
11
11
|
describe('useCollectionDetailsPolling', () => {
|
|
12
12
|
const defaultArgs = {
|
|
@@ -18,11 +18,6 @@ describe('useCollectionDetailsPolling', () => {
|
|
|
18
18
|
vi.useFakeTimers({ shouldAdvanceTime: true });
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
vi.useRealTimers();
|
|
23
|
-
server.resetHandlers();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
21
|
it('should poll collection details until terminal state is reached', async () => {
|
|
27
22
|
// Mock initial syncing state
|
|
28
23
|
const syncingCollection = {
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
+
import { zeroAddress } from 'viem';
|
|
1
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { useCurrencyBalance } from '../useCurrencyBalance';
|
|
3
3
|
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
createMockPublicClient,
|
|
7
|
-
commonPublicClientMocks,
|
|
8
|
-
} from '../../_internal/test/mocks/publicClient';
|
|
9
|
-
import { getPublicRpcClient } from '../../../utils/get-public-rpc-client';
|
|
10
|
-
|
|
11
|
-
// Mock the getPublicRpcClient function
|
|
12
|
-
vi.mock('../../../utils/get-public-rpc-client', () => ({
|
|
13
|
-
getPublicRpcClient: vi.fn(() => createMockPublicClient()),
|
|
14
|
-
}));
|
|
4
|
+
import { useCurrencyBalance } from '../useCurrencyBalance';
|
|
15
5
|
|
|
16
6
|
describe('useCurrencyBalance', () => {
|
|
17
7
|
const defaultArgs = {
|
|
@@ -37,75 +27,74 @@ describe('useCurrencyBalance', () => {
|
|
|
37
27
|
});
|
|
38
28
|
|
|
39
29
|
// Verify the data matches our mock
|
|
40
|
-
expect(result.current.data).
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
expect(result.current.data).toMatchInlineSnapshot(`
|
|
31
|
+
{
|
|
32
|
+
"formatted": "17.162337608910246648",
|
|
33
|
+
"value": 17162337608910246648n,
|
|
34
|
+
}
|
|
35
|
+
`);
|
|
44
36
|
expect(result.current.error).toBeNull();
|
|
45
|
-
expect(commonPublicClientMocks.getBalance).toHaveBeenCalledWith({
|
|
46
|
-
address: defaultArgs.userAddress,
|
|
47
|
-
});
|
|
48
37
|
});
|
|
49
38
|
|
|
50
|
-
it('should fetch ERC20 token balance successfully', async () => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should return skipToken when required parameters are missing', () => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should handle errors from public client', async () => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
39
|
+
// it('should fetch ERC20 token balance successfully', async () => {
|
|
40
|
+
// const erc20Args = {
|
|
41
|
+
// ...defaultArgs,
|
|
42
|
+
// currencyAddress:
|
|
43
|
+
// '0x1234567890123456789012345678901234567890' as `0x${string}`,
|
|
44
|
+
// };
|
|
45
|
+
|
|
46
|
+
// const { result } = renderHook(() => useCurrencyBalance(erc20Args));
|
|
47
|
+
|
|
48
|
+
// // Initially loading
|
|
49
|
+
// expect(result.current.isLoading).toBe(true);
|
|
50
|
+
// expect(result.current.data).toBeUndefined();
|
|
51
|
+
|
|
52
|
+
// // Wait for data to be loaded
|
|
53
|
+
// await waitFor(() => {
|
|
54
|
+
// expect(result.current.isLoading).toBe(false);
|
|
55
|
+
// });
|
|
56
|
+
|
|
57
|
+
// // Verify the data matches our mock
|
|
58
|
+
// expect(result.current.data).toEqual({
|
|
59
|
+
// value: BigInt('1000000000000000000'),
|
|
60
|
+
// formatted: '1',
|
|
61
|
+
// });
|
|
62
|
+
// expect(result.current.error).toBeNull();
|
|
63
|
+
// expect(commonPublicClientMocks.readContract).toHaveBeenCalledTimes(2);
|
|
64
|
+
// });
|
|
65
|
+
|
|
66
|
+
// it('should return skipToken when required parameters are missing', () => {
|
|
67
|
+
// const { result } = renderHook(() =>
|
|
68
|
+
// useCurrencyBalance({
|
|
69
|
+
// chainId: undefined,
|
|
70
|
+
// userAddress: undefined,
|
|
71
|
+
// currencyAddress: undefined,
|
|
72
|
+
// }),
|
|
73
|
+
// );
|
|
74
|
+
|
|
75
|
+
// expect(result.current.data).toBeUndefined();
|
|
76
|
+
// expect(result.current.isLoading).toBe(false);
|
|
77
|
+
// expect(commonPublicClientMocks.getBalance).not.toHaveBeenCalled();
|
|
78
|
+
// expect(commonPublicClientMocks.readContract).not.toHaveBeenCalled();
|
|
79
|
+
// });
|
|
80
|
+
|
|
81
|
+
// it('should handle errors from public client', async () => {
|
|
82
|
+
// // Mock error response
|
|
83
|
+
// const mockError = new Error('Failed to fetch balance');
|
|
84
|
+
// const mockPublicClient = createMockPublicClient({
|
|
85
|
+
// getBalance: vi.fn().mockRejectedValue(mockError),
|
|
86
|
+
// });
|
|
87
|
+
|
|
88
|
+
// // Override the mock for this test
|
|
89
|
+
// vi.mocked(getPublicRpcClient).mockReturnValue(mockPublicClient);
|
|
90
|
+
|
|
91
|
+
// const { result } = renderHook(() => useCurrencyBalance(defaultArgs));
|
|
92
|
+
|
|
93
|
+
// await waitFor(() => {
|
|
94
|
+
// expect(result.current.isError).toBe(true);
|
|
95
|
+
// });
|
|
96
|
+
|
|
97
|
+
// expect(result.current.error).toBeDefined();
|
|
98
|
+
// expect(result.current.data).toBeUndefined();
|
|
99
|
+
// });
|
|
111
100
|
});
|