import { ChainTypeEnum, type EmbeddedAccount, EmbeddedState, type Openfort } from '@openfort/openfort-js'; import { type Dispatch, type RefObject, type SetStateAction } from 'react'; import type { EmbeddedAccountRequest } from '../../actions/createEmbeddedWallet.js'; import type { OpenfortWalletConfig } from '../../components/Openfort/types.js'; import type { WalletFlowStatus } from '../../hooks/openfort/walletTypes.js'; import type { CreateEmbeddedWalletOptions, WalletStatus } from '../types.js'; import { type EmbeddedSignerOperationContext } from '../utils/embeddedSignerOperationQueue.js'; /** Local state both embedded-wallet hooks track between renders. */ export type EmbeddedWalletInternalState = { status: WalletStatus; activeWallet: TWallet | null; provider: TProvider | null; error: string | null; }; /** Everything a chain's sync effect reads or writes. */ export type EmbeddedWalletSyncParameters = { client: Openfort; /** Embedded accounts belonging to this chain. */ accounts: EmbeddedAccount[]; /** The core store's single source of truth for the active wallet. */ activeEmbeddedAddress: string | undefined; embeddedState: EmbeddedState; isLoadingAccounts: boolean; /** Chain the modal is currently routed to, which may differ from this hook's chain. */ routedChainType: ChainTypeEnum; state: EmbeddedWalletInternalState; setState: Dispatch>>; setActiveInProgressRef: RefObject | null>; /** Runs work that must not overlap another operation on this client's signer. */ runSignerOperation: (operation: (context: EmbeddedSignerOperationContext) => Promise) => Promise; /** Builds (or fetches) this chain's provider for an account. */ getProvider: (account: EmbeddedAccount, context: EmbeddedSignerOperationContext) => Promise; setActiveEmbeddedAddress: (address: string | undefined) => void; }; /** Chain-specific values read from React context and options. */ export type EmbeddedWalletChainBindings = { /** * Resolves `accountType` (and `chainId` where the account type needs one) for * create and import. Must be referentially stable: it feeds the `create` and * `import` callback identities. */ buildAccountRequest: (options: CreateEmbeddedWalletOptions | undefined) => EmbeddedAccountRequest; /** Extra chain-specific fields merged into the hook result. */ resultProps: Record; }; /** Provider placeholder used while an embedded wallet is still recovering. */ export declare function rejectUnreadyProvider(): Promise; type EmbeddedWalletHookConfig = { /** Chain whose embedded accounts this hook exposes. */ chainType: ChainTypeEnum; /** Chain name used in wallet error messages. */ chainName: 'Ethereum' | 'Solana'; /** * Canonical form used for every address comparison on this chain. EVM * addresses are case-insensitive so they lowercase; Solana addresses are * base58 and compare verbatim. */ normalizeAddress: (address: string) => string; /** Builds this chain's provider, bound to `account` where the chain needs it. */ buildProvider: (parameters: { client: Openfort; account: EmbeddedAccount; ethereumRpcUrls: NonNullable['rpcUrls'] | undefined; assertCurrent: () => void; }) => Promise; /** Maps this chain's accounts to the `wallets` list the hook exposes. */ buildWallets: (parameters: { accounts: EmbeddedAccount[]; getProvider: (account: EmbeddedAccount) => Promise; status: WalletStatus; activeWallet: TWallet | null; }) => TWallet[]; /** Builds the connected wallet once a provider is ready. */ buildActiveWallet: (parameters: { account: EmbeddedAccount; walletIndex: number; provider: TProvider; }) => TWallet; /** Builds the placeholder wallet exposed while `setActive` is still recovering. */ buildConnectingWallet: (parameters: { account: EmbeddedAccount; walletIndex: number; }) => TWallet; /** Store status published while this chain's `setActive` is in flight. */ buildConnectingStatus: (wallet: TWallet) => WalletFlowStatus; /** Reads the chain's React context and hook options. */ useChainBindings: (options: TOptions | undefined) => EmbeddedWalletChainBindings; /** Reconciles local state with the core store's `activeEmbeddedAddress`. */ useSyncActiveWallet: (parameters: EmbeddedWalletSyncParameters) => void; }; /** * Builds an embedded-wallet hook for one chain. * * The returned hook owns everything both chains share — store subscriptions, * local status state, the create/import/setActive/setRecovery/exportPrivateKey * actions, and the derived result shape — while the chain supplies provider * construction, address normalization, wallet shapes and its sync effect. * * @param config - Chain-specific behaviour injected into the shared hook body. * @returns A React hook returning this chain's wallet state. */ export declare function createEmbeddedWalletHook(config: EmbeddedWalletHookConfig): (options?: TOptions) => TResult; export {};