diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-06-28 02:17:32 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-06-28 02:17:32 +0800 |
commit | b6f546ebe0b71ce450c1e724fc8f3b670bf97773 (patch) | |
tree | 94f6afa5b4e0519c5dfa47c0b7cd24fb6c8f14e7 /packages/website/ts | |
parent | 2a092143dc01d84e5dc0b6dc2998cfd4efb38d73 (diff) | |
download | dexon-0x-contracts-b6f546ebe0b71ce450c1e724fc8f3b670bf97773.tar.gz dexon-0x-contracts-b6f546ebe0b71ce450c1e724fc8f3b670bf97773.tar.zst dexon-0x-contracts-b6f546ebe0b71ce450c1e724fc8f3b670bf97773.zip |
Fix convention stuff
Diffstat (limited to 'packages/website/ts')
-rw-r--r-- | packages/website/ts/blockchain.ts | 30 | ||||
-rw-r--r-- | packages/website/ts/components/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<number> { + private static async _getInjectedWeb3ProviderNetworkIdIfExistsAsync(): Promise<number | undefined> { // 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<string>(injectedWeb3.version.getNetwork)()); + networkIdIfExists = _.parseInt(await promisify<string>(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<PortalOnboardingFlowProp const ethTokenState = this.props.trackedTokenStateByAddress[ethToken.address]; const zrxTokenState = this.props.trackedTokenStateByAddress[zrxToken.address]; if (ethTokenState && zrxTokenState) { - return ethTokenState.allowance > 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<PortalOnboardingFlowProp if (!token) { return null; } - const tokenState = this.props.trackedTokenStateByAddress[token.address]; - if (!tokenState) { + const tokenStateIfExists = this.props.trackedTokenStateByAddress[token.address]; + if (_.isUndefined(tokenStateIfExists)) { return null; } return ( <AllowanceToggle token={token} - tokenState={tokenState} - isDisabled={!tokenState.isLoaded} + tokenState={tokenStateIfExists} + isDisabled={!tokenStateIfExists.isLoaded} blockchain={this.props.blockchain} // tslint:disable-next-line:jsx-no-lambda refetchTokenStateAsync={async () => this.props.refetchTokenStateAsync(token.address)} |