wallets-wrapper
Version:
How to install
157 lines (156 loc) • 5.74 kB
TypeScript
import { ethers } from 'ethers';
import { BehaviorSubject } from 'rxjs';
import { AccountInfo, ChainInfo, IProviderRpcError, SubscriptionMessage, TransferToken, WalletsNames, WalletStateProps } from '../../../models';
import { ChainIds, ERC20Names } from '../../../networks';
import { AddEthereumChainParameter, GetBalanceProps, SignProps, WatchAssetParams } from '../models';
import { IMetamaskWrapper } from '../models/interfaces';
/**
* The client describes how to work with Metamask Extension.
* @implements IMetamaskWrapper
* @class
*/
export declare class MetamaskWrapper implements IMetamaskWrapper {
static instance: MetamaskWrapper;
static type: WalletsNames;
/**
* The BehaviorSubject witch return current metamask address
* @type {string[]}
*/
address$: BehaviorSubject<string[]>;
/**
* The BehaviorSubject witch return chain
* @type {ChainInfo | null}
*/
chainId$: BehaviorSubject<ChainInfo | null>;
/**
* The BehaviorSubject witch return current status of connect to Metamask
* @type {boolean}
*/
isConnected$: BehaviorSubject<boolean>;
subscriptionMessage$: BehaviorSubject<SubscriptionMessage | null>;
/**
* The BehaviorSubject witch return current errors in Metamask
* @type {IProviderRpcError | null}
*/
errors$: BehaviorSubject<IProviderRpcError | null>;
private initialObject;
getProvider: () => Promise<ethers.providers.Web3Provider>;
isInstalled: () => boolean;
/**
* Current class is Singleton
* @constructor
*/
constructor({ address$, chainId$, isConnected$, subscriptionMessage$, errors$, }: WalletStateProps);
init(): Promise<boolean>;
/**
* Generate Ethers wallet
* @return {object} - Object with address, mnemonic and privateKey
* @async
*/
generateWallet(): {
address: string;
mnemonic: string;
privateKey: string;
};
/**
* Connect to Metamask Extension and return current wallet address if extension exists
* or open installation page
* @return {Promise<string[]>} - wallet address
* @async
*/
connectWallet(): Promise<string[]>;
/**
* Get current Metamask wallet address
* @return {Promise<string[]>} - wallet address
* @async
*/
getAddress(): Promise<string[]>;
/**
* Get balance from current wallet in native coin
* @param {GetBalanceProps} getBalanceProps -
* custom props if balance in custom network and address needed
* @param {ChainIds} network
* @param {string} address
* @return {Promise<number[]>} - balance value
* @async
*/
getBalance({ network, address }: GetBalanceProps): Promise<number[]>;
/**
* Get balance from current wallet in native coin
* @param {GetBalanceProps[]} accounts -
* @return {Promise<AccountInfo[]>} - balance value
* @async
*/
getAccountInfo(accounts: GetBalanceProps[]): Promise<AccountInfo[]>;
/**
* Get Chain
* @return {Promise<ChainInfo|null>} - Chain class with chainId and name
* @async
*/
getChain(): Promise<ChainInfo | null>;
/**
* Switch to another chain network
* @param {ChainIds} chainId - id of Chain
* @return {Promise<void>}
* @async
*/
switchNetwork(chainId: ChainIds): Promise<void>;
/**
* Switch to custom chain network
* @param {AddEthereumChainParameter} network - Object of chain network
* @return {Promise<void>}
* @async
*/
switchCustomNetwork(network: AddEthereumChainParameter): Promise<void>;
/**
* Add coin token (only ERC20 for now @metamask docs) to metamask
* @param {CoinsTypes} token - CoinsTypes, like USDT
* @return {Promise<boolean>}
* @async
*/
addToken(token: ERC20Names): Promise<boolean>;
/**
* Add custom token (only ERC20 for now @metamask docs) to metamask
* @param {WatchAssetParams} newAsset - Asset object
* @return {Promise<boolean>}
* @async
*/
addCustomToken(newAsset: WatchAssetParams): Promise<boolean>;
/**
* Sign transaction with metamask
* @param {SignProps} object - Sign Object with type and message
* @return {Promise<void>}
* @async
*/
sign({ type, message }: SignProps): Promise<void>;
/**
* Transfer native coin
* @param {TransferToken} args
* @return {Promise<ethers.providers.TransactionResponse | null>}
* @async
*/
transfer(args: TransferToken): Promise<ethers.providers.TransactionResponse | null>;
/**
* Send Transaction with user's metamask
* @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} tx - Transaction Request
* @return {Promise<ethers.providers.TransactionResponse>}
* @async
*/
sendSignedTransaction({ tx, }: {
tx?: ethers.utils.Deferrable<ethers.providers.TransactionRequest>;
}): Promise<ethers.providers.TransactionResponse>;
/**
* Send Transaction
* @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} tx - Transaction Request
* @return {Promise<ethers.providers.TransactionResponse>}
* @async
*/
sendTransaction(tx: string): Promise<ethers.providers.TransactionResponse>;
addEventListener(eventFilter: ethers.providers.EventType, listener: ethers.providers.Listener): Promise<void>;
scanQrCode(regex?: RegExp): Promise<string>;
/**
* Get lint for mobile metamask
* @return {string}
*/
getMobileLink(): string;
}