mirror of
https://github.com/luxfhe/example-poker.git
synced 2026-10-30 18:13:22 +00:00
27 lines
921 B
TypeScript
27 lines
921 B
TypeScript
import create from "zustand";
|
|
import scaffoldConfig from "~~/scaffold.config";
|
|
import { ChainWithAttributes } from "~~/utils/scaffold-eth";
|
|
|
|
/**
|
|
* Zustand Store
|
|
*
|
|
* You can add global state to the app using this useGlobalState, to get & set
|
|
* values from anywhere in the app.
|
|
*
|
|
* Think about it as a global useState.
|
|
*/
|
|
|
|
type GlobalState = {
|
|
nativeCurrencyPrice: number;
|
|
setNativeCurrencyPrice: (newNativeCurrencyPriceState: number) => void;
|
|
targetNetwork: ChainWithAttributes;
|
|
setTargetNetwork: (newTargetNetwork: ChainWithAttributes) => void;
|
|
};
|
|
|
|
export const useGlobalState = create<GlobalState>(set => ({
|
|
nativeCurrencyPrice: 0,
|
|
setNativeCurrencyPrice: (newValue: number): void => set(() => ({ nativeCurrencyPrice: newValue })),
|
|
targetNetwork: scaffoldConfig.targetNetworks[0],
|
|
setTargetNetwork: (newTargetNetwork: ChainWithAttributes) => set(() => ({ targetNetwork: newTargetNetwork })),
|
|
}));
|