import { useEffect, useState, useCallback } from 'react' import { getAlbyService } from '@/lib/alby' interface AlbyInstallerProps { onInstalled?: () => void } function InfoIcon(): JSX.Element { return ( ) } interface InstallerActionsProps { onInstalled?: () => void markInstalled: () => void } function InstallerActions({ onInstalled, markInstalled }: InstallerActionsProps): JSX.Element { const connect = useCallback(() => { const alby = getAlbyService() void alby.enable().then(() => { markInstalled() onInstalled?.() }) }, [markInstalled, onInstalled]) return (
Install Alby
) } function InstallerBody({ onInstalled, markInstalled }: InstallerActionsProps): JSX.Element { 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): { isInstalled: boolean; isChecking: boolean; markInstalled: () => void } { const [isInstalled, setIsInstalled] = useState(false) const [isChecking, setIsChecking] = useState(true) useEffect(() => { const checkAlby = (): void => { 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 = (): void => { setIsInstalled(true) } return { isInstalled, isChecking, markInstalled } } export function AlbyInstaller({ onInstalled }: AlbyInstallerProps): JSX.Element | null { const { isInstalled, isChecking, markInstalled } = useAlbyStatus(onInstalled) if (isChecking || isInstalled) { return null } return (
) }