@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,162 @@
1
+ import {
2
+ ResourceStatus,
3
+ type ContractInfo,
4
+ PropertyType,
5
+ } from '@0xsequence/metadata';
6
+ import { http, HttpResponse } from 'msw';
7
+ import type { TokenMetadata, PropertyFilter } from '../marketplace.gen';
8
+ import { zeroAddress } from 'viem';
9
+
10
+ // Debug configuration
11
+ export let isDebugEnabled = false;
12
+ export const enableDebug = () => {
13
+ isDebugEnabled = true;
14
+ };
15
+ export const disableDebug = () => {
16
+ isDebugEnabled = false;
17
+ };
18
+
19
+ // Debug logger function
20
+ const debugLog = (endpoint: string, request: unknown, response: unknown) => {
21
+ if (isDebugEnabled) {
22
+ console.log(`[MSW Debug] ${endpoint}:`, {
23
+ request,
24
+ response,
25
+ });
26
+ }
27
+ };
28
+
29
+ // Mock data
30
+ export const mockContractInfo: ContractInfo = {
31
+ address: zeroAddress,
32
+ chainId: 1,
33
+ name: 'Mock Collection',
34
+ symbol: 'MOCK',
35
+ source: 'https://example.com/source',
36
+ notFound: false,
37
+ status: ResourceStatus.AVAILABLE,
38
+ type: 'ERC721',
39
+ deployed: true,
40
+ updatedAt: new Date().toISOString(),
41
+ bytecodeHash: '0x1234567890',
42
+ extensions: {
43
+ description: 'A mock collection for testing',
44
+ link: 'https://example.com',
45
+ ogImage: 'https://example.com/image.png',
46
+ ogName: 'Mock Collection',
47
+ originAddress: '0x0000000000000000000000000000000000000000',
48
+ originChainId: 1,
49
+ verified: true,
50
+ categories: ['Mock'],
51
+ blacklist: false,
52
+ verifiedBy: '0x',
53
+ featured: true,
54
+ },
55
+ logoURI: 'https://example.com/logo.png',
56
+ };
57
+
58
+ export const mockTokenMetadata: TokenMetadata = {
59
+ tokenId: '1',
60
+ name: 'Mock NFT #1',
61
+ description: 'A mock NFT for testing purposes',
62
+ image: 'https://example.com/nft.png',
63
+ video: 'https://example.com/nft.mp4',
64
+ audio: 'https://example.com/nft.mp3',
65
+ properties: {
66
+ series: 'Mock Series',
67
+ edition: 1,
68
+ },
69
+ attributes: [
70
+ { trait_type: 'Type', value: 'Mock' },
71
+ { trait_type: 'Rarity', value: 'Common' },
72
+ ],
73
+ image_data: 'data:image/svg+xml;base64,...',
74
+ external_url: 'https://example.com/nft/1',
75
+ background_color: '#ffffff',
76
+ animation_url: 'https://example.com/nft/1/animation',
77
+ decimals: 0,
78
+ updatedAt: new Date().toISOString(),
79
+ assets: [
80
+ {
81
+ id: 1,
82
+ collectionId: 1,
83
+ tokenId: '1',
84
+ url: 'https://example.com/nft.png',
85
+ metadataField: 'image',
86
+ name: 'Main Image',
87
+ filesize: 1024,
88
+ mimeType: 'image/png',
89
+ width: 1000,
90
+ height: 1000,
91
+ updatedAt: new Date().toISOString(),
92
+ },
93
+ ],
94
+ };
95
+
96
+ export const mockPropertyFilters: PropertyFilter[] = [
97
+ {
98
+ name: 'Type',
99
+ type: PropertyType.STRING,
100
+ values: ['Mock', 'Test', 'Sample'],
101
+ },
102
+ {
103
+ name: 'Rarity',
104
+ type: PropertyType.STRING,
105
+ values: ['Common', 'Uncommon', 'Rare', 'Epic', 'Legendary'],
106
+ },
107
+ ];
108
+
109
+ // The transformed format that the hook returns when not using showAllFilters
110
+ export const mockFilters = [
111
+ {
112
+ id: 'type',
113
+ name: 'Type',
114
+ values: ['Mock', 'Test', 'Sample'],
115
+ },
116
+ {
117
+ id: 'rarity',
118
+ name: 'Rarity',
119
+ values: ['Common', 'Uncommon', 'Rare', 'Epic', 'Legendary'],
120
+ },
121
+ ];
122
+
123
+ type Endpoint =
124
+ | 'GetContractInfo'
125
+ | 'GetTokenMetadata'
126
+ | 'TokenCollectionFilters'
127
+ | 'GetContractInfoBatch';
128
+
129
+ export const mockMetadataEndpoint = (endpoint: Endpoint) =>
130
+ `*/rpc/Metadata/${endpoint}`;
131
+
132
+ // Add JsonValue type constraint to ensure response is JSON-serializable
133
+ export const mockMetadataHandler = <T extends Record<string, unknown>>(
134
+ endpoint: Endpoint,
135
+ response: T,
136
+ ) => {
137
+ return http.post(mockMetadataEndpoint(endpoint), (request) => {
138
+ debugLog(endpoint, request, response);
139
+ return HttpResponse.json(response);
140
+ });
141
+ };
142
+
143
+ // MSW handlers
144
+ export const handlers = [
145
+ mockMetadataHandler('GetContractInfo', {
146
+ contractInfo: mockContractInfo,
147
+ }),
148
+
149
+ mockMetadataHandler('GetTokenMetadata', {
150
+ tokenMetadata: [mockTokenMetadata],
151
+ }),
152
+
153
+ mockMetadataHandler('TokenCollectionFilters', {
154
+ filters: mockPropertyFilters,
155
+ }),
156
+
157
+ mockMetadataHandler('GetContractInfoBatch', {
158
+ contractInfoMap: {
159
+ [mockContractInfo.address]: mockContractInfo,
160
+ },
161
+ }),
162
+ ];
@@ -0,0 +1,39 @@
1
+ import { vi } from 'vitest';
2
+ import type { PublicClient } from 'viem';
3
+
4
+ export type MockPublicClient = PublicClient;
5
+
6
+ /**
7
+ * Common mock implementations for public client functions
8
+ */
9
+ export const commonPublicClientMocks = {
10
+ getBalance: vi.fn().mockResolvedValue(BigInt('1000000000000000000')), // 1 ETH
11
+ readContract: vi.fn().mockImplementation(async ({ functionName }) => {
12
+ if (functionName === 'balanceOf') {
13
+ return BigInt('1000000000000000000'); // 1 Token
14
+ }
15
+ if (functionName === 'decimals') {
16
+ return 18;
17
+ }
18
+ return BigInt(0);
19
+ }),
20
+ };
21
+
22
+ /**
23
+ * Creates a mock public client with pre-configured mock functions for testing
24
+ * @param overrides - Optional overrides for the default mock implementations
25
+ * @returns A mock public client instance with vitest mock functions
26
+ */
27
+ export function createMockPublicClient(
28
+ overrides?: Partial<MockPublicClient>,
29
+ ): MockPublicClient {
30
+ const defaultMockPublicClient = {
31
+ getBalance: commonPublicClientMocks.getBalance,
32
+ readContract: commonPublicClientMocks.readContract,
33
+ } as unknown as PublicClient;
34
+
35
+ return {
36
+ ...defaultMockPublicClient,
37
+ ...overrides,
38
+ };
39
+ }
@@ -0,0 +1,61 @@
1
+ import { vi } from 'vitest';
2
+ import type { Config } from 'wagmi';
3
+ import type { ReactNode } from 'react';
4
+ import { zeroAddress } from 'viem';
5
+
6
+ export type MockWagmiConfig = Config;
7
+
8
+ /**
9
+ * Common mock implementations for wagmi hooks and functions
10
+ */
11
+ export const commonWagmiMocks = {
12
+ useAccount: vi.fn().mockReturnValue({
13
+ address: zeroAddress,
14
+ isConnecting: false,
15
+ isDisconnected: false,
16
+ isReconnecting: false,
17
+ status: 'connected',
18
+ }),
19
+ createConfig: vi.fn().mockReturnValue({
20
+ chains: [],
21
+ connectors: [],
22
+ transports: {},
23
+ }),
24
+ http: vi.fn().mockReturnValue({}),
25
+ WagmiProvider: vi
26
+ .fn()
27
+ .mockImplementation(({ children }: { children: ReactNode }) => children),
28
+ };
29
+
30
+ /**
31
+ * Creates mock wagmi hooks and functions with pre-configured implementations for testing
32
+ * @param overrides - Optional overrides for the default mock implementations
33
+ * @returns Mock wagmi hooks and functions with vitest mock functions
34
+ */
35
+ export function createMockWagmi(overrides?: Partial<typeof commonWagmiMocks>) {
36
+ return {
37
+ ...commonWagmiMocks,
38
+ ...overrides,
39
+ };
40
+ }
41
+
42
+ /**
43
+ * Mock chain data for testing
44
+ */
45
+ export const mockChains = {
46
+ mainnet: { id: 1, name: 'Ethereum', network: 'mainnet' },
47
+ sepolia: { id: 11155111, name: 'Sepolia', network: 'sepolia' },
48
+ };
49
+
50
+ /**
51
+ * Mock connector data for testing
52
+ */
53
+ export const mockConnectors = {
54
+ mock: () => ({
55
+ accounts: [
56
+ '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
57
+ '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
58
+ '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
59
+ ],
60
+ }),
61
+ };
@@ -0,0 +1,61 @@
1
+ import { vi } from 'vitest';
2
+ import { custom, type Hex } from 'viem';
3
+ import { WalletKind } from '../../api/marketplace.gen';
4
+ import type { WalletInstance } from '../../wallet/wallet';
5
+ import type { TransactionReceipt } from '@0xsequence/indexer';
6
+ import { ChainSwitchUserRejectedError } from '../../../../utils/_internal/error/transaction';
7
+
8
+ export type MockWallet = WalletInstance;
9
+
10
+ /**
11
+ * Creates a mock wallet with pre-configured mock functions for testing
12
+ * @param overrides - Optional overrides for the default mock implementations
13
+ * @returns A mock wallet instance with vitest mock functions
14
+ */
15
+ export function createMockWallet(overrides?: Partial<MockWallet>): MockWallet {
16
+ const defaultMockWallet: MockWallet = {
17
+ getChainId: vi.fn().mockResolvedValue(1),
18
+ switchChain: vi.fn().mockResolvedValue(undefined),
19
+ address: vi
20
+ .fn()
21
+ .mockResolvedValue('0x0000000000000000000000000000000000000000' as Hex),
22
+ handleSendTransactionStep: vi.fn().mockResolvedValue('0x123' as Hex),
23
+ handleSignMessageStep: vi.fn().mockResolvedValue('0xsignature' as Hex),
24
+ handleConfirmTransactionStep: vi
25
+ .fn()
26
+ .mockResolvedValue({} as TransactionReceipt),
27
+ isWaaS: false,
28
+ transport: custom({
29
+ request: vi.fn(),
30
+ }),
31
+ walletKind: WalletKind.unknown,
32
+ hasTokenApproval: vi.fn().mockResolvedValue(true),
33
+ };
34
+
35
+ return {
36
+ ...defaultMockWallet,
37
+ ...overrides,
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Common mock implementations for wallet functions
43
+ * These are the actual mock functions that can be used directly or as overrides
44
+ */
45
+ export const commonWalletMocks = {
46
+ successfulChainId: vi.fn().mockResolvedValue(1),
47
+ successfulAddress: vi
48
+ .fn()
49
+ .mockResolvedValue('0x0000000000000000000000000000000000000000' as Hex),
50
+ successfulTransaction: vi.fn().mockResolvedValue('0x123' as Hex),
51
+ successfulSignature: vi.fn().mockResolvedValue('0xsignature' as Hex),
52
+ successfulConfirmation: vi.fn().mockResolvedValue({} as TransactionReceipt),
53
+ successfulTokenApproval: vi.fn().mockResolvedValue(true),
54
+ chainSwitchRejection: vi
55
+ .fn()
56
+ .mockRejectedValue(new ChainSwitchUserRejectedError()),
57
+ transactionFailure: vi
58
+ .fn()
59
+ .mockRejectedValue(new Error('Transaction failed')),
60
+ signatureFailure: vi.fn().mockRejectedValue(new Error('Signature failed')),
61
+ };
@@ -0,0 +1,28 @@
1
+ import { afterAll, afterEach, beforeAll } from 'vitest';
2
+ import { cleanup } from '@testing-library/react';
3
+ import '@testing-library/jest-dom/vitest';
4
+ import { setupServer } from 'msw/node';
5
+ import { handlers as marketplaceHandlers } from '../api/__mocks__/marketplace.msw';
6
+ import { handlers as metadataHandlers } from '../api/__mocks__/metadata.msw';
7
+ import { handlers as indexerHandlers } from '../api/__mocks__/indexer.msw';
8
+ import { handlers as marketplaceConfigHandlers } from '../../hooks/options/__mocks__/marketplaceConfig.msw';
9
+
10
+ export const server = setupServer(
11
+ ...marketplaceHandlers,
12
+ ...metadataHandlers,
13
+ ...indexerHandlers,
14
+ ...marketplaceConfigHandlers,
15
+ );
16
+
17
+ beforeAll(() => {
18
+ server.listen();
19
+ });
20
+
21
+ afterEach(() => {
22
+ cleanup();
23
+ server.resetHandlers();
24
+ });
25
+
26
+ afterAll(() => {
27
+ server.close();
28
+ });
@@ -1,11 +1,14 @@
1
1
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
2
- import { render as rtlRender } from '@testing-library/react';
2
+ import { renderHook, render as rtlRender } from '@testing-library/react';
3
3
  import type { RenderOptions } from '@testing-library/react';
4
4
  import type { ReactElement } from 'react';
5
- import { createConfig, http, WagmiProvider } from 'wagmi';
5
+ import { type Config, createConfig, http, WagmiProvider } from 'wagmi';
6
6
  import { mainnet, sepolia } from 'wagmi/chains';
7
7
  import { mock } from 'wagmi/connectors';
8
8
 
9
+ // https://github.com/jsdom/jsdom/issues/1695
10
+ window.HTMLElement.prototype.scrollIntoView = () => {};
11
+
9
12
  const createTestQueryClient = () =>
10
13
  new QueryClient({
11
14
  defaultOptions: {
@@ -25,6 +28,10 @@ const config = createConfig({
25
28
  '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
26
29
  '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
27
30
  ],
31
+ // TODO: Enable this once it works, so we won't have to manually connect the wallet in the tests.
32
+ // features: {
33
+ // defaultConnected: true,
34
+ // },
28
35
  }),
29
36
  ],
30
37
  transports: {
@@ -63,6 +70,28 @@ export function renderWithClient(
63
70
  };
64
71
  }
65
72
 
73
+ export function renderHookWithClient<P, R>(
74
+ callback: (props: P) => R,
75
+ options?: Omit<RenderOptions, 'queries'>,
76
+ wagmiConfig?: Config,
77
+ ) {
78
+ const testQueryClient = createTestQueryClient();
79
+
80
+ return renderHook(callback, {
81
+ wrapper: ({ children }) => {
82
+ return (
83
+ <WagmiProvider config={wagmiConfig ?? config}>
84
+ <QueryClientProvider client={testQueryClient}>
85
+ {children}
86
+ </QueryClientProvider>
87
+ </WagmiProvider>
88
+ );
89
+ },
90
+ ...options,
91
+ });
92
+ }
93
+
66
94
  export * from '@testing-library/react';
67
95
 
68
96
  export { renderWithClient as render };
97
+ export { renderHookWithClient as renderHook };
@@ -1,8 +1,13 @@
1
1
  import { describe, it, expect, beforeEach } from 'vitest';
2
2
  import { createWagmiConfig } from '../create-config';
3
3
  import { getWaasConnectors } from '../embedded';
4
- import type { MarketplaceConfig, SdkConfig } from '../../../../types';
5
- import { WalletOptions } from '../../../../types';
4
+ import {
5
+ MarketplaceType,
6
+ MarketplaceWallet,
7
+ OrderbookKind,
8
+ type MarketplaceConfig,
9
+ type SdkConfig,
10
+ } from '../../../../types';
6
11
  import { polygon } from 'viem/chains';
7
12
  import { MissingConfigError } from '../../../../utils/_internal/error/transaction';
8
13
  import { cookieStorage, type Config } from 'wagmi';
@@ -13,25 +18,48 @@ describe('createWagmiConfig', () => {
13
18
 
14
19
  beforeEach(() => {
15
20
  baseMarketplaceConfig = {
16
- projectId: 1,
21
+ cssString: '',
22
+ manifestUrl: '',
17
23
  publisherId: 'test-publisher',
18
24
  title: 'Test Marketplace',
19
25
  shortDescription: 'Test Description',
26
+ socials: {
27
+ twitter: '',
28
+ discord: '',
29
+ website: '',
30
+ tiktok: '',
31
+ instagram: '',
32
+ youtube: '',
33
+ },
20
34
  faviconUrl: 'https://test.com/favicon.ico',
21
35
  landingBannerUrl: 'https://test.com/banner.jpg',
22
- titleTemplate: '%s | Test',
23
- walletOptions: [WalletOptions.Sequence],
36
+ walletOptions: {
37
+ walletType: MarketplaceWallet.UNIVERSAL,
38
+ oidcIssuers: {},
39
+ connectors: [],
40
+ includeEIP6963Wallets: false,
41
+ },
24
42
  collections: [
25
43
  {
26
- collectionAddress: '0x1234567890123456789012345678901234567890',
44
+ address: '0x1234567890123456789012345678901234567890',
27
45
  chainId: polygon.id,
28
- marketplaceFeePercentage: 2.5,
29
- marketplaceType: 'orderbook',
46
+ marketplaceType: MarketplaceType.ORDERBOOK,
47
+ currencyOptions: [],
48
+ destinationMarketplace: OrderbookKind.sequence_marketplace_v2,
49
+ filterSettings: {
50
+ filterOrder: [],
51
+ exclusions: [],
52
+ },
53
+ exchanges: [],
54
+ bannerUrl: '',
55
+ feePercentage: 0,
30
56
  },
31
57
  ],
32
58
  landingPageLayout: 'default',
33
- cssString: '',
34
- manifestUrl: 'https://test.com/manifest.json',
59
+ logoUrl: '',
60
+ bannerUrl: '',
61
+ fontUrl: '',
62
+ ogImage: '',
35
63
  };
36
64
 
37
65
  baseSdkConfig = {
@@ -59,10 +87,11 @@ describe('createWagmiConfig', () => {
59
87
  it('should create config with universal wallet setup', () => {
60
88
  const marketplaceConfig: MarketplaceConfig = {
61
89
  ...baseMarketplaceConfig,
62
- walletOptionsNew: {
90
+ walletOptions: {
63
91
  connectors: ['walletconnect', 'coinbase'],
64
92
  includeEIP6963Wallets: true,
65
- walletType: 'universal',
93
+ walletType: MarketplaceWallet.UNIVERSAL,
94
+ oidcIssuers: {},
66
95
  },
67
96
  };
68
97
 
@@ -81,10 +110,11 @@ describe('createWagmiConfig', () => {
81
110
  it('should create config with embedded wallet setup', () => {
82
111
  const marketplaceConfig: MarketplaceConfig = {
83
112
  ...baseMarketplaceConfig,
84
- walletOptionsNew: {
113
+ walletOptions: {
85
114
  connectors: ['walletconnect'],
86
115
  includeEIP6963Wallets: false,
87
- walletType: 'embedded',
116
+ walletType: MarketplaceWallet.EMBEDDED,
117
+ oidcIssuers: {},
88
118
  },
89
119
  };
90
120
 
@@ -109,10 +139,11 @@ describe('createWagmiConfig', () => {
109
139
  it('should respect EIP6963 wallet inclusion setting', () => {
110
140
  const marketplaceConfig: MarketplaceConfig = {
111
141
  ...baseMarketplaceConfig,
112
- walletOptionsNew: {
142
+ walletOptions: {
113
143
  connectors: ['walletconnect'],
114
144
  includeEIP6963Wallets: false,
115
- walletType: 'universal',
145
+ walletType: MarketplaceWallet.UNIVERSAL,
146
+ oidcIssuers: {},
116
147
  },
117
148
  };
118
149
 
@@ -145,10 +176,11 @@ describe('createWagmiConfig', () => {
145
176
  it('should throw error when trying to use embedded wallet without waasConfigKey', () => {
146
177
  const marketplaceConfig: MarketplaceConfig = {
147
178
  ...baseMarketplaceConfig,
148
- walletOptionsNew: {
179
+ walletOptions: {
149
180
  connectors: ['walletconnect'],
150
181
  includeEIP6963Wallets: false,
151
- walletType: 'embedded',
182
+ walletType: MarketplaceWallet.EMBEDDED,
183
+ oidcIssuers: {},
152
184
  },
153
185
  };
154
186
 
@@ -181,10 +213,11 @@ describe('createWagmiConfig', () => {
181
213
  it('should still create config when walletConnectProjectId is missing', () => {
182
214
  const marketplaceConfig: MarketplaceConfig = {
183
215
  ...baseMarketplaceConfig,
184
- walletOptionsNew: {
216
+ walletOptions: {
185
217
  connectors: ['walletconnect'],
186
218
  includeEIP6963Wallets: true,
187
- walletType: 'universal',
219
+ walletType: MarketplaceWallet.UNIVERSAL,
220
+ oidcIssuers: {},
188
221
  },
189
222
  };
190
223
 
@@ -24,15 +24,14 @@ export const createWagmiConfig = (
24
24
  ? getUniversalConnectors(marketplaceConfig, sdkConfig)
25
25
  : getWaasConnectors(marketplaceConfig, sdkConfig);
26
26
 
27
- // The old config did not support disabling EIP-6963 wallets
28
- const includeEIP6963Wallets =
29
- marketplaceConfig.walletOptionsNew?.includeEIP6963Wallets ?? true;
27
+ const multiInjectedProviderDiscovery =
28
+ marketplaceConfig.walletOptions.includeEIP6963Wallets;
30
29
 
31
30
  return createConfig({
32
31
  connectors,
33
32
  chains,
34
33
  ssr,
35
- multiInjectedProviderDiscovery: includeEIP6963Wallets,
34
+ multiInjectedProviderDiscovery,
36
35
  storage: ssr
37
36
  ? createStorage({
38
37
  storage: cookieStorage,
@@ -28,10 +28,7 @@ export function getWaasConnectors(
28
28
 
29
29
  const { title: appName } = marketplaceConfig;
30
30
 
31
- // Normalizing the wallet options, TODO: remove this after the marketplaceConfig is updated
32
- const walletOptions = marketplaceConfig.walletOptionsNew || {
33
- connectors: ['coinbase', 'walletconnect'],
34
- };
31
+ const walletOptions = marketplaceConfig.walletOptions;
35
32
 
36
33
  const wallets: Wallet[] = [
37
34
  emailWaas({
@@ -48,10 +48,7 @@ function getWalletConfigs(
48
48
  ): Wallet[] {
49
49
  const wallets: Wallet[] = [];
50
50
 
51
- // Normalizing the wallet options, TODO: remove this after the marketplaceConfig is updated
52
- const walletOptions = marketplaceConfig.walletOptionsNew || {
53
- connectors: ['coinbase', 'walletconnect'],
54
- };
51
+ const walletOptions = marketplaceConfig.walletOptions;
55
52
 
56
53
  wallets.push(sequence(sequenceWalletOptions));
57
54
 
@@ -130,6 +130,7 @@ export const wallet = ({
130
130
  });
131
131
  return await wallet.signTypedData({
132
132
  account: wallet.account,
133
+ // biome-ignore lint/style/noNonNullAssertion: <explanation>
133
134
  domain: stepItem.signature!.domain as TypedDataDomain,
134
135
  // biome-ignore lint/style/noNonNullAssertion: <explanation>
135
136
  types: stepItem.signature!.types,