import { useEffect, useState, useCallback } from 'react' import { getAlbyService } from '@/lib/alby' interface AlbyInstallerProps { onInstalled?: () => void } function InfoIcon() { return ( ) } interface InstallerActionsProps { onInstalled?: () => void markInstalled: () => void } function InstallerActions({ onInstalled, markInstalled }: InstallerActionsProps) { const connect = useCallback(() => { const alby = getAlbyService() void alby.enable().then(() => { markInstalled() onInstalled?.() }) }, [markInstalled, onInstalled]) return (
Install Alby
) } function InstallerBody({ onInstalled, markInstalled }: InstallerActionsProps) { return (

Alby Extension Required

To make Lightning payments, please install the Alby browser extension.

Alby is a Lightning wallet that enables instant Bitcoin payments in your browser.

) } function useAlbyStatus(onInstalled?: () => void) { const [isInstalled, setIsInstalled] = useState(false) const [isChecking, setIsChecking] = useState(true) useEffect(() => { const checkAlby = () => { try { const alby = getAlbyService() const installed = alby.isEnabled() setIsInstalled(installed) if (installed) { onInstalled?.() } } catch (e) { console.error('Error checking Alby:', e) setIsInstalled(false) } finally { setIsChecking(false) } } checkAlby() }, [onInstalled]) const markInstalled = () => { setIsInstalled(true) } return { isInstalled, isChecking, markInstalled } } export function AlbyInstaller({ onInstalled }: AlbyInstallerProps) { const { isInstalled, isChecking, markInstalled } = useAlbyStatus(onInstalled) if (isChecking || isInstalled) { return null } return (
) }