@0xsequence/marketplace-sdk 0.7.0 → 0.8.0
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/fuzzy-forks-smoke.md +5 -0
- package/CHANGELOG.md +7 -0
- package/dist/chunk-2MSBZYLW.js +128 -0
- package/dist/chunk-2MSBZYLW.js.map +1 -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-XNA64MZQ.js → chunk-BCO4CYE4.js} +2 -2
- 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-QKGZXS4T.js} +147 -357
- package/dist/chunk-QKGZXS4T.js.map +1 -0
- package/dist/{chunk-HTFORA4Q.js → chunk-SBI52HTX.js} +1880 -1010
- package/dist/chunk-SBI52HTX.js.map +1 -0
- package/dist/{chunk-XTGMMNV5.js → chunk-WHFXVREI.js} +2 -2
- 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 +9 -9
- 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 +11 -10
- 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 +10 -19
- 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 +14 -23
- 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 +14 -13
- package/dist/react/ui/components/marketplace-logos/index.js +1 -1
- package/dist/react/ui/icons/index.js +7 -7
- package/dist/react/ui/index.d.ts +18 -22
- package/dist/react/ui/index.js +14 -13
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +6 -11
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +11 -10
- package/dist/types/index.js +2 -2
- package/dist/{types-Ct1uCT3M.d.ts → types-o_pKUpQG.d.ts} +2 -5
- package/dist/utils/abi/index.js +5 -5
- package/dist/utils/index.d.ts +1 -5
- package/dist/utils/index.js +9 -9
- 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 +67 -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-XNA64MZQ.js.map → chunk-BCO4CYE4.js.map} +0 -0
- /package/dist/{chunk-Q5URKSC4.js.map → chunk-FMEEJFAF.js.map} +0 -0
- /package/dist/{chunk-XTGMMNV5.js.map → chunk-WHFXVREI.js.map} +0 -0
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { renderHook, server } from '@test';
|
|
2
|
-
import { http, HttpResponse } from 'msw';
|
|
3
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import { mock, useAccount, useConnect, useDisconnect } from 'wagmi';
|
|
5
|
-
import { MarketplaceKind, WalletKind } from '../../_internal';
|
|
6
|
-
import {
|
|
7
|
-
mockMarketplaceEndpoint,
|
|
8
|
-
mockSteps,
|
|
9
|
-
} from '../../_internal/api/__mocks__/marketplace.msw';
|
|
10
|
-
import { useGenerateBuyTransaction } from '../useGenerateBuyTransaction';
|
|
11
|
-
|
|
12
|
-
describe('useGenerateBuyTransaction', () => {
|
|
13
|
-
const defaultArgs = {
|
|
14
|
-
chainId: '1',
|
|
15
|
-
collectionAddress:
|
|
16
|
-
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' as `0x${string}`,
|
|
17
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
18
|
-
ordersData: [
|
|
19
|
-
{
|
|
20
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
21
|
-
orderId: '1',
|
|
22
|
-
quantity: '1',
|
|
23
|
-
price: '1',
|
|
24
|
-
currency: 'ETH',
|
|
25
|
-
currencyAddress:
|
|
26
|
-
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' as `0x${string}`,
|
|
27
|
-
currencyDecimals: 18,
|
|
28
|
-
currencySymbol: 'ETH',
|
|
29
|
-
currencyName: 'Ether',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
walletType: WalletKind.sequence,
|
|
33
|
-
query: {},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
vi.clearAllMocks();
|
|
38
|
-
|
|
39
|
-
// Mock default steps response with delay to simulate loading state
|
|
40
|
-
server.use(
|
|
41
|
-
http.post(mockMarketplaceEndpoint('GenerateBuyTransaction'), async () => {
|
|
42
|
-
await new Promise((resolve) => setTimeout(resolve, 100)); // Add small delay
|
|
43
|
-
return HttpResponse.json({
|
|
44
|
-
steps: mockSteps,
|
|
45
|
-
});
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should skip query when no address is available', async () => {
|
|
51
|
-
const { result: generateBuyTransactionResult } = renderHook(() =>
|
|
52
|
-
useGenerateBuyTransaction(defaultArgs),
|
|
53
|
-
);
|
|
54
|
-
const { result: disconnectResult } = renderHook(() => useDisconnect());
|
|
55
|
-
|
|
56
|
-
// make sure we are disconnected
|
|
57
|
-
await disconnectResult.current.disconnectAsync();
|
|
58
|
-
|
|
59
|
-
expect(generateBuyTransactionResult.current.isLoading).toBe(false);
|
|
60
|
-
expect(generateBuyTransactionResult.current.error).toBeNull();
|
|
61
|
-
expect(generateBuyTransactionResult.current.data).toBeUndefined();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should fetch transaction data when wallet is connected', async () => {
|
|
65
|
-
// Setup mock wallet connection
|
|
66
|
-
const mockAddress = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
|
|
67
|
-
const { result: accountResult } = renderHook(() => useAccount());
|
|
68
|
-
const { result: connectResult } = renderHook(() => useConnect());
|
|
69
|
-
|
|
70
|
-
await connectResult.current.connectAsync({
|
|
71
|
-
connector: mock({
|
|
72
|
-
accounts: [mockAddress],
|
|
73
|
-
}),
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// Ensure we have a connected wallet
|
|
77
|
-
expect(accountResult.current.address).toBe(mockAddress);
|
|
78
|
-
|
|
79
|
-
const { result } = renderHook(() => useGenerateBuyTransaction(defaultArgs));
|
|
80
|
-
|
|
81
|
-
// Initial state should be loading
|
|
82
|
-
expect(result.current.isLoading).toBe(true);
|
|
83
|
-
expect(result.current.data).toBeUndefined();
|
|
84
|
-
|
|
85
|
-
// Wait for the query to complete
|
|
86
|
-
await vi.waitFor(() => {
|
|
87
|
-
expect(result.current.isLoading).toBe(false);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Verify the data matches our mock
|
|
91
|
-
expect(result.current.error).toBeNull();
|
|
92
|
-
expect(result.current.data).toEqual(mockSteps);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should handle API errors correctly', async () => {
|
|
96
|
-
// Setup mock wallet connection
|
|
97
|
-
const mockAddress = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
|
|
98
|
-
const { result: connectResult } = renderHook(() => useConnect());
|
|
99
|
-
|
|
100
|
-
await connectResult.current.connectAsync({
|
|
101
|
-
connector: mock({
|
|
102
|
-
accounts: [mockAddress],
|
|
103
|
-
}),
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// Mock API error response
|
|
107
|
-
server.use(
|
|
108
|
-
http.post(mockMarketplaceEndpoint('GenerateBuyTransaction'), () => {
|
|
109
|
-
return HttpResponse.json(
|
|
110
|
-
{ message: 'Invalid order data' },
|
|
111
|
-
{ status: 400 },
|
|
112
|
-
);
|
|
113
|
-
}),
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const { result } = renderHook(() => useGenerateBuyTransaction(defaultArgs));
|
|
117
|
-
|
|
118
|
-
// Initial state should be loading
|
|
119
|
-
expect(result.current.isLoading).toBe(true);
|
|
120
|
-
expect(result.current.error).toBeNull();
|
|
121
|
-
expect(result.current.data).toBeUndefined();
|
|
122
|
-
|
|
123
|
-
// Wait for the query to complete
|
|
124
|
-
await vi.waitFor(() => {
|
|
125
|
-
expect(result.current.isLoading).toBe(false);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// Verify error state
|
|
129
|
-
expect(result.current.error).toBeTruthy();
|
|
130
|
-
expect(result.current.data).toBeUndefined();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should handle invalid input arguments correctly', async () => {
|
|
134
|
-
// Setup mock wallet connection
|
|
135
|
-
const mockAddress = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
|
|
136
|
-
const { result: connectResult } = renderHook(() => useConnect());
|
|
137
|
-
|
|
138
|
-
await connectResult.current.connectAsync({
|
|
139
|
-
connector: mock({
|
|
140
|
-
accounts: [mockAddress],
|
|
141
|
-
}),
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Create invalid args by omitting required fields and using invalid types
|
|
145
|
-
const invalidArgs = {
|
|
146
|
-
...defaultArgs,
|
|
147
|
-
chainId: 1, // Should be string
|
|
148
|
-
collectionAddress: 'invalid-address', // Invalid address format
|
|
149
|
-
ordersData: [
|
|
150
|
-
{
|
|
151
|
-
...defaultArgs.ordersData[0],
|
|
152
|
-
quantity: 1, // Should be string
|
|
153
|
-
orderId: undefined, // Required field missing
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const { result } = renderHook(() =>
|
|
159
|
-
// @ts-expect-error - Testing runtime validation
|
|
160
|
-
useGenerateBuyTransaction(invalidArgs),
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
// Wait for the query to complete
|
|
164
|
-
await vi.waitFor(() => {
|
|
165
|
-
expect(result.current.isLoading).toBe(false);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// Verify validation error state
|
|
169
|
-
expect(result.current.error).toBeTruthy();
|
|
170
|
-
expect(result.current.data).toBeUndefined();
|
|
171
|
-
});
|
|
172
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { queryOptions, skipToken, useQuery } from '@tanstack/react-query';
|
|
2
|
-
import type { Hex } from 'viem';
|
|
3
|
-
import { useAccount } from 'wagmi';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import type { SdkConfig } from '../../types';
|
|
6
|
-
import {
|
|
7
|
-
AddressSchema,
|
|
8
|
-
ChainIdSchema,
|
|
9
|
-
MarketplaceKind,
|
|
10
|
-
QueryArgSchema,
|
|
11
|
-
WalletKind,
|
|
12
|
-
getMarketplaceClient,
|
|
13
|
-
} from '../_internal';
|
|
14
|
-
import { useConfig } from './useConfig';
|
|
15
|
-
|
|
16
|
-
export const UseGenerateBuyTransactionArgsSchema = z.object({
|
|
17
|
-
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
18
|
-
collectionAddress: AddressSchema,
|
|
19
|
-
marketplace: z.nativeEnum(MarketplaceKind),
|
|
20
|
-
ordersData: z.array(
|
|
21
|
-
z.object({
|
|
22
|
-
orderId: z.string(),
|
|
23
|
-
quantity: z.string(),
|
|
24
|
-
marketplace: z.string(),
|
|
25
|
-
tokenId: z.string().optional(),
|
|
26
|
-
}),
|
|
27
|
-
),
|
|
28
|
-
walletType: z.nativeEnum(WalletKind).optional(),
|
|
29
|
-
query: QueryArgSchema,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
type UseGenerateBuyTransactionArgs = z.infer<
|
|
33
|
-
typeof UseGenerateBuyTransactionArgsSchema
|
|
34
|
-
>;
|
|
35
|
-
|
|
36
|
-
export const fetchGenerateBuyTransaction = async (
|
|
37
|
-
args: UseGenerateBuyTransactionArgs & { buyer: Hex },
|
|
38
|
-
config: SdkConfig,
|
|
39
|
-
) => {
|
|
40
|
-
const parsedArgs = UseGenerateBuyTransactionArgsSchema.parse(args);
|
|
41
|
-
const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
|
|
42
|
-
|
|
43
|
-
return marketplaceClient
|
|
44
|
-
.generateBuyTransaction({
|
|
45
|
-
...parsedArgs,
|
|
46
|
-
buyer: args.buyer,
|
|
47
|
-
additionalFees: [], // TODO: Add additional fees
|
|
48
|
-
})
|
|
49
|
-
.then((data) => data.steps);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const generateBuyTransactionOptions = (
|
|
53
|
-
args: UseGenerateBuyTransactionArgs & { buyer: Hex },
|
|
54
|
-
config: SdkConfig,
|
|
55
|
-
) => {
|
|
56
|
-
return queryOptions({
|
|
57
|
-
queryKey: ['generateBuyTransaction', args],
|
|
58
|
-
queryFn: () => fetchGenerateBuyTransaction(args, config),
|
|
59
|
-
...args.query,
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const useGenerateBuyTransaction = (
|
|
64
|
-
args: UseGenerateBuyTransactionArgs,
|
|
65
|
-
) => {
|
|
66
|
-
const { address } = useAccount();
|
|
67
|
-
const config = useConfig();
|
|
68
|
-
|
|
69
|
-
return useQuery({
|
|
70
|
-
queryKey: ['generateBuyTransaction', args],
|
|
71
|
-
queryFn: address
|
|
72
|
-
? () => {
|
|
73
|
-
return fetchGenerateBuyTransaction(
|
|
74
|
-
{ buyer: address, ...args },
|
|
75
|
-
config,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
: skipToken,
|
|
79
|
-
});
|
|
80
|
-
};
|
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
import { useSelectPaymentModal } from '@0xsequence/checkout';
|
|
2
|
-
import { renderHook } from '@testing-library/react';
|
|
3
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
MarketplaceKind,
|
|
7
|
-
WalletKind,
|
|
8
|
-
} from '../../../../../_internal/api/marketplace.gen';
|
|
9
|
-
import { TransactionCrypto } from '../../../../../_internal/api/marketplace.gen';
|
|
10
|
-
import { getMarketplaceClient } from '../../../../../_internal/api/services';
|
|
11
|
-
import { useWallet } from '../../../../../_internal/wallet/useWallet';
|
|
12
|
-
import { useConfig } from '../../../../../hooks';
|
|
13
|
-
import { useBuyCollectable } from '../useBuyCollectable';
|
|
14
|
-
import { useFees } from '../useFees';
|
|
15
|
-
|
|
16
|
-
// Mock dependencies
|
|
17
|
-
vi.mock('@0xsequence/checkout', () => ({
|
|
18
|
-
useSelectPaymentModal: vi.fn(),
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
vi.mock('../../../../../_internal/wallet/useWallet', () => ({
|
|
22
|
-
useWallet: vi.fn(),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
vi.mock('../../../../../hooks', () => ({
|
|
26
|
-
useConfig: vi.fn(),
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
vi.mock('../useFees', () => ({
|
|
30
|
-
useFees: vi.fn(),
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
vi.mock('../../../../../_internal', (actualImport) => {
|
|
34
|
-
const actualModule = actualImport();
|
|
35
|
-
return {
|
|
36
|
-
getMarketplaceClient: vi.fn(),
|
|
37
|
-
...actualModule,
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('useBuyCollectable', () => {
|
|
42
|
-
const defaultProps = {
|
|
43
|
-
chainId: '1',
|
|
44
|
-
collectionAddress: '0x123',
|
|
45
|
-
tokenId: '1',
|
|
46
|
-
priceCurrencyAddress: '0x0',
|
|
47
|
-
setCheckoutModalIsLoading: vi.fn(),
|
|
48
|
-
setCheckoutModalLoaded: vi.fn(),
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
beforeEach(() => {
|
|
52
|
-
vi.clearAllMocks();
|
|
53
|
-
|
|
54
|
-
// Setup default mock implementations
|
|
55
|
-
(
|
|
56
|
-
useSelectPaymentModal as unknown as ReturnType<typeof vi.fn>
|
|
57
|
-
).mockReturnValue({
|
|
58
|
-
openSelectPaymentModal: vi.fn(),
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
(useConfig as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
62
|
-
projectAccessKey: 'test-key',
|
|
63
|
-
projectId: 'test-id',
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
(useFees as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
67
|
-
amount: '250',
|
|
68
|
-
receiver: '0x123',
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should return loading state initially', () => {
|
|
73
|
-
// Mock useWallet to return loading state
|
|
74
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
75
|
-
wallet: null,
|
|
76
|
-
isLoading: true,
|
|
77
|
-
isError: false,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const { result } = renderHook(() => useBuyCollectable(defaultProps));
|
|
81
|
-
|
|
82
|
-
expect(result.current).toEqual({
|
|
83
|
-
status: 'loading',
|
|
84
|
-
buy: null,
|
|
85
|
-
isLoading: true,
|
|
86
|
-
isError: false,
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should return error state when wallet is not available', () => {
|
|
91
|
-
// Mock useWallet to return error state
|
|
92
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
93
|
-
wallet: null,
|
|
94
|
-
isLoading: false,
|
|
95
|
-
isError: true,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const { result } = renderHook(() => useBuyCollectable(defaultProps));
|
|
99
|
-
|
|
100
|
-
expect(result.current).toEqual({
|
|
101
|
-
status: 'error',
|
|
102
|
-
buy: null,
|
|
103
|
-
isLoading: false,
|
|
104
|
-
isError: true,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Also test when wallet is undefined but no error
|
|
108
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
109
|
-
wallet: undefined,
|
|
110
|
-
isLoading: false,
|
|
111
|
-
isError: false,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const { result: result2 } = renderHook(() =>
|
|
115
|
-
useBuyCollectable(defaultProps),
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
expect(result2.current).toEqual({
|
|
119
|
-
status: 'error',
|
|
120
|
-
buy: null,
|
|
121
|
-
isLoading: false,
|
|
122
|
-
isError: true,
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it.skip('should call buy function with correct parameters', async () => {
|
|
127
|
-
// Mock useWallet to return a valid wallet
|
|
128
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
129
|
-
wallet: {
|
|
130
|
-
kind: WalletKind.sequence,
|
|
131
|
-
address: async () => '0x123',
|
|
132
|
-
chainId: '1',
|
|
133
|
-
},
|
|
134
|
-
isLoading: false,
|
|
135
|
-
isError: false,
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const openSelectPaymentModalMock = vi.fn();
|
|
139
|
-
(
|
|
140
|
-
useSelectPaymentModal as unknown as ReturnType<typeof vi.fn>
|
|
141
|
-
).mockReturnValue({
|
|
142
|
-
openSelectPaymentModal: openSelectPaymentModalMock,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const generateBuyTransactionMock = vi.fn().mockResolvedValue({
|
|
146
|
-
steps: [
|
|
147
|
-
{
|
|
148
|
-
type: 'transaction',
|
|
149
|
-
value: '1000000000000000000',
|
|
150
|
-
to: '0x123',
|
|
151
|
-
data: '0x456',
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const marketplaceClientMock = {
|
|
157
|
-
generateBuyTransaction: generateBuyTransactionMock,
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
(
|
|
161
|
-
getMarketplaceClient as unknown as ReturnType<typeof vi.fn>
|
|
162
|
-
).mockReturnValue(marketplaceClientMock);
|
|
163
|
-
|
|
164
|
-
const { result } = renderHook(() => useBuyCollectable(defaultProps));
|
|
165
|
-
|
|
166
|
-
if (result.current.status === 'ready') {
|
|
167
|
-
await result.current.buy({
|
|
168
|
-
orderId: '1',
|
|
169
|
-
quantity: '1',
|
|
170
|
-
collectableDecimals: 18,
|
|
171
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
172
|
-
checkoutOptions: {
|
|
173
|
-
swap: [],
|
|
174
|
-
nftCheckout: [],
|
|
175
|
-
onRamp: [],
|
|
176
|
-
crypto: TransactionCrypto.all,
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
expect(generateBuyTransactionMock).toHaveBeenCalledWith({
|
|
182
|
-
collectionAddress: defaultProps.collectionAddress,
|
|
183
|
-
buyer: '0x123',
|
|
184
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
185
|
-
ordersData: [
|
|
186
|
-
{
|
|
187
|
-
orderId: '1',
|
|
188
|
-
quantity: '1',
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
additionalFees: [
|
|
192
|
-
{
|
|
193
|
-
amount: '250',
|
|
194
|
-
receiver: '0x123',
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
walletType: WalletKind.unknown,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
expect(openSelectPaymentModalMock).toHaveBeenCalledWith({
|
|
201
|
-
chain: defaultProps.chainId,
|
|
202
|
-
collectibles: [
|
|
203
|
-
{
|
|
204
|
-
tokenId: defaultProps.tokenId,
|
|
205
|
-
quantity: '1',
|
|
206
|
-
decimals: 18,
|
|
207
|
-
},
|
|
208
|
-
],
|
|
209
|
-
currencyAddress: defaultProps.priceCurrencyAddress,
|
|
210
|
-
price: '1000000000000000000',
|
|
211
|
-
targetContractAddress: '0x123',
|
|
212
|
-
txData: '0x456',
|
|
213
|
-
collectionAddress: defaultProps.collectionAddress,
|
|
214
|
-
recipientAddress: '0x123',
|
|
215
|
-
enableMainCurrencyPayment: true,
|
|
216
|
-
enableSwapPayments: true,
|
|
217
|
-
creditCardProviders: [],
|
|
218
|
-
onSuccess: expect.any(Function),
|
|
219
|
-
onError: undefined,
|
|
220
|
-
onClose: expect.any(Function),
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
expect(defaultProps.setCheckoutModalIsLoading).toHaveBeenCalledWith(true);
|
|
224
|
-
expect(defaultProps.setCheckoutModalLoaded).toHaveBeenCalledWith(true);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it.skip('should handle success callback', async () => {
|
|
228
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
229
|
-
wallet: {
|
|
230
|
-
kind: WalletKind.sequence,
|
|
231
|
-
address: async () => '0x123',
|
|
232
|
-
chainId: '1',
|
|
233
|
-
},
|
|
234
|
-
isLoading: false,
|
|
235
|
-
isError: false,
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
const openSelectPaymentModalMock = vi.fn();
|
|
239
|
-
(
|
|
240
|
-
useSelectPaymentModal as unknown as ReturnType<typeof vi.fn>
|
|
241
|
-
).mockReturnValue({
|
|
242
|
-
openSelectPaymentModal: openSelectPaymentModalMock,
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// const generateBuyTransactionMock = vi.fn().mockResolvedValue({
|
|
246
|
-
// steps: [
|
|
247
|
-
// {
|
|
248
|
-
// type: 'transaction',
|
|
249
|
-
// value: '1000000000000000000',
|
|
250
|
-
// to: '0x123',
|
|
251
|
-
// data: '0x456',
|
|
252
|
-
// },
|
|
253
|
-
// ],
|
|
254
|
-
// });
|
|
255
|
-
|
|
256
|
-
// const marketplaceClientMock = {
|
|
257
|
-
// generateBuyTransaction: generateBuyTransactionMock,
|
|
258
|
-
// };
|
|
259
|
-
|
|
260
|
-
// (
|
|
261
|
-
// getMarketplaceClient as unknown as ReturnType<typeof vi.fn>
|
|
262
|
-
// ).mockReturnValue(marketplaceClientMock);
|
|
263
|
-
|
|
264
|
-
const onSuccessMock = vi.fn();
|
|
265
|
-
const props = {
|
|
266
|
-
...defaultProps,
|
|
267
|
-
callbacks: {
|
|
268
|
-
onSuccess: onSuccessMock,
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
const { result } = renderHook(() => useBuyCollectable(props));
|
|
273
|
-
|
|
274
|
-
if (result.current.status === 'ready') {
|
|
275
|
-
await result.current.buy({
|
|
276
|
-
orderId: '1',
|
|
277
|
-
quantity: '1',
|
|
278
|
-
collectableDecimals: 18,
|
|
279
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
280
|
-
checkoutOptions: {
|
|
281
|
-
swap: [],
|
|
282
|
-
nftCheckout: [],
|
|
283
|
-
onRamp: [],
|
|
284
|
-
crypto: TransactionCrypto.all,
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const onSuccessCallback =
|
|
290
|
-
openSelectPaymentModalMock.mock.calls[0][0].onSuccess;
|
|
291
|
-
|
|
292
|
-
const txHash = '0x789';
|
|
293
|
-
await onSuccessCallback(txHash);
|
|
294
|
-
|
|
295
|
-
expect(onSuccessMock).toHaveBeenCalledWith({ hash: txHash });
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it.skip('should handle error callback', async () => {
|
|
299
|
-
// Mock useWallet to return a valid wallet
|
|
300
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
301
|
-
wallet: {
|
|
302
|
-
kind: WalletKind.sequence,
|
|
303
|
-
address: async () => '0x123',
|
|
304
|
-
chainId: '1',
|
|
305
|
-
},
|
|
306
|
-
isLoading: false,
|
|
307
|
-
isError: false,
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
const openSelectPaymentModalMock = vi.fn();
|
|
311
|
-
(
|
|
312
|
-
useSelectPaymentModal as unknown as ReturnType<typeof vi.fn>
|
|
313
|
-
).mockReturnValue({
|
|
314
|
-
openSelectPaymentModal: openSelectPaymentModalMock,
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
const onErrorMock = vi.fn();
|
|
318
|
-
const props = {
|
|
319
|
-
...defaultProps,
|
|
320
|
-
callbacks: {
|
|
321
|
-
onError: onErrorMock,
|
|
322
|
-
},
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
const { result } = renderHook(() => useBuyCollectable(props));
|
|
326
|
-
|
|
327
|
-
if (result.current.status === 'ready') {
|
|
328
|
-
await result.current.buy({
|
|
329
|
-
orderId: '1',
|
|
330
|
-
quantity: '1',
|
|
331
|
-
collectableDecimals: 18,
|
|
332
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
333
|
-
checkoutOptions: {
|
|
334
|
-
swap: [],
|
|
335
|
-
nftCheckout: [],
|
|
336
|
-
onRamp: [],
|
|
337
|
-
crypto: TransactionCrypto.all,
|
|
338
|
-
},
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const onErrorCallback = openSelectPaymentModalMock.mock.calls[0][0].onError;
|
|
343
|
-
|
|
344
|
-
const error = new Error('Transaction failed');
|
|
345
|
-
onErrorCallback(error);
|
|
346
|
-
|
|
347
|
-
expect(onErrorMock).toHaveBeenCalledWith(error);
|
|
348
|
-
});
|
|
349
|
-
});
|