UNPKG

unich-web3-sdk

Version:

Web3 SDK for DEX applications with multi-chain support

114 lines (108 loc) 4.12 kB
import React from 'react'; export { EVMChainAdapter, SVMChainAdapter, getAllChains, getChainAdapter, getChainAdapterForChain, getChainById, popularEVMChains, popularSVMChains } from './chains/index.js'; import { C as ConnectorStatus, a as Connector } from './index-CTevj-R6.js'; export { B as BaseConnector, b as ConnectorError, c as ConnectorEvent, M as MetaMaskConnector, P as PhantomConnector, W as WalletInfo, g as getAvailableConnectors, d as getConnectorById } from './index-CTevj-R6.js'; import { C as ChainId, a as ChainConfig } from './chain-BlOpMgJb.js'; export { c as ChainAdapter, b as ChainType, N as NetworkType } from './chain-BlOpMgJb.js'; import * as react_jsx_runtime from 'react/jsx-runtime'; import * as zustand_middleware from 'zustand/middleware'; import * as zustand from 'zustand'; import 'viem/experimental'; import 'viem/_types/utils/ccip'; import 'viem'; import '@solana/web3.js'; import 'eventemitter3'; /** * Configuration for the Web3 SDK */ interface Web3Config { defaultChain?: string | number; autoConnect?: boolean; connectors?: any[]; chains?: any[]; walletModal?: { title?: string; description?: string; customComponent?: React.ComponentType<any>; }; } interface Web3HookReturn { status: ConnectorStatus; account: string | null; chainId: ChainId | null; chain: ChainConfig | null; error: Error | null; isConnected: boolean; isConnecting: boolean; isDisconnected: boolean; isError: boolean; connect: (connectorId: string, chainId?: ChainId) => Promise<void>; disconnect: () => Promise<void>; switchChain: (chainId: ChainId) => Promise<void>; getAvailableConnectors: () => Connector[]; } /** * Hook for interacting with the web3 store * @param config Configuration options * @returns Web3 state and actions */ declare function useWeb3(config?: { autoConnect?: boolean; defaultChain?: ChainId; }): Web3HookReturn; /** * Web3Provider props */ interface Web3ProviderProps { children: React.ReactNode; config?: Web3Config; } /** * Web3Provider component * Provides web3 context to child components */ declare function Web3Provider({ children, config }: Web3ProviderProps): react_jsx_runtime.JSX.Element | null; /** * Hook to access web3 context * @returns Web3 context */ declare function useWeb3Context(): Web3HookReturn; /** * ConnectWalletButton component * Button to connect wallet */ declare function ConnectWalletButton({ onConnect, onError, chainId, className, children, }: { onConnect?: (account: string) => void; onError?: (error: Error) => void; chainId?: string | number; className?: string; children?: React.ReactNode; }): react_jsx_runtime.JSX.Element; interface Web3State { status: ConnectorStatus; account: string | null; chainId: ChainId | null; connector: Connector | null; error: Error | null; chain: ChainConfig | null; connect: (connectorId: string, chainId?: ChainId) => Promise<void>; disconnect: () => Promise<void>; switchChain: (chainId: ChainId) => Promise<void>; setStatus: (status: ConnectorStatus) => void; setAccount: (account: string | null) => void; setChainId: (chainId: ChainId | null) => void; setConnector: (connector: Connector | null) => void; setError: (error: Error | null) => void; } declare const useWeb3Store: zustand.UseBoundStore<Omit<zustand.StoreApi<Web3State>, "persist"> & { persist: { setOptions: (options: Partial<zustand_middleware.PersistOptions<Web3State, Partial<Web3State>>>) => void; clearStorage: () => void; rehydrate: () => Promise<void> | void; hasHydrated: () => boolean; onHydrate: (fn: (state: Web3State) => void) => () => void; onFinishHydration: (fn: (state: Web3State) => void) => () => void; getOptions: () => Partial<zustand_middleware.PersistOptions<Web3State, Partial<Web3State>>>; }; }>; export { ChainConfig, ChainId, ConnectWalletButton, Connector, ConnectorStatus, type Web3Config, Web3Provider, useWeb3, useWeb3Context, useWeb3Store };