aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-03-09 22:08:02 +0800
committerFabio Berger <me@fabioberger.com>2018-03-09 22:08:02 +0800
commit918f3cde948592e9cb83342c051b71378821f3c5 (patch)
tree8b1599d45aa942e2de7065919fe684787c1971f5 /packages
parent7b82a8669d7a7c69d879349a083424d5dcdf79ec (diff)
downloaddexon-0x-contracts-918f3cde948592e9cb83342c051b71378821f3c5.tar
dexon-0x-contracts-918f3cde948592e9cb83342c051b71378821f3c5.tar.gz
dexon-0x-contracts-918f3cde948592e9cb83342c051b71378821f3c5.tar.bz2
dexon-0x-contracts-918f3cde948592e9cb83342c051b71378821f3c5.tar.lz
dexon-0x-contracts-918f3cde948592e9cb83342c051b71378821f3c5.tar.xz
dexon-0x-contracts-918f3cde948592e9cb83342c051b71378821f3c5.tar.zst
dexon-0x-contracts-918f3cde948592e9cb83342c051b71378821f3c5.zip
Remove duplicitous methods from website's webWrapper
Diffstat (limited to 'packages')
-rw-r--r--packages/website/package.json1
-rw-r--r--packages/website/ts/web3_wrapper.ts44
2 files changed, 9 insertions, 36 deletions
diff --git a/packages/website/package.json b/packages/website/package.json
index db3035642..a7fc1fe26 100644
--- a/packages/website/package.json
+++ b/packages/website/package.json
@@ -22,6 +22,7 @@
"@0xproject/react-docs": "^0.0.1",
"@0xproject/react-shared": "^0.0.1",
"@0xproject/subproviders": "^0.7.0",
+ "@0xproject/web3-wrapper": "^0.2.1",
"@0xproject/utils": "^0.4.1",
"accounting": "^0.4.1",
"basscss": "^8.0.3",
diff --git a/packages/website/ts/web3_wrapper.ts b/packages/website/ts/web3_wrapper.ts
index 9d8d771af..fca98ac8f 100644
--- a/packages/website/ts/web3_wrapper.ts
+++ b/packages/website/ts/web3_wrapper.ts
@@ -1,10 +1,11 @@
import { BigNumber, intervalUtils, promisify } from '@0xproject/utils';
+import { Web3Wrapper as Web3WrapperBase } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { Dispatcher } from 'ts/redux/dispatcher';
import { utils } from 'ts/utils/utils';
import * as Web3 from 'web3';
-export class Web3Wrapper {
+export class Web3Wrapper extends Web3WrapperBase {
private _dispatcher: Dispatcher;
private _web3: Web3;
private _prevNetworkId: number;
@@ -18,6 +19,7 @@ export class Web3Wrapper {
networkIdIfExists: number,
shouldPollUserAddress: boolean,
) {
+ super(provider);
this._dispatcher = dispatcher;
this._prevNetworkId = networkIdIfExists;
this._shouldPollUserAddress = shouldPollUserAddress;
@@ -25,56 +27,30 @@ export class Web3Wrapper {
this._web3 = new Web3();
this._web3.setProvider(provider);
}
- public isAddress(address: string) {
- return this._web3.isAddress(address);
- }
- public async getAccountsAsync(): Promise<string[]> {
- const addresses = await promisify<string[]>(this._web3.eth.getAccounts)();
- return addresses;
- }
public async getFirstAccountIfExistsAsync() {
- const addresses = await this.getAccountsAsync();
+ const addresses = await this.getAvailableAddressesAsync();
if (_.isEmpty(addresses)) {
return '';
}
return addresses[0];
}
- public async getNodeVersionAsync(): Promise<string> {
- const nodeVersion = await promisify<string>(this._web3.version.getNode)();
- return nodeVersion;
- }
public getProviderObj() {
return this._web3.currentProvider;
}
- public async getNetworkIdIfExists() {
+ public async getNetworkIdIfExistsAsync(): Promise<number | undefined> {
try {
- const networkId = await this._getNetworkAsync();
+ const networkId = await this.getNetworkIdAsync();
return Number(networkId);
} catch (err) {
return undefined;
}
}
public async getBalanceInEthAsync(owner: string): Promise<BigNumber> {
- const balanceInWei: BigNumber = await promisify<BigNumber>(this._web3.eth.getBalance)(owner);
+ const balanceInWei = await this.getBalanceInWeiAsync(owner);
const balanceEthOldBigNumber = this._web3.fromWei(balanceInWei, 'ether');
const balanceEth = new BigNumber(balanceEthOldBigNumber);
return balanceEth;
}
- public async doesContractExistAtAddressAsync(address: string): Promise<boolean> {
- const code = await promisify<string>(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<string> {
- const signData = await promisify<string>(this._web3.eth.sign)(address, message);
- return signData;
- }
- public async getBlockTimestampAsync(blockHash: string): Promise<number> {
- const { timestamp } = await promisify<Web3.BlockWithoutTransactionData>(this._web3.eth.getBlock)(blockHash);
- return timestamp;
- }
public destroy() {
this._stopEmittingNetworkConnectionAndUserBalanceStateAsync();
// HACK: stop() is only available on providerEngine instances
@@ -98,7 +74,7 @@ export class Web3Wrapper {
this._watchNetworkAndBalanceIntervalId = intervalUtils.setAsyncExcludingInterval(
async () => {
// Check for network state changes
- const currentNetworkId = await this.getNetworkIdIfExists();
+ const currentNetworkId = await this.getNetworkIdIfExistsAsync();
if (currentNetworkId !== this._prevNetworkId) {
this._prevNetworkId = currentNetworkId;
this._dispatcher.updateNetworkId(currentNetworkId);
@@ -138,10 +114,6 @@ export class Web3Wrapper {
},
);
}
- private async _getNetworkAsync() {
- const networkId = await promisify(this._web3.version.getNetwork)();
- return networkId;
- }
private async _updateUserEtherBalanceAsync(userAddress: string) {
const balance = await this.getBalanceInEthAsync(userAddress);
if (!balance.eq(this._prevUserEtherBalanceInEth)) {