diff --git a/src/actions/LocalStorageActions.js b/src/actions/LocalStorageActions.js index ad959790..ce6d4f9f 100644 --- a/src/actions/LocalStorageActions.js +++ b/src/actions/LocalStorageActions.js @@ -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 diff --git a/src/actions/WalletActions.js b/src/actions/WalletActions.js index 14045e29..ddbb9003 100644 --- a/src/actions/WalletActions.js +++ b/src/actions/WalletActions.js @@ -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 diff --git a/src/actions/constants/wallet.js b/src/actions/constants/wallet.js index 0ccff06d..fa3bf052 100644 --- a/src/actions/constants/wallet.js +++ b/src/actions/constants/wallet.js @@ -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'; diff --git a/src/reducers/WalletReducer.js b/src/reducers/WalletReducer.js index aa92c230..fab169a2 100644 --- a/src/reducers/WalletReducer.js +++ b/src/reducers/WalletReducer.js @@ -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; } diff --git a/src/services/LocalStorageService.js b/src/services/LocalStorageService.js index 4f79cbe5..c5d9daf6 100644 --- a/src/services/LocalStorageService.js +++ b/src/services/LocalStorageService.js @@ -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;