@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.
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.changeset/seven-doors-taste.md +5 -0
- package/CHANGELOG.md +13 -0
- package/dist/{chunk-MPBN3E54.js → chunk-2VHHJNXY.js} +3 -3
- package/dist/{chunk-FBUMNJQ4.js → chunk-3II5GLHE.js} +2 -2
- package/dist/chunk-3JU7SQVE.js +182 -0
- package/dist/chunk-3JU7SQVE.js.map +1 -0
- package/dist/{chunk-XTGMMNV5.js → chunk-A5ACY5YV.js} +2 -2
- package/dist/chunk-ABSYNRT5.js +128 -0
- package/dist/chunk-ABSYNRT5.js.map +1 -0
- package/dist/{chunk-XNA64MZQ.js → chunk-BCO4CYE4.js} +2 -2
- package/dist/{chunk-HTFORA4Q.js → chunk-BN36GABQ.js} +1883 -1010
- package/dist/chunk-BN36GABQ.js.map +1 -0
- package/dist/{chunk-4XK7XNJ7.js → chunk-BNAUZXPV.js} +73 -2
- package/dist/chunk-BNAUZXPV.js.map +1 -0
- package/dist/{chunk-Q5URKSC4.js → chunk-FMEEJFAF.js} +1 -1
- package/dist/{chunk-BBASZVT3.js → chunk-GBQVYNCD.js} +5 -6
- package/dist/chunk-GBQVYNCD.js.map +1 -0
- package/dist/{chunk-3AKOPSON.js → chunk-IZ44XPBH.js} +2 -9
- package/dist/chunk-IZ44XPBH.js.map +1 -0
- package/dist/{chunk-EAJ5K7QV.js → chunk-Q5RKAMYF.js} +3 -4
- package/dist/chunk-Q5RKAMYF.js.map +1 -0
- package/dist/{chunk-RBEPPVLT.js → chunk-X3QNSQER.js} +145 -355
- package/dist/chunk-X3QNSQER.js.map +1 -0
- package/dist/{index-CzTANLaA.d.ts → index-CnaFSNE9.d.ts} +6 -7
- package/dist/index.css +113 -31
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +4 -4
- package/dist/listCollectibles-B0tbqnRd.d.ts +155 -0
- package/dist/react/_internal/api/index.d.ts +28 -2
- package/dist/react/_internal/api/index.js +3 -1
- package/dist/react/_internal/databeat/index.js +10 -9
- package/dist/react/_internal/index.d.ts +2 -3
- package/dist/react/_internal/index.js +4 -4
- package/dist/react/_internal/wagmi/index.js +2 -2
- package/dist/react/hooks/index.d.ts +259 -674
- package/dist/react/hooks/index.js +11 -20
- package/dist/react/hooks/options/index.d.ts +1 -2
- package/dist/react/hooks/options/index.js +4 -4
- package/dist/react/index.d.ts +7 -7
- package/dist/react/index.js +15 -24
- package/dist/react/queries/index.d.ts +25 -0
- package/dist/react/queries/index.js +48 -0
- package/dist/react/queries/index.js.map +1 -0
- package/dist/react/ssr/index.js +3 -3
- package/dist/react/ui/components/collectible-card/index.d.ts +1 -6
- package/dist/react/ui/components/collectible-card/index.js +13 -12
- package/dist/react/ui/components/marketplace-logos/index.js +1 -1
- package/dist/react/ui/icons/index.js +6 -6
- package/dist/react/ui/index.d.ts +18 -22
- package/dist/react/ui/index.js +13 -12
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +6 -11
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +10 -9
- package/dist/types/index.js +2 -2
- package/dist/{types-Ct1uCT3M.d.ts → types-o_pKUpQG.d.ts} +2 -5
- package/dist/utils/index.d.ts +1 -5
- package/dist/utils/index.js +4 -4
- package/package.json +22 -16
- package/src/react/_internal/api/__mocks__/indexer.msw.ts +3 -1
- package/src/react/_internal/api/__mocks__/marketplace.msw.ts +1 -1
- package/src/react/_internal/api/__mocks__/metadata.msw.ts +14 -12
- package/src/react/_internal/api/index.ts +1 -0
- package/src/react/_internal/api/laos-api.ts +103 -0
- package/src/react/_internal/api/zod-schema.ts +3 -3
- package/src/react/_internal/types.ts +1 -10
- package/src/react/_internal/wallet/__tests__/wallet.test.ts +43 -0
- package/src/react/_internal/wallet/useWallet.ts +6 -3
- package/src/react/hooks/__tests__/useAutoSelectFeeOption.test.tsx +1 -1
- package/src/react/hooks/__tests__/useCancelOrder.test.tsx +1 -1
- package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +1 -1
- package/src/react/hooks/__tests__/useCollectible.test.tsx +2 -2
- package/src/react/hooks/__tests__/useCollection.test.tsx +2 -2
- package/src/react/hooks/__tests__/useComparePrices.test.tsx +1 -1
- package/src/react/hooks/__tests__/useConvertPriceToUSD.test.tsx +1 -1
- package/src/react/hooks/__tests__/useCountListingsForCollectible.test.tsx +1 -1
- package/src/react/hooks/__tests__/useCountOfCollectables.test.tsx +2 -2
- package/src/react/hooks/__tests__/useCountOffersForCollectible.test.tsx +1 -1
- package/src/react/hooks/__tests__/useCurrencies.test.tsx +2 -2
- package/src/react/hooks/__tests__/useCurrency.test.tsx +2 -2
- package/src/react/hooks/__tests__/useFilters.test.tsx +2 -2
- package/src/react/hooks/__tests__/useFloorOrder.test.tsx +2 -2
- package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +1 -1
- package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +1 -1
- package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +1 -1
- package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +1 -1
- package/src/react/hooks/__tests__/useListCollectibleActivities.test.tsx +2 -2
- package/src/react/hooks/__tests__/useListCollectibles.test.tsx +3 -2
- package/src/react/hooks/__tests__/useListCollectiblesPaginated.test.tsx +1 -1
- package/src/react/hooks/__tests__/useListCollectionActivities.test.tsx +1 -1
- package/src/react/hooks/__tests__/useListListingsForCollectible.test.tsx +1 -1
- package/src/react/hooks/__tests__/useListOffersForCollectible.test.tsx +1 -1
- package/src/react/hooks/__tests__/useLowestListing.test.tsx +1 -1
- package/src/react/hooks/__tests__/useRoyalty.test.tsx +1 -2
- package/src/react/hooks/index.ts +0 -1
- package/src/react/hooks/options/collectionOptions.ts +2 -3
- package/src/react/hooks/useAutoSelectFeeOption.tsx +1 -1
- package/src/react/hooks/useCancelOrder.tsx +3 -3
- package/src/react/hooks/useCancelTransactionSteps.tsx +1 -1
- package/src/react/hooks/useCheckoutOptions.tsx +1 -2
- package/src/react/hooks/useCollectible.tsx +2 -3
- package/src/react/hooks/useCollectionBalanceDetails.tsx +1 -2
- package/src/react/hooks/useComparePrices.tsx +2 -9
- package/src/react/hooks/useConvertPriceToUSD.tsx +1 -4
- package/src/react/hooks/useCountListingsForCollectible.tsx +1 -2
- package/src/react/hooks/useCountOfCollectables.tsx +1 -2
- package/src/react/hooks/useCountOffersForCollectible.tsx +1 -2
- package/src/react/hooks/useCurrencies.tsx +1 -4
- package/src/react/hooks/useCurrency.tsx +3 -8
- package/src/react/hooks/useFilters.tsx +5 -4
- package/src/react/hooks/useFloorOrder.tsx +1 -2
- package/src/react/hooks/useGenerateCancelTransaction.tsx +3 -6
- package/src/react/hooks/useGenerateListingTransaction.tsx +2 -3
- package/src/react/hooks/useGenerateOfferTransaction.tsx +2 -3
- package/src/react/hooks/useGenerateSellTransaction.tsx +3 -6
- package/src/react/hooks/useHighestOffer.tsx +1 -1
- package/src/react/hooks/useListCollectibles.tsx +33 -61
- package/src/react/hooks/useListCollectiblesPaginated.tsx +2 -6
- package/src/react/hooks/useListListingsForCollectible.tsx +1 -2
- package/src/react/hooks/useListOffersForCollectible.tsx +1 -2
- package/src/react/hooks/useLowestListing.tsx +1 -2
- package/src/react/hooks/useRoyalty.tsx +3 -8
- package/src/react/hooks/useTransferTokens.tsx +2 -2
- package/src/react/queries/balanceOfCollectible.ts +9 -32
- package/src/react/queries/getTokenSupplies.ts +38 -0
- package/src/react/queries/index.ts +5 -0
- package/src/react/queries/listCollectibles.ts +96 -0
- package/src/react/ui/components/_internals/action-button/ActionButton.tsx +1 -1
- package/src/react/ui/components/_internals/action-button/__tests__/ActionButton.test.tsx +1 -1
- package/src/react/ui/components/_internals/action-button/components/NonOwnerActions.tsx +4 -3
- package/src/react/ui/components/_internals/action-button/components/OwnerActions.tsx +1 -1
- package/src/react/ui/components/collectible-card/CollectibleCard.tsx +2 -3
- package/src/react/ui/components/collectible-card/__tests__/CollectibleCard.test.tsx +1 -1
- package/src/react/ui/modals/BuyModal/ERC1155QuantityModal.tsx +127 -0
- package/src/react/ui/modals/BuyModal/Modal.tsx +70 -85
- package/src/react/ui/modals/BuyModal/__tests__/Modal.test.tsx +85 -226
- package/src/react/ui/modals/BuyModal/__tests__/Modal1155.test.tsx +140 -0
- package/src/react/ui/modals/BuyModal/__tests__/store.test.ts +67 -76
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useCheckoutOptions.test.tsx +1 -60
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +1 -1
- package/src/react/ui/modals/BuyModal/hooks/useCheckoutOptions.ts +29 -13
- package/src/react/ui/modals/BuyModal/hooks/useLoadData.ts +26 -21
- package/src/react/ui/modals/BuyModal/hooks/usePaymentModalParams.ts +200 -0
- package/src/react/ui/modals/BuyModal/index.tsx +4 -14
- package/src/react/ui/modals/BuyModal/store.ts +71 -76
- package/src/react/ui/modals/CreateListingModal/Modal.tsx +71 -7
- package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +2 -2
- package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +1 -1
- package/src/react/ui/modals/CreateListingModal/hooks/useGetTokenApproval.ts +1 -1
- package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +9 -5
- package/src/react/ui/modals/CreateListingModal/store.ts +7 -2
- package/src/react/ui/modals/MakeOfferModal/Modal.tsx +103 -6
- package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +1 -1
- package/src/react/ui/modals/MakeOfferModal/hooks/useGetTokenApproval.tsx +1 -1
- package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +1 -1
- package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +8 -4
- package/src/react/ui/modals/MakeOfferModal/store.ts +5 -3
- package/src/react/ui/modals/SellModal/Modal.tsx +76 -4
- package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +1 -1
- package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +1 -1
- package/src/react/ui/modals/SellModal/hooks/useSell.tsx +1 -1
- package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +16 -8
- package/src/react/ui/modals/SellModal/store.ts +5 -3
- package/src/react/ui/modals/TransferModal/_store.ts +15 -3
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TokenQuantityInput.tsx +58 -0
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TransferButton.tsx +56 -0
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/WalletAddressInput.tsx +50 -0
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +94 -66
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +22 -14
- package/src/react/ui/modals/TransferModal/index.tsx +72 -38
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +43 -42
- package/src/react/ui/modals/_internal/components/actionModal/store.ts +1 -2
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +2 -2
- package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +9 -1
- package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +27 -12
- package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +1 -1
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +19 -3
- package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +3 -0
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/_components/ActionButtons.tsx +60 -0
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/_components/BalanceIndicator.tsx +30 -0
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/index.tsx +126 -0
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/store.ts +25 -0
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/useWaasFeeOptionManager.tsx +74 -0
- package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +1 -2
- package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +1 -2
- package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +1 -1
- package/src/react/ui/modals/_internal/components/transaction-footer/index.tsx +4 -7
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +1 -1
- package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +1 -1
- package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +1 -1
- package/src/react/ui/modals/_internal/components/transactionStatusModal/hooks/useTransactionStatus.ts +1 -1
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +6 -1
- package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +2 -2
- package/src/react/ui/modals/_internal/components/waasFeeOptionsSelect/WaasFeeOptionsSelect.tsx +10 -31
- package/src/react/ui/modals/_internal/hooks/useSelectWaasFeeOptions.ts +53 -0
- package/src/react/ui/modals/_internal/types.ts +2 -1
- package/src/types/waas-types.ts +38 -0
- package/src/utils/network.ts +2 -4
- package/test/const.ts +1 -1
- package/test/setup.ts +10 -0
- package/test/test-utils.tsx +31 -5
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/chunk-3AKOPSON.js.map +0 -1
- package/dist/chunk-4XK7XNJ7.js.map +0 -1
- package/dist/chunk-BBASZVT3.js.map +0 -1
- package/dist/chunk-EAJ5K7QV.js.map +0 -1
- package/dist/chunk-HTFORA4Q.js.map +0 -1
- package/dist/chunk-OFY7OFTL.js +0 -458
- package/dist/chunk-OFY7OFTL.js.map +0 -1
- package/dist/chunk-RBEPPVLT.js.map +0 -1
- package/src/react/hooks/__tests__/useGenerateBuyTransaction.test.tsx +0 -172
- package/src/react/hooks/useGenerateBuyTransaction.tsx +0 -80
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useBuyCollectable.test.tsx +0 -349
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useLoadData.test.tsx +0 -185
- package/src/react/ui/modals/BuyModal/hooks/useBuyCollectable.ts +0 -170
- package/src/react/ui/modals/BuyModal/modals/CheckoutModal.tsx +0 -47
- package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +0 -140
- package/src/react/ui/modals/BuyModal/modals/__tests__/CheckoutModal.test.tsx +0 -162
- package/src/react/ui/modals/BuyModal/modals/__tests__/Modal1155.test.tsx +0 -327
- package/src/react/ui/modals/_internal/components/waasFeeOptionsBox/index.tsx +0 -124
- package/src/react/ui/modals/_internal/components/waasFeeOptionsBox/store.ts +0 -12
- /package/dist/{chunk-MPBN3E54.js.map → chunk-2VHHJNXY.js.map} +0 -0
- /package/dist/{chunk-FBUMNJQ4.js.map → chunk-3II5GLHE.js.map} +0 -0
- /package/dist/{chunk-XTGMMNV5.js.map → chunk-A5ACY5YV.js.map} +0 -0
- /package/dist/{chunk-XNA64MZQ.js.map → chunk-BCO4CYE4.js.map} +0 -0
- /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
|
|
3
|
-
import {
|
|
2
|
+
import { MarketplaceKind } from '../../../../_internal';
|
|
3
|
+
import { buyModalStore } from '../store';
|
|
4
4
|
|
|
5
5
|
describe('BuyModal Store', () => {
|
|
6
6
|
beforeEach(() => {
|
|
7
|
-
|
|
7
|
+
buyModalStore.send({ type: 'close' });
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
it('should initialize with correct default state', () => {
|
|
11
|
-
|
|
12
|
-
expect(
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
expect(
|
|
44
|
-
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
expect(
|
|
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
|
-
|
|
93
|
-
|
|
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
|
-
|
|
96
|
-
|
|
88
|
+
// Test resetting by closing
|
|
89
|
+
buyModalStore.send({ type: 'close' });
|
|
97
90
|
|
|
98
|
-
|
|
99
|
-
|
|
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 {
|
|
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')),
|
|
@@ -32,19 +32,35 @@ export const useCheckoutOptions = (input: {
|
|
|
32
32
|
queryFn: wallet
|
|
33
33
|
? async () => {
|
|
34
34
|
const marketplaceClient = getMarketplaceClient(input.chainId, config);
|
|
35
|
-
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
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
|
|
8
|
-
chainId
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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 ||
|
|
61
|
-
|
|
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
|
};
|