diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-02 04:05:17 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-02 04:05:17 +0800 |
commit | b7b45b69a66cfaf9c3737d1a8d95be21edccf527 (patch) | |
tree | 4337613836a8062bd73fc8ee1e4db444961df172 /packages | |
parent | df9cfe7840b99d72ed95058e47f2ffb6623d440e (diff) | |
parent | 9ca41b9536908dddfa51854abd41b7926e69bd09 (diff) | |
download | dexon-sol-tools-b7b45b69a66cfaf9c3737d1a8d95be21edccf527.tar dexon-sol-tools-b7b45b69a66cfaf9c3737d1a8d95be21edccf527.tar.gz dexon-sol-tools-b7b45b69a66cfaf9c3737d1a8d95be21edccf527.tar.bz2 dexon-sol-tools-b7b45b69a66cfaf9c3737d1a8d95be21edccf527.tar.lz dexon-sol-tools-b7b45b69a66cfaf9c3737d1a8d95be21edccf527.tar.xz dexon-sol-tools-b7b45b69a66cfaf9c3737d1a8d95be21edccf527.tar.zst dexon-sol-tools-b7b45b69a66cfaf9c3737d1a8d95be21edccf527.zip |
Merge branch 'v2-prototype' into refactor/order-utils/for-v2
* v2-prototype: (33 commits)
Only show ProviderDisplay in portal
Improve sol-cov docs
Remove old parse code
Refactor order parser and add shared order support to new portal
Add generate and fill order routes
Address feedback
Override ethereumjs-tx version
Fix missing key
Update placeholder param ordering
Change userEtherBalanceInWei to optional so we can know if its loading
Add loading state to ProviderDisplay
Tweaks
Add Placeholder component
Add StandardIconRow
Split render into loading and loaaded
Fix linter errors
Fix linter errors
Add ethereum-types to extraFileIncludes
Introduce ethereum-types package
Remove merge conflicts from yarn.lock
...
# Conflicts:
# packages/contracts/src/utils/exchange_wrapper.ts
# packages/contracts/src/utils/match_order_tester.ts
# packages/contracts/src/utils/types.ts
# packages/contracts/test/exchange/core.ts
# packages/contracts/test/exchange/match_orders.ts
# packages/contracts/test/libraries/lib_bytes.ts
# packages/sol-cov/package.json
Diffstat (limited to 'packages')
127 files changed, 961 insertions, 953 deletions
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 9efb1c972..1324a73d1 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -44,6 +44,7 @@ "docPublishConfigs": { "extraFileIncludes": [ "../types/src/index.ts", + "../ethereum-types/src/index.ts", "../contract-wrappers/src/types.ts", "../contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts", "../contract-wrappers/src/contract_wrappers/exchange_wrapper.ts", @@ -108,6 +109,7 @@ "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", "@0xproject/web3-wrapper": "^0.6.4", + "ethereum-types": "^0.0.1", "ethers": "^3.0.15", "lodash": "^4.17.4" }, diff --git a/packages/abi-gen/package.json b/packages/abi-gen/package.json index d3af33fdf..e02b930ed 100644 --- a/packages/abi-gen/package.json +++ b/packages/abi-gen/package.json @@ -27,9 +27,9 @@ }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/abi-gen/README.md", "dependencies": { - "@0xproject/types": "^0.7.0", "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", + "ethereum-types": "^0.0.1", "chalk": "^2.3.0", "glob": "^7.1.2", "handlebars": "^4.0.11", diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index ef5710f53..b7e6722ea 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -1,8 +1,8 @@ #!/usr/bin/env node -import { AbiDefinition, ConstructorAbi, EventAbi, MethodAbi } from '@0xproject/types'; import { abiUtils, logUtils } from '@0xproject/utils'; import chalk from 'chalk'; +import { AbiDefinition, ConstructorAbi, EventAbi, MethodAbi } from 'ethereum-types'; import * as fs from 'fs'; import { sync as globSync } from 'glob'; import * as Handlebars from 'handlebars'; diff --git a/packages/abi-gen/src/types.ts b/packages/abi-gen/src/types.ts index 648281774..68765b04d 100644 --- a/packages/abi-gen/src/types.ts +++ b/packages/abi-gen/src/types.ts @@ -1,4 +1,4 @@ -import { EventAbi, MethodAbi } from '@0xproject/types'; +import { EventAbi, MethodAbi } from 'ethereum-types'; export enum ParamKind { Input = 'input', diff --git a/packages/abi-gen/src/utils.ts b/packages/abi-gen/src/utils.ts index 20b734959..a46209dad 100644 --- a/packages/abi-gen/src/utils.ts +++ b/packages/abi-gen/src/utils.ts @@ -1,4 +1,4 @@ -import { AbiType, ConstructorAbi, DataItem } from '@0xproject/types'; +import { AbiType, ConstructorAbi, DataItem } from 'ethereum-types'; import * as fs from 'fs'; import * as _ from 'lodash'; import * as path from 'path'; diff --git a/packages/base-contract/package.json b/packages/base-contract/package.json index f79d3ebf6..c01a133e4 100644 --- a/packages/base-contract/package.json +++ b/packages/base-contract/package.json @@ -42,7 +42,7 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/types": "^0.7.0", + "ethereum-types": "^0.0.1", "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", "@0xproject/web3-wrapper": "^0.6.4", diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index f9298f413..d9e28f9f2 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -1,3 +1,5 @@ +import { abiUtils, BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { AbiDefinition, AbiType, @@ -8,9 +10,7 @@ import { Provider, TxData, TxDataPayable, -} from '@0xproject/types'; -import { abiUtils, BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; +} from 'ethereum-types'; import * as ethers from 'ethers'; import * as _ from 'lodash'; diff --git a/packages/base-contract/src/utils.ts b/packages/base-contract/src/utils.ts index 4b86bb1ad..61f176df5 100644 --- a/packages/base-contract/src/utils.ts +++ b/packages/base-contract/src/utils.ts @@ -1,4 +1,4 @@ -import { DataItem } from '@0xproject/types'; +import { DataItem } from 'ethereum-types'; import * as _ from 'lodash'; // tslint:disable-next-line:completed-docs diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index b28d04685..61e92903f 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -85,6 +85,7 @@ "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", "@0xproject/web3-wrapper": "^0.6.4", + "ethereum-types": "^0.0.1", "ethereumjs-blockstream": "^2.0.6", "ethereumjs-util": "^5.1.1", "ethers": "^3.0.15", diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index b2765b1a5..5fb19af11 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -2,11 +2,11 @@ * This file is auto-generated using abi-gen. Don't edit directly. * Templates can be found at https://github.com/0xProject/0x-monorepo/tree/development/packages/contract_templates. */ -// tslint:disable:no-consecutive-blank-lines +// tslint:disable:no-consecutive-blank-lines ordered-imports // tslint:disable-next-line:no-unused-variable import { BaseContract } from '@0xproject/base-contract'; import { ContractArtifact } from '@0xproject/sol-compiler'; -import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, MethodAbi, Provider, TxData, TxDataPayable } from '@0xproject/types'; +import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, DecodedLogArgs, MethodAbi, Provider, TxData, TxDataPayable } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as ethers from 'ethers'; diff --git a/packages/contract_templates/partials/event.handlebars b/packages/contract_templates/partials/event.handlebars index 3c6100e4f..69a99d937 100644 --- a/packages/contract_templates/partials/event.handlebars +++ b/packages/contract_templates/partials/event.handlebars @@ -1,4 +1,4 @@ -export interface {{name}}ContractEventArgs { +export interface {{name}}ContractEventArgs extends DecodedLogArgs { {{#each inputs}} {{name}}: {{#returnType type components}}{{/returnType}}; {{/each}} diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 8d29366a4..8b2945861 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -48,7 +48,9 @@ "@0xproject/subproviders": "^0.10.1", "@0xproject/sol-cov": "^0.0.11", "@types/lodash": "4.14.104", + "@types/bn.js": "^4.11.0", "@types/node": "^8.0.53", + "@types/ethereumjs-abi": "^0.6.0", "@types/yargs": "^10.0.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", @@ -73,6 +75,7 @@ "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", "@0xproject/web3-wrapper": "^0.6.4", + "ethereum-types": "^0.0.1", "bn.js": "^4.11.8", "ethereumjs-abi": "^0.6.4", "ethereumjs-util": "^5.1.1", diff --git a/packages/contracts/src/utils/erc20_wrapper.ts b/packages/contracts/src/utils/erc20_wrapper.ts index 92cf01cc2..0f45fb1e6 100644 --- a/packages/contracts/src/utils/erc20_wrapper.ts +++ b/packages/contracts/src/utils/erc20_wrapper.ts @@ -1,6 +1,6 @@ -import { Provider } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider } from 'ethereum-types'; import * as _ from 'lodash'; import { DummyERC20TokenContract } from '../contract_wrappers/generated/dummy_e_r_c20_token'; diff --git a/packages/contracts/src/utils/erc721_wrapper.ts b/packages/contracts/src/utils/erc721_wrapper.ts index bea801f3d..11a012602 100644 --- a/packages/contracts/src/utils/erc721_wrapper.ts +++ b/packages/contracts/src/utils/erc721_wrapper.ts @@ -1,7 +1,7 @@ import { generatePseudoRandomSalt } from '@0xproject/order-utils'; -import { Provider } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider } from 'ethereum-types'; import * as _ from 'lodash'; import { DummyERC721TokenContract } from '../contract_wrappers/generated/dummy_e_r_c721_token'; diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts index 8f5915d97..dd278e77c 100644 --- a/packages/contracts/src/utils/exchange_wrapper.ts +++ b/packages/contracts/src/utils/exchange_wrapper.ts @@ -1,6 +1,7 @@ -import { AssetProxyId, Provider, SignedOrder, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; +import { AssetProxyId, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { LogEntry, Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; import { ExchangeContract } from '../contract_wrappers/generated/exchange'; diff --git a/packages/contracts/src/utils/log_decoder.ts b/packages/contracts/src/utils/log_decoder.ts index 32819b657..07d10e69d 100644 --- a/packages/contracts/src/utils/log_decoder.ts +++ b/packages/contracts/src/utils/log_decoder.ts @@ -1,13 +1,14 @@ import { ContractArtifact } from '@0xproject/sol-compiler'; +import { AbiDecoder, BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { AbiDefinition, + DecodedLogArgs, LogEntry, LogWithDecodedArgs, RawLog, TransactionReceiptWithDecodedLogs, -} from '@0xproject/types'; -import { AbiDecoder, BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; +} from 'ethereum-types'; import * as _ from 'lodash'; import { artifacts } from './artifacts'; @@ -36,7 +37,7 @@ export class LogDecoder { }); this._abiDecoder = new AbiDecoder(abiArrays); } - public decodeLogOrThrow<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog { + public decodeLogOrThrow<ArgsType extends DecodedLogArgs>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog { const logWithDecodedArgsOrLog = this._abiDecoder.tryToDecodeLogOrNoop(log); if (_.isUndefined((logWithDecodedArgsOrLog as LogWithDecodedArgs<ArgsType>).args)) { throw new Error(`Unable to decode log: ${JSON.stringify(log)}`); diff --git a/packages/contracts/src/utils/match_order_tester.ts b/packages/contracts/src/utils/match_order_tester.ts index 85348b14d..09c0d8083 100644 --- a/packages/contracts/src/utils/match_order_tester.ts +++ b/packages/contracts/src/utils/match_order_tester.ts @@ -1,8 +1,9 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { assetProxyUtils, crypto, orderHashUtils } from '@0xproject/order-utils'; -import { AssetProxyId, LogWithDecodedArgs, SignedOrder } from '@0xproject/types'; +import { AssetProxyId, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; +import { LogWithDecodedArgs } from 'ethereum-types'; import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; diff --git a/packages/contracts/src/utils/multi_sig_wrapper.ts b/packages/contracts/src/utils/multi_sig_wrapper.ts index d67692194..9971e8f6e 100644 --- a/packages/contracts/src/utils/multi_sig_wrapper.ts +++ b/packages/contracts/src/utils/multi_sig_wrapper.ts @@ -1,6 +1,6 @@ -import { Provider, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; import { AssetProxyOwnerContract } from '../contract_wrappers/generated/asset_proxy_owner'; diff --git a/packages/contracts/src/utils/token_registry_wrapper.ts b/packages/contracts/src/utils/token_registry_wrapper.ts index 86daeca62..240c06fdc 100644 --- a/packages/contracts/src/utils/token_registry_wrapper.ts +++ b/packages/contracts/src/utils/token_registry_wrapper.ts @@ -1,16 +1,21 @@ -import * as Web3 from 'web3'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider } from 'ethereum-types'; import { TokenRegistryContract } from '../contract_wrappers/generated/token_registry'; import { Token } from './types'; +import { constants } from './constants'; + export class TokenRegWrapper { private _tokenReg: TokenRegistryContract; - constructor(tokenRegContract: TokenRegistryContract) { + private _web3Wrapper: Web3Wrapper; + constructor(tokenRegContract: TokenRegistryContract, provider: Provider) { this._tokenReg = tokenRegContract; + this._web3Wrapper = new Web3Wrapper(provider); } public async addTokenAsync(token: Token, from: string): Promise<string> { - const tx = this._tokenReg.addToken.sendTransactionAsync( + const txHash = await this._tokenReg.addToken.sendTransactionAsync( token.address as string, token.name, token.symbol, @@ -19,7 +24,8 @@ export class TokenRegWrapper { token.swarmHash, { from }, ); - return tx; + await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + return txHash; } public async getTokenMetaDataAsync(tokenAddress: string): Promise<Token> { const data = await this._tokenReg.getTokenMetaData.callAsync(tokenAddress); diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index a6c90dae0..6340c4a51 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -1,5 +1,6 @@ -import { AbiDefinition, ContractAbi, Order, OrderWithoutExchangeAddress } from '@0xproject/types'; +import { Order, OrderWithoutExchangeAddress } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; +import { AbiDefinition, ContractAbi } from 'ethereum-types'; export interface ERC20BalancesByOwner { [ownerAddress: string]: { diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts index 4b8512222..1049ab967 100644 --- a/packages/contracts/src/utils/web3_wrapper.ts +++ b/packages/contracts/src/utils/web3_wrapper.ts @@ -1,7 +1,7 @@ import { devConstants, env, EnvVars, web3Factory } from '@0xproject/dev-utils'; import { prependSubprovider } from '@0xproject/subproviders'; -import { Provider } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider } from 'ethereum-types'; import { coverage } from './coverage'; diff --git a/packages/contracts/test/asset_proxy_owner.ts b/packages/contracts/test/asset_proxy_owner.ts index 43c5da512..4c16b5cff 100644 --- a/packages/contracts/test/asset_proxy_owner.ts +++ b/packages/contracts/test/asset_proxy_owner.ts @@ -1,7 +1,7 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; -import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; +import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; import 'make-promises-safe'; import * as Web3 from 'web3'; @@ -66,8 +66,14 @@ describe('AssetProxyOwner', () => { SECONDS_TIME_LOCKED, ); multiSigWrapper = new MultiSigWrapper(multiSig, provider); - await erc20Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner }); - await erc721Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner }); + await web3Wrapper.awaitTransactionSuccessAsync( + await erc20Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await erc721Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 10dd635fe..4e52b658f 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -83,7 +83,10 @@ describe('EtherToken', () => { it('should convert ether tokens to ether with sufficient balance', async () => { const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); - await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }); + await web3Wrapper.awaitTransactionSuccessAsync( + await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const ethTokensToWithdraw = initEthTokenBalance; diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index adc57c7a4..8320e97d6 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -1,9 +1,10 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { assetProxyUtils, crypto, orderHashUtils } from '@0xproject/order-utils'; -import { AssetProxyId, LogWithDecodedArgs, SignedOrder } from '@0xproject/types'; +import { AssetProxyId, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; +import { LogWithDecodedArgs } from 'ethereum-types'; import ethUtil = require('ethereumjs-util'); import 'make-promises-safe'; diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index 67281a915..07295d78a 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -1,9 +1,10 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { assetProxyUtils, crypto } from '@0xproject/order-utils'; -import { AssetProxyId, LogWithDecodedArgs, SignedOrder } from '@0xproject/types'; +import { AssetProxyId, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; +import { LogWithDecodedArgs } from 'ethereum-types'; import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 32b319e56..26cfa8291 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -1,9 +1,10 @@ import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; -import { AssetProxyId, LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; +import { AssetProxyId } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import BN = require('bn.js'); import * as chai from 'chai'; +import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import ethUtil = require('ethereumjs-util'); import * as Web3 from 'web3'; diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 7b7885a00..1302d0fa0 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -1,8 +1,8 @@ import { BlockchainLifecycle, web3Factory } from '@0xproject/dev-utils'; -import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; +import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; import 'make-promises-safe'; import * as Web3 from 'web3'; diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 7980977c8..64caac387 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -35,7 +35,7 @@ describe('TokenRegistry', () => { owner = accounts[0]; notOwner = accounts[1]; tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync(artifacts.TokenRegistry, provider, txDefaults); - tokenRegWrapper = new TokenRegWrapper(tokenReg); + tokenRegWrapper = new TokenRegWrapper(tokenReg, provider); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index e5787d5b8..df01f31bb 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -1,6 +1,6 @@ // import { ECSignature, SignedOrder, ZeroEx } from '0x.js'; // import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; -// import { ExchangeContractErrs } from '@0xproject/types'; +// import { ExchangeContractErrs } from 'ethereum-types'; // import { BigNumber } from '@0xproject/utils'; // import { Web3Wrapper } from '@0xproject/web3-wrapper'; // import * as chai from 'chai'; diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index c68d8bdcf..b2acdebaa 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -64,7 +64,10 @@ describe('UnlimitedAllowanceToken', () => { const receiver = spender; const initOwnerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = new BigNumber(1); - await token.transfer.sendTransactionAsync(receiver, amountToTransfer, { from: owner }); + await web3Wrapper.awaitTransactionSuccessAsync( + await token.transfer.sendTransactionAsync(receiver, amountToTransfer, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const finalOwnerBalance = await token.balanceOf.callAsync(owner); const finalReceiverBalance = await token.balanceOf.callAsync(receiver); @@ -86,7 +89,10 @@ describe('UnlimitedAllowanceToken', () => { it('should throw if owner has insufficient balance', async () => { const ownerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = ownerBalance.plus(1); - await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner }); + await web3Wrapper.awaitTransactionSuccessAsync( + await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); return expect( token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, @@ -121,11 +127,17 @@ describe('UnlimitedAllowanceToken', () => { const initOwnerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; - await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner }); - await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, { - from: spender, - gas: constants.MAX_TOKEN_TRANSFERFROM_GAS, - }); + await web3Wrapper.awaitTransactionSuccessAsync( + await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, { + from: spender, + gas: constants.MAX_TOKEN_TRANSFERFROM_GAS, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const newSpenderAllowance = await token.allowance.callAsync(owner, spender); expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance); @@ -135,11 +147,17 @@ describe('UnlimitedAllowanceToken', () => { const initOwnerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner }); - await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, { - from: spender, - gas: constants.MAX_TOKEN_TRANSFERFROM_GAS, - }); + await web3Wrapper.awaitTransactionSuccessAsync( + await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, { + from: spender, + gas: constants.MAX_TOKEN_TRANSFERFROM_GAS, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const newOwnerBalance = await token.balanceOf.callAsync(owner); const newSpenderBalance = await token.balanceOf.callAsync(spender); @@ -152,11 +170,17 @@ describe('UnlimitedAllowanceToken', () => { const initOwnerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = initOwnerBalance; const initSpenderAllowance = initOwnerBalance; - await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner }); - await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, { - from: spender, - gas: constants.MAX_TOKEN_TRANSFERFROM_GAS, - }); + await web3Wrapper.awaitTransactionSuccessAsync( + await token.approve.sendTransactionAsync(spender, initSpenderAllowance, { from: owner }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await token.transferFrom.sendTransactionAsync(owner, spender, amountToTransfer, { + from: spender, + gas: constants.MAX_TOKEN_TRANSFERFROM_GAS, + }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); const newSpenderAllowance = await token.allowance.callAsync(owner, spender); expect(newSpenderAllowance).to.be.bignumber.equal(0); diff --git a/packages/dev-utils/package.json b/packages/dev-utils/package.json index 0b11029f6..47a13733b 100644 --- a/packages/dev-utils/package.json +++ b/packages/dev-utils/package.json @@ -46,6 +46,7 @@ "dependencies": { "@0xproject/subproviders": "^0.10.2", "@0xproject/types": "^0.7.0", + "ethereum-types": "^0.0.1", "@0xproject/typescript-typings": "^0.3.2", "@0xproject/web3-wrapper": "^0.6.4", "lodash": "^4.17.4", diff --git a/packages/dev-utils/src/web3_factory.ts b/packages/dev-utils/src/web3_factory.ts index c273035da..12872c122 100644 --- a/packages/dev-utils/src/web3_factory.ts +++ b/packages/dev-utils/src/web3_factory.ts @@ -7,7 +7,7 @@ import ProviderEngine = require('web3-provider-engine'); import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); import { EmptyWalletSubprovider, FakeGasEstimateSubprovider, GanacheSubprovider } from '@0xproject/subproviders'; -import { Provider } from '@0xproject/types'; +import { Provider } from 'ethereum-types'; import * as fs from 'fs'; import * as _ from 'lodash'; import * as process from 'process'; diff --git a/packages/dev-utils/test/blockchain_lifecycle_test.ts b/packages/dev-utils/test/blockchain_lifecycle_test.ts index 857a6b50e..3d7d2e0ef 100644 --- a/packages/dev-utils/test/blockchain_lifecycle_test.ts +++ b/packages/dev-utils/test/blockchain_lifecycle_test.ts @@ -1,6 +1,6 @@ -import { BlockParamLiteral } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; +import { BlockParamLiteral } from 'ethereum-types'; import 'make-promises-safe'; import 'mocha'; diff --git a/packages/dev-utils/test/rpc_test.ts b/packages/dev-utils/test/rpc_test.ts index 45d1226c2..cff946e23 100644 --- a/packages/dev-utils/test/rpc_test.ts +++ b/packages/dev-utils/test/rpc_test.ts @@ -1,6 +1,6 @@ -import { BlockParamLiteral } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; +import { BlockParamLiteral } from 'ethereum-types'; import 'make-promises-safe'; import 'mocha'; diff --git a/packages/ethereum-types/.npmignore b/packages/ethereum-types/.npmignore new file mode 100644 index 000000000..24e65ad5b --- /dev/null +++ b/packages/ethereum-types/.npmignore @@ -0,0 +1,6 @@ +.* +yarn-error.log +/scripts/ +/src/ +tsconfig.json +/lib/monorepo_scripts/ diff --git a/packages/ethereum-types/CHANGELOG.json b/packages/ethereum-types/CHANGELOG.json new file mode 100644 index 000000000..ed0526ee0 --- /dev/null +++ b/packages/ethereum-types/CHANGELOG.json @@ -0,0 +1,11 @@ +[ + { + "version": "0.0.1", + "changes": [ + { + "note": "Initial publish", + "pr": "642" + } + ] + } +] diff --git a/packages/ethereum-types/README.md b/packages/ethereum-types/README.md new file mode 100644 index 000000000..817e22d15 --- /dev/null +++ b/packages/ethereum-types/README.md @@ -0,0 +1,61 @@ +## ethereum-types + +Typescript types shared across Ethereum-related packages/libraries/tools. + +## Installation + +```bash +yarn add -D ethereum-types +``` + +## Usage + +```javascript +import { TransactionReceipt, TxData, TxDataPayable } from 'ethereum-types'; +``` + +## Contributing + +We welcome improvements and fixes from the wider community! 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 +``` + +### Build + +To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: + +```bash +PKG=ethereum-types yarn build +``` + +Or continuously rebuild on change: + +```bash +PKG=ethereum-types yarn watch +``` + +### Clean + +```bash +yarn clean +``` + +### Lint + +```bash +yarn lint +``` diff --git a/packages/ethereum-types/package.json b/packages/ethereum-types/package.json new file mode 100644 index 000000000..0c9519994 --- /dev/null +++ b/packages/ethereum-types/package.json @@ -0,0 +1,42 @@ +{ + "name": "ethereum-types", + "version": "0.0.1", + "engines": { + "node": ">=6.12" + }, + "description": "Ethereum types", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "scripts": { + "watch": "tsc -w", + "build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts", + "clean": "shx rm -rf lib scripts", + "lint": "tslint --project .", + "manual:postpublish": "yarn build; node ./scripts/postpublish.js" + }, + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/0xProject/0x-monorepo.git" + }, + "bugs": { + "url": "https://github.com/0xProject/0x-monorepo/issues" + }, + "homepage": "https://github.com/0xProject/0x-monorepo/packages/ethereum-types/README.md", + "devDependencies": { + "@0xproject/monorepo-scripts": "^0.1.20", + "@0xproject/tslint-config": "^0.4.18", + "copyfiles": "^1.2.0", + "make-promises-safe": "^1.1.0", + "shx": "^0.2.2", + "tslint": "5.8.0", + "typescript": "2.7.1" + }, + "dependencies": { + "@types/node": "^8.0.53", + "bignumber.js": "~4.1.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/ethereum-types/src/globals.d.ts b/packages/ethereum-types/src/globals.d.ts new file mode 100644 index 000000000..94e63a32d --- /dev/null +++ b/packages/ethereum-types/src/globals.d.ts @@ -0,0 +1,6 @@ +declare module '*.json' { + const json: any; + /* tslint:disable */ + export default json; + /* tslint:enable */ +} diff --git a/packages/ethereum-types/src/index.ts b/packages/ethereum-types/src/index.ts new file mode 100644 index 000000000..f00ae963a --- /dev/null +++ b/packages/ethereum-types/src/index.ts @@ -0,0 +1,281 @@ +import { BigNumber } from 'bignumber.js'; + +export type JSONRPCErrorCallback = (err: Error | null, result?: JSONRPCResponsePayload) => void; + +/** + * Do not create your own provider. Use an existing provider from a Web3 or ProviderEngine library + * Read more about Providers in the 0x wiki. + */ +export interface Provider { + sendAsync(payload: JSONRPCRequestPayload, callback: JSONRPCErrorCallback): void; +} + +export type ContractAbi = AbiDefinition[]; + +export type AbiDefinition = FunctionAbi | EventAbi; + +export type FunctionAbi = MethodAbi | ConstructorAbi | FallbackAbi; + +export type ConstructorStateMutability = 'nonpayable' | 'payable'; +export type StateMutability = 'pure' | 'view' | ConstructorStateMutability; + +export interface MethodAbi { + type: AbiType.Function; + name: string; + inputs: DataItem[]; + outputs: DataItem[]; + constant: boolean; + stateMutability: StateMutability; + payable: boolean; +} + +export interface ConstructorAbi { + type: AbiType.Constructor; + inputs: DataItem[]; + payable: boolean; + stateMutability: ConstructorStateMutability; +} + +export interface FallbackAbi { + type: AbiType.Fallback; + payable: boolean; +} + +export interface EventParameter extends DataItem { + indexed: boolean; +} + +export interface EventAbi { + type: AbiType.Event; + name: string; + inputs: EventParameter[]; + anonymous: boolean; +} + +export interface DataItem { + name: string; + type: string; + components?: DataItem[]; +} + +export enum OpCode { + DelegateCall = 'DELEGATECALL', + Revert = 'REVERT', + Create = 'CREATE', + Stop = 'STOP', + Invalid = 'INVALID', + CallCode = 'CALLCODE', + StaticCall = 'STATICCALL', + Return = 'RETURN', + Call = 'CALL', + SelfDestruct = 'SELFDESTRUCT', +} + +export interface StructLog { + depth: number; + error: string; + gas: number; + gasCost: number; + memory: string[]; + op: OpCode; + pc: number; + stack: string[]; + storage: { [location: string]: string }; +} + +export interface TransactionTrace { + gas: number; + returnValue: any; + structLogs: StructLog[]; +} + +export type Unit = + | 'kwei' + | 'ada' + | 'mwei' + | 'babbage' + | 'gwei' + | 'shannon' + | 'szabo' + | 'finney' + | 'ether' + | 'kether' + | 'grand' + | 'einstein' + | 'mether' + | 'gether' + | 'tether'; + +export interface JSONRPCRequestPayload { + params: any[]; + method: string; + id: number; + jsonrpc: string; +} + +export interface JSONRPCResponsePayload { + result: any; + id: number; + jsonrpc: string; +} + +export 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; + totalDifficulty: BigNumber; + extraData: string; + size: number; + gasLimit: number; + gasUsed: number; + timestamp: number; + uncles: string[]; +} + +export interface BlockWithoutTransactionData extends AbstractBlock { + transactions: string[]; +} + +export interface BlockWithTransactionData extends AbstractBlock { + transactions: Transaction[]; +} + +export interface Transaction { + hash: string; + nonce: number; + blockHash: string | null; + blockNumber: number | null; + transactionIndex: number | null; + from: string; + to: string | null; + value: BigNumber; + gasPrice: BigNumber; + gas: number; + input: string; +} + +export interface CallTxDataBase { + to?: string; + value?: number | string | BigNumber; + gas?: number | string | BigNumber; + gasPrice?: number | string | BigNumber; + data?: string; + nonce?: number; +} + +export interface TxData extends CallTxDataBase { + from: string; +} + +export interface CallData extends CallTxDataBase { + from?: string; +} + +export interface FilterObject { + fromBlock?: number | string; + toBlock?: number | string; + address?: string; + topics?: LogTopic[]; +} + +export type LogTopic = null | string | string[]; + +export interface DecodedLogEntry<A> extends LogEntry { + event: string; + args: A; +} + +export interface DecodedLogEntryEvent<A> extends DecodedLogEntry<A> { + removed: boolean; +} + +export interface LogEntryEvent extends LogEntry { + removed: boolean; +} + +export interface LogEntry { + logIndex: number | null; + transactionIndex: number | null; + transactionHash: string; + blockHash: string | null; + blockNumber: number | null; + address: string; + data: string; + topics: string[]; +} + +export interface TxDataPayable extends TxData { + value?: BigNumber; +} + +export 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[]; +} + +export enum AbiType { + Function = 'function', + Constructor = 'constructor', + Event = 'event', + Fallback = 'fallback', +} + +export type ContractEventArg = string | BigNumber | number | boolean; + +export interface DecodedLogArgs { + [argName: string]: ContractEventArg; +} + +export interface LogWithDecodedArgs<ArgsType extends DecodedLogArgs> extends DecodedLogEntry<ArgsType> {} +export type RawLog = LogEntry; + +export enum BlockParamLiteral { + Earliest = 'earliest', + Latest = 'latest', + Pending = 'pending', +} + +export type BlockParam = BlockParamLiteral | number; + +export interface RawLogEntry { + logIndex: string | null; + transactionIndex: string | null; + transactionHash: string; + blockHash: string | null; + blockNumber: string | null; + address: string; + data: string; + topics: string[]; +} + +export enum SolidityTypes { + Address = 'address', + Uint256 = 'uint256', + Uint8 = 'uint8', + Uint = 'uint', +} + +/** + * Contains the logs returned by a TransactionReceipt. We attempt to decode the + * logs using AbiDecoder. If we have the logs corresponding ABI, we decode it, + * otherwise we don't. + */ +export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt { + logs: Array<LogWithDecodedArgs<DecodedLogArgs> | LogEntry>; +} diff --git a/packages/ethereum-types/src/monorepo_scripts/postpublish.ts b/packages/ethereum-types/src/monorepo_scripts/postpublish.ts new file mode 100644 index 000000000..dcb99d0f7 --- /dev/null +++ b/packages/ethereum-types/src/monorepo_scripts/postpublish.ts @@ -0,0 +1,8 @@ +import { postpublishUtils } from '@0xproject/monorepo-scripts'; + +import * as packageJSON from '../package.json'; +import * as tsConfigJSON from '../tsconfig.json'; + +const cwd = `${__dirname}/..`; +// tslint:disable-next-line:no-floating-promises +postpublishUtils.runAsync(packageJSON, tsConfigJSON, cwd); diff --git a/packages/ethereum-types/tsconfig.json b/packages/ethereum-types/tsconfig.json new file mode 100644 index 000000000..82a45ea94 --- /dev/null +++ b/packages/ethereum-types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { + "typeRoots": ["../../node_modules/@types"], + "outDir": "lib" + }, + "include": ["src/**/*"] +} diff --git a/packages/ethereum-types/tslint.json b/packages/ethereum-types/tslint.json new file mode 100644 index 000000000..ffaefe83a --- /dev/null +++ b/packages/ethereum-types/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": ["@0xproject/tslint-config"] +} diff --git a/packages/fill-scenarios/package.json b/packages/fill-scenarios/package.json index e2f1a2af1..d0d3d9ec4 100644 --- a/packages/fill-scenarios/package.json +++ b/packages/fill-scenarios/package.json @@ -39,6 +39,7 @@ "@0xproject/base-contract": "^0.3.2", "@0xproject/order-utils": "0.0.5", "@0xproject/types": "0.7.0", + "ethereum-types": "^0.0.1", "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", "@0xproject/web3-wrapper": "^0.6.4", diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index 64805b6a8..603e5ab73 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -27,7 +27,8 @@ "assets": [], "docPublishConfigs": { "extraFileIncludes": [ - "../types/src/index.ts" + "../types/src/index.ts", + "../ethereum-types/src/index.ts" ], "s3BucketPath": "s3://doc-jsons/json-schemas/", "s3StagingBucketPath": "s3://staging-doc-jsons/json-schemas/" diff --git a/packages/metacoin/package.json b/packages/metacoin/package.json index 312aa0819..a85bf8f77 100644 --- a/packages/metacoin/package.json +++ b/packages/metacoin/package.json @@ -35,6 +35,7 @@ "@0xproject/types": "^0.7.0", "@0xproject/utils": "^0.6.2", "@0xproject/web3-wrapper": "^0.6.4", + "ethereum-types": "^0.0.1", "ethers": "^3.0.15", "lodash": "^4.17.4", "web3-provider-engine": "^14.0.4" diff --git a/packages/metacoin/test/metacoin_test.ts b/packages/metacoin/test/metacoin_test.ts index 034c1265e..3436fb49e 100644 --- a/packages/metacoin/test/metacoin_test.ts +++ b/packages/metacoin/test/metacoin_test.ts @@ -1,9 +1,9 @@ import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils'; import { ContractArtifact } from '@0xproject/sol-compiler'; -import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; +import { LogWithDecodedArgs } from 'ethereum-types'; import 'make-promises-safe'; import * as MetacoinArtifact from '../artifacts/Metacoin.json'; diff --git a/packages/migrations/package.json b/packages/migrations/package.json index b8137cab9..75d735e6a 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -53,6 +53,7 @@ "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", "@0xproject/web3-wrapper": "^0.6.4", + "ethereum-types": "^0.0.1", "ethers": "^3.0.15", "lodash": "^4.17.4" }, diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts index 49b4e897c..a6fd86e5a 100644 --- a/packages/migrations/src/migrate.ts +++ b/packages/migrations/src/migrate.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node import { devConstants, web3Factory } from '@0xproject/dev-utils'; -import { Provider } from '@0xproject/types'; import { logUtils } from '@0xproject/utils'; +import { Provider } from 'ethereum-types'; import * as path from 'path'; import * as yargs from 'yargs'; diff --git a/packages/migrations/src/v1/migration.ts b/packages/migrations/src/v1/migration.ts index 233339244..baa776537 100644 --- a/packages/migrations/src/v1/migration.ts +++ b/packages/migrations/src/v1/migration.ts @@ -1,6 +1,6 @@ -import { Provider, TxData } from '@0xproject/types'; import { BigNumber, NULL_BYTES } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider, TxData } from 'ethereum-types'; import * as _ from 'lodash'; import { ArtifactWriter } from '../artifact_writer'; diff --git a/packages/migrations/src/v2/migration.ts b/packages/migrations/src/v2/migration.ts index fd7223252..08a8ad2a7 100644 --- a/packages/migrations/src/v2/migration.ts +++ b/packages/migrations/src/v2/migration.ts @@ -1,6 +1,6 @@ -import { Provider, TxData } from '@0xproject/types'; import { BigNumber, NULL_BYTES } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider, TxData } from 'ethereum-types'; import * as _ from 'lodash'; import { ArtifactWriter } from '../artifact_writer'; diff --git a/packages/order-utils/package.json b/packages/order-utils/package.json index f4ca7ea40..ebfd8b8b4 100644 --- a/packages/order-utils/package.json +++ b/packages/order-utils/package.json @@ -30,7 +30,8 @@ "postpublish": { "docPublishConfigs": { "extraFileIncludes": [ - "../types/src/index.ts" + "../types/src/index.ts", + "../ethereum-types/src/index.ts" ], "s3BucketPath": "s3://doc-jsons/order-utils/", "s3StagingBucketPath": "s3://staging-doc-jsons/order-utils/" @@ -50,6 +51,8 @@ "@0xproject/dev-utils": "^0.4.2", "@0xproject/monorepo-scripts": "^0.1.20", "@0xproject/tslint-config": "^0.4.18", + "@types/ethereumjs-abi": "^0.6.0", + "@types/bn.js": "^4.11.0", "@types/lodash": "4.14.104", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", diff --git a/packages/order-watcher/package.json b/packages/order-watcher/package.json index 6b8165116..fcc40d56d 100644 --- a/packages/order-watcher/package.json +++ b/packages/order-watcher/package.json @@ -86,6 +86,7 @@ "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", "@0xproject/web3-wrapper": "^0.6.4", + "ethereum-types": "^0.0.1", "bintrees": "^1.0.2", "ethers": "^3.0.15", "lodash": "^4.17.4" diff --git a/packages/react-docs/package.json b/packages/react-docs/package.json index 531c0d90c..3d9ef08e8 100644 --- a/packages/react-docs/package.json +++ b/packages/react-docs/package.json @@ -28,6 +28,7 @@ "@0xproject/dev-utils": "^0.4.2", "@0xproject/monorepo-scripts": "^0.1.20", "@0xproject/tslint-config": "^0.4.18", + "@types/compare-versions": "^3.0.0", "copyfiles": "^1.2.0", "make-promises-safe": "^1.1.0", "shx": "^0.2.2", diff --git a/packages/react-shared/package.json b/packages/react-shared/package.json index d28972325..eb964a0f4 100644 --- a/packages/react-shared/package.json +++ b/packages/react-shared/package.json @@ -41,6 +41,7 @@ "@types/react": "16.3.13", "@types/react-dom": "^16.0.3", "@types/react-scroll": "0.0.31", + "@types/is-mobile": "0.3.0", "basscss": "^8.0.3", "is-mobile": "^0.2.2", "lodash": "^4.17.4", diff --git a/packages/sol-compiler/package.json b/packages/sol-compiler/package.json index a74e4ae3e..60ed3655f 100644 --- a/packages/sol-compiler/package.json +++ b/packages/sol-compiler/package.json @@ -28,7 +28,8 @@ "assets": [], "docPublishConfigs": { "extraFileIncludes": [ - "../types/src/index.ts" + "../types/src/index.ts", + "../ethereum-types/src/index.ts" ], "s3BucketPath": "s3://doc-jsons/sol-compiler/", "s3StagingBucketPath": "s3://staging-doc-jsons/sol-compiler/" @@ -80,6 +81,7 @@ "@0xproject/utils": "^0.6.2", "@0xproject/web3-wrapper": "^0.6.4", "@types/yargs": "^11.0.0", + "ethereum-types": "^0.0.1", "chalk": "^2.3.0", "ethereumjs-util": "^5.1.1", "isomorphic-fetch": "^2.2.1", diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index 1d5bdb940..d2dda75ea 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -11,9 +11,9 @@ import { Resolver, URLResolver, } from '@0xproject/sol-resolver'; -import { ContractAbi } from '@0xproject/types'; import { logUtils, promisify } from '@0xproject/utils'; import chalk from 'chalk'; +import { ContractAbi } from 'ethereum-types'; import * as ethUtil from 'ethereumjs-util'; import * as fs from 'fs'; import 'isomorphic-fetch'; diff --git a/packages/sol-compiler/src/utils/encoder.ts b/packages/sol-compiler/src/utils/encoder.ts index 806efbbca..0f2d75691 100644 --- a/packages/sol-compiler/src/utils/encoder.ts +++ b/packages/sol-compiler/src/utils/encoder.ts @@ -1,4 +1,4 @@ -import { AbiDefinition, AbiType, ContractAbi, DataItem } from '@0xproject/types'; +import { AbiDefinition, AbiType, ContractAbi, DataItem } from 'ethereum-types'; import * as _ from 'lodash'; import * as web3Abi from 'web3-eth-abi'; diff --git a/packages/sol-compiler/src/utils/types.ts b/packages/sol-compiler/src/utils/types.ts index d43347fa6..759a7a555 100644 --- a/packages/sol-compiler/src/utils/types.ts +++ b/packages/sol-compiler/src/utils/types.ts @@ -1,4 +1,4 @@ -import { ContractAbi, Provider, TxData } from '@0xproject/types'; +import { ContractAbi, Provider, TxData } from 'ethereum-types'; import * as solc from 'solc'; import * as Web3 from 'web3'; import * as yargs from 'yargs'; diff --git a/packages/sol-compiler/test/util/provider.ts b/packages/sol-compiler/test/util/provider.ts index 2bd178129..7215ffae7 100644 --- a/packages/sol-compiler/test/util/provider.ts +++ b/packages/sol-compiler/test/util/provider.ts @@ -1,5 +1,5 @@ import { web3Factory } from '@0xproject/dev-utils'; -import { Provider } from '@0xproject/types'; +import { Provider } from 'ethereum-types'; import * as Web3 from 'web3'; const providerConfigs = { shouldUseInProcessGanache: true }; diff --git a/packages/sol-cov/package.json b/packages/sol-cov/package.json index 72110265c..4d92a610b 100644 --- a/packages/sol-cov/package.json +++ b/packages/sol-cov/package.json @@ -29,7 +29,8 @@ "docPublishConfigs": { "extraFileIncludes": [ "../subproviders/src/types.ts", - "../types/src/index.ts" + "../types/src/index.ts", + "../ethereum-types/src/index.ts" ], "s3BucketPath": "s3://doc-jsons/sol-cov/", "s3StagingBucketPath": "s3://staging-doc-jsons/sol-cov/" @@ -48,9 +49,9 @@ "dependencies": { "@0xproject/sol-compiler": "^0.5.0", "@0xproject/subproviders": "^0.10.2", - "@0xproject/types": "1.0.0", "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", + "ethereum-types": "^0.0.1", "ethereumjs-util": "^5.1.1", "glob": "^7.1.2", "istanbul": "^0.4.5", @@ -67,6 +68,7 @@ "@types/istanbul": "^0.4.30", "@types/loglevel": "^1.5.3", "@types/mkdirp": "^0.5.1", + "@types/solidity-parser-antlr": "^0.2.0", "@types/mocha": "^2.2.42", "@types/node": "^8.0.53", "@types/rimraf": "^2.0.2", diff --git a/packages/sol-cov/src/coverage_subprovider.ts b/packages/sol-cov/src/coverage_subprovider.ts index 438339a3f..ca7f4aed2 100644 --- a/packages/sol-cov/src/coverage_subprovider.ts +++ b/packages/sol-cov/src/coverage_subprovider.ts @@ -1,5 +1,5 @@ import { Callback, ErrorCallback, NextCallback, Subprovider } from '@0xproject/subproviders'; -import { BlockParam, CallData, JSONRPCRequestPayload, TransactionTrace, TxData } from '@0xproject/types'; +import { BlockParam, CallData, JSONRPCRequestPayload, TransactionTrace, TxData } from 'ethereum-types'; import * as fs from 'fs'; import * as _ from 'lodash'; import { Lock } from 'semaphore-async-await'; diff --git a/packages/sol-cov/src/trace.ts b/packages/sol-cov/src/trace.ts index 6caea1610..1c21c8e5c 100644 --- a/packages/sol-cov/src/trace.ts +++ b/packages/sol-cov/src/trace.ts @@ -1,5 +1,5 @@ -import { OpCode, StructLog, TransactionTrace } from '@0xproject/types'; import { addressUtils, BigNumber, logUtils } from '@0xproject/utils'; +import { OpCode, StructLog, TransactionTrace } from 'ethereum-types'; import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util'; import * as fs from 'fs'; import * as _ from 'lodash'; diff --git a/packages/sol-cov/test/trace_test.ts b/packages/sol-cov/test/trace_test.ts index c140cba0d..07e270b71 100644 --- a/packages/sol-cov/test/trace_test.ts +++ b/packages/sol-cov/test/trace_test.ts @@ -1,5 +1,5 @@ -import { OpCode, StructLog } from '@0xproject/types'; import * as chai from 'chai'; +import { OpCode, StructLog } from 'ethereum-types'; import * as fs from 'fs'; import * as _ from 'lodash'; import 'mocha'; diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index 3cd5f0e9b..3a28e5e8d 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -31,7 +31,8 @@ "assets": [], "docPublishConfigs": { "extraFileIncludes": [ - "../types/src/index.ts" + "../types/src/index.ts", + "../ethereum-types/src/index.ts" ], "s3BucketPath": "s3://doc-jsons/subproviders/", "s3StagingBucketPath": "s3://staging-doc-jsons/subproviders/" @@ -45,6 +46,7 @@ "@0xproject/utils": "^0.6.2", "@ledgerhq/hw-app-eth": "^4.3.0", "@ledgerhq/hw-transport-u2f": "^4.3.0", + "ethereum-types": "^0.0.1", "bip39": "^2.5.0", "bn.js": "^4.11.8", "ethereumjs-tx": "^1.3.3", @@ -61,6 +63,9 @@ "@0xproject/tslint-config": "^0.4.18", "@0xproject/utils": "^0.6.2", "@types/bip39": "^2.4.0", + "@types/bn.js": "^4.11.0", + "@types/hdkey": "^0.7.0", + "@types/ethereumjs-tx": "^1.0.0", "@types/lodash": "4.14.104", "@types/mocha": "^2.2.42", "@types/node": "^8.0.53", diff --git a/packages/subproviders/src/subproviders/base_wallet_subprovider.ts b/packages/subproviders/src/subproviders/base_wallet_subprovider.ts index a04be68e1..c4b344e3b 100644 --- a/packages/subproviders/src/subproviders/base_wallet_subprovider.ts +++ b/packages/subproviders/src/subproviders/base_wallet_subprovider.ts @@ -1,6 +1,6 @@ import { assert } from '@0xproject/assert'; -import { JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types'; import { addressUtils } from '@0xproject/utils'; +import { JSONRPCRequestPayload, JSONRPCResponsePayload } from 'ethereum-types'; import * as _ from 'lodash'; import { Callback, ErrorCallback, PartialTxParams, ResponseWithTxParams, WalletSubproviderErrors } from '../types'; diff --git a/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts index bd7a4b6d9..4268c67bd 100644 --- a/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts +++ b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts @@ -1,4 +1,4 @@ -import { JSONRPCRequestPayload } from '@0xproject/types'; +import { JSONRPCRequestPayload } from 'ethereum-types'; import { Callback, ErrorCallback } from '../types'; diff --git a/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts index 6c49f20cf..d750505e7 100644 --- a/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts +++ b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts @@ -1,4 +1,4 @@ -import { JSONRPCRequestPayload } from '@0xproject/types'; +import { JSONRPCRequestPayload } from 'ethereum-types'; import { Callback, ErrorCallback } from '../types'; diff --git a/packages/subproviders/src/subproviders/ganache.ts b/packages/subproviders/src/subproviders/ganache.ts index 9ab764048..73d0513cc 100644 --- a/packages/subproviders/src/subproviders/ganache.ts +++ b/packages/subproviders/src/subproviders/ganache.ts @@ -1,4 +1,4 @@ -import { JSONRPCRequestPayload, Provider } from '@0xproject/types'; +import { JSONRPCRequestPayload, Provider } from 'ethereum-types'; import * as Ganache from 'ganache-core'; import { Callback, ErrorCallback } from '../types'; diff --git a/packages/subproviders/src/subproviders/injected_web3.ts b/packages/subproviders/src/subproviders/injected_web3.ts index 73b870cd5..165c66d62 100644 --- a/packages/subproviders/src/subproviders/injected_web3.ts +++ b/packages/subproviders/src/subproviders/injected_web3.ts @@ -1,4 +1,4 @@ -import { JSONRPCRequestPayload, Provider } from '@0xproject/types'; +import { JSONRPCRequestPayload, Provider } from 'ethereum-types'; import * as _ from 'lodash'; import * as Web3 from 'web3'; diff --git a/packages/subproviders/src/subproviders/nonce_tracker.ts b/packages/subproviders/src/subproviders/nonce_tracker.ts index 345e5e975..98773e79c 100644 --- a/packages/subproviders/src/subproviders/nonce_tracker.ts +++ b/packages/subproviders/src/subproviders/nonce_tracker.ts @@ -1,6 +1,6 @@ import * as _ from 'lodash'; -import { BlockParamLiteral, JSONRPCRequestPayload } from '@0xproject/types'; +import { BlockParamLiteral, JSONRPCRequestPayload } from 'ethereum-types'; import EthereumTx = require('ethereumjs-tx'); import ethUtil = require('ethereumjs-util'); import providerEngineUtils = require('web3-provider-engine/util/rpc-cache-utils'); diff --git a/packages/subproviders/src/subproviders/redundant_subprovider.ts b/packages/subproviders/src/subproviders/redundant_subprovider.ts index 37c8bba5a..a60d6706e 100644 --- a/packages/subproviders/src/subproviders/redundant_subprovider.ts +++ b/packages/subproviders/src/subproviders/redundant_subprovider.ts @@ -1,5 +1,5 @@ -import { JSONRPCRequestPayload } from '@0xproject/types'; import { promisify } from '@0xproject/utils'; +import { JSONRPCRequestPayload } from 'ethereum-types'; import * as _ from 'lodash'; import { Callback } from '../types'; diff --git a/packages/subproviders/src/subproviders/subprovider.ts b/packages/subproviders/src/subproviders/subprovider.ts index cb6dffc4a..f9491707e 100644 --- a/packages/subproviders/src/subproviders/subprovider.ts +++ b/packages/subproviders/src/subproviders/subprovider.ts @@ -1,5 +1,5 @@ -import { JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types'; import { promisify } from '@0xproject/utils'; +import { JSONRPCRequestPayload, JSONRPCResponsePayload } from 'ethereum-types'; import * as Web3 from 'web3'; import { Callback, ErrorCallback, JSONRPCRequestPayloadWithMethod } from '../types'; diff --git a/packages/subproviders/src/types.ts b/packages/subproviders/src/types.ts index 30a3b4a4e..7a8413305 100644 --- a/packages/subproviders/src/types.ts +++ b/packages/subproviders/src/types.ts @@ -1,4 +1,5 @@ -import { ECSignature, JSONRPCRequestPayload } from '@0xproject/types'; +import { ECSignature } from '@0xproject/types'; +import { JSONRPCRequestPayload } from 'ethereum-types'; import HDNode = require('hdkey'); import * as _ from 'lodash'; diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts index d3e9d0fde..315dfa894 100644 --- a/packages/subproviders/test/integration/ledger_subprovider_test.ts +++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts @@ -1,10 +1,11 @@ -import { DoneCallback, JSONRPCResponsePayload } from '@0xproject/types'; +import { DoneCallback } from '@0xproject/types'; import { promisify } from '@0xproject/utils'; import Eth from '@ledgerhq/hw-app-eth'; // HACK: This dependency is optional and tslint skips optional dependencies // tslint:disable-next-line:no-implicit-dependencies import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; import * as chai from 'chai'; +import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; import * as _ from 'lodash'; import 'make-promises-safe'; diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts index 8571f7d11..17e72a694 100644 --- a/packages/subproviders/test/unit/ledger_subprovider_test.ts +++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts @@ -1,5 +1,5 @@ -import { JSONRPCResponsePayload } from '@0xproject/types'; import * as chai from 'chai'; +import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; import * as _ from 'lodash'; import 'make-promises-safe'; diff --git a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts index 90565181e..fba221af0 100644 --- a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts +++ b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts @@ -1,5 +1,5 @@ -import { JSONRPCResponsePayload } from '@0xproject/types'; import * as chai from 'chai'; +import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; import * as _ from 'lodash'; import 'make-promises-safe'; diff --git a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts index 864f977ea..ac88d8cac 100644 --- a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts +++ b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts @@ -1,5 +1,5 @@ -import { JSONRPCResponsePayload } from '@0xproject/types'; import * as chai from 'chai'; +import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; import * as _ from 'lodash'; import 'make-promises-safe'; diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts index fdbbb332c..fcfec1367 100644 --- a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts +++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts @@ -1,5 +1,6 @@ -import { DoneCallback, JSONRPCResponsePayload } from '@0xproject/types'; +import { DoneCallback } from '@0xproject/types'; import * as chai from 'chai'; +import { JSONRPCResponsePayload } from 'ethereum-types'; import * as _ from 'lodash'; import 'make-promises-safe'; import Web3 = require('web3'); diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index c565d5b7d..06f8d3e84 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -20,7 +20,6 @@ "dependencies": { "0x.js": "^0.38.0", "@0xproject/subproviders": "^0.10.2", - "@0xproject/types": "^0.7.0", "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", "body-parser": "^1.17.1", @@ -37,6 +36,7 @@ "@types/body-parser": "^1.16.1", "@types/express": "^4.0.35", "@types/lodash": "4.14.104", + "ethereum-types": "^0.0.1", "awesome-typescript-loader": "^3.1.3", "gulp": "^3.9.1", "make-promises-safe": "^1.1.0", diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index d5f0dc2f9..3a105742e 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -1,6 +1,6 @@ import { Order, SignedOrder, ZeroEx } from '0x.js'; -import { Provider } from '@0xproject/types'; import { BigNumber, logUtils } from '@0xproject/utils'; +import { Provider } from 'ethereum-types'; import * as express from 'express'; import * as _ from 'lodash'; import * as Web3 from 'web3'; diff --git a/packages/types/package.json b/packages/types/package.json index e70546bd3..95b7721d3 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -34,7 +34,8 @@ }, "dependencies": { "@types/node": "^8.0.53", - "bignumber.js": "~4.1.0" + "bignumber.js": "~4.1.0", + "ethereum-types": "^0.0.1" }, "publishConfig": { "access": "public" diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index b1d6f97cb..8bd6e097e 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,285 +1,5 @@ import { BigNumber } from 'bignumber.js'; - -export type JSONRPCErrorCallback = (err: Error | null, result?: JSONRPCResponsePayload) => void; - -/** - * Do not create your own provider. Use an existing provider from a Web3 or ProviderEngine library - * Read more about Providers in the 0x wiki. - */ -export interface Provider { - sendAsync(payload: JSONRPCRequestPayload, callback: JSONRPCErrorCallback): void; -} - -export type ContractAbi = AbiDefinition[]; - -export type AbiDefinition = FunctionAbi | EventAbi; - -export type FunctionAbi = MethodAbi | ConstructorAbi | FallbackAbi; - -export type ConstructorStateMutability = 'nonpayable' | 'payable'; -export type StateMutability = 'pure' | 'view' | ConstructorStateMutability; - -export interface MethodAbi { - type: AbiType.Function; - name: string; - inputs: DataItem[]; - outputs: DataItem[]; - constant: boolean; - stateMutability: StateMutability; - payable: boolean; -} - -export interface ConstructorAbi { - type: AbiType.Constructor; - inputs: DataItem[]; - payable: boolean; - stateMutability: ConstructorStateMutability; -} - -export interface FallbackAbi { - type: AbiType.Fallback; - payable: boolean; -} - -export interface EventParameter extends DataItem { - indexed: boolean; -} - -export interface EventAbi { - type: AbiType.Event; - name: string; - inputs: EventParameter[]; - anonymous: boolean; -} - -export interface DataItem { - name: string; - type: string; - components?: DataItem[]; -} - -export enum OpCode { - DelegateCall = 'DELEGATECALL', - Revert = 'REVERT', - Create = 'CREATE', - Stop = 'STOP', - Invalid = 'INVALID', - CallCode = 'CALLCODE', - StaticCall = 'STATICCALL', - Return = 'RETURN', - Call = 'CALL', - SelfDestruct = 'SELFDESTRUCT', -} - -export interface StructLog { - depth: number; - error: string; - gas: number; - gasCost: number; - memory: string[]; - op: OpCode; - pc: number; - stack: string[]; - storage: { [location: string]: string }; -} - -export interface TransactionTrace { - gas: number; - returnValue: any; - structLogs: StructLog[]; -} - -export type Unit = - | 'kwei' - | 'ada' - | 'mwei' - | 'babbage' - | 'gwei' - | 'shannon' - | 'szabo' - | 'finney' - | 'ether' - | 'kether' - | 'grand' - | 'einstein' - | 'mether' - | 'gether' - | 'tether'; - -export interface JSONRPCRequestPayload { - params: any[]; - method: string; - id: number; - jsonrpc: string; -} - -export interface JSONRPCResponsePayload { - result: any; - id: number; - jsonrpc: string; -} - -export 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; - totalDifficulty: BigNumber; - extraData: string; - size: number; - gasLimit: number; - gasUsed: number; - timestamp: number; - uncles: string[]; -} - -export interface BlockWithoutTransactionData extends AbstractBlock { - transactions: string[]; -} - -export interface BlockWithTransactionData extends AbstractBlock { - transactions: Transaction[]; -} - -export interface Transaction { - hash: string; - nonce: number; - blockHash: string | null; - blockNumber: number | null; - transactionIndex: number | null; - from: string; - to: string | null; - value: BigNumber; - gasPrice: BigNumber; - gas: number; - input: string; -} - -export interface CallTxDataBase { - to?: string; - value?: number | string | BigNumber; - gas?: number | string | BigNumber; - gasPrice?: number | string | BigNumber; - data?: string; - nonce?: number; -} - -export interface TxData extends CallTxDataBase { - from: string; -} - -export interface CallData extends CallTxDataBase { - from?: string; -} - -export interface FilterObject { - fromBlock?: number | string; - toBlock?: number | string; - address?: string; - topics?: LogTopic[]; -} - -export type LogTopic = null | string | string[]; - -export interface DecodedLogEntry<A> extends LogEntry { - event: string; - args: A; -} - -export interface DecodedLogEntryEvent<A> extends DecodedLogEntry<A> { - removed: boolean; -} - -export interface LogEntryEvent extends LogEntry { - removed: boolean; -} - -export interface LogEntry { - logIndex: number | null; - transactionIndex: number | null; - transactionHash: string; - blockHash: string | null; - blockNumber: number | null; - address: string; - data: string; - topics: string[]; -} - -export interface TxDataPayable extends TxData { - value?: BigNumber; -} - -export 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[]; -} - -export enum AbiType { - Function = 'function', - Constructor = 'constructor', - Event = 'event', - Fallback = 'fallback', -} - -export type ContractEventArg = string | BigNumber | number; - -export interface DecodedLogArgs { - [argName: string]: ContractEventArg; -} - -export interface LogWithDecodedArgs<ArgsType> extends DecodedLogEntry<ArgsType> {} -export type RawLog = LogEntry; -export enum SolidityTypes { - Address = 'address', - Uint256 = 'uint256', - Uint8 = 'uint8', - Uint = 'uint', -} - -/** - * Contains the logs returned by a TransactionReceipt. We attempt to decode the - * logs using AbiDecoder. If we have the logs corresponding ABI, we decode it, - * otherwise we don't. - */ -export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt { - logs: Array<LogWithDecodedArgs<DecodedLogArgs> | LogEntry>; -} - -// Earliest is omitted by design. It is simply an alias for the `0` constant and -// is thus not very helpful. Moreover, this type is used in places that only accept -// `latest` or `pending`. -export enum BlockParamLiteral { - Latest = 'latest', - Pending = 'pending', -} - -export type BlockParam = BlockParamLiteral | number; - -export interface RawLogEntry { - logIndex: string | null; - transactionIndex: string | null; - transactionHash: string; - blockHash: string | null; - blockNumber: string | null; - address: string; - data: string; - topics: string[]; -} +import { ContractAbi, DecodedLogArgs, LogEntry, LogWithDecodedArgs, TransactionReceipt } from 'ethereum-types'; export interface Order { senderAddress: string; diff --git a/packages/typescript-typings/CHANGELOG.json b/packages/typescript-typings/CHANGELOG.json index 86b4a5078..555da22d1 100644 --- a/packages/typescript-typings/CHANGELOG.json +++ b/packages/typescript-typings/CHANGELOG.json @@ -1,17 +1,17 @@ [ { - "version": "0.5.0", - "changes": [ - { - "note": "Add types for `react-popper`, remove types for `react-joyride`" - } - ] - }, - { "version": "0.4.0", "changes": [ { "note": "Add types for `react-joyride`" + }, + { + "note": "Add types for `react-popper`, remove types for `react-joyride`" + }, + { + "note": + "Remove types for blockies, bn.js, compare-versions, ethereumjs-abi, ethereumjs-tx, find-versions, hdkey, is-mobile, solidity-parser-antlr, xml-js as they were moved to DefinitelyTyped", + "pr": 641 } ] }, diff --git a/packages/typescript-typings/package.json b/packages/typescript-typings/package.json index 932f89ec5..4bae1f437 100644 --- a/packages/typescript-typings/package.json +++ b/packages/typescript-typings/package.json @@ -25,13 +25,12 @@ }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/typescript-typings#readme", "dependencies": { - "@0xproject/types": "^0.7.0", + "ethereum-types": "^0.0.1", "bignumber.js": "~4.1.0" }, "devDependencies": { "@0xproject/monorepo-scripts": "^0.1.20", "copyfiles": "^1.2.0", - "make-promises-safe": "^1.1.0", "shx": "^0.2.2" }, "publishConfig": { diff --git a/packages/typescript-typings/types/blockies/index.d.ts b/packages/typescript-typings/types/blockies/index.d.ts deleted file mode 100644 index d4068e50f..000000000 --- a/packages/typescript-typings/types/blockies/index.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -// blockies declarations -declare interface BlockiesIcon { - toDataURL(): string; -} -declare interface BlockiesConfig { - seed: string; -} -declare function blockies(config: BlockiesConfig): BlockiesIcon; -declare module 'blockies' { - export = blockies; -} diff --git a/packages/typescript-typings/types/bn.js/index.d.ts b/packages/typescript-typings/types/bn.js/index.d.ts deleted file mode 100644 index f59b74bad..000000000 --- a/packages/typescript-typings/types/bn.js/index.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -declare module 'bn.js' { - import { Buffer } from 'buffer'; - - type Endianness = 'le' | 'be'; - - class BN { - constructor(num: number | string | number[] | Buffer, base?: number, endian?: Endianness); - public clone(): BN; - public toString(base?: number, length?: number): string; - public toNumber(): number; - public toJSON(): string; - public toArray(endian?: Endianness, length?: number): number[]; - public toBuffer(endian?: Endianness, length?: number): Buffer; - public bitLength(): number; - public zeroBits(): number; - public byteLength(): number; - public isNeg(): boolean; - public isEven(): boolean; - public isOdd(): boolean; - public isZero(): boolean; - public cmp(b: any): number; - public lt(b: any): boolean; - public lte(b: any): boolean; - public gt(b: any): boolean; - public gte(b: any): boolean; - public eq(b: any): boolean; - public isBN(b: any): boolean; - - public neg(): BN; - public abs(): BN; - public add(b: BN): BN; - public sub(b: BN): BN; - public mul(b: BN): BN; - public sqr(): BN; - public pow(b: BN): BN; - public div(b: BN): BN; - public mod(b: BN): BN; - public divRound(b: BN): BN; - - public or(b: BN): BN; - public and(b: BN): BN; - public xor(b: BN): BN; - public setn(b: number): BN; - public shln(b: number): BN; - public shrn(b: number): BN; - public testn(b: number): boolean; - public maskn(b: number): BN; - public bincn(b: number): BN; - public notn(w: number): BN; - - public gcd(b: BN): BN; - public egcd(b: BN): { a: BN; b: BN; gcd: BN }; - public invm(b: BN): BN; - } - - export = BN; -} diff --git a/packages/typescript-typings/types/compare-versions/index.d.ts b/packages/typescript-typings/types/compare-versions/index.d.ts deleted file mode 100644 index b19e1f94b..000000000 --- a/packages/typescript-typings/types/compare-versions/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -// compare-version declarations -declare function compareVersions(firstVersion: string, secondVersion: string): number; -declare module 'compare-versions' { - export = compareVersions; -} diff --git a/packages/typescript-typings/types/ethereumjs-abi/index.d.ts b/packages/typescript-typings/types/ethereumjs-abi/index.d.ts deleted file mode 100644 index e3d660a4a..000000000 --- a/packages/typescript-typings/types/ethereumjs-abi/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare module 'ethereumjs-abi' { - const soliditySHA3: (argTypes: string[], args: any[]) => Buffer; - const soliditySHA256: (argTypes: string[], args: any[]) => Buffer; - const methodID: (name: string, types: string[]) => Buffer; -} diff --git a/packages/typescript-typings/types/ethereumjs-tx/index.d.ts b/packages/typescript-typings/types/ethereumjs-tx/index.d.ts deleted file mode 100644 index 1b99d06d9..000000000 --- a/packages/typescript-typings/types/ethereumjs-tx/index.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -declare module 'ethereumjs-tx' { - class EthereumTx { - public raw: Buffer[]; - public r: Buffer; - public s: Buffer; - public v: Buffer; - public nonce: Buffer; - public serialize(): Buffer; - public sign(buffer: Buffer): void; - public getSenderAddress(): Buffer; - constructor(txParams: any); - } - export = EthereumTx; -} diff --git a/packages/typescript-typings/types/ethers/index.d.ts b/packages/typescript-typings/types/ethers/index.d.ts index addf85613..d40428a9b 100644 --- a/packages/typescript-typings/types/ethers/index.d.ts +++ b/packages/typescript-typings/types/ethers/index.d.ts @@ -1,5 +1,5 @@ declare module 'ethers' { - import { TxData } from '@0xproject/types'; + import { TxData } from 'ethereum-types'; export interface TransactionDescription { name: string; diff --git a/packages/typescript-typings/types/find-versions/index.d.ts b/packages/typescript-typings/types/find-versions/index.d.ts deleted file mode 100644 index e7c1c6461..000000000 --- a/packages/typescript-typings/types/find-versions/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare function findVersions(version: string): string[]; -declare module 'find-versions' { - export = findVersions; -} diff --git a/packages/typescript-typings/types/ganache-core/index.d.ts b/packages/typescript-typings/types/ganache-core/index.d.ts index feeb5721e..84635038f 100644 --- a/packages/typescript-typings/types/ganache-core/index.d.ts +++ b/packages/typescript-typings/types/ganache-core/index.d.ts @@ -1,5 +1,5 @@ declare module 'ganache-core' { - import { Provider } from '@0xproject/types'; + import { Provider } from 'ethereum-types'; export interface GanacheOpts { verbose?: boolean; logger?: { diff --git a/packages/typescript-typings/types/hdkey/index.d.ts b/packages/typescript-typings/types/hdkey/index.d.ts deleted file mode 100644 index 84b751bd7..000000000 --- a/packages/typescript-typings/types/hdkey/index.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -declare module 'hdkey' { - class HDNode { - public static fromMasterSeed(seed: Buffer): HDNode; - public publicKey: Buffer; - public privateKey: Buffer; - public chainCode: Buffer; - public constructor(); - public derive(path: string): HDNode; - } - export = HDNode; -} diff --git a/packages/typescript-typings/types/is-mobile/index.d.ts b/packages/typescript-typings/types/is-mobile/index.d.ts deleted file mode 100644 index 0b3b57854..000000000 --- a/packages/typescript-typings/types/is-mobile/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare function isMobile(): boolean; -declare module 'is-mobile' { - export = isMobile; -} diff --git a/packages/typescript-typings/types/solc/index.d.ts b/packages/typescript-typings/types/solc/index.d.ts index 5a87ac267..571bae101 100644 --- a/packages/typescript-typings/types/solc/index.d.ts +++ b/packages/typescript-typings/types/solc/index.d.ts @@ -114,7 +114,7 @@ declare module 'solc' { message: string; formattedMessage?: string; } - import { ContractAbi } from '@0xproject/types'; + import { ContractAbi } from 'ethereum-types'; export interface StandardContractOutput { abi: ContractAbi; evm: { diff --git a/packages/typescript-typings/types/solidity-parser-antlr/index.d.ts b/packages/typescript-typings/types/solidity-parser-antlr/index.d.ts deleted file mode 100644 index cc1246a0e..000000000 --- a/packages/typescript-typings/types/solidity-parser-antlr/index.d.ts +++ /dev/null @@ -1,314 +0,0 @@ -declare module 'solidity-parser-antlr' { - export interface BaseASTNode { - range: [number, number]; - } - export interface SourceUnit extends BaseASTNode {} - export interface PragmaDirective extends BaseASTNode {} - export interface PragmaName extends BaseASTNode {} - export interface PragmaValue extends BaseASTNode {} - export interface Version extends BaseASTNode {} - export interface VersionOperator extends BaseASTNode {} - export interface VersionConstraint extends BaseASTNode {} - export interface ImportDeclaration extends BaseASTNode {} - export interface ImportDirective extends BaseASTNode {} - export interface ContractDefinition extends BaseASTNode {} - export interface InheritanceSpecifier extends BaseASTNode {} - export interface ContractPart extends BaseASTNode {} - export interface StateVariableDeclaration extends BaseASTNode { - variables: VariableDeclaration[]; - } - export interface UsingForDeclaration extends BaseASTNode {} - export interface StructDefinition extends BaseASTNode {} - export interface ModifierDefinition extends BaseASTNode { - name: string; - } - export interface ModifierInvocation extends BaseASTNode { - name: string; - } - export interface FunctionDefinition extends BaseASTNode { - name: string; - } - export interface ReturnParameters extends BaseASTNode {} - export interface ModifierList extends BaseASTNode {} - export interface EventDefinition extends BaseASTNode {} - export interface EnumValue extends BaseASTNode {} - export interface EnumDefinition extends BaseASTNode {} - export interface ParameterList extends BaseASTNode {} - export interface Parameter extends BaseASTNode {} - export interface EventParameterList extends BaseASTNode {} - export interface EventParameter extends BaseASTNode {} - export interface FunctionTypeParameterList extends BaseASTNode {} - export interface FunctionTypeParameter extends BaseASTNode {} - export interface VariableDeclaration extends BaseASTNode { - visibility: 'public' | 'private'; - isStateVar: boolean; - } - export interface TypeName extends BaseASTNode {} - export interface UserDefinedTypeName extends BaseASTNode {} - export interface Mapping extends BaseASTNode {} - export interface FunctionTypeName extends BaseASTNode {} - export interface StorageLocation extends BaseASTNode {} - export interface StateMutability extends BaseASTNode {} - export interface Block extends BaseASTNode {} - export interface Statement extends BaseASTNode {} - export interface ExpressionStatement extends BaseASTNode { - expression: ASTNode; - } - export interface IfStatement extends BaseASTNode { - trueBody: ASTNode; - falseBody: ASTNode; - } - export interface WhileStatement extends BaseASTNode {} - export interface SimpleStatement extends BaseASTNode {} - export interface ForStatement extends BaseASTNode {} - export interface InlineAssemblyStatement extends BaseASTNode {} - export interface DoWhileStatement extends BaseASTNode {} - export interface ContinueStatement extends BaseASTNode {} - export interface BreakStatement extends BaseASTNode {} - export interface ReturnStatement extends BaseASTNode {} - export interface ThrowStatement extends BaseASTNode {} - export interface VariableDeclarationStatement extends BaseASTNode {} - export interface IdentifierList extends BaseASTNode {} - export interface ElementaryTypeName extends BaseASTNode {} - export interface Expression extends BaseASTNode {} - export interface PrimaryExpression extends BaseASTNode {} - export interface ExpressionList extends BaseASTNode {} - export interface NameValueList extends BaseASTNode {} - export interface NameValue extends BaseASTNode {} - export interface FunctionCallArguments extends BaseASTNode {} - export interface AssemblyBlock extends BaseASTNode {} - export interface AssemblyItem extends BaseASTNode {} - export interface AssemblyExpression extends BaseASTNode {} - export interface AssemblyCall extends BaseASTNode {} - export interface AssemblyLocalDefinition extends BaseASTNode {} - export interface AssemblyAssignment extends BaseASTNode {} - export interface AssemblyIdentifierOrList extends BaseASTNode {} - export interface AssemblyIdentifierList extends BaseASTNode {} - export interface AssemblyStackAssignment extends BaseASTNode {} - export interface LabelDefinition extends BaseASTNode {} - export interface AssemblySwitch extends BaseASTNode {} - export interface AssemblyCase extends BaseASTNode {} - export interface AssemblyFunctionDefinition extends BaseASTNode {} - export interface AssemblyFunctionReturns extends BaseASTNode {} - export interface AssemblyFor extends BaseASTNode {} - export interface AssemblyIf extends BaseASTNode {} - export interface AssemblyLiteral extends BaseASTNode {} - export interface SubAssembly extends BaseASTNode {} - export interface TupleExpression extends BaseASTNode {} - export interface ElementaryTypeNameExpression extends BaseASTNode {} - export interface NumberLiteral extends BaseASTNode {} - export interface Identifier extends BaseASTNode {} - export type BinOp = - | '+' - | '-' - | '*' - | '/' - | '**' - | '%' - | '<<' - | '>>' - | '&&' - | '||' - | '&' - | '|' - | '^' - | '<' - | '>' - | '<=' - | '>=' - | '==' - | '!=' - | '=' - | '|=' - | '^=' - | '&=' - | '<<=' - | '>>=' - | '+=' - | '-=' - | '*=' - | '/=' - | '%='; - export interface BinaryOperation extends BaseASTNode { - left: ASTNode; - right: ASTNode; - operator: BinOp; - } - export interface Conditional extends BaseASTNode { - trueExpression: ASTNode; - falseExpression: ASTNode; - } - - export type ASTNode = - | SourceUnit - | PragmaDirective - | PragmaName - | PragmaValue - | Version - | VersionOperator - | VersionConstraint - | ImportDeclaration - | ImportDirective - | ContractDefinition - | InheritanceSpecifier - | ContractPart - | StateVariableDeclaration - | UsingForDeclaration - | StructDefinition - | ModifierDefinition - | ModifierInvocation - | FunctionDefinition - | ReturnParameters - | ModifierList - | EventDefinition - | EnumValue - | EnumDefinition - | ParameterList - | Parameter - | EventParameterList - | EventParameter - | FunctionTypeParameterList - | FunctionTypeParameter - | VariableDeclaration - | TypeName - | UserDefinedTypeName - | Mapping - | FunctionTypeName - | StorageLocation - | StateMutability - | Block - | Statement - | ExpressionStatement - | IfStatement - | WhileStatement - | SimpleStatement - | ForStatement - | InlineAssemblyStatement - | DoWhileStatement - | ContinueStatement - | BreakStatement - | ReturnStatement - | ThrowStatement - | VariableDeclarationStatement - | IdentifierList - | ElementaryTypeName - | Expression - | PrimaryExpression - | ExpressionList - | NameValueList - | NameValue - | FunctionCallArguments - | AssemblyBlock - | AssemblyItem - | AssemblyExpression - | AssemblyCall - | AssemblyLocalDefinition - | AssemblyAssignment - | AssemblyIdentifierOrList - | AssemblyIdentifierList - | AssemblyStackAssignment - | LabelDefinition - | AssemblySwitch - | AssemblyCase - | AssemblyFunctionDefinition - | AssemblyFunctionReturns - | AssemblyFor - | AssemblyIf - | AssemblyLiteral - | SubAssembly - | TupleExpression - | ElementaryTypeNameExpression - | NumberLiteral - | Identifier - | BinaryOperation - | Conditional; - export interface Visitor { - SourceUnit?: (node: SourceUnit) => void; - PragmaDirective?: (node: PragmaDirective) => void; - PragmaName?: (node: PragmaName) => void; - PragmaValue?: (node: PragmaValue) => void; - Version?: (node: Version) => void; - VersionOperator?: (node: VersionOperator) => void; - VersionConstraint?: (node: VersionConstraint) => void; - ImportDeclaration?: (node: ImportDeclaration) => void; - ImportDirective?: (node: ImportDirective) => void; - ContractDefinition?: (node: ContractDefinition) => void; - InheritanceSpecifier?: (node: InheritanceSpecifier) => void; - ContractPart?: (node: ContractPart) => void; - StateVariableDeclaration?: (node: StateVariableDeclaration) => void; - UsingForDeclaration?: (node: UsingForDeclaration) => void; - StructDefinition?: (node: StructDefinition) => void; - ModifierDefinition?: (node: ModifierDefinition) => void; - ModifierInvocation?: (node: ModifierInvocation) => void; - FunctionDefinition?: (node: FunctionDefinition) => void; - ReturnParameters?: (node: ReturnParameters) => void; - ModifierList?: (node: ModifierList) => void; - EventDefinition?: (node: EventDefinition) => void; - EnumValue?: (node: EnumValue) => void; - EnumDefinition?: (node: EnumDefinition) => void; - ParameterList?: (node: ParameterList) => void; - Parameter?: (node: Parameter) => void; - EventParameterList?: (node: EventParameterList) => void; - EventParameter?: (node: EventParameter) => void; - FunctionTypeParameterList?: (node: FunctionTypeParameterList) => void; - FunctionTypeParameter?: (node: FunctionTypeParameter) => void; - VariableDeclaration?: (node: VariableDeclaration) => void; - TypeName?: (node: TypeName) => void; - UserDefinedTypeName?: (node: UserDefinedTypeName) => void; - Mapping?: (node: Mapping) => void; - FunctionTypeName?: (node: FunctionTypeName) => void; - StorageLocation?: (node: StorageLocation) => void; - StateMutability?: (node: StateMutability) => void; - Block?: (node: Block) => void; - Statement?: (node: Statement) => void; - ExpressionStatement?: (node: ExpressionStatement) => void; - IfStatement?: (node: IfStatement) => void; - WhileStatement?: (node: WhileStatement) => void; - SimpleStatement?: (node: SimpleStatement) => void; - ForStatement?: (node: ForStatement) => void; - InlineAssemblyStatement?: (node: InlineAssemblyStatement) => void; - DoWhileStatement?: (node: DoWhileStatement) => void; - ContinueStatement?: (node: ContinueStatement) => void; - BreakStatement?: (node: BreakStatement) => void; - ReturnStatement?: (node: ReturnStatement) => void; - ThrowStatement?: (node: ThrowStatement) => void; - VariableDeclarationStatement?: (node: VariableDeclarationStatement) => void; - IdentifierList?: (node: IdentifierList) => void; - ElementaryTypeName?: (node: ElementaryTypeName) => void; - Expression?: (node: Expression) => void; - PrimaryExpression?: (node: PrimaryExpression) => void; - ExpressionList?: (node: ExpressionList) => void; - NameValueList?: (node: NameValueList) => void; - NameValue?: (node: NameValue) => void; - FunctionCallArguments?: (node: FunctionCallArguments) => void; - AssemblyBlock?: (node: AssemblyBlock) => void; - AssemblyItem?: (node: AssemblyItem) => void; - AssemblyExpression?: (node: AssemblyExpression) => void; - AssemblyCall?: (node: AssemblyCall) => void; - AssemblyLocalDefinition?: (node: AssemblyLocalDefinition) => void; - AssemblyAssignment?: (node: AssemblyAssignment) => void; - AssemblyIdentifierOrList?: (node: AssemblyIdentifierOrList) => void; - AssemblyIdentifierList?: (node: AssemblyIdentifierList) => void; - AssemblyStackAssignment?: (node: AssemblyStackAssignment) => void; - LabelDefinition?: (node: LabelDefinition) => void; - AssemblySwitch?: (node: AssemblySwitch) => void; - AssemblyCase?: (node: AssemblyCase) => void; - AssemblyFunctionDefinition?: (node: AssemblyFunctionDefinition) => void; - AssemblyFunctionReturns?: (node: AssemblyFunctionReturns) => void; - AssemblyFor?: (node: AssemblyFor) => void; - AssemblyIf?: (node: AssemblyIf) => void; - AssemblyLiteral?: (node: AssemblyLiteral) => void; - SubAssembly?: (node: SubAssembly) => void; - TupleExpression?: (node: TupleExpression) => void; - ElementaryTypeNameExpression?: (node: ElementaryTypeNameExpression) => void; - NumberLiteral?: (node: NumberLiteral) => void; - Identifier?: (node: Identifier) => void; - BinaryOperation?: (node: BinaryOperation) => void; - Conditional?: (node: Conditional) => void; - } - export interface ParserOpts { - range?: boolean; - } - export function parse(sourceCode: string, parserOpts: ParserOpts): ASTNode; - export function visit(ast: ASTNode, visitor: Visitor): void; -} diff --git a/packages/typescript-typings/types/truffle-hdwalet-provider/index.d.ts b/packages/typescript-typings/types/truffle-hdwalet-provider/index.d.ts index af82557cb..007df61e0 100644 --- a/packages/typescript-typings/types/truffle-hdwalet-provider/index.d.ts +++ b/packages/typescript-typings/types/truffle-hdwalet-provider/index.d.ts @@ -1,5 +1,5 @@ declare module 'truffle-hdwallet-provider' { - import { JSONRPCRequestPayload, JSONRPCResponsePayload, Provider } from '@0xproject/types'; + import { JSONRPCRequestPayload, JSONRPCResponsePayload, Provider } from 'ethereum-types'; class HDWalletProvider implements Provider { constructor(mnemonic: string, rpcUrl: string); public sendAsync( diff --git a/packages/typescript-typings/types/web3-provider-engine/index.d.ts b/packages/typescript-typings/types/web3-provider-engine/index.d.ts index 8d5aef749..1733f2731 100644 --- a/packages/typescript-typings/types/web3-provider-engine/index.d.ts +++ b/packages/typescript-typings/types/web3-provider-engine/index.d.ts @@ -1,5 +1,5 @@ declare module 'web3-provider-engine' { - import { Provider, JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types'; + import { Provider, JSONRPCRequestPayload, JSONRPCResponsePayload } from 'ethereum-types'; class Web3ProviderEngine implements Provider { public on(event: string, handler: () => void): void; public send(payload: JSONRPCRequestPayload): void; @@ -23,7 +23,7 @@ declare module 'web3-provider-engine/subproviders/subprovider' { export = Subprovider; } declare module 'web3-provider-engine/subproviders/rpc' { - import { JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types'; + import { JSONRPCRequestPayload, JSONRPCResponsePayload } from 'ethereum-types'; class RpcSubprovider { constructor(options: { rpcUrl: string }); public handleRequest( @@ -41,7 +41,7 @@ declare module 'web3-provider-engine/util/rpc-cache-utils' { export = ProviderEngineRpcUtils; } declare module 'web3-provider-engine/subproviders/fixture' { - import { JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types'; + import { JSONRPCRequestPayload, JSONRPCResponsePayload } from 'ethereum-types'; class FixtureSubprovider { constructor(staticResponses: any); public handleRequest( diff --git a/packages/typescript-typings/types/web3/index.d.ts b/packages/typescript-typings/types/web3/index.d.ts index 15e7575a8..4085c71a7 100644 --- a/packages/typescript-typings/types/web3/index.d.ts +++ b/packages/typescript-typings/types/web3/index.d.ts @@ -16,7 +16,7 @@ declare module 'web3' { LogEntryEvent, JSONRPCRequestPayload, JSONRPCResponsePayload, - } from '@0xproject/types'; + } from 'ethereum-types'; type MixedData = string | number | object | any[] | BigNumber.BigNumber; diff --git a/packages/typescript-typings/types/xml-js/index.d.ts b/packages/typescript-typings/types/xml-js/index.d.ts deleted file mode 100644 index 8e4873aeb..000000000 --- a/packages/typescript-typings/types/xml-js/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare interface XML2JSONOpts { - compact?: boolean; - spaces?: number; -} -declare module 'xml-js' { - const xml2json: (xml: string, opts: XML2JSONOpts) => string; -} diff --git a/packages/utils/package.json b/packages/utils/package.json index 24551dd93..89daadbec 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -35,7 +35,7 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/types": "^0.7.0", + "ethereum-types": "^0.0.1", "@0xproject/typescript-typings": "^0.3.2", "@types/node": "^8.0.53", "ethereumjs-util": "^5.1.1", diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index d2d8364ca..ed3297ee1 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -8,7 +8,7 @@ import { LogWithDecodedArgs, RawLog, SolidityTypes, -} from '@0xproject/types'; +} from 'ethereum-types'; import * as ethers from 'ethers'; import * as _ from 'lodash'; @@ -22,7 +22,7 @@ export class AbiDecoder { _.forEach(abiArrays, this.addABI.bind(this)); } // This method can only decode logs from the 0x & ERC20 smart contracts - public tryToDecodeLogOrNoop<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog { + public tryToDecodeLogOrNoop<ArgsType extends DecodedLogArgs>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog { const methodId = log.topics[0]; const event = this._methodIds[methodId]; if (_.isUndefined(event)) { diff --git a/packages/utils/src/abi_utils.ts b/packages/utils/src/abi_utils.ts index c4533d42e..b5822425c 100644 --- a/packages/utils/src/abi_utils.ts +++ b/packages/utils/src/abi_utils.ts @@ -1,4 +1,4 @@ -import { AbiDefinition, AbiType, ConstructorAbi, ContractAbi, DataItem, MethodAbi } from '@0xproject/types'; +import { AbiDefinition, AbiType, ConstructorAbi, ContractAbi, DataItem, MethodAbi } from 'ethereum-types'; import * as _ from 'lodash'; export const abiUtils = { diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json index 18bbf14a0..9baaba391 100644 --- a/packages/web3-wrapper/package.json +++ b/packages/web3-wrapper/package.json @@ -26,7 +26,8 @@ "postpublish": { "docPublishConfigs": { "extraFileIncludes": [ - "../types/src/index.ts" + "../types/src/index.ts", + "../ethereum-types/src/index.ts" ], "s3BucketPath": "s3://doc-jsons/web3-wrapper/", "s3StagingBucketPath": "s3://staging-doc-jsons/web3-wrapper/" @@ -62,9 +63,9 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/types": "^0.7.0", "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", + "ethereum-types": "^0.0.1", "ethers": "^3.0.15", "lodash": "^4.17.4", "web3": "^0.20.0" diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 40a554522..3de152df1 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -1,3 +1,4 @@ +import { AbiDecoder, addressUtils, BigNumber, intervalUtils, promisify } from '@0xproject/utils'; import { BlockParam, BlockWithoutTransactionData, @@ -12,8 +13,7 @@ import { TransactionReceipt, TransactionReceiptWithDecodedLogs, TxData, -} from '@0xproject/types'; -import { AbiDecoder, addressUtils, BigNumber, intervalUtils, promisify } from '@0xproject/utils'; +} from 'ethereum-types'; import * as _ from 'lodash'; import * as Web3 from 'web3'; diff --git a/packages/website/md/docs/sol_cov/usage.md b/packages/website/md/docs/sol_cov/usage.md index 63a88f595..59638f611 100644 --- a/packages/website/md/docs/sol_cov/usage.md +++ b/packages/website/md/docs/sol_cov/usage.md @@ -2,8 +2,47 @@ Sol-cov uses transaction traces in order to figure out which lines of Solidity s The CoverageSubprovider eavesdrops on the `eth_sendTransaction` and `eth_call` RPC calls and collects traces after each call using `debug_traceTransaction`. `eth_call`'s' don't generate traces - so we take a snapshot, re-submit it as a transaction, get the trace and then revert the snapshot. +Coverage subprovider needs some info about your contracts (`srcMap`, `bytecode`). It gets that info from your project's artifacts. Some frameworks have their own artifact format. Some artifact formats don't actually contain all the neccessary data. + +In order to use `CoverageSubprovider` with your favorite framework you need to pass an `artifactsAdapter` to it. + +### Sol-compiler + +If you are generating your artifacts with [@0xproject/sol-compiler](LINK) you can use the `SolCompilerArtifactsAdapter` we've implemented for you. + +```typescript +<<<<<<< HEAD +import { CoverageSubprovider } from '@0xproject/sol-cov'; +======= +import { SolCompilerArtifactsAdapter } from '@0xproject/sol-cov'; +const artifactsPath = 'src/artifacts'; +const contractsPath = 'src/contracts'; +const artifactsAdapter = new SolCompilerArtifactsAdapter(artifactsPath, contractsPath); +``` + +### Truffle + +If your project is using [Truffle](LINK), we've written a `TruffleArtifactsAdapter`for you. + +```typescript +import { TruffleArtifactAdapter } from '@0xproject/sol-cov'; +const contractsPath = 'src/contracts'; +const artifactAdapter = new TruffleArtifactAdapter(contractsDir); +``` + +Because truffle artifacts don't have all the data we need - we actually will recompile your contracts under the hood. That's why you don't need to pass an `artifactsPath`. + +### Other framework/toolset + +You'll need to write your own artifacts adapter. It should extend `AbstractArtifactsAdapter`. +Look at the code of the two adapters above for examples. + +### Usage + ```typescript import { CoverageSubprovider } from '@0xproject/sol-cov'; +import ProviderEngine = require('web3-provider-engine'); +>>>>>>> Improve sol-cov docs const provider = new ProviderEngine(); @@ -12,15 +51,20 @@ const contractsPath = 'src/contracts'; const networkId = 50; // Some calls might not have `from` address specified. Nevertheless - transactions need to be submitted from an address with at least some funds. defaultFromAddress is the address that will be used to submit those calls as transactions from. const defaultFromAddress = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; +<<<<<<< HEAD const coverageSubprovider = new CoverageSubprovider(artifactsPath, contractsPath, defaultFromAddress); +======= +const isVerbose = true; +const coverageSubprovider = new CoverageSubprovider(artifactsAdapter, defaultFromAddress, isVerbose); +>>>>>>> Improve sol-cov docs provider.addProvider(coverageSubprovider); ``` -After your test suite is complete (e.g global `after` hook), you'll need to call: +After your test suite is complete (e.g in the Mocha global `after` hook), you'll need to call: ```typescript await coverageSubprovider.writeCoverageAsync(); ``` -This will create a `coverage.json` file in the `coverage` directory. This file has an [Istanbul format](https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md) - so you can use any of the existing Instanbul reporters. +This will create a `coverage.json` file in a `coverage` directory. This file has an [Istanbul format](https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md) - so you can use it with any of the existing Istanbul reporters. diff --git a/packages/website/package.json b/packages/website/package.json index 95804f988..a17964f2b 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -57,11 +57,13 @@ "web3": "^0.20.0", "web3-provider-engine": "^14.0.4", "whatwg-fetch": "^2.0.3", - "xml-js": "^1.3.2" + "xml-js": "^1.6.4" }, "devDependencies": { "@types/accounting": "^0.4.1", + "@types/blockies": "^0.0.0", "@types/deep-equal": "^1.0.0", + "@types/find-versions": "^2.0.0", "@types/jsonschema": "^1.1.1", "@types/lodash": "4.14.104", "@types/material-ui": "0.18.0", diff --git a/packages/website/ts/blockchain_watcher.ts b/packages/website/ts/blockchain_watcher.ts index c420a98a4..0d376bc74 100644 --- a/packages/website/ts/blockchain_watcher.ts +++ b/packages/website/ts/blockchain_watcher.ts @@ -10,7 +10,7 @@ export class BlockchainWatcher { private _prevNetworkId: number; private _shouldPollUserAddress: boolean; private _watchNetworkAndBalanceIntervalId: NodeJS.Timer; - private _prevUserEtherBalanceInWei: BigNumber; + private _prevUserEtherBalanceInWei?: BigNumber; private _prevUserAddressIfExists: string; constructor( dispatcher: Dispatcher, @@ -41,7 +41,7 @@ export class BlockchainWatcher { } let prevNodeVersion: string; - this._prevUserEtherBalanceInWei = new BigNumber(0); + this._prevUserEtherBalanceInWei = undefined; this._dispatcher.updateNetworkId(this._prevNetworkId); this._watchNetworkAndBalanceIntervalId = intervalUtils.setAsyncExcludingInterval( async () => { @@ -94,7 +94,7 @@ export class BlockchainWatcher { } private async _updateUserWeiBalanceAsync(userAddress: string): Promise<void> { const balanceInWei = await this._web3Wrapper.getBalanceInWeiAsync(userAddress); - if (!balanceInWei.eq(this._prevUserEtherBalanceInWei)) { + if (_.isUndefined(this._prevUserEtherBalanceInWei) || !balanceInWei.eq(this._prevUserEtherBalanceInWei)) { this._prevUserEtherBalanceInWei = balanceInWei; this._dispatcher.updateUserWeiBalance(balanceInWei); } diff --git a/packages/website/ts/components/eth_weth_conversion_button.tsx b/packages/website/ts/components/eth_weth_conversion_button.tsx index 4b91a2ebd..2fb35cc1c 100644 --- a/packages/website/ts/components/eth_weth_conversion_button.tsx +++ b/packages/website/ts/components/eth_weth_conversion_button.tsx @@ -18,7 +18,7 @@ interface EthWethConversionButtonProps { ethToken: Token; dispatcher: Dispatcher; blockchain: Blockchain; - userEtherBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; isOutdatedWrappedEther: boolean; onConversionSuccessful?: () => void; isDisabled?: boolean; diff --git a/packages/website/ts/components/eth_wrappers.tsx b/packages/website/ts/components/eth_wrappers.tsx index a5758a66a..1db5ff77f 100644 --- a/packages/website/ts/components/eth_wrappers.tsx +++ b/packages/website/ts/components/eth_wrappers.tsx @@ -33,7 +33,7 @@ interface EthWrappersProps { dispatcher: Dispatcher; tokenByAddress: TokenByAddress; userAddress: string; - userEtherBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; lastForceTokenStateRefetch: number; } diff --git a/packages/website/ts/components/legacy_portal/legacy_portal.tsx b/packages/website/ts/components/legacy_portal/legacy_portal.tsx index a5ea95629..e5d152e3e 100644 --- a/packages/website/ts/components/legacy_portal/legacy_portal.tsx +++ b/packages/website/ts/components/legacy_portal/legacy_portal.tsx @@ -38,6 +38,7 @@ import { } from 'ts/types'; import { configs } from 'ts/utils/configs'; import { constants } from 'ts/utils/constants'; +import { orderParser } from 'ts/utils/order_parser'; import { Translate } from 'ts/utils/translate'; import { utils } from 'ts/utils/utils'; @@ -55,7 +56,7 @@ export interface LegacyPortalProps { providerType: ProviderType; screenWidth: ScreenWidths; tokenByAddress: TokenByAddress; - userEtherBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; userAddress: string; shouldBlockchainErrDialogBeOpen: boolean; userSuppliedOrderCache: Order; @@ -86,7 +87,7 @@ export class LegacyPortal extends React.Component<LegacyPortalProps, LegacyPorta } constructor(props: LegacyPortalProps) { super(props); - this._sharedOrderIfExists = this._getSharedOrderIfExists(); + this._sharedOrderIfExists = orderParser.parse(window.location.search); this._throttledScreenWidthUpdate = _.throttle(this._updateScreenWidth.bind(this), THROTTLE_TIMEOUT); const isViewingBalances = _.includes(props.location.pathname, `${WebsitePaths.Portal}/balances`); @@ -362,32 +363,6 @@ export class LegacyPortal extends React.Component<LegacyPortalProps, LegacyPorta isWethNoticeDialogOpen: false, }); } - private _getSharedOrderIfExists(): Order | undefined { - const queryString = window.location.search; - if (queryString.length === 0) { - return undefined; - } - const queryParams = queryString.substring(1).split('&'); - const orderQueryParam = _.find(queryParams, queryParam => { - const queryPair = queryParam.split('='); - return queryPair[0] === 'order'; - }); - if (_.isUndefined(orderQueryParam)) { - return undefined; - } - const orderPair = orderQueryParam.split('='); - if (orderPair.length !== 2) { - return undefined; - } - - const order = JSON.parse(decodeURIComponent(orderPair[1])); - const validationResult = validator.validate(order, portalOrderSchema); - if (validationResult.errors.length > 0) { - logUtils.log(`Invalid shared order: ${validationResult.errors}`); - return undefined; - } - return order; - } private _updateScreenWidth(): void { const newScreenWidth = utils.getScreenWidth(); this.props.dispatcher.updateScreenWidth(newScreenWidth); diff --git a/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx b/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx index edaeb3736..2014dd7b0 100644 --- a/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx +++ b/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx @@ -14,7 +14,7 @@ export interface PortalOnboardingFlowProps { providerType: ProviderType; injectedProviderName: string; blockchainIsLoaded: boolean; - userEthBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; tokenByAddress: TokenByAddress; updateIsRunning: (isRunning: boolean) => void; updateOnboardingStep: (stepIndex: number) => void; @@ -85,7 +85,7 @@ export class PortalOnboardingFlow extends React.Component<PortalOnboardingFlowPr } private _userHasEth(): boolean { - return this.props.userEthBalanceInWei > new BigNumber(0); + return this.props.userEtherBalanceInWei > new BigNumber(0); } private _userHasWeth(): boolean { diff --git a/packages/website/ts/components/portal/menu.tsx b/packages/website/ts/components/portal/menu.tsx index 6a3301549..6e97ee37e 100644 --- a/packages/website/ts/components/portal/menu.tsx +++ b/packages/website/ts/components/portal/menu.tsx @@ -43,9 +43,14 @@ export const defaultMenuItemEntries: MenuItemEntry[] = [ iconName: 'zmdi-circle-o', }, { - to: `${WebsitePaths.Portal}/direct`, - labelText: 'Trade direct', - iconName: 'zmdi-swap', + to: `${WebsitePaths.Portal}/generate`, + labelText: 'Generate order', + iconName: 'zmdi-arrow-right-top', + }, + { + to: `${WebsitePaths.Portal}/fill`, + labelText: 'Fill order', + iconName: 'zmdi-arrow-left-bottom', }, ]; diff --git a/packages/website/ts/components/portal/portal.tsx b/packages/website/ts/components/portal/portal.tsx index 0e1506e17..589ad00ad 100644 --- a/packages/website/ts/components/portal/portal.tsx +++ b/packages/website/ts/components/portal/portal.tsx @@ -10,6 +10,7 @@ import { BlockchainErrDialog } from 'ts/components/dialogs/blockchain_err_dialog import { LedgerConfigDialog } from 'ts/components/dialogs/ledger_config_dialog'; import { PortalDisclaimerDialog } from 'ts/components/dialogs/portal_disclaimer_dialog'; import { EthWrappers } from 'ts/components/eth_wrappers'; +import { FillOrder } from 'ts/components/fill_order'; import { AssetPicker } from 'ts/components/generate_order/asset_picker'; import { BackButton } from 'ts/components/portal/back_button'; import { Loading } from 'ts/components/portal/loading'; @@ -42,6 +43,7 @@ import { } from 'ts/types'; import { configs } from 'ts/utils/configs'; import { constants } from 'ts/utils/constants'; +import { orderParser } from 'ts/utils/order_parser'; import { Translate } from 'ts/utils/translate'; import { utils } from 'ts/utils/utils'; @@ -57,7 +59,7 @@ export interface PortalProps { providerType: ProviderType; screenWidth: ScreenWidths; tokenByAddress: TokenByAddress; - userEtherBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; userAddress: string; shouldBlockchainErrDialogBeOpen: boolean; userSuppliedOrderCache: Order; @@ -116,9 +118,11 @@ const styles: Styles = { export class Portal extends React.Component<PortalProps, PortalState> { private _blockchain: Blockchain; + private _sharedOrderIfExists: Order; private _throttledScreenWidthUpdate: () => void; constructor(props: PortalProps) { super(props); + this._sharedOrderIfExists = orderParser.parse(window.location.search); this._throttledScreenWidthUpdate = _.throttle(this._updateScreenWidth.bind(this), THROTTLE_TIMEOUT); const didAcceptPortalDisclaimer = localStorage.getItemIfExists(constants.LOCAL_STORAGE_KEY_ACCEPT_DISCLAIMER); const hasAcceptedDisclaimer = @@ -336,9 +340,14 @@ export class Portal extends React.Component<PortalProps, PortalState> { render: this._renderTradeHistory.bind(this), }, { - pathName: `${WebsitePaths.Portal}/direct`, - headerText: 'Trade Direct', - render: this._renderTradeDirect.bind(this), + pathName: `${WebsitePaths.Portal}/generate`, + headerText: 'Generate Order', + render: this._renderGenerateOrderForm.bind(this), + }, + { + pathName: `${WebsitePaths.Portal}/fill`, + headerText: 'Fill Order', + render: this._renderFillOrder.bind(this), }, ]; return ( @@ -386,7 +395,7 @@ export class Portal extends React.Component<PortalProps, PortalState> { /> ); } - private _renderTradeDirect(match: any, location: Location, history: History): React.ReactNode { + private _renderGenerateOrderForm(): React.ReactNode { return ( <GenerateOrderForm blockchain={this._blockchain} @@ -395,6 +404,25 @@ export class Portal extends React.Component<PortalProps, PortalState> { /> ); } + private _renderFillOrder(): React.ReactNode { + const initialFillOrder = !_.isUndefined(this.props.userSuppliedOrderCache) + ? this.props.userSuppliedOrderCache + : this._sharedOrderIfExists; + return ( + <FillOrder + blockchain={this._blockchain} + blockchainErr={this.props.blockchainErr} + initialOrder={initialFillOrder} + isOrderInUrl={!_.isUndefined(this._sharedOrderIfExists)} + orderFillAmount={this.props.orderFillAmount} + networkId={this.props.networkId} + userAddress={this.props.userAddress} + tokenByAddress={this.props.tokenByAddress} + dispatcher={this.props.dispatcher} + lastForceTokenStateRefetch={this.props.lastForceTokenStateRefetch} + /> + ); + } private _renderTokenBalances(): React.ReactNode { const allTokens = _.values(this.props.tokenByAddress); const trackedTokens = _.filter(allTokens, t => t.isTracked); diff --git a/packages/website/ts/components/token_balances.tsx b/packages/website/ts/components/token_balances.tsx index f5a51dabb..7a0742bbe 100644 --- a/packages/website/ts/components/token_balances.tsx +++ b/packages/website/ts/components/token_balances.tsx @@ -85,6 +85,9 @@ interface TokenBalancesState { } export class TokenBalances extends React.Component<TokenBalancesProps, TokenBalancesState> { + public static defaultProps: Partial<TokenBalancesProps> = { + userEtherBalanceInWei: new BigNumber(0), + }; private _isUnmounted: boolean; public constructor(props: TokenBalancesProps) { super(props); diff --git a/packages/website/ts/components/top_bar/provider_display.tsx b/packages/website/ts/components/top_bar/provider_display.tsx index 679ec07dc..8a337119a 100644 --- a/packages/website/ts/components/top_bar/provider_display.tsx +++ b/packages/website/ts/components/top_bar/provider_display.tsx @@ -1,5 +1,6 @@ import { Styles } from '@0xproject/react-shared'; import * as _ from 'lodash'; +import CircularProgress from 'material-ui/CircularProgress'; import RaisedButton from 'material-ui/RaisedButton'; import * as React from 'react'; @@ -23,7 +24,8 @@ export interface ProviderDisplayProps { injectedProviderName: string; providerType: ProviderType; onToggleLedgerDialog: () => void; - blockchain: Blockchain; + blockchain?: Blockchain; + blockchainIsLoaded: boolean; } interface ProviderDisplayState {} @@ -44,11 +46,18 @@ export class ProviderDisplay extends React.Component<ProviderDisplayProps, Provi this.props.providerType, this.props.injectedProviderName, ); - const displayAddress = isAddressAvailable - ? utils.getAddressBeginAndEnd(this.props.userAddress) - : isExternallyInjectedProvider - ? 'Account locked' - : '0x0000...0000'; + let displayMessage; + if (!this._isBlockchainReady()) { + displayMessage = 'loading account'; + } else if (isAddressAvailable) { + displayMessage = utils.getAddressBeginAndEnd(this.props.userAddress); + // tslint:disable-next-line: prefer-conditional-expression + } else if (isExternallyInjectedProvider) { + displayMessage = 'Account locked'; + } else { + displayMessage = '0x0000...0000'; + } + // If the "injected" provider is our fallback public node, then we want to // show the "connect a wallet" message instead of the providerName const injectedProviderName = isExternallyInjectedProvider @@ -60,10 +69,14 @@ export class ProviderDisplay extends React.Component<ProviderDisplayProps, Provi const hoverActiveNode = ( <div className="flex right lg-pr0 md-pr2 sm-pr2 p1" style={styles.root}> <div> - <Identicon address={this.props.userAddress} diameter={ROOT_HEIGHT} /> + {this._isBlockchainReady() ? ( + <Identicon address={this.props.userAddress} diameter={ROOT_HEIGHT} /> + ) : ( + <CircularProgress size={ROOT_HEIGHT} thickness={2} /> + )} </div> <div style={{ marginLeft: 12, paddingTop: 3 }}> - <div style={{ fontSize: 16, color: colors.darkGrey }}>{displayAddress}</div> + <div style={{ fontSize: 16, color: colors.darkGrey }}>{displayMessage}</div> </div> {isProviderMetamask && ( <div style={{ marginLeft: 16 }}> @@ -87,7 +100,9 @@ export class ProviderDisplay extends React.Component<ProviderDisplayProps, Provi ); } public renderPopoverContent(hasInjectedProvider: boolean, hasLedgerProvider: boolean): React.ReactNode { - if (hasInjectedProvider || hasLedgerProvider) { + if (!this._isBlockchainReady()) { + return null; + } else if (hasInjectedProvider || hasLedgerProvider) { return ( <ProviderPicker dispatcher={this.props.dispatcher} @@ -159,4 +174,7 @@ export class ProviderDisplay extends React.Component<ProviderDisplayProps, Provi ); } } + private _isBlockchainReady(): boolean { + return this.props.blockchainIsLoaded && !_.isUndefined(this.props.blockchain); + } } diff --git a/packages/website/ts/components/top_bar/top_bar.tsx b/packages/website/ts/components/top_bar/top_bar.tsx index db8e3cb82..e2d791ae3 100644 --- a/packages/website/ts/components/top_bar/top_bar.tsx +++ b/packages/website/ts/components/top_bar/top_bar.tsx @@ -261,7 +261,7 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> { </div> </div> )} - {this.props.blockchainIsLoaded && ( + {this._isViewingPortal() && ( <div className="sm-hide xs-hide col col-5" style={{ paddingTop: 8, marginRight: 36 }}> <ProviderDisplay dispatcher={this.props.dispatcher} @@ -271,6 +271,7 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> { providerType={this.props.providerType} onToggleLedgerDialog={this.props.onToggleLedgerDialog} blockchain={this.props.blockchain} + blockchainIsLoaded={this.props.blockchainIsLoaded} /> </div> )} diff --git a/packages/website/ts/components/wallet/wallet.tsx b/packages/website/ts/components/wallet/wallet.tsx index 30d1285f4..18dada22f 100644 --- a/packages/website/ts/components/wallet/wallet.tsx +++ b/packages/website/ts/components/wallet/wallet.tsx @@ -7,6 +7,7 @@ import { import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; +import CircularProgress from 'material-ui/CircularProgress'; import FlatButton from 'material-ui/FlatButton'; import FloatingActionButton from 'material-ui/FloatingActionButton'; import { ListItem } from 'material-ui/List'; @@ -23,6 +24,7 @@ import firstBy = require('thenby'); import { Blockchain } from 'ts/blockchain'; import { AllowanceToggle } from 'ts/components/inputs/allowance_toggle'; +import { Container } from 'ts/components/ui/container'; import { IconButton } from 'ts/components/ui/icon_button'; import { Identicon } from 'ts/components/ui/identicon'; import { Island } from 'ts/components/ui/island'; @@ -59,7 +61,7 @@ export interface WalletProps { dispatcher: Dispatcher; tokenByAddress: TokenByAddress; trackedTokens: Token[]; - userEtherBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; lastForceTokenStateRefetch: number; injectedProviderName: string; providerType: ProviderType; @@ -92,9 +94,6 @@ const styles: Styles = { zIndex: zIndex.aboveOverlay, position: 'relative', }, - headerItemInnerDiv: { - paddingLeft: 65, - }, footerItemInnerDiv: { paddingLeft: 24, borderTopColor: colors.walletBorder, @@ -108,6 +107,7 @@ const styles: Styles = { }, tokenItem: { backgroundColor: colors.walletDefaultItemBackground, + minHeight: 85, }, amountLabel: { fontWeight: 'bold', @@ -129,10 +129,13 @@ const styles: Styles = { color: colors.mediumBlue, fontWeight: 'bold', }, + loadingBody: { + height: 381, + }, }; const ETHER_ICON_PATH = '/images/ether.png'; -const ICON_DIMENSION = 24; +const ICON_DIMENSION = 28; const TOKEN_AMOUNT_DISPLAY_PRECISION = 3; const BODY_ITEM_KEY = 'BODY'; const HEADER_ITEM_KEY = 'HEADER'; @@ -191,26 +194,40 @@ export class Wallet extends React.Component<WalletProps, WalletState> { } } public render(): React.ReactNode { - const isReadyToRender = this.props.blockchainIsLoaded && this.props.blockchainErr === BlockchainErrs.NoError; - const isAddressAvailable = !_.isEmpty(this.props.userAddress); + const isBlockchainLoaded = this.props.blockchainIsLoaded && this.props.blockchainErr === BlockchainErrs.NoError; return ( <Island className="flex flex-column wallet" style={styles.root}> - {isReadyToRender && isAddressAvailable - ? _.concat(this._renderConnectedHeaderRows(), this._renderBody(), this._renderFooterRows()) - : _.concat(this._renderDisconnectedHeaderRows(), this._renderDisconnectedRows())} + {isBlockchainLoaded ? this._renderLoadedRows() : this._renderLoadingRows()} </Island> ); } + private _renderLoadedRows(): React.ReactNode { + const isAddressAvailable = !_.isEmpty(this.props.userAddress); + return isAddressAvailable + ? _.concat(this._renderConnectedHeaderRows(), this._renderBody(), this._renderFooterRows()) + : _.concat(this._renderDisconnectedHeaderRows(), this._renderDisconnectedRows()); + } + private _renderLoadingRows(): React.ReactNode { + return _.concat(this._renderDisconnectedHeaderRows(), this._renderLoadingBodyRows()); + } + private _renderLoadingBodyRows(): React.ReactElement<{}> { + return ( + <div key={BODY_ITEM_KEY} className="flex items-center" style={styles.loadingBody}> + <div className="mx-auto"> + <CircularProgress size={40} thickness={5} /> + </div> + </div> + ); + } private _renderDisconnectedHeaderRows(): React.ReactElement<{}> { const userAddress = this.props.userAddress; const primaryText = 'wallet'; return ( - <ListItem + <StandardIconRow key={HEADER_ITEM_KEY} - primaryText={primaryText.toUpperCase()} - leftIcon={<ActionAccountBalanceWallet color={colors.mediumBlue} />} - style={styles.paddedItem} - innerDivStyle={styles.headerItemInnerDiv} + icon={<ActionAccountBalanceWallet color={colors.mediumBlue} />} + main={primaryText.toUpperCase()} + style={styles.borderedItem} /> ); } @@ -229,11 +246,10 @@ export class Wallet extends React.Component<WalletProps, WalletState> { const primaryText = utils.getAddressBeginAndEnd(userAddress); return ( <Link key={HEADER_ITEM_KEY} to={ACCOUNT_PATH} style={{ textDecoration: 'none' }}> - <ListItem - primaryText={primaryText} - leftIcon={<Identicon address={userAddress} diameter={ICON_DIMENSION} />} - style={{ ...styles.paddedItem, ...styles.borderedItem }} - innerDivStyle={styles.headerItemInnerDiv} + <StandardIconRow + icon={<Identicon address={userAddress} diameter={ICON_DIMENSION} />} + main={primaryText} + style={styles.borderedItem} /> </Link> ); @@ -320,26 +336,23 @@ export class Wallet extends React.Component<WalletProps, WalletState> { private _renderEthRows(): React.ReactNode { const icon = <img style={{ width: ICON_DIMENSION, height: ICON_DIMENSION }} src={ETHER_ICON_PATH} />; const primaryText = this._renderAmount( - this.props.userEtherBalanceInWei, + this.props.userEtherBalanceInWei || new BigNumber(0), constants.DECIMAL_PLACES_ETH, constants.ETHER_SYMBOL, + _.isUndefined(this.props.userEtherBalanceInWei), ); const etherToken = this._getEthToken(); - const etherPrice = this.state.trackedTokenStateByAddress[etherToken.address].price; + const etherTokenState = this.state.trackedTokenStateByAddress[etherToken.address]; + const etherPrice = etherTokenState.price; const secondaryText = this._renderValue( - this.props.userEtherBalanceInWei, + this.props.userEtherBalanceInWei || new BigNumber(0), constants.DECIMAL_PLACES_ETH, etherPrice, + _.isUndefined(this.props.userEtherBalanceInWei) || !etherTokenState.isLoaded, ); const accessoryItemConfig = { wrappedEtherDirection: Side.Deposit, }; - const isInWrappedEtherState = - !_.isUndefined(this.state.wrappedEtherDirection) && - this.state.wrappedEtherDirection === accessoryItemConfig.wrappedEtherDirection; - const style = isInWrappedEtherState - ? { ...walletItemStyles.focusedItem, ...styles.paddedItem } - : { ...styles.tokenItem, ...styles.borderedItem, ...styles.paddedItem }; const key = ETHER_ITEM_KEY; return this._renderBalanceRow(key, icon, primaryText, secondaryText, accessoryItemConfig, 'eth-row'); } @@ -360,10 +373,15 @@ export class Wallet extends React.Component<WalletProps, WalletState> { EtherscanLinkSuffixes.Address, ); const icon = <TokenIcon token={token} diameter={ICON_DIMENSION} link={tokenLink} />; - const primaryText = this._renderAmount(tokenState.balance, token.decimals, token.symbol); - const secondaryText = this._renderValue(tokenState.balance, token.decimals, tokenState.price); const isWeth = token.symbol === constants.ETHER_TOKEN_SYMBOL; const wrappedEtherDirection = isWeth ? Side.Receive : undefined; + const primaryText = this._renderAmount(tokenState.balance, token.decimals, token.symbol, !tokenState.isLoaded); + const secondaryText = this._renderValue( + tokenState.balance, + token.decimals, + tokenState.price, + !tokenState.isLoaded, + ); const accessoryItemConfig: AccessoryItemConfig = { wrappedEtherDirection, allowanceToggleConfig: { @@ -391,22 +409,24 @@ export class Wallet extends React.Component<WalletProps, WalletState> { ): React.ReactNode { const shouldShowWrapEtherItem = !_.isUndefined(this.state.wrappedEtherDirection) && - this.state.wrappedEtherDirection === accessoryItemConfig.wrappedEtherDirection; - const style = shouldShowWrapEtherItem - ? { ...walletItemStyles.focusedItem, ...styles.paddedItem } - : { ...styles.tokenItem, ...styles.borderedItem, ...styles.paddedItem }; + this.state.wrappedEtherDirection === accessoryItemConfig.wrappedEtherDirection && + !_.isUndefined(this.props.userEtherBalanceInWei); + const additionalStyle = shouldShowWrapEtherItem ? walletItemStyles.focusedItem : styles.borderedItem; + const style = { ...styles.tokenItem, ...additionalStyle }; const etherToken = this._getEthToken(); return ( <div key={key} className={`flex flex-column ${className || ''}`}> - <div className="flex items-center" style={style}> - <div className="px2">{icon}</div> - <div className="flex-none pr2 pt2 pb2"> - {primaryText} - {secondaryText} - </div> - <div className="flex-auto" /> - <div>{this._renderAccessoryItems(accessoryItemConfig)}</div> - </div> + <StandardIconRow + icon={icon} + main={ + <div className="flex flex-column"> + {primaryText} + <Container marginTop="3px">{secondaryText}</Container> + </div> + } + accessory={this._renderAccessoryItems(accessoryItemConfig)} + style={style} + /> {shouldShowWrapEtherItem && ( <WrapEtherItem userAddress={this.props.userAddress} @@ -458,21 +478,45 @@ export class Wallet extends React.Component<WalletProps, WalletState> { /> ); } - private _renderAmount(amount: BigNumber, decimals: number, symbol: string): React.ReactNode { + private _renderAmount( + amount: BigNumber, + decimals: number, + symbol: string, + isLoading: boolean = false, + ): React.ReactNode { const unitAmount = Web3Wrapper.toUnitAmount(amount, decimals); const formattedAmount = unitAmount.toPrecision(TOKEN_AMOUNT_DISPLAY_PRECISION); const result = `${formattedAmount} ${symbol}`; - return <div style={styles.amountLabel}>{result}</div>; + return ( + <PlaceHolder hideChildren={isLoading}> + <div style={styles.amountLabel}>{result}</div> + </PlaceHolder> + ); } - private _renderValue(amount: BigNumber, decimals: number, price?: BigNumber): React.ReactNode { - if (_.isUndefined(price)) { - return null; + private _renderValue( + amount: BigNumber, + decimals: number, + price?: BigNumber, + isLoading: boolean = false, + ): React.ReactNode { + let result; + if (!isLoading) { + if (_.isUndefined(price)) { + result = '--'; + } else { + const unitAmount = Web3Wrapper.toUnitAmount(amount, decimals); + const value = unitAmount.mul(price); + const formattedAmount = value.toFixed(USD_DECIMAL_PLACES); + result = `$${formattedAmount}`; + } + } else { + result = '$0.00'; } - const unitAmount = Web3Wrapper.toUnitAmount(amount, decimals); - const value = unitAmount.mul(price); - const formattedAmount = value.toFixed(USD_DECIMAL_PLACES); - const result = `$${formattedAmount}`; - return <div style={styles.valueLabel}>{result}</div>; + return ( + <PlaceHolder hideChildren={isLoading}> + <div style={styles.valueLabel}>{result}</div> + </PlaceHolder> + ); } private _renderWrappedEtherButton(wrappedEtherDirection: Side): React.ReactNode { const isWrappedEtherDirectionOpen = this.state.wrappedEtherDirection === wrappedEtherDirection; @@ -589,4 +633,41 @@ export class Wallet extends React.Component<WalletProps, WalletState> { private _getEthToken(): Token { return utils.getEthToken(this.props.tokenByAddress); } -} // tslint:disable:max-file-line-count +} + +interface StandardIconRowProps { + icon: React.ReactNode; + main: React.ReactNode; + accessory?: React.ReactNode; + style?: React.CSSProperties; +} +const StandardIconRow = (props: StandardIconRowProps) => { + return ( + <div className="flex items-center" style={props.style}> + <div className="p2">{props.icon}</div> + <div className="flex-none pr2 pt2 pb2">{props.main}</div> + <div className="flex-auto" /> + <div>{props.accessory}</div> + </div> + ); +}; +interface PlaceHolderProps { + hideChildren: React.ReactNode; + children?: React.ReactNode; +} +const PlaceHolder = (props: PlaceHolderProps) => { + const rootBackgroundColor = props.hideChildren ? colors.lightGrey : 'transparent'; + const rootStyle: React.CSSProperties = { + backgroundColor: rootBackgroundColor, + display: 'inline-block', + borderRadius: 2, + }; + const childrenVisibility = props.hideChildren ? 'hidden' : 'visible'; + const childrenStyle: React.CSSProperties = { visibility: childrenVisibility }; + return ( + <div style={rootStyle}> + <div style={childrenStyle}>{props.children}</div> + </div> + ); +}; +// tslint:disable:max-file-line-count diff --git a/packages/website/ts/components/wallet/wallet_disconnected_item.tsx b/packages/website/ts/components/wallet/wallet_disconnected_item.tsx index 39a62e1fb..17fd8a19e 100644 --- a/packages/website/ts/components/wallet/wallet_disconnected_item.tsx +++ b/packages/website/ts/components/wallet/wallet_disconnected_item.tsx @@ -31,7 +31,7 @@ const styles: Styles = { }, }; -const ITEM_HEIGHT = 292; +const ITEM_HEIGHT = 381; const METAMASK_ICON_WIDTH = 35; const LEDGER_ICON_WIDTH = 30; const BUTTON_BOTTOM_PADDING = 80; diff --git a/packages/website/ts/containers/legacy_portal.ts b/packages/website/ts/containers/legacy_portal.ts index 3b1172a44..eae450c21 100644 --- a/packages/website/ts/containers/legacy_portal.ts +++ b/packages/website/ts/containers/legacy_portal.ts @@ -24,7 +24,7 @@ interface ConnectedState { providerType: ProviderType; tokenByAddress: TokenByAddress; lastForceTokenStateRefetch: number; - userEtherBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; screenWidth: ScreenWidths; shouldBlockchainErrDialogBeOpen: boolean; userAddress: string; diff --git a/packages/website/ts/containers/portal.ts b/packages/website/ts/containers/portal.ts index 3f0feb6e9..b8c8fb999 100644 --- a/packages/website/ts/containers/portal.ts +++ b/packages/website/ts/containers/portal.ts @@ -21,7 +21,7 @@ interface ConnectedState { providerType: ProviderType; tokenByAddress: TokenByAddress; lastForceTokenStateRefetch: number; - userEtherBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; screenWidth: ScreenWidths; shouldBlockchainErrDialogBeOpen: boolean; userAddress: string; diff --git a/packages/website/ts/containers/portal_onboarding_flow.ts b/packages/website/ts/containers/portal_onboarding_flow.ts index 84739192f..8202fb2ae 100644 --- a/packages/website/ts/containers/portal_onboarding_flow.ts +++ b/packages/website/ts/containers/portal_onboarding_flow.ts @@ -17,7 +17,7 @@ interface ConnectedState { providerType: ProviderType; injectedProviderName: string; blockchainIsLoaded: boolean; - userEthBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; tokenByAddress: TokenByAddress; } @@ -33,7 +33,7 @@ const mapStateToProps = (state: State): ConnectedState => ({ providerType: state.providerType, injectedProviderName: state.injectedProviderName, blockchainIsLoaded: state.blockchainIsLoaded, - userEthBalanceInWei: state.userEtherBalanceInWei, + userEtherBalanceInWei: state.userEtherBalanceInWei, tokenByAddress: state.tokenByAddress, hasBeenSeen: state.hasPortalOnboardingBeenSeen, }); diff --git a/packages/website/ts/containers/sol_cov_documentation.ts b/packages/website/ts/containers/sol_cov_documentation.ts index 58755c1e0..bc05b6854 100644 --- a/packages/website/ts/containers/sol_cov_documentation.ts +++ b/packages/website/ts/containers/sol_cov_documentation.ts @@ -22,6 +22,9 @@ const docSections = { installation: 'installation', usage: 'usage', coverageSubprovider: 'coverageSubprovider', + abstractArtifactAdapter: 'abstractArtifactAdapter', + solCompilerArtifactAdapter: 'solCompilerArtifactAdapter', + truffleArtifactAdapter: 'truffleArtifactAdapter', types: docConstants.TYPES_SECTION_NAME, }; @@ -34,7 +37,10 @@ const docsInfoConfig: DocsInfoConfig = { introduction: [docSections.introduction], install: [docSections.installation], usage: [docSections.usage], - coverageSubprovider: [docSections.coverageSubprovider], + 'coverage-subprovider': [docSections.coverageSubprovider], + 'abstract-artifact-adapter': [docSections.abstractArtifactAdapter], + 'sol-compiler-artifact-adapter': [docSections.solCompilerArtifactAdapter], + 'truffle-artifact-adapter': [docSections.truffleArtifactAdapter], types: [docSections.types], }, sectionNameToMarkdown: { @@ -44,18 +50,40 @@ const docsInfoConfig: DocsInfoConfig = { }, sectionNameToModulePath: { [docSections.coverageSubprovider]: ['"sol-cov/src/coverage_subprovider"'], + [docSections.abstractArtifactAdapter]: ['"sol-cov/src/artifact_adapters/abstract_artifact_adapter"'], + [docSections.solCompilerArtifactAdapter]: ['"sol-cov/src/artifact_adapters/sol_compiler_artifact_adapter"'], + [docSections.truffleArtifactAdapter]: ['"sol-cov/src/artifact_adapters/truffle_artifact_adapter"'], [docSections.types]: ['"subproviders/src/types"', '"types/src/index"'], }, menuSubsectionToVersionWhenIntroduced: {}, sections: docSections, - visibleConstructors: [docSections.coverageSubprovider], + visibleConstructors: [ + docSections.coverageSubprovider, + docSections.abstractArtifactAdapter, + docSections.solCompilerArtifactAdapter, + docSections.truffleArtifactAdapter, + ], typeConfigs: { // Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is // currently no way to extract the re-exported types from index.ts via TypeDoc :( - publicTypes: ['NextCallback', 'OnNextCompleted', 'ErrorCallback', 'JSONRPCRequestPayload'], + publicTypes: [ + 'JSONRPCRequestPayload', + 'NextCallback', + 'ErrorCallback', + 'AbstractArtifactAdapter', + 'CoverageSubprovider', + 'TruffleArtifactAdapter', + 'SolCompilerArtifactAdapter', + 'ContractData', + ], typeNameToExternalLink: {}, typeNameToPrefix: {}, - typeNameToDocSection: {}, + typeNameToDocSection: { + AbstractArtifactAdapter: docSections.abstractArtifactAdapter, + CoverageSubprovider: docSections.coverageSubprovider, + TruffleArtifactAdapter: docSections.truffleArtifactAdapter, + SolCompilerArtifactAdapter: docSections.solCompilerArtifactAdapter, + }, }, }; const docsInfo = new DocsInfo(docsInfoConfig); diff --git a/packages/website/ts/redux/dispatcher.ts b/packages/website/ts/redux/dispatcher.ts index 0b4cc3938..e0ce43ae5 100644 --- a/packages/website/ts/redux/dispatcher.ts +++ b/packages/website/ts/redux/dispatcher.ts @@ -155,7 +155,7 @@ export class Dispatcher { type: ActionTypes.UpdateOrderECSignature, }); } - public updateUserWeiBalance(balance: BigNumber): void { + public updateUserWeiBalance(balance?: BigNumber): void { this._dispatch({ data: balance, type: ActionTypes.UpdateUserEtherBalance, diff --git a/packages/website/ts/redux/reducer.ts b/packages/website/ts/redux/reducer.ts index 5c57792f7..9d3d8f7d9 100644 --- a/packages/website/ts/redux/reducer.ts +++ b/packages/website/ts/redux/reducer.ts @@ -39,7 +39,7 @@ export interface State { tokenByAddress: TokenByAddress; lastForceTokenStateRefetch: number; userAddress: string; - userEtherBalanceInWei: BigNumber; + userEtherBalanceInWei?: BigNumber; portalOnboardingStep: number; isPortalOnboardingShowing: boolean; hasPortalOnboardingBeenSeen: boolean; @@ -81,7 +81,7 @@ export const INITIAL_STATE: State = { tokenByAddress: {}, lastForceTokenStateRefetch: moment().unix(), userAddress: '', - userEtherBalanceInWei: new BigNumber(0), + userEtherBalanceInWei: undefined, userSuppliedOrderCache: undefined, portalOnboardingStep: 0, isPortalOnboardingShowing: false, diff --git a/packages/website/ts/utils/order_parser.ts b/packages/website/ts/utils/order_parser.ts new file mode 100644 index 000000000..be08da80e --- /dev/null +++ b/packages/website/ts/utils/order_parser.ts @@ -0,0 +1,33 @@ +import { logUtils } from '@0xproject/utils'; +import * as _ from 'lodash'; + +import { portalOrderSchema } from 'ts/schemas/portal_order_schema'; +import { validator } from 'ts/schemas/validator'; +import { Order } from 'ts/types'; + +export const orderParser = { + parse(queryString: string): Order | undefined { + if (queryString.length === 0) { + return undefined; + } + const queryParams = queryString.substring(1).split('&'); + const orderQueryParam = _.find(queryParams, queryParam => { + const queryPair = queryParam.split('='); + return queryPair[0] === 'order'; + }); + if (_.isUndefined(orderQueryParam)) { + return undefined; + } + const orderPair = orderQueryParam.split('='); + if (orderPair.length !== 2) { + return undefined; + } + const order = JSON.parse(decodeURIComponent(orderPair[1])); + const validationResult = validator.validate(order, portalOrderSchema); + if (validationResult.errors.length > 0) { + logUtils.log(`Invalid shared order: ${validationResult.errors}`); + return undefined; + } + return order; + }, +}; |