import { EthAddress } from "@joincivil/typescript-types" ; import { CivilErrors , isDefined } from "@joincivil/utils" ; import { Observable } from "rxjs/Observable" ; import { EthApi } from "./ethapi" ; export function requireAccount ( ethApi ) { return ethApi . accountStream . first ( ) . map ( account => { if ( isDefined ( account ) ) { return account ; } throw new Error ( CivilErrors . NoUnlockedAccount ) ; } ) ; } export function hasInjectedProvider ( ) { return typeof window !== "undefined" && ( window as any ) . web3 !== undefined ; } export async function currentAccount ( ethApi ) { return ethApi . accountStream . first ( ) . toPromise ( ) ; } export async function currentNetwork ( ethApi ) { return ethApi . networkStream . first ( ) . toPromise ( ) ; } export enum EthereumUnits { wei = "1" , kwei = "1000" , mwei = "1000000" , gwei = "1000000000" , microether = "1000000000000" , milliether = "1000000000000000" , ether = "1000000000000000000" , kether = "1000000000000000000000" , mether = "1000000000000000000000000" , gether = "1000000000000000000000000000" , tether = "1000000000000000000000000000000" , babbage = "1000" , lovelace = "1000000" , shannon = "1000000000" , szabo = "1000000000000" , finney = "1000000000000000" }