* Add wallet debug logs * Add checkbox to toggle diagnostics * Require authentication for /wallets/debug * Update debug log messages * Use me.privates.diagnostics as source of truth
24 lines
754 B
JavaScript
24 lines
754 B
JavaScript
import { useMe } from '@/components/me'
|
|
import { useToast } from '@/components/toast'
|
|
import { SET_DIAGNOSTICS } from '@/fragments/users'
|
|
import { useMutation } from '@apollo/client'
|
|
import { useCallback } from 'react'
|
|
|
|
export function useDiagnostics () {
|
|
const { me, refreshMe } = useMe()
|
|
const [mutate] = useMutation(SET_DIAGNOSTICS)
|
|
const toaster = useToast()
|
|
|
|
const setDiagnostics = useCallback(async (diagnostics) => {
|
|
try {
|
|
await mutate({ variables: { diagnostics } })
|
|
await refreshMe()
|
|
} catch (err) {
|
|
console.error('failed to toggle diagnostics:', err)
|
|
toaster.danger('failed to toggle diagnostics')
|
|
}
|
|
}, [mutate, toaster, refreshMe])
|
|
|
|
return [me?.privates?.diagnostics ?? false, setDiagnostics]
|
|
}
|