mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2025-12-17 14:24:26 +01:00
Show the channel fee warning from federation swap
This commit is contained in:
committed by
Tony Giorgio
parent
a3e356dc09
commit
570e46dbff
@@ -5,7 +5,10 @@ import { FeesModal } from "~/components/MoreInfoModal";
|
|||||||
import { useI18n } from "~/i18n/context";
|
import { useI18n } from "~/i18n/context";
|
||||||
import { useMegaStore } from "~/state/megaStore";
|
import { useMegaStore } from "~/state/megaStore";
|
||||||
|
|
||||||
export function ReceiveWarnings(props: { amountSats: string | bigint }) {
|
export function ReceiveWarnings(props: {
|
||||||
|
amountSats: string | bigint;
|
||||||
|
from_fedi_to_ln: boolean;
|
||||||
|
}) {
|
||||||
const i18n = useI18n();
|
const i18n = useI18n();
|
||||||
const [state, _actions] = useMegaStore();
|
const [state, _actions] = useMegaStore();
|
||||||
|
|
||||||
@@ -26,7 +29,7 @@ export function ReceiveWarnings(props: { amountSats: string | bigint }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const warningText = () => {
|
const warningText = () => {
|
||||||
if (state.federations?.length !== 0) {
|
if (state.federations?.length !== 0 && props.from_fedi_to_ln != true) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if ((state.balance?.lightning || 0n) === 0n) {
|
if ((state.balance?.lightning || 0n) === 0n) {
|
||||||
|
|||||||
@@ -606,7 +606,8 @@ export default {
|
|||||||
completed: "Swap Completed",
|
completed: "Swap Completed",
|
||||||
sats_added: "+{{amount}} sats have been added to your Lightning balance",
|
sats_added: "+{{amount}} sats have been added to your Lightning balance",
|
||||||
sats_fee: "+{{amount}} sats fee",
|
sats_fee: "+{{amount}} sats fee",
|
||||||
confirm_swap: "Confirm Swap"
|
confirm_swap: "Confirm Swap",
|
||||||
|
preview_swap: "Preview Swap Fee"
|
||||||
},
|
},
|
||||||
reload: {
|
reload: {
|
||||||
mutiny_update: "Mutiny Update",
|
mutiny_update: "Mutiny Update",
|
||||||
|
|||||||
@@ -377,7 +377,10 @@ export function Receive() {
|
|||||||
setAmountSats={setAmount}
|
setAmountSats={setAmount}
|
||||||
onSubmit={getQr}
|
onSubmit={getQr}
|
||||||
/>
|
/>
|
||||||
<ReceiveWarnings amountSats={amount() || "0"} />
|
<ReceiveWarnings
|
||||||
|
amountSats={amount() || "0"}
|
||||||
|
from_fedi_to_ln={false}
|
||||||
|
/>
|
||||||
</VStack>
|
</VStack>
|
||||||
<div class="flex-1" />
|
<div class="flex-1" />
|
||||||
<VStack>
|
<VStack>
|
||||||
|
|||||||
@@ -21,13 +21,14 @@ import {
|
|||||||
DefaultMain,
|
DefaultMain,
|
||||||
Failure,
|
Failure,
|
||||||
Fee,
|
Fee,
|
||||||
HackActivityType,
|
FeeDisplay,
|
||||||
InfoBox,
|
InfoBox,
|
||||||
LargeHeader,
|
LargeHeader,
|
||||||
MegaCheck,
|
MegaCheck,
|
||||||
MegaEx,
|
MegaEx,
|
||||||
MutinyWalletGuard,
|
MutinyWalletGuard,
|
||||||
NavBar,
|
NavBar,
|
||||||
|
ReceiveWarnings,
|
||||||
showToast,
|
showToast,
|
||||||
SuccessModal,
|
SuccessModal,
|
||||||
TextField,
|
TextField,
|
||||||
@@ -49,18 +50,20 @@ export function SwapLightning() {
|
|||||||
const i18n = useI18n();
|
const i18n = useI18n();
|
||||||
|
|
||||||
const [amountSats, setAmountSats] = createSignal(0n);
|
const [amountSats, setAmountSats] = createSignal(0n);
|
||||||
|
const [feeSats, setFeeSats] = createSignal(0n);
|
||||||
|
const [maxFederationBalanceBeforeSwap, setMaxFederationBalanceBeforeSwap] =
|
||||||
|
createSignal(0n);
|
||||||
|
const [previewFee, setPreviewFee] = createSignal(false);
|
||||||
|
|
||||||
const [loading, setLoading] = createSignal(false);
|
const [loading, setLoading] = createSignal(false);
|
||||||
|
|
||||||
// Details Modal
|
|
||||||
const [detailsOpen, setDetailsOpen] = createSignal(false);
|
|
||||||
const [detailsKind, setDetailsKind] = createSignal<HackActivityType>();
|
|
||||||
const [detailsId, setDetailsId] = createSignal("");
|
|
||||||
|
|
||||||
const [sweepResult, setSweepResult] = createSignal<SweepResultDetails>();
|
const [sweepResult, setSweepResult] = createSignal<SweepResultDetails>();
|
||||||
|
|
||||||
function resetState() {
|
function resetState() {
|
||||||
setAmountSats(0n);
|
setAmountSats(0n);
|
||||||
|
setFeeSats(0n);
|
||||||
|
setPreviewFee(false);
|
||||||
|
setMaxFederationBalanceBeforeSwap(0n);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setSweepResult(undefined);
|
setSweepResult(undefined);
|
||||||
}
|
}
|
||||||
@@ -110,7 +113,7 @@ export function SwapLightning() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (amountSats() > (state.balance?.federation || 0n)) {
|
if (amountSats() > (state.balance?.federation || 0n)) {
|
||||||
return i18n.t("swap.insufficient_funds");
|
return i18n.t("swap_lightning.insufficient_funds");
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -128,11 +131,47 @@ export function SwapLightning() {
|
|||||||
return amountSats() === calculateMaxFederation();
|
return amountSats() === calculateMaxFederation();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const feeIsSet = createMemo(() => {
|
||||||
|
return feeSats() !== 0n;
|
||||||
|
});
|
||||||
|
|
||||||
|
const feeEstimate = async () => {
|
||||||
|
if (canSwap()) {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
if (isMax()) {
|
||||||
|
const fee =
|
||||||
|
await state.mutiny_wallet?.estimate_sweep_federation_fee(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
setFeeSats(fee);
|
||||||
|
setMaxFederationBalanceBeforeSwap(calculateMaxFederation());
|
||||||
|
setPreviewFee(true);
|
||||||
|
} else {
|
||||||
|
const fee =
|
||||||
|
await state.mutiny_wallet?.estimate_sweep_federation_fee(
|
||||||
|
amountSats()
|
||||||
|
);
|
||||||
|
setFeeSats(fee);
|
||||||
|
setMaxFederationBalanceBeforeSwap(calculateMaxFederation());
|
||||||
|
setPreviewFee(true);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return undefined;
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MutinyWalletGuard>
|
<MutinyWalletGuard>
|
||||||
<DefaultMain>
|
<DefaultMain>
|
||||||
<BackLink />
|
<BackLink />
|
||||||
<LargeHeader>{i18n.t("swap.header")}</LargeHeader>
|
<LargeHeader>{i18n.t("swap_lightning.header")}</LargeHeader>
|
||||||
<SuccessModal
|
<SuccessModal
|
||||||
confirmText={
|
confirmText={
|
||||||
sweepResult()?.result
|
sweepResult()?.result
|
||||||
@@ -153,21 +192,13 @@ export function SwapLightning() {
|
|||||||
<Failure reason={sweepResult()?.failure_reason} />
|
<Failure reason={sweepResult()?.failure_reason} />
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={sweepResult()?.result}>
|
<Match when={sweepResult()?.result}>
|
||||||
<Show when={detailsId() && detailsKind()}>
|
|
||||||
<ActivityDetailsModal
|
|
||||||
open={detailsOpen()}
|
|
||||||
kind={detailsKind()}
|
|
||||||
id={detailsId()}
|
|
||||||
setOpen={setDetailsOpen}
|
|
||||||
/>
|
|
||||||
</Show>
|
|
||||||
<MegaCheck />
|
<MegaCheck />
|
||||||
<div class="flex flex-col justify-center">
|
<div class="flex flex-col justify-center">
|
||||||
<h1 class="mb-2 mt-4 w-full justify-center text-center text-2xl font-semibold md:text-3xl">
|
<h1 class="mb-2 mt-4 w-full justify-center text-center text-2xl font-semibold md:text-3xl">
|
||||||
{i18n.t("swap.completed")}
|
{i18n.t("swap_lightning.completed")}
|
||||||
</h1>
|
</h1>
|
||||||
<p class="text-center text-xl">
|
<p class="text-center text-xl">
|
||||||
{i18n.t("swap.sats_added", {
|
{i18n.t("swap_lightning.sats_added", {
|
||||||
amount: Number(
|
amount: Number(
|
||||||
sweepResult()?.result?.amount
|
sweepResult()?.result?.amount
|
||||||
).toLocaleString()
|
).toLocaleString()
|
||||||
@@ -205,6 +236,17 @@ export function SwapLightning() {
|
|||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
<Show when={feeIsSet()}>
|
||||||
|
<FeeDisplay
|
||||||
|
amountSats={amountSats().toString()}
|
||||||
|
fee={feeSats()!.toString()}
|
||||||
|
maxAmountSats={maxFederationBalanceBeforeSwap()!.toString()}
|
||||||
|
/>
|
||||||
|
</Show>
|
||||||
|
<ReceiveWarnings
|
||||||
|
amountSats={amountSats() || "0"}
|
||||||
|
from_fedi_to_ln={true}
|
||||||
|
/>
|
||||||
<Show when={amountWarning() && amountSats() > 0n}>
|
<Show when={amountWarning() && amountSats() > 0n}>
|
||||||
<InfoBox accent={"red"}>{amountWarning()}</InfoBox>
|
<InfoBox accent={"red"}>{amountWarning()}</InfoBox>
|
||||||
</Show>
|
</Show>
|
||||||
@@ -214,10 +256,18 @@ export function SwapLightning() {
|
|||||||
<Button
|
<Button
|
||||||
disabled={!canSwap()}
|
disabled={!canSwap()}
|
||||||
intent="blue"
|
intent="blue"
|
||||||
onClick={handleSwap}
|
onClick={() => {
|
||||||
|
if (!previewFee()) {
|
||||||
|
feeEstimate();
|
||||||
|
} else {
|
||||||
|
handleSwap();
|
||||||
|
}
|
||||||
|
}}
|
||||||
loading={loading()}
|
loading={loading()}
|
||||||
>
|
>
|
||||||
{i18n.t("swap.confirm_swap")}
|
{!previewFee()
|
||||||
|
? i18n.t("swap_lightning.preview_swap")
|
||||||
|
: i18n.t("swap_lightning.confirm_swap")}
|
||||||
</Button>
|
</Button>
|
||||||
</VStack>
|
</VStack>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user