From f1b267cc9fe7f6e5566dc2535b064b92aef92df1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 6 Dec 2017 20:55:09 +0300 Subject: Refactor web3Wrapper to a separate package --- packages/website/package.json | 1 - packages/website/ts/blockchain.ts | 6 +++--- .../ts/components/ui/lifecycle_raised_button.tsx | 2 +- packages/website/ts/globals.d.ts | 1 - .../ts/subproviders/redundant_rpc_subprovider.ts | 2 +- packages/website/ts/web3_wrapper.ts | 18 +++++++++--------- 6 files changed, 14 insertions(+), 16 deletions(-) (limited to 'packages/website') diff --git a/packages/website/package.json b/packages/website/package.json index 68e9e8f47..fdc5de5d7 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -27,7 +27,6 @@ "dateformat": "^2.0.0", "deep-equal": "^1.0.1", "dharma-loan-frame": "^0.0.12", - "es6-promisify": "^5.0.0", "ethereum-address": "^0.0.4", "ethereumjs-tx": "^1.3.3", "ethereumjs-util": "^5.1.1", diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 31d725a41..9136dc916 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -16,9 +16,9 @@ import { ZeroEx, ZeroExError, } from '0x.js'; +import {promisify} from '@0xproject/utils'; import BigNumber from 'bignumber.js'; import compareVersions = require('compare-versions'); -import promisify = require('es6-promisify'); import ethUtil = require('ethereumjs-util'); import findVersions = require('find-versions'); import * as _ from 'lodash'; @@ -65,7 +65,7 @@ export class Blockchain { public nodeVersion: string; private zeroEx: ZeroEx; private dispatcher: Dispatcher; - private web3Wrapper: Web3Wrapper; + private web3Wrapper?: Web3Wrapper; private exchangeAddress: string; private tokenTransferProxy: ContractInstance; private tokenRegistry: ContractInstance; @@ -624,7 +624,7 @@ export class Blockchain { let networkId: number; if (!_.isUndefined(injectedWeb3)) { try { - networkId = _.parseInt(await promisify(injectedWeb3.version.getNetwork)()); + networkId = _.parseInt(await promisify(injectedWeb3.version.getNetwork)()); } catch (err) { // Ignore error and proceed with networkId undefined } diff --git a/packages/website/ts/components/ui/lifecycle_raised_button.tsx b/packages/website/ts/components/ui/lifecycle_raised_button.tsx index 338a3bf76..cba94ca8c 100644 --- a/packages/website/ts/components/ui/lifecycle_raised_button.tsx +++ b/packages/website/ts/components/ui/lifecycle_raised_button.tsx @@ -20,7 +20,7 @@ interface LifeCycleRaisedButtonProps { labelReady: React.ReactNode|string; labelLoading: React.ReactNode|string; labelComplete: React.ReactNode|string; - onClickAsyncFn: () => boolean; + onClickAsyncFn: () => Promise; backgroundColor?: string; labelColor?: string; } diff --git a/packages/website/ts/globals.d.ts b/packages/website/ts/globals.d.ts index c5b94dc45..7bbbb3a98 100644 --- a/packages/website/ts/globals.d.ts +++ b/packages/website/ts/globals.d.ts @@ -1,6 +1,5 @@ declare module 'react-tooltip'; declare module 'react-router-hash-link'; -declare module 'es6-promisify'; declare module 'truffle-contract'; declare module 'ethereumjs-util'; declare module 'keccak'; diff --git a/packages/website/ts/subproviders/redundant_rpc_subprovider.ts b/packages/website/ts/subproviders/redundant_rpc_subprovider.ts index 8dffd4437..d540e6e7b 100644 --- a/packages/website/ts/subproviders/redundant_rpc_subprovider.ts +++ b/packages/website/ts/subproviders/redundant_rpc_subprovider.ts @@ -1,4 +1,4 @@ -import promisify = require('es6-promisify'); +import {promisify} from '@0xproject/utils'; import * as _ from 'lodash'; import {JSONRPCPayload} from 'ts/types'; import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); diff --git a/packages/website/ts/web3_wrapper.ts b/packages/website/ts/web3_wrapper.ts index c43436c7e..b713f8a33 100644 --- a/packages/website/ts/web3_wrapper.ts +++ b/packages/website/ts/web3_wrapper.ts @@ -1,8 +1,8 @@ +import {promisify} from '@0xproject/utils'; import BigNumber from 'bignumber.js'; -import promisify = require('es6-promisify'); import * as _ from 'lodash'; import {Dispatcher} from 'ts/redux/dispatcher'; -import Web3 = require('web3'); +import * as Web3 from 'web3'; export class Web3Wrapper { private dispatcher: Dispatcher; @@ -28,7 +28,7 @@ export class Web3Wrapper { return this.web3.isAddress(address); } public async getAccountsAsync(): Promise { - const addresses = await promisify(this.web3.eth.getAccounts)(); + const addresses = await promisify(this.web3.eth.getAccounts)(); return addresses; } public async getFirstAccountIfExistsAsync() { @@ -38,8 +38,8 @@ export class Web3Wrapper { } return (addresses)[0]; } - public async getNodeVersionAsync() { - const nodeVersion = await promisify(this.web3.version.getNode)(); + public async getNodeVersionAsync(): Promise { + const nodeVersion = await promisify(this.web3.version.getNode)(); return nodeVersion; } public getProviderObj() { @@ -54,24 +54,24 @@ export class Web3Wrapper { } } public async getBalanceInEthAsync(owner: string): Promise { - const balanceInWei: BigNumber = await promisify(this.web3.eth.getBalance)(owner); + const balanceInWei: BigNumber = await promisify(this.web3.eth.getBalance)(owner); const balanceEthOldBigNumber = this.web3.fromWei(balanceInWei, 'ether'); const balanceEth = new BigNumber(balanceEthOldBigNumber); return balanceEth; } public async doesContractExistAtAddressAsync(address: string): Promise { - const code = await promisify(this.web3.eth.getCode)(address); + const code = await promisify(this.web3.eth.getCode)(address); // Regex matches 0x0, 0x00, 0x in order to accomodate poorly implemented clients const zeroHexAddressRegex = /^0[xX][0]*$/; const didFindCode = _.isNull(code.match(zeroHexAddressRegex)); return didFindCode; } public async signTransactionAsync(address: string, message: string): Promise { - const signData = await promisify(this.web3.eth.sign)(address, message); + const signData = await promisify(this.web3.eth.sign)(address, message); return signData; } public async getBlockTimestampAsync(blockHash: string): Promise { - const {timestamp} = await promisify(this.web3.eth.getBlock)(blockHash); + const {timestamp} = await promisify(this.web3.eth.getBlock)(blockHash); return timestamp; } public destroy() { -- cgit v1.2.3