import { HistoryItem , SharedState } from '../worker/WorkerState' ; import { AuthenticateRequest , AuthenticateResponse , CloseChannelsForCurrentHubRequest , DepositRequest , DidStoreMnemonicRequest , FetchHistoryRequest , GenKeyringRequest , GetSharedStateRequest , LockWalletRequest , PopulateChannelsRequest , RememberPageRequest , ResetRequest , RestoreWalletRequest , SendRequest , StatusRequest , ToggleFrameRequest , UnlockWalletRequest } from '../lib/rpc/yns' ; import * as BigNumber from 'bignumber.js' ; import JsonRpcClient from '../lib/messaging/JsonRpcClient' ; import { WorkerStatus } from '../lib/rpc/WorkerStatus' ; import { JSONRPCResponsePayload } from 'web3' ; import { Postable } from '../lib/messaging/Postable' ; import Web3 = require ( 'web3' ) ; export default class WorkerProxy extends JsonRpcClient { web3 : Web3 ; constructor ( target ) { super ( 'WorkerProxy' , target , navigator . serviceWorker , window . location . origin ) ; this . web3 = new Web3 ( { sendAsync : ( payload , callback ) => { this . call ( payload . method , ... payload . params ) . then ( ( res ) => { ( callback as any ) ( null , res ) ; } ) . catch ( ( e ) => { ( callback as any ) ( e , null ) ; } ) ; } } ) ; } closeChannelsForCurrentHub ( ) { return this . call ( CloseChannelsForCurrentHubRequest . method ) ; } deposit ( amount ) { return this . call ( DepositRequest . method , amount . toNumber ( ) ) ; } populateChannels ( ) { return this . call ( PopulateChannelsRequest . method ) ; } getWeb3 ( ) { return this . web3 ; } doLock ( ) { return this . call ( LockWalletRequest . method ) ; } doUnlock ( password ) { return this . call ( UnlockWalletRequest . method , password ) ; } genKeyring ( password ) { return this . call ( GenKeyringRequest . method , password ) ; } restoreWallet ( password , mnemonic ) { return this . call ( RestoreWalletRequest . method , password , mnemonic ) ; } getSharedState ( ) { return this . call ( GetSharedStateRequest . method ) ; } didStoreMnemonic ( ) { return this . call ( DidStoreMnemonicRequest . method ) ; } rememberPage ( path ) { return this . call ( RememberPageRequest . method , path ) ; } authenticate ( ) { return this . call ( AuthenticateRequest . method , window . location . hostname ) ; } toggleFrame ( status , forceRedirect ? ) { return this . call ( ToggleFrameRequest . method , status , forceRedirect ) ; } fetchHistory ( ) { return this . call ( FetchHistoryRequest . method ) ; } send ( to , value , gas ? , gasPrice ? ) { return this . call ( SendRequest . method , to , value , gas , gasPrice ) ; } status ( ) { return this . callWithTimeout ( 500 , StatusRequest . method ) ; } reset ( ) { return this . call ( ResetRequest . method ) ; } }