UNPKG

@meterio/web3-context

Version:

A React Context wrapper for Blocknative OnbardJS with a couple of utility functions

77 lines (76 loc) 2.91 kB
/// <reference types="node" /> 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' | 'currentBaseFee' | 'recommendedBaseFee'; declare type EthGasnowSettings = 'fast' | 'standard' | 'slow'; declare type TokenConfig = { address: string; name?: string; symbol?: string; imageUri?: string; native: boolean; decimals: number; }; declare type TokensToWatch = { [networkId: number]: TokenConfig[]; }; declare type BridgeConfig = { chainId: number; networkId: number; name: string; bridgeAddress: string; erc20HandlerAddress: string; rpcUrl: string; type: "Ethereum" | "Substrate"; tokens: TokenConfig[]; nativeTokenSymbol: string; nativeTokenDecimals: number; amplController: string; amplApprovalContract: string; blockExplorer: string; defaultGasPrice?: number; testnet?: boolean; }; declare type Web3ContextProps = { cacheWalletSelection?: boolean; checkNetwork?: boolean; children: React.ReactNode; ethGasStationApiKey?: string; gasPricePollingInterval?: number; gasPriceSetting?: EthGasStationSettings | EtherchainGasSettings | EthGasnowSettings; networkIds?: number[]; onboardConfig?: OnboardConfig; spenderAddress?: string; tokensToWatch?: TokensToWatch; ethGasPriceFromGasnow?: Boolean; useGasPricePoller?: Boolean; bridgeList?: BridgeConfig[]; loopNativeTokenInterval?: number; }; declare type Web3Context = { address?: string; ethBalance?: number; gasPrice: number; isReady: boolean; isMobile: boolean; network?: number; onboard?: OnboardApi; provider?: providers.Web3Provider; wallet?: Wallet; tokens: Tokens; walletConnecting?: boolean; timer?: NodeJS.Timer | null; checkIsReady(): Promise<boolean>; refreshGasPrice(): Promise<Number>; resetOnboard(): void; signMessage(message: string): Promise<string>; updateCurrentTokenBalance(address: string): void; }; declare const Web3Context: React.Context<Web3Context | undefined>; declare const Web3Provider: ({ children, onboardConfig, networkIds, ethGasStationApiKey, gasPricePollingInterval, gasPriceSetting, tokensToWatch, spenderAddress, cacheWalletSelection, checkNetwork, ethGasPriceFromGasnow, useGasPricePoller, bridgeList, loopNativeTokenInterval, }: Web3ContextProps) => JSX.Element; declare const useWeb3: () => Web3Context; export { Web3Provider, useWeb3, providers };