From e034d103aaa7dad6bbc24a7df38f86accbdd112b Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Mon, 27 May 2019 14:48:38 +0200 Subject: [PATCH] fix coin selection bug --- .../WalletSettings/components/Coins/index.js | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/views/Wallet/views/WalletSettings/components/Coins/index.js b/src/views/Wallet/views/WalletSettings/components/Coins/index.js index 21aab25a..b0234201 100644 --- a/src/views/Wallet/views/WalletSettings/components/Coins/index.js +++ b/src/views/Wallet/views/WalletSettings/components/Coins/index.js @@ -1,6 +1,6 @@ /* @flow */ import styled from 'styled-components'; -import React, { PureComponent } from 'react'; +import React, { Component } from 'react'; import { FormattedMessage } from 'react-intl'; import { FONT_SIZE } from 'config/variables'; import coins from 'constants/coins'; @@ -23,6 +23,11 @@ type State = { showAllCoinsExternal: boolean, }; +type NextProps = { + hiddenCoins: Array, + hiddenCoinsExternal: Array, +}; + const Wrapper = styled.div` display: flex; flex-direction: column; @@ -96,7 +101,7 @@ const ToggleAll = styled.div` cursor: pointer; `; -class CoinsSettings extends PureComponent { +class CoinsSettings extends Component { constructor(props: Props) { super(props); this.state = { @@ -105,6 +110,24 @@ class CoinsSettings extends PureComponent { }; } + componentWillReceiveProps(nextProps: NextProps) { + if (nextProps.hiddenCoins.length > 0) { + this.setState({ showAllCoins: false }); + } else { + this.setState({ + showAllCoins: true, + }); + } + + if (nextProps.hiddenCoinsExternal.length > 0) { + this.setState({ showAllCoinsExternal: false }); + } else { + this.setState({ + showAllCoinsExternal: true, + }); + } + } + render() { const { props } = this; return ( @@ -142,13 +165,9 @@ class CoinsSettings extends PureComponent { !this.state.showAllCoins, false ); - - this.setState(prevState => ({ - showAllCoins: !prevState.showAllCoins, - })); }} > - {props.hiddenCoins.length > 0 ? 'Show all' : 'Hide all'} + {props.hiddenCoins.length === 0 ? 'Hide all' : 'Show all'} @@ -212,13 +231,11 @@ class CoinsSettings extends PureComponent { !this.state.showAllCoinsExternal, true ); - - this.setState(prevState => ({ - showAllCoinsExternal: !prevState.showAllCoinsExternal, - })); }} > - {props.hiddenCoinsExternal.length > 0 ? 'Show all' : 'Hide all'} + {props.hiddenCoinsExternal.length === 0 + ? 'Hide all' + : 'Show all'}