@0xsequence/marketplace-sdk 0.7.0 → 0.8.1

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 (227) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +11 -0
  3. package/.changeset/seven-doors-taste.md +5 -0
  4. package/CHANGELOG.md +13 -0
  5. package/dist/{chunk-MPBN3E54.js → chunk-2VHHJNXY.js} +3 -3
  6. package/dist/{chunk-FBUMNJQ4.js → chunk-3II5GLHE.js} +2 -2
  7. package/dist/chunk-3JU7SQVE.js +182 -0
  8. package/dist/chunk-3JU7SQVE.js.map +1 -0
  9. package/dist/{chunk-XTGMMNV5.js → chunk-A5ACY5YV.js} +2 -2
  10. package/dist/chunk-ABSYNRT5.js +128 -0
  11. package/dist/chunk-ABSYNRT5.js.map +1 -0
  12. package/dist/{chunk-XNA64MZQ.js → chunk-BCO4CYE4.js} +2 -2
  13. package/dist/{chunk-HTFORA4Q.js → chunk-BN36GABQ.js} +1883 -1010
  14. package/dist/chunk-BN36GABQ.js.map +1 -0
  15. package/dist/{chunk-4XK7XNJ7.js → chunk-BNAUZXPV.js} +73 -2
  16. package/dist/chunk-BNAUZXPV.js.map +1 -0
  17. package/dist/{chunk-Q5URKSC4.js → chunk-FMEEJFAF.js} +1 -1
  18. package/dist/{chunk-BBASZVT3.js → chunk-GBQVYNCD.js} +5 -6
  19. package/dist/chunk-GBQVYNCD.js.map +1 -0
  20. package/dist/{chunk-3AKOPSON.js → chunk-IZ44XPBH.js} +2 -9
  21. package/dist/chunk-IZ44XPBH.js.map +1 -0
  22. package/dist/{chunk-EAJ5K7QV.js → chunk-Q5RKAMYF.js} +3 -4
  23. package/dist/chunk-Q5RKAMYF.js.map +1 -0
  24. package/dist/{chunk-RBEPPVLT.js → chunk-X3QNSQER.js} +145 -355
  25. package/dist/chunk-X3QNSQER.js.map +1 -0
  26. package/dist/{index-CzTANLaA.d.ts → index-CnaFSNE9.d.ts} +6 -7
  27. package/dist/index.css +113 -31
  28. package/dist/index.css.map +1 -1
  29. package/dist/index.d.ts +2 -4
  30. package/dist/index.js +4 -4
  31. package/dist/listCollectibles-B0tbqnRd.d.ts +155 -0
  32. package/dist/react/_internal/api/index.d.ts +28 -2
  33. package/dist/react/_internal/api/index.js +3 -1
  34. package/dist/react/_internal/databeat/index.js +10 -9
  35. package/dist/react/_internal/index.d.ts +2 -3
  36. package/dist/react/_internal/index.js +4 -4
  37. package/dist/react/_internal/wagmi/index.js +2 -2
  38. package/dist/react/hooks/index.d.ts +259 -674
  39. package/dist/react/hooks/index.js +11 -20
  40. package/dist/react/hooks/options/index.d.ts +1 -2
  41. package/dist/react/hooks/options/index.js +4 -4
  42. package/dist/react/index.d.ts +7 -7
  43. package/dist/react/index.js +15 -24
  44. package/dist/react/queries/index.d.ts +25 -0
  45. package/dist/react/queries/index.js +48 -0
  46. package/dist/react/queries/index.js.map +1 -0
  47. package/dist/react/ssr/index.js +3 -3
  48. package/dist/react/ui/components/collectible-card/index.d.ts +1 -6
  49. package/dist/react/ui/components/collectible-card/index.js +13 -12
  50. package/dist/react/ui/components/marketplace-logos/index.js +1 -1
  51. package/dist/react/ui/icons/index.js +6 -6
  52. package/dist/react/ui/index.d.ts +18 -22
  53. package/dist/react/ui/index.js +13 -12
  54. package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +6 -11
  55. package/dist/react/ui/modals/_internal/components/actionModal/index.js +10 -9
  56. package/dist/types/index.js +2 -2
  57. package/dist/{types-Ct1uCT3M.d.ts → types-o_pKUpQG.d.ts} +2 -5
  58. package/dist/utils/index.d.ts +1 -5
  59. package/dist/utils/index.js +4 -4
  60. package/package.json +22 -16
  61. package/src/react/_internal/api/__mocks__/indexer.msw.ts +3 -1
  62. package/src/react/_internal/api/__mocks__/marketplace.msw.ts +1 -1
  63. package/src/react/_internal/api/__mocks__/metadata.msw.ts +14 -12
  64. package/src/react/_internal/api/index.ts +1 -0
  65. package/src/react/_internal/api/laos-api.ts +103 -0
  66. package/src/react/_internal/api/zod-schema.ts +3 -3
  67. package/src/react/_internal/types.ts +1 -10
  68. package/src/react/_internal/wallet/__tests__/wallet.test.ts +43 -0
  69. package/src/react/_internal/wallet/useWallet.ts +6 -3
  70. package/src/react/hooks/__tests__/useAutoSelectFeeOption.test.tsx +1 -1
  71. package/src/react/hooks/__tests__/useCancelOrder.test.tsx +1 -1
  72. package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +1 -1
  73. package/src/react/hooks/__tests__/useCollectible.test.tsx +2 -2
  74. package/src/react/hooks/__tests__/useCollection.test.tsx +2 -2
  75. package/src/react/hooks/__tests__/useComparePrices.test.tsx +1 -1
  76. package/src/react/hooks/__tests__/useConvertPriceToUSD.test.tsx +1 -1
  77. package/src/react/hooks/__tests__/useCountListingsForCollectible.test.tsx +1 -1
  78. package/src/react/hooks/__tests__/useCountOfCollectables.test.tsx +2 -2
  79. package/src/react/hooks/__tests__/useCountOffersForCollectible.test.tsx +1 -1
  80. package/src/react/hooks/__tests__/useCurrencies.test.tsx +2 -2
  81. package/src/react/hooks/__tests__/useCurrency.test.tsx +2 -2
  82. package/src/react/hooks/__tests__/useFilters.test.tsx +2 -2
  83. package/src/react/hooks/__tests__/useFloorOrder.test.tsx +2 -2
  84. package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +1 -1
  85. package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +1 -1
  86. package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +1 -1
  87. package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +1 -1
  88. package/src/react/hooks/__tests__/useListCollectibleActivities.test.tsx +2 -2
  89. package/src/react/hooks/__tests__/useListCollectibles.test.tsx +3 -2
  90. package/src/react/hooks/__tests__/useListCollectiblesPaginated.test.tsx +1 -1
  91. package/src/react/hooks/__tests__/useListCollectionActivities.test.tsx +1 -1
  92. package/src/react/hooks/__tests__/useListListingsForCollectible.test.tsx +1 -1
  93. package/src/react/hooks/__tests__/useListOffersForCollectible.test.tsx +1 -1
  94. package/src/react/hooks/__tests__/useLowestListing.test.tsx +1 -1
  95. package/src/react/hooks/__tests__/useRoyalty.test.tsx +1 -2
  96. package/src/react/hooks/index.ts +0 -1
  97. package/src/react/hooks/options/collectionOptions.ts +2 -3
  98. package/src/react/hooks/useAutoSelectFeeOption.tsx +1 -1
  99. package/src/react/hooks/useCancelOrder.tsx +3 -3
  100. package/src/react/hooks/useCancelTransactionSteps.tsx +1 -1
  101. package/src/react/hooks/useCheckoutOptions.tsx +1 -2
  102. package/src/react/hooks/useCollectible.tsx +2 -3
  103. package/src/react/hooks/useCollectionBalanceDetails.tsx +1 -2
  104. package/src/react/hooks/useComparePrices.tsx +2 -9
  105. package/src/react/hooks/useConvertPriceToUSD.tsx +1 -4
  106. package/src/react/hooks/useCountListingsForCollectible.tsx +1 -2
  107. package/src/react/hooks/useCountOfCollectables.tsx +1 -2
  108. package/src/react/hooks/useCountOffersForCollectible.tsx +1 -2
  109. package/src/react/hooks/useCurrencies.tsx +1 -4
  110. package/src/react/hooks/useCurrency.tsx +3 -8
  111. package/src/react/hooks/useFilters.tsx +5 -4
  112. package/src/react/hooks/useFloorOrder.tsx +1 -2
  113. package/src/react/hooks/useGenerateCancelTransaction.tsx +3 -6
  114. package/src/react/hooks/useGenerateListingTransaction.tsx +2 -3
  115. package/src/react/hooks/useGenerateOfferTransaction.tsx +2 -3
  116. package/src/react/hooks/useGenerateSellTransaction.tsx +3 -6
  117. package/src/react/hooks/useHighestOffer.tsx +1 -1
  118. package/src/react/hooks/useListCollectibles.tsx +33 -61
  119. package/src/react/hooks/useListCollectiblesPaginated.tsx +2 -6
  120. package/src/react/hooks/useListListingsForCollectible.tsx +1 -2
  121. package/src/react/hooks/useListOffersForCollectible.tsx +1 -2
  122. package/src/react/hooks/useLowestListing.tsx +1 -2
  123. package/src/react/hooks/useRoyalty.tsx +3 -8
  124. package/src/react/hooks/useTransferTokens.tsx +2 -2
  125. package/src/react/queries/balanceOfCollectible.ts +9 -32
  126. package/src/react/queries/getTokenSupplies.ts +38 -0
  127. package/src/react/queries/index.ts +5 -0
  128. package/src/react/queries/listCollectibles.ts +96 -0
  129. package/src/react/ui/components/_internals/action-button/ActionButton.tsx +1 -1
  130. package/src/react/ui/components/_internals/action-button/__tests__/ActionButton.test.tsx +1 -1
  131. package/src/react/ui/components/_internals/action-button/components/NonOwnerActions.tsx +4 -3
  132. package/src/react/ui/components/_internals/action-button/components/OwnerActions.tsx +1 -1
  133. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +2 -3
  134. package/src/react/ui/components/collectible-card/__tests__/CollectibleCard.test.tsx +1 -1
  135. package/src/react/ui/modals/BuyModal/ERC1155QuantityModal.tsx +127 -0
  136. package/src/react/ui/modals/BuyModal/Modal.tsx +70 -85
  137. package/src/react/ui/modals/BuyModal/__tests__/Modal.test.tsx +85 -226
  138. package/src/react/ui/modals/BuyModal/__tests__/Modal1155.test.tsx +140 -0
  139. package/src/react/ui/modals/BuyModal/__tests__/store.test.ts +67 -76
  140. package/src/react/ui/modals/BuyModal/hooks/__tests__/useCheckoutOptions.test.tsx +1 -60
  141. package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +1 -1
  142. package/src/react/ui/modals/BuyModal/hooks/useCheckoutOptions.ts +29 -13
  143. package/src/react/ui/modals/BuyModal/hooks/useLoadData.ts +26 -21
  144. package/src/react/ui/modals/BuyModal/hooks/usePaymentModalParams.ts +200 -0
  145. package/src/react/ui/modals/BuyModal/index.tsx +4 -14
  146. package/src/react/ui/modals/BuyModal/store.ts +71 -76
  147. package/src/react/ui/modals/CreateListingModal/Modal.tsx +71 -7
  148. package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +2 -2
  149. package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +1 -1
  150. package/src/react/ui/modals/CreateListingModal/hooks/useGetTokenApproval.ts +1 -1
  151. package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +9 -5
  152. package/src/react/ui/modals/CreateListingModal/store.ts +7 -2
  153. package/src/react/ui/modals/MakeOfferModal/Modal.tsx +103 -6
  154. package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +1 -1
  155. package/src/react/ui/modals/MakeOfferModal/hooks/useGetTokenApproval.tsx +1 -1
  156. package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +1 -1
  157. package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +8 -4
  158. package/src/react/ui/modals/MakeOfferModal/store.ts +5 -3
  159. package/src/react/ui/modals/SellModal/Modal.tsx +76 -4
  160. package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +1 -1
  161. package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +1 -1
  162. package/src/react/ui/modals/SellModal/hooks/useSell.tsx +1 -1
  163. package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +16 -8
  164. package/src/react/ui/modals/SellModal/store.ts +5 -3
  165. package/src/react/ui/modals/TransferModal/_store.ts +15 -3
  166. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TokenQuantityInput.tsx +58 -0
  167. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TransferButton.tsx +56 -0
  168. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/WalletAddressInput.tsx +50 -0
  169. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +94 -66
  170. package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +22 -14
  171. package/src/react/ui/modals/TransferModal/index.tsx +72 -38
  172. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +43 -42
  173. package/src/react/ui/modals/_internal/components/actionModal/store.ts +1 -2
  174. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +2 -2
  175. package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +9 -1
  176. package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +27 -12
  177. package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +1 -1
  178. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +19 -3
  179. package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +3 -0
  180. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/_components/ActionButtons.tsx +60 -0
  181. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/_components/BalanceIndicator.tsx +30 -0
  182. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/index.tsx +126 -0
  183. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/store.ts +25 -0
  184. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/useWaasFeeOptionManager.tsx +74 -0
  185. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +1 -2
  186. package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +1 -2
  187. package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +1 -1
  188. package/src/react/ui/modals/_internal/components/transaction-footer/index.tsx +4 -7
  189. package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +1 -1
  190. package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +1 -1
  191. package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +1 -1
  192. package/src/react/ui/modals/_internal/components/transactionStatusModal/hooks/useTransactionStatus.ts +1 -1
  193. package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +6 -1
  194. package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +2 -2
  195. package/src/react/ui/modals/_internal/components/waasFeeOptionsSelect/WaasFeeOptionsSelect.tsx +10 -31
  196. package/src/react/ui/modals/_internal/hooks/useSelectWaasFeeOptions.ts +53 -0
  197. package/src/react/ui/modals/_internal/types.ts +2 -1
  198. package/src/types/waas-types.ts +38 -0
  199. package/src/utils/network.ts +2 -4
  200. package/test/const.ts +1 -1
  201. package/test/setup.ts +10 -0
  202. package/test/test-utils.tsx +31 -5
  203. package/tsconfig.tsbuildinfo +1 -1
  204. package/dist/chunk-3AKOPSON.js.map +0 -1
  205. package/dist/chunk-4XK7XNJ7.js.map +0 -1
  206. package/dist/chunk-BBASZVT3.js.map +0 -1
  207. package/dist/chunk-EAJ5K7QV.js.map +0 -1
  208. package/dist/chunk-HTFORA4Q.js.map +0 -1
  209. package/dist/chunk-OFY7OFTL.js +0 -458
  210. package/dist/chunk-OFY7OFTL.js.map +0 -1
  211. package/dist/chunk-RBEPPVLT.js.map +0 -1
  212. package/src/react/hooks/__tests__/useGenerateBuyTransaction.test.tsx +0 -172
  213. package/src/react/hooks/useGenerateBuyTransaction.tsx +0 -80
  214. package/src/react/ui/modals/BuyModal/hooks/__tests__/useBuyCollectable.test.tsx +0 -349
  215. package/src/react/ui/modals/BuyModal/hooks/__tests__/useLoadData.test.tsx +0 -185
  216. package/src/react/ui/modals/BuyModal/hooks/useBuyCollectable.ts +0 -170
  217. package/src/react/ui/modals/BuyModal/modals/CheckoutModal.tsx +0 -47
  218. package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +0 -140
  219. package/src/react/ui/modals/BuyModal/modals/__tests__/CheckoutModal.test.tsx +0 -162
  220. package/src/react/ui/modals/BuyModal/modals/__tests__/Modal1155.test.tsx +0 -327
  221. package/src/react/ui/modals/_internal/components/waasFeeOptionsBox/index.tsx +0 -124
  222. package/src/react/ui/modals/_internal/components/waasFeeOptionsBox/store.ts +0 -12
  223. /package/dist/{chunk-MPBN3E54.js.map → chunk-2VHHJNXY.js.map} +0 -0
  224. /package/dist/{chunk-FBUMNJQ4.js.map → chunk-3II5GLHE.js.map} +0 -0
  225. /package/dist/{chunk-XTGMMNV5.js.map → chunk-A5ACY5YV.js.map} +0 -0
  226. /package/dist/{chunk-XNA64MZQ.js.map → chunk-BCO4CYE4.js.map} +0 -0
  227. /package/dist/{chunk-Q5URKSC4.js.map → chunk-FMEEJFAF.js.map} +0 -0
