From 04d11d6fac265d8e43de8c14cab78655bb90d035 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 2 Jul 2018 13:38:02 -0700 Subject: Add human readable names for Toshi and Cipher --- packages/website/ts/blockchain.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'packages/website/ts/blockchain.ts') diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index d18c34c32..b59306974 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -73,6 +73,8 @@ const providerToName: { [provider: string]: string } = { [Providers.Metamask]: constants.PROVIDER_NAME_METAMASK, [Providers.Parity]: constants.PROVIDER_NAME_PARITY_SIGNER, [Providers.Mist]: constants.PROVIDER_NAME_MIST, + [Providers.Toshi]: constants.PROVIDER_NAME_TOSHI, + [Providers.Cipher]: constants.PROVIDER_NAME_CIPHER, }; export class Blockchain { -- cgit v1.2.3 From d09711363951f7ae25b3b3d5e091df7a420caf9f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Jul 2018 23:34:51 +0200 Subject: Remove dep on Web3 in Website. Introduced InjectedWeb3 type. --- packages/website/ts/blockchain.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'packages/website/ts/blockchain.ts') diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index b59306974..a93ec9331 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -46,6 +46,7 @@ import { Fill, InjectedProviderObservable, InjectedProviderUpdate, + InjectedWeb3, Order as PortalOrder, Providers, ProviderType, @@ -59,7 +60,6 @@ import { configs } from 'ts/utils/configs'; import { constants } from 'ts/utils/constants'; import { errorReporter } from 'ts/utils/error_reporter'; import { utils } from 'ts/utils/utils'; -import Web3 = require('web3'); import ProviderEngine = require('web3-provider-engine'); import FilterSubprovider = require('web3-provider-engine/subproviders/filters'); import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); @@ -97,8 +97,18 @@ export class Blockchain { } return providerNameIfExists; } - private static _getInjectedWeb3(): any { - return (window as any).web3; + private static _getInjectedWeb3(): InjectedWeb3 { + const injectedWeb3IfExists = (window as any).web3; + // Our core assumptions about the injected web3 object is that it has the following + // properties and methods. + if ( + !_.isUndefined(injectedWeb3IfExists.version) && + !_.isUndefined(injectedWeb3IfExists.version.getNetwork) && + !_.isUndefined(injectedWeb3IfExists.currentProvider) + ) { + return undefined; + } + return injectedWeb3IfExists; } private static async _getInjectedWeb3ProviderNetworkIdIfExistsAsync(): Promise { // Hack: We need to know the networkId the injectedWeb3 is connected to (if it is defined) in @@ -119,7 +129,7 @@ export class Blockchain { return networkIdIfExists; } private static async _getProviderAsync( - injectedWeb3: Web3, + injectedWeb3: InjectedWeb3, networkIdIfExists: number, shouldUserLedgerProvider: boolean = false, ): Promise<[Provider, LedgerSubprovider | undefined]> { @@ -834,10 +844,10 @@ export class Blockchain { this._dispatcher.updateNetworkId(networkId); await this._rehydrateStoreWithContractEventsAsync(); } - private _updateProviderName(injectedWeb3: Web3): void { - const doesInjectedWeb3Exist = !_.isUndefined(injectedWeb3); + private _updateProviderName(injectedWeb3IfExists: InjectedWeb3): void { + const doesInjectedWeb3Exist = !_.isUndefined(injectedWeb3IfExists); const providerName = doesInjectedWeb3Exist - ? Blockchain._getNameGivenProvider(injectedWeb3.currentProvider) + ? Blockchain._getNameGivenProvider(injectedWeb3IfExists.currentProvider) : constants.PROVIDER_NAME_PUBLIC; this._dispatcher.updateInjectedProviderName(providerName); } -- cgit v1.2.3 From 2b4bb579d47037fa8c8a2c858bc467ccd8eed3b0 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Jul 2018 23:57:19 +0200 Subject: Rename subprovider in blockchain.ts --- packages/website/ts/blockchain.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/website/ts/blockchain.ts') diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index a93ec9331..8f1b33aeb 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -12,10 +12,10 @@ import { import { isValidOrderHash, signOrderHashAsync } from '@0xproject/order-utils'; import { EtherscanLinkSuffixes, utils as sharedUtils } from '@0xproject/react-shared'; import { - InjectedWeb3Subprovider, ledgerEthereumBrowserClientFactoryAsync, LedgerSubprovider, RedundantSubprovider, + SignerSubprovider, Subprovider, } from '@0xproject/subproviders'; import { @@ -163,7 +163,7 @@ export class Blockchain { // We catch all requests involving a users account and send it to the injectedWeb3 // instance. All other requests go to the public hosted node. const provider = new ProviderEngine(); - provider.addProvider(new InjectedWeb3Subprovider(injectedWeb3.currentProvider)); + provider.addProvider(new SignerSubprovider(injectedWeb3.currentProvider)); provider.addProvider(new FilterSubprovider()); const rpcSubproviders = _.map(publicNodeUrlsIfExistsForNetworkId, publicNodeUrl => { return new RpcSubprovider({ -- cgit v1.2.3 From 9db0bc262ba85d7dc3b104a0c1c81f85e985acfb Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 4 Jul 2018 00:36:57 +0200 Subject: Fix conditional --- packages/website/ts/blockchain.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'packages/website/ts/blockchain.ts') diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 8f1b33aeb..eb2cba268 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -102,9 +102,9 @@ export class Blockchain { // Our core assumptions about the injected web3 object is that it has the following // properties and methods. if ( - !_.isUndefined(injectedWeb3IfExists.version) && - !_.isUndefined(injectedWeb3IfExists.version.getNetwork) && - !_.isUndefined(injectedWeb3IfExists.currentProvider) + _.isUndefined(injectedWeb3IfExists.version) || + _.isUndefined(injectedWeb3IfExists.version.getNetwork) || + _.isUndefined(injectedWeb3IfExists.currentProvider) ) { return undefined; } @@ -787,6 +787,7 @@ export class Blockchain { const networkIdIfExists = await Blockchain._getInjectedWeb3ProviderNetworkIdIfExistsAsync(); this.networkId = !_.isUndefined(networkIdIfExists) ? networkIdIfExists : constants.NETWORK_ID_MAINNET; const injectedWeb3IfExists = Blockchain._getInjectedWeb3(); + console.log(injectedWeb3IfExists); if (!_.isUndefined(injectedWeb3IfExists) && !_.isUndefined(injectedWeb3IfExists.currentProvider)) { const injectedProviderObservable = injectedWeb3IfExists.currentProvider.publicConfigStore; if (!_.isUndefined(injectedProviderObservable) && _.isUndefined(this._injectedProviderObservable)) { -- cgit v1.2.3 From 0d56daf7ab71031edfa5145704a9a9b746fd80cf Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 4 Jul 2018 00:37:39 +0200 Subject: remove console.log --- packages/website/ts/blockchain.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/website/ts/blockchain.ts') diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index eb2cba268..6a92403f2 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -787,7 +787,6 @@ export class Blockchain { const networkIdIfExists = await Blockchain._getInjectedWeb3ProviderNetworkIdIfExistsAsync(); this.networkId = !_.isUndefined(networkIdIfExists) ? networkIdIfExists : constants.NETWORK_ID_MAINNET; const injectedWeb3IfExists = Blockchain._getInjectedWeb3(); - console.log(injectedWeb3IfExists); if (!_.isUndefined(injectedWeb3IfExists) && !_.isUndefined(injectedWeb3IfExists.currentProvider)) { const injectedProviderObservable = injectedWeb3IfExists.currentProvider.publicConfigStore; if (!_.isUndefined(injectedProviderObservable) && _.isUndefined(this._injectedProviderObservable)) { -- cgit v1.2.3 From 4e783fba57bbd3d389ab52679ca8763bfa03cbf3 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 4 Jul 2018 16:34:03 +0200 Subject: Add missing undefined check --- packages/website/ts/blockchain.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/website/ts/blockchain.ts') diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 6a92403f2..cc2afa28a 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -102,6 +102,7 @@ export class Blockchain { // Our core assumptions about the injected web3 object is that it has the following // properties and methods. if ( + _.isUndefined(injectedWeb3IfExists) || _.isUndefined(injectedWeb3IfExists.version) || _.isUndefined(injectedWeb3IfExists.version.getNetwork) || _.isUndefined(injectedWeb3IfExists.currentProvider) -- cgit v1.2.3