fix coin selection bug

pull/571/head
Vladimir Volek 5 years ago
parent 3f50ef5343
commit e034d103aa

@ -1,6 +1,6 @@
/* @flow */ /* @flow */
import styled from 'styled-components'; import styled from 'styled-components';
import React, { PureComponent } from 'react'; import React, { Component } from 'react';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { FONT_SIZE } from 'config/variables'; import { FONT_SIZE } from 'config/variables';
import coins from 'constants/coins'; import coins from 'constants/coins';
@ -23,6 +23,11 @@ type State = {
showAllCoinsExternal: boolean, showAllCoinsExternal: boolean,
}; };
type NextProps = {
hiddenCoins: Array<string>,
hiddenCoinsExternal: Array<string>,
};
const Wrapper = styled.div` const Wrapper = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -96,7 +101,7 @@ const ToggleAll = styled.div`
cursor: pointer; cursor: pointer;
`; `;
class CoinsSettings extends PureComponent<Props, State> { class CoinsSettings extends Component<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.state = { this.state = {
@ -105,6 +110,24 @@ class CoinsSettings extends PureComponent<Props, State> {
}; };
} }
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() { render() {
const { props } = this; const { props } = this;
return ( return (
@ -142,13 +165,9 @@ class CoinsSettings extends PureComponent<Props, State> {
!this.state.showAllCoins, !this.state.showAllCoins,
false false
); );
this.setState(prevState => ({
showAllCoins: !prevState.showAllCoins,
}));
}} }}
> >
{props.hiddenCoins.length > 0 ? 'Show all' : 'Hide all'} {props.hiddenCoins.length === 0 ? 'Hide all' : 'Show all'}
</ToggleAll> </ToggleAll>
</Right> </Right>
</Label> </Label>
@ -212,13 +231,11 @@ class CoinsSettings extends PureComponent<Props, State> {
!this.state.showAllCoinsExternal, !this.state.showAllCoinsExternal,
true true
); );
this.setState(prevState => ({
showAllCoinsExternal: !prevState.showAllCoinsExternal,
}));
}} }}
> >
{props.hiddenCoinsExternal.length > 0 ? 'Show all' : 'Hide all'} {props.hiddenCoinsExternal.length === 0
? 'Hide all'
: 'Show all'}
</ToggleAll> </ToggleAll>
</Right> </Right>
</Label> </Label>

Loading…
Cancel
Save