dispatch new action

pull/513/head
Vladimir Volek 5 years ago
parent cc217c7aa1
commit 184d8a2b23

@ -354,7 +354,7 @@ export const getImportedAccounts = (): ?Array<Account> => {
export const handleCoinVisibility = ( export const handleCoinVisibility = (
coinShortcut: String, coinShortcut: String,
shouldBeVisible: boolean shouldBeVisible: boolean
): ThunkAction => (): void => { ): ThunkAction => (dispatch: Dispatch): void => {
const configuration: ?Array<String> = getHiddenCoins(); const configuration: ?Array<String> = getHiddenCoins();
let newConfig = configuration; let newConfig = configuration;
const isAlreadyHidden = configuration.find(coin => coin === coinShortcut); const isAlreadyHidden = configuration.find(coin => coin === coinShortcut);
@ -366,6 +366,10 @@ export const handleCoinVisibility = (
} }
storageUtils.set(TYPE, KEY_HIDDEN_COINS, JSON.stringify(newConfig)); storageUtils.set(TYPE, KEY_HIDDEN_COINS, JSON.stringify(newConfig));
dispatch({
type: WALLET.SET_HIDDEN_COINS,
hiddenCoins: newConfig,
});
}; };
export const getHiddenCoins = (): ?Array<String> => { export const getHiddenCoins = (): ?Array<String> => {

@ -19,3 +19,4 @@ export const TOGGLE_SIDEBAR: 'wallet__toggle_sidebar' = 'wallet__toggle_sidebar'
export const SET_LANGUAGE: 'wallet__set_language' = 'wallet__set_language'; export const SET_LANGUAGE: 'wallet__set_language' = 'wallet__set_language';
export const SET_LOCAL_CURRENCY: 'wallet__set_local_currency' = 'wallet__set_local_currency'; export const SET_LOCAL_CURRENCY: 'wallet__set_local_currency' = 'wallet__set_local_currency';
export const SET_HIDE_BALANCE: 'wallet__set_hide_balance' = 'wallet__set_hide_balance'; export const SET_HIDE_BALANCE: 'wallet__set_hide_balance' = 'wallet__set_hide_balance';
export const SET_HIDDEN_COINS: 'wallet__set_hidden_coins' = 'wallet__set_hidden_coins';

@ -24,6 +24,7 @@ type State = {
firstLocationChange: boolean, firstLocationChange: boolean,
disconnectRequest: ?TrezorDevice, disconnectRequest: ?TrezorDevice,
selectedDevice: ?TrezorDevice, selectedDevice: ?TrezorDevice,
hiddenCoins: ?Array<String>,
}; };
const initialState: State = { const initialState: State = {
@ -41,6 +42,7 @@ const initialState: State = {
initialPathname: null, initialPathname: null,
disconnectRequest: null, disconnectRequest: null,
selectedDevice: null, selectedDevice: null,
hiddenCoins: [],
}; };
export default function wallet(state: State = initialState, action: Action): State { export default function wallet(state: State = initialState, action: Action): State {
@ -145,6 +147,12 @@ export default function wallet(state: State = initialState, action: Action): Sta
hideBalance: action.toggled, hideBalance: action.toggled,
}; };
case WALLET.SET_HIDDEN_COINS:
return {
...state,
hiddenCoins: action.hiddenCoins,
};
default: default:
return state; return state;
} }

@ -1,6 +1,6 @@
/* @flow */ /* @flow */
import styled from 'styled-components'; import styled from 'styled-components';
import React, { Component } from 'react'; import React from 'react';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { FONT_SIZE } from 'config/variables'; import { FONT_SIZE } from 'config/variables';
@ -62,41 +62,36 @@ const LogoWrapper = styled.div`
align-items: center; align-items: center;
`; `;
class CoinsSettings extends Component { const CoinsSettings = (props: Props) => (
render() { <Wrapper>
const { networks, handleCoinVisibility } = this.props; <Row>
return ( <Label>
<Wrapper> <FormattedMessage {...l10nMessages.TR_VISIBLE_COINS} />
<Row> </Label>
<Label> <Content>
<FormattedMessage {...l10nMessages.TR_VISIBLE_COINS} /> {props.networks
</Label> .filter(network => !network.isHidden)
<Content> .map(network => (
{networks <CoinRow key={network.shortcut}>
.filter(network => !network.isHidden) <Left>
.map(network => ( <LogoWrapper>
<CoinRow key={network.shortcut}> <CoinLogo height="23" network={network.shortcut} />
<Left> </LogoWrapper>
<LogoWrapper> <Name>{network.name}</Name>
<CoinLogo height="23" network={network.shortcut} /> </Left>
</LogoWrapper> <Right>
<Name>{network.name}</Name> <Switch
</Left> onChange={isVisible => {
<Right> props.handleCoinVisibility(network.shortcut, !isVisible);
<Switch }}
onChange={isVisible => { checked={props.hiddenCoins.includes(network.shortcut)}
handleCoinVisibility(network.shortcut, !isVisible); />
}} </Right>
checked </CoinRow>
/> ))}
</Right> </Content>
</CoinRow> </Row>
))} </Wrapper>
</Content> );
</Row>
</Wrapper>
);
}
}
export default CoinsSettings; export default CoinsSettings;

@ -78,7 +78,6 @@ const buildCurrencyOption = currency => {
const WalletSettings = (props: Props) => ( const WalletSettings = (props: Props) => (
<StyledContent> <StyledContent>
{console.log(props.localStorage)}
<Section> <Section>
<LabelTop> <LabelTop>
<FormattedMessage {...l10nMessages.TR_LOCAL_CURRENCY} /> <FormattedMessage {...l10nMessages.TR_LOCAL_CURRENCY} />
@ -115,6 +114,7 @@ const WalletSettings = (props: Props) => (
<Coins <Coins
networks={props.localStorage.config.networks} networks={props.localStorage.config.networks}
handleCoinVisibility={props.handleCoinVisibility} handleCoinVisibility={props.handleCoinVisibility}
hiddenCoins={props.wallet.hiddenCoins}
/> />
</Section> </Section>
<Actions> <Actions>

Loading…
Cancel
Save