From b6bdd143f0501fb8c13f29f2769ed3ed7b9294bc Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Wed, 8 May 2024 18:15:54 -0500 Subject: [PATCH] amountless on-chain, fix receive warnings --- public/i18n/en.json | 2 +- src/components/ReceiveWarnings.tsx | 22 +++++---- src/routes/Receive.tsx | 74 +++++++++++++++--------------- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/public/i18n/en.json b/public/i18n/en.json index a41eb261..bb0d2611 100644 --- a/public/i18n/en.json +++ b/public/i18n/en.json @@ -124,7 +124,7 @@ "error_creating_address": "Something went wrong when creating the on-chain address.", "amount_editable": { "receive_too_small": "Your first receive needs to be {{amount}} SATS or greater.", - "setup_fee_lightning": "A lightning setup fee will be charged if paid over lightning.", + "setup_fee_lightning": "A lightning setup fee will be charged.", "more_than_21m": "There are only 21 million bitcoin.", "set_amount": "Set amount", "max": "MAX", diff --git a/src/components/ReceiveWarnings.tsx b/src/components/ReceiveWarnings.tsx index 2471923a..c7895afc 100644 --- a/src/components/ReceiveWarnings.tsx +++ b/src/components/ReceiveWarnings.tsx @@ -39,17 +39,19 @@ export function ReceiveWarnings(props: { if (state.federations?.length !== 0 && props.from_fedi_to_ln !== true) { return undefined; } - if ( - (state.balance?.lightning || 0n) === 0n && - !state.settings?.lsps_connection_string - ) { - return i18n.t("receive.amount_editable.receive_too_small", { - amount: "100,000" - }); - } + if (props.flavor === "lightning") { + if ( + (state.balance?.lightning || 0n) === 0n && + !state.settings?.lsps_connection_string + ) { + return i18n.t("receive.amount_editable.receive_too_small", { + amount: "100,000" + }); + } - if (props.amountSats > (inboundCapacity() || 0n)) { - return i18n.t("receive.amount_editable.setup_fee_lightning"); + if (props.amountSats > (inboundCapacity() || 0n)) { + return i18n.t("receive.amount_editable.setup_fee_lightning"); + } } return undefined; diff --git a/src/routes/Receive.tsx b/src/routes/Receive.tsx index fb33c392..5e8308ee 100644 --- a/src/routes/Receive.tsx +++ b/src/routes/Receive.tsx @@ -247,22 +247,24 @@ export function Receive() { } } - async function getOnchainReceiveString(amount: bigint) { + async function getOnchainReceiveString(amount?: bigint) { try { - if (amount < 546n) { + if (amount && amount < 546n) { throw new Error(i18n.t("receive.error_under_min_onchain")); } const raw = await sw.get_new_address(receiveTags()); - - const btc_amount = await sw.convert_sats_to_btc(amount); - - const params = objectToSearchParams({ - amount: btc_amount.toString() - }); - const address = raw?.address; - setRawReceiveStrings({ address }); - return `bitcoin:${address}?${params}`; + + if (amount && amount > 0n) { + const btc_amount = await sw.convert_sats_to_btc(amount); + const params = objectToSearchParams({ + amount: btc_amount.toString() + }); + setRawReceiveStrings({ address }); + return `bitcoin:${address}?${params}`; + } else { + return `bitcoin:${address}`; + } } catch (e) { console.error(e); } @@ -275,37 +277,31 @@ export function Receive() { } async function getQr() { - if (amount()) { - setLoading(true); - try { - if (flavor() === "lightning") { - const lightning = await getLightningReceiveString(amount()); - setReceiveStrings({ lightning }); - } - - if (flavor() === "onchain") { - const onchain = await getOnchainReceiveString(amount()); - setReceiveStrings({ onchain }); - } + setLoading(true); + try { + if (flavor() === "lightning") { + const lightning = await getLightningReceiveString(amount()); + setReceiveStrings({ lightning }); + } - if ( - !receiveStrings()?.lightning && - !receiveStrings()?.onchain - ) { - throw new Error(i18n.t("receive.receive_strings_error")); - } + if (flavor() === "onchain") { + const onchain = await getOnchainReceiveString(amount()); + setReceiveStrings({ onchain }); + } - // TODO: THOUGHTS? - if (!error()) { - setReceiveState("show"); - } - } catch (e) { - console.error(e); - showToast(eify(e)); + if (!receiveStrings()?.lightning && !receiveStrings()?.onchain) { + throw new Error(i18n.t("receive.receive_strings_error")); } - setLoading(false); + if (!error()) { + setReceiveState("show"); + } + } catch (e) { + console.error(e); + showToast(eify(e)); } + + setLoading(false); } const qrString = createMemo(() => { @@ -442,7 +438,9 @@ export function Receive() { />