diff --git a/src/actions/LocalStorageActions.js b/src/actions/LocalStorageActions.js index 6355c962..ad959790 100644 --- a/src/actions/LocalStorageActions.js +++ b/src/actions/LocalStorageActions.js @@ -57,6 +57,7 @@ const KEY_TOKENS: string = `${STORAGE_PATH}tokens`; 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`; // https://github.com/STRML/react-localstorage/blob/master/react-localstorage.js // or @@ -276,6 +277,11 @@ const loadStorageData = (): ThunkAction => (dispatch: Dispatch): void => { } else { dispatch(WalletActions.fetchLocale(l10nUtils.getInitialLocale())); } + + const localCurrency: ?string = storageUtils.get(TYPE, KEY_LOCAL_CURRENCY); + if (localCurrency) { + dispatch(WalletActions.setLocalCurrency(JSON.parse(localCurrency))); + } }; export const loadData = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => { @@ -296,3 +302,11 @@ export const setLanguage = (): ThunkAction => (dispatch: Dispatch, getState: Get const { language } = getState().wallet; storageUtils.set(TYPE, KEY_LANGUAGE, JSON.stringify(language)); }; + +export const setLocalCurrency = (): ThunkAction => ( + dispatch: Dispatch, + getState: GetState +): void => { + const { localCurrency } = getState().wallet; + storageUtils.set(TYPE, KEY_LOCAL_CURRENCY, JSON.stringify(localCurrency)); +}; diff --git a/src/actions/WalletActions.js b/src/actions/WalletActions.js index 063f548e..14045e29 100644 --- a/src/actions/WalletActions.js +++ b/src/actions/WalletActions.js @@ -58,6 +58,10 @@ export type WalletAction = type: typeof WALLET.SET_LANGUAGE, locale: string, messages: { [string]: string }, + } + | { + type: typeof WALLET.SET_LOCAL_CURRENCY, + localCurrency: string, }; export const init = (): ThunkAction => (dispatch: Dispatch): void => { @@ -96,6 +100,11 @@ export const fetchLocale = (locale: string): ThunkAction => (dispatch: Dispatch) }); }; +export const setLocalCurrency = (localCurrency: string): WalletAction => ({ + type: WALLET.SET_LOCAL_CURRENCY, + localCurrency: localCurrency.toLowerCase(), +}); + // 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 d1d8bb0a..0ccff06d 100644 --- a/src/actions/constants/wallet.js +++ b/src/actions/constants/wallet.js @@ -17,3 +17,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'; diff --git a/src/reducers/WalletReducer.js b/src/reducers/WalletReducer.js index 7f2e9a22..aa92c230 100644 --- a/src/reducers/WalletReducer.js +++ b/src/reducers/WalletReducer.js @@ -13,6 +13,7 @@ type State = { ready: boolean, online: boolean, language: string, + localCurrency: string, messages: { [string]: string }, dropdownOpened: boolean, showBetaDisclaimer: boolean, @@ -28,6 +29,7 @@ const initialState: State = { ready: false, online: navigator.onLine, language: 'en', + localCurrency: 'usd', messages: {}, dropdownOpened: false, firstLocationChange: true, @@ -129,6 +131,12 @@ export default function wallet(state: State = initialState, action: Action): Sta messages: action.messages ? action.messages : state.messages, }; + case WALLET.SET_LOCAL_CURRENCY: + return { + ...state, + localCurrency: action.localCurrency, + }; + default: return state; } diff --git a/src/services/LocalStorageService.js b/src/services/LocalStorageService.js index 5a258ada..4f79cbe5 100644 --- a/src/services/LocalStorageService.js +++ b/src/services/LocalStorageService.js @@ -25,6 +25,10 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar case WALLET.SET_LANGUAGE: api.dispatch(LocalStorageActions.setLanguage()); break; + + case WALLET.SET_LOCAL_CURRENCY: + api.dispatch(LocalStorageActions.setLocalCurrency()); + break; // first time saving case CONNECT.REMEMBER: api.dispatch(LocalStorageActions.save());