Skip to content

Commit

Permalink
Add lightning sweep functionality to fedimint
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyRonning committed Feb 1, 2024
1 parent 6cd7708 commit f8f0103
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 50 deletions.
43 changes: 30 additions & 13 deletions src/components/BalanceBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,37 @@ export function BalanceBox(props: { loading?: boolean }) {
<Show when={state.federations && state.federations.length}>
<Show when={!props.loading} fallback={<LoadingShimmer />}>
<hr class="my-2 border-m-grey-750" />
<div class="flex flex-col gap-1">
<div class="text-2xl">
<AmountSats
amountSats={state.balance?.federation || 0}
icon="community"
denominationSize="lg"
/>
</div>
<div class="text-lg text-white/70">
<AmountFiat
amountSats={state.balance?.federation || 0n}
denominationSize="sm"
/>
<div class="flex justify-between">
<div class="flex flex-col gap-1">
<div class="text-2xl">
<AmountSats
amountSats={
state.balance?.federation || 0
}
icon="community"
denominationSize="lg"
/>
</div>
<div class="text-lg text-white/70">
<AmountFiat
amountSats={
state.balance?.federation || 0n
}
denominationSize="sm"
/>
</div>
</div>
<Show when={state.balance?.federation || 0n > 0n}>
<div class="self-end justify-self-end">
<A href="/swaplightning" class={STYLE}>
<img
src={shuffle}
alt="swaplightning"
class="h-6 w-6"
/>
</A>
</div>
</Show>
</div>
</Show>
</Show>
Expand Down
86 changes: 86 additions & 0 deletions src/components/Failure.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { MutinyInvoice } from "@mutinywallet/mutiny-wasm";
import { A, useNavigate, useSearchParams } from "@solidjs/router";
import {
createEffect,
createMemo,
createResource,
createSignal,
JSX,
Match,
onMount,
Show,
Suspense,
Switch
} from "solid-js";

import bolt from "~/assets/icons/bolt.svg";
import chain from "~/assets/icons/chain.svg";
import close from "~/assets/icons/close.svg";
import {
ActivityDetailsModal,
AmountEditable,
AmountFiat,
AmountSats,
BackPop,
Button,
DefaultMain,
Fee,
FeeDisplay,
HackActivityType,
InfoBox,
LabelCircle,
LoadingShimmer,
MegaCheck,
MegaClock,
MegaEx,
MethodChoice,
MutinyWalletGuard,
NavBar,
showToast,
SimpleInput,
SmallHeader,
StringShower,
SuccessModal,
UnstyledBackPop,
VStack
} from "~/components";
import { useI18n } from "~/i18n/context";
import { ParsedParams } from "~/logic/waila";
import { useMegaStore } from "~/state/megaStore";
import { eify, vibrateSuccess } from "~/utils";

export function Failure(props: { reason: string }) {
const i18n = useI18n();

return (
<Switch>
<Match when={props.reason === "Payment timed out."}>
<MegaClock />
<h1 class="mb-2 mt-4 w-full text-center text-2xl font-semibold md:text-3xl">
{i18n.t("send.payment_pending")}
</h1>
<InfoBox accent="white">
{i18n.t("send.payment_pending_description")}
</InfoBox>
</Match>
<Match
when={props.reason === "Channel reserve amount is too high."}
>
<MegaEx />
<h1 class="mb-2 mt-4 w-full text-center text-2xl font-semibold md:text-3xl">
{i18n.t("send.error_channel_reserves")}
</h1>
<InfoBox accent="white">
{i18n.t("send.error_channel_reserves_explained")}{" "}
<A href="/settings/channels">{i18n.t("common.why")}</A>
</InfoBox>
</Match>
<Match when={true}>
<MegaEx />
<h1 class="mb-2 mt-4 w-full text-center text-2xl font-semibold md:text-3xl">
{props.reason}
</h1>
</Match>
</Switch>
);
}
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export * from "./Restart";
export * from "./ResyncOnchain";
export * from "./SeedWords";
export * from "./SetupErrorDisplay";
export * from "./Failure";
export * from "./ShareCard";
export * from "./Toaster";
export * from "./NostrActivity";
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/en/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,14 @@ export default {
connecting: "Connecting...",
confirm_swap: "Confirm Swap"
},
swap_lightning: {
insufficient_funds: "You don't have enough funds to swap to lightning",
header: "Swap to Lightning",
initiated: "Swap Initiated",
sats_added: "+{{amount}} sats will be added to your Lightning balance",
sats_fee: "+{{amount}} sats fee",
confirm_swap: "Confirm Swap"
},
reload: {
mutiny_update: "Mutiny Update",
new_version_description:
Expand Down
4 changes: 3 additions & 1 deletion src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
Scanner,
Search,
Send,
Swap
Swap,
SwapLightning
} from "~/routes";
import {
Admin,
Expand Down Expand Up @@ -101,6 +102,7 @@ export function Router() {
<Route path="/scanner" component={Scanner} />
<Route path="/send" component={Send} />
<Route path="/swap" component={Swap} />
<Route path="/swaplightning" component={SwapLightning} />
<Route path="/search" component={Search} />
<Route path="/settings">
<Route path="/" component={Settings} />
Expand Down
37 changes: 1 addition & 36 deletions src/routes/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
BackPop,
Button,
DefaultMain,
Failure,
Fee,
FeeDisplay,
HackActivityType,
Expand Down Expand Up @@ -206,42 +207,6 @@ function DestinationItem(props: {
);
}

function Failure(props: { reason: string }) {
const i18n = useI18n();

return (
<Switch>
<Match when={props.reason === "Payment timed out."}>
<MegaClock />
<h1 class="mb-2 mt-4 w-full text-center text-2xl font-semibold md:text-3xl">
{i18n.t("send.payment_pending")}
</h1>
<InfoBox accent="white">
{i18n.t("send.payment_pending_description")}
</InfoBox>
</Match>
<Match
when={props.reason === "Channel reserve amount is too high."}
>
<MegaEx />
<h1 class="mb-2 mt-4 w-full text-center text-2xl font-semibold md:text-3xl">
{i18n.t("send.error_channel_reserves")}
</h1>
<InfoBox accent="white">
{i18n.t("send.error_channel_reserves_explained")}{" "}
<A href="/settings/channels">{i18n.t("common.why")}</A>
</InfoBox>
</Match>
<Match when={true}>
<MegaEx />
<h1 class="mb-2 mt-4 w-full text-center text-2xl font-semibold md:text-3xl">
{props.reason}
</h1>
</Match>
</Switch>
);
}

export function Send() {
const [state, actions] = useMegaStore();
const navigate = useNavigate();
Expand Down
Loading

0 comments on commit f8f0103

Please sign in to comment.