From b6f546ebe0b71ce450c1e724fc8f3b670bf97773 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 27 Jun 2018 11:17:32 -0700 Subject: Fix convention stuff --- packages/website/ts/blockchain.ts | 30 +++++++++++----------- .../onboarding/portal_onboarding_flow.tsx | 10 ++++---- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index a0a404d5a..4a041d20c 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -97,18 +97,18 @@ export class Blockchain { private static _getInjectedWeb3(): any { return (window as any).web3; } - private static async _getInjectedWeb3ProviderNetworkIdIfExistsAsync(): Promise { + private static async _getInjectedWeb3ProviderNetworkIdIfExistsAsync(): Promise { // Hack: We need to know the networkId the injectedWeb3 is connected to (if it is defined) in // order to properly instantiate the web3Wrapper. Since we must use the async call, we cannot // retrieve it from within the web3Wrapper constructor. This is and should remain the only // call to a web3 instance outside of web3Wrapper in the entire dapp. // In addition, if the user has an injectedWeb3 instance that is disconnected from a backing // Ethereum node, this call will throw. We need to handle this case gracefully - const injectedWeb3 = Blockchain._getInjectedWeb3(); + const injectedWeb3IfExists = Blockchain._getInjectedWeb3(); let networkIdIfExists: number; - if (!_.isUndefined(injectedWeb3)) { + if (!_.isUndefined(injectedWeb3IfExists)) { try { - networkIdIfExists = _.parseInt(await promisify(injectedWeb3.version.getNetwork)()); + networkIdIfExists = _.parseInt(await promisify(injectedWeb3IfExists.version.getNetwork)()); } catch (err) { // Ignore error and proceed with networkId undefined } @@ -119,13 +119,13 @@ export class Blockchain { injectedWeb3: Web3, networkIdIfExists: number, shouldUserLedgerProvider: boolean = false, - ): Promise<[Provider, LedgerSubprovider]> { + ): Promise<[Provider, LedgerSubprovider | undefined]> { const doesInjectedWeb3Exist = !_.isUndefined(injectedWeb3); - const isNetworkIdDefined = !_.isUndefined(networkIdIfExists); + const isNetworkIdAvailable = !_.isUndefined(networkIdIfExists); const publicNodeUrlsIfExistsForNetworkId = configs.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkIdIfExists]; const isPublicNodeAvailableForNetworkId = !_.isUndefined(publicNodeUrlsIfExistsForNetworkId); - if (shouldUserLedgerProvider && isNetworkIdDefined) { + if (shouldUserLedgerProvider && isNetworkIdAvailable) { const isU2FSupported = await utils.isU2FSupportedAsync(); if (!isU2FSupported) { throw new Error('Cannot update providerType to LEDGER without U2F support'); @@ -243,7 +243,7 @@ export class Blockchain { const shouldPollUserAddress = true; const shouldUserLedgerProvider = false; this._dispatcher.updateBlockchainIsLoaded(false); - // We don't want to be out of sync with the network metamask declares. + // We don't want to be out of sync with the network the injected provider declares. const networkId = await Blockchain._getInjectedWeb3ProviderNetworkIdIfExistsAsync(); await this._resetOrInitializeAsync(networkId, shouldPollUserAddress, shouldUserLedgerProvider); } @@ -772,15 +772,15 @@ export class Blockchain { await utils.onPageLoadAsync(); // wait for page to load const networkIdIfExists = await Blockchain._getInjectedWeb3ProviderNetworkIdIfExistsAsync(); this.networkId = !_.isUndefined(networkIdIfExists) ? networkIdIfExists : constants.NETWORK_ID_MAINNET; - const injectedWeb3 = Blockchain._getInjectedWeb3(); - if (injectedWeb3) { - const injectedProviderObservable = injectedWeb3.currentProvider.publicConfigStore; + const injectedWeb3IfExists = Blockchain._getInjectedWeb3(); + if (injectedWeb3IfExists) { + const injectedProviderObservable = injectedWeb3IfExists.currentProvider.publicConfigStore; if (injectedProviderObservable && !this._injectedProviderObservable) { this._injectedProviderObservable = injectedProviderObservable; this._injectedProviderObservable.subscribe(this._injectedProviderUpdateHandler); } } - this._updateProviderName(injectedWeb3); + this._updateProviderName(injectedWeb3IfExists); const shouldPollUserAddress = true; const shouldUseLedgerProvider = false; await this._resetOrInitializeAsync(this.networkId, shouldPollUserAddress, shouldUseLedgerProvider); @@ -793,9 +793,9 @@ export class Blockchain { this._dispatcher.updateBlockchainIsLoaded(false); this._dispatcher.updateUserWeiBalance(undefined); this.networkId = networkId; - const injectedWeb3 = Blockchain._getInjectedWeb3(); + const injectedWeb3IfExists = Blockchain._getInjectedWeb3(); const [provider, ledgerSubproviderIfExists] = await Blockchain._getProviderAsync( - injectedWeb3, + injectedWeb3IfExists, networkId, shouldUserLedgerProvider, ); @@ -819,7 +819,7 @@ export class Blockchain { const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync(); this._userAddressIfExists = userAddresses[0]; this._dispatcher.updateUserAddress(this._userAddressIfExists); - if (!_.isUndefined(injectedWeb3)) { + if (!_.isUndefined(injectedWeb3IfExists)) { this._dispatcher.updateProviderType(ProviderType.Injected); } await this.fetchTokenInformationAsync(); diff --git a/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx b/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx index 35b51140d..296b410fe 100644 --- a/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx +++ b/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx @@ -162,7 +162,7 @@ class PlainPortalOnboardingFlow extends React.Component new BigNumber(0) && zrxTokenState.allowance > new BigNumber(0); + return ethTokenState.allowance.gt(0) && zrxTokenState.allowance.gt(0); } } return false; @@ -223,15 +223,15 @@ class PlainPortalOnboardingFlow extends React.Component this.props.refetchTokenStateAsync(token.address)} -- cgit v1.2.3