UNPKG

wallets-wrapper

Version:

How to install

137 lines (136 loc) 5.54 kB
import { EventType, Listener } from '@ethersproject/abstract-provider'; import { LoginChallenge, RequestLoginAsync } from '@trezor/connect/lib/types/api/requestLogin'; import { Manifest, Params } from '@trezor/connect-web'; import { ethers } from 'ethers'; import { BehaviorSubject } from 'rxjs'; import { ChainInfo, GetAccountInfo, GetAddress, GetBalance, IProviderRpcError, SendSignedTransaction, SendTransaction, SubscriptionMessage, Transfer, WalletsNames, WalletsWrapperProps, WalletWrapper } from '../models'; import { AnchorWrapper } from '../wallets/anchor'; import { AddEthereumChainParameter, SignProps, WatchAssetParams } from '../wallets/metamask'; import { ChainIds, ERC20Names, MetamaskWrapper, StandardContract, TrezorWrapper } from '..'; /** * The client describes how to work with all wallets. * All connection to wallets must be with this client * @implements WalletWrapper * @class */ export declare class WalletsWrapper implements WalletWrapper { static instances: Record<WalletsNames, WalletsWrapper> | Record<string, never>; /** * The BehaviorSubject watch for child clients addresses * @type {GlobalState<string[]> | null} */ address$: BehaviorSubject<string[]>; /** * The BehaviorSubject watch for child clients chainIds * @type {GlobalState<ChainInfo | null> | null} */ chainId$: BehaviorSubject<ChainInfo | null>; /** * The BehaviorSubject watch for child clients messages from blockchain * @type {GlobalState<ProviderMessage | null> | null} */ subscriptionMessage$: BehaviorSubject<SubscriptionMessage | null>; /** * The BehaviorSubject watch for child clients connection to wallets * @type {GlobalState<boolean> | null} */ isConnected$: BehaviorSubject<boolean>; /** * The BehaviorSubject watch for child clients errors * @type {GlobalState<IProviderRpcError | null> | null} */ errors$: BehaviorSubject<IProviderRpcError | null>; type: WalletsNames; wallet: MetamaskWrapper | TrezorWrapper | AnchorWrapper; /** * Creates an instance of a class to work with a specific wallet * @param {WalletsWrapperProps} object * @param {WalletsNames} type - type of wallet, default is MetamaskWrapper * @param {WalletsWrapperProps} infuraApiKey - the parameter is needed to connect * to the blockchain * @constructor */ constructor({ type, infuraApiKey }: WalletsWrapperProps); /** * init library * @param {Manifest} object * @return {Promise<void>} * @async */ init(props: Manifest): Promise<boolean>; /** * Check wallet existing * @return {Promise<boolean>} * @async */ isInstalled(): Promise<boolean>; generateWallet(): Promise<import("../wallets/metamask").NewEthereumWallet>; getProvider(): Promise<import("anchor-link").Link | ethers.providers.Web3Provider | import("@trezor/connect-web").TrezorConnect>; getWallet(): MetamaskWrapper | TrezorWrapper | AnchorWrapper; /** * Connect to chosen wallet * @param {Params<RequestLoginAsync | LoginChallenge>} params - params for trezor * @return {Promise<string[]>} - wallet address * @async */ connectWallet(params?: Params<RequestLoginAsync | LoginChallenge>): Promise<string[]>; /** * Get current wallet addresses * @param {GetAddressProps} object * @return {Promise<string[]>} - wallet address * @async */ getAddress: GetAddress; /** * Get balance from current wallet in native coin * @param {GetBalanceProps} args * AllCoins[] - for trezor, GetBalanceProps - for metamask * @return {Promise<number[]>} - balance value * @async */ getBalance: GetBalance; /** * Get account info from current wallets in native coin * @param {GetAccountInfo[] | GetBalanceProps} args * AllCoins[] - for trezor, GetBalanceProps - for metamask * @return {Promise<number[]>} * @async */ getAccountInfo: GetAccountInfo; getChain(): Promise<ChainInfo | null>; switchNetwork(chainId: ChainIds): Promise<void>; switchCustomNetwork(network: AddEthereumChainParameter): Promise<void>; addToken(token: ERC20Names): Promise<boolean>; addCustomToken(newAsset: WatchAssetParams): Promise<boolean>; sign(args: SignProps): Promise<void>; /** * Send signed transaction * @param args * @return {Promise<AllResponses, ethers.providers.TransactionResponse>} * @async */ sendSignedTransaction: SendSignedTransaction; /** * Send signed transaction * @param args * @return {Promise<AllResponses, ethers.providers.TransactionResponse>} * @async */ sendTransaction: SendTransaction; /** * Transfer native coin * @param {TransferToken | TransferProps} args * @return {Promise<(TransactionResponse | null) & AllResponses>} * @async */ transfer: Transfer; /** * Get client for contract connection * @param {string} address - Contract address * @param {ChainIds} network - network in which to search for a contract * @return {Promise<StandardContract>} * @async */ getStandardContract(address: string, network?: ChainIds): Promise<StandardContract>; addEventListener(event: EventType, listener: Listener): Promise<void>; }