import { formatBytes } from '@/lib/format' import { useEffect, useState } from 'react' import { useKeyHash, useKeyUpdatedAt } from '@/wallets/client/context' import { useRemoteKeyHash, useRemoteKeyHashUpdatedAt, useWalletsUpdatedAt } from '@/wallets/client/hooks' import { timeSince } from '@/lib/time' export function WalletDebugSettings () { const localKeyHash = useKeyHash() const localKeyUpdatedAt = useKeyUpdatedAt() const remoteKeyHash = useRemoteKeyHash() const remoteKeyHashUpdatedAt = useRemoteKeyHashUpdatedAt() const walletsUpdatedAt = useWalletsUpdatedAt() const [persistent, setPersistent] = useState(null) const [quota, setQuota] = useState(null) const [usage, setUsage] = useState(null) useEffect(() => { async function init () { try { const persistent = await navigator.storage.persisted() setPersistent(persistent) } catch (err) { console.error('failed to check persistent storage:', err) } try { const estimate = await navigator.storage.estimate() setQuota(estimate.quota) setUsage(estimate.usage) } catch (err) { console.error('failed to get estimate:', err) } } init() }, []) return (
persistent storage:
{persistent !== null ? persistent?.toString() : 'unknown'}
storage quota:
{quota !== null ? formatBytes(quota) : 'unknown'}
storage usage:
{usage !== null ? formatBytes(usage) : 'unknown'}
storage remaining:
{usage !== null && quota !== null ? formatBytes(quota - usage) : 'unknown'}
device key hash:
{localKeyHash ? shortHash(localKeyHash) : 'unknown'}
server key hash:
{remoteKeyHash ? shortHash(remoteKeyHash) : 'unknown'}
device key update:
{localKeyUpdatedAt ? `${timeSince(localKeyUpdatedAt)} ago` : 'unknown'}
server key update:
{remoteKeyHashUpdatedAt ? `${timeSince(new Date(remoteKeyHashUpdatedAt).getTime())} ago` : 'unknown'}
wallet update:
{walletsUpdatedAt ? `${timeSince(new Date(walletsUpdatedAt).getTime())} ago` : 'unknown'}
) } function shortHash (hash) { return hash.slice(0, 6) + '...' + hash.slice(-6) }