diff options
author | Fabio Berger <me@fabioberger.com> | 2018-01-31 03:12:32 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-01-31 03:12:32 +0800 |
commit | e219772b2a25712f41fb819be36917d3b889201f (patch) | |
tree | c9720d042e65d896c33d68eed918e69c3ad3771c /packages/website/ts/components/eth_wrappers.tsx | |
parent | 144a507a2e0e341e8c8b97f67a25e1283ebc3687 (diff) | |
download | dexon-sol-tools-e219772b2a25712f41fb819be36917d3b889201f.tar.gz dexon-sol-tools-e219772b2a25712f41fb819be36917d3b889201f.tar.zst dexon-sol-tools-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/eth_wrappers.tsx')
-rw-r--r-- | packages/website/ts/components/eth_wrappers.tsx | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/packages/website/ts/components/eth_wrappers.tsx b/packages/website/ts/components/eth_wrappers.tsx index 460a6cae3..90d2c0514 100644 --- a/packages/website/ts/components/eth_wrappers.tsx +++ b/packages/website/ts/components/eth_wrappers.tsx @@ -54,8 +54,10 @@ interface EthWrappersState { } export class EthWrappers extends React.Component<EthWrappersProps, EthWrappersState> { + private _isUnmounted: boolean; constructor(props: EthWrappersProps) { super(props); + this._isUnmounted = false; const outdatedWETHAddresses = this._getOutdatedWETHAddresses(); const outdatedWETHAddressToIsStateLoaded: OutdatedWETHAddressToIsStateLoaded = {}; const outdatedWETHStateByAddress: OutdatedWETHStateByAddress = {}; @@ -91,6 +93,9 @@ export class EthWrappers extends React.Component<EthWrappersProps, EthWrappersSt // tslint:disable-next-line:no-floating-promises this._fetchWETHStateAsync(); } + public componentWillUnmount() { + this._isUnmounted = true; + } public render() { const etherToken = this._getEthToken(); const wethBalance = ZeroEx.toUnitAmount(this.state.ethTokenState.balance, constants.DECIMAL_PLACES_ETH); @@ -394,15 +399,17 @@ export class EthWrappers extends React.Component<EthWrappersProps, EthWrappersSt }; outdatedWETHAddressToIsStateLoaded[address] = true; } - this.setState({ - outdatedWETHStateByAddress, - outdatedWETHAddressToIsStateLoaded, - ethTokenState: { - balance: wethBalance, - allowance: wethAllowance, - }, - isWethStateLoaded: true, - }); + if (!this._isUnmounted) { + this.setState({ + outdatedWETHStateByAddress, + outdatedWETHAddressToIsStateLoaded, + ethTokenState: { + balance: wethBalance, + allowance: wethAllowance, + }, + isWethStateLoaded: true, + }); + } } private _getOutdatedWETHAddresses(): string[] { const outdatedWETHAddresses = _.compact( |