@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
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
act,
|
|
3
|
-
cleanup,
|
|
4
|
-
fireEvent,
|
|
5
|
-
render,
|
|
6
|
-
screen,
|
|
7
|
-
waitFor,
|
|
8
|
-
within,
|
|
9
|
-
} from '@test';
|
|
10
|
-
import {
|
|
11
|
-
type Mock,
|
|
12
|
-
afterEach,
|
|
13
|
-
beforeEach,
|
|
14
|
-
describe,
|
|
15
|
-
expect,
|
|
16
|
-
it,
|
|
17
|
-
vi,
|
|
18
|
-
} from 'vitest';
|
|
19
|
-
import { createMockWallet } from '../../../../../../../test/mocks/wallet';
|
|
20
|
-
import type { Order, TokenMetadata } from '../../../../../_internal';
|
|
21
|
-
import {
|
|
22
|
-
mockOrder as baseMockOrder,
|
|
23
|
-
mockTokenMetadata,
|
|
24
|
-
} from '../../../../../_internal/api/__mocks__/marketplace.msw';
|
|
25
|
-
import { buyModal$ } from '../../store';
|
|
26
|
-
import { ERC1155QuantityModal } from '../Modal1155';
|
|
27
|
-
|
|
28
|
-
vi.mock(import('../../../../../hooks'), async (importOriginal) => {
|
|
29
|
-
const actual = await importOriginal();
|
|
30
|
-
return {
|
|
31
|
-
...actual,
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const mockWallet = createMockWallet();
|
|
36
|
-
|
|
37
|
-
const getChainIdMock = mockWallet.getChainId as Mock<
|
|
38
|
-
typeof mockWallet.getChainId
|
|
39
|
-
>;
|
|
40
|
-
const switchChainMock = mockWallet.switchChain as Mock<
|
|
41
|
-
typeof mockWallet.switchChain
|
|
42
|
-
>;
|
|
43
|
-
|
|
44
|
-
vi.mock('../../../../../_internal/wallet/useWallet', () => ({
|
|
45
|
-
useWallet: () => ({
|
|
46
|
-
wallet: mockWallet,
|
|
47
|
-
}),
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
// Mock switch chain modal hook
|
|
51
|
-
vi.mock('../../_internal/components/switchChainModal', () => ({
|
|
52
|
-
useSwitchChainModal: () => ({
|
|
53
|
-
show: vi.fn(),
|
|
54
|
-
}),
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
vi.mock('@0xsequence/kit', () => ({
|
|
58
|
-
useWaasFeeOptions: vi.fn().mockReturnValue([]),
|
|
59
|
-
}));
|
|
60
|
-
|
|
61
|
-
describe.skip('ERC1155QuantityModal', () => {
|
|
62
|
-
// Customize the mock order for ERC1155 testing with specific price for predictable calculations
|
|
63
|
-
const mockOrder: Order = {
|
|
64
|
-
...baseMockOrder,
|
|
65
|
-
priceAmount: '1000000000000000000', // 1 ETH in wei
|
|
66
|
-
priceAmountFormatted: '1',
|
|
67
|
-
quantityRemaining: '10',
|
|
68
|
-
quantityRemainingFormatted: '10',
|
|
69
|
-
quantityAvailable: '10',
|
|
70
|
-
quantityAvailableFormatted: '10',
|
|
71
|
-
quantityDecimals: 0,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const mockCollectable: TokenMetadata = mockTokenMetadata;
|
|
75
|
-
|
|
76
|
-
const mockBuy = vi.fn();
|
|
77
|
-
|
|
78
|
-
beforeEach(() => {
|
|
79
|
-
vi.clearAllMocks();
|
|
80
|
-
|
|
81
|
-
// Reset the modal state
|
|
82
|
-
buyModal$.close();
|
|
83
|
-
buyModal$.state.checkoutModalLoaded.set(false);
|
|
84
|
-
buyModal$.state.checkoutModalIsLoading.set(false);
|
|
85
|
-
buyModal$.state.invalidQuantity.set(false);
|
|
86
|
-
buyModal$.state.quantity.set('10'); // Match the initial quantity with the mock order
|
|
87
|
-
|
|
88
|
-
// Reset mock wallet calls
|
|
89
|
-
switchChainMock.mockClear();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
afterEach(() => {
|
|
93
|
-
buyModal$.close();
|
|
94
|
-
cleanup();
|
|
95
|
-
vi.clearAllMocks();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it.skip('should render quantity input correctly', async () => {
|
|
99
|
-
// Open the modal with initial state
|
|
100
|
-
buyModal$.open({
|
|
101
|
-
order: mockOrder,
|
|
102
|
-
callbacks: {},
|
|
103
|
-
chainId: '1',
|
|
104
|
-
collectionAddress: '0x123',
|
|
105
|
-
tokenId: '1',
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
render(
|
|
109
|
-
<ERC1155QuantityModal
|
|
110
|
-
buy={mockBuy}
|
|
111
|
-
collectable={mockCollectable}
|
|
112
|
-
order={mockOrder}
|
|
113
|
-
chainId="1"
|
|
114
|
-
collectionAddress="0x123"
|
|
115
|
-
collectibleId="1"
|
|
116
|
-
/>,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
// Verify modal title
|
|
120
|
-
expect(screen.getByText('Select Quantity')).toBeInTheDocument();
|
|
121
|
-
|
|
122
|
-
// Verify quantity input is present with initial value
|
|
123
|
-
const quantityInput = screen.getByRole('textbox', {
|
|
124
|
-
name: /enter quantity/i,
|
|
125
|
-
});
|
|
126
|
-
expect(quantityInput).toBeInTheDocument();
|
|
127
|
-
expect(quantityInput).toHaveValue('10'); // Match the initial quantity
|
|
128
|
-
|
|
129
|
-
// Wait for price to be displayed
|
|
130
|
-
await waitFor(() => {
|
|
131
|
-
const priceLabels = screen.getAllByText('Total Price');
|
|
132
|
-
const priceContainer = priceLabels[0].parentElement;
|
|
133
|
-
if (!priceContainer) throw new Error('Price container not found');
|
|
134
|
-
|
|
135
|
-
// Check for the price without decimal
|
|
136
|
-
const priceElement = within(priceContainer).getByText('10');
|
|
137
|
-
expect(priceElement).toBeInTheDocument();
|
|
138
|
-
expect(within(priceContainer).getByText('ETH')).toBeInTheDocument();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// Verify buy button
|
|
142
|
-
const buyButton = screen.getByRole('button', { name: /buy now/i });
|
|
143
|
-
expect(buyButton).toBeInTheDocument();
|
|
144
|
-
expect(buyButton).not.toBeDisabled();
|
|
145
|
-
|
|
146
|
-
// Verify currency image (not NFT image)
|
|
147
|
-
const currencyImage = screen.getByRole('img', { name: '' });
|
|
148
|
-
expect(currencyImage).toBeInTheDocument();
|
|
149
|
-
// expect(currencyImage).toHaveAttribute('src', mockCurrencies[0].imageUrl);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it.skip('should update total price when quantity changes', async () => {
|
|
153
|
-
buyModal$.open({
|
|
154
|
-
order: mockOrder,
|
|
155
|
-
callbacks: {},
|
|
156
|
-
chainId: '1',
|
|
157
|
-
collectionAddress: '0x123',
|
|
158
|
-
tokenId: '1',
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
render(
|
|
162
|
-
<ERC1155QuantityModal
|
|
163
|
-
buy={mockBuy}
|
|
164
|
-
collectable={mockCollectable}
|
|
165
|
-
order={mockOrder}
|
|
166
|
-
chainId="1"
|
|
167
|
-
collectionAddress="0x123"
|
|
168
|
-
collectibleId="1"
|
|
169
|
-
/>,
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const quantityInput = screen.getByRole('textbox', {
|
|
173
|
-
name: /enter quantity/i,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// Change quantity to 2
|
|
177
|
-
await act(async () => {
|
|
178
|
-
fireEvent.change(quantityInput, { target: { value: '2' } });
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// Wait for updated price to be displayed
|
|
182
|
-
await waitFor(() => {
|
|
183
|
-
const priceLabels = screen.getAllByText('Total Price');
|
|
184
|
-
const priceContainer = priceLabels[0].parentElement;
|
|
185
|
-
if (!priceContainer) throw new Error('Price container not found');
|
|
186
|
-
|
|
187
|
-
// Check for the price without decimal
|
|
188
|
-
const priceElement = within(priceContainer).getByText('2');
|
|
189
|
-
expect(priceElement).toBeInTheDocument();
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should disable buy button when quantity is invalid', async () => {
|
|
194
|
-
buyModal$.open({
|
|
195
|
-
order: mockOrder,
|
|
196
|
-
callbacks: {},
|
|
197
|
-
chainId: '1',
|
|
198
|
-
collectionAddress: '0x123',
|
|
199
|
-
tokenId: '1',
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// Set invalid quantity and loading state
|
|
203
|
-
buyModal$.state.invalidQuantity.set(true);
|
|
204
|
-
buyModal$.state.checkoutModalIsLoading.set(true);
|
|
205
|
-
|
|
206
|
-
render(
|
|
207
|
-
<ERC1155QuantityModal
|
|
208
|
-
buy={mockBuy}
|
|
209
|
-
collectable={mockCollectable}
|
|
210
|
-
order={mockOrder}
|
|
211
|
-
chainId="1"
|
|
212
|
-
collectionAddress="0x123"
|
|
213
|
-
collectibleId="1"
|
|
214
|
-
/>,
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
const buyButton = screen.getByRole('button', { name: /buy now/i });
|
|
218
|
-
|
|
219
|
-
// Wait for the button to be disabled
|
|
220
|
-
await waitFor(() => {
|
|
221
|
-
expect(buyButton).toBeDisabled();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
// Click should not trigger buy function
|
|
225
|
-
fireEvent.click(buyButton);
|
|
226
|
-
expect(mockBuy).not.toHaveBeenCalled();
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it.skip('should calculate total price correctly', async () => {
|
|
230
|
-
// Open the modal with initial state
|
|
231
|
-
buyModal$.open({
|
|
232
|
-
order: mockOrder,
|
|
233
|
-
callbacks: {},
|
|
234
|
-
chainId: '1',
|
|
235
|
-
collectionAddress: '0x123',
|
|
236
|
-
tokenId: '1',
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
render(
|
|
240
|
-
<ERC1155QuantityModal
|
|
241
|
-
buy={mockBuy}
|
|
242
|
-
collectable={mockCollectable}
|
|
243
|
-
order={mockOrder}
|
|
244
|
-
chainId="1"
|
|
245
|
-
collectionAddress="0x123"
|
|
246
|
-
collectibleId="1"
|
|
247
|
-
/>,
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
// Wait for modal content to be fully loaded
|
|
251
|
-
await waitFor(() => {
|
|
252
|
-
expect(screen.getByText('Select Quantity')).toBeInTheDocument();
|
|
253
|
-
expect(
|
|
254
|
-
screen.getByRole('textbox', { name: /enter quantity/i }),
|
|
255
|
-
).toBeInTheDocument();
|
|
256
|
-
expect(screen.getAllByText('Total Price')[0]).toBeInTheDocument();
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// Wait for initial price
|
|
260
|
-
await waitFor(() => {
|
|
261
|
-
const priceLabels = screen.getAllByText('Total Price');
|
|
262
|
-
const priceContainer = priceLabels[0].parentElement;
|
|
263
|
-
if (!priceContainer) throw new Error('Price container not found');
|
|
264
|
-
|
|
265
|
-
// Check for the price without decimal
|
|
266
|
-
const priceElement = within(priceContainer).getByText('10');
|
|
267
|
-
expect(priceElement).toBeInTheDocument();
|
|
268
|
-
expect(within(priceContainer).getByText('ETH')).toBeInTheDocument();
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
// Change quantity to 3
|
|
272
|
-
const quantityInput = screen.getByRole('textbox', {
|
|
273
|
-
name: /enter quantity/i,
|
|
274
|
-
});
|
|
275
|
-
await act(async () => {
|
|
276
|
-
fireEvent.change(quantityInput, { target: { value: '3' } });
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
// Wait for updated price
|
|
280
|
-
await waitFor(() => {
|
|
281
|
-
const priceLabels = screen.getAllByText('Total Price');
|
|
282
|
-
const priceContainer = priceLabels[0].parentElement;
|
|
283
|
-
if (!priceContainer) throw new Error('Price container not found');
|
|
284
|
-
|
|
285
|
-
// Check for the price without decimal
|
|
286
|
-
const priceElement = within(priceContainer).getByText('3');
|
|
287
|
-
expect(priceElement).toBeInTheDocument();
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it.skip('should handle chain mismatch correctly', async () => {
|
|
292
|
-
// Mock wallet to return a different chain ID
|
|
293
|
-
getChainIdMock.mockResolvedValueOnce(2); // Different from order.chainId (1)
|
|
294
|
-
|
|
295
|
-
buyModal$.open({
|
|
296
|
-
order: mockOrder,
|
|
297
|
-
callbacks: {},
|
|
298
|
-
chainId: '1',
|
|
299
|
-
collectionAddress: '0x123',
|
|
300
|
-
tokenId: '1',
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
render(
|
|
304
|
-
<ERC1155QuantityModal
|
|
305
|
-
buy={mockBuy}
|
|
306
|
-
collectable={mockCollectable}
|
|
307
|
-
order={mockOrder}
|
|
308
|
-
chainId="1"
|
|
309
|
-
collectionAddress="0x123"
|
|
310
|
-
collectibleId="1"
|
|
311
|
-
/>,
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
const buyButton = screen.getByRole('button', { name: /buy now/i });
|
|
315
|
-
|
|
316
|
-
// Click buy button
|
|
317
|
-
fireEvent.click(buyButton);
|
|
318
|
-
|
|
319
|
-
// Verify chain switch was attempted
|
|
320
|
-
await waitFor(() => {
|
|
321
|
-
expect(getChainIdMock).toHaveBeenCalled();
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
// Verify buy function was not called
|
|
325
|
-
expect(mockBuy).not.toHaveBeenCalled();
|
|
326
|
-
});
|
|
327
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useWaasFeeOptions } from '@0xsequence/connect';
|
|
4
|
-
import { Button, Skeleton, Text, WarningIcon } from '@0xsequence/design-system';
|
|
5
|
-
import { observer } from '@legendapp/state/react';
|
|
6
|
-
import { useEffect } from 'react';
|
|
7
|
-
import { type Hex, zeroAddress } from 'viem';
|
|
8
|
-
import { useAccount } from 'wagmi';
|
|
9
|
-
import { useCurrencyBalance } from '../../../../../hooks/useCurrencyBalance';
|
|
10
|
-
import WaasFeeOptionsSelect, {
|
|
11
|
-
type FeeOption,
|
|
12
|
-
} from '../waasFeeOptionsSelect/WaasFeeOptionsSelect';
|
|
13
|
-
import { waasFeeOptionsModal$ } from './store';
|
|
14
|
-
|
|
15
|
-
type WaasFeeOptionsBoxProps = {
|
|
16
|
-
onFeeOptionsLoaded: () => void;
|
|
17
|
-
onFeeOptionConfirmed: () => void;
|
|
18
|
-
chainId: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const WaasFeeOptionsBox = observer(
|
|
22
|
-
({
|
|
23
|
-
onFeeOptionsLoaded,
|
|
24
|
-
onFeeOptionConfirmed,
|
|
25
|
-
chainId,
|
|
26
|
-
}: WaasFeeOptionsBoxProps) => {
|
|
27
|
-
const { address: userAddress } = useAccount();
|
|
28
|
-
const selectedFeeOption$ = waasFeeOptionsModal$.selectedFeeOption;
|
|
29
|
-
const [pendingFeeOptionConfirmation, confirmPendingFeeOption] =
|
|
30
|
-
useWaasFeeOptions();
|
|
31
|
-
const { data: currencyBalance, isLoading: currencyBalanceLoading } =
|
|
32
|
-
useCurrencyBalance({
|
|
33
|
-
chainId,
|
|
34
|
-
currencyAddress: (selectedFeeOption$.token.contractAddress.get() ||
|
|
35
|
-
zeroAddress) as Hex,
|
|
36
|
-
userAddress: userAddress as Hex,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (pendingFeeOptionConfirmation) {
|
|
42
|
-
onFeeOptionsLoaded();
|
|
43
|
-
}
|
|
44
|
-
}, [pendingFeeOptionConfirmation]);
|
|
45
|
-
|
|
46
|
-
const selectedFeeOption = selectedFeeOption$.get();
|
|
47
|
-
const insufficientBalance = (() => {
|
|
48
|
-
if (!selectedFeeOption?.value || !selectedFeeOption.token.decimals) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!currencyBalance?.value && currencyBalance?.value !== 0n) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const feeValue = BigInt(selectedFeeOption.value);
|
|
58
|
-
return currencyBalance.value === 0n || currencyBalance.value < feeValue;
|
|
59
|
-
} catch {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
})();
|
|
63
|
-
|
|
64
|
-
const handleConfirmFeeOption = () => {
|
|
65
|
-
if (!selectedFeeOption?.token || !pendingFeeOptionConfirmation?.id)
|
|
66
|
-
return;
|
|
67
|
-
|
|
68
|
-
confirmPendingFeeOption(
|
|
69
|
-
pendingFeeOptionConfirmation?.id,
|
|
70
|
-
selectedFeeOption.token.contractAddress || zeroAddress,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
onFeeOptionConfirmed();
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
if (!pendingFeeOptionConfirmation) return null;
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<div className="absolute bottom-[-140px] left-0 flex w-full flex-col gap-2 rounded-2xl bg-button-emphasis p-4 backdrop-blur-md">
|
|
80
|
-
<Text className="mb-2 font-body text-large" fontWeight="bold">
|
|
81
|
-
Select a fee option
|
|
82
|
-
</Text>
|
|
83
|
-
<WaasFeeOptionsSelect
|
|
84
|
-
options={(pendingFeeOptionConfirmation?.options as FeeOption[]) || []}
|
|
85
|
-
selectedFeeOption$={selectedFeeOption$}
|
|
86
|
-
/>
|
|
87
|
-
<div className="flex w-full items-center justify-between">
|
|
88
|
-
{currencyBalanceLoading ? (
|
|
89
|
-
<Skeleton className="w-1/3 rounded-xl" style={{ height: 15 }} />
|
|
90
|
-
) : (
|
|
91
|
-
<div className="flex items-center gap-2">
|
|
92
|
-
{insufficientBalance && (
|
|
93
|
-
<WarningIcon className="text-negative" size="xs" />
|
|
94
|
-
)}
|
|
95
|
-
<Text
|
|
96
|
-
className="font-body text-sm"
|
|
97
|
-
fontWeight="semibold"
|
|
98
|
-
color={insufficientBalance ? 'negative' : 'text100'}
|
|
99
|
-
>
|
|
100
|
-
You have {currencyBalance?.formatted || '0'}{' '}
|
|
101
|
-
{selectedFeeOption?.token.symbol}
|
|
102
|
-
</Text>
|
|
103
|
-
</div>
|
|
104
|
-
)}
|
|
105
|
-
|
|
106
|
-
<Button
|
|
107
|
-
disabled={
|
|
108
|
-
!selectedFeeOption?.token ||
|
|
109
|
-
insufficientBalance ||
|
|
110
|
-
currencyBalanceLoading
|
|
111
|
-
}
|
|
112
|
-
pending={currencyBalanceLoading}
|
|
113
|
-
onClick={handleConfirmFeeOption}
|
|
114
|
-
label={<div className="flex items-center gap-2">Confirm</div>}
|
|
115
|
-
variant={insufficientBalance ? 'danger' : 'primary'}
|
|
116
|
-
size="xs"
|
|
117
|
-
/>
|
|
118
|
-
</div>
|
|
119
|
-
</div>
|
|
120
|
-
);
|
|
121
|
-
},
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
export default WaasFeeOptionsBox;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { observable } from '@legendapp/state';
|
|
2
|
-
import type { FeeOption } from '../waasFeeOptionsSelect/WaasFeeOptionsSelect';
|
|
3
|
-
|
|
4
|
-
type WaasFeeOptionsModalState = {
|
|
5
|
-
selectedFeeOption: FeeOption | undefined;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const initialState = {
|
|
9
|
-
selectedFeeOption: undefined,
|
|
10
|
-
} as WaasFeeOptionsModalState;
|
|
11
|
-
|
|
12
|
-
export const waasFeeOptionsModal$ = observable(initialState);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|