mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-27 18:58:08 +00:00
add redux support for setting local currency
This commit is contained in:
parent
8f55a04931
commit
c9d7fc8ea9
@ -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));
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user