vega-frontend-monorepo/apps/trading/stores/global.ts
Matthew Russell 28b4593a1d
refactor(trading,governance,wallet): wallet rewrite (#5815)
Co-authored-by: bwallacee <ben@vega.xyz>
2024-03-01 14:25:56 +00:00

33 lines
840 B
TypeScript

import { LocalStorage } from '@vegaprotocol/utils';
import { create } from 'zustand';
import produce from 'immer';
interface GlobalStore {
marketId: string | null;
update: (store: Partial<Omit<GlobalStore, 'update'>>) => void;
}
interface PageTitleStore {
pageTitle: string | null;
updateTitle: (title: string) => void;
}
export const useGlobalStore = create<GlobalStore>()((set) => ({
marketId: LocalStorage.getItem('marketId') || null,
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 }),
}));