1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-13 20:08:56 +00:00

add setHideBalance action, save setting to localStorage

This commit is contained in:
slowbackspace 2019-03-14 23:31:19 +01:00
parent b21cc9cfcd
commit 02f05e625e
5 changed files with 34 additions and 2 deletions

View File

@ -58,6 +58,7 @@ const KEY_PENDING: string = `${STORAGE_PATH}pending`;
const KEY_BETA_MODAL: string = '/betaModalPrivacy'; // this key needs to be compatible with "parent" (old) wallet
const KEY_LANGUAGE: string = `${STORAGE_PATH}language`;
const KEY_LOCAL_CURRENCY: string = `${STORAGE_PATH}localCurrency`;
const KEY_HIDE_BALANCE: string = `${STORAGE_PATH}hideBalance`;
// https://github.com/STRML/react-localstorage/blob/master/react-localstorage.js
// or
@ -282,6 +283,11 @@ const loadStorageData = (): ThunkAction => (dispatch: Dispatch): void => {
if (localCurrency) {
dispatch(WalletActions.setLocalCurrency(JSON.parse(localCurrency)));
}
const hideBalance: ?boolean = storageUtils.get(TYPE, KEY_HIDE_BALANCE);
if (hideBalance) {
dispatch(WalletActions.setHideBalance(JSON.parse(hideBalance)));
}
};
export const loadData = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
@ -303,6 +309,11 @@ export const setLanguage = (): ThunkAction => (dispatch: Dispatch, getState: Get
storageUtils.set(TYPE, KEY_LANGUAGE, JSON.stringify(language));
};
export const setHideBalance = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
const { hideBalance } = getState().wallet;
storageUtils.set(TYPE, KEY_HIDE_BALANCE, JSON.stringify(hideBalance));
};
export const setLocalCurrency = (): ThunkAction => (
dispatch: Dispatch,
getState: GetState

View File

@ -62,6 +62,9 @@ export type WalletAction =
| {
type: typeof WALLET.SET_LOCAL_CURRENCY,
localCurrency: string,
}
| {
type: typeof WALLET.SET_HIDE_BALANCE,
};
export const init = (): ThunkAction => (dispatch: Dispatch): void => {
@ -105,6 +108,11 @@ export const setLocalCurrency = (localCurrency: string): WalletAction => ({
localCurrency: localCurrency.toLowerCase(),
});
export const setHideBalance = (toggled: boolean): WalletAction => ({
type: WALLET.SET_HIDE_BALANCE,
toggled,
});
// This method will be called after each DEVICE.CONNECT action
// if connected device has different "passphrase_protection" settings than saved instances
// all saved instances will be removed immediately inside DevicesReducer

View File

@ -18,3 +18,4 @@ export const CLEAR_UNAVAILABLE_DEVICE_DATA: 'wallet__clear_unavailable_device_da
export const TOGGLE_SIDEBAR: 'wallet__toggle_sidebar' = 'wallet__toggle_sidebar';
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';

View File

@ -13,8 +13,9 @@ type State = {
ready: boolean,
online: boolean,
language: string,
localCurrency: string,
messages: { [string]: string },
localCurrency: string,
hideBalance: boolean,
dropdownOpened: boolean,
showBetaDisclaimer: boolean,
showSidebar: ?boolean,
@ -29,8 +30,9 @@ const initialState: State = {
ready: false,
online: navigator.onLine,
language: 'en',
localCurrency: 'usd',
messages: {},
localCurrency: 'usd',
hideBalance: false,
dropdownOpened: false,
firstLocationChange: true,
showBetaDisclaimer: false,
@ -137,6 +139,12 @@ export default function wallet(state: State = initialState, action: Action): Sta
localCurrency: action.localCurrency,
};
case WALLET.SET_HIDE_BALANCE:
return {
...state,
hideBalance: action.toggled,
};
default:
return state;
}

View File

@ -26,6 +26,10 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar
api.dispatch(LocalStorageActions.setLanguage());
break;
case WALLET.SET_HIDE_BALANCE:
api.dispatch(LocalStorageActions.setHideBalance());
break;
case WALLET.SET_LOCAL_CURRENCY:
api.dispatch(LocalStorageActions.setLocalCurrency());
break;