@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
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { server } from '@test';
|
|
2
|
+
import {
|
|
3
|
+
type Account,
|
|
4
|
+
type Address,
|
|
5
|
+
type Chain,
|
|
6
|
+
type PublicClient,
|
|
7
|
+
type WalletClient,
|
|
8
|
+
hexToBigInt,
|
|
9
|
+
} from 'viem';
|
|
10
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
11
|
+
import type { Connector } from 'wagmi';
|
|
12
|
+
import type { SdkConfig } from '../../../../types';
|
|
13
|
+
import {
|
|
14
|
+
ChainSwitchError,
|
|
15
|
+
TransactionExecutionError,
|
|
16
|
+
TransactionSignatureError,
|
|
17
|
+
UserRejectedRequestError,
|
|
18
|
+
} from '../../../../utils/_internal/error/transaction';
|
|
19
|
+
import { StepType, WalletKind } from '../../api';
|
|
20
|
+
import { mockIndexerHandler } from '../../api/__mocks__/indexer.msw';
|
|
21
|
+
import { mockMetadataHandler } from '../../api/__mocks__/metadata.msw';
|
|
22
|
+
import type { SignatureStep, TransactionStep } from '../../utils';
|
|
23
|
+
import { wallet } from '../wallet';
|
|
24
|
+
|
|
25
|
+
describe('wallet', () => {
|
|
26
|
+
const mockChains = [
|
|
27
|
+
{ id: 1, name: 'Ethereum' },
|
|
28
|
+
{ id: 137, name: 'Polygon' },
|
|
29
|
+
] as unknown as readonly [Chain, ...Chain[]];
|
|
30
|
+
|
|
31
|
+
const mockAddress = '0x1234567890123456789012345678901234567890' as Address;
|
|
32
|
+
const mockAccount: Account = {
|
|
33
|
+
address: mockAddress,
|
|
34
|
+
type: 'json-rpc',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const mockConnector = {
|
|
38
|
+
id: 'sequence',
|
|
39
|
+
name: 'Sequence',
|
|
40
|
+
type: 'injected',
|
|
41
|
+
connect: vi.fn(),
|
|
42
|
+
disconnect: vi.fn(),
|
|
43
|
+
getAccount: vi.fn(),
|
|
44
|
+
getAccounts: vi.fn(),
|
|
45
|
+
getChainId: vi.fn(),
|
|
46
|
+
getProvider: vi.fn(),
|
|
47
|
+
isAuthorized: vi.fn(),
|
|
48
|
+
onAccountsChanged: vi.fn(),
|
|
49
|
+
onChainChanged: vi.fn(),
|
|
50
|
+
onDisconnect: vi.fn(),
|
|
51
|
+
} as unknown as Connector;
|
|
52
|
+
|
|
53
|
+
const mockTransport = {
|
|
54
|
+
key: 'mock',
|
|
55
|
+
name: 'Mock Transport',
|
|
56
|
+
request: vi.fn(),
|
|
57
|
+
type: 'mock',
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const mockWalletClient = {
|
|
61
|
+
account: mockAccount,
|
|
62
|
+
transport: mockTransport,
|
|
63
|
+
type: 'walletClient',
|
|
64
|
+
chain: mockChains[0],
|
|
65
|
+
uid: 'test-uid',
|
|
66
|
+
key: 'mock',
|
|
67
|
+
name: 'Mock Wallet',
|
|
68
|
+
cacheTime: 0,
|
|
69
|
+
pollingInterval: 0,
|
|
70
|
+
request: vi.fn(),
|
|
71
|
+
extend: vi.fn(),
|
|
72
|
+
getChainId: vi.fn().mockResolvedValue(1),
|
|
73
|
+
getAddresses: vi.fn().mockResolvedValue([mockAddress]),
|
|
74
|
+
switchChain: vi.fn(),
|
|
75
|
+
signMessage: vi.fn(),
|
|
76
|
+
signTypedData: vi.fn(),
|
|
77
|
+
sendTransaction: vi.fn(),
|
|
78
|
+
signTransaction: vi.fn(),
|
|
79
|
+
addChain: vi.fn(),
|
|
80
|
+
deployContract: vi.fn(),
|
|
81
|
+
getPermissions: vi.fn(),
|
|
82
|
+
requestAddresses: vi.fn(),
|
|
83
|
+
requestPermissions: vi.fn(),
|
|
84
|
+
watchAsset: vi.fn(),
|
|
85
|
+
writeContract: vi.fn(),
|
|
86
|
+
prepareTransactionRequest: vi.fn(),
|
|
87
|
+
sendRawTransaction: vi.fn(),
|
|
88
|
+
} as unknown as WalletClient & { account: Account };
|
|
89
|
+
|
|
90
|
+
const mockSdkConfig: SdkConfig = {
|
|
91
|
+
projectAccessKey: 'test-key',
|
|
92
|
+
projectId: 'test-project',
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const mockPublicClient = {
|
|
96
|
+
readContract: vi.fn(),
|
|
97
|
+
} as unknown as PublicClient;
|
|
98
|
+
|
|
99
|
+
let walletInstance: ReturnType<typeof wallet>;
|
|
100
|
+
|
|
101
|
+
beforeEach(() => {
|
|
102
|
+
walletInstance = wallet({
|
|
103
|
+
wallet: mockWalletClient,
|
|
104
|
+
chains: mockChains,
|
|
105
|
+
connector: mockConnector,
|
|
106
|
+
sdkConfig: mockSdkConfig,
|
|
107
|
+
publicClient: mockPublicClient,
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('initialization', () => {
|
|
112
|
+
it('should create wallet instance with correct properties', () => {
|
|
113
|
+
expect(walletInstance.transport).toBeDefined();
|
|
114
|
+
expect(walletInstance.isWaaS).toBe(false);
|
|
115
|
+
expect(walletInstance.walletKind).toBe(WalletKind.sequence);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('address', () => {
|
|
120
|
+
it('should return wallet address', async () => {
|
|
121
|
+
const address = await walletInstance.address();
|
|
122
|
+
expect(address).toBe(mockAddress);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('switchChain', () => {
|
|
127
|
+
it('should switch chain successfully', async () => {
|
|
128
|
+
await walletInstance.switchChain(137);
|
|
129
|
+
expect(mockWalletClient.switchChain).toHaveBeenCalledWith({ id: 137 });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should throw ChainSwitchError on unsupported chain switch', async () => {
|
|
133
|
+
vi.mocked(mockWalletClient.switchChain).mockRejectedValueOnce({
|
|
134
|
+
name: 'SwitchChainNotSupportedError',
|
|
135
|
+
});
|
|
136
|
+
await expect(walletInstance.switchChain(137)).rejects.toThrow(
|
|
137
|
+
ChainSwitchError,
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should throw UserRejectedRequestError when user rejects chain switch', async () => {
|
|
142
|
+
vi.mocked(mockWalletClient.switchChain).mockRejectedValueOnce({
|
|
143
|
+
name: 'UserRejectedRequestError',
|
|
144
|
+
});
|
|
145
|
+
await expect(walletInstance.switchChain(137)).rejects.toThrow(
|
|
146
|
+
UserRejectedRequestError,
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('handleSignMessageStep', () => {
|
|
152
|
+
const mockSignatureStep: SignatureStep = {
|
|
153
|
+
id: StepType.signEIP191,
|
|
154
|
+
data: '0xmessage',
|
|
155
|
+
to: '0x456' as Address,
|
|
156
|
+
value: '0x0',
|
|
157
|
+
price: '0x0',
|
|
158
|
+
post: {
|
|
159
|
+
endpoint: '/api/test',
|
|
160
|
+
method: 'POST',
|
|
161
|
+
body: {},
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
it('should handle EIP-191 signature', async () => {
|
|
166
|
+
// Add MSW handler for any API calls that might happen during signing
|
|
167
|
+
server.use(
|
|
168
|
+
mockIndexerHandler('GetTokenBalances', {
|
|
169
|
+
page: { page: 1, pageSize: 10, more: false },
|
|
170
|
+
balances: [],
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const mockSignature = '0xsignature';
|
|
175
|
+
vi.mocked(mockWalletClient.signMessage).mockResolvedValueOnce(
|
|
176
|
+
mockSignature,
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const result =
|
|
180
|
+
await walletInstance.handleSignMessageStep(mockSignatureStep);
|
|
181
|
+
|
|
182
|
+
expect(result).toBe(mockSignature);
|
|
183
|
+
expect(mockWalletClient.signMessage).toHaveBeenCalled();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('should handle EIP-712 signature', async () => {
|
|
187
|
+
const mockEip712Step: SignatureStep & {
|
|
188
|
+
signature: NonNullable<SignatureStep['signature']>;
|
|
189
|
+
} = {
|
|
190
|
+
id: StepType.signEIP712,
|
|
191
|
+
data: '0x',
|
|
192
|
+
to: '0x456' as Address,
|
|
193
|
+
price: '0x0',
|
|
194
|
+
value: '0x0',
|
|
195
|
+
post: {
|
|
196
|
+
endpoint: '/api/test',
|
|
197
|
+
method: 'POST',
|
|
198
|
+
body: {},
|
|
199
|
+
},
|
|
200
|
+
signature: {
|
|
201
|
+
domain: {
|
|
202
|
+
name: 'Test Domain',
|
|
203
|
+
version: '1',
|
|
204
|
+
chainId: 1,
|
|
205
|
+
verifyingContract: '0x123' as Address,
|
|
206
|
+
},
|
|
207
|
+
types: {},
|
|
208
|
+
primaryType: 'Mail',
|
|
209
|
+
value: {},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// Add specific handler for EIP-712 signing
|
|
214
|
+
server.use(
|
|
215
|
+
mockMetadataHandler('GetContractInfo', {
|
|
216
|
+
contractInfo: {
|
|
217
|
+
address: mockEip712Step.signature.domain.verifyingContract,
|
|
218
|
+
chainId: mockEip712Step.signature.domain.chainId,
|
|
219
|
+
name: mockEip712Step.signature.domain.name,
|
|
220
|
+
type: 'ERC721',
|
|
221
|
+
},
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const mockSignature = '0xsignature';
|
|
226
|
+
vi.mocked(mockWalletClient.signTypedData).mockResolvedValueOnce(
|
|
227
|
+
mockSignature,
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
const result = await walletInstance.handleSignMessageStep(mockEip712Step);
|
|
231
|
+
|
|
232
|
+
expect(result).toBe(mockSignature);
|
|
233
|
+
expect(mockWalletClient.signTypedData).toHaveBeenCalled();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('should throw TransactionSignatureError on signature failure', async () => {
|
|
237
|
+
vi.mocked(mockWalletClient.signMessage).mockRejectedValueOnce(
|
|
238
|
+
new Error('Signature failed'),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
await expect(
|
|
242
|
+
walletInstance.handleSignMessageStep(mockSignatureStep),
|
|
243
|
+
).rejects.toThrow(TransactionSignatureError);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe('handleSendTransactionStep', () => {
|
|
248
|
+
const mockTxStep: TransactionStep = {
|
|
249
|
+
id: StepType.buy,
|
|
250
|
+
to: '0x456' as Address,
|
|
251
|
+
value: '0x0',
|
|
252
|
+
data: '0x',
|
|
253
|
+
price: '0x0',
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
it('should send transaction successfully', async () => {
|
|
257
|
+
// Add MSW handler for transaction-related API calls
|
|
258
|
+
server.use(
|
|
259
|
+
mockIndexerHandler('FetchTransactionReceipt', {
|
|
260
|
+
receipt: {
|
|
261
|
+
txnHash: '0xtxhash',
|
|
262
|
+
txnStatus: 'SUCCESSFUL',
|
|
263
|
+
},
|
|
264
|
+
}),
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const mockTxHash = '0xtxhash';
|
|
268
|
+
vi.mocked(mockWalletClient.sendTransaction).mockResolvedValueOnce(
|
|
269
|
+
mockTxHash,
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const result = await walletInstance.handleSendTransactionStep(
|
|
273
|
+
1,
|
|
274
|
+
mockTxStep,
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
expect(result).toBe(mockTxHash);
|
|
278
|
+
expect(mockWalletClient.sendTransaction).toHaveBeenCalledWith(
|
|
279
|
+
expect.objectContaining({
|
|
280
|
+
to: mockTxStep.to,
|
|
281
|
+
value: hexToBigInt('0x0'),
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('should throw TransactionExecutionError on transaction failure', async () => {
|
|
287
|
+
vi.mocked(mockWalletClient.sendTransaction).mockRejectedValueOnce(
|
|
288
|
+
new Error('Transaction failed'),
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
await expect(
|
|
292
|
+
walletInstance.handleSendTransactionStep(1, mockTxStep),
|
|
293
|
+
).rejects.toThrow(TransactionExecutionError);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('should handle transaction with contract interaction', async () => {
|
|
297
|
+
const mockContractTxStep: TransactionStep = {
|
|
298
|
+
id: StepType.buy,
|
|
299
|
+
to: '0x456' as Address,
|
|
300
|
+
price: '0x0',
|
|
301
|
+
value: '0x0',
|
|
302
|
+
data: '0x123456', // Mock contract interaction data
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// Add handlers for contract-related API calls
|
|
306
|
+
server.use(
|
|
307
|
+
mockIndexerHandler('FetchTransactionReceipt', {
|
|
308
|
+
receipt: {
|
|
309
|
+
txnHash: '0xtxhash',
|
|
310
|
+
txnStatus: 'SUCCESSFUL',
|
|
311
|
+
logs: [],
|
|
312
|
+
},
|
|
313
|
+
}),
|
|
314
|
+
mockMetadataHandler('GetContractInfo', {
|
|
315
|
+
contractInfo: {
|
|
316
|
+
address: mockContractTxStep.to,
|
|
317
|
+
chainId: 1,
|
|
318
|
+
name: 'Test Contract',
|
|
319
|
+
type: 'ERC721',
|
|
320
|
+
},
|
|
321
|
+
}),
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const mockTxHash = '0xtxhash';
|
|
325
|
+
vi.mocked(mockWalletClient.sendTransaction).mockResolvedValueOnce(
|
|
326
|
+
mockTxHash,
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
const result = await walletInstance.handleSendTransactionStep(
|
|
330
|
+
1,
|
|
331
|
+
mockContractTxStep,
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
expect(result).toBe(mockTxHash);
|
|
335
|
+
expect(mockWalletClient.sendTransaction).toHaveBeenCalledWith(
|
|
336
|
+
expect.objectContaining({
|
|
337
|
+
to: mockContractTxStep.to,
|
|
338
|
+
data: mockContractTxStep.data,
|
|
339
|
+
}),
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
});
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { skipToken, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import {
|
|
3
|
+
useAccount,
|
|
4
|
+
useChainId,
|
|
5
|
+
usePublicClient,
|
|
6
|
+
useSwitchChain,
|
|
7
|
+
useWalletClient,
|
|
8
|
+
} from 'wagmi';
|
|
4
9
|
import { useConfig } from '../../hooks';
|
|
10
|
+
import { type WalletInstance, wallet } from './wallet';
|
|
5
11
|
|
|
6
12
|
type UseWalletReturn = {
|
|
7
13
|
wallet: WalletInstance | null | undefined;
|
|
@@ -16,22 +22,23 @@ export const useWallet = (): UseWalletReturn => {
|
|
|
16
22
|
const { connector, isConnected, isConnecting } = useAccount();
|
|
17
23
|
const sdkConfig = useConfig();
|
|
18
24
|
const chainId = useChainId();
|
|
25
|
+
const publicClient = usePublicClient();
|
|
19
26
|
|
|
20
27
|
const { data, isLoading, isError } = useQuery({
|
|
21
28
|
queryKey: ['wallet', chainId, connector?.uid],
|
|
22
|
-
queryFn:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
queryFn:
|
|
30
|
+
walletClient && connector && isConnected && publicClient
|
|
31
|
+
? () => {
|
|
32
|
+
return wallet({
|
|
33
|
+
wallet: walletClient,
|
|
34
|
+
chains,
|
|
35
|
+
connector,
|
|
36
|
+
sdkConfig,
|
|
37
|
+
publicClient,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
: skipToken,
|
|
33
41
|
staleTime: Number.POSITIVE_INFINITY,
|
|
34
|
-
enabled: Boolean(walletClient && connector && isConnected),
|
|
35
42
|
});
|
|
36
43
|
|
|
37
44
|
return {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { TransactionReceipt } from '@0xsequence/indexer';
|
|
1
2
|
import {
|
|
2
3
|
type Account,
|
|
3
4
|
type Address,
|
|
4
5
|
type Chain,
|
|
5
6
|
type Hex,
|
|
7
|
+
type PublicClient,
|
|
6
8
|
TransactionReceiptNotFoundError,
|
|
7
9
|
type TypedDataDomain,
|
|
8
10
|
type WalletClient as ViemWalletClient,
|
|
@@ -15,7 +17,12 @@ import {
|
|
|
15
17
|
} from 'viem';
|
|
16
18
|
import type { Connector } from 'wagmi';
|
|
17
19
|
import type { SwitchChainErrorType } from 'wagmi/actions';
|
|
18
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
SEQUENCE_MARKET_V1_ADDRESS,
|
|
22
|
+
SEQUENCE_MARKET_V2_ADDRESS,
|
|
23
|
+
} from '../../../consts';
|
|
24
|
+
import type { SdkConfig } from '../../../types';
|
|
25
|
+
import { ERC1155_ABI } from '../../../utils';
|
|
19
26
|
import {
|
|
20
27
|
ChainSwitchError,
|
|
21
28
|
TransactionConfirmationError,
|
|
@@ -23,15 +30,9 @@ import {
|
|
|
23
30
|
TransactionSignatureError,
|
|
24
31
|
UserRejectedRequestError,
|
|
25
32
|
} from '../../../utils/_internal/error/transaction';
|
|
26
|
-
import {
|
|
33
|
+
import { StepType, WalletKind, getIndexerClient } from '../api';
|
|
27
34
|
import { createLogger } from '../logger';
|
|
28
35
|
import type { SignatureStep, TransactionStep } from '../utils';
|
|
29
|
-
import {
|
|
30
|
-
SEQUENCE_MARKET_V1_ADDRESS,
|
|
31
|
-
SEQUENCE_MARKET_V2_ADDRESS,
|
|
32
|
-
} from '../../../consts';
|
|
33
|
-
import type { SdkConfig } from '../../../types';
|
|
34
|
-
import type { TransactionReceipt } from '@0xsequence/indexer';
|
|
35
36
|
|
|
36
37
|
interface WalletClient extends Omit<ViemWalletClient, 'account'> {
|
|
37
38
|
account: Account;
|
|
@@ -60,24 +61,30 @@ export interface WalletInstance {
|
|
|
60
61
|
}) => Promise<bigint | boolean>;
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
const isSequenceWallet = (connector: Connector) =>
|
|
65
|
+
connector.id === 'sequence' || connector.id === 'sequence-waas';
|
|
66
|
+
|
|
63
67
|
export const wallet = ({
|
|
64
68
|
wallet,
|
|
65
69
|
chains,
|
|
66
70
|
connector,
|
|
67
71
|
sdkConfig,
|
|
72
|
+
publicClient,
|
|
68
73
|
}: {
|
|
69
74
|
wallet: WalletClient;
|
|
70
75
|
chains: readonly [Chain, ...Chain[]];
|
|
71
76
|
connector: Connector;
|
|
72
77
|
sdkConfig: SdkConfig;
|
|
78
|
+
publicClient: PublicClient;
|
|
73
79
|
}): WalletInstance => {
|
|
74
80
|
const logger = createLogger('Wallet');
|
|
75
81
|
|
|
76
82
|
const walletInstance = {
|
|
77
83
|
transport: custom(wallet.transport),
|
|
78
84
|
isWaaS: connector.id.endsWith('waas'),
|
|
79
|
-
walletKind:
|
|
80
|
-
|
|
85
|
+
walletKind: isSequenceWallet(connector)
|
|
86
|
+
? WalletKind.sequence
|
|
87
|
+
: WalletKind.unknown,
|
|
81
88
|
getChainId: wallet.getChainId,
|
|
82
89
|
address: async () => {
|
|
83
90
|
let address = wallet.account?.address;
|
|
@@ -202,7 +209,6 @@ export const wallet = ({
|
|
|
202
209
|
contractAddress: Address;
|
|
203
210
|
spender: Address | 'sequenceMarketV1' | 'sequenceMarketV2';
|
|
204
211
|
}) => {
|
|
205
|
-
const publicClient = getPublicRpcClient(await wallet.getChainId());
|
|
206
212
|
const walletAddress = await walletInstance.address();
|
|
207
213
|
const spenderAddress =
|
|
208
214
|
spender === 'sequenceMarketV1'
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { renderHook, waitFor } from '../../_internal/test-utils';
|
|
4
|
-
import { zeroAddress } from 'viem';
|
|
1
|
+
import { useChain } from '@0xsequence/kit';
|
|
2
|
+
import { renderHook, server, waitFor } from '@test';
|
|
5
3
|
import { http, HttpResponse } from 'msw';
|
|
6
|
-
import {
|
|
4
|
+
import { zeroAddress } from 'viem';
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import { useAccount } from 'wagmi';
|
|
7
|
+
import { mainnet } from 'wagmi/chains';
|
|
7
8
|
import {
|
|
8
|
-
mockTokenBalance,
|
|
9
9
|
mockIndexerEndpoint,
|
|
10
10
|
mockIndexerHandler,
|
|
11
|
+
mockTokenBalance,
|
|
11
12
|
} from '../../_internal/api/__mocks__/indexer.msw';
|
|
12
|
-
import { useAccount } from 'wagmi';
|
|
13
|
-
import { useChain } from '@0xsequence/kit';
|
|
14
|
-
import { mainnet } from 'wagmi/chains';
|
|
15
13
|
import type { FeeOption } from '../../ui/modals/_internal/components/waasFeeOptionsSelect/WaasFeeOptionsSelect';
|
|
14
|
+
import { useAutoSelectFeeOption } from '../useAutoSelectFeeOption';
|
|
16
15
|
|
|
17
16
|
// Mock wagmi hooks
|
|
18
17
|
vi.mock('wagmi', async () => {
|
|
@@ -74,9 +73,6 @@ describe('useAutoSelectFeeOption', () => {
|
|
|
74
73
|
};
|
|
75
74
|
|
|
76
75
|
beforeEach(() => {
|
|
77
|
-
// Reset handlers before each test
|
|
78
|
-
server.resetHandlers();
|
|
79
|
-
|
|
80
76
|
// Mock useAccount hook with complete wagmi account type
|
|
81
77
|
vi.mocked(useAccount).mockReturnValue({
|
|
82
78
|
address: mockUserAddress as `0x${string}`,
|
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { renderHook, server, waitFor } from '@test';
|
|
2
|
+
import { http, HttpResponse } from 'msw';
|
|
3
|
+
import { zeroAddress } from 'viem';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
4
5
|
import {
|
|
6
|
+
mockIndexerEndpoint,
|
|
5
7
|
mockTokenBalance,
|
|
6
|
-
enableDebug,
|
|
7
8
|
} from '../../_internal/api/__mocks__/indexer.msw';
|
|
8
|
-
import {
|
|
9
|
-
import { server } from '../../_internal/test/setup';
|
|
10
|
-
import { http, HttpResponse } from 'msw';
|
|
11
|
-
import { mockIndexerEndpoint } from '../../_internal/api/__mocks__/indexer.msw';
|
|
9
|
+
import { useBalanceOfCollectible } from '../useBalanceOfCollectible';
|
|
12
10
|
|
|
13
11
|
describe('useBalanceOfCollectible', () => {
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
vi.clearAllMocks();
|
|
16
|
-
enableDebug();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
12
|
const defaultArgs = {
|
|
20
13
|
collectionAddress: zeroAddress,
|
|
21
14
|
collectableId: '1',
|