From f1e80cc475724b6bb8748e87fd7ad2c8947eeda7 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Mon, 27 Nov 2023 15:39:15 -0600 Subject: [PATCH] list individual channels on channels page --- src/i18n/en/translations.ts | 7 +- src/routes/settings/Channels.tsx | 240 ++++++++++++++++++++++++++----- 2 files changed, 214 insertions(+), 33 deletions(-) diff --git a/src/i18n/en/translations.ts b/src/i18n/en/translations.ts index 3eb5f57d..e0735d8a 100644 --- a/src/i18n/en/translations.ts +++ b/src/i18n/en/translations.ts @@ -315,7 +315,12 @@ export default { reserve_tip: "About 1% of your channel balance is reserved on lightning for fees. Additional reserves are required for channels you opened via swap.", no_channels: - "It looks like you don't have any channels yet. To get started, receive some sats over lightning, or swap some on-chain funds into a channel. Get your hands dirty!" + "It looks like you don't have any channels yet. To get started, receive some sats over lightning, or swap some on-chain funds into a channel. Get your hands dirty!", + close_channel: "Close", + online_channels: "Online Channels", + offline_channels: "Offline Channels", + close_channel_confirm: + "Closing this channel will move the balance on-chain and incur an on-chain fee." }, connections: { title: "Wallet Connections", diff --git a/src/routes/settings/Channels.tsx b/src/routes/settings/Channels.tsx index e0ff38ae..e49a5e7b 100644 --- a/src/routes/settings/Channels.tsx +++ b/src/routes/settings/Channels.tsx @@ -1,37 +1,62 @@ -import { createResource, Match, Switch } from "solid-js"; +import { MutinyChannel } from "@mutinywallet/mutiny-wasm"; +import { + createEffect, + createMemo, + createResource, + createSignal, + For, + Match, + Show, + Suspense, + Switch +} from "solid-js"; import { AmountSmall, BackLink, Card, + Collapser, + ConfirmDialog, DefaultMain, + ExternalLink, LargeHeader, MutinyWalletGuard, NavBar, NiceP, SafeArea, + SettingsCard, + showToast, SmallHeader, TinyText, VStack } from "~/components"; import { useI18n } from "~/i18n/context"; +import { Network } from "~/logic/mutinyWalletSetup"; import { useMegaStore } from "~/state/megaStore"; +import { createDeepSignal, eify, mempoolTxUrl } from "~/utils"; export function BalanceBar(props: { inbound: number; reserve: number; outbound: number; + hideHeader?: boolean; }) { const i18n = useI18n(); return ( -
- - {i18n.t("settings.channels.outbound")} - - {i18n.t("settings.channels.reserve")} - {i18n.t("settings.channels.inbound")} -
+ +
+ + {i18n.t("settings.channels.outbound")} + + + {i18n.t("settings.channels.reserve")} + + + {i18n.t("settings.channels.inbound")} + +
+
splitChannelNumbers(props.channel)); + + return ( + + + +
+ + {i18n.t("common.view_transaction")} + + +
+ setConfirmOpen(false)} + > + {i18n.t("settings.channels.close_channel_confirm")} + +
+
+ ); +} + export function LiquidityMonitor() { const i18n = useI18n(); const [state, _actions] = useMegaStore(); - const [channelInfo] = createResource(async () => { + async function listChannels() { try { - const channels = await state.mutiny_wallet?.list_channels(); + const channels: MutinyChannel[] | undefined = + await state.mutiny_wallet?.list_channels(); + + if (!channels) + return { + inbound: 0, + reserve: 0, + outbound: 0, + channelCount: 0 + }; + let outbound = 0n; let inbound = 0n; let reserve = 0n; @@ -83,37 +200,94 @@ export function LiquidityMonitor() { inbound, reserve, outbound, - channelCount: channels?.length + channelCount: channels?.length, + online: channels?.filter((c) => c.is_usable), + offline: channels?.filter((c) => !c.is_usable) }; } catch (e) { console.error(e); return { inbound: 0, reserve: 0, outbound: 0, channelCount: 0 }; } + } + + const [channelInfo, { refetch }] = createResource(listChannels, { + storage: createDeepSignal + }); + + createEffect(() => { + // Refetch on the sync interval + if (!state.is_syncing) { + refetch(); + } }); return ( - - - {i18n.t("settings.channels.have_channels")}{" "} - {channelInfo()?.channelCount}{" "} - {channelInfo()?.channelCount === 1 - ? i18n.t("settings.channels.have_channels_one") - : i18n.t("settings.channels.have_channels_many")} - {" "} - - - {i18n.t("settings.channels.inbound_outbound_tip")} - - - {i18n.t("settings.channels.reserve_tip")} - - + + + + {i18n.t("settings.channels.have_channels")}{" "} + {channelInfo()?.channelCount}{" "} + {channelInfo()?.channelCount === 1 + ? i18n.t("settings.channels.have_channels_one") + : i18n.t( + "settings.channels.have_channels_many" + )} + {" "} + + + {i18n.t("settings.channels.inbound_outbound_tip")} + + + {i18n.t("settings.channels.reserve_tip")} + + + + + + + + {(channel) => ( + + )} + + + + + + + + + + + {(channel) => ( + + )} + + + + + + {i18n.t("settings.channels.no_channels")} @@ -135,7 +309,9 @@ export function Channels() { {i18n.t("settings.channels.title")} - + + +