diff --git a/packages/dapp-kit-ui/src/class/connect-modal-manager.ts b/packages/dapp-kit-ui/src/classes/connect-modal-manager.ts similarity index 100% rename from packages/dapp-kit-ui/src/class/connect-modal-manager.ts rename to packages/dapp-kit-ui/src/classes/connect-modal-manager.ts diff --git a/packages/dapp-kit-ui/src/class/custom-wallet-connect-modal.ts b/packages/dapp-kit-ui/src/classes/custom-wallet-connect-modal.ts similarity index 100% rename from packages/dapp-kit-ui/src/class/custom-wallet-connect-modal.ts rename to packages/dapp-kit-ui/src/classes/custom-wallet-connect-modal.ts diff --git a/packages/dapp-kit-ui/src/class/index.ts b/packages/dapp-kit-ui/src/classes/index.ts similarity index 100% rename from packages/dapp-kit-ui/src/class/index.ts rename to packages/dapp-kit-ui/src/classes/index.ts diff --git a/packages/dapp-kit-ui/src/client.ts b/packages/dapp-kit-ui/src/client.ts index 879099c3..7025a3e9 100644 --- a/packages/dapp-kit-ui/src/client.ts +++ b/packages/dapp-kit-ui/src/client.ts @@ -1,7 +1,7 @@ /// import type { DAppKitOptions, WalletManager } from '@vechain/dapp-kit'; import { DAppKit } from '@vechain/dapp-kit'; -import { CustomWalletConnectModal, ConnectModalManager } from './class'; +import { CustomWalletConnectModal, ConnectModalManager } from './classes'; import { type CustomizedStyle, dispatchCustomEvent, diff --git a/packages/dapp-kit-ui/src/index.ts b/packages/dapp-kit-ui/src/index.ts index 2d9c17cb..d66fd5dd 100644 --- a/packages/dapp-kit-ui/src/index.ts +++ b/packages/dapp-kit-ui/src/index.ts @@ -2,4 +2,4 @@ export * from './client'; export * from './components'; export * from './constants'; export * from './utils'; -export * from './class'; +export * from './classes'; diff --git a/packages/dapp-kit/src/wallets/certificate-wallet.ts b/packages/dapp-kit/src/classes/certificate-wallet.ts similarity index 96% rename from packages/dapp-kit/src/wallets/certificate-wallet.ts rename to packages/dapp-kit/src/classes/certificate-wallet.ts index 98841142..1a0350a9 100644 --- a/packages/dapp-kit/src/wallets/certificate-wallet.ts +++ b/packages/dapp-kit/src/classes/certificate-wallet.ts @@ -1,6 +1,6 @@ import { Certificate } from 'thor-devkit'; import type { BaseWallet, ConnectResponse, ConnexWallet } from '../types'; -import { DEFAULT_CONNECT_CERT_MESSAGE } from '../certificates'; +import { DEFAULT_CONNECT_CERT_MESSAGE } from '../constants'; /** * A `ConnexWallet` for wallet's that use a certificate connection diff --git a/packages/dapp-kit/src/classes/index.ts b/packages/dapp-kit/src/classes/index.ts new file mode 100644 index 00000000..0f251e78 --- /dev/null +++ b/packages/dapp-kit/src/classes/index.ts @@ -0,0 +1,3 @@ +export * from './wallet-manager'; +export * from './certificate-wallet'; +export * from './wc-wallet'; diff --git a/packages/dapp-kit/src/wallet-manager.ts b/packages/dapp-kit/src/classes/wallet-manager.ts similarity index 96% rename from packages/dapp-kit/src/wallet-manager.ts rename to packages/dapp-kit/src/classes/wallet-manager.ts index b92aefe8..3c1660ae 100644 --- a/packages/dapp-kit/src/wallet-manager.ts +++ b/packages/dapp-kit/src/classes/wallet-manager.ts @@ -7,12 +7,9 @@ import type { DAppKitOptions, WalletManagerState, WalletSource, -} from './types'; -import { createWallet } from './create-wallet'; -import { WalletSources } from './wallet'; -import { Storage } from './local-storage'; -import { DAppKitLogger } from './utils'; -import { DEFAULT_CONNECT_CERT_MESSAGE } from './certificates'; +} from '../types'; +import { DAppKitLogger, Storage, createWallet } from '../utils'; +import { DEFAULT_CONNECT_CERT_MESSAGE, WalletSources } from '../constants'; class WalletManager { public readonly state: WalletManagerState; diff --git a/packages/dapp-kit/src/wallets/wc-wallet.ts b/packages/dapp-kit/src/classes/wc-wallet.ts similarity index 86% rename from packages/dapp-kit/src/wallets/wc-wallet.ts rename to packages/dapp-kit/src/classes/wc-wallet.ts index 3c5ac167..a07ae5f6 100644 --- a/packages/dapp-kit/src/wallets/wc-wallet.ts +++ b/packages/dapp-kit/src/classes/wc-wallet.ts @@ -1,5 +1,4 @@ -import type { WCSigner } from '../wallet-connect'; -import type { ConnectResponse, ConnexWallet } from '../types'; +import type { ConnectResponse, ConnexWallet, WCSigner } from '../types'; class WCWallet implements ConnexWallet { constructor(private readonly signer: WCSigner) {} diff --git a/packages/dapp-kit/src/certificates.ts b/packages/dapp-kit/src/constants/certificates.ts similarity index 100% rename from packages/dapp-kit/src/certificates.ts rename to packages/dapp-kit/src/constants/certificates.ts diff --git a/packages/dapp-kit/src/genesis.ts b/packages/dapp-kit/src/constants/genesis-blocks.ts similarity index 76% rename from packages/dapp-kit/src/genesis.ts rename to packages/dapp-kit/src/constants/genesis-blocks.ts index 8dc91acb..e15faeed 100644 --- a/packages/dapp-kit/src/genesis.ts +++ b/packages/dapp-kit/src/constants/genesis-blocks.ts @@ -1,5 +1,3 @@ -import type { Genesis } from './types'; - type NetworkType = 'main' | 'test'; export const genesisBlocks: Record = { @@ -48,22 +46,3 @@ export const genesisBlocks: Record = { transactions: [], }, }; - -const normalizeGenesisId = (genesis?: Genesis): string => { - if (!genesis) return genesisBlocks.main.id; - - if (genesis === 'main' || genesis === 'test') - return genesisBlocks[genesis].id; - - return genesis.id; -}; - -const normalizeGenesisBlock = (genesis?: Genesis): Connex.Thor.Block => { - if (!genesis) return genesisBlocks.main; - - if (genesis === 'main' || genesis === 'test') return genesisBlocks[genesis]; - - return genesis; -}; - -export { normalizeGenesisId, normalizeGenesisBlock }; diff --git a/packages/dapp-kit/src/constants/index.ts b/packages/dapp-kit/src/constants/index.ts new file mode 100644 index 00000000..7aab048c --- /dev/null +++ b/packages/dapp-kit/src/constants/index.ts @@ -0,0 +1,4 @@ +export * from './certificates'; +export * from './genesis-blocks'; +export * from './wallet-settings'; +export * from './wallet-connect'; diff --git a/packages/dapp-kit/src/wallet-connect/constants.ts b/packages/dapp-kit/src/constants/wallet-connect.ts similarity index 100% rename from packages/dapp-kit/src/wallet-connect/constants.ts rename to packages/dapp-kit/src/constants/wallet-connect.ts diff --git a/packages/dapp-kit/src/wallet.ts b/packages/dapp-kit/src/constants/wallet-settings.ts similarity index 88% rename from packages/dapp-kit/src/wallet.ts rename to packages/dapp-kit/src/constants/wallet-settings.ts index 40630ecd..bfbc9b81 100644 --- a/packages/dapp-kit/src/wallet.ts +++ b/packages/dapp-kit/src/constants/wallet-settings.ts @@ -2,7 +2,7 @@ * Wallet types */ -import type { WalletConfig, WalletSource } from './types'; +import type { WalletConfig, WalletSource } from '../types'; const DEFAULT_CONFIG: WalletConfig = { requiresCertificate: true, diff --git a/packages/dapp-kit/src/dapp-kit.ts b/packages/dapp-kit/src/dapp-kit.ts index 4474f1c8..85ccc8df 100644 --- a/packages/dapp-kit/src/dapp-kit.ts +++ b/packages/dapp-kit/src/dapp-kit.ts @@ -4,9 +4,8 @@ import { } from '@vechain/connex-driver/dist/index.js'; import { Framework } from '@vechain/connex-framework'; import { blake2b256 } from 'thor-devkit'; -import { normalizeGenesisBlock } from './genesis'; -import { WalletManager } from './wallet-manager'; -import { DAppKitLogger } from './utils/logger'; +import { WalletManager } from './classes'; +import { DAppKitLogger, normalizeGenesisBlock } from './utils'; import type { DAppKitOptions } from './types'; const cache: Record = {}; diff --git a/packages/dapp-kit/src/index.ts b/packages/dapp-kit/src/index.ts index da0c5845..a3317b2d 100644 --- a/packages/dapp-kit/src/index.ts +++ b/packages/dapp-kit/src/index.ts @@ -1,17 +1,5 @@ export * from './dapp-kit'; -export * from './wallet'; -export * from './wallet-manager'; -export * from './wallet-connect'; -export * from './genesis'; +export * from './constants'; +export * from './classes'; export * from './utils'; - -export type { - DAppKitOptions, - ConnexWallet, - WalletSource, - ConnectResponse, - WalletConfig, - BaseWallet, - WalletManagerState, - Genesis, -} from './types'; +export * from './types'; diff --git a/packages/dapp-kit/src/wallet-connect/index.ts b/packages/dapp-kit/src/types/index.ts similarity index 50% rename from packages/dapp-kit/src/wallet-connect/index.ts rename to packages/dapp-kit/src/types/index.ts index 61ed556b..1d1ccb01 100644 --- a/packages/dapp-kit/src/wallet-connect/index.ts +++ b/packages/dapp-kit/src/types/index.ts @@ -1,6 +1,13 @@ -import { newWcSigner } from './signer'; -import { createWcModal } from './web3-modal'; -import { createWcClient } from './client'; +export type { + DAppKitOptions, + ConnexWallet, + WalletSource, + ConnectResponse, + WalletConfig, + BaseWallet, + WalletManagerState, + Genesis, +} from './types'; export type { WCSigner, @@ -11,6 +18,4 @@ export type { WCModal, OpenOptions, SubscribeModalState, -} from './types'; - -export { newWcSigner, createWcModal, createWcClient }; +} from './wc-types'; diff --git a/packages/dapp-kit/src/types.d.ts b/packages/dapp-kit/src/types/types.d.ts similarity index 97% rename from packages/dapp-kit/src/types.d.ts rename to packages/dapp-kit/src/types/types.d.ts index 79e63192..3b1c4b25 100644 --- a/packages/dapp-kit/src/types.d.ts +++ b/packages/dapp-kit/src/types/types.d.ts @@ -1,6 +1,6 @@ import type { Certificate } from 'thor-devkit'; import type { WalletConnectOptions } from '@vechain/dapp-kit'; -import type { LogLevel } from './utils/logger'; +import type { LogLevel } from '../utils/logger'; declare global { interface Window { diff --git a/packages/dapp-kit/src/wallet-connect/types.d.ts b/packages/dapp-kit/src/types/wc-types.d.ts similarity index 100% rename from packages/dapp-kit/src/wallet-connect/types.d.ts rename to packages/dapp-kit/src/types/wc-types.d.ts diff --git a/packages/dapp-kit/src/vendor-signer.ts b/packages/dapp-kit/src/utils/convert-vendor-to-signer.ts similarity index 97% rename from packages/dapp-kit/src/vendor-signer.ts rename to packages/dapp-kit/src/utils/convert-vendor-to-signer.ts index 02794f2a..0ed1638b 100644 --- a/packages/dapp-kit/src/vendor-signer.ts +++ b/packages/dapp-kit/src/utils/convert-vendor-to-signer.ts @@ -1,4 +1,4 @@ -import { DAppKitLogger } from './utils'; +import { DAppKitLogger } from './logger'; export const convertVendorToSigner = (vendor: Connex.Vendor): Connex.Signer => { return { diff --git a/packages/dapp-kit/src/create-wallet.ts b/packages/dapp-kit/src/utils/create-wallet.ts similarity index 77% rename from packages/dapp-kit/src/create-wallet.ts rename to packages/dapp-kit/src/utils/create-wallet.ts index fc5e3cdb..e9b0c889 100644 --- a/packages/dapp-kit/src/create-wallet.ts +++ b/packages/dapp-kit/src/utils/create-wallet.ts @@ -1,12 +1,19 @@ import { Connex } from '@vechain/connex'; -import type { WCClient, WCModal } from './wallet-connect'; -import { createWcClient, createWcModal, newWcSigner } from './wallet-connect'; -import type { ConnexWallet, DAppKitOptions, WalletSource } from './types'; -import { CertificateBasedWallet } from './wallets/certificate-wallet'; -import { WCWallet } from './wallets/wc-wallet'; +import type { + ConnexWallet, + DAppKitOptions, + WalletSource, + WCClient, + WCModal, +} from '../types'; +import { CertificateBasedWallet } from '../classes/certificate-wallet'; +import { WCWallet } from '../classes/wc-wallet'; +import { createWcClient } from './create-wc-client'; +import { createWcModal } from './create-wc-modal'; +import { createWcSigner } from './create-wc-signer'; +import { convertVendorToSigner } from './convert-vendor-to-signer'; import { normalizeGenesisId } from './genesis'; -import { convertVendorToSigner } from './vendor-signer'; -import { DAppKitLogger } from './utils'; +import { DAppKitLogger } from './logger'; type ICreateWallet = DAppKitOptions & { source: WalletSource; @@ -61,7 +68,7 @@ export const createWallet = ({ const web3Modal: WCModal = modal ?? createWcModal(projectId); - const wallet = newWcSigner({ + const wallet = createWcSigner({ genesisId, wcClient, web3Modal, diff --git a/packages/dapp-kit/src/wallet-connect/client.ts b/packages/dapp-kit/src/utils/create-wc-client.ts similarity index 97% rename from packages/dapp-kit/src/wallet-connect/client.ts rename to packages/dapp-kit/src/utils/create-wc-client.ts index fb2a729c..6ae8cb2b 100644 --- a/packages/dapp-kit/src/wallet-connect/client.ts +++ b/packages/dapp-kit/src/utils/create-wc-client.ts @@ -3,7 +3,7 @@ import type { ResolvedSignClient, WalletConnectOptions, WCClient, -} from './types'; +} from '../types/wc-types'; const _cachedClients: Record = {}; diff --git a/packages/dapp-kit/src/wallet-connect/web3-modal.ts b/packages/dapp-kit/src/utils/create-wc-modal.ts similarity index 96% rename from packages/dapp-kit/src/wallet-connect/web3-modal.ts rename to packages/dapp-kit/src/utils/create-wc-modal.ts index af6f65f7..700b1080 100644 --- a/packages/dapp-kit/src/wallet-connect/web3-modal.ts +++ b/packages/dapp-kit/src/utils/create-wc-modal.ts @@ -1,5 +1,5 @@ import { WalletConnectModal } from '@walletconnect/modal'; -import type { WCModal } from './types'; +import type { WCModal } from '../types/wc-types'; const _cachedModals: Record = {}; diff --git a/packages/dapp-kit/src/wallet-connect/signer.ts b/packages/dapp-kit/src/utils/create-wc-signer.ts similarity index 97% rename from packages/dapp-kit/src/wallet-connect/signer.ts rename to packages/dapp-kit/src/utils/create-wc-signer.ts index 3b9e1a79..7180225b 100644 --- a/packages/dapp-kit/src/wallet-connect/signer.ts +++ b/packages/dapp-kit/src/utils/create-wc-signer.ts @@ -5,9 +5,9 @@ import type { } from '@walletconnect/types'; import { getSdkError } from '@walletconnect/utils'; import type { SignClient } from '@walletconnect/sign-client/dist/types/client'; -import { DAppKitLogger } from '../utils'; -import type { WCSigner, WCSignerOptions } from './types'; -import { DefaultMethods } from './constants'; +import type { WCSigner, WCSignerOptions } from '../types/wc-types'; +import { DefaultMethods } from '../constants/wallet-connect'; +import { DAppKitLogger } from './logger'; interface SessionAccount { networkIdentifier: string; @@ -20,7 +20,7 @@ interface SessionAccount { * @param options - The signer options. See {@link WCSignerOptions} * @returns A new {@link WCSigner} */ -export const newWcSigner = ({ +export const createWcSigner = ({ genesisId, wcClient, web3Modal, diff --git a/packages/dapp-kit/src/utils/genesis.ts b/packages/dapp-kit/src/utils/genesis.ts new file mode 100644 index 00000000..cfd51644 --- /dev/null +++ b/packages/dapp-kit/src/utils/genesis.ts @@ -0,0 +1,21 @@ +import { genesisBlocks } from '../constants'; +import type { Genesis } from '../types'; + +const normalizeGenesisId = (genesis?: Genesis): string => { + if (!genesis) return genesisBlocks.main.id; + + if (genesis === 'main' || genesis === 'test') + return genesisBlocks[genesis].id; + + return genesis.id; +}; + +const normalizeGenesisBlock = (genesis?: Genesis): Connex.Thor.Block => { + if (!genesis) return genesisBlocks.main; + + if (genesis === 'main' || genesis === 'test') return genesisBlocks[genesis]; + + return genesis; +}; + +export { normalizeGenesisId, normalizeGenesisBlock }; diff --git a/packages/dapp-kit/src/utils/index.ts b/packages/dapp-kit/src/utils/index.ts index 1ff09efd..0156b3b0 100644 --- a/packages/dapp-kit/src/utils/index.ts +++ b/packages/dapp-kit/src/utils/index.ts @@ -1 +1,8 @@ export * from './logger'; +export * from './convert-vendor-to-signer'; +export * from './local-storage'; +export * from './genesis'; +export * from './create-wallet'; +export * from './create-wc-client'; +export * from './create-wc-signer'; +export * from './create-wc-modal'; diff --git a/packages/dapp-kit/src/local-storage.ts b/packages/dapp-kit/src/utils/local-storage.ts similarity index 92% rename from packages/dapp-kit/src/local-storage.ts rename to packages/dapp-kit/src/utils/local-storage.ts index f2cf37e4..113e9738 100644 --- a/packages/dapp-kit/src/local-storage.ts +++ b/packages/dapp-kit/src/utils/local-storage.ts @@ -1,5 +1,5 @@ -import type { WalletSource } from './types'; -import { DAppKitLogger } from './utils'; +import type { WalletSource } from '../types'; +import { DAppKitLogger } from './logger'; const STORAGE_PREFIX = 'dappkit@vechain'; const WALLET_SOURCE_KEY = `${STORAGE_PREFIX}/source`; diff --git a/packages/dapp-kit/test/create-wallet.test.ts b/packages/dapp-kit/test/create-wallet.test.ts index 235c9660..164e1f04 100644 --- a/packages/dapp-kit/test/create-wallet.test.ts +++ b/packages/dapp-kit/test/create-wallet.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, vi } from 'vitest'; import type { Connex1 } from '@vechain/connex/esm/signer'; -import { createWallet } from '../src/create-wallet'; +import { createWallet } from '../src/utils'; import type { DAppKitOptions, WalletConnectOptions, diff --git a/packages/dapp-kit/test/genesis.test.ts b/packages/dapp-kit/test/genesis.test.ts index 2c449044..d9164859 100644 --- a/packages/dapp-kit/test/genesis.test.ts +++ b/packages/dapp-kit/test/genesis.test.ts @@ -1,9 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { - genesisBlocks, - normalizeGenesisBlock, - normalizeGenesisId, -} from '../src/genesis'; +import { normalizeGenesisBlock, normalizeGenesisId } from '../src/utils'; +import { genesisBlocks } from '../src/constants'; const customBlock = { number: 0, diff --git a/packages/dapp-kit/test/helpers/mocked-sign-client.ts b/packages/dapp-kit/test/helpers/mocked-sign-client.ts index fe2ee985..d87b0897 100644 --- a/packages/dapp-kit/test/helpers/mocked-sign-client.ts +++ b/packages/dapp-kit/test/helpers/mocked-sign-client.ts @@ -5,7 +5,7 @@ import type { } from '@walletconnect/types/dist/types/sign-client/engine'; import type { SessionTypes } from '@walletconnect/types'; import type { ResolvedSignClient } from '../../src'; -import { DefaultMethods } from '../../src/wallet-connect/constants'; +import { DefaultMethods } from '../../src'; import { wcSessionStruct } from './wc-fixtures'; import { address, mockedConnexSigner } from './mocked-signer'; import { randomUUID } from 'node:crypto'; diff --git a/packages/dapp-kit/test/helpers/wc-fixtures.ts b/packages/dapp-kit/test/helpers/wc-fixtures.ts index d670bdc9..4c11c725 100644 --- a/packages/dapp-kit/test/helpers/wc-fixtures.ts +++ b/packages/dapp-kit/test/helpers/wc-fixtures.ts @@ -1,6 +1,5 @@ import type { SessionTypes, SignClientTypes } from '@walletconnect/types'; -import { normalizeGenesisBlock } from '../../src/genesis'; -import { DefaultMethods } from '../../src/wallet-connect/constants'; +import { normalizeGenesisBlock, DefaultMethods } from '../../src'; import { address } from './mocked-signer'; const wcMetadata: SignClientTypes.Options['metadata'] = { diff --git a/packages/dapp-kit/test/wallet-connect/client.test.ts b/packages/dapp-kit/test/utils/client.test.ts similarity index 100% rename from packages/dapp-kit/test/wallet-connect/client.test.ts rename to packages/dapp-kit/test/utils/client.test.ts diff --git a/packages/dapp-kit/test/utils/convert-vendor-to-signer.test.ts b/packages/dapp-kit/test/utils/convert-vendor-to-signer.test.ts new file mode 100644 index 00000000..64b3c7c5 --- /dev/null +++ b/packages/dapp-kit/test/utils/convert-vendor-to-signer.test.ts @@ -0,0 +1,142 @@ +import { convertVendorToSigner } from '../../src'; +import { vi, it, describe, expect } from 'vitest'; + +describe('convertVendorToSigner', () => { + it('should return the correct message', async () => { + const gasMock = vi.fn(); + const signerMock = vi.fn(); + const dependsOnMock = vi.fn(); + const linkMock = vi.fn(); + const commentMock = vi.fn(); + const delegateMock = vi.fn(); + const acceptedMock = vi.fn(); + const requestMock = vi.fn(); + const mockSign = vi.fn(() => ({ + gas: gasMock, + signer: signerMock, + dependsOn: dependsOnMock, + link: linkMock, + comment: commentMock, + delegate: delegateMock, + accepted: acceptedMock, + request: requestMock, + })); + const vendorMock = { + sign: mockSign, + }; + + // Create a fake transaction message and options + const fakeMsg = 'Your fake transaction message'; + const fakeOptions = { + gas: 100000, + }; + + // Call the function with the mock + const signer = convertVendorToSigner(vendorMock as Connex.Vendor); + await signer.signTx([{ to: 'address', value: fakeMsg }], fakeOptions); + + expect(mockSign).toHaveBeenCalledWith('tx', [ + { + to: 'address', + value: fakeMsg, + }, + ]); + + await signer.signCert( + { + purpose: 'identification', + payload: { + type: 'text', + content: '', + }, + }, + {}, + ); + expect(mockSign).toHaveBeenCalledWith('cert', { + purpose: 'identification', + payload: { + type: 'text', + content: '', + }, + }); + + expect(gasMock).toHaveBeenCalledWith(fakeOptions.gas); + expect(requestMock).toHaveBeenCalled(); + }); + it('should call it with multiple options', async () => { + const gasMock = vi.fn(); + const signerMock = vi.fn(); + const dependsOnMock = vi.fn(); + const linkMock = vi.fn(); + const commentMock = vi.fn(); + const delegateMock = vi.fn(); + const acceptedMock = vi.fn(); + const requestMock = vi.fn(); + const mockSign = vi.fn(() => ({ + gas: gasMock, + signer: signerMock, + dependsOn: dependsOnMock, + link: linkMock, + comment: commentMock, + delegate: delegateMock, + accepted: acceptedMock, + request: requestMock, + })); + const vendorMock = { + sign: mockSign, + }; + + // Create a fake transaction message and options + const fakeMsg = 'Your fake transaction message'; + const fakeOptions = { + signer: '0x1234567890', + dependsOn: '0x0987654321', + link: 'https://example.com', + comment: 'This is a comment', + onAccepted: () => {}, + delegator: { + url: 'https://example.com', + signer: '0x1234567890', + }, + }; + + // Call the function with the mock + const signer = convertVendorToSigner(vendorMock); + await signer.signTx([{ to: 'address', value: fakeMsg }], fakeOptions); + expect(mockSign).toHaveBeenCalledWith('tx', [ + { + to: 'address', + value: fakeMsg, + }, + ]); + await signer.signCert( + { + purpose: 'identification', + payload: { + type: 'text', + content: '', + }, + }, + fakeOptions, + ); + expect(mockSign).toHaveBeenCalledWith('cert', { + purpose: 'identification', + payload: { + type: 'text', + content: '', + }, + }); + + expect(gasMock).not.toHaveBeenCalled(); + expect(signerMock).toHaveBeenCalledWith(fakeOptions.signer); + expect(dependsOnMock).toHaveBeenCalledWith(fakeOptions.dependsOn); + expect(linkMock).toHaveBeenCalledWith(fakeOptions.link); + expect(commentMock).toHaveBeenCalledWith(fakeOptions.comment); + expect(delegateMock).toHaveBeenCalledWith( + fakeOptions.delegator.url, + fakeOptions.delegator.signer, + ); + expect(acceptedMock).toHaveBeenCalledWith(fakeOptions.onAccepted); + expect(requestMock).toHaveBeenCalled(); + }); +}); diff --git a/packages/dapp-kit/test/wallet-connect/signer.test.ts b/packages/dapp-kit/test/utils/signer.test.ts similarity index 91% rename from packages/dapp-kit/test/wallet-connect/signer.test.ts rename to packages/dapp-kit/test/utils/signer.test.ts index 209f6e15..0b255841 100644 --- a/packages/dapp-kit/test/wallet-connect/signer.test.ts +++ b/packages/dapp-kit/test/utils/signer.test.ts @@ -2,9 +2,9 @@ import { describe, expect, it, vi } from 'vitest'; import { SignClient } from '@walletconnect/sign-client'; import type { SignClientTypes } from '@walletconnect/types'; import type { WCModal, WCSigner } from '../../src'; -import { createWcClient, newWcSigner } from '../../src'; +import { createWcClient, createWcSigner } from '../../src'; import { mockedSignClient } from '../helpers/mocked-sign-client'; -import { normalizeGenesisId } from '../../src/genesis'; +import { normalizeGenesisId } from '../../src'; import { address } from '../helpers/mocked-signer'; vi.spyOn(SignClient, 'init').mockResolvedValue(mockedSignClient); @@ -26,7 +26,7 @@ const customModal: WCModal = { }; const createNewSignClient = (): WCSigner => - newWcSigner({ + createWcSigner({ genesisId: normalizeGenesisId('main'), wcClient: createWcClient({ projectId, metadata }), onDisconnected: () => { @@ -35,7 +35,7 @@ const createNewSignClient = (): WCSigner => web3Modal: customModal, }); -describe('newWcSigner', () => { +describe('createWcSigner', () => { it('can connect', async () => { const signer = createNewSignClient(); diff --git a/packages/dapp-kit/test/wallet-connect/web3-modal.test.ts b/packages/dapp-kit/test/utils/web3-modal.test.ts similarity index 100% rename from packages/dapp-kit/test/wallet-connect/web3-modal.test.ts rename to packages/dapp-kit/test/utils/web3-modal.test.ts