@0xsequence/marketplace-sdk 0.5.6 → 0.6.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/dist/chunk-2J7JIOW5.js +2 -0
- package/dist/chunk-2J7JIOW5.js.map +1 -0
- package/dist/{chunk-Y75XGZOB.js → chunk-5O3ZAEEX.js} +4 -2
- package/dist/chunk-5O3ZAEEX.js.map +1 -0
- package/dist/{chunk-J6F5QOW5.js → chunk-6MYDUGVO.js} +28 -77
- package/dist/chunk-6MYDUGVO.js.map +1 -0
- package/dist/chunk-6WMO5YM5.js +94 -0
- package/dist/chunk-6WMO5YM5.js.map +1 -0
- package/dist/{chunk-AIGFG26L.js → chunk-A5ICXOCZ.js} +183 -250
- package/dist/chunk-A5ICXOCZ.js.map +1 -0
- package/dist/{chunk-4YR6AIXG.js → chunk-C42WHQRT.js} +6 -8
- package/dist/chunk-C42WHQRT.js.map +1 -0
- package/dist/{chunk-ZBLU3Q22.js → chunk-DLB2EQRX.js} +2 -2
- package/dist/{chunk-ZBLU3Q22.js.map → chunk-DLB2EQRX.js.map} +1 -1
- package/dist/{chunk-YOKGP2EQ.js → chunk-FG2BBP3P.js} +1 -1
- package/dist/{chunk-YOKGP2EQ.js.map → chunk-FG2BBP3P.js.map} +1 -1
- package/dist/{chunk-UZIAX32Y.js → chunk-GMWUIMX4.js} +10 -8
- package/dist/{chunk-UZIAX32Y.js.map → chunk-GMWUIMX4.js.map} +1 -1
- package/dist/{chunk-7C7ADZ2H.js → chunk-NKHM2AIS.js} +28 -44
- package/dist/chunk-NKHM2AIS.js.map +1 -0
- package/dist/{chunk-RIGIV5XT.js → chunk-NXORBVUS.js} +10 -4
- package/dist/chunk-NXORBVUS.js.map +1 -0
- package/dist/{chunk-7FN62HOP.js → chunk-UMYRZJVY.js} +11 -3
- package/dist/chunk-UMYRZJVY.js.map +1 -0
- package/dist/{chunk-E2V2BMF6.js → chunk-UZ3GJXBR.js} +2979 -3037
- package/dist/chunk-UZ3GJXBR.js.map +1 -0
- package/dist/{chunk-6YHHCGGY.js → chunk-VPJHNXZ2.js} +50 -74
- package/dist/chunk-VPJHNXZ2.js.map +1 -0
- package/dist/{create-config-CtFGrwXc.d.ts → create-config-CILyA_Hy.d.ts} +1 -1
- package/dist/index-BwDj_3at.d.ts +72 -0
- package/dist/index.css +12 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +175 -85
- package/dist/react/_internal/api/index.d.ts +2 -2
- package/dist/react/_internal/databeat/index.css.map +1 -1
- package/dist/react/_internal/databeat/index.js +9 -8
- package/dist/react/_internal/index.d.ts +5 -5
- package/dist/react/_internal/index.js +2 -2
- package/dist/react/_internal/wagmi/index.d.ts +2 -2
- package/dist/react/_internal/wagmi/index.js +1 -1
- package/dist/react/hooks/index.css.map +1 -1
- package/dist/react/hooks/index.d.ts +10 -79
- package/dist/react/hooks/index.js +10 -10
- package/dist/react/hooks/options/index.d.ts +8 -0
- package/dist/react/hooks/options/index.js +17 -0
- package/dist/react/hooks/options/index.js.map +1 -0
- package/dist/react/index.css +52 -35
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +6 -5
- package/dist/react/index.js +19 -14
- package/dist/react/ssr/index.d.ts +1 -0
- package/dist/react/ssr/index.js +10 -2
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/components/collectible-card/index.css +52 -35
- package/dist/react/ui/components/collectible-card/index.css.map +1 -1
- package/dist/react/ui/components/collectible-card/index.d.ts +4 -3
- package/dist/react/ui/components/collectible-card/index.js +14 -12
- package/dist/react/ui/components/marketplace-logos/index.d.ts +1 -1
- package/dist/react/ui/components/marketplace-logos/index.js +1 -1
- package/dist/react/ui/icons/index.css.map +1 -1
- package/dist/react/ui/icons/index.js +1 -1
- package/dist/react/ui/index.css +52 -35
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +2 -2
- package/dist/react/ui/index.js +14 -12
- package/dist/react/ui/modals/_internal/components/actionModal/index.css +48 -48
- package/dist/react/ui/modals/_internal/components/actionModal/index.css.map +1 -1
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +9 -8
- package/dist/react/ui/styles/index.css.map +1 -1
- package/dist/{sdk-config-xWkdBdrL.d.ts → sdk-config-Bs3H_le_.d.ts} +1 -0
- package/dist/{services-Cled3TJr.d.ts → services-C3lzi1sL.d.ts} +1 -1
- package/dist/styles/index.css +12 -6
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/index.d.ts +3 -2
- package/dist/styles/index.js +3 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +2 -2
- package/dist/{types-C4oGsbnK.d.ts → types-CPl0DH-A.d.ts} +2 -2
- package/dist/utils/abi/index.js +5 -5
- package/dist/utils/index.d.ts +10 -9
- package/dist/utils/index.js +13 -11
- package/package.json +19 -15
- package/src/consts.ts +2 -0
- package/src/react/__tests__/provider.test.tsx +4 -4
- package/src/react/_internal/api/__mocks__/indexer.msw.ts +5 -5
- package/src/react/_internal/api/__mocks__/metadata.msw.ts +2 -2
- package/src/react/_internal/api/zod-schema.ts +2 -2
- package/src/react/_internal/databeat/index.ts +11 -3
- package/src/react/_internal/types.ts +2 -2
- package/src/react/_internal/wagmi/__tests__/create-config.test.ts +6 -6
- package/src/react/_internal/wagmi/create-config.ts +11 -2
- package/src/react/_internal/wallet/__tests__/wallet.test.ts +343 -0
- package/src/react/_internal/wallet/useWallet.ts +22 -15
- package/src/react/_internal/wallet/wallet.ts +17 -11
- package/src/react/hooks/__tests__/useAutoSelectFeeOption.test.tsx +8 -12
- package/src/react/hooks/__tests__/useBalanceOfCollectible.test.tsx +6 -13
- package/src/react/hooks/__tests__/useCancelOrder.test.tsx +59 -155
- package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +21 -20
- package/src/react/hooks/__tests__/useCollectible.test.tsx +6 -7
- package/src/react/hooks/__tests__/useCollection.test.tsx +5 -6
- package/src/react/hooks/__tests__/useCollectionBalanceDetails.test.tsx +8 -16
- package/src/react/hooks/__tests__/useCollectionDetails.test.tsx +7 -6
- package/src/react/hooks/__tests__/useCollectionDetailsPolling.test.tsx +8 -12
- package/src/react/hooks/__tests__/useComparePrices.test.tsx +1 -2
- package/src/react/hooks/__tests__/useConvertPriceToUSD.test.tsx +2 -3
- package/src/react/hooks/__tests__/useCountListingsForCollectible.test.tsx +4 -5
- package/src/react/hooks/__tests__/useCountOfCollectables.test.tsx +6 -7
- package/src/react/hooks/__tests__/useCountOffersForCollectible.test.tsx +4 -5
- package/src/react/hooks/__tests__/useCurrencies.test.tsx +3 -4
- package/src/react/hooks/__tests__/useCurrency.test.tsx +4 -6
- package/src/react/hooks/__tests__/useCurrencyBalance.test.tsx +78 -84
- package/src/react/hooks/__tests__/useFilters.test.tsx +5 -6
- package/src/react/hooks/__tests__/useFloorOrder.test.tsx +5 -6
- package/src/react/hooks/__tests__/useGenerateBuyTransaction.test.tsx +6 -7
- package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +11 -67
- package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +6 -17
- package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +6 -16
- package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +7 -17
- package/src/react/hooks/__tests__/useHighestOffer.test.tsx +6 -7
- package/src/react/hooks/__tests__/useListBalances.test.tsx +4 -9
- package/src/react/hooks/__tests__/useListCollectibleActivities.test.tsx +5 -11
- package/src/react/hooks/__tests__/useListCollectibles.test.tsx +6 -7
- package/src/react/hooks/__tests__/useListCollectiblesPaginated.test.tsx +2 -3
- package/src/react/hooks/__tests__/useListCollectionActivities.test.tsx +6 -12
- package/src/react/hooks/__tests__/useListCollections.test.tsx +5 -14
- package/src/react/hooks/__tests__/useListListingsForCollectible.test.tsx +6 -7
- package/src/react/hooks/__tests__/useListOffersForCollectible.test.tsx +6 -7
- package/src/react/hooks/__tests__/useLowestListing.test.tsx +6 -7
- package/src/react/hooks/__tests__/useMarketplaceConfig.test.tsx +5 -14
- package/src/react/hooks/__tests__/useRoyaltyPercentage.test.tsx +46 -78
- package/src/react/hooks/options/__mocks__/marketplaceConfig.msw.ts +9 -4
- package/src/react/hooks/options/__tests__/marketplaceConfigOptions.test.tsx +3 -4
- package/src/react/hooks/options/collectionOptions.ts +42 -0
- package/src/react/hooks/options/index.ts +2 -0
- package/src/react/hooks/useCancelOrder.tsx +3 -3
- package/src/react/hooks/useCancelTransactionSteps.tsx +11 -11
- package/src/react/hooks/useCollection.tsx +6 -37
- package/src/react/hooks/useCollectionBalanceDetails.tsx +3 -3
- package/src/react/hooks/useCollectionDetailsPolling.tsx +1 -1
- package/src/react/hooks/useCurrencies.tsx +1 -1
- package/src/react/hooks/useCurrencyBalance.tsx +4 -5
- package/src/react/hooks/useGenerateListingTransaction.tsx +1 -1
- package/src/react/hooks/useGenerateOfferTransaction.tsx +1 -1
- package/src/react/hooks/useGetReceiptFromHash.tsx +1 -1
- package/src/react/hooks/useListCollectibleActivities.tsx +1 -1
- package/src/react/hooks/useListCollectionActivities.tsx +1 -1
- package/src/react/hooks/useRoyaltyPercentage.tsx +16 -8
- package/src/react/index.ts +1 -0
- package/src/react/provider.tsx +2 -2
- package/src/react/ssr/__tests__/create-ssr-client.test.ts +97 -0
- package/src/react/ssr/create-ssr-client.ts +1 -1
- package/src/react/ui/components/_internals/action-button/ActionButton.tsx +3 -3
- package/src/react/ui/components/_internals/action-button/components/ActionButtonBody.tsx +2 -2
- package/src/react/ui/components/_internals/action-button/components/NonOwnerActions.tsx +4 -4
- package/src/react/ui/components/_internals/action-button/components/OwnerActions.tsx +2 -2
- package/src/react/ui/components/_internals/action-button/hooks/useActionButtonLogic.ts +1 -1
- package/src/react/ui/components/_internals/custom-select/__tests__/CustomSelect.test.tsx +2 -7
- package/src/react/ui/components/collectible-card/CollectibleCard.tsx +33 -7
- package/src/react/ui/components/collectible-card/Footer.tsx +47 -8
- package/src/react/ui/components/collectible-card/styles.css.ts +26 -2
- package/src/react/ui/components/marketplace-logos/marketplace-logos.tsx +1 -1
- package/src/react/ui/icons/index.ts +2 -5
- package/src/react/ui/{icons/DiamondEye.tsx → images/marketplaces/LooksRare.tsx} +1 -1
- package/src/react/ui/modals/BuyModal/__tests__/Modal.test.tsx +10 -11
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useBuyCollectable.test.tsx +343 -0
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useCheckoutOptions.test.tsx +8 -31
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useFees.test.tsx +4 -4
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useLoadData.test.tsx +9 -36
- package/src/react/ui/modals/BuyModal/hooks/useCheckoutOptions.ts +3 -3
- package/src/react/ui/modals/BuyModal/hooks/useLoadData.ts +1 -1
- package/src/react/ui/modals/BuyModal/modals/Modal1155.tsx +25 -15
- package/src/react/ui/modals/BuyModal/modals/__tests__/CheckoutModal.test.tsx +2 -2
- package/src/react/ui/modals/BuyModal/modals/__tests__/Modal1155.test.tsx +209 -242
- package/src/react/ui/modals/CreateListingModal/Modal.tsx +3 -2
- package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +5 -11
- package/src/react/ui/modals/CreateListingModal/hooks/useGetTokenApproval.ts +1 -1
- package/src/react/ui/modals/CreateListingModal/index.tsx +1 -1
- package/src/react/ui/modals/MakeOfferModal/Modal.tsx +1 -1
- package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +46 -49
- package/src/react/ui/modals/SellModal/Modal.tsx +1 -0
- package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +9 -28
- package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +2 -2
- package/src/react/ui/modals/SuccessfulPurchaseModal/__tests__/Modal.test.tsx +3 -3
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +4 -4
- package/src/react/ui/modals/_internal/components/actionModal/store.ts +1 -1
- package/src/react/ui/modals/_internal/components/alertMessage/index.tsx +2 -3
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +4 -4
- package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +1 -1
- package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +1 -8
- package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +9 -5
- package/src/react/ui/modals/_internal/components/switchChainModal/__tests__/SwitchChainModal.test.tsx +4 -10
- package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +2 -2
- package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +1 -1
- package/src/react/ui/modals/_internal/components/transaction-footer/index.tsx +9 -3
- package/src/react/ui/modals/_internal/components/transaction-footer/transactionFooter.css.ts +11 -0
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +8 -7
- package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +4 -9
- package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/utils.test.ts +3 -3
- package/src/react/ui/modals/_internal/components/transactionStatusModal/hooks/useTransactionStatus.ts +4 -4
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +1 -1
- package/src/react/ui/modals/modal-provider.tsx +2 -2
- package/src/types/sdk-config.ts +1 -0
- package/src/utils/__tests__/address.test.ts +1 -1
- package/src/utils/__tests__/getMarketplaceDetails.test.ts +4 -4
- package/src/utils/getMarketplaceDetails.ts +7 -7
- package/src/utils/index.ts +1 -1
- package/src/utils/networkconfigToWagmiChain.ts +17 -0
- package/src/utils/price.ts +8 -0
- package/test/const.ts +35 -0
- package/test/globalSetup.ts +15 -0
- package/test/index.ts +1 -0
- package/{src/react/_internal/test → test}/mocks/wallet.ts +5 -5
- package/test/setup.ts +20 -0
- package/test/test-utils.tsx +157 -0
- package/tsconfig.json +7 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.js +5 -3
- package/dist/chunk-4YR6AIXG.js.map +0 -1
- package/dist/chunk-6YHHCGGY.js.map +0 -1
- package/dist/chunk-7C7ADZ2H.js.map +0 -1
- package/dist/chunk-7FN62HOP.js.map +0 -1
- package/dist/chunk-AIGFG26L.js.map +0 -1
- package/dist/chunk-E2V2BMF6.js.map +0 -1
- package/dist/chunk-J6F5QOW5.js.map +0 -1
- package/dist/chunk-RIGIV5XT.js.map +0 -1
- package/dist/chunk-Y75XGZOB.js.map +0 -1
- package/src/react/_internal/test/mocks/publicClient.ts +0 -39
- package/src/react/_internal/test/mocks/wagmi.ts +0 -61
- package/src/react/_internal/test/setup.ts +0 -28
- package/src/react/_internal/test-utils.tsx +0 -97
- package/src/react/ui/icons/ArrowUp.tsx +0 -32
- package/src/react/ui/icons/InventoryIcon.tsx +0 -44
- package/src/react/ui/icons/MinusIcon.tsx +0 -34
- package/src/react/ui/icons/PlusIcon.tsx +0 -32
- package/src/react/ui/icons/PositiveCircleIcon.tsx +0 -38
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useBuyCollectable.test.tsx.bak +0 -379
- package/src/utils/__tests__/get-public-rpc-client.test.ts +0 -111
- package/src/utils/get-public-rpc-client.ts +0 -41
- /package/src/react/ui/icons/{Bell.tsx → BellIcon.tsx} +0 -0
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
import { renderHook } from '@testing-library/react';
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import { useBuyCollectable } from '../useBuyCollectable';
|
|
4
|
-
import { useWallet } from '../../../../../_internal/wallet/useWallet';
|
|
5
|
-
import { useSelectPaymentModal } from '@0xsequence/kit-checkout';
|
|
6
|
-
import { useConfig } from '../../../../../hooks';
|
|
7
|
-
import { useFees } from '../useFees';
|
|
8
|
-
import {
|
|
9
|
-
MarketplaceKind,
|
|
10
|
-
TransactionCrypto,
|
|
11
|
-
WalletKind,
|
|
12
|
-
getMarketplaceClient,
|
|
13
|
-
} from '../../../../../_internal';
|
|
14
|
-
|
|
15
|
-
// Mock dependencies
|
|
16
|
-
vi.mock('@0xsequence/kit-checkout', () => ({
|
|
17
|
-
useSelectPaymentModal: vi.fn(),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
vi.mock('../../../../../_internal/wallet/useWallet', () => ({
|
|
21
|
-
useWallet: vi.fn(),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
vi.mock('../../../../../hooks', () => ({
|
|
25
|
-
useConfig: vi.fn(),
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
vi.mock('../useFees', () => ({
|
|
29
|
-
useFees: vi.fn(),
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
// Mock the buyModal$ store
|
|
33
|
-
const mockClose = vi.fn();
|
|
34
|
-
vi.mock('../store', () => ({
|
|
35
|
-
buyModal$: {
|
|
36
|
-
close: mockClose,
|
|
37
|
-
},
|
|
38
|
-
}));
|
|
39
|
-
|
|
40
|
-
vi.mock('../../../../../_internal', async () => {
|
|
41
|
-
const actual = (await vi.importActual('../../../../../_internal')) as Record<
|
|
42
|
-
string,
|
|
43
|
-
unknown
|
|
44
|
-
>;
|
|
45
|
-
return {
|
|
46
|
-
...actual,
|
|
47
|
-
getMarketplaceClient: vi.fn(() => ({
|
|
48
|
-
generateBuyTransaction: vi.fn().mockResolvedValue({
|
|
49
|
-
steps: [
|
|
50
|
-
{
|
|
51
|
-
type: 'transaction',
|
|
52
|
-
value: '1000000000000000000',
|
|
53
|
-
to: '0x123',
|
|
54
|
-
data: '0x456',
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
}),
|
|
58
|
-
})),
|
|
59
|
-
collectableKeys: {
|
|
60
|
-
listings: ['listings'],
|
|
61
|
-
listingsCount: ['listingsCount'],
|
|
62
|
-
lists: ['lists'],
|
|
63
|
-
userBalances: ['userBalances'],
|
|
64
|
-
},
|
|
65
|
-
balanceQueries: {
|
|
66
|
-
all: ['balances'],
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('useBuyCollectable', () => {
|
|
72
|
-
const defaultProps = {
|
|
73
|
-
chainId: '1',
|
|
74
|
-
collectionAddress: '0x123',
|
|
75
|
-
tokenId: '1',
|
|
76
|
-
priceCurrencyAddress: '0x0',
|
|
77
|
-
setCheckoutModalIsLoading: vi.fn(),
|
|
78
|
-
setCheckoutModalLoaded: vi.fn(),
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
beforeEach(() => {
|
|
82
|
-
vi.clearAllMocks();
|
|
83
|
-
|
|
84
|
-
// Setup default mock implementations
|
|
85
|
-
(
|
|
86
|
-
useSelectPaymentModal as unknown as ReturnType<typeof vi.fn>
|
|
87
|
-
).mockReturnValue({
|
|
88
|
-
openSelectPaymentModal: vi.fn(),
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
(useConfig as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
92
|
-
projectAccessKey: 'test-key',
|
|
93
|
-
projectId: 'test-id',
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
(useFees as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
97
|
-
amount: '250',
|
|
98
|
-
receiver: '0x123',
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should return loading state initially', () => {
|
|
103
|
-
// Mock useWallet to return loading state
|
|
104
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
105
|
-
wallet: null,
|
|
106
|
-
isLoading: true,
|
|
107
|
-
isError: false,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
const { result } = renderHook(() => useBuyCollectable(defaultProps));
|
|
111
|
-
|
|
112
|
-
expect(result.current).toEqual({
|
|
113
|
-
status: 'loading',
|
|
114
|
-
buy: null,
|
|
115
|
-
isLoading: true,
|
|
116
|
-
isError: false,
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should return error state when wallet is not available', () => {
|
|
121
|
-
// Mock useWallet to return error state
|
|
122
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
123
|
-
wallet: null,
|
|
124
|
-
isLoading: false,
|
|
125
|
-
isError: true,
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const { result } = renderHook(() => useBuyCollectable(defaultProps));
|
|
129
|
-
|
|
130
|
-
expect(result.current).toEqual({
|
|
131
|
-
status: 'error',
|
|
132
|
-
buy: null,
|
|
133
|
-
isLoading: false,
|
|
134
|
-
isError: true,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// Also test when wallet is undefined but no error
|
|
138
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
139
|
-
wallet: undefined,
|
|
140
|
-
isLoading: false,
|
|
141
|
-
isError: false,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const { result: result2 } = renderHook(() =>
|
|
145
|
-
useBuyCollectable(defaultProps),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
expect(result2.current).toEqual({
|
|
149
|
-
status: 'error',
|
|
150
|
-
buy: null,
|
|
151
|
-
isLoading: false,
|
|
152
|
-
isError: true,
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('should call buy function with correct parameters', async () => {
|
|
157
|
-
// Mock useWallet to return a valid wallet
|
|
158
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
159
|
-
wallet: {
|
|
160
|
-
kind: WalletKind.sequence,
|
|
161
|
-
address: async () => '0x123',
|
|
162
|
-
chainId: '1',
|
|
163
|
-
},
|
|
164
|
-
isLoading: false,
|
|
165
|
-
isError: false,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
const openSelectPaymentModalMock = vi.fn();
|
|
169
|
-
(
|
|
170
|
-
useSelectPaymentModal as unknown as ReturnType<typeof vi.fn>
|
|
171
|
-
).mockReturnValue({
|
|
172
|
-
openSelectPaymentModal: openSelectPaymentModalMock,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const generateBuyTransactionMock = vi.fn().mockResolvedValue({
|
|
176
|
-
steps: [
|
|
177
|
-
{
|
|
178
|
-
type: 'transaction',
|
|
179
|
-
value: '1000000000000000000',
|
|
180
|
-
to: '0x123',
|
|
181
|
-
data: '0x456',
|
|
182
|
-
},
|
|
183
|
-
],
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
const marketplaceClientMock = {
|
|
187
|
-
generateBuyTransaction: generateBuyTransactionMock,
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
(
|
|
191
|
-
getMarketplaceClient as unknown as ReturnType<typeof vi.fn>
|
|
192
|
-
).mockReturnValue(marketplaceClientMock);
|
|
193
|
-
|
|
194
|
-
const { result } = renderHook(() => useBuyCollectable(defaultProps));
|
|
195
|
-
|
|
196
|
-
if (result.current.status === 'ready') {
|
|
197
|
-
await result.current.buy({
|
|
198
|
-
orderId: '1',
|
|
199
|
-
quantity: '1',
|
|
200
|
-
collectableDecimals: 18,
|
|
201
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
202
|
-
checkoutOptions: {
|
|
203
|
-
swap: [],
|
|
204
|
-
nftCheckout: [],
|
|
205
|
-
onRamp: [],
|
|
206
|
-
crypto: TransactionCrypto.all,
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
expect(generateBuyTransactionMock).toHaveBeenCalledWith({
|
|
212
|
-
collectionAddress: defaultProps.collectionAddress,
|
|
213
|
-
buyer: '0x123',
|
|
214
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
215
|
-
ordersData: [
|
|
216
|
-
{
|
|
217
|
-
orderId: '1',
|
|
218
|
-
quantity: '1',
|
|
219
|
-
},
|
|
220
|
-
],
|
|
221
|
-
additionalFees: [
|
|
222
|
-
{
|
|
223
|
-
amount: '250',
|
|
224
|
-
receiver: '0x123',
|
|
225
|
-
},
|
|
226
|
-
],
|
|
227
|
-
walletType: WalletKind.unknown,
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
expect(openSelectPaymentModalMock).toHaveBeenCalledWith({
|
|
231
|
-
chain: defaultProps.chainId,
|
|
232
|
-
collectibles: [
|
|
233
|
-
{
|
|
234
|
-
tokenId: defaultProps.tokenId,
|
|
235
|
-
quantity: '1',
|
|
236
|
-
decimals: 18,
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
currencyAddress: defaultProps.priceCurrencyAddress,
|
|
240
|
-
price: '1000000000000000000',
|
|
241
|
-
targetContractAddress: '0x123',
|
|
242
|
-
txData: '0x456',
|
|
243
|
-
collectionAddress: defaultProps.collectionAddress,
|
|
244
|
-
recipientAddress: '0x123',
|
|
245
|
-
enableMainCurrencyPayment: true,
|
|
246
|
-
enableSwapPayments: true,
|
|
247
|
-
creditCardProviders: [],
|
|
248
|
-
onSuccess: expect.any(Function),
|
|
249
|
-
onError: undefined,
|
|
250
|
-
onClose: expect.any(Function),
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
expect(defaultProps.setCheckoutModalIsLoading).toHaveBeenCalledWith(true);
|
|
254
|
-
expect(defaultProps.setCheckoutModalLoaded).toHaveBeenCalledWith(true);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('should handle success callback', async () => {
|
|
258
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
259
|
-
wallet: {
|
|
260
|
-
kind: WalletKind.sequence,
|
|
261
|
-
address: async () => '0x123',
|
|
262
|
-
chainId: '1',
|
|
263
|
-
},
|
|
264
|
-
isLoading: false,
|
|
265
|
-
isError: false,
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
const openSelectPaymentModalMock = vi.fn();
|
|
269
|
-
(
|
|
270
|
-
useSelectPaymentModal as unknown as ReturnType<typeof vi.fn>
|
|
271
|
-
).mockReturnValue({
|
|
272
|
-
openSelectPaymentModal: openSelectPaymentModalMock,
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
const generateBuyTransactionMock = vi.fn().mockResolvedValue({
|
|
276
|
-
steps: [
|
|
277
|
-
{
|
|
278
|
-
type: 'transaction',
|
|
279
|
-
value: '1000000000000000000',
|
|
280
|
-
to: '0x123',
|
|
281
|
-
data: '0x456',
|
|
282
|
-
},
|
|
283
|
-
],
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
const marketplaceClientMock = {
|
|
287
|
-
generateBuyTransaction: generateBuyTransactionMock,
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
(
|
|
291
|
-
getMarketplaceClient as unknown as ReturnType<typeof vi.fn>
|
|
292
|
-
).mockReturnValue(marketplaceClientMock);
|
|
293
|
-
|
|
294
|
-
const onSuccessMock = vi.fn();
|
|
295
|
-
const props = {
|
|
296
|
-
...defaultProps,
|
|
297
|
-
callbacks: {
|
|
298
|
-
onSuccess: onSuccessMock,
|
|
299
|
-
},
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
const { result } = renderHook(() => useBuyCollectable(props));
|
|
303
|
-
|
|
304
|
-
if (result.current.status === 'ready') {
|
|
305
|
-
await result.current.buy({
|
|
306
|
-
orderId: '1',
|
|
307
|
-
quantity: '1',
|
|
308
|
-
collectableDecimals: 18,
|
|
309
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
310
|
-
checkoutOptions: {
|
|
311
|
-
swap: [],
|
|
312
|
-
nftCheckout: [],
|
|
313
|
-
onRamp: [],
|
|
314
|
-
crypto: TransactionCrypto.all,
|
|
315
|
-
},
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const onSuccessCallback =
|
|
320
|
-
openSelectPaymentModalMock.mock.calls[0][0].onSuccess;
|
|
321
|
-
|
|
322
|
-
const txHash = '0x789';
|
|
323
|
-
await onSuccessCallback(txHash);
|
|
324
|
-
|
|
325
|
-
expect(onSuccessMock).toHaveBeenCalledWith({ hash: txHash });
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
it('should handle error callback', async () => {
|
|
329
|
-
// Mock useWallet to return a valid wallet
|
|
330
|
-
(useWallet as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
331
|
-
wallet: {
|
|
332
|
-
kind: WalletKind.sequence,
|
|
333
|
-
address: async () => '0x123',
|
|
334
|
-
chainId: '1',
|
|
335
|
-
},
|
|
336
|
-
isLoading: false,
|
|
337
|
-
isError: false,
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
const openSelectPaymentModalMock = vi.fn();
|
|
341
|
-
(
|
|
342
|
-
useSelectPaymentModal as unknown as ReturnType<typeof vi.fn>
|
|
343
|
-
).mockReturnValue({
|
|
344
|
-
openSelectPaymentModal: openSelectPaymentModalMock,
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
const onErrorMock = vi.fn();
|
|
348
|
-
const props = {
|
|
349
|
-
...defaultProps,
|
|
350
|
-
callbacks: {
|
|
351
|
-
onError: onErrorMock,
|
|
352
|
-
},
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
const { result } = renderHook(() => useBuyCollectable(props));
|
|
356
|
-
|
|
357
|
-
if (result.current.status === 'ready') {
|
|
358
|
-
await result.current.buy({
|
|
359
|
-
orderId: '1',
|
|
360
|
-
quantity: '1',
|
|
361
|
-
collectableDecimals: 18,
|
|
362
|
-
marketplace: MarketplaceKind.sequence_marketplace_v2,
|
|
363
|
-
checkoutOptions: {
|
|
364
|
-
swap: [],
|
|
365
|
-
nftCheckout: [],
|
|
366
|
-
onRamp: [],
|
|
367
|
-
crypto: TransactionCrypto.all,
|
|
368
|
-
},
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const onErrorCallback = openSelectPaymentModalMock.mock.calls[0][0].onError;
|
|
373
|
-
|
|
374
|
-
const error = new Error('Transaction failed');
|
|
375
|
-
onErrorCallback(error);
|
|
376
|
-
|
|
377
|
-
expect(onErrorMock).toHaveBeenCalledWith(error);
|
|
378
|
-
});
|
|
379
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import { getPublicRpcClient } from '../get-public-rpc-client';
|
|
3
|
-
import { allNetworks, findNetworkConfig } from '@0xsequence/network';
|
|
4
|
-
import { MissingConfigError } from '../_internal/error/transaction';
|
|
5
|
-
import type { PublicClient } from 'viem';
|
|
6
|
-
|
|
7
|
-
describe('getPublicRpcClient', () => {
|
|
8
|
-
describe('successful client creation', () => {
|
|
9
|
-
test('should create client for mainnet', () => {
|
|
10
|
-
const chainId = 1;
|
|
11
|
-
const client = getPublicRpcClient(chainId);
|
|
12
|
-
|
|
13
|
-
expect(client).toBeDefined();
|
|
14
|
-
expect(client).toHaveProperty('chain');
|
|
15
|
-
expect(
|
|
16
|
-
(client as PublicClient & { chain: { id: number } }).chain.id,
|
|
17
|
-
).toBe(chainId);
|
|
18
|
-
expect(
|
|
19
|
-
(client as PublicClient & { chain: { name: string } }).chain.name,
|
|
20
|
-
).toBe('mainnet');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('should create client for polygon', () => {
|
|
24
|
-
const chainId = 137;
|
|
25
|
-
const client = getPublicRpcClient(chainId);
|
|
26
|
-
|
|
27
|
-
expect(client).toBeDefined();
|
|
28
|
-
expect(
|
|
29
|
-
(client as PublicClient & { chain: { id: number } }).chain.id,
|
|
30
|
-
).toBe(chainId);
|
|
31
|
-
expect(
|
|
32
|
-
(client as PublicClient & { chain: { name: string } }).chain.name,
|
|
33
|
-
).toBe('polygon');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('should set up multicall batching', () => {
|
|
37
|
-
const chainId = 1;
|
|
38
|
-
const client = getPublicRpcClient(chainId);
|
|
39
|
-
|
|
40
|
-
expect(client).toHaveProperty('batch');
|
|
41
|
-
expect(
|
|
42
|
-
(client as PublicClient & { batch: { multicall: boolean } }).batch
|
|
43
|
-
.multicall,
|
|
44
|
-
).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('should configure RPC URLs correctly', () => {
|
|
48
|
-
const chainId = 1;
|
|
49
|
-
const network = findNetworkConfig(allNetworks, chainId);
|
|
50
|
-
expect(network).toBeDefined();
|
|
51
|
-
const client = getPublicRpcClient(chainId);
|
|
52
|
-
|
|
53
|
-
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
54
|
-
expect(client.chain!.rpcUrls.default.http).toEqual([network!.rpcUrl]);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('should set up native currency details', () => {
|
|
58
|
-
const chainId = 1;
|
|
59
|
-
const network = findNetworkConfig(allNetworks, chainId);
|
|
60
|
-
expect(network).toBeDefined();
|
|
61
|
-
const client = getPublicRpcClient(chainId);
|
|
62
|
-
|
|
63
|
-
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
64
|
-
expect(client.chain!.nativeCurrency).toEqual(network!.nativeToken);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('error handling', () => {
|
|
69
|
-
test('should throw MissingConfigError for invalid chainId', () => {
|
|
70
|
-
const invalidChainId = 999999;
|
|
71
|
-
|
|
72
|
-
expect(() => getPublicRpcClient(invalidChainId)).toThrow(
|
|
73
|
-
MissingConfigError,
|
|
74
|
-
);
|
|
75
|
-
expect(() => getPublicRpcClient(invalidChainId)).toThrow(
|
|
76
|
-
`Network configuration for chainId: ${invalidChainId}`,
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('should throw MissingConfigError for undefined chainId', () => {
|
|
81
|
-
const undefinedChainId = undefined as unknown as number;
|
|
82
|
-
|
|
83
|
-
expect(() => getPublicRpcClient(undefinedChainId)).toThrow(
|
|
84
|
-
`Network configuration for chainId: ${undefinedChainId}`,
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('client configuration', () => {
|
|
90
|
-
test('should create client with correct transport configuration', () => {
|
|
91
|
-
const chainId = 1;
|
|
92
|
-
const client = getPublicRpcClient(chainId);
|
|
93
|
-
|
|
94
|
-
expect(client).toHaveProperty('transport');
|
|
95
|
-
expect(client.transport).toHaveProperty('request');
|
|
96
|
-
expect(typeof client.transport.request).toBe('function');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('should create unique instances for different chains', () => {
|
|
100
|
-
const mainnetClient = getPublicRpcClient(1);
|
|
101
|
-
const polygonClient = getPublicRpcClient(137);
|
|
102
|
-
|
|
103
|
-
expect(mainnetClient).not.toBe(polygonClient);
|
|
104
|
-
expect(
|
|
105
|
-
(mainnetClient as PublicClient & { chain: { id: number } }).chain.id,
|
|
106
|
-
).not.toBe(
|
|
107
|
-
(polygonClient as PublicClient & { chain: { id: number } }).chain.id,
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { allNetworks, findNetworkConfig } from '@0xsequence/network';
|
|
2
|
-
import { http, type PublicClient, createPublicClient } from 'viem';
|
|
3
|
-
import type { ChainId } from '../react/_internal';
|
|
4
|
-
import { MissingConfigError } from './_internal/error/transaction';
|
|
5
|
-
|
|
6
|
-
export const getPublicRpcClient = (chainId: ChainId): PublicClient => {
|
|
7
|
-
if (chainId === undefined) {
|
|
8
|
-
throw new MissingConfigError(
|
|
9
|
-
`Network configuration for chainId: ${chainId}`,
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const network = findNetworkConfig(allNetworks, chainId);
|
|
14
|
-
|
|
15
|
-
if (!network) {
|
|
16
|
-
throw new MissingConfigError(
|
|
17
|
-
`Network configuration for chainId: ${chainId}`,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return createPublicClient({
|
|
22
|
-
chain: {
|
|
23
|
-
...network,
|
|
24
|
-
id: Number(chainId),
|
|
25
|
-
name: network.name,
|
|
26
|
-
nativeCurrency: { ...network.nativeToken },
|
|
27
|
-
rpcUrls: {
|
|
28
|
-
default: {
|
|
29
|
-
http: [network.rpcUrl],
|
|
30
|
-
},
|
|
31
|
-
public: {
|
|
32
|
-
http: [network.rpcUrl],
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
batch: {
|
|
37
|
-
multicall: true,
|
|
38
|
-
},
|
|
39
|
-
transport: http(),
|
|
40
|
-
});
|
|
41
|
-
};
|
|
File without changes
|