@@ -0,0 +1,140 @@
1
+ import { act, fireEvent, render, screen } from '@test';
2
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
3
+ import type { Order } from '../../../../_internal';
4
+ import { MarketplaceKind, OrderSide, OrderStatus } from '../../../../_internal';
5
+ import { ERC1155QuantityModal } from '../ERC1155QuantityModal';
6
+ import { buyModalStore } from '../store';
7
+
8
+ const testOrder: Order = {
9
+ chainId: 1,
10
+ orderId: '1',
11
+ collectionContractAddress: '0x123',
12
+ createdAt: '2023-01-01T00:00:00Z',
13
+ createdBy: '0x123',
14
+ feeBps: 250,
15
+ feeBreakdown: [],
16
+ marketplace: MarketplaceKind.sequence_marketplace_v2,
17
+ priceAmount: '1000000000000000000',
18
+ priceAmountFormatted: '1',
19
+ priceAmountNet: '975000000000000000',
20
+ side: OrderSide.listing,
21
+ status: OrderStatus.active,
22
+ originName: '',
23
+ priceAmountNetFormatted: '',
24
+ priceCurrencyAddress: '',
25
+ priceDecimals: 0,
26
+ priceUSD: 0,
27
+ priceUSDFormatted: '',
28
+ quantityInitial: '10',
29
+ quantityInitialFormatted: '10',
30
+ quantityRemaining: '10',
31
+ quantityRemainingFormatted: '10',
32
+ quantityAvailable: '10',
33
+ quantityAvailableFormatted: '10',
34
+ quantityDecimals: 0,
35
+ validFrom: '',
36
+ validUntil: '',
37
+ blockNumber: 0,
38
+ updatedAt: '',
39
+ };
40
+
41
+ describe('ERC1155QuantityModal', () => {
42
+ beforeEach(() => {
43
+ // Initialize the store before each test
44
+ buyModalStore.send({
45
+ type: 'open',
46
+ props: {
47
+ chainId: 1,
48
+ orderId: '1',
49
+ collectionAddress: '0x123' as `0x${string}`,
50
+ collectibleId: '1',
51
+ marketplace: MarketplaceKind.sequence_marketplace_v2,
52
+ },
53
+ });
54
+ });
55
+
56
+ afterEach(() => {
57
+ // Reset the store after each test
58
+ buyModalStore.send({ type: 'close' });
59
+ });
60
+
61
+ it('should render quantity modal with order details', async () => {
62
+ render(<ERC1155QuantityModal order={testOrder} />);
63
+
64
+ // Check if the modal renders with the correct title
65
+ expect(screen.getByText('Select Quantity')).toBeInTheDocument();
66
+
67
+ // Check if the Buy now button exists
68
+ const buyButton = await screen.findByRole('button', { name: /buy now/i });
69
+ expect(buyButton).toBeInTheDocument();
70
+ // Capture the initial store state
71
+ const initialState = buyModalStore.getSnapshot();
72
+ expect(initialState.context.quantity).toBeUndefined();
73
+
74
+ // Click the Buy now button with default quantity "1"
75
+ await act(async () => {
76
+ fireEvent.click(buyButton);
77
+ });
78
+
79
+ // Ensure the store context was updated with the correct quantity
80
+ const updatedState = buyModalStore.getSnapshot();
81
+ expect(updatedState.context.quantity).toBe(1);
82
+ });
83
+
84
+ it('should update quantity when user changes the input value', async () => {
85
+ render(<ERC1155QuantityModal order={testOrder} />);
86
+
87
+ // Find the quantity input using label text
88
+ const quantityInput = await screen.findByLabelText('Enter quantity');
89
+
90
+ // Capture initial store state
91
+ const initialState = buyModalStore.getSnapshot();
92
+ expect(initialState.context.quantity).toBeUndefined();
93
+
94
+ // Change quantity to 5
95
+ await act(async () => {
96
+ fireEvent.change(quantityInput, { target: { value: '5' } });
97
+ });
98
+
99
+ // Click Buy now button
100
+ const buyButton = screen.getByRole('button', { name: /buy now/i });
101
+ await act(async () => {
102
+ fireEvent.click(buyButton);
103
+ });
104
+
105
+ // Check that the store is updated with quantity = 5
106
+ const updatedState = buyModalStore.getSnapshot();
107
+ expect(updatedState.context.quantity).toBe(5);
108
+ });
109
+
110
+ it('should validate input quantity against available quantity', async () => {
111
+ render(<ERC1155QuantityModal order={testOrder} />);
112
+
113
+ const quantityInput = await screen.findByLabelText('Enter quantity');
114
+
115
+ const invalidQuantity = '';
116
+ await act(async () => {
117
+ fireEvent.change(quantityInput, { target: { value: invalidQuantity } });
118
+ });
119
+
120
+ const buyButton = await screen.findByRole('button', { name: /buy now/i });
121
+ // The button should be disabled due to invalid quantity
122
+ expect(buyButton).toBeDisabled();
123
+
124
+ // Set valid quantity
125
+ await act(async () => {
126
+ fireEvent.change(quantityInput, { target: { value: '10' } });
127
+ });
128
+
129
+ // Button should be enabled
130
+ expect(buyButton).not.toBeDisabled();
131
+
132
+ // Click the button and check store update
133
+ await act(async () => {
134
+ fireEvent.click(buyButton);
135
+ });
136
+
137
+ const updatedState = buyModalStore.getSnapshot();
138
+ expect(updatedState.context.quantity).toBe(10);
139
+ });
140
+ });
@@ -1,103 +1,94 @@
1
1
  import { beforeEach, describe, expect, it } from 'vitest';
2
- import type { Order } from '../../../../_internal';
3
- import { buyModal$, initialState } from '../store';
2
+ import { MarketplaceKind } from '../../../../_internal';
3
+ import { buyModalStore } from '../store';
4
4
 
5
5
  describe('BuyModal Store', () => {
6
6
  beforeEach(() => {
7
- buyModal$.set(initialState);
7
+ buyModalStore.send({ type: 'close' });
8
8
  });
9
9
 
10
10
  it('should initialize with correct default state', () => {
11
- expect(buyModal$.isOpen.get()).toBe(false);
12
- expect(buyModal$.state.get()).toEqual({
13
- order: undefined as unknown as Order,
14
- quantity: '1',
15
- invalidQuantity: false,
16
- checkoutModalIsLoading: false,
17
- checkoutModalLoaded: false,
18
- purchaseProcessing: false,
19
- customProviderCallback: null,
20
- });
21
- expect(buyModal$.callbacks.get()).toBeUndefined();
11
+ const state = buyModalStore.getSnapshot();
12
+ expect(state.context.isOpen).toBe(false);
13
+ expect(state.context.props).toBeDefined();
14
+ expect(state.context.quantity).toBeUndefined();
22
15
  });
23
16
 
24
17
  it('should handle open action correctly', () => {
25
- const mockOrder: Order = {
26
- quantityAvailableFormatted: '10',
27
- } as Order;
18
+ const mockProps = {
19
+ orderId: '1',
20
+ chainId: 1,
21
+ collectionAddress: '0x123' as `0x${string}`,
22
+ collectibleId: '1',
23
+ marketplace: MarketplaceKind.sequence_marketplace_v2,
24
+ };
28
25
 
29
- const mockCallbacks = {
26
+ buyModalStore.send({
27
+ type: 'open',
28
+ props: mockProps,
30
29
  onSuccess: () => {},
31
30
  onError: () => {},
32
- };
33
-
34
- buyModal$.open({
35
- order: mockOrder,
36
- chainId: '1',
37
- collectionAddress: '0x123',
38
- tokenId: '123',
39
- callbacks: mockCallbacks,
40
31
  });
41
32
 
42
- expect(buyModal$.isOpen.get()).toBe(true);
43
- expect(buyModal$.state.get()).toEqual({
44
- order: mockOrder,
45
- quantity: '10',
46
- invalidQuantity: false,
47
- checkoutModalIsLoading: false,
48
- checkoutModalLoaded: false,
49
- purchaseProcessing: false,
50
- });
51
- expect(buyModal$.callbacks.get()).toBe(mockCallbacks);
33
+ const state = buyModalStore.getSnapshot();
34
+ expect(state.context.isOpen).toBe(true);
35
+ expect(state.context.props).toEqual(mockProps);
52
36
  });
53
37
 
54
38
  it('should handle close action correctly', () => {
55
- const mockOrder: Order = {
56
- quantityAvailableFormatted: '10',
57
- } as Order;
58
-
59
- buyModal$.open({
60
- order: mockOrder,
61
- chainId: '1',
62
- collectionAddress: '0x123',
63
- tokenId: '123',
64
- callbacks: {
65
- onSuccess: () => {},
66
- onError: () => {},
67
- },
39
+ const mockProps = {
40
+ orderId: '1',
41
+ chainId: 1,
42
+ collectionAddress: '0x123' as `0x${string}`,
43
+ collectibleId: '1',
44
+ marketplace: MarketplaceKind.sequence_marketplace_v2,
45
+ };
46
+
47
+ buyModalStore.send({
48
+ type: 'open',
49
+ props: mockProps,
50
+ onSuccess: () => {},
51
+ onError: () => {},
68
52
  });
69
53
 
70
- expect(buyModal$.isOpen.get()).toBe(true);
71
-
72
- buyModal$.close();
73
-
74
- expect(buyModal$.isOpen.get()).toBe(false);
75
- expect(buyModal$.state.get().quantity).toBe('1');
76
- expect(buyModal$.state.get().invalidQuantity).toBe(false);
77
- expect(buyModal$.state.get().checkoutModalIsLoading).toBe(false);
78
- expect(buyModal$.state.get().checkoutModalLoaded).toBe(false);
79
- expect(buyModal$.callbacks.get()).toBeUndefined();
80
- expect(buyModal$.state.order.get()).toBeUndefined();
81
- expect(
82
- buyModal$.state.order.collectionContractAddress.get(),
83
- ).toBeUndefined();
84
- expect(buyModal$.state.order.tokenId.get()).toBeUndefined();
85
- expect(buyModal$.state.order.chainId.get()).toBeUndefined();
86
- expect(
87
- buyModal$.state.order.quantityAvailableFormatted.get(),
88
- ).toBeUndefined();
54
+ const openState = buyModalStore.getSnapshot();
55
+ expect(openState.context.isOpen).toBe(true);
56
+
57
+ buyModalStore.send({ type: 'close' });
58
+
59
+ const closedState = buyModalStore.getSnapshot();
60
+ expect(closedState.context.isOpen).toBe(false);
89
61
  });
90
62
 
91
63
  it('should update loading states correctly', () => {
92
- buyModal$.state.checkoutModalIsLoading.set(true);
93
- expect(buyModal$.state.checkoutModalIsLoading.get()).toBe(true);
64
+ const mockProps = {
65
+ orderId: '1',
66
+ chainId: 1,
67
+ collectionAddress: '0x123' as `0x${string}`,
68
+ collectibleId: '1',
69
+ marketplace: MarketplaceKind.sequence_marketplace_v2,
70
+ };
71
+
72
+ buyModalStore.send({
73
+ type: 'open',
74
+ props: mockProps,
75
+ });
76
+
77
+ const state1 = buyModalStore.getSnapshot();
78
+ expect(state1.context.quantity).toBeUndefined();
79
+
80
+ buyModalStore.send({
81
+ type: 'setQuantity',
82
+ quantity: 5,
83
+ });
84
+
85
+ const state2 = buyModalStore.getSnapshot();
86
+ expect(state2.context.quantity).toBe(5);
94
87
 
95
- buyModal$.state.checkoutModalLoaded.set(true);
96
- expect(buyModal$.state.checkoutModalLoaded.get()).toBe(true);
88
+ // Test resetting by closing
89
+ buyModalStore.send({ type: 'close' });
97
90
 
98
- buyModal$.state.checkoutModalIsLoading.set(false);
99
- buyModal$.state.checkoutModalLoaded.set(false);
100
- expect(buyModal$.state.checkoutModalIsLoading.get()).toBe(false);
101
- expect(buyModal$.state.checkoutModalLoaded.get()).toBe(false);
91
+ const state3 = buyModalStore.getSnapshot();
92
+ expect(state3.context.quantity).toBeUndefined();
102
93
  });
103
94
  });
@@ -1,4 +1,4 @@
1
- import { type RenderHookOptions, renderHook, server, waitFor } from '@test';
1
+ import { renderHook, server, waitFor } from '@test';
2
2
  import { http, HttpResponse } from 'msw';
3
3
  import { zeroAddress } from 'viem';
4
4
  import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -44,34 +44,6 @@ describe('useCheckoutOptions', () => {
44
44
  });
45
45
  });
46
46
 
47
- it('should fetch checkout options successfully', async () => {
48
- const { result } = renderHook(() => useCheckoutOptions(defaultInput));
49
-
50
- await waitFor(() => {
51
- expect(result.current.isSuccess).toBe(true);
52
- });
53
-
54
- expect(result.current.data).toEqual({
55
- crypto: TransactionCrypto.all,
56
- swap: [],
57
- nftCheckout: [],
58
- onRamp: [],
59
- });
60
- });
61
-
62
- it('should not fetch when wallet is not available', () => {
63
- vi.mocked(useWallet).mockReturnValue({
64
- wallet: null,
65
- isLoading: false,
66
- isError: false,
67
- });
68
-
69
- const { result } = renderHook(() => useCheckoutOptions(defaultInput));
70
-
71
- expect(result.current.data).toBeUndefined();
72
- expect(result.current.isLoading).toBe(false);
73
- });
74
-
75
47
  it('should include fees in the API request', async () => {
76
48
  const mockFeeAmount = '200000000000000000';
77
49
  vi.mocked(useFees).mockReturnValue({
@@ -133,37 +105,6 @@ describe('useCheckoutOptions', () => {
133
105
  expect(result.current.data).toBeUndefined();
134
106
  });
135
107
 
136
- it('should refetch when input parameters change', async () => {
137
- const { result, rerender } = renderHook<
138
- typeof defaultInput,
139
- ReturnType<typeof useCheckoutOptions>
140
- >((props) => useCheckoutOptions(props), {
141
- initialProps: defaultInput,
142
- } as RenderHookOptions<typeof defaultInput>);
143
-
144
- await waitFor(() => {
145
- expect(result.current.isSuccess).toBe(true);
146
- });
147
-
148
- // Change input
149
- rerender({
150
- ...defaultInput,
151
- orderId: '456',
152
- });
153
-
154
- await waitFor(() => {
155
- expect(result.current.isSuccess).toBe(true);
156
- });
157
-
158
- // Verify that the query was refetched
159
- expect(result.current.data).toEqual({
160
- crypto: TransactionCrypto.all,
161
- swap: [],
162
- nftCheckout: [],
163
- onRamp: [],
164
- });
165
- });
166
-
167
108
  it('should handle wallet address resolution failure', async () => {
168
109
  const mockWalletWithFailure = createMockWallet({
169
110
  address: vi.fn().mockRejectedValue(new Error('Failed to get address')),
@@ -33,7 +33,7 @@ describe('useFees', () => {
33
33
  collections: [
34
34
  {
35
35
  address: '0x456',
36
- chainId: '1',
36
+ chainId: 1,
37
37
  feePercentage: '5.0',
38
38
  },
39
39
  ],
@@ -32,19 +32,35 @@ export const useCheckoutOptions = (input: {
32
32
  queryFn: wallet
33
33
  ? async () => {
34
34
  const marketplaceClient = getMarketplaceClient(input.chainId, config);
35
- return marketplaceClient
36
- .checkoutOptionsMarketplace({
37
- wallet: await wallet.address(),
38
- orders: [
39
- {
40
- contractAddress: input.collectionAddress,
41
- orderId: input.orderId,
42
- marketplace: input.marketplace,
43
- },
44
- ],
45
- additionalFee: Number(fees.amount),
46
- })
47
- .then((res) => res.options);
35
+ const response = await marketplaceClient.checkoutOptionsMarketplace({
36
+ wallet: await wallet.address(),
37
+ orders: [
38
+ {
39
+ contractAddress: input.collectionAddress,
40
+ orderId: input.orderId,
41
+ marketplace: input.marketplace,
42
+ },
43
+ ],
44
+ additionalFee: Number(fees.amount),
45
+ });
46
+
47
+ // Get order data
48
+ const orderResponse = await marketplaceClient.getOrders({
49
+ input: [
50
+ {
51
+ contractAddress: input.collectionAddress,
52
+ orderId: input.orderId,
53
+ marketplace: input.marketplace,
54
+ },
55
+ ],
56
+ });
57
+
58
+ const order = orderResponse.orders[0];
59
+
60
+ return {
61
+ ...response.options,
62
+ order,
63
+ };
48
64
  }
49
65
  : skipToken,
50
66
  enabled: !!wallet,
@@ -1,24 +1,18 @@
1
- import type { Hex } from 'viem';
2
- import type { MarketplaceKind } from '../../../../_internal';
1
+ import { useWallet } from '../../../../_internal/wallet/useWallet';
3
2
  import { useCollectible, useCollection } from '../../../../hooks';
4
-
3
+ import { useBuyModalProps } from '../store';
5
4
  import { useCheckoutOptions } from './useCheckoutOptions';
6
5
 
7
- export type UseLoadDataProps = {
8
- chainId: number;
9
- collectionAddress: Hex;
10
- collectibleId: string | undefined;
11
- orderId: string;
12
- marketplace: MarketplaceKind;
13
- };
6
+ export const useLoadData = () => {
7
+ const { chainId, collectionAddress, collectibleId, orderId, marketplace } =
8
+ useBuyModalProps();
9
+
10
+ const {
11
+ wallet,
12
+ isLoading: walletLoading,
13
+ isError: walletError,
14
+ } = useWallet();
14
15
 
15
- export const useLoadData = ({
16
- chainId,
17
- collectionAddress,
18
- collectibleId,
19
- orderId,
20
- marketplace,
21
- }: UseLoadDataProps) => {
22
16
  const {
23
17
  data: collection,
24
18
  isLoading: collectionLoading,
@@ -33,7 +27,7 @@ export const useLoadData = ({
33
27
  isLoading: collectableLoading,
34
28
  isError: collectableError,
35
29
  } = useCollectible({
36
- chainId: String(chainId),
30
+ chainId,
37
31
  collectionAddress,
38
32
  collectibleId,
39
33
  query: {
@@ -45,6 +39,7 @@ export const useLoadData = ({
45
39
  data: checkoutOptions,
46
40
  isLoading: checkoutOptionsLoading,
47
41
  isError: checkoutOptionsError,
42
+ // TODO: rename this... its order and checkout options
48
43
  } = useCheckoutOptions({
49
44
  chainId,
50
45
  collectionAddress,
@@ -55,9 +50,19 @@ export const useLoadData = ({
55
50
  return {
56
51
  collection,
57
52
  collectable,
58
- checkoutOptions,
53
+ order: checkoutOptions?.order,
54
+ checkoutOptions: checkoutOptions,
55
+ wallet,
59
56
  isLoading:
60
- collectionLoading || collectableLoading || checkoutOptionsLoading,
61
- isError: collectionError || collectableError || checkoutOptionsError,
57
+ collectionLoading ||
58
+ collectableLoading ||
59
+ checkoutOptionsLoading ||
60
+ walletLoading,
61
+ // TODO: we should have a way to determine what is causing the error
62
+ isError:
63
+ collectionError ||
64
+ collectableError ||
65
+ checkoutOptionsError ||
66
+ walletError,
62
67
  };
63
68
  };