Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list individual channels on channels page #743

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.mutinywallet.mutinywallet"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 38
versionName "0.4.37"
versionCode 39
versionName "0.4.38"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
4 changes: 2 additions & 2 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.4.37;
MARKETING_VERSION = 1.4.38;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = com.mutinywallet.mutiny;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -387,7 +387,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.4.37;
MARKETING_VERSION = 1.4.38;
PRODUCT_BUNDLE_IDENTIFIER = com.mutinywallet.mutiny;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mutiny-wallet",
"version": "0.4.37",
"version": "0.4.38",
"license": "MIT",
"packageManager": "[email protected]",
"scripts": {
Expand Down Expand Up @@ -55,7 +55,7 @@
"@kobalte/core": "^0.9.8",
"@kobalte/tailwindcss": "^0.5.0",
"@modular-forms/solid": "^0.18.1",
"@mutinywallet/mutiny-wasm": "0.4.37",
"@mutinywallet/mutiny-wasm": "0.4.38",
"@mutinywallet/waila-wasm": "^0.2.4",
"@solid-primitives/upload": "^0.0.111",
"@solid-primitives/websocket": "^1.2.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/i18n/en/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
240 changes: 208 additions & 32 deletions src/routes/settings/Channels.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<VStack smallgap>
<div class="flex justify-between">
<SmallHeader>
{i18n.t("settings.channels.outbound")}
</SmallHeader>
<SmallHeader>{i18n.t("settings.channels.reserve")}</SmallHeader>
<SmallHeader>{i18n.t("settings.channels.inbound")}</SmallHeader>
</div>
<Show when={!props.hideHeader}>
<div class="flex justify-between">
<SmallHeader>
{i18n.t("settings.channels.outbound")}
</SmallHeader>
<SmallHeader>
{i18n.t("settings.channels.reserve")}
</SmallHeader>
<SmallHeader>
{i18n.t("settings.channels.inbound")}
</SmallHeader>
</div>
</Show>
<div class="flex w-full gap-1">
<div
class="min-w-fit rounded-l-xl bg-m-green p-2"
Expand Down Expand Up @@ -62,13 +87,105 @@ export function BalanceBar(props: {
);
}

function splitChannelNumbers(channel: MutinyChannel): {
inbound: number;
reserve: number;
outbound: number;
} {
return {
inbound: Number(channel.inbound) || 0,
reserve: Number(channel.reserve),
outbound: Number(channel.balance)
};
}

function SingleChannelItem(props: { channel: MutinyChannel }) {
const i18n = useI18n();
const [state, _actions] = useMegaStore();
const network = state.mutiny_wallet?.get_network() as Network;

const [confirmOpen, setConfirmOpen] = createSignal(false);
const [confirmLoading, setConfirmLoading] = createSignal(false);

function confirmChannelClose() {
setConfirmOpen(true);
}

async function closeChannel() {
try {
if (!props.channel.outpoint) return;
setConfirmLoading(true);
await state.mutiny_wallet?.close_channel(
props.channel.outpoint,
false,
false
);
} catch (e) {
console.error(e);
showToast(eify(e));
} finally {
setConfirmOpen(false);
setConfirmLoading(false);
}
}

const channelDetails = createMemo(() => splitChannelNumbers(props.channel));

return (
<Card>
<VStack smallgap>
<BalanceBar
inbound={channelDetails().inbound}
reserve={channelDetails().reserve}
outbound={channelDetails().outbound}
hideHeader
/>
<div class="flex justify-between text-sm">
<ExternalLink
href={mempoolTxUrl(
props.channel.outpoint?.split(":")[0],
network
)}
>
{i18n.t("common.view_transaction")}
</ExternalLink>
<button
onClick={confirmChannelClose}
class="self-center font-semibold text-m-red no-underline active:text-m-red/80"
>
{i18n.t("settings.channels.close_channel")}
</button>
</div>
<ConfirmDialog
loading={confirmLoading()}
open={confirmOpen()}
onConfirm={closeChannel}
onCancel={() => setConfirmOpen(false)}
>
{i18n.t("settings.channels.close_channel_confirm")}
</ConfirmDialog>
</VStack>
</Card>
);
}

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;
Expand All @@ -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 (
<Switch>
<Match when={channelInfo()?.channelCount}>
<Card>
<NiceP>
{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")}
</NiceP>{" "}
<BalanceBar
inbound={Number(channelInfo()?.inbound) || 0}
reserve={Number(channelInfo()?.reserve) || 0}
outbound={Number(channelInfo()?.outbound) || 0}
/>
<TinyText>
{i18n.t("settings.channels.inbound_outbound_tip")}
</TinyText>
<TinyText>
{i18n.t("settings.channels.reserve_tip")}
</TinyText>
</Card>
<VStack>
<Card>
<NiceP>
{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"
)}
</NiceP>{" "}
<BalanceBar
inbound={Number(channelInfo()?.inbound) || 0}
reserve={Number(channelInfo()?.reserve) || 0}
outbound={Number(channelInfo()?.outbound) || 0}
/>
<TinyText>
{i18n.t("settings.channels.inbound_outbound_tip")}
</TinyText>
<TinyText>
{i18n.t("settings.channels.reserve_tip")}
</TinyText>
</Card>
<Show when={channelInfo()?.online?.length}>
<SettingsCard>
<Collapser
title={i18n.t(
"settings.channels.online_channels"
)}
activityLight="on"
>
<VStack>
<For each={channelInfo()?.online}>
{(channel) => (
<SingleChannelItem
channel={channel}
/>
)}
</For>
</VStack>
</Collapser>
</SettingsCard>
</Show>
<Show when={channelInfo()?.offline?.length}>
<SettingsCard>
<Collapser
title={i18n.t(
"settings.channels.offline_channels"
)}
activityLight="off"
>
<VStack>
<For each={channelInfo()?.offline}>
{(channel) => (
<SingleChannelItem
channel={channel}
/>
)}
</For>
</VStack>
</Collapser>
</SettingsCard>
</Show>
</VStack>
</Match>
<Match when={true}>
<NiceP>{i18n.t("settings.channels.no_channels")}</NiceP>
Expand All @@ -135,7 +309,9 @@ export function Channels() {
<LargeHeader>
{i18n.t("settings.channels.title")}
</LargeHeader>
<LiquidityMonitor />
<Suspense>
<LiquidityMonitor />
</Suspense>
</DefaultMain>
<NavBar activeTab="settings" />
</SafeArea>
Expand Down