diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-06-01 03:00:31 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-06-05 01:27:24 +0800 |
commit | c8421efcd32af9dbe58b433fdb97d009a6d89b84 (patch) | |
tree | 31893e7a08edb731a95928677f455a58c84f383d /packages/website | |
parent | f382609d01ab86da52a746ba24ddd73a1a507aa6 (diff) | |
download | dexon-sol-tools-c8421efcd32af9dbe58b433fdb97d009a6d89b84.tar dexon-sol-tools-c8421efcd32af9dbe58b433fdb97d009a6d89b84.tar.gz dexon-sol-tools-c8421efcd32af9dbe58b433fdb97d009a6d89b84.tar.bz2 dexon-sol-tools-c8421efcd32af9dbe58b433fdb97d009a6d89b84.tar.lz dexon-sol-tools-c8421efcd32af9dbe58b433fdb97d009a6d89b84.tar.xz dexon-sol-tools-c8421efcd32af9dbe58b433fdb97d009a6d89b84.tar.zst dexon-sol-tools-c8421efcd32af9dbe58b433fdb97d009a6d89b84.zip |
Address feedback
Diffstat (limited to 'packages/website')
4 files changed, 20 insertions, 14 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 212e829dd..6e4d03e27 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -506,7 +506,7 @@ export class Blockchain { public async getTokenBalanceAndAllowanceAsync( ownerAddressIfExists: string, tokenAddress: string, - ): Promise<BigNumber[]> { + ): Promise<[BigNumber, BigNumber]> { utils.assert(!_.isUndefined(this._contractWrappers), 'ContractWrappers must be instantiated.'); if (_.isUndefined(ownerAddressIfExists)) { @@ -516,8 +516,10 @@ export class Blockchain { let balance = new BigNumber(0); let allowance = new BigNumber(0); if (this._doesUserAddressExist()) { - balance = await this._contractWrappers.token.getBalanceAsync(tokenAddress, ownerAddressIfExists); - allowance = await this._contractWrappers.token.getProxyAllowanceAsync(tokenAddress, ownerAddressIfExists); + [balance, allowance] = await Promise.all([ + this._contractWrappers.token.getBalanceAsync(tokenAddress, ownerAddressIfExists), + this._contractWrappers.token.getProxyAllowanceAsync(tokenAddress, ownerAddressIfExists), + ]); } return [balance, allowance]; } diff --git a/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx b/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx index 398ce0141..bf52684d7 100644 --- a/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx +++ b/packages/website/ts/components/onboarding/portal_onboarding_flow.tsx @@ -69,13 +69,13 @@ export class PortalOnboardingFlow extends React.Component<PortalOnboardingFlowPr target: '.eth-row', content: 'Before you begin you will need to send some ETH to your metamask wallet', placement: 'right', - continueButtonDisplay: this._userHasEth() ? 'enabled' : 'disabled', + continueButtonDisplay: this._userHasVisibleEth() ? 'enabled' : 'disabled', }, { target: '.weth-row', content: 'You need to convert some of your ETH into tradeable Wrapped ETH (WETH)', placement: 'right', - continueButtonDisplay: this._userHasWeth() ? 'enabled' : 'disabled', + continueButtonDisplay: this._userHasVisibleWeth() ? 'enabled' : 'disabled', }, ]; return steps; @@ -85,11 +85,11 @@ export class PortalOnboardingFlow extends React.Component<PortalOnboardingFlowPr return !_.isEmpty(this.props.userAddress); } - private _userHasEth(): boolean { + private _userHasVisibleEth(): boolean { return this.props.userEtherBalanceInWei > new BigNumber(0); } - private _userHasWeth(): boolean { + private _userHasVisibleWeth(): boolean { const ethToken = utils.getEthToken(this.props.tokenByAddress); if (!ethToken) { return false; diff --git a/packages/website/ts/components/portal/portal.tsx b/packages/website/ts/components/portal/portal.tsx index 15654083f..9aa83546a 100644 --- a/packages/website/ts/components/portal/portal.tsx +++ b/packages/website/ts/components/portal/portal.tsx @@ -582,11 +582,15 @@ export class Portal extends React.Component<PortalProps, PortalState> { private async _fetchBalancesAndAllowancesAsync(tokenAddresses: string[]): Promise<void> { const trackedTokenStateByAddress = this.state.trackedTokenStateByAddress; const userAddressIfExists = _.isEmpty(this.props.userAddress) ? undefined : this.props.userAddress; - for (const tokenAddress of tokenAddresses) { - const [balance, allowance] = await this._blockchain.getTokenBalanceAndAllowanceAsync( - userAddressIfExists, - tokenAddress, - ); + const balancesAndAllowances = await Promise.all( + tokenAddresses.map(async tokenAddress => { + return this._blockchain.getTokenBalanceAndAllowanceAsync(userAddressIfExists, tokenAddress); + }), + ); + for (let i = 0; i < tokenAddresses.length; i++) { + // Order is preserved in Promise.all + const [balance, allowance] = balancesAndAllowances[i]; + const tokenAddress = tokenAddresses[i]; trackedTokenStateByAddress[tokenAddress] = { balance, allowance, diff --git a/packages/website/ts/components/wallet/wallet.tsx b/packages/website/ts/components/wallet/wallet.tsx index af6b216c5..7059ca350 100644 --- a/packages/website/ts/components/wallet/wallet.tsx +++ b/packages/website/ts/components/wallet/wallet.tsx @@ -404,7 +404,7 @@ export class Wallet extends React.Component<WalletProps, WalletState> { lastForceTokenStateRefetch={this.props.lastForceTokenStateRefetch} onConversionSuccessful={this._closeWrappedEtherActionRow.bind(this)} // tslint:disable:jsx-no-lambda - refetchEthTokenStateAsync={() => this.props.refetchTokenStateAsync(etherToken.address)} + refetchEthTokenStateAsync={async () => this.props.refetchTokenStateAsync(etherToken.address)} /> )} </div> @@ -440,7 +440,7 @@ export class Wallet extends React.Component<WalletProps, WalletState> { onErrorOccurred={_.noop} // TODO: Error handling userAddress={this.props.userAddress} isDisabled={!config.tokenState.isLoaded} - refetchTokenStateAsync={() => this.props.refetchTokenStateAsync(config.token.address)} + refetchTokenStateAsync={async () => this.props.refetchTokenStateAsync(config.token.address)} /> ); } |