Fix convention stuff
This commit is contained in:
@@ -97,18 +97,18 @@ export class Blockchain {
|
|||||||
private static _getInjectedWeb3(): any {
|
private static _getInjectedWeb3(): any {
|
||||||
return (window as any).web3;
|
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
|
// 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
|
// 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
|
// 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.
|
// 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
|
// 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
|
// Ethereum node, this call will throw. We need to handle this case gracefully
|
||||||
const injectedWeb3 = Blockchain._getInjectedWeb3();
|
const injectedWeb3IfExists = Blockchain._getInjectedWeb3();
|
||||||
let networkIdIfExists: number;
|
let networkIdIfExists: number;
|
||||||
if (!_.isUndefined(injectedWeb3)) {
|
if (!_.isUndefined(injectedWeb3IfExists)) {
|
||||||
try {
|
try {
|
||||||
networkIdIfExists = _.parseInt(await promisify<string>(injectedWeb3.version.getNetwork)());
|
networkIdIfExists = _.parseInt(await promisify<string>(injectedWeb3IfExists.version.getNetwork)());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Ignore error and proceed with networkId undefined
|
// Ignore error and proceed with networkId undefined
|
||||||
}
|
}
|
||||||
@@ -119,13 +119,13 @@ export class Blockchain {
|
|||||||
injectedWeb3: Web3,
|
injectedWeb3: Web3,
|
||||||
networkIdIfExists: number,
|
networkIdIfExists: number,
|
||||||
shouldUserLedgerProvider: boolean = false,
|
shouldUserLedgerProvider: boolean = false,
|
||||||
): Promise<[Provider, LedgerSubprovider]> {
|
): Promise<[Provider, LedgerSubprovider | undefined]> {
|
||||||
const doesInjectedWeb3Exist = !_.isUndefined(injectedWeb3);
|
const doesInjectedWeb3Exist = !_.isUndefined(injectedWeb3);
|
||||||
const isNetworkIdDefined = !_.isUndefined(networkIdIfExists);
|
const isNetworkIdAvailable = !_.isUndefined(networkIdIfExists);
|
||||||
const publicNodeUrlsIfExistsForNetworkId = configs.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkIdIfExists];
|
const publicNodeUrlsIfExistsForNetworkId = configs.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkIdIfExists];
|
||||||
const isPublicNodeAvailableForNetworkId = !_.isUndefined(publicNodeUrlsIfExistsForNetworkId);
|
const isPublicNodeAvailableForNetworkId = !_.isUndefined(publicNodeUrlsIfExistsForNetworkId);
|
||||||
|
|
||||||
if (shouldUserLedgerProvider && isNetworkIdDefined) {
|
if (shouldUserLedgerProvider && isNetworkIdAvailable) {
|
||||||
const isU2FSupported = await utils.isU2FSupportedAsync();
|
const isU2FSupported = await utils.isU2FSupportedAsync();
|
||||||
if (!isU2FSupported) {
|
if (!isU2FSupported) {
|
||||||
throw new Error('Cannot update providerType to LEDGER without U2F support');
|
throw new Error('Cannot update providerType to LEDGER without U2F support');
|
||||||
@@ -243,7 +243,7 @@ export class Blockchain {
|
|||||||
const shouldPollUserAddress = true;
|
const shouldPollUserAddress = true;
|
||||||
const shouldUserLedgerProvider = false;
|
const shouldUserLedgerProvider = false;
|
||||||
this._dispatcher.updateBlockchainIsLoaded(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();
|
const networkId = await Blockchain._getInjectedWeb3ProviderNetworkIdIfExistsAsync();
|
||||||
await this._resetOrInitializeAsync(networkId, shouldPollUserAddress, shouldUserLedgerProvider);
|
await this._resetOrInitializeAsync(networkId, shouldPollUserAddress, shouldUserLedgerProvider);
|
||||||
}
|
}
|
||||||
@@ -772,15 +772,15 @@ export class Blockchain {
|
|||||||
await utils.onPageLoadAsync(); // wait for page to load
|
await utils.onPageLoadAsync(); // wait for page to load
|
||||||
const networkIdIfExists = await Blockchain._getInjectedWeb3ProviderNetworkIdIfExistsAsync();
|
const networkIdIfExists = await Blockchain._getInjectedWeb3ProviderNetworkIdIfExistsAsync();
|
||||||
this.networkId = !_.isUndefined(networkIdIfExists) ? networkIdIfExists : constants.NETWORK_ID_MAINNET;
|
this.networkId = !_.isUndefined(networkIdIfExists) ? networkIdIfExists : constants.NETWORK_ID_MAINNET;
|
||||||
const injectedWeb3 = Blockchain._getInjectedWeb3();
|
const injectedWeb3IfExists = Blockchain._getInjectedWeb3();
|
||||||
if (injectedWeb3) {
|
if (injectedWeb3IfExists) {
|
||||||
const injectedProviderObservable = injectedWeb3.currentProvider.publicConfigStore;
|
const injectedProviderObservable = injectedWeb3IfExists.currentProvider.publicConfigStore;
|
||||||
if (injectedProviderObservable && !this._injectedProviderObservable) {
|
if (injectedProviderObservable && !this._injectedProviderObservable) {
|
||||||
this._injectedProviderObservable = injectedProviderObservable;
|
this._injectedProviderObservable = injectedProviderObservable;
|
||||||
this._injectedProviderObservable.subscribe(this._injectedProviderUpdateHandler);
|
this._injectedProviderObservable.subscribe(this._injectedProviderUpdateHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._updateProviderName(injectedWeb3);
|
this._updateProviderName(injectedWeb3IfExists);
|
||||||
const shouldPollUserAddress = true;
|
const shouldPollUserAddress = true;
|
||||||
const shouldUseLedgerProvider = false;
|
const shouldUseLedgerProvider = false;
|
||||||
await this._resetOrInitializeAsync(this.networkId, shouldPollUserAddress, shouldUseLedgerProvider);
|
await this._resetOrInitializeAsync(this.networkId, shouldPollUserAddress, shouldUseLedgerProvider);
|
||||||
@@ -793,9 +793,9 @@ export class Blockchain {
|
|||||||
this._dispatcher.updateBlockchainIsLoaded(false);
|
this._dispatcher.updateBlockchainIsLoaded(false);
|
||||||
this._dispatcher.updateUserWeiBalance(undefined);
|
this._dispatcher.updateUserWeiBalance(undefined);
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
const injectedWeb3 = Blockchain._getInjectedWeb3();
|
const injectedWeb3IfExists = Blockchain._getInjectedWeb3();
|
||||||
const [provider, ledgerSubproviderIfExists] = await Blockchain._getProviderAsync(
|
const [provider, ledgerSubproviderIfExists] = await Blockchain._getProviderAsync(
|
||||||
injectedWeb3,
|
injectedWeb3IfExists,
|
||||||
networkId,
|
networkId,
|
||||||
shouldUserLedgerProvider,
|
shouldUserLedgerProvider,
|
||||||
);
|
);
|
||||||
@@ -819,7 +819,7 @@ export class Blockchain {
|
|||||||
const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
|
const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
|
||||||
this._userAddressIfExists = userAddresses[0];
|
this._userAddressIfExists = userAddresses[0];
|
||||||
this._dispatcher.updateUserAddress(this._userAddressIfExists);
|
this._dispatcher.updateUserAddress(this._userAddressIfExists);
|
||||||
if (!_.isUndefined(injectedWeb3)) {
|
if (!_.isUndefined(injectedWeb3IfExists)) {
|
||||||
this._dispatcher.updateProviderType(ProviderType.Injected);
|
this._dispatcher.updateProviderType(ProviderType.Injected);
|
||||||
}
|
}
|
||||||
await this.fetchTokenInformationAsync();
|
await this.fetchTokenInformationAsync();
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ class PlainPortalOnboardingFlow extends React.Component<PortalOnboardingFlowProp
|
|||||||
const ethTokenState = this.props.trackedTokenStateByAddress[ethToken.address];
|
const ethTokenState = this.props.trackedTokenStateByAddress[ethToken.address];
|
||||||
const zrxTokenState = this.props.trackedTokenStateByAddress[zrxToken.address];
|
const zrxTokenState = this.props.trackedTokenStateByAddress[zrxToken.address];
|
||||||
if (ethTokenState && zrxTokenState) {
|
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;
|
return false;
|
||||||
@@ -223,15 +223,15 @@ class PlainPortalOnboardingFlow extends React.Component<PortalOnboardingFlowProp
|
|||||||
if (!token) {
|
if (!token) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const tokenState = this.props.trackedTokenStateByAddress[token.address];
|
const tokenStateIfExists = this.props.trackedTokenStateByAddress[token.address];
|
||||||
if (!tokenState) {
|
if (_.isUndefined(tokenStateIfExists)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<AllowanceToggle
|
<AllowanceToggle
|
||||||
token={token}
|
token={token}
|
||||||
tokenState={tokenState}
|
tokenState={tokenStateIfExists}
|
||||||
isDisabled={!tokenState.isLoaded}
|
isDisabled={!tokenStateIfExists.isLoaded}
|
||||||
blockchain={this.props.blockchain}
|
blockchain={this.props.blockchain}
|
||||||
// tslint:disable-next-line:jsx-no-lambda
|
// tslint:disable-next-line:jsx-no-lambda
|
||||||
refetchTokenStateAsync={async () => this.props.refetchTokenStateAsync(token.address)}
|
refetchTokenStateAsync={async () => this.props.refetchTokenStateAsync(token.address)}
|
||||||
|
|||||||
Reference in New Issue
Block a user