import WalletConnectProvider, { ProviderOptions as WalletConnectProviderConfig, } from '@walletconnect/web3-provider'; import Web3 from 'web3'; import { Provider } from 'web3/providers'; import { Bitski, BitskiSDKOptions } from 'bitski'; import { O } from 'ts-toolbelt'; import Fortmatic from 'fortmatic'; export type ConnectionStatus = 'disconnected' | 'pending' | 'connected'; export interface ConnectResult { web3: Web3; account: string; } export type ConnectionDetails = { wallet: T; provider: Provider; } & (InitializationResult extends null ? {} : { payload: InitializationResult; }); export type ConnectionDetailsUnion = T extends WalletType ? ConnectionDetails : never; // type: [InitializationResult, InitializationConfig] interface WalletsSignatures { 'wallet-connect': [WalletConnectProvider, WalletConnectProviderConfig]; bitski: [Bitski, BitskiConfig]; metamask: [null, null]; fortmatic: [Fortmatic, FortmaticConfig]; // portis: [null, null]; // squarelink: [null, null]; // torus: [null, null]; // ledger: [null, null]; } export type WalletType = keyof WalletsSignatures; type InitializationResult = WalletsSignatures[K][0]; type InitializationConfig = WalletsSignatures[K][1]; type MaybePromise = T | Promise; export type Resolver = { initialize(config: InitializationConfig): MaybePromise>; destroy(details: ConnectionDetails): MaybePromise; }; export type Resolvers = { [key in WalletType]: Resolver; }; /* *** Wallet Configs *** */ export type WalletConfigs = O.Filter< { [T in WalletType]: InitializationConfig; }, null >; interface BitskiConfig { clientId: string; redirectUri: string; additionalScopes?: string[]; options?: BitskiSDKOptions; } interface FortmaticConfig { apiKey: string; network?: 'rinkeby' | 'kovan' | 'ropsten'; } /* *** Other *** */ export interface MetamaskInpageProvider extends Provider { enable?(): Promise; }