vega-frontend-monorepo/apps/trading/stores/global.ts
Sam Keen 5ab5aa01a2
feat(trading): 2803 console announcement banner (#2830)
Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
Co-authored-by: Dariusz Majcherczyk <dariusz.majcherczyk@gmail.com>
2023-02-03 10:34:32 +00:00

39 lines
1.0 KiB
TypeScript

import { LocalStorage } from '@vegaprotocol/react-helpers';
import { create } from 'zustand';
import produce from 'immer';
interface GlobalStore {
networkSwitcherDialog: boolean;
marketId: string | null;
update: (store: Partial<Omit<GlobalStore, 'update'>>) => void;
shouldDisplayWelcomeDialog: boolean;
shouldDisplayAnnouncementBanner: boolean;
}
interface PageTitleStore {
pageTitle: string | null;
updateTitle: (title: string) => void;
}
export const useGlobalStore = create<GlobalStore>((set) => ({
networkSwitcherDialog: false,
marketId: LocalStorage.getItem('marketId') || null,
shouldDisplayWelcomeDialog: false,
shouldDisplayAnnouncementBanner: true,
update: (newState) => {
set(
produce((state: GlobalStore) => {
Object.assign(state, newState);
})
);
if (newState.marketId) {
LocalStorage.setItem('marketId', newState.marketId);
}
},
}));
export const usePageTitleStore = create<PageTitleStore>((set) => ({
pageTitle: null,
updateTitle: (title: string) => set({ pageTitle: title }),
}));