1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-02-06 21:22:45 +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_BETA_MODAL: string = '/betaModalPrivacy'; // this key needs to be compatible with "parent" (old) wallet
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`;
// https://github.com/STRML/react-localstorage/blob/master/react-localstorage.js // https://github.com/STRML/react-localstorage/blob/master/react-localstorage.js
// or // or
@ -282,6 +283,11 @@ const loadStorageData = (): ThunkAction => (dispatch: Dispatch): void => {
if (localCurrency) { if (localCurrency) {
dispatch(WalletActions.setLocalCurrency(JSON.parse(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 => { 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)); 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 => ( export const setLocalCurrency = (): ThunkAction => (
dispatch: Dispatch, dispatch: Dispatch,
getState: GetState getState: GetState

View File

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

View File

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

View File

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