fix(website): do not fetch balances for empty tokens

This commit is contained in:
Brandon Millman 2018-10-22 10:56:11 -07:00
parent 38eaacdd44
commit 2bb53d5b1d

View File

@ -210,12 +210,16 @@ export class Portal extends React.Component<PortalProps, PortalState> {
isLoaded: false, isLoaded: false,
}; };
} }
this.setState({ this.setState(
{
trackedTokenStateByAddress, trackedTokenStateByAddress,
}); },
() => {
// Fetch the actual balance/allowance. // Fetch the actual balance/allowance.
// tslint:disable-next-line:no-floating-promises // tslint:disable-next-line:no-floating-promises
this._fetchBalancesAndAllowancesAsync(newTokenAddresses); this._fetchBalancesAndAllowancesAsync(newTokenAddresses);
},
);
} }
} }
public render(): React.ReactNode { public render(): React.ReactNode {
@ -644,6 +648,9 @@ export class Portal extends React.Component<PortalProps, PortalState> {
} }
private async _fetchBalancesAndAllowancesAsync(tokenAddresses: string[]): Promise<void> { private async _fetchBalancesAndAllowancesAsync(tokenAddresses: string[]): Promise<void> {
if (_.isEmpty(tokenAddresses)) {
return;
}
const trackedTokenStateByAddress = this.state.trackedTokenStateByAddress; const trackedTokenStateByAddress = this.state.trackedTokenStateByAddress;
const userAddressIfExists = _.isEmpty(this.props.userAddress) ? undefined : this.props.userAddress; const userAddressIfExists = _.isEmpty(this.props.userAddress) ? undefined : this.props.userAddress;
const balancesAndAllowances = await Promise.all( const balancesAndAllowances = await Promise.all(