amanpay / web /src /hooks /useD3Enabled.ts
MHamdan's picture
CI deploy 02b619b (part 2)
9f48c3c verified
Raw
History Blame Contribute Delete
927 Bytes
import { useEffect, useState } from 'react'
import { financeStatus } from '../api/ledger'
/**
* Runtime probe for whether the D3 simulated-finance surface is enabled on THIS deployment.
*
* `/finance/v1/status` returns `{enabled:true}` when D3 is mounted, `{enabled:false}` when the
* runtime isn't ready, and 404 (a thrown ApiRequestError) when the router isn't mounted at all
* (D3 dormant — e.g. the public Space). We hide the Wallet/ATM entry points unless it is truly
* enabled, so a dormant deployment never shows dead tabs. Returns null while probing.
*/
export function useD3Enabled(): boolean | null {
const [enabled, setEnabled] = useState<boolean | null>(null)
useEffect(() => {
let alive = true
financeStatus()
.then((s) => { if (alive) setEnabled(!!(s && s.enabled)) })
.catch(() => { if (alive) setEnabled(false) })
return () => { alive = false }
}, [])
return enabled
}