aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/token_balances.tsx
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-01-31 03:12:32 +0800
committerFabio Berger <me@fabioberger.com>2018-01-31 03:12:32 +0800
commite219772b2a25712f41fb819be36917d3b889201f (patch)
treec9720d042e65d896c33d68eed918e69c3ad3771c /packages/website/ts/components/token_balances.tsx
parent144a507a2e0e341e8c8b97f67a25e1283ebc3687 (diff)
downloaddexon-0x-contracts-e219772b2a25712f41fb819be36917d3b889201f.tar.gz
dexon-0x-contracts-e219772b2a25712f41fb819be36917d3b889201f.tar.zst
dexon-0x-contracts-e219772b2a25712f41fb819be36917d3b889201f.zip
Fix all setState calls after unmounted errors. Decided to create our own flag rather then using a cancellablePromise since there was little to be gained from this alternative
Diffstat (limited to 'packages/website/ts/components/token_balances.tsx')
-rw-r--r--packages/website/ts/components/token_balances.tsx13
1 files changed, 10 insertions, 3 deletions
diff --git a/packages/website/ts/components/token_balances.tsx b/packages/website/ts/components/token_balances.tsx
index 776ccb16e..c0df285cf 100644
--- a/packages/website/ts/components/token_balances.tsx
+++ b/packages/website/ts/components/token_balances.tsx
@@ -91,8 +91,10 @@ interface TokenBalancesState {
}
export class TokenBalances extends React.Component<TokenBalancesProps, TokenBalancesState> {
+ private _isUnmounted: boolean;
public constructor(props: TokenBalancesProps) {
super(props);
+ this._isUnmounted = false;
const initialTrackedTokenStateByAddress = this._getInitialTrackedTokenStateByAddress(props.trackedTokens);
this.state = {
errorType: undefined,
@@ -109,6 +111,9 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
const trackedTokenAddresses = _.keys(this.state.trackedTokenStateByAddress);
this._fetchBalancesAndAllowancesAsync(trackedTokenAddresses);
}
+ public componentWillUnmount() {
+ this._isUnmounted = true;
+ }
public componentWillReceiveProps(nextProps: TokenBalancesProps) {
if (nextProps.userEtherBalance !== this.props.userEtherBalance) {
if (this.state.isBalanceSpinnerVisible) {
@@ -671,9 +676,11 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
isLoaded: true,
};
}
- this.setState({
- trackedTokenStateByAddress,
- });
+ if (!this._isUnmounted) {
+ this.setState({
+ trackedTokenStateByAddress,
+ });
+ }
}
private _getInitialTrackedTokenStateByAddress(trackedTokens: Token[]) {
const trackedTokenStateByAddress: TokenStateByAddress = {};