@chainsafe/web3-context
Version:
A React Context wrapper for Blocknative OnbardJS with a couple of utility functions
62 lines (61 loc) • 2.27 kB
TypeScript
import * as React from 'react';
import { API as OnboardApi, Wallet, Initialization } from 'bnc-onboard/dist/src/interfaces';
import { providers } from 'ethers';
import { Tokens } from './tokensReducer';
export declare type OnboardConfig = Partial<Omit<Initialization, 'networkId'>>;
declare type EthGasStationSettings = 'fast' | 'fastest' | 'safeLow' | 'average';
declare type EtherchainGasSettings = 'safeLow' | 'standard' | 'fast' | 'fastest';
declare type TokenConfig = {
address: string;
name?: string;
symbol?: string;
imageUri?: string;
};
declare type TokensToWatch = {
[networkId: number]: TokenConfig[];
};
export declare type AddChainParams = {
chainId: number;
chainName: string;
rpcUrls: string[];
nativeCurrency: {
name: string;
symbol: string;
decimals: number;
};
blockExplorerUrls?: string[];
};
declare type Web3ContextProps = {
cacheWalletSelection?: boolean;
checkNetwork?: boolean;
children: React.ReactNode;
ethGasStationApiKey?: string;
gasPricePollingInterval?: number;
gasPriceSetting?: EthGasStationSettings | EtherchainGasSettings;
networkIds?: number[];
onboardConfig?: OnboardConfig;
spenderAddress?: string;
tokensToWatch?: TokensToWatch;
additionalChainParams?: AddChainParams[];
};
declare type Web3Context = {
address?: string;
ethBalance?: number;
gasPrice: number;
isReady: boolean;
isMobile: boolean;
network?: number;
onboard?: OnboardApi;
provider?: providers.Web3Provider;
wallet?: Wallet;
tokens: Tokens;
checkIsReady(): Promise<boolean>;
refreshGasPrice(): Promise<void>;
resetOnboard(): void;
signMessage(message: string): Promise<string>;
switchNetwork(chainId: number): Promise<void>;
};
declare const Web3Context: React.Context<Web3Context | undefined>;
declare const Web3Provider: ({ children, onboardConfig, networkIds, ethGasStationApiKey, gasPricePollingInterval, gasPriceSetting, tokensToWatch, spenderAddress, cacheWalletSelection, checkNetwork, additionalChainParams, }: Web3ContextProps) => JSX.Element;
declare const useWeb3: () => Web3Context;
export { Web3Provider, useWeb3 };