import storage from '@/services/local-storage.service' import { createContext, useContext, useState } from 'react' type TZapContext = { defaultZapSats: number updateDefaultSats: (sats: number) => void defaultZapComment: string updateDefaultComment: (comment: string) => void quickZap: boolean updateQuickZap: (quickZap: boolean) => void } const ZapContext = createContext(undefined) export const useZap = () => { const context = useContext(ZapContext) if (!context) { throw new Error('useZap must be used within a ZapProvider') } return context } export function ZapProvider({ children }: { children: React.ReactNode }) { const [defaultZapSats, setDefaultZapSats] = useState(storage.getDefaultZapSats()) const [defaultZapComment, setDefaultZapComment] = useState(storage.getDefaultZapComment()) const [quickZap, setQuickZap] = useState(storage.getQuickZap()) const updateDefaultSats = (sats: number) => { storage.setDefaultZapSats(sats) setDefaultZapSats(sats) } const updateDefaultComment = (comment: string) => { storage.setDefaultZapComment(comment) setDefaultZapComment(comment) } const updateQuickZap = (quickZap: boolean) => { storage.setQuickZap(quickZap) setQuickZap(quickZap) } return ( {children} ) }