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;
for (const channel of channels) {
- inbound =
- inbound +
- BigInt(channel.size) -
- BigInt(channel.balance + channel.reserve);
+ inbound = inbound + BigInt(channel.inbound);
reserve = reserve + BigInt(channel.reserve);
outbound = outbound + BigInt(channel.balance);
}
@@ -86,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")}
@@ -138,7 +309,9 @@ export function Channels() {
{i18n.t("settings.channels.title")}
-
+
+
+