@jim4565/dapp-wrapper-react
Version:
React components and hooks for @jim4565/dapp-wrapper with persistent wallet connection
153 lines • 4.71 kB
TypeScript
export interface WalletState {
address: string | undefined;
isConnected: boolean;
isConnecting: boolean;
isReconnecting: boolean;
isDisconnecting: boolean;
error: Error | null;
}
export interface WalletActions {
connect: () => Promise<void>;
disconnect: () => void;
reconnect: () => Promise<void>;
}
export interface ContractConfig {
name: string;
address: string;
abi: any[];
}
export interface ContractInstance {
address: string;
abi: any[];
[key: string]: any;
}
export type ContractFunctionType = 'view' | 'pure' | 'nonpayable' | 'payable';
export interface ContractReadOptions {
enabled?: boolean;
refetchInterval?: number;
onSuccess?: (data: any) => void;
onError?: (error: Error) => void;
}
export interface ContractWriteOptions {
onSuccess?: (data: any) => void;
onError?: (error: Error) => void;
onSettled?: () => void;
}
export interface TransactionState {
isLoading: boolean;
isError: boolean;
isSuccess: boolean;
error: Error | null;
data: any;
}
export interface TransactionRequest {
to: string;
data?: string;
value?: string;
gasLimit?: string;
gasPrice?: string;
}
export interface IncentivWalletConfig {
contracts?: ContractConfig[];
autoConnect?: boolean;
reconnectOnMount?: boolean;
pollingInterval?: number;
}
export interface UseIncentivWalletReturn extends WalletState, WalletActions {
balance: string | undefined;
isBalanceLoading: boolean;
refreshBalance: () => Promise<void>;
isReady: boolean;
connector: string | undefined;
}
export interface UseContractReturn<T = ContractInstance> {
contract: T | undefined;
isLoading: boolean;
error: Error | null;
}
export interface UseContractReadReturn<T = any> {
data: T | undefined;
isLoading: boolean;
error: Error | null;
refetch: () => Promise<void>;
lastFetched: number;
}
export interface UseContractWriteReturn {
write: (...args: any[]) => void;
writeAsync: (...args: any[]) => Promise<any>;
data: any;
isLoading: boolean;
error: Error | null;
reset: () => void;
}
export interface UseTransactionReturn extends TransactionState {
sendTransaction: (txRequest: TransactionRequest) => Promise<any>;
reset: () => void;
}
export interface StoredWalletData {
address: string | null;
wasConnected: boolean;
hasEverConnected: boolean;
lastConnectedAt: number;
}
export declare enum WalletErrorCode {
USER_REJECTED = 4001,
UNAUTHORIZED = 4100,
UNSUPPORTED_METHOD = 4200,
DISCONNECTED = 4900,
CHAIN_DISCONNECTED = 4901,
UNKNOWN_ERROR = -1
}
export declare class WalletError extends Error {
code: WalletErrorCode;
reason?: string;
method?: string;
constructor(message: string, options?: {
code?: WalletErrorCode;
reason?: string;
method?: string;
cause?: unknown;
});
}
export type WalletActionType = 'SET_CONNECTING' | 'SET_RECONNECTING' | 'SET_CONNECTED' | 'SET_DISCONNECTING' | 'SET_DISCONNECTED' | 'SET_ERROR' | 'CLEAR_ERROR' | 'RESET_STATE';
export interface WalletAction {
type: WalletActionType;
payload?: any;
}
export interface WalletEvent {
type: 'connect' | 'disconnect' | 'accountsChanged' | 'chainChanged' | 'error';
data?: any;
}
export declare const STORAGE_KEYS: {
readonly WALLET_ADDRESS: "incentiv_wallet_address";
readonly WALLET_CONNECTED: "incentiv_wallet_connected";
readonly EVER_CONNECTED: "incentiv_wallet_ever_connected";
readonly LAST_CONNECTED_AT: "incentiv_wallet_last_connected";
readonly CONTRACTS: "incentiv_wallet_contracts";
};
export type StorageKey = typeof STORAGE_KEYS[keyof typeof STORAGE_KEYS];
/**
* WICHTIGE ÄNDERUNG in @jim4565/dapp-wrapper v1.x:
*
* Die zugrunde liegende Bibliothek unterscheidet jetzt automatisch zwischen:
*
* 1. VIEW/PURE Funktionen:
* - Lesen nur Blockchain-Daten
* - Benötigen KEINE Wallet-Verbindung
* - Werden direkt mit dem Provider ausgeführt
* - Beispiele: balanceOf, totalSupply, getName
*
* 2. NONPAYABLE/PAYABLE Funktionen:
* - Ändern den Blockchain-State
* - Benötigen eine Wallet-Verbindung für die Signatur
* - Werden mit dem Signer ausgeführt
* - Beispiele: transfer, approve, mint
*
* Diese Unterscheidung passiert automatisch basierend auf der ABI stateMutability.
*
* Für React-Entwickler bedeutet das:
* - useContractRead: Funktioniert ohne Wallet-Verbindung
* - useContractWrite: Erfordert weiterhin eine Wallet-Verbindung
* - useContract: Stellt Contract immer zur Verfügung, Wallet-Check erfolgt bei Methodenaufruf
*/
//# sourceMappingURL=index.d.ts.map