aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2018-01-11 02:35:37 +0800
committerGitHub <noreply@github.com>2018-01-11 02:35:37 +0800
commitde943c5f305402bc64a6b3273c59669faa62a60d (patch)
tree936eae17521984e5ccc28057973461e707322326 /packages
parente6a783aff803c276392efec93571d24fc96feb6e (diff)
parente34b0af25133629ad4c177c4d7d5050bd6ac19b8 (diff)
downloaddexon-0x-contracts-de943c5f305402bc64a6b3273c59669faa62a60d.tar.gz
dexon-0x-contracts-de943c5f305402bc64a6b3273c59669faa62a60d.tar.zst
dexon-0x-contracts-de943c5f305402bc64a6b3273c59669faa62a60d.zip
Merge pull request #307 from 0xProject/feature/web3-type-roots
Base tsconfig.json
Diffstat (limited to 'packages')
-rw-r--r--packages/0x.js/package.json2
-rw-r--r--packages/0x.js/src/0x.ts7
-rw-r--r--packages/0x.js/src/contract_wrappers/contract_wrapper.ts5
-rw-r--r--packages/0x.js/test/ether_token_wrapper_test.ts103
-rw-r--r--packages/0x.js/test/exchange_wrapper_test.ts45
-rw-r--r--packages/0x.js/test/expiration_watcher_test.ts10
-rw-r--r--packages/0x.js/test/order_state_watcher_test.ts47
-rw-r--r--packages/0x.js/test/subscription_test.ts22
-rw-r--r--packages/0x.js/test/token_wrapper_test.ts64
-rw-r--r--packages/0x.js/test/utils/report_callback_errors.ts58
-rw-r--r--packages/0x.js/tsconfig.json10
-rw-r--r--packages/abi-gen/src/types.ts7
-rw-r--r--packages/abi-gen/src/utils.ts4
-rw-r--r--packages/abi-gen/tsconfig.json10
-rw-r--r--packages/assert/src/index.ts7
-rw-r--r--packages/assert/test/assert_test.ts12
-rw-r--r--packages/assert/tsconfig.json17
-rw-r--r--packages/connect/package.json2
-rw-r--r--packages/connect/tsconfig.json13
-rw-r--r--packages/contracts/deploy/solc/bin_paths.ts2
-rw-r--r--packages/contracts/deploy/src/utils/contract.ts4
-rw-r--r--packages/contracts/package.json2
-rw-r--r--packages/contracts/tsconfig.json12
-rw-r--r--packages/dev-utils/tsconfig.json10
-rw-r--r--packages/json-schemas/tsconfig.json10
-rw-r--r--packages/kovan-faucets/package.json2
-rw-r--r--packages/kovan-faucets/src/ts/configs.ts2
-rw-r--r--packages/kovan-faucets/src/ts/id_management.ts4
-rw-r--r--packages/kovan-faucets/src/ts/request_queue.ts4
-rw-r--r--packages/kovan-faucets/tsconfig.json12
-rw-r--r--packages/monorepo-scripts/tsconfig.json8
-rw-r--r--packages/subproviders/tsconfig.json13
-rw-r--r--packages/tslint-config/tsconfig.json10
-rw-r--r--packages/types/tsconfig.json10
-rw-r--r--packages/utils/tsconfig.json12
-rw-r--r--packages/web3-typescript-typings/.gitignore2
-rw-r--r--packages/web3-typescript-typings/README.md49
-rw-r--r--packages/web3-typescript-typings/index.d.ts421
-rw-r--r--packages/web3-typescript-typings/package.json30
-rw-r--r--packages/web3-typescript-typings/tslint.json3
-rw-r--r--packages/web3-typescript-typings/yarn.lock197
-rw-r--r--packages/web3-wrapper/package.json2
-rw-r--r--packages/web3-wrapper/src/index.ts2
-rw-r--r--packages/web3-wrapper/tsconfig.json10
-rw-r--r--packages/website/package.json2
-rw-r--r--packages/website/ts/blockchain.ts6
-rw-r--r--packages/website/ts/components/dialogs/ledger_config_dialog.tsx10
-rw-r--r--packages/website/ts/components/fill_warning_dialog.tsx2
-rw-r--r--packages/website/ts/components/inputs/allowance_toggle.tsx7
-rw-r--r--packages/website/ts/components/inputs/token_amount_input.tsx2
-rw-r--r--packages/website/ts/components/portal.tsx10
-rw-r--r--packages/website/ts/components/top_bar.tsx12
-rw-r--r--packages/website/ts/containers/portal.tsx8
-rw-r--r--packages/website/ts/local_storage/tracked_token_storage.ts10
-rw-r--r--packages/website/ts/types.ts6
-rw-r--r--packages/website/ts/utils/doc_utils.ts4
-rw-r--r--packages/website/tsconfig.json9
57 files changed, 1013 insertions, 353 deletions
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json
index b0c646bc5..41dc65467 100644
--- a/packages/0x.js/package.json
+++ b/packages/0x.js/package.json
@@ -78,7 +78,7 @@
"typedoc": "~0.8.0",
"typescript": "~2.6.1",
"web3-provider-engine": "^13.0.1",
- "web3-typescript-typings": "^0.7.2",
+ "web3-typescript-typings": "^0.9.0",
"webpack": "^3.1.0"
},
"dependencies": {
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts
index 67b75df95..244b77a85 100644
--- a/packages/0x.js/src/0x.ts
+++ b/packages/0x.js/src/0x.ts
@@ -213,12 +213,17 @@ export class ZeroEx {
* @param networkId The id of the network your provider is connected to
*/
public setProvider(provider: Web3Provider, networkId: number): void {
- this._web3Wrapper.setProvider(provider, networkId);
+ this._web3Wrapper.setProvider(provider);
(this.exchange as any)._invalidateContractInstances();
+ (this.exchange as any)._setNetworkId(networkId);
(this.tokenRegistry as any)._invalidateContractInstance();
+ (this.tokenRegistry as any)._setNetworkId(networkId);
(this.token as any)._invalidateContractInstances();
+ (this.token as any)._setNetworkId(networkId);
(this.proxy as any)._invalidateContractInstance();
+ (this.proxy as any)._setNetworkId(networkId);
(this.etherToken as any)._invalidateContractInstance();
+ (this.etherToken as any)._setNetworkId(networkId);
}
/**
* Get user Ethereum addresses available through the supplied web3 provider available for sending transactions.
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
index eb7e042e7..9c4e5dfd3 100644
--- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
@@ -87,7 +87,7 @@ export class ContractWrapper {
}
const filterToken = filterUtils.generateUUID();
this._filters[filterToken] = filter;
- this._filterCallbacks[filterToken] = callback;
+ this._filterCallbacks[filterToken] = callback as EventCallback<ContractEventArgs>;
return filterToken;
}
protected async _getLogsAsync<ArgsType extends ContractEventArgs>(
@@ -177,6 +177,9 @@ export class ContractWrapper {
this._onLogStateChanged.bind(this, isRemoved),
);
}
+ private _setNetworkId(networkId: number): void {
+ this._networkId = networkId;
+ }
private _stopBlockAndLogStream(): void {
if (_.isUndefined(this._blockAndLogStreamerIfExists)) {
throw new Error(ZeroExError.SubscriptionNotFound);
diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts
index db7acc8e5..b810fc9f1 100644
--- a/packages/0x.js/test/ether_token_wrapper_test.ts
+++ b/packages/0x.js/test/ether_token_wrapper_test.ts
@@ -22,6 +22,7 @@ import { DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
+import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
import { web3Factory } from './utils/web3_factory';
@@ -153,19 +154,19 @@ describe('EtherTokenWrapper', () => {
// Source: https://github.com/mochajs/mocha/issues/2407
it('Should receive the Transfer event when tokens are transfered', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<TransferContractEventArgs>) => {
- expect(err).to.be.null();
- expect(logEvent).to.not.be.undefined();
- expect(logEvent.isRemoved).to.be.false();
- expect(logEvent.log.logIndex).to.be.equal(0);
- expect(logEvent.log.transactionIndex).to.be.equal(0);
- expect(logEvent.log.blockNumber).to.be.a('number');
- const args = logEvent.log.args;
- expect(args._from).to.be.equal(addressWithETH);
- expect(args._to).to.be.equal(addressWithoutFunds);
- expect(args._value).to.be.bignumber.equal(transferAmount);
- done();
- };
+ const callback = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<TransferContractEventArgs>) => {
+ expect(logEvent).to.not.be.undefined();
+ expect(logEvent.isRemoved).to.be.false();
+ expect(logEvent.log.logIndex).to.be.equal(0);
+ expect(logEvent.log.transactionIndex).to.be.equal(0);
+ expect(logEvent.log.blockNumber).to.be.a('number');
+ const args = logEvent.log.args;
+ expect(args._from).to.be.equal(addressWithETH);
+ expect(args._to).to.be.equal(addressWithoutFunds);
+ expect(args._value).to.be.bignumber.equal(transferAmount);
+ },
+ );
await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH);
zeroEx.etherToken.subscribe(etherTokenAddress, EtherTokenEvents.Transfer, indexFilterValues, callback);
await zeroEx.token.transferAsync(
@@ -178,16 +179,16 @@ describe('EtherTokenWrapper', () => {
});
it('Should receive the Approval event when allowance is being set', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- expect(err).to.be.null();
- expect(logEvent).to.not.be.undefined();
- expect(logEvent.isRemoved).to.be.false();
- const args = logEvent.log.args;
- expect(args._owner).to.be.equal(addressWithETH);
- expect(args._spender).to.be.equal(addressWithoutFunds);
- expect(args._value).to.be.bignumber.equal(allowanceAmount);
- done();
- };
+ const callback = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ expect(logEvent).to.not.be.undefined();
+ expect(logEvent.isRemoved).to.be.false();
+ const args = logEvent.log.args;
+ expect(args._owner).to.be.equal(addressWithETH);
+ expect(args._spender).to.be.equal(addressWithoutFunds);
+ expect(args._value).to.be.bignumber.equal(allowanceAmount);
+ },
+ );
zeroEx.etherToken.subscribe(etherTokenAddress, EtherTokenEvents.Approval, indexFilterValues, callback);
await zeroEx.token.setAllowanceAsync(
etherTokenAddress,
@@ -199,30 +200,30 @@ describe('EtherTokenWrapper', () => {
});
it('Should receive the Deposit event when ether is being deposited', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<DepositContractEventArgs>) => {
- expect(err).to.be.null();
- expect(logEvent).to.not.be.undefined();
- expect(logEvent.isRemoved).to.be.false();
- const args = logEvent.log.args;
- expect(args._owner).to.be.equal(addressWithETH);
- expect(args._value).to.be.bignumber.equal(depositAmount);
- done();
- };
+ const callback = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<DepositContractEventArgs>) => {
+ expect(logEvent).to.not.be.undefined();
+ expect(logEvent.isRemoved).to.be.false();
+ const args = logEvent.log.args;
+ expect(args._owner).to.be.equal(addressWithETH);
+ expect(args._value).to.be.bignumber.equal(depositAmount);
+ },
+ );
zeroEx.etherToken.subscribe(etherTokenAddress, EtherTokenEvents.Deposit, indexFilterValues, callback);
await zeroEx.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH);
})().catch(done);
});
it('Should receive the Withdrawal event when ether is being withdrawn', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<WithdrawalContractEventArgs>) => {
- expect(err).to.be.null();
- expect(logEvent).to.not.be.undefined();
- expect(logEvent.isRemoved).to.be.false();
- const args = logEvent.log.args;
- expect(args._owner).to.be.equal(addressWithETH);
- expect(args._value).to.be.bignumber.equal(depositAmount);
- done();
- };
+ const callback = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<WithdrawalContractEventArgs>) => {
+ expect(logEvent).to.not.be.undefined();
+ expect(logEvent.isRemoved).to.be.false();
+ const args = logEvent.log.args;
+ expect(args._owner).to.be.equal(addressWithETH);
+ expect(args._value).to.be.bignumber.equal(depositAmount);
+ },
+ );
await zeroEx.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH);
zeroEx.etherToken.subscribe(
etherTokenAddress,
@@ -235,18 +236,18 @@ describe('EtherTokenWrapper', () => {
});
it('should cancel outstanding subscriptions when ZeroEx.setProvider is called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- done(new Error('Expected this subscription to have been cancelled'));
- };
+ const callbackNeverToBeCalled = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ done(new Error('Expected this subscription to have been cancelled'));
+ },
+ );
zeroEx.etherToken.subscribe(
etherTokenAddress,
EtherTokenEvents.Transfer,
indexFilterValues,
callbackNeverToBeCalled,
);
- const callbackToBeCalled = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- done();
- };
+ const callbackToBeCalled = reportNodeCallbackErrors(done)();
const newProvider = web3Factory.getRpcProvider();
zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH);
@@ -266,9 +267,11 @@ describe('EtherTokenWrapper', () => {
});
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- done(new Error('Expected this subscription to have been cancelled'));
- };
+ const callbackNeverToBeCalled = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ done(new Error('Expected this subscription to have been cancelled'));
+ },
+ );
await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH);
const subscriptionToken = zeroEx.etherToken.subscribe(
etherTokenAddress,
diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts
index cb927ba8f..39a5be61d 100644
--- a/packages/0x.js/test/exchange_wrapper_test.ts
+++ b/packages/0x.js/test/exchange_wrapper_test.ts
@@ -1,6 +1,7 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
+import * as _ from 'lodash';
import 'mocha';
import * as Web3 from 'web3';
@@ -22,6 +23,7 @@ import { BlockParamLiteral, DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios';
+import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
import { web3Factory } from './utils/web3_factory';
@@ -851,10 +853,11 @@ describe('ExchangeWrapper', () => {
// Source: https://github.com/mochajs/mocha/issues/2407
it('Should receive the LogFill event when an order is filled', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
- expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill);
- done();
- };
+ const callback = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
+ expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill);
+ },
+ );
zeroEx.exchange.subscribe(ExchangeEvents.LogFill, indexFilterValues, callback);
await zeroEx.exchange.fillOrderAsync(
signedOrder,
@@ -866,28 +869,32 @@ describe('ExchangeWrapper', () => {
});
it('Should receive the LogCancel event when an order is cancelled', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<LogCancelContractEventArgs>) => {
- expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogCancel);
- done();
- };
+ const callback = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<LogCancelContractEventArgs>) => {
+ expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogCancel);
+ },
+ );
zeroEx.exchange.subscribe(ExchangeEvents.LogCancel, indexFilterValues, callback);
await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelTakerAmountInBaseUnits);
})().catch(done);
});
it('Outstanding subscriptions are cancelled when zeroEx.setProvider called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
- done(new Error('Expected this subscription to have been cancelled'));
- };
+ const callbackNeverToBeCalled = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
+ done(new Error('Expected this subscription to have been cancelled'));
+ },
+ );
zeroEx.exchange.subscribe(ExchangeEvents.LogFill, indexFilterValues, callbackNeverToBeCalled);
const newProvider = web3Factory.getRpcProvider();
zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
- const callback = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
- expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill);
- done();
- };
+ const callback = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
+ expect(logEvent.log.event).to.be.equal(ExchangeEvents.LogFill);
+ },
+ );
zeroEx.exchange.subscribe(ExchangeEvents.LogFill, indexFilterValues, callback);
await zeroEx.exchange.fillOrderAsync(
signedOrder,
@@ -899,9 +906,11 @@ describe('ExchangeWrapper', () => {
});
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
- done(new Error('Expected this subscription to have been cancelled'));
- };
+ const callbackNeverToBeCalled = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
+ done(new Error('Expected this subscription to have been cancelled'));
+ },
+ );
const subscriptionToken = zeroEx.exchange.subscribe(
ExchangeEvents.LogFill,
indexFilterValues,
diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts
index e7ba3533a..770615f88 100644
--- a/packages/0x.js/test/expiration_watcher_test.ts
+++ b/packages/0x.js/test/expiration_watcher_test.ts
@@ -15,7 +15,7 @@ import { utils } from '../src/utils/utils';
import { chaiSetup } from './utils/chai_setup';
import { constants as testConstants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios';
-import { reportCallbackErrors } from './utils/report_callback_errors';
+import { reportNoErrorCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
import { web3Factory } from './utils/web3_factory';
@@ -87,10 +87,9 @@ describe('ExpirationWatcher', () => {
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec.times(1000));
- const callbackAsync = reportCallbackErrors(done)(async (hash: string) => {
+ const callbackAsync = reportNoErrorCallbackErrors(done)((hash: string) => {
expect(hash).to.be.equal(orderHash);
expect(utils.getCurrentUnixTimestampSec()).to.be.bignumber.gte(expirationUnixTimestampSec);
- done();
});
expirationWatcher.subscribe(callbackAsync);
timer.tick(orderLifetimeSec * 1000);
@@ -110,7 +109,7 @@ describe('ExpirationWatcher', () => {
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec.times(1000));
- const callbackAsync = reportCallbackErrors(done)(async (hash: string) => {
+ const callbackAsync = reportNoErrorCallbackErrors(done)(async (hash: string) => {
done(new Error('Emitted expiration went before the order actually expired'));
});
expirationWatcher.subscribe(callbackAsync);
@@ -146,7 +145,8 @@ describe('ExpirationWatcher', () => {
expirationWatcher.addOrder(orderHash2, signedOrder2.expirationUnixTimestampSec.times(1000));
expirationWatcher.addOrder(orderHash1, signedOrder1.expirationUnixTimestampSec.times(1000));
const expirationOrder = [orderHash1, orderHash2];
- const callbackAsync = reportCallbackErrors(done)(async (hash: string) => {
+ const expectToBeCalledOnce = false;
+ const callbackAsync = reportNoErrorCallbackErrors(done, expectToBeCalledOnce)((hash: string) => {
const orderHash = expirationOrder.shift();
expect(hash).to.be.equal(orderHash);
if (_.isEmpty(expirationOrder)) {
diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts
index 9f284cfd9..311752bd8 100644
--- a/packages/0x.js/test/order_state_watcher_test.ts
+++ b/packages/0x.js/test/order_state_watcher_test.ts
@@ -20,7 +20,7 @@ import { DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios';
-import { reportCallbackErrors } from './utils/report_callback_errors';
+import { reportNoErrorCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
import { web3Factory } from './utils/web3_factory';
@@ -134,12 +134,11 @@ describe('OrderStateWatcher', () => {
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
const invalidOrderState = orderState as OrderStateInvalid;
expect(invalidOrderState.orderHash).to.be.equal(orderHash);
expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.InsufficientMakerAllowance);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.token.setProxyAllowanceAsync(makerToken.address, maker, new BigNumber(0));
@@ -155,7 +154,7 @@ describe('OrderStateWatcher', () => {
fillableAmount,
);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
throw new Error('OrderState callback fired for irrelevant order');
});
zeroEx.orderStateWatcher.subscribe(callback);
@@ -179,12 +178,11 @@ describe('OrderStateWatcher', () => {
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
const invalidOrderState = orderState as OrderStateInvalid;
expect(invalidOrderState.orderHash).to.be.equal(orderHash);
expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.InsufficientMakerBalance);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
const anyRecipient = taker;
@@ -204,12 +202,11 @@ describe('OrderStateWatcher', () => {
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
const invalidOrderState = orderState as OrderStateInvalid;
expect(invalidOrderState.orderHash).to.be.equal(orderHash);
expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.OrderRemainingFillAmountZero);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
@@ -237,7 +234,7 @@ describe('OrderStateWatcher', () => {
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
const validOrderState = orderState as OrderStateValid;
expect(validOrderState.orderHash).to.be.equal(orderHash);
@@ -251,7 +248,6 @@ describe('OrderStateWatcher', () => {
remainingFillable,
);
expect(orderRelevantState.makerBalance).to.be.bignumber.equal(remainingMakerBalance);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
const shouldThrowOnInsufficientBalanceOrAllowance = true;
@@ -277,9 +273,7 @@ describe('OrderStateWatcher', () => {
fillableAmount,
taker,
);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
- done();
- });
+ const callback = reportNoErrorCallbackErrors(done)();
zeroEx.orderStateWatcher.addOrder(signedOrder);
zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.token.setProxyAllowanceAsync(zrxTokenAddress, maker, new BigNumber(0));
@@ -301,7 +295,7 @@ describe('OrderStateWatcher', () => {
const fillAmountInBaseUnits = ZeroEx.toBaseUnitAmount(new BigNumber(2), decimals);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
const validOrderState = orderState as OrderStateValid;
expect(validOrderState.orderHash).to.be.equal(orderHash);
@@ -312,7 +306,6 @@ describe('OrderStateWatcher', () => {
expect(orderRelevantState.remainingFillableTakerTokenAmount).to.be.bignumber.equal(
ZeroEx.toBaseUnitAmount(new BigNumber(8), decimals),
);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
const shouldThrowOnInsufficientBalanceOrAllowance = true;
@@ -337,7 +330,7 @@ describe('OrderStateWatcher', () => {
const changedMakerApprovalAmount = ZeroEx.toBaseUnitAmount(new BigNumber(3), decimals);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
const validOrderState = orderState as OrderStateValid;
const orderRelevantState = validOrderState.orderRelevantState;
expect(orderRelevantState.remainingFillableMakerTokenAmount).to.be.bignumber.equal(
@@ -346,7 +339,6 @@ describe('OrderStateWatcher', () => {
expect(orderRelevantState.remainingFillableTakerTokenAmount).to.be.bignumber.equal(
changedMakerApprovalAmount,
);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.token.setProxyAllowanceAsync(makerToken.address, maker, changedMakerApprovalAmount);
@@ -368,7 +360,7 @@ describe('OrderStateWatcher', () => {
const transferAmount = makerBalance.sub(remainingAmount);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
const validOrderState = orderState as OrderStateValid;
const orderRelevantState = validOrderState.orderRelevantState;
@@ -378,7 +370,6 @@ describe('OrderStateWatcher', () => {
expect(orderRelevantState.remainingFillableTakerTokenAmount).to.be.bignumber.equal(
remainingAmount,
);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.token.transferAsync(makerToken.address, maker, ZeroEx.NULL_ADDRESS, transferAmount);
@@ -404,14 +395,13 @@ describe('OrderStateWatcher', () => {
const transferTokenAmount = makerFee.sub(remainingTokenAmount);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
const validOrderState = orderState as OrderStateValid;
const orderRelevantState = validOrderState.orderRelevantState;
expect(orderRelevantState.remainingFillableMakerTokenAmount).to.be.bignumber.equal(
remainingTokenAmount,
);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.exchange.cancelOrderAsync(signedOrder, transferTokenAmount);
@@ -439,13 +429,12 @@ describe('OrderStateWatcher', () => {
const transferTokenAmount = makerFee.sub(remainingTokenAmount);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
const validOrderState = orderState as OrderStateValid;
const orderRelevantState = validOrderState.orderRelevantState;
expect(orderRelevantState.remainingFillableMakerTokenAmount).to.be.bignumber.equal(
remainingFeeAmount,
);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.token.setProxyAllowanceAsync(zrxTokenAddress, maker, remainingFeeAmount);
@@ -475,13 +464,12 @@ describe('OrderStateWatcher', () => {
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
const validOrderState = orderState as OrderStateValid;
const orderRelevantState = validOrderState.orderRelevantState;
expect(orderRelevantState.remainingFillableMakerTokenAmount).to.be.bignumber.equal(
fillableAmount,
);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.token.setProxyAllowanceAsync(
@@ -504,12 +492,11 @@ describe('OrderStateWatcher', () => {
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
const invalidOrderState = orderState as OrderStateInvalid;
expect(invalidOrderState.orderHash).to.be.equal(orderHash);
expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.OrderRemainingFillAmountZero);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
@@ -529,12 +516,11 @@ describe('OrderStateWatcher', () => {
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.false();
const invalidOrderState = orderState as OrderStateInvalid;
expect(invalidOrderState.orderHash).to.be.equal(orderHash);
expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.OrderFillRoundingError);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.exchange.cancelOrderAsync(
@@ -557,13 +543,12 @@ describe('OrderStateWatcher', () => {
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const callback = reportNoErrorCallbackErrors(done)((orderState: OrderState) => {
expect(orderState.isValid).to.be.true();
const validOrderState = orderState as OrderStateValid;
expect(validOrderState.orderHash).to.be.equal(orderHash);
const orderRelevantState = validOrderState.orderRelevantState;
expect(orderRelevantState.cancelledTakerTokenAmount).to.be.bignumber.equal(cancelAmountInBaseUnits);
- done();
});
zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmountInBaseUnits);
diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts
index d6269f15f..f4c6f748f 100644
--- a/packages/0x.js/test/subscription_test.ts
+++ b/packages/0x.js/test/subscription_test.ts
@@ -1,6 +1,5 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
-import * as chai from 'chai';
import * as _ from 'lodash';
import 'mocha';
import * as Sinon from 'sinon';
@@ -11,11 +10,10 @@ import { DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
-import { reportCallbackErrors } from './utils/report_callback_errors';
+import { assertNodeCallbackError } from './utils/report_callback_errors';
import { web3Factory } from './utils/web3_factory';
chaiSetup.configure();
-const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL);
describe('SubscriptionTest', () => {
@@ -59,13 +57,7 @@ describe('SubscriptionTest', () => {
it('Should receive the Error when an error occurs while fetching the block', (done: DoneCallback) => {
(async () => {
const errMsg = 'Error fetching block';
- const callback = reportCallbackErrors(done)(
- (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- expect(err.message).to.be.equal(errMsg);
- expect(logEvent).to.be.undefined();
- done();
- },
- );
+ const callback = assertNodeCallbackError(done, errMsg);
stubs = [Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync').throws(new Error(errMsg))];
zeroEx.token.subscribe(tokenAddress, TokenEvents.Approval, indexFilterValues, callback);
await zeroEx.token.setAllowanceAsync(tokenAddress, coinbase, addressWithoutFunds, allowanceAmount);
@@ -74,13 +66,7 @@ describe('SubscriptionTest', () => {
it('Should receive the Error when an error occurs while reconciling the new block', (done: DoneCallback) => {
(async () => {
const errMsg = 'Error fetching logs';
- const callback = reportCallbackErrors(done)(
- (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- expect(err.message).to.be.equal(errMsg);
- expect(logEvent).to.be.undefined();
- done();
- },
- );
+ const callback = assertNodeCallbackError(done, errMsg);
stubs = [Sinon.stub((zeroEx as any)._web3Wrapper, 'getLogsAsync').throws(new Error(errMsg))];
zeroEx.token.subscribe(tokenAddress, TokenEvents.Approval, indexFilterValues, callback);
await zeroEx.token.setAllowanceAsync(tokenAddress, coinbase, addressWithoutFunds, allowanceAmount);
@@ -88,7 +74,7 @@ describe('SubscriptionTest', () => {
});
it('Should allow unsubscribeAll to be called successfully after an error', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => _.noop;
+ const callback = (err: Error | null, logEvent?: DecodedLogEvent<ApprovalContractEventArgs>) => _.noop;
zeroEx.token.subscribe(tokenAddress, TokenEvents.Approval, indexFilterValues, callback);
stubs = [Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync').throws(new Error('JSON RPC error'))];
zeroEx.token.unsubscribeAll();
diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts
index 296a704dd..4ba1f07c5 100644
--- a/packages/0x.js/test/token_wrapper_test.ts
+++ b/packages/0x.js/test/token_wrapper_test.ts
@@ -20,6 +20,7 @@ import { DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
+import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
import { web3Factory } from './utils/web3_factory';
@@ -386,46 +387,47 @@ describe('TokenWrapper', () => {
// Source: https://github.com/mochajs/mocha/issues/2407
it('Should receive the Transfer event when tokens are transfered', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<TransferContractEventArgs>) => {
- expect(logEvent).to.not.be.undefined();
- expect(logEvent.isRemoved).to.be.false();
- expect(logEvent.log.logIndex).to.be.equal(0);
- expect(logEvent.log.transactionIndex).to.be.equal(0);
- expect(logEvent.log.blockNumber).to.be.a('number');
- const args = logEvent.log.args;
- expect(args._from).to.be.equal(coinbase);
- expect(args._to).to.be.equal(addressWithoutFunds);
- expect(args._value).to.be.bignumber.equal(transferAmount);
- done();
- };
+ const callback = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<TransferContractEventArgs>) => {
+ expect(logEvent.isRemoved).to.be.false();
+ expect(logEvent.log.logIndex).to.be.equal(0);
+ expect(logEvent.log.transactionIndex).to.be.equal(0);
+ expect(logEvent.log.blockNumber).to.be.a('number');
+ const args = logEvent.log.args;
+ expect(args._from).to.be.equal(coinbase);
+ expect(args._to).to.be.equal(addressWithoutFunds);
+ expect(args._value).to.be.bignumber.equal(transferAmount);
+ },
+ );
zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callback);
await zeroEx.token.transferAsync(tokenAddress, coinbase, addressWithoutFunds, transferAmount);
})().catch(done);
});
it('Should receive the Approval event when allowance is being set', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- expect(logEvent).to.not.be.undefined();
- expect(logEvent.isRemoved).to.be.false();
- const args = logEvent.log.args;
- expect(args._owner).to.be.equal(coinbase);
- expect(args._spender).to.be.equal(addressWithoutFunds);
- expect(args._value).to.be.bignumber.equal(allowanceAmount);
- done();
- };
+ const callback = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ expect(logEvent).to.not.be.undefined();
+ expect(logEvent.isRemoved).to.be.false();
+ const args = logEvent.log.args;
+ expect(args._owner).to.be.equal(coinbase);
+ expect(args._spender).to.be.equal(addressWithoutFunds);
+ expect(args._value).to.be.bignumber.equal(allowanceAmount);
+ },
+ );
zeroEx.token.subscribe(tokenAddress, TokenEvents.Approval, indexFilterValues, callback);
await zeroEx.token.setAllowanceAsync(tokenAddress, coinbase, addressWithoutFunds, allowanceAmount);
})().catch(done);
});
it('Outstanding subscriptions are cancelled when zeroEx.setProvider called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- done(new Error('Expected this subscription to have been cancelled'));
- };
+ const callbackNeverToBeCalled = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ done(new Error('Expected this subscription to have been cancelled'));
+ },
+ );
zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled);
- const callbackToBeCalled = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- done();
- };
+ const callbackToBeCalled = reportNodeCallbackErrors(done)();
const newProvider = web3Factory.getRpcProvider();
zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled);
@@ -434,9 +436,11 @@ describe('TokenWrapper', () => {
});
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
- done(new Error('Expected this subscription to have been cancelled'));
- };
+ const callbackNeverToBeCalled = reportNodeCallbackErrors(done)(
+ (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ done(new Error('Expected this subscription to have been cancelled'));
+ },
+ );
const subscriptionToken = zeroEx.token.subscribe(
tokenAddress,
TokenEvents.Transfer,
diff --git a/packages/0x.js/test/utils/report_callback_errors.ts b/packages/0x.js/test/utils/report_callback_errors.ts
index 8a8f4d966..a7d9e61be 100644
--- a/packages/0x.js/test/utils/report_callback_errors.ts
+++ b/packages/0x.js/test/utils/report_callback_errors.ts
@@ -1,10 +1,22 @@
+import * as chai from 'chai';
+import * as _ from 'lodash';
+
import { DoneCallback } from '../../src/types';
-export const reportCallbackErrors = (done: DoneCallback) => {
- return (f: (...args: any[]) => void) => {
- const wrapped = async (...args: any[]) => {
+const expect = chai.expect;
+
+export const reportNoErrorCallbackErrors = (done: DoneCallback, expectToBeCalledOnce = true) => {
+ return <T>(f?: (value: T) => void) => {
+ const wrapped = (value: T) => {
+ if (_.isUndefined(f)) {
+ done();
+ return;
+ }
try {
- f(...args);
+ f(value);
+ if (expectToBeCalledOnce) {
+ done();
+ }
} catch (err) {
done(err);
}
@@ -12,3 +24,41 @@ export const reportCallbackErrors = (done: DoneCallback) => {
return wrapped;
};
};
+
+export const reportNodeCallbackErrors = (done: DoneCallback) => {
+ return <T>(f?: (value: T) => void) => {
+ const wrapped = (error: Error | null, value: T | undefined) => {
+ if (!_.isNull(error)) {
+ done(error);
+ } else {
+ if (_.isUndefined(f)) {
+ done();
+ return;
+ }
+ try {
+ f(value as T);
+ done();
+ } catch (err) {
+ done(err);
+ }
+ }
+ };
+ return wrapped;
+ };
+};
+
+export const assertNodeCallbackError = (done: DoneCallback, errMsg: string) => {
+ const wrapped = <T>(error: Error | null, value: T | undefined) => {
+ if (_.isNull(error)) {
+ done(new Error('Expected callback to receive an error'));
+ } else {
+ try {
+ expect(error.message).to.be.equal(errMsg);
+ done();
+ } catch (err) {
+ done(err);
+ }
+ }
+ };
+ return wrapped;
+};
diff --git a/packages/0x.js/tsconfig.json b/packages/0x.js/tsconfig.json
index d872fcf54..117f51e83 100644
--- a/packages/0x.js/tsconfig.json
+++ b/packages/0x.js/tsconfig.json
@@ -1,14 +1,8 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2015", "dom"],
"outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "experimentalDecorators": true,
- "strictNullChecks": true
+ "noImplicitThis": false
},
"include": [
"./src/**/*",
diff --git a/packages/abi-gen/src/types.ts b/packages/abi-gen/src/types.ts
index 8b158d77a..e82ab824b 100644
--- a/packages/abi-gen/src/types.ts
+++ b/packages/abi-gen/src/types.ts
@@ -5,6 +5,13 @@ export enum ParamKind {
Output = 'output',
}
+export enum AbiType {
+ Function = 'function',
+ Constructor = 'constructor',
+ Event = 'event',
+ Fallback = 'fallback',
+}
+
export interface Method extends Web3.MethodAbi {
singleReturnValue: boolean;
}
diff --git a/packages/abi-gen/src/utils.ts b/packages/abi-gen/src/utils.ts
index f6291d98d..14255643a 100644
--- a/packages/abi-gen/src/utils.ts
+++ b/packages/abi-gen/src/utils.ts
@@ -3,7 +3,7 @@ import * as _ from 'lodash';
import * as path from 'path';
import * as Web3 from 'web3';
-import { ParamKind } from './types';
+import { AbiType, ParamKind } from './types';
export const utils = {
solTypeToTsType(paramKind: ParamKind, solType: string): string {
@@ -64,7 +64,7 @@ export const utils = {
},
getEmptyConstructor(): Web3.ConstructorAbi {
return {
- type: 'constructor',
+ type: AbiType.Constructor,
stateMutability: 'nonpayable',
payable: false,
inputs: [],
diff --git a/packages/abi-gen/tsconfig.json b/packages/abi-gen/tsconfig.json
index c9a7e9189..5e0c7c6d3 100644
--- a/packages/abi-gen/tsconfig.json
+++ b/packages/abi-gen/tsconfig.json
@@ -1,13 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2015", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
"include": ["./src/**/*", "./test/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"]
}
diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts
index 051a741c5..56f663780 100644
--- a/packages/assert/src/index.ts
+++ b/packages/assert/src/index.ts
@@ -18,9 +18,6 @@ export const assert = {
`${variableName} should be in baseUnits (no decimals), found value: ${value.toNumber()}`,
);
},
- isUndefined(value: any, variableName?: string): void {
- this.assert(_.isUndefined(value), this.typeAssertionMessage(variableName, 'undefined', value));
- },
isString(variableName: string, value: string): void {
this.assert(_.isString(value), this.typeAssertionMessage(variableName, 'string', value));
},
@@ -77,11 +74,11 @@ Validation errors: ${validationResult.errors.join(', ')}`;
this.assert(!hasValidationErrors, msg);
},
isHttpUrl(variableName: string, value: any): void {
- const isValidUrl = validUrl.isWebUri(value);
+ const isValidUrl = !_.isUndefined(validUrl.isWebUri(value));
this.assert(isValidUrl, this.typeAssertionMessage(variableName, 'http url', value));
},
isUri(variableName: string, value: any): void {
- const isValidUri = validUrl.isUri(value);
+ const isValidUri = !_.isUndefined(validUrl.isUri(value));
this.assert(isValidUri, this.typeAssertionMessage(variableName, 'uri', value));
},
assert(condition: boolean, message: string): void {
diff --git a/packages/assert/test/assert_test.ts b/packages/assert/test/assert_test.ts
index 29344584a..ff337196d 100644
--- a/packages/assert/test/assert_test.ts
+++ b/packages/assert/test/assert_test.ts
@@ -22,16 +22,6 @@ describe('Assertions', () => {
invalidInputs.forEach(input => expect(assert.isBigNumber.bind(assert, variableName, input)).to.throw());
});
});
- describe('#isUndefined', () => {
- it('should not throw for valid input', () => {
- const validInputs = [undefined];
- validInputs.forEach(input => expect(assert.isUndefined.bind(assert, input, variableName)).to.not.throw());
- });
- it('should throw for invalid input', () => {
- const invalidInputs = ['test', 42, false, { random: 'test' }];
- invalidInputs.forEach(input => expect(assert.isUndefined.bind(assert, input, variableName)).to.throw());
- });
- });
describe('#isString', () => {
it('should not throw for valid input', () => {
const validInputs = ['hello', 'goodbye'];
@@ -44,7 +34,7 @@ describe('Assertions', () => {
});
describe('#isFunction', () => {
it('should not throw for valid input', () => {
- const validInputs = [BigNumber, assert.isString.bind(this)];
+ const validInputs = [BigNumber, assert.isString];
validInputs.forEach(input => expect(assert.isFunction.bind(assert, variableName, input)).to.not.throw());
});
it('should throw for invalid input', () => {
diff --git a/packages/assert/tsconfig.json b/packages/assert/tsconfig.json
index 31bedfeb7..88a467ccb 100644
--- a/packages/assert/tsconfig.json
+++ b/packages/assert/tsconfig.json
@@ -1,18 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2017", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
- "include": [
- "./src/**/*",
- "./test/**/*",
- "../../node_modules/chai-typescript-typings/index.d.ts",
- "../../node_modules/web3-typescript-typings/index.d.ts"
- ]
+ "include": ["./src/**/*", "./test/**/*", "../../node_modules/chai-typescript-typings/index.d.ts"]
}
diff --git a/packages/connect/package.json b/packages/connect/package.json
index bd200db8d..2eb0cc0b0 100644
--- a/packages/connect/package.json
+++ b/packages/connect/package.json
@@ -59,6 +59,6 @@
"tslint": "5.8.0",
"typedoc": "~0.8.0",
"typescript": "~2.6.1",
- "web3-typescript-typings": "^0.7.2"
+ "web3-typescript-typings": "^0.9.0"
}
}
diff --git a/packages/connect/tsconfig.json b/packages/connect/tsconfig.json
index 90400975b..3c150236e 100644
--- a/packages/connect/tsconfig.json
+++ b/packages/connect/tsconfig.json
@@ -1,19 +1,12 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2015", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
"include": [
"./src/**/*",
"./test/**/*",
"../../node_modules/chai-as-promised-typescript-typings/index.d.ts",
- "../../node_modules/chai-typescript-typings/index.d.ts",
- "../../node_modules/web3-typescript-typings/index.d.ts"
+ "../../node_modules/chai-typescript-typings/index.d.ts"
]
}
diff --git a/packages/contracts/deploy/solc/bin_paths.ts b/packages/contracts/deploy/solc/bin_paths.ts
index a2d345bd7..e5b107101 100644
--- a/packages/contracts/deploy/solc/bin_paths.ts
+++ b/packages/contracts/deploy/solc/bin_paths.ts
@@ -1,4 +1,4 @@
-interface BinaryPaths {
+export interface BinaryPaths {
[key: string]: string;
}
diff --git a/packages/contracts/deploy/src/utils/contract.ts b/packages/contracts/deploy/src/utils/contract.ts
index 2c8bbb79e..546e82dfb 100644
--- a/packages/contracts/deploy/src/utils/contract.ts
+++ b/packages/contracts/deploy/src/utils/contract.ts
@@ -24,7 +24,7 @@ export class Contract implements Web3.ContractInstance {
this._validator = new SchemaValidator();
}
private _populateFunctions(): void {
- const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Function);
+ const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Function) as Web3.FunctionAbi[];
_.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => {
if (functionAbi.constant) {
const cbStyleCallFunction = this._contract[functionAbi.name].call;
@@ -42,7 +42,7 @@ export class Contract implements Web3.ContractInstance {
});
}
private _populateEvents(): void {
- const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Event);
+ const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Event) as Web3.EventAbi[];
_.forEach(eventsAbi, (eventAbi: Web3.EventAbi) => {
this[eventAbi.name] = this._contract[eventAbi.name];
});
diff --git a/packages/contracts/package.json b/packages/contracts/package.json
index d5bd78fc2..41a7756da 100644
--- a/packages/contracts/package.json
+++ b/packages/contracts/package.json
@@ -52,7 +52,7 @@
"types-bn": "^0.0.1",
"types-ethereumjs-util": "0xProject/types-ethereumjs-util",
"typescript": "~2.6.1",
- "web3-typescript-typings": "^0.7.2",
+ "web3-typescript-typings": "^0.9.0",
"yargs": "^10.0.3"
},
"dependencies": {
diff --git a/packages/contracts/tsconfig.json b/packages/contracts/tsconfig.json
index cbcd8ad6d..38008a542 100644
--- a/packages/contracts/tsconfig.json
+++ b/packages/contracts/tsconfig.json
@@ -1,17 +1,17 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "outDir": "./lib/",
- "sourceMap": true,
- "noImplicitAny": true,
- "module": "commonjs",
- "target": "es6",
+ "outDir": "lib",
"baseUrl": ".",
+ "declaration": false,
+ "strictNullChecks": false,
+ "strictFunctionTypes": false,
"allowJs": true
},
"include": [
"../../node_modules/types-ethereumjs-util/index.d.ts",
- "../../node_modules/web3-typescript-typings/index.d.ts",
"../../node_modules/chai-typescript-typings/index.d.ts",
+ "../../node_modules/web3-typescript-typings/index.d.ts",
"../../node_modules/chai-as-promised-typescript-typings/index.d.ts",
"../../node_modules/types-ethereumjs-util/index.d.ts",
"../../node_modules/types-bn/index.d.ts",
diff --git a/packages/dev-utils/tsconfig.json b/packages/dev-utils/tsconfig.json
index 51e3d5ef0..b28e45170 100644
--- a/packages/dev-utils/tsconfig.json
+++ b/packages/dev-utils/tsconfig.json
@@ -1,13 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2017", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
"include": [
"./src/**/*",
diff --git a/packages/json-schemas/tsconfig.json b/packages/json-schemas/tsconfig.json
index 27d415a13..88a467ccb 100644
--- a/packages/json-schemas/tsconfig.json
+++ b/packages/json-schemas/tsconfig.json
@@ -1,13 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2017", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
"include": ["./src/**/*", "./test/**/*", "../../node_modules/chai-typescript-typings/index.d.ts"]
}
diff --git a/packages/kovan-faucets/package.json b/packages/kovan-faucets/package.json
index fe7cef5f2..797368064 100644
--- a/packages/kovan-faucets/package.json
+++ b/packages/kovan-faucets/package.json
@@ -36,7 +36,7 @@
"source-map-loader": "^0.1.6",
"tslint": "5.8.0",
"typescript": "~2.6.1",
- "web3-typescript-typings": "^0.7.2",
+ "web3-typescript-typings": "^0.9.0",
"webpack": "^3.1.0",
"webpack-node-externals": "^1.6.0"
}
diff --git a/packages/kovan-faucets/src/ts/configs.ts b/packages/kovan-faucets/src/ts/configs.ts
index 697e7522b..2e5a7f64d 100644
--- a/packages/kovan-faucets/src/ts/configs.ts
+++ b/packages/kovan-faucets/src/ts/configs.ts
@@ -1,5 +1,5 @@
export const configs = {
- DISPENSER_ADDRESS: process.env.DISPENSER_ADDRESS.toLowerCase(),
+ DISPENSER_ADDRESS: (process.env.DISPENSER_ADDRESS as string).toLowerCase(),
DISPENSER_PRIVATE_KEY: process.env.DISPENSER_PRIVATE_KEY,
ENVIRONMENT: process.env.FAUCET_ENVIRONMENT,
ROLLBAR_ACCESS_KEY: process.env.FAUCET_ROLLBAR_ACCESS_KEY,
diff --git a/packages/kovan-faucets/src/ts/id_management.ts b/packages/kovan-faucets/src/ts/id_management.ts
index 74865afb8..930821172 100644
--- a/packages/kovan-faucets/src/ts/id_management.ts
+++ b/packages/kovan-faucets/src/ts/id_management.ts
@@ -3,7 +3,7 @@ import EthereumTx = require('ethereumjs-tx');
import { configs } from './configs';
import { utils } from './utils';
-type Callback = (err: Error, accounts: any) => void;
+type Callback = (err: Error | null, accounts: any) => void;
export const idManagement = {
getAccounts(callback: Callback) {
@@ -15,7 +15,7 @@ export const idManagement = {
},
signTransaction(txData: object, callback: Callback) {
const tx = new EthereumTx(txData);
- const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY, 'hex');
+ const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY as string, 'hex');
tx.sign(privateKeyBuffer);
const rawTx = `0x${tx.serialize().toString('hex')}`;
callback(null, rawTx);
diff --git a/packages/kovan-faucets/src/ts/request_queue.ts b/packages/kovan-faucets/src/ts/request_queue.ts
index ea3eee18e..2b42ca4bf 100644
--- a/packages/kovan-faucets/src/ts/request_queue.ts
+++ b/packages/kovan-faucets/src/ts/request_queue.ts
@@ -38,10 +38,10 @@ export class RequestQueue {
}
protected start() {
this.queueIntervalId = timers.setInterval(() => {
- if (this.queue.length === 0) {
+ const recipientAddress = this.queue.shift();
+ if (_.isUndefined(recipientAddress)) {
return;
}
- const recipientAddress = this.queue.shift();
// tslint:disable-next-line:no-floating-promises
this.processNextRequestFireAndForgetAsync(recipientAddress);
}, this.queueIntervalMs);
diff --git a/packages/kovan-faucets/tsconfig.json b/packages/kovan-faucets/tsconfig.json
index 7f0031ec6..7f0c084ff 100644
--- a/packages/kovan-faucets/tsconfig.json
+++ b/packages/kovan-faucets/tsconfig.json
@@ -1,13 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2015", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "experimentalDecorators": true
+ "outDir": "lib"
},
- "include": ["../../node_modules/web3-typescript-typings/index.d.ts", "./src/ts/**/*"]
+ "include": ["./src/ts/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"]
}
diff --git a/packages/monorepo-scripts/tsconfig.json b/packages/monorepo-scripts/tsconfig.json
index b915df2a8..c56d255d5 100644
--- a/packages/monorepo-scripts/tsconfig.json
+++ b/packages/monorepo-scripts/tsconfig.json
@@ -1,11 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2015", "dom"],
- "outDir": "lib",
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
"include": ["./src/**/*"]
}
diff --git a/packages/subproviders/tsconfig.json b/packages/subproviders/tsconfig.json
index 63fb7d7d1..9a65a0a97 100644
--- a/packages/subproviders/tsconfig.json
+++ b/packages/subproviders/tsconfig.json
@@ -1,20 +1,13 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2015", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "experimentalDecorators": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
"include": [
"./src/**/*",
"./test/**/*",
- "../../node_modules/web3-typescript-typings/index.d.ts",
"../../node_modules/chai-typescript-typings/index.d.ts",
+ "../../node_modules/web3-typescript-typings/index.d.ts",
"../../node_modules/types-bn/index.d.ts",
"../../node_modules/types-ethereumjs-util/index.d.ts",
"../../node_modules/chai-as-promised-typescript-typings/index.d.ts"
diff --git a/packages/tslint-config/tsconfig.json b/packages/tslint-config/tsconfig.json
index 77ddf892f..15da53092 100644
--- a/packages/tslint-config/tsconfig.json
+++ b/packages/tslint-config/tsconfig.json
@@ -1,13 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2017", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
"include": ["./rules/**/*"]
}
diff --git a/packages/types/tsconfig.json b/packages/types/tsconfig.json
index 0aa8c3dde..3d967d05f 100644
--- a/packages/types/tsconfig.json
+++ b/packages/types/tsconfig.json
@@ -1,13 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2017", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
"include": ["./src/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"]
}
diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json
index 10c38a15b..3d967d05f 100644
--- a/packages/utils/tsconfig.json
+++ b/packages/utils/tsconfig.json
@@ -1,13 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2017", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
- "include": ["./src/**/*"]
+ "include": ["./src/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"]
}
diff --git a/packages/web3-typescript-typings/.gitignore b/packages/web3-typescript-typings/.gitignore
new file mode 100644
index 000000000..85dcc16df
--- /dev/null
+++ b/packages/web3-typescript-typings/.gitignore
@@ -0,0 +1,2 @@
+.git
+node_modules
diff --git a/packages/web3-typescript-typings/README.md b/packages/web3-typescript-typings/README.md
new file mode 100644
index 000000000..95c193287
--- /dev/null
+++ b/packages/web3-typescript-typings/README.md
@@ -0,0 +1,49 @@
+## web3-typescript-typings
+
+There currently isn't an official [Web3][web3]
+type definition included in the [DefinitelyTyped][definitelytyped] project.
+Until that happens, we will continue to improve our own type definition.
+If it get's close to comprehensive, we'll add it to [DefinitelyTyped][definitelytyped].
+
+[web3]: https://github.com/ethereum/web3.js/
+[definitelytyped]: https://github.com/DefinitelyTyped/DefinitelyTyped
+
+## Installation
+
+```bash
+yarn add -D web3-typescript-typings
+```
+
+## Usage
+
+Add the following line within an `include` section of your `tsconfig.json`
+
+```json
+"./node_modules/web3-typescript-typings/index.d.ts"
+```
+
+## Contributing
+
+We strongly encourage that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository.
+
+Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
+
+### Install Dependencies
+
+If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
+
+```bash
+yarn config set workspaces-experimental true
+```
+
+Then install dependencies
+
+```bash
+yarn install
+```
+
+### Lint
+
+```bash
+yarn lint
+```
diff --git a/packages/web3-typescript-typings/index.d.ts b/packages/web3-typescript-typings/index.d.ts
new file mode 100644
index 000000000..6fd126d2a
--- /dev/null
+++ b/packages/web3-typescript-typings/index.d.ts
@@ -0,0 +1,421 @@
+declare module 'web3' {
+ import * as BigNumber from 'bignumber.js';
+
+ type MixedData = string | number | object | any[] | BigNumber.BigNumber;
+
+ class Web3 {
+ public static providers: typeof providers;
+ public currentProvider: Web3.Provider;
+
+ public eth: Web3.EthApi;
+ public personal: Web3.PersonalApi | undefined;
+ public version: Web3.VersionApi;
+ public net: Web3.NetApi;
+
+ public constructor(provider?: Web3.Provider);
+
+ public isConnected(): boolean;
+ public setProvider(provider: Web3.Provider): void;
+ public reset(keepIsSyncing: boolean): void;
+ public toHex(data: MixedData): string;
+ public toAscii(hex: string): string;
+ public fromAscii(ascii: string, padding?: number): string;
+ public toDecimal(hex: string): number;
+ public fromDecimal(value: number | string): string;
+ public fromWei(value: number | string, unit: Web3.Unit): string;
+ public fromWei(value: BigNumber.BigNumber, unit: Web3.Unit): BigNumber.BigNumber;
+ public toWei(amount: number | string, unit: Web3.Unit): string;
+ public toWei(amount: BigNumber.BigNumber, unit: Web3.Unit): BigNumber.BigNumber;
+ public toBigNumber(value: number | string): BigNumber.BigNumber;
+ public isAddress(address: string): boolean;
+ public isChecksumAddress(address: string): boolean;
+ public sha3(value: string, options?: Web3.Sha3Options): string;
+ }
+
+ namespace providers {
+ class HttpProvider implements Web3.Provider {
+ constructor(url?: string, timeout?: number, username?: string, password?: string);
+ public sendAsync(
+ payload: Web3.JSONRPCRequestPayload,
+ callback: (err: Error, result: Web3.JSONRPCResponsePayload) => void,
+ ): void;
+ }
+ }
+
+ namespace Web3 {
+ type ContractAbi = AbiDefinition[];
+
+ type AbiDefinition = FunctionAbi | EventAbi;
+
+ type FunctionAbi = MethodAbi | ConstructorAbi | FallbackAbi;
+
+ enum AbiType {
+ Function = 'function',
+ Constructor = 'constructor',
+ Event = 'event',
+ Fallback = 'fallback',
+ }
+
+ type ConstructorStateMutability = 'nonpayable' | 'payable';
+ type StateMutability = 'pure' | 'view' | ConstructorStateMutability;
+
+ interface MethodAbi {
+ type: AbiType.Function;
+ name: string;
+ inputs: FunctionParameter[];
+ outputs: FunctionParameter[];
+ constant: boolean;
+ stateMutability: StateMutability;
+ payable: boolean;
+ }
+
+ interface ConstructorAbi {
+ type: AbiType.Constructor;
+ inputs: FunctionParameter[];
+ payable: boolean;
+ stateMutability: ConstructorStateMutability;
+ }
+
+ interface FallbackAbi {
+ type: AbiType.Fallback;
+ payable: boolean;
+ }
+
+ interface EventParameter {
+ name: string;
+ type: string;
+ indexed: boolean;
+ }
+
+ interface EventAbi {
+ type: AbiType.Event;
+ name: string;
+ inputs: EventParameter[];
+ anonymous: boolean;
+ }
+
+ interface FunctionParameter {
+ name: string;
+ type: string;
+ }
+
+ interface ContractInstance {
+ address: string;
+ abi: Web3.ContractAbi;
+ [name: string]: any;
+ }
+
+ interface Contract<A extends ContractInstance> {
+ at(address: string): A;
+ 'new'(...args: any[]): A;
+ }
+
+ interface FilterObject {
+ fromBlock?: number | string;
+ toBlock?: number | string;
+ address?: string;
+ topics?: LogTopic[];
+ }
+
+ type LogTopic = null | string | string[];
+
+ interface DecodedLogEntry<A> extends LogEntry {
+ event: string;
+ args: A;
+ }
+
+ interface DecodedLogEntryEvent<A> extends DecodedLogEntry<A> {
+ removed: boolean;
+ }
+
+ interface LogEntryEvent extends LogEntry {
+ removed: boolean;
+ }
+
+ interface FilterResult {
+ get(callback: () => void): void;
+ watch(callback: (err: Error, result: LogEntryEvent) => void): void;
+ stopWatching(callback?: () => void): void;
+ }
+
+ export interface JSONRPCRequestPayload {
+ params: any[];
+ method: string;
+ id: number;
+ jsonrpc: string;
+ }
+
+ export interface JSONRPCResponsePayload {
+ result: any;
+ id: number;
+ jsonrpc: string;
+ }
+
+ interface Provider {
+ sendAsync(
+ payload: JSONRPCRequestPayload,
+ callback: (err: Error, result: JSONRPCResponsePayload) => void,
+ ): void;
+ }
+
+ interface Sha3Options {
+ encoding: 'hex';
+ }
+
+ interface EthApi {
+ coinbase: string;
+ mining: boolean;
+ hashrate: number;
+ gasPrice: BigNumber.BigNumber;
+ accounts: string[];
+ blockNumber: number;
+ defaultAccount: string;
+ defaultBlock: Web3.BlockParam;
+ syncing: Web3.SyncingResult;
+ compile: {
+ solidity(sourceString: string, cb?: (err: Error, result: any) => void): object;
+ };
+ getMining(cd: (err: Error, mining: boolean) => void): void;
+ getHashrate(cd: (err: Error, hashrate: number) => void): void;
+ getGasPrice(cd: (err: Error, gasPrice: BigNumber.BigNumber) => void): void;
+ getAccounts(cd: (err: Error, accounts: string[]) => void): void;
+ getBlockNumber(callback: (err: Error, blockNumber: number) => void): void;
+ getSyncing(cd: (err: Error, syncing: Web3.SyncingResult) => void): void;
+ isSyncing(cb: (err: Error, isSyncing: boolean, syncingState: Web3.SyncingState) => void): Web3.IsSyncing;
+
+ getBlock(hashStringOrBlockNumber: string | Web3.BlockParam): Web3.BlockWithoutTransactionData;
+ getBlock(
+ hashStringOrBlockNumber: string | Web3.BlockParam,
+ callback: (err: Error, blockObj: Web3.BlockWithoutTransactionData) => void,
+ ): void;
+ getBlock(
+ hashStringOrBlockNumber: string | Web3.BlockParam,
+ returnTransactionObjects: true,
+ ): Web3.BlockWithTransactionData;
+ getBlock(
+ hashStringOrBlockNumber: string | Web3.BlockParam,
+ returnTransactionObjects: true,
+ callback: (err: Error, blockObj: Web3.BlockWithTransactionData) => void,
+ ): void;
+
+ getBlockTransactionCount(hashStringOrBlockNumber: string | Web3.BlockParam): number;
+ getBlockTransactionCount(
+ hashStringOrBlockNumber: string | Web3.BlockParam,
+ callback: (err: Error, blockTransactionCount: number) => void,
+ ): void;
+
+ // TODO returnTransactionObjects
+ getUncle(
+ hashStringOrBlockNumber: string | Web3.BlockParam,
+ uncleNumber: number,
+ ): Web3.BlockWithoutTransactionData;
+ getUncle(
+ hashStringOrBlockNumber: string | Web3.BlockParam,
+ uncleNumber: number,
+ callback: (err: Error, uncle: Web3.BlockWithoutTransactionData) => void,
+ ): void;
+
+ getTransaction(transactionHash: string): Web3.Transaction;
+ getTransaction(
+ transactionHash: string,
+ callback: (err: Error, transaction: Web3.Transaction) => void,
+ ): void;
+
+ getTransactionFromBlock(
+ hashStringOrBlockNumber: string | Web3.BlockParam,
+ indexNumber: number,
+ ): Web3.Transaction;
+ getTransactionFromBlock(
+ hashStringOrBlockNumber: string | Web3.BlockParam,
+ indexNumber: number,
+ callback: (err: Error, transaction: Web3.Transaction) => void,
+ ): void;
+
+ contract(abi: Web3.AbiDefinition[]): Web3.Contract<any>;
+
+ // TODO block param
+ getBalance(addressHexString: string): BigNumber.BigNumber;
+ getBalance(addressHexString: string, callback: (err: Error, result: BigNumber.BigNumber) => void): void;
+
+ // TODO block param
+ getStorageAt(address: string, position: number): string;
+ getStorageAt(address: string, position: number, callback: (err: Error, storage: string) => void): void;
+
+ // TODO block param
+ getCode(addressHexString: string): string;
+ getCode(addressHexString: string, callback: (err: Error, code: string) => void): void;
+
+ filter(value: string | Web3.FilterObject): Web3.FilterResult;
+
+ sendTransaction(txData: Web3.TxData): string;
+ sendTransaction(txData: Web3.TxData, callback: (err: Error, value: string) => void): void;
+
+ sendRawTransaction(rawTxData: string): string;
+ sendRawTransaction(rawTxData: string, callback: (err: Error, value: string) => void): void;
+
+ sign(address: string, data: string): string;
+ sign(address: string, data: string, callback: (err: Error, signature: string) => void): void;
+
+ getTransactionReceipt(txHash: string): Web3.TransactionReceipt;
+ getTransactionReceipt(
+ txHash: string,
+ callback: (err: Error, receipt: Web3.TransactionReceipt) => void,
+ ): void;
+
+ // TODO block param
+ call(callData: Web3.CallData): string;
+ call(callData: Web3.CallData, callback: (err: Error, result: string) => void): void;
+
+ estimateGas(callData: Web3.CallData): number;
+ estimateGas(callData: Web3.CallData, callback: (err: Error, gas: number) => void): void;
+
+ // TODO defaultBlock
+ getTransactionCount(address: string): number;
+ getTransactionCount(address: string, callback: (err: Error, count: number) => void): void;
+ }
+
+ interface VersionApi {
+ api: string;
+ network: string;
+ node: string;
+ ethereum: string;
+ whisper: string;
+ getNetwork(cd: (err: Error, networkId: string) => void): void;
+ getNode(cd: (err: Error, nodeVersion: string) => void): void;
+ getEthereum(cd: (err: Error, ethereum: string) => void): void;
+ getWhisper(cd: (err: Error, whisper: string) => void): void;
+ }
+
+ interface PersonalApi {
+ listAccounts: string[] | undefined;
+ newAccount(password?: string): string;
+ unlockAccount(address: string, password?: string, duration?: number): boolean;
+ lockAccount(address: string): boolean;
+ sign(message: string, account: string, password: string): string;
+ sign(hexMessage: string, account: string, callback: (error: Error, signature: string) => void): void;
+ }
+
+ interface NetApi {
+ listening: boolean;
+ peerCount: boolean;
+ getListening(cd: (err: Error, listening: boolean) => void): void;
+ getPeerCount(cd: (err: Error, peerCount: number) => void): void;
+ }
+
+ type BlockParam = number | 'earliest' | 'latest' | 'pending';
+
+ type Unit =
+ | 'kwei'
+ | 'ada'
+ | 'mwei'
+ | 'babbage'
+ | 'gwei'
+ | 'shannon'
+ | 'szabo'
+ | 'finney'
+ | 'ether'
+ | 'kether'
+ | 'grand'
+ | 'einstein'
+ | 'mether'
+ | 'gether'
+ | 'tether';
+
+ interface SyncingState {
+ startingBlock: number;
+ currentBlock: number;
+ highestBlock: number;
+ }
+ type SyncingResult = false | SyncingState;
+
+ interface IsSyncing {
+ addCallback(cb: (err: Error, isSyncing: boolean, syncingState: SyncingState) => void): void;
+ stopWatching(): void;
+ }
+
+ interface AbstractBlock {
+ number: number | null;
+ hash: string | null;
+ parentHash: string;
+ nonce: string | null;
+ sha3Uncles: string;
+ logsBloom: string | null;
+ transactionsRoot: string;
+ stateRoot: string;
+ miner: string;
+ difficulty: BigNumber.BigNumber;
+ totalDifficulty: BigNumber.BigNumber;
+ extraData: string;
+ size: number;
+ gasLimit: number;
+ gasUsed: number;
+ timestamp: number;
+ uncles: string[];
+ }
+ interface BlockWithoutTransactionData extends AbstractBlock {
+ transactions: string[];
+ }
+ interface BlockWithTransactionData extends AbstractBlock {
+ transactions: Transaction[];
+ }
+
+ interface Transaction {
+ hash: string;
+ nonce: number;
+ blockHash: string | null;
+ blockNumber: number | null;
+ transactionIndex: number | null;
+ from: string;
+ to: string | null;
+ value: BigNumber.BigNumber;
+ gasPrice: BigNumber.BigNumber;
+ gas: number;
+ input: string;
+ }
+
+ interface CallTxDataBase {
+ to?: string;
+ value?: number | string | BigNumber.BigNumber;
+ gas?: number | string | BigNumber.BigNumber;
+ gasPrice?: number | string | BigNumber.BigNumber;
+ data?: string;
+ nonce?: number;
+ }
+
+ interface TxData extends CallTxDataBase {
+ from: string;
+ }
+
+ interface CallData extends CallTxDataBase {
+ from?: string;
+ }
+
+ interface TransactionReceipt {
+ blockHash: string;
+ blockNumber: number;
+ transactionHash: string;
+ transactionIndex: number;
+ from: string;
+ to: string;
+ status: null | string | 0 | 1;
+ cumulativeGasUsed: number;
+ gasUsed: number;
+ contractAddress: string | null;
+ logs: LogEntry[];
+ }
+
+ interface LogEntry {
+ logIndex: number | null;
+ transactionIndex: number | null;
+ transactionHash: string;
+ blockHash: string | null;
+ blockNumber: number | null;
+ address: string;
+ data: string;
+ topics: string[];
+ }
+ }
+ /* tslint:disable */
+ export = Web3;
+ /* tslint:enable */
+}
diff --git a/packages/web3-typescript-typings/package.json b/packages/web3-typescript-typings/package.json
new file mode 100644
index 000000000..c69cd40fb
--- /dev/null
+++ b/packages/web3-typescript-typings/package.json
@@ -0,0 +1,30 @@
+{
+ "name": "web3-typescript-typings",
+ "version": "0.9.0",
+ "description": "Typescript type definitions for web3",
+ "main": "index.d.ts",
+ "types": "index.d.ts",
+ "scripts": {
+ "lint": "tslint index.d.ts"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/0xProject/web3-typescript-typings.git"
+ },
+ "author": "Fabio Berger",
+ "contributors": ["Leonid Logvinov <logvinov.leon@gmail.com>"],
+ "license": "Apache-2.0",
+ "bugs": {
+ "url": "https://github.com/0xProject/web3-typescript-typings/issues"
+ },
+ "homepage": "https://github.com/0xProject/web3-typescript-typings#readme",
+ "devDependencies": {
+ "@types/bignumber.js": "^4.0.2",
+ "tslint": "^5.5.0",
+ "tslint-config-0xproject": "^0.0.2",
+ "typescript": "~2.6.1"
+ },
+ "dependencies": {
+ "bignumber.js": "~4.1.0"
+ }
+}
diff --git a/packages/web3-typescript-typings/tslint.json b/packages/web3-typescript-typings/tslint.json
new file mode 100644
index 000000000..9a93a1f74
--- /dev/null
+++ b/packages/web3-typescript-typings/tslint.json
@@ -0,0 +1,3 @@
+{
+ "extends": ["tslint-config-0xproject"]
+}
diff --git a/packages/web3-typescript-typings/yarn.lock b/packages/web3-typescript-typings/yarn.lock
new file mode 100644
index 000000000..f1d0f843a
--- /dev/null
+++ b/packages/web3-typescript-typings/yarn.lock
@@ -0,0 +1,197 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+
+"@types/bignumber.js@^4.0.2":
+ version "4.0.2"
+ resolved "https://registry.yarnpkg.com/@types/bignumber.js/-/bignumber.js-4.0.2.tgz#22a16946c9faa9f2c9c0ad4c7c3734a3033320ae"
+
+ansi-regex@^2.0.0:
+ version "2.1.1"
+ resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
+
+ansi-styles@^2.2.1:
+ version "2.2.1"
+ resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
+
+babel-code-frame@^6.22.0:
+ version "6.22.0"
+ resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4"
+ dependencies:
+ chalk "^1.1.0"
+ esutils "^2.0.2"
+ js-tokens "^3.0.0"
+
+balanced-match@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
+
+bignumber.js@^4.0.2:
+ version "4.0.2"
+ resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-4.0.2.tgz#2d1dc37ee5968867ecea90b6da4d16e68608d21d"
+
+brace-expansion@^1.1.7:
+ version "1.1.8"
+ resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292"
+ dependencies:
+ balanced-match "^1.0.0"
+ concat-map "0.0.1"
+
+chalk@^1.1.0:
+ version "1.1.3"
+ resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
+ dependencies:
+ ansi-styles "^2.2.1"
+ escape-string-regexp "^1.0.2"
+ has-ansi "^2.0.0"
+ strip-ansi "^3.0.0"
+ supports-color "^2.0.0"
+
+colors@^1.1.2:
+ version "1.1.2"
+ resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"
+
+commander@^2.9.0:
+ version "2.11.0"
+ resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
+
+concat-map@0.0.1:
+ version "0.0.1"
+ resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
+
+diff@^3.2.0:
+ version "3.3.0"
+ resolved "https://registry.yarnpkg.com/diff/-/diff-3.3.0.tgz#056695150d7aa93237ca7e378ac3b1682b7963b9"
+
+escape-string-regexp@^1.0.2:
+ version "1.0.5"
+ resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
+
+esutils@^2.0.2:
+ version "2.0.2"
+ resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
+
+fs.realpath@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
+
+glob@^7.1.1:
+ version "7.1.2"
+ resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
+ dependencies:
+ fs.realpath "^1.0.0"
+ inflight "^1.0.4"
+ inherits "2"
+ minimatch "^3.0.4"
+ once "^1.3.0"
+ path-is-absolute "^1.0.0"
+
+has-ansi@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
+ dependencies:
+ ansi-regex "^2.0.0"
+
+inflight@^1.0.4:
+ version "1.0.6"
+ resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
+ dependencies:
+ once "^1.3.0"
+ wrappy "1"
+
+inherits@2:
+ version "2.0.3"
+ resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
+
+js-tokens@^3.0.0:
+ version "3.0.2"
+ resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
+
+minimatch@^3.0.4:
+ version "3.0.4"
+ resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
+ dependencies:
+ brace-expansion "^1.1.7"
+
+once@^1.3.0:
+ version "1.4.0"
+ resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
+ dependencies:
+ wrappy "1"
+
+path-is-absolute@^1.0.0:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
+
+path-parse@^1.0.5:
+ version "1.0.5"
+ resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1"
+
+resolve@^1.3.2:
+ version "1.3.3"
+ resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.3.tgz#655907c3469a8680dc2de3a275a8fdd69691f0e5"
+ dependencies:
+ path-parse "^1.0.5"
+
+semver@^5.3.0:
+ version "5.4.1"
+ resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
+
+strip-ansi@^3.0.0:
+ version "3.0.1"
+ resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
+ dependencies:
+ ansi-regex "^2.0.0"
+
+supports-color@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
+
+tslib@^1.7.1:
+ version "1.7.1"
+ resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec"
+
+tslint-config-0xproject@^0.0.2:
+ version "0.0.2"
+ resolved "https://registry.yarnpkg.com/tslint-config-0xproject/-/tslint-config-0xproject-0.0.2.tgz#39901e0c0b3e9388f00092a28b90c015395d5bba"
+ dependencies:
+ tslint-react "^3.0.0"
+
+tslint-react@^3.0.0:
+ version "3.1.0"
+ resolved "https://registry.yarnpkg.com/tslint-react/-/tslint-react-3.1.0.tgz#a4de1a22fef41b663fa44daae27cbf04dc8a59d6"
+ dependencies:
+ tsutils "^1.7.0"
+
+tslint@^5.5.0:
+ version "5.5.0"
+ resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.5.0.tgz#10e8dab3e3061fa61e9442e8cee3982acf20a6aa"
+ dependencies:
+ babel-code-frame "^6.22.0"
+ colors "^1.1.2"
+ commander "^2.9.0"
+ diff "^3.2.0"
+ glob "^7.1.1"
+ minimatch "^3.0.4"
+ resolve "^1.3.2"
+ semver "^5.3.0"
+ tslib "^1.7.1"
+ tsutils "^2.5.1"
+
+tsutils@^1.7.0:
+ version "1.9.1"
+ resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.9.1.tgz#b9f9ab44e55af9681831d5f28d0aeeaf5c750cb0"
+
+tsutils@^2.5.1:
+ version "2.8.0"
+ resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.8.0.tgz#0160173729b3bf138628dd14a1537e00851d814a"
+ dependencies:
+ tslib "^1.7.1"
+
+typescript@^2.4.2:
+ version "2.4.2"
+ resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844"
+
+wrappy@1:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json
index e7269d277..13e32e991 100644
--- a/packages/web3-wrapper/package.json
+++ b/packages/web3-wrapper/package.json
@@ -26,7 +26,7 @@
"shx": "^0.2.2",
"tslint": "5.8.0",
"typescript": "~2.6.1",
- "web3-typescript-typings": "^0.7.2"
+ "web3-typescript-typings": "^0.9.0"
},
"dependencies": {
"@0xproject/utils": "^0.1.2",
diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts
index 8fa38e987..c4826f2be 100644
--- a/packages/web3-wrapper/src/index.ts
+++ b/packages/web3-wrapper/src/index.ts
@@ -33,7 +33,7 @@ export class Web3Wrapper {
public getContractDefaults(): Partial<TxData> {
return this._defaults;
}
- public setProvider(provider: Web3.Provider, networkId: number) {
+ public setProvider(provider: Web3.Provider) {
this._web3.setProvider(provider);
}
public isAddress(address: string): boolean {
diff --git a/packages/web3-wrapper/tsconfig.json b/packages/web3-wrapper/tsconfig.json
index 0aa8c3dde..3d967d05f 100644
--- a/packages/web3-wrapper/tsconfig.json
+++ b/packages/web3-wrapper/tsconfig.json
@@ -1,13 +1,7 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
- "module": "commonjs",
- "target": "es5",
- "lib": ["es2017", "dom"],
- "outDir": "lib",
- "sourceMap": true,
- "declaration": true,
- "noImplicitAny": true,
- "strictNullChecks": true
+ "outDir": "lib"
},
"include": ["./src/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"]
}
diff --git a/packages/website/package.json b/packages/website/package.json
index 89f8e14bc..eb541218b 100644
--- a/packages/website/package.json
+++ b/packages/website/package.json
@@ -101,7 +101,7 @@
"style-loader": "0.13.x",
"tslint": "5.8.0",
"typescript": "~2.6.1",
- "web3-typescript-typings": "^0.7.2",
+ "web3-typescript-typings": "^0.9.0",
"webpack": "^3.1.0",
"webpack-dev-middleware": "^1.10.0",
"webpack-dev-server": "^2.5.0"
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts
index 50cac6d29..1320fbeb9 100644
--- a/packages/website/ts/blockchain.ts
+++ b/packages/website/ts/blockchain.ts
@@ -66,12 +66,12 @@ export class Blockchain {
private _cachedProvider: Web3.Provider;
private _ledgerSubprovider: LedgerWalletSubprovider;
private _zrxPollIntervalId: NodeJS.Timer;
- private static async _onPageLoadAsync() {
+ private static async _onPageLoadAsync(): Promise<void> {
if (document.readyState === 'complete') {
return; // Already loaded
}
- return new Promise((resolve, reject) => {
- window.onload = resolve;
+ return new Promise<void>((resolve, reject) => {
+ window.onload = () => resolve();
});
}
private static _getNameGivenProvider(provider: Web3.Provider): string {
diff --git a/packages/website/ts/components/dialogs/ledger_config_dialog.tsx b/packages/website/ts/components/dialogs/ledger_config_dialog.tsx
index c8547694a..60db93c52 100644
--- a/packages/website/ts/components/dialogs/ledger_config_dialog.tsx
+++ b/packages/website/ts/components/dialogs/ledger_config_dialog.tsx
@@ -134,7 +134,7 @@ export class LedgerConfigDialog extends React.Component<LedgerConfigDialogProps,
labelReady="Update"
labelLoading="Updating..."
labelComplete="Updated!"
- onClickAsyncFn={this._onFetchAddressesForDerivationPathAsync.bind(this, true)}
+ onClickAsyncFn={this._onFetchAddressesForDerivationPathAsync.bind(this)}
/>
</div>
</div>
@@ -191,13 +191,15 @@ export class LedgerConfigDialog extends React.Component<LedgerConfigDialogProps,
const isOpen = false;
this.props.toggleDialogFn(isOpen);
}
- private async _onFetchAddressesForDerivationPathAsync() {
+ private async _onFetchAddressesForDerivationPathAsync(): Promise<boolean> {
const currentlySetPath = this.props.blockchain.getLedgerDerivationPathIfExists();
+ let didSucceed;
if (currentlySetPath === this.state.derivationPath) {
- return;
+ didSucceed = true;
+ return didSucceed;
}
this.props.blockchain.updateLedgerDerivationPathIfExists(this.state.derivationPath);
- const didSucceed = await this._fetchAddressesAndBalancesAsync();
+ didSucceed = await this._fetchAddressesAndBalancesAsync();
if (!didSucceed) {
this.setState({
derivationErrMsg: 'Failed to connect to Ledger.',
diff --git a/packages/website/ts/components/fill_warning_dialog.tsx b/packages/website/ts/components/fill_warning_dialog.tsx
index 38c10870b..165d21b34 100644
--- a/packages/website/ts/components/fill_warning_dialog.tsx
+++ b/packages/website/ts/components/fill_warning_dialog.tsx
@@ -5,7 +5,7 @@ import { colors } from 'ts/utils/colors';
interface FillWarningDialogProps {
isOpen: boolean;
- onToggleDialog: () => void;
+ onToggleDialog: (didUserCancel: boolean) => void;
}
export function FillWarningDialog(props: FillWarningDialogProps) {
diff --git a/packages/website/ts/components/inputs/allowance_toggle.tsx b/packages/website/ts/components/inputs/allowance_toggle.tsx
index b29511390..1be441e17 100644
--- a/packages/website/ts/components/inputs/allowance_toggle.tsx
+++ b/packages/website/ts/components/inputs/allowance_toggle.tsx
@@ -47,7 +47,7 @@ export class AllowanceToggle extends React.Component<AllowanceToggleProps, Allow
<Toggle
disabled={this.state.isSpinnerVisible}
toggled={this._isAllowanceSet()}
- onToggle={this._onToggleAllowanceAsync.bind(this, this.props.token)}
+ onToggle={this._onToggleAllowanceAsync.bind(this)}
/>
</div>
{this.state.isSpinnerVisible && (
@@ -58,10 +58,9 @@ export class AllowanceToggle extends React.Component<AllowanceToggleProps, Allow
</div>
);
}
- private async _onToggleAllowanceAsync() {
+ private async _onToggleAllowanceAsync(): Promise<void> {
if (this.props.userAddress === '') {
this.props.dispatcher.updateShouldBlockchainErrDialogBeOpen(true);
- return false;
}
this.setState({
@@ -80,7 +79,7 @@ export class AllowanceToggle extends React.Component<AllowanceToggleProps, Allow
});
const errMsg = '' + err;
if (_.includes(errMsg, 'User denied transaction')) {
- return false;
+ return;
}
utils.consoleLog(`Unexpected error encountered: ${err}`);
utils.consoleLog(err.stack);
diff --git a/packages/website/ts/components/inputs/token_amount_input.tsx b/packages/website/ts/components/inputs/token_amount_input.tsx
index f3f522ce3..63966d759 100644
--- a/packages/website/ts/components/inputs/token_amount_input.tsx
+++ b/packages/website/ts/components/inputs/token_amount_input.tsx
@@ -63,6 +63,8 @@ export class TokenAmountInput extends React.Component<TokenAmountInputProps, Tok
</Link>
</span>
);
+ } else {
+ return undefined;
}
}
}
diff --git a/packages/website/ts/components/portal.tsx b/packages/website/ts/components/portal.tsx
index 22cdcbf20..e2e28e8b6 100644
--- a/packages/website/ts/components/portal.tsx
+++ b/packages/website/ts/components/portal.tsx
@@ -322,10 +322,10 @@ export class Portal extends React.Component<PortalAllProps, PortalAllState> {
isWethNoticeDialogOpen: false,
});
}
- private _getSharedOrderIfExists(): Order {
+ private _getSharedOrderIfExists(): Order | undefined {
const queryString = window.location.search;
if (queryString.length === 0) {
- return;
+ return undefined;
}
const queryParams = queryString.substring(1).split('&');
const orderQueryParam = _.find(queryParams, queryParam => {
@@ -333,11 +333,11 @@ export class Portal extends React.Component<PortalAllProps, PortalAllState> {
return queryPair[0] === 'order';
});
if (_.isUndefined(orderQueryParam)) {
- return;
+ return undefined;
}
const orderPair = orderQueryParam.split('=');
if (orderPair.length !== 2) {
- return;
+ return undefined;
}
const validator = new SchemaValidator();
@@ -345,7 +345,7 @@ export class Portal extends React.Component<PortalAllProps, PortalAllState> {
const validationResult = validator.validate(order, orderSchema);
if (validationResult.errors.length > 0) {
utils.consoleLog(`Invalid shared order: ${validationResult.errors}`);
- return;
+ return undefined;
}
return order;
}
diff --git a/packages/website/ts/components/top_bar.tsx b/packages/website/ts/components/top_bar.tsx
index cd835930b..601471222 100644
--- a/packages/website/ts/components/top_bar.tsx
+++ b/packages/website/ts/components/top_bar.tsx
@@ -238,12 +238,12 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
</Drawer>
);
}
- private _renderDocsMenu() {
+ private _renderDocsMenu(): React.ReactNode {
if (
(!this._isViewing0xjsDocs() && !this._isViewingSmartContractsDocs() && !this._isViewingConnectDocs()) ||
_.isUndefined(this.props.menu)
) {
- return;
+ return undefined;
}
const sectionTitle = `${this.props.docsInfo.displayName} Docs`;
@@ -264,9 +264,9 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
</div>
);
}
- private _renderWiki() {
+ private _renderWiki(): React.ReactNode {
if (!this._isViewingWiki()) {
- return;
+ return undefined;
}
return (
@@ -283,9 +283,9 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
</div>
);
}
- private _renderPortalMenu() {
+ private _renderPortalMenu(): React.ReactNode {
if (!this._isViewingPortal()) {
- return;
+ return undefined;
}
return (
diff --git a/packages/website/ts/containers/portal.tsx b/packages/website/ts/containers/portal.tsx
index cdf5fc268..f0247935b 100644
--- a/packages/website/ts/containers/portal.tsx
+++ b/packages/website/ts/containers/portal.tsx
@@ -3,11 +3,7 @@ import * as _ from 'lodash';
import * as React from 'react';
import { connect } from 'react-redux';
import { Dispatch } from 'redux';
-import {
- Portal as PortalComponent,
- PortalAllProps as PortalComponentAllProps,
- PortalPassedProps as PortalComponentPassedProps,
-} from 'ts/components/portal';
+import { Portal as PortalComponent, PortalAllProps as PortalComponentAllProps } from 'ts/components/portal';
import { Dispatcher } from 'ts/redux/dispatcher';
import { State } from 'ts/redux/reducer';
import { BlockchainErrs, HashData, Order, ScreenWidths, Side, TokenByAddress, TokenStateByAddress } from 'ts/types';
@@ -80,6 +76,6 @@ const mapDispatchToProps = (dispatch: Dispatch<State>): ConnectedDispatch => ({
dispatcher: new Dispatcher(dispatch),
});
-export const Portal: React.ComponentClass<PortalComponentPassedProps> = connect(mapStateToProps, mapDispatchToProps)(
+export const Portal: React.ComponentClass<PortalComponentAllProps> = connect(mapStateToProps, mapDispatchToProps)(
PortalComponent,
);
diff --git a/packages/website/ts/local_storage/tracked_token_storage.ts b/packages/website/ts/local_storage/tracked_token_storage.ts
index 0cc384791..7733e8436 100644
--- a/packages/website/ts/local_storage/tracked_token_storage.ts
+++ b/packages/website/ts/local_storage/tracked_token_storage.ts
@@ -1,6 +1,6 @@
import * as _ from 'lodash';
import { localStorage } from 'ts/local_storage/local_storage';
-import { Token, TrackedTokensByNetworkId } from 'ts/types';
+import { Token, TrackedTokensByUserAddress } from 'ts/types';
import { configs } from 'ts/utils/configs';
const TRACKED_TOKENS_KEY = 'trackedTokens';
@@ -9,14 +9,14 @@ const TRACKED_TOKENS_CLEAR_KEY = 'lastClearTrackedTokensDate';
export const trackedTokenStorage = {
// Clear trackedTokens localStorage if we've updated the config variable in an update
// that introduced a backward incompatible change requiring the tracked tokens to be re-set
- clearIfRequired() {
+ clearIfRequired(): void {
const lastClearFillDate = localStorage.getItemIfExists(TRACKED_TOKENS_CLEAR_KEY);
if (lastClearFillDate !== configs.LAST_LOCAL_STORAGE_TRACKED_TOKEN_CLEARANCE_DATE) {
localStorage.removeItem(TRACKED_TOKENS_KEY);
}
localStorage.setItem(TRACKED_TOKENS_CLEAR_KEY, configs.LAST_LOCAL_STORAGE_TRACKED_TOKEN_CLEARANCE_DATE);
},
- addTrackedTokenToUser(userAddress: string, networkId: number, token: Token) {
+ addTrackedTokenToUser(userAddress: string, networkId: number, token: Token): void {
const trackedTokensByUserAddress = this.getTrackedTokensByUserAddress();
let trackedTokensByNetworkId = trackedTokensByUserAddress[userAddress];
if (_.isUndefined(trackedTokensByNetworkId)) {
@@ -31,7 +31,7 @@ export const trackedTokenStorage = {
const trackedTokensByUserAddressJSONString = JSON.stringify(trackedTokensByUserAddress);
localStorage.setItem(TRACKED_TOKENS_KEY, trackedTokensByUserAddressJSONString);
},
- getTrackedTokensByUserAddress(): TrackedTokensByNetworkId {
+ getTrackedTokensByUserAddress(): TrackedTokensByUserAddress {
const trackedTokensJSONString = localStorage.getItemIfExists(TRACKED_TOKENS_KEY);
if (_.isEmpty(trackedTokensJSONString)) {
return {};
@@ -52,7 +52,7 @@ export const trackedTokenStorage = {
const trackedTokens = trackedTokensByNetworkId[networkId];
return trackedTokens;
},
- removeTrackedToken(userAddress: string, networkId: number, tokenAddress: string) {
+ removeTrackedToken(userAddress: string, networkId: number, tokenAddress: string): void {
const trackedTokensByUserAddress = this.getTrackedTokensByUserAddress();
const trackedTokensByNetworkId = trackedTokensByUserAddress[userAddress];
const trackedTokens = trackedTokensByNetworkId[networkId];
diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts
index 7f82fded9..f873f95fa 100644
--- a/packages/website/ts/types.ts
+++ b/packages/website/ts/types.ts
@@ -155,7 +155,11 @@ export interface Action {
}
export interface TrackedTokensByNetworkId {
- [networkId: number]: Token;
+ [networkId: number]: Token[];
+}
+
+export interface TrackedTokensByUserAddress {
+ [userAddress: string]: TrackedTokensByNetworkId;
}
export interface Styles {
diff --git a/packages/website/ts/utils/doc_utils.ts b/packages/website/ts/utils/doc_utils.ts
index 0bc670d76..1f5f75ee2 100644
--- a/packages/website/ts/utils/doc_utils.ts
+++ b/packages/website/ts/utils/doc_utils.ts
@@ -20,7 +20,7 @@ export const docUtils = {
// TODO: Show the user an error message when the docs fail to load
const errMsg = await response.text();
utils.consoleLog(`Failed to load JSON file list: ${response.status} ${errMsg}`);
- return;
+ throw new Error(errMsg);
}
const responseXML = await response.text();
const responseJSONString = convert.xml2json(responseXML, {
@@ -43,7 +43,7 @@ export const docUtils = {
// TODO: Show the user an error message when the docs fail to load
const errMsg = await response.text();
utils.consoleLog(`Failed to load Doc JSON: ${response.status} ${errMsg}`);
- return;
+ throw new Error(errMsg);
}
const jsonDocObj = await response.json();
return jsonDocObj;
diff --git a/packages/website/tsconfig.json b/packages/website/tsconfig.json
index ebbee7ff3..38b177d0b 100644
--- a/packages/website/tsconfig.json
+++ b/packages/website/tsconfig.json
@@ -1,15 +1,14 @@
{
+ "extends": "../../tsconfig",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"outDir": "./transpiled/",
- "sourceMap": true,
- "lib": ["es2015", "dom"],
- "noImplicitAny": true,
- "module": "commonjs",
- "target": "es5",
"jsx": "react",
"baseUrl": "./",
"allowJs": true,
+ "strictNullChecks": false,
+ "noImplicitThis": false,
+ "declaration": false,
"paths": {
"*": ["node_modules/@types/*", "*"]
}