mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-27 10:48:22 +00:00
add logic for hiding coins
This commit is contained in:
parent
0833d1597a
commit
cc217c7aa1
@ -60,6 +60,7 @@ const KEY_BETA_MODAL: string = '/betaModalPrivacy'; // this key needs to be comp
|
|||||||
const KEY_LANGUAGE: string = `${STORAGE_PATH}language`;
|
const KEY_LANGUAGE: string = `${STORAGE_PATH}language`;
|
||||||
const KEY_LOCAL_CURRENCY: string = `${STORAGE_PATH}localCurrency`;
|
const KEY_LOCAL_CURRENCY: string = `${STORAGE_PATH}localCurrency`;
|
||||||
const KEY_HIDE_BALANCE: string = `${STORAGE_PATH}hideBalance`;
|
const KEY_HIDE_BALANCE: string = `${STORAGE_PATH}hideBalance`;
|
||||||
|
const KEY_HIDDEN_COINS: string = `${STORAGE_PATH}hiddenCoins`;
|
||||||
|
|
||||||
// https://github.com/STRML/react-localstorage/blob/master/react-localstorage.js
|
// https://github.com/STRML/react-localstorage/blob/master/react-localstorage.js
|
||||||
// or
|
// or
|
||||||
@ -350,6 +351,31 @@ export const getImportedAccounts = (): ?Array<Account> => {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const handleCoinVisibility = (
|
||||||
|
coinShortcut: String,
|
||||||
|
shouldBeVisible: boolean
|
||||||
|
): ThunkAction => (): void => {
|
||||||
|
const configuration: ?Array<String> = getHiddenCoins();
|
||||||
|
let newConfig = configuration;
|
||||||
|
const isAlreadyHidden = configuration.find(coin => coin === coinShortcut);
|
||||||
|
|
||||||
|
if (isAlreadyHidden && shouldBeVisible) {
|
||||||
|
newConfig = configuration.filter(coin => coin !== coinShortcut);
|
||||||
|
} else if (!isAlreadyHidden) {
|
||||||
|
newConfig = [...configuration, coinShortcut];
|
||||||
|
}
|
||||||
|
|
||||||
|
storageUtils.set(TYPE, KEY_HIDDEN_COINS, JSON.stringify(newConfig));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getHiddenCoins = (): ?Array<String> => {
|
||||||
|
const coinsConfig: ?string = storageUtils.get(TYPE, KEY_HIDDEN_COINS);
|
||||||
|
if (coinsConfig) {
|
||||||
|
return JSON.parse(coinsConfig);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
export const removeImportedAccounts = (device: TrezorDevice): ThunkAction => (
|
export const removeImportedAccounts = (device: TrezorDevice): ThunkAction => (
|
||||||
dispatch: Dispatch
|
dispatch: Dispatch
|
||||||
): void => {
|
): void => {
|
||||||
|
@ -5,6 +5,7 @@ import { injectIntl } from 'react-intl';
|
|||||||
import type { IntlShape } from 'react-intl';
|
import type { IntlShape } from 'react-intl';
|
||||||
|
|
||||||
import * as WalletActions from 'actions/WalletActions';
|
import * as WalletActions from 'actions/WalletActions';
|
||||||
|
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
||||||
import type { State, Dispatch } from 'flowtype';
|
import type { State, Dispatch } from 'flowtype';
|
||||||
import WalletSettings from './index';
|
import WalletSettings from './index';
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ type StateProps = {|
|
|||||||
type DispatchProps = {|
|
type DispatchProps = {|
|
||||||
setLocalCurrency: typeof WalletActions.setLocalCurrency,
|
setLocalCurrency: typeof WalletActions.setLocalCurrency,
|
||||||
setHideBalance: typeof WalletActions.setHideBalance,
|
setHideBalance: typeof WalletActions.setHideBalance,
|
||||||
|
handleCoinVisibility: typeof LocalStorageActions.handleCoinVisibility,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
export type Props = {| ...OwnProps, ...StateProps, ...DispatchProps |};
|
export type Props = {| ...OwnProps, ...StateProps, ...DispatchProps |};
|
||||||
@ -34,6 +36,7 @@ const mapStateToProps = (state: State): StateProps => ({
|
|||||||
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
|
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
|
||||||
setLocalCurrency: bindActionCreators(WalletActions.setLocalCurrency, dispatch),
|
setLocalCurrency: bindActionCreators(WalletActions.setLocalCurrency, dispatch),
|
||||||
setHideBalance: bindActionCreators(WalletActions.setHideBalance, dispatch),
|
setHideBalance: bindActionCreators(WalletActions.setHideBalance, dispatch),
|
||||||
|
handleCoinVisibility: bindActionCreators(LocalStorageActions.handleCoinVisibility, dispatch),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default injectIntl<OwnProps>(
|
export default injectIntl<OwnProps>(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import React 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';
|
||||||
|
|
||||||
@ -62,31 +62,41 @@ const LogoWrapper = styled.div`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const CoinsSettings = (props: Props) => (
|
class CoinsSettings extends Component {
|
||||||
<Wrapper>
|
render() {
|
||||||
<Row>
|
const { networks, handleCoinVisibility } = this.props;
|
||||||
<Label>
|
return (
|
||||||
<FormattedMessage {...l10nMessages.TR_VISIBLE_COINS} />
|
<Wrapper>
|
||||||
</Label>
|
<Row>
|
||||||
<Content>
|
<Label>
|
||||||
{props.networks
|
<FormattedMessage {...l10nMessages.TR_VISIBLE_COINS} />
|
||||||
.filter(network => !network.isHidden)
|
</Label>
|
||||||
.map(network => (
|
<Content>
|
||||||
<CoinRow key={network.shortcut}>
|
{networks
|
||||||
<Left>
|
.filter(network => !network.isHidden)
|
||||||
<LogoWrapper>
|
.map(network => (
|
||||||
<CoinLogo height="23" network={network.shortcut} />
|
<CoinRow key={network.shortcut}>
|
||||||
</LogoWrapper>
|
<Left>
|
||||||
<Name>{network.name}</Name>
|
<LogoWrapper>
|
||||||
</Left>
|
<CoinLogo height="23" network={network.shortcut} />
|
||||||
<Right>
|
</LogoWrapper>
|
||||||
<Switch onChange={() => {}} checked />
|
<Name>{network.name}</Name>
|
||||||
</Right>
|
</Left>
|
||||||
</CoinRow>
|
<Right>
|
||||||
))}
|
<Switch
|
||||||
</Content>
|
onChange={isVisible => {
|
||||||
</Row>
|
handleCoinVisibility(network.shortcut, !isVisible);
|
||||||
</Wrapper>
|
}}
|
||||||
);
|
checked
|
||||||
|
/>
|
||||||
|
</Right>
|
||||||
|
</CoinRow>
|
||||||
|
))}
|
||||||
|
</Content>
|
||||||
|
</Row>
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default CoinsSettings;
|
export default CoinsSettings;
|
||||||
|
@ -78,6 +78,7 @@ 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} />
|
||||||
@ -111,7 +112,10 @@ const WalletSettings = (props: Props) => (
|
|||||||
</Row>
|
</Row>
|
||||||
</Section>
|
</Section>
|
||||||
<Section>
|
<Section>
|
||||||
<Coins networks={props.localStorage.config.networks} />
|
<Coins
|
||||||
|
networks={props.localStorage.config.networks}
|
||||||
|
handleCoinVisibility={props.handleCoinVisibility}
|
||||||
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
<Actions>
|
<Actions>
|
||||||
<Info>
|
<Info>
|
||||||
|
Loading…
Reference in New Issue
Block a user