feat: zap (#107)
This commit is contained in:
parent
407a6fb802
commit
249593d547
72 changed files with 2582 additions and 818 deletions
57
src/providers/ZapProvider.tsx
Normal file
57
src/providers/ZapProvider.tsx
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
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<TZapContext | undefined>(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<number>(storage.getDefaultZapSats())
|
||||
const [defaultZapComment, setDefaultZapComment] = useState<string>(storage.getDefaultZapComment())
|
||||
const [quickZap, setQuickZap] = useState<boolean>(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 (
|
||||
<ZapContext.Provider
|
||||
value={{
|
||||
defaultZapSats,
|
||||
updateDefaultSats,
|
||||
defaultZapComment,
|
||||
updateDefaultComment,
|
||||
quickZap,
|
||||
updateQuickZap
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</ZapContext.Provider>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue