vega-frontend-monorepo/apps/trading/stores/global.ts
macqbat 0bb2e95091
chore: market header live update (#1672)
* chore: market header live update

* chore: market header live update

* chore: market header live update - adjust some mocks

* chore: market header live update - add single market query

* chore: market header live update - small fixes

* chore: market header live update - fix int tests

* chore: market header live update - fix int tests

* chore: market header live update - remove unnecessary props from query

* chore: market header live update - change concept - split for small comps

* chore: market header live update - small fix for mocks

* chore: market header live update - fix updates throttling

* chore: market header live update - improve update methods of data providers

* chore: market header live update - improve update methods of data providers

* chore: market header live update - improve update methods store for get rid of blinking

* chore: market header live update - fix title component

Co-authored-by: maciek <maciek@vegaprotocol.io>
2022-10-11 14:30:07 +02:00

35 lines
997 B
TypeScript

import { LocalStorage } from '@vegaprotocol/react-helpers';
import create from 'zustand';
interface GlobalStore {
connectDialog: boolean;
networkSwitcherDialog: boolean;
landingDialog: boolean;
riskNoticeDialog: boolean;
marketId: string | null;
pageTitle: string | null;
update: (store: Partial<Omit<GlobalStore, 'update'>>) => void;
updateTitle: (title: string) => void;
updateMarketId: (marketId: string) => void;
}
export const useGlobalStore = create<GlobalStore>((set) => ({
connectDialog: false,
networkSwitcherDialog: false,
landingDialog: false,
riskNoticeDialog: false,
marketId: LocalStorage.getItem('marketId') || null,
pageTitle: null,
update: (state) => {
set(state);
if (state.marketId) {
LocalStorage.setItem('marketId', state.marketId);
}
},
updateTitle: (title: string) => set({ pageTitle: title }),
updateMarketId: (marketId: string) => {
set({ marketId });
LocalStorage.setItem('marketId', marketId);
},
}));