mirror of
https://github.com/trezor/trezor-wallet
synced 2025-03-22 02:55:44 +00:00
split hidden coins, toggle all
This commit is contained in:
parent
59a3284e67
commit
e32d7a32bd
@ -60,6 +60,7 @@ const KEY_LANGUAGE: string = `${STORAGE_PATH}language`;
|
||||
const KEY_LOCAL_CURRENCY: string = `${STORAGE_PATH}localCurrency`;
|
||||
const KEY_HIDE_BALANCE: string = `${STORAGE_PATH}hideBalance`;
|
||||
const KEY_HIDDEN_COINS: string = `${STORAGE_PATH}hiddenCoins`;
|
||||
const KEY_HIDDEN_COINS_EXTERNAL: string = `${STORAGE_PATH}hiddenCoinsExternal`;
|
||||
|
||||
// https://github.com/STRML/react-localstorage/blob/master/react-localstorage.js
|
||||
// or
|
||||
@ -247,13 +248,18 @@ const loadStorageData = (): ThunkAction => (dispatch: Dispatch): void => {
|
||||
});
|
||||
}
|
||||
|
||||
const hiddenCoins = getHiddenCoins();
|
||||
if (hiddenCoins) {
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS,
|
||||
hiddenCoins,
|
||||
});
|
||||
}
|
||||
const hiddenCoins = getHiddenCoins(false);
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS,
|
||||
hiddenCoins,
|
||||
});
|
||||
|
||||
const isExternal = true;
|
||||
const hiddenCoinsExternal = getHiddenCoins(isExternal);
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS_EXTERNAL,
|
||||
hiddenCoinsExternal,
|
||||
});
|
||||
|
||||
const userTokens: ?string = storageUtils.get(TYPE, KEY_TOKENS);
|
||||
if (userTokens) {
|
||||
@ -360,9 +366,10 @@ export const getImportedAccounts = (): ?Array<Account> => {
|
||||
|
||||
export const handleCoinVisibility = (
|
||||
coinShortcut: string,
|
||||
shouldBeVisible: boolean
|
||||
shouldBeVisible: boolean,
|
||||
isExternal: boolean
|
||||
): ThunkAction => (dispatch: Dispatch): void => {
|
||||
const configuration: Array<string> = getHiddenCoins();
|
||||
const configuration: Array<string> = getHiddenCoins(isExternal);
|
||||
let newConfig: Array<string> = configuration;
|
||||
const isAlreadyHidden = configuration.find(coin => coin === coinShortcut);
|
||||
|
||||
@ -372,45 +379,68 @@ export const handleCoinVisibility = (
|
||||
newConfig = [...configuration, coinShortcut];
|
||||
}
|
||||
|
||||
storageUtils.set(TYPE, KEY_HIDDEN_COINS, JSON.stringify(newConfig));
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS,
|
||||
hiddenCoins: newConfig,
|
||||
});
|
||||
console.log(coinShortcut, shouldBeVisible, isExternal);
|
||||
|
||||
if (isExternal) {
|
||||
storageUtils.set(TYPE, KEY_HIDDEN_COINS_EXTERNAL, JSON.stringify(newConfig));
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS_EXTERNAL,
|
||||
hiddenCoinsExternal: newConfig,
|
||||
});
|
||||
} else {
|
||||
storageUtils.set(TYPE, KEY_HIDDEN_COINS, JSON.stringify(newConfig));
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS,
|
||||
hiddenCoins: newConfig,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const handleAllCoinsVisibility = (
|
||||
checked: boolean,
|
||||
export const toggleGroupCoinsVisibility = (
|
||||
allCoins: Array<string>,
|
||||
hiddenCoins: Array<string>
|
||||
checked: boolean,
|
||||
isExternal: boolean
|
||||
): ThunkAction => (dispatch: Dispatch) => {
|
||||
const configuration: Array<string> = getHiddenCoins();
|
||||
const newConfig: Array<string> = configuration;
|
||||
let result = [];
|
||||
|
||||
console.log('old config', newConfig);
|
||||
|
||||
if (checked) {
|
||||
const intersection = allCoins.filter(x => hiddenCoins.includes(x));
|
||||
if (intersection) {
|
||||
result = newConfig.filter(x => !intersection.includes(x));
|
||||
}
|
||||
} else {
|
||||
const intersection = allCoins.filter(x => hiddenCoins.includes(x));
|
||||
console.log('intersection', intersection);
|
||||
result = [configuration, ...intersection];
|
||||
if (checked && isExternal) {
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS_EXTERNAL,
|
||||
hiddenCoinsExternal: [],
|
||||
});
|
||||
storageUtils.set(TYPE, KEY_HIDDEN_COINS_EXTERNAL, JSON.stringify([]));
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS,
|
||||
hiddenCoins: result,
|
||||
});
|
||||
if (!checked && isExternal) {
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS_EXTERNAL,
|
||||
hiddenCoinsExternal: allCoins,
|
||||
});
|
||||
storageUtils.set(TYPE, KEY_HIDDEN_COINS_EXTERNAL, JSON.stringify(allCoins));
|
||||
}
|
||||
|
||||
storageUtils.set(TYPE, KEY_HIDDEN_COINS, JSON.stringify(result));
|
||||
if (checked && !isExternal) {
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS,
|
||||
hiddenCoins: [],
|
||||
});
|
||||
storageUtils.set(TYPE, KEY_HIDDEN_COINS, JSON.stringify([]));
|
||||
}
|
||||
|
||||
if (!checked && !isExternal) {
|
||||
dispatch({
|
||||
type: WALLET.SET_HIDDEN_COINS,
|
||||
hiddenCoins: allCoins,
|
||||
});
|
||||
storageUtils.set(TYPE, KEY_HIDDEN_COINS, JSON.stringify(allCoins));
|
||||
}
|
||||
};
|
||||
|
||||
export const getHiddenCoins = (): Array<string> => {
|
||||
const coinsConfig: ?string = storageUtils.get(TYPE, KEY_HIDDEN_COINS);
|
||||
export const getHiddenCoins = (isExternal: boolean): Array<string> => {
|
||||
let coinsConfig: ?string = '';
|
||||
if (isExternal) {
|
||||
coinsConfig = storageUtils.get(TYPE, KEY_HIDDEN_COINS_EXTERNAL);
|
||||
} else {
|
||||
coinsConfig = storageUtils.get(TYPE, KEY_HIDDEN_COINS);
|
||||
}
|
||||
if (coinsConfig) {
|
||||
return JSON.parse(coinsConfig);
|
||||
}
|
||||
|
@ -29,6 +29,10 @@ export type WalletAction =
|
||||
type: typeof WALLET.SET_HIDDEN_COINS,
|
||||
hiddenCoins: Array<string>,
|
||||
}
|
||||
| {
|
||||
type: typeof WALLET.SET_HIDDEN_COINS_EXTERNAL,
|
||||
hiddenCoinsExternal: Array<string>,
|
||||
}
|
||||
| {
|
||||
type: typeof WALLET.TOGGLE_DEVICE_DROPDOWN,
|
||||
opened: boolean,
|
||||
|
@ -20,3 +20,5 @@ 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_HIDE_BALANCE: 'wallet__set_hide_balance' = 'wallet__set_hide_balance';
|
||||
export const SET_HIDDEN_COINS: 'wallet__set_hidden_coins' = 'wallet__set_hidden_coins';
|
||||
export const SET_HIDDEN_COINS_EXTERNAL: 'wallet__set_hidden_coins_external' =
|
||||
'wallet__set_hidden_coins_external';
|
||||
|
@ -25,6 +25,7 @@ type State = {
|
||||
disconnectRequest: ?TrezorDevice,
|
||||
selectedDevice: ?TrezorDevice,
|
||||
hiddenCoins: Array<string>,
|
||||
hiddenCoinsExternal: Array<string>,
|
||||
};
|
||||
|
||||
const initialState: State = {
|
||||
@ -43,6 +44,7 @@ const initialState: State = {
|
||||
disconnectRequest: null,
|
||||
selectedDevice: null,
|
||||
hiddenCoins: [],
|
||||
hiddenCoinsExternal: [],
|
||||
};
|
||||
|
||||
export default function wallet(state: State = initialState, action: Action): State {
|
||||
@ -153,6 +155,12 @@ export default function wallet(state: State = initialState, action: Action): Sta
|
||||
hiddenCoins: action.hiddenCoins,
|
||||
};
|
||||
|
||||
case WALLET.SET_HIDDEN_COINS_EXTERNAL:
|
||||
return {
|
||||
...state,
|
||||
hiddenCoinsExternal: action.hiddenCoinsExternal,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ type DispatchProps = {|
|
||||
setLocalCurrency: typeof WalletActions.setLocalCurrency,
|
||||
setHideBalance: typeof WalletActions.setHideBalance,
|
||||
handleCoinVisibility: typeof LocalStorageActions.handleCoinVisibility,
|
||||
handleAllCoinsVisibility: typeof LocalStorageActions.handleAllCoinsVisibility,
|
||||
toggleGroupCoinsVisibility: typeof LocalStorageActions.toggleGroupCoinsVisibility,
|
||||
|};
|
||||
|
||||
export type Props = {| ...OwnProps, ...StateProps, ...DispatchProps |};
|
||||
@ -38,8 +38,8 @@ const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
|
||||
setLocalCurrency: bindActionCreators(WalletActions.setLocalCurrency, dispatch),
|
||||
setHideBalance: bindActionCreators(WalletActions.setHideBalance, dispatch),
|
||||
handleCoinVisibility: bindActionCreators(LocalStorageActions.handleCoinVisibility, dispatch),
|
||||
handleAllCoinsVisibility: bindActionCreators(
|
||||
LocalStorageActions.handleAllCoinsVisibility,
|
||||
toggleGroupCoinsVisibility: bindActionCreators(
|
||||
LocalStorageActions.toggleGroupCoinsVisibility,
|
||||
dispatch
|
||||
),
|
||||
});
|
||||
|
@ -13,8 +13,9 @@ import l10nMessages from '../../index.messages';
|
||||
type Props = {
|
||||
networks: Array<Network>,
|
||||
hiddenCoins: Array<string>,
|
||||
hiddenCoinsExternal: Array<string>,
|
||||
handleCoinVisibility: typeof LocalStorageActions.handleCoinVisibility,
|
||||
handleAllCoinsVisibility: typeof LocalStorageActions.handleAllCoinsVisibility,
|
||||
toggleGroupCoinsVisibility: typeof LocalStorageActions.toggleGroupCoinsVisibility,
|
||||
};
|
||||
|
||||
const Wrapper = styled.div`
|
||||
@ -118,16 +119,10 @@ const CoinsSettings = (props: Props) => (
|
||||
.filter(x => !x.isHidden)
|
||||
.map(item => item.shortcut);
|
||||
|
||||
props.handleAllCoinsVisibility(
|
||||
checked,
|
||||
allCoins,
|
||||
props.hiddenCoins
|
||||
);
|
||||
props.toggleGroupCoinsVisibility(allCoins, checked, false);
|
||||
}}
|
||||
>
|
||||
{props.hiddenCoins.every(val => props.networks.includes(val))
|
||||
? 'Hide all'
|
||||
: 'Show all'}
|
||||
{props.hiddenCoins.length > 0 ? 'Show all' : 'Hide all'}
|
||||
</ToggleAll>
|
||||
</Right>
|
||||
</Label>
|
||||
@ -147,7 +142,11 @@ const CoinsSettings = (props: Props) => (
|
||||
checkedIcon={false}
|
||||
uncheckedIcon={false}
|
||||
onChange={visible => {
|
||||
props.handleCoinVisibility(network.shortcut, visible);
|
||||
props.handleCoinVisibility(
|
||||
network.shortcut,
|
||||
visible,
|
||||
false
|
||||
);
|
||||
}}
|
||||
checked={!props.hiddenCoins.includes(network.shortcut)}
|
||||
/>
|
||||
@ -180,11 +179,7 @@ const CoinsSettings = (props: Props) => (
|
||||
.filter(x => !x.isHidden)
|
||||
.map(coin => coin.id);
|
||||
|
||||
props.handleAllCoinsVisibility(
|
||||
checked,
|
||||
allCoins,
|
||||
props.hiddenCoins
|
||||
);
|
||||
props.toggleGroupCoinsVisibility(allCoins, checked, true);
|
||||
}}
|
||||
>
|
||||
Show all
|
||||
@ -207,9 +202,9 @@ const CoinsSettings = (props: Props) => (
|
||||
checkedIcon={false}
|
||||
uncheckedIcon={false}
|
||||
onChange={visible => {
|
||||
props.handleCoinVisibility(network.id, visible);
|
||||
props.handleCoinVisibility(network.id, visible, true);
|
||||
}}
|
||||
checked={!props.hiddenCoins.includes(network.id)}
|
||||
checked={!props.hiddenCoinsExternal.includes(network.id)}
|
||||
/>
|
||||
</Right>
|
||||
</CoinRow>
|
||||
|
@ -120,8 +120,9 @@ const WalletSettings = (props: Props) => (
|
||||
<Coins
|
||||
networks={props.localStorage.config.networks}
|
||||
handleCoinVisibility={props.handleCoinVisibility}
|
||||
handleAllCoinsVisibility={props.handleAllCoinsVisibility}
|
||||
toggleGroupCoinsVisibility={props.toggleGroupCoinsVisibility}
|
||||
hiddenCoins={props.wallet.hiddenCoins}
|
||||
hiddenCoinsExternal={props.wallet.hiddenCoinsExternal}
|
||||
/>
|
||||
</Section>
|
||||
<Actions>
|
||||
|
Loading…
Reference in New Issue
Block a user