File size: 927 Bytes
9f48c3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
}