UNPKG

@funkit/connect

Version:

Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.

137 lines (136 loc) 4.9 kB
import type { WalletConnectParameters } from '../wagmi/connectors'; import type { Connector, CreateConnectorFn } from '../wagmi/hooks'; import type { TransactionReceipt } from 'viem'; import type { CoinbaseWalletOptions } from './walletConnectors/coinbaseWallet/coinbaseWallet'; import type { WalletConnectWalletOptions } from './walletConnectors/walletConnectWallet/walletConnectWallet'; export type InstructionStepName = 'install' | 'create' | 'scan' | 'connect' | 'refresh'; type FunkitSdkConnector = { mobile?: { getUri?: (uri: string) => string; }; desktop?: { getUri?: (uri: string) => string; instructions?: { learnMoreUrl: string; steps: { step: InstructionStepName; title: string; description: string; }[]; }; }; qrCode?: { getUri: (uri: string) => string; instructions?: { learnMoreUrl: string; steps: { step: InstructionStepName; title: string; description: string; }[]; }; }; extension?: { instructions?: { learnMoreUrl: string; steps: { step: InstructionStepName; title: string; description: string; }[]; }; }; }; export type Wallet = { id: string; name: string; rdns?: string; shortName?: string; iconUrl: string | (() => Promise<string>); iconAccent?: string; iconBackground: string; installed?: boolean; downloadUrls?: { android?: string; ios?: string; mobile?: string; qrCode?: string; chrome?: string; edge?: string; firefox?: string; opera?: string; safari?: string; browserExtension?: string; macos?: string; windows?: string; linux?: string; desktop?: string; }; hidden?: () => boolean; createConnector: (walletDetails: WalletDetailsParams) => CreateConnectorFn; } & FunkitSdkConnector; export interface DefaultWalletOptions { projectId: string; walletConnectParameters?: FunkitConnectWalletConnectParameters; } export type CreateWalletFn = (createWalletParams: CoinbaseWalletOptions & Omit<WalletConnectWalletOptions, 'projectId'> & DefaultWalletOptions) => Wallet; type WalletListEntry = { groupName: string; wallets: CreateWalletFn[]; }; export type WalletList = [WalletListEntry, ...WalletListEntry[]]; export type FunkitConnectWalletConnectParameters = Omit<WalletConnectParameters, 'showQrModal' | 'projectId'>; export type FunkitConnectDetails = Omit<Wallet, 'createConnector' | 'hidden'> & { index: number; groupIndex: number; groupName: string; isWalletConnectModalConnector?: boolean; isFunkitSdkConnector: boolean; walletConnectModalConnector?: Connector; showQrModal?: true; }; export type WalletDetailsParams = { fkcDetails: FunkitConnectDetails; }; export type CreateConnector = (walletDetails: { fkcDetails: FunkitConnectDetails; }) => CreateConnectorFn; export type WagmiConnectorInstance = Connector & { fkcDetails?: FunkitConnectDetails; }; export type WalletInstance = Connector & FunkitConnectDetails; export type WithdrawalTransaction = { to: string; data: string; value: string; }; export interface WithdrawalClient { getChainId: () => Promise<number>; switchChain: (chainId: number) => Promise<void>; sendTransaction: (chainId: number, transaction: WithdrawalTransaction) => Promise<string>; /** * Optional batched submitter. When provided, the SDK collapses approve + * swap/deposit steps into a single user signature via this method (e.g. * EIP-5792 `wallet_sendCalls` with `forceAtomic`). * * Must return a tx hash that {@link confirmTransaction} can wait on. * Implementations using `wallet_sendCalls` should map the calls-id back to * the underlying tx hash via `waitForCallsStatus` → * `receipts[0].transactionHash`. */ sendTransactions?: (chainId: number, transactions: WithdrawalTransaction[]) => Promise<string>; confirmTransaction: (txHash: string, chainId: number) => Promise<TransactionReceipt>; address: () => string; } /** * WithdrawalClient variant for Lighter (LVM). Satisfies WithdrawalClient for * address lookup and display, but also carries the relay-sdk AdaptedWallet so * startRelayDirectExecution can execute the LVM steps directly instead of * wrapping in an EVM shim. */ export interface LighterWithdrawalClient extends WithdrawalClient { readonly _type: 'lighter'; readonly adaptedWallet: import('@funkit/fun-relay').LighterWallet; } export declare function isLighterWithdrawalClient(client: WithdrawalClient): client is LighterWithdrawalClient; export {};