import { NwcProfile } from "@mutinywallet/mutiny-wasm"; import { timeAgo } from "~/utils/prettyPrintTime"; import { Card, LoadingSpinner, VStack } from "./layout"; import bolt from "~/assets/icons/bolt.svg"; import { For, Match, Show, Suspense, Switch, createEffect, createResource, createSignal } from "solid-js"; import { useMegaStore } from "~/state/megaStore"; import greenCheck from "~/assets/icons/green-check.svg"; import redClose from "~/assets/icons/red-close.svg"; import { ActivityAmount } from "./ActivityItem"; import { InfoBox } from "./InfoBox"; import eify from "~/utils/eify"; import { A } from "solid-start"; type PendingItem = { id: string; name_of_connection: string; date?: bigint; amount_sats?: bigint; }; export function PendingNwc() { const [state, _actions] = useMegaStore(); const [error, setError] = createSignal(); const [pendingRequests, { refetch }] = createResource(async () => { const profiles: NwcProfile[] = await state.mutiny_wallet?.get_nwc_profiles(); const pending = await state.mutiny_wallet?.get_pending_nwc_invoices(); const pendingItems: PendingItem[] = []; for (const p of pending) { const profile = profiles.find((pro) => pro.index === p.index); if (profile) { pendingItems.push({ id: p.id, name_of_connection: profile.name, date: p.expiry, amount_sats: p.amount_sats }); } } console.log(pendingItems); return pendingItems; }); const [paying, setPaying] = createSignal(""); async function payItem(item: PendingItem) { try { setPaying(item.id); const nodes = await state.mutiny_wallet?.list_nodes(); await state.mutiny_wallet?.approve_invoice(item.id, nodes[0]); } catch (e) { setError(eify(e)); console.error(e); } finally { setPaying(""); refetch(); } } async function rejectItem(item: PendingItem) { try { setPaying(item.id); await state.mutiny_wallet?.deny_invoice(item.id); } catch (e) { setError(eify(e)); console.error(e); } finally { setPaying(""); refetch(); } } createEffect(() => { // When there's an error wait five seconds and then clear it if (error()) { setTimeout(() => { setError(undefined); }, 5000); } }); return ( 0}>
{error()?.message} {(pendingItem) => (
onchain
{pendingItem.name_of_connection}
)}
Configure ); }