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

Consider fedimint balance for on chain sends #1118

Merged
merged 3 commits into from
May 9, 2024
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: 3 additions & 1 deletion public/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@
"body": "Lightning receives will automatically go into your chosen federation. You can swap to self-custodial later if you want."
},
"receive_strings_error": "Something went wrong generating an invoice or on-chain address.",
"error_under_min_onchain": "That's under the dust limit! On-chain transactions should be much bigger."
"error_under_min_onchain": "That's under the dust limit! On-chain transactions should be much bigger.",
"warning_on_chain_fedi": "On-chain fedimint deposits require 10 confirmations.",
"warning_address_reuse": "Only send to this address once!"
},
"send": {
"search": {
Expand Down
87 changes: 46 additions & 41 deletions src/components/ActivityDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function OnchainHeader(props: { info: OnChainTx; kind?: HackActivityType }) {
</Match>
</Switch>
</div>
<Show when={props.kind !== "ChannelClose"}>
<Show when={props.kind !== "ChannelClose" && Number(amount()) > 0}>
<div class="flex flex-col items-center">
<div
class="text-2xl"
Expand Down Expand Up @@ -408,48 +408,53 @@ function OnchainDetails(props: {
"Pending"
)}
</KeyValue>
<KeyValue key={i18n.t("activity.transaction_details.txid")}>
<div class="flex gap-1">
{/* Have to do all these shenanigans because css / html is hard */}
<div class="grid w-full grid-cols-[minmax(0,_1fr)_auto] gap-1">
<a
target="_blank"
rel="noopener noreferrer"
href={mempoolTxUrl(props.info.txid, network)}
<Show when={props.info.txid}>
<KeyValue key={i18n.t("activity.transaction_details.txid")}>
<div class="flex gap-1">
{/* Have to do all these shenanigans because css / html is hard */}
<div class="grid w-full grid-cols-[minmax(0,_1fr)_auto] gap-1">
<a
target="_blank"
rel="noopener noreferrer"
href={mempoolTxUrl(
props.info.txid,
network
)}
>
<div class="flex flex-nowrap items-center font-mono text-white">
<span class="truncate">
{props.info.txid}
</span>
<span>
{props.info.txid.length > 32
? props.info.txid.slice(-8)
: ""}
</span>
<svg
class="inline-block w-[16px] overflow-visible pl-0.5 text-white"
width="16"
height="16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M6.00002 3.33337v1.33334H10.39L2.66669 12.39l.94333.9434 7.72338-7.72336V10h1.3333V3.33337H6.00002Z"
fill="currentColor"
/>
</svg>
</div>
</a>
</div>
<button
class="min-w-[1.5rem] p-1"
classList={{ "bg-m-green rounded": copied() }}
onClick={() => copy(props.info.txid)}
>
<div class="flex flex-nowrap items-center font-mono text-white">
<span class="truncate">
{props.info.txid}
</span>
<span>
{props.info.txid.length > 32
? props.info.txid.slice(-8)
: ""}
</span>
<svg
class="inline-block w-[16px] overflow-visible pl-0.5 text-white"
width="16"
height="16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M6.00002 3.33337v1.33334H10.39L2.66669 12.39l.94333.9434 7.72338-7.72336V10h1.3333V3.33337H6.00002Z"
fill="currentColor"
/>
</svg>
</div>
</a>
<Copy class="h-4 w-4" />
</button>
</div>
<button
class="min-w-[1.5rem] p-1"
classList={{ "bg-m-green rounded": copied() }}
onClick={() => copy(props.info.txid)}
>
<Copy class="h-4 w-4" />
</button>
</div>
</KeyValue>
</KeyValue>
</Show>
</ul>
</VStack>
);
Expand Down
13 changes: 12 additions & 1 deletion src/components/ReceiveWarnings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createResource, Match, Switch } from "solid-js";
import { createMemo, createResource, Match, Switch } from "solid-js";

import { InfoBox } from "~/components/InfoBox";
import { FeesModal } from "~/components/MoreInfoModal";
Expand Down Expand Up @@ -79,6 +79,12 @@ export function ReceiveWarnings(props: {
}
};

const onChainFedi = createMemo(() => {
if (props.flavor === "onchain" && state.federations?.length) {
return true;
}
});

return (
<Switch>
<Match when={tooSmallWarning()}>
Expand All @@ -92,6 +98,11 @@ export function ReceiveWarnings(props: {
{warningText()} <FeesModal />
</InfoBox>
</Match>
<Match when={onChainFedi()}>
<InfoBox accent="blue">
{i18n.t("receive.warning_on_chain_fedi")}
</InfoBox>
</Match>
</Switch>
);
}
8 changes: 7 additions & 1 deletion src/routes/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type OnChainTx = {
}>;
};
txid: string;
internal_id: string;
received: number;
sent: number;
confirmation_time: {
Expand Down Expand Up @@ -213,7 +214,7 @@ export function Receive() {
const paymentTxId =
paidState() === "onchain_paid"
? paymentTx()
? paymentTx()?.txid
? paymentTx()?.internal_id
: undefined
: paymentInvoice()
? paymentInvoice()?.payment_hash
Expand Down Expand Up @@ -459,6 +460,11 @@ export function Receive() {
<p>{error()}</p>
</InfoBox>
</Show>
<Show when={flavor() === "onchain"}>
<InfoBox accent="blue">
{i18n.t("receive.warning_address_reuse")}
</InfoBox>
</Show>
<IntegratedQr
value={qrString() ?? ""}
amountSats={amount() ? amount().toString() : "0"}
Expand Down
13 changes: 9 additions & 4 deletions src/routes/Send.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MutinyInvoice, TagItem } from "@mutinywallet/mutiny-wasm";
import {
createAsync,

Check warning on line 3 in src/routes/Send.tsx

View workflow job for this annotation

GitHub Actions / code_quality

'createAsync' is defined but never used. Allowed unused vars must match /^_/u
useLocation,
useNavigate,
useSearchParams
Expand Down Expand Up @@ -248,10 +248,15 @@
});

const maxOnchain = createMemo(() => {
return (
(state.balance?.confirmed ?? 0n) +
(state.balance?.unconfirmed ?? 0n)
);
const conf = state.balance?.confirmed ?? 0n;
const unc = state.balance?.unconfirmed ?? 0n;
const fed = state.balance?.federation ?? 0n;

if (fed > conf + unc) {
return fed;
} else {
return conf + unc;
}
});

const maxLightning = createMemo(() => {
Expand Down
Loading