Files
dydx-v4-web/src/state/localizationMiddleware.ts
T
Jared VuandBill He 99e708a984 Notifications Refresh (#135)
* Remove X button from tablet/mobile Notification menu

* Toast styling

* missed in merge

* .env.example

* Update abacus@1.0.9

* Add notif strings, and abaucs notif state

* Update Notification hooks, add Notification Preference controls

* Consolidate Notification into single component

* withLabel -> withTrigger prop

* nits

* OrderStatusChanged -> AbacusGenerated

* Notification OnClick

* Move Notification -> Components

* withAnimation -> $withAnimation

* Notification styling and click handle

* load state, onClick, localStorage

* add error count

* Rez localStorage Notifications

* Update TransferStatus UI

* Use Notification component for other abacusNotifs

* fix uselocalnotif query

* Default to Notification from NotificationMenu

---------

Co-authored-by: Bill He <bill@dydx.exchange>
2023-11-10 20:55:34 -08:00

81 lines
2.1 KiB
TypeScript

import type { PayloadAction } from '@reduxjs/toolkit';
import {
LOCALE_DATA,
NOTIFICATIONS,
SupportedLocale,
TOOLTIPS,
} from '@dydxprotocol/v4-localization';
import {
type LocaleData,
SUPPORTED_BASE_TAGS_LOCALE_MAPPING,
SupportedLocales,
} from '@/constants/localization';
import { LocalStorageKey } from '@/constants/localStorage';
import { initializeLocalization } from '@/state/app';
import { setLocaleData, setLocaleLoaded, setSelectedLocale } from '@/state/localization';
import { getLocalStorage, setLocalStorage } from '@/lib/localStorage';
const getNewLocaleData = ({
store,
locale,
isAutoDetect,
}: {
store: any;
locale: SupportedLocale;
isAutoDetect: boolean;
}) => {
store.dispatch(setLocaleLoaded(false));
const newLocaleData = {
...LOCALE_DATA[locale],
...NOTIFICATIONS[locale],
TOOLTIPS: TOOLTIPS[locale],
};
store.dispatch(setLocaleData(newLocaleData as LocaleData));
if (!isAutoDetect) {
setLocalStorage({ key: LocalStorageKey.SelectedLocale, value: locale });
}
};
export default (store: any) => (next: any) => async (action: PayloadAction<any>) => {
next(action);
const { type, payload } = action;
switch (type) {
case initializeLocalization().type: {
const localStorageLocale = getLocalStorage({
key: LocalStorageKey.SelectedLocale,
}) as SupportedLocales;
if (localStorageLocale) {
store.dispatch(setSelectedLocale({ locale: localStorageLocale }));
} else if (globalThis.navigator?.language) {
const browserLanguageBaseTag = globalThis.navigator.language.split('-')[0].toLowerCase();
const locale = SUPPORTED_BASE_TAGS_LOCALE_MAPPING[
browserLanguageBaseTag
] as SupportedLocales;
if (locale) {
store.dispatch(setSelectedLocale({ locale, isAutoDetect: true }));
}
}
break;
}
// @ts-ignore
case setSelectedLocale().type: {
const { locale, isAutoDetect } = payload;
getNewLocaleData({ store, locale, isAutoDetect });
break;
}
default: {
break;
}
}
};