import { useCallback, useEffect, useRef, useState } from 'react'; import { createIndexedDbAdapter, createMetricsHost, type MetricsHost, type StorageAdapter, } from '@elata-biosciences/app-metrics/host'; import { APP_ID, DEMO_WALLET_ADDRESS } from '../shared/handshake'; /** * The host shell is what the appstore would be in production. It owns * IndexedDB and hands the sandboxed iframe a transferred MessagePort. * * This shell is dev-only — when you run `npm run build:zip`, only the * iframe app (game.html) gets packaged for upload. */ export default function HostApp() { const iframeRef = useRef(null); const hostRef = useRef(null); const adapterRef = useRef(null); const [status, setStatus] = useState<'booting' | 'ready' | 'error'>('booting'); const [errorMessage, setErrorMessage] = useState(null); const handleIframeLoad = useCallback(() => { const iframe = iframeRef.current; if (!iframe) return; try { const adapter = createIndexedDbAdapter(); adapterRef.current = adapter; const host = createMetricsHost({ iframe, appId: APP_ID, walletAddress: DEMO_WALLET_ADDRESS, storage: adapter, }); host.start(); hostRef.current = host; setStatus('ready'); } catch (err) { setStatus('error'); setErrorMessage(err instanceof Error ? err.message : String(err)); } }, []); useEffect(() => { return () => { hostRef.current?.stop(); hostRef.current = null; }; }, []); const handleWipe = useCallback(async () => { const adapter = adapterRef.current; if (!adapter) return; await adapter.clearScope(DEMO_WALLET_ADDRESS, APP_ID); // Force iframe to reload so it sees an empty leaderboard. if (iframeRef.current) { iframeRef.current.src = iframeRef.current.src; } }, []); return (

Pulse-game host shell

You are looking at the appstore shell. The boxed area below is a sandboxed iframe — the actual app. It talks to this shell over a transferred MessagePort; storage lives here, not in the app.

{status === 'booting' && 'Booting host…'} {status === 'ready' && `Host ready · scope (${shorten(DEMO_WALLET_ADDRESS)}, ${APP_ID})`} {status === 'error' && `Host error: ${errorMessage ?? 'unknown'}`}