diff --git a/src/components/layout/Radio.tsx b/src/components/layout/Radio.tsx index 7de314c..8dd785d 100644 --- a/src/components/layout/Radio.tsx +++ b/src/components/layout/Radio.tsx @@ -24,7 +24,7 @@ export function StyledRadioGroup(props: { value: string, choices: Choices, onVal
-
{choice.label}
+
{choice.label}
{choice.caption}
diff --git a/src/routes/Scanner.tsx b/src/routes/Scanner.tsx index 87f499d..a0fc6ee 100644 --- a/src/routes/Scanner.tsx +++ b/src/routes/Scanner.tsx @@ -14,6 +14,7 @@ export type ParsedParams = { network?: string; memo?: string; node_pubkey?: string; + lnurl?: string; } export function toParsedParams(str: string, ourNetwork: string): Result { @@ -25,23 +26,12 @@ export function toParsedParams(str: string, ourNetwork: string): Result void }) { +function MethodChooser(props: { source: SendSource, setSource: (source: string) => void, both?: boolean }) { const [store, _actions] = useMegaStore(); const methods = createMemo(() => { return [ - { value: "lightning", label: "Lightning", caption: store.balance?.lightning ? `${store.balance?.lightning.toLocaleString()} SATS` : "No balance" }, - { value: "onchain", label: "On-chain", caption: store.balance?.confirmed ? `${store.balance?.confirmed.toLocaleString()} SATS` : "No balance" } + { value: "lightning", label: "Lightning Balance", caption: store.balance?.lightning ? `${store.balance?.lightning.toLocaleString()} SATS` : "No balance" }, + { value: "onchain", label: "On-chain Balance", caption: store.balance?.confirmed ? `${store.balance?.confirmed.toLocaleString()} SATS` : "No balance" } ] }) return ( - + + + + + + + + + + + ) } @@ -80,6 +90,7 @@ function DestinationShower(props: { address?: string, invoice?: MutinyInvoice, nodePubkey?: string, + lnurl?: string, clearAll: () => void, }) { return ( @@ -93,6 +104,9 @@ function DestinationShower(props: { + + + ) @@ -113,6 +127,7 @@ export default function Send() { // These can only be derived from the "destination" signal const [invoice, setInvoice] = createSignal(); const [nodePubkey, setNodePubkey] = createSignal(); + const [lnurlp, setLnurlp] = createSignal(); const [address, setAddress] = createSignal(); const [description, setDescription] = createSignal(); @@ -131,6 +146,7 @@ export default function Send() { setAddress(undefined); setDescription(undefined); setNodePubkey(undefined); + setLnurlp(undefined); setFieldDestination(""); } @@ -154,7 +170,6 @@ export default function Send() { // Rerun every time the destination changes createEffect(() => { const source = destination(); - console.log(source) if (!source) return undefined; try { if (source.address) setAddress(source.address) @@ -170,6 +185,14 @@ export default function Send() { setAmountSats(source.amount_sats || 0n); setNodePubkey(source.node_pubkey); setSource("lightning") + } else if (source.lnurl) { + state.mutiny_wallet?.decode_lnurl(source.lnurl).then((lnurlParams) => { + if (lnurlParams.tag === "payRequest") { + setAmountSats(source.amount_sats || 0n); + setLnurlp(source.lnurl); + setSource("lightning") + } + }) } else { setAmountSats(source.amount_sats || 0n); setSource("onchain") @@ -190,7 +213,7 @@ export default function Send() { showToast(result.error); return; } else { - if (result.value?.address || result.value?.invoice || result.value?.node_pubkey) { + if (result.value?.address || result.value?.invoice || result.value?.node_pubkey || result.value?.lnurl) { setDestination(result.value); // Important! we need to clear the scan result once we've used it actions.setScanResult(undefined); @@ -278,6 +301,16 @@ export default function Send() { } else { sentDetails.amount = amountSats(); } + } else if (source() === "lightning" && lnurlp()) { + const nodes = await state.mutiny_wallet?.list_nodes(); + const firstNode = nodes[0] as string || "" + const payment = await state.mutiny_wallet?.lnurl_pay(firstNode, lnurlp()!, amountSats(), tags); + + if (!payment?.paid) { + throw new Error("Lnurl Pay failed") + } else { + sentDetails.amount = amountSats(); + } } else if (source() === "onchain" && address()) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const txid = await state.mutiny_wallet?.send_to_address(address()!, amountSats(), tags); @@ -308,7 +341,7 @@ export default function Send() { - }> + }> clearAll()} title="Start Over" /> Send Bitcoin @@ -339,18 +372,16 @@ export default function Send() { - - - - + + + - + Private tags -