import "./WalletPage.css"; import { useEffect, useState } from "react"; import { RouteObject } from "react-router-dom"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCheck, faClock, faXmark } from "@fortawesome/free-solid-svg-icons"; import NoteTime from "Element/NoteTime"; import { openWallet, WalletInvoice, Sats, WalletInfo, WalletInvoiceState, useWallet, LNWallet } from "Wallet"; export const WalletRoutes: RouteObject[] = [ { path: "/wallet", element: , }, ]; export default function WalletPage() { const [info, setInfo] = useState(); const [balance, setBalance] = useState(); const [history, setHistory] = useState(); const wallet = useWallet(); async function loadWallet(wallet: LNWallet) { const i = await wallet.getInfo(); if ("error" in i) { return; } setInfo(i as WalletInfo); const b = await wallet.getBalance(); setBalance(b as Sats); const h = await wallet.getInvoices(); setHistory((h as WalletInvoice[]).sort((a, b) => b.timestamp - a.timestamp)); } useEffect(() => { if (wallet) { loadWallet(wallet).catch(console.warn); } }, [wallet]); function stateIcon(s: WalletInvoiceState) { switch (s) { case WalletInvoiceState.Pending: return ; case WalletInvoiceState.Paid: return ; case WalletInvoiceState.Expired: return ; } } async function createInvoice() { const cfg = window.localStorage.getItem("wallet-lndhub"); if (cfg) { const wallet = await openWallet(cfg); const rsp = await wallet.createInvoice({ memo: "test", amount: 100, }); console.debug(rsp); } } return ( <> {info?.alias} Balance: {(balance ?? 0).toLocaleString()} sats Send createInvoice()}>Receive History {history?.map(a => ( {(a.memo ?? "").length === 0 ? <> > : a.memo} {stateIcon(a.state)} {a.amount.toLocaleString()} sats ))} > ); }