33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { create } from 'zustand'
|
|
|
|
interface DashboardState {
|
|
selectedPostId: number | null
|
|
asset: 'BTC' | 'ETH'
|
|
timeframe: '5m' | '15m' | '1H' | '4H' | '1D' | '1W'
|
|
walletAddress: string | null
|
|
isSubscribed: boolean
|
|
livePrices: { BTC: number | null; ETH: number | null }
|
|
setSelectedPost: (id: number | null) => void
|
|
setAsset: (asset: 'BTC' | 'ETH') => void
|
|
setTimeframe: (tf: '5m' | '15m' | '1H' | '4H' | '1D' | '1W') => void
|
|
setWallet: (address: string | null) => void
|
|
setSubscribed: (subscribed: boolean) => void
|
|
setLivePrice: (asset: 'BTC' | 'ETH', price: number) => void
|
|
}
|
|
|
|
export const useDashboardStore = create<DashboardState>((set) => ({
|
|
selectedPostId: null,
|
|
asset: 'BTC',
|
|
timeframe: '4H',
|
|
walletAddress: null,
|
|
isSubscribed: false,
|
|
livePrices: { BTC: null, ETH: null },
|
|
setSelectedPost: (id) => set({ selectedPostId: id }),
|
|
setAsset: (asset) => set({ asset }),
|
|
setTimeframe: (timeframe) => set({ timeframe }),
|
|
setWallet: (walletAddress) => set({ walletAddress }),
|
|
setSubscribed: (isSubscribed) => set({ isSubscribed }),
|
|
setLivePrice: (asset, price) =>
|
|
set((s) => ({ livePrices: { ...s.livePrices, [asset]: price } })),
|
|
}))
|