From 8663e85c5c8329ae64f9080f342435aadef4e0bc Mon Sep 17 00:00:00 2001 From: Anton Kovalenko Date: Fri, 24 Sep 2021 05:28:10 +0300 Subject: [PATCH] App: show lightning address Some formatting fixes also sneaked in. --- src/App.svelte | 109 ++++++++++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 43 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 85952fc..075b7c6 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -6,7 +6,7 @@ import SiteCard from './SiteCard.svelte'; import SiteDeck from './SiteDeck.svelte'; import InputMask from './InputMask.svelte'; - + import payways from './payways.js'; import QR from './QR.svelte'; @@ -19,7 +19,7 @@ import PayFlow from './PayFlow.svelte'; let payway = payways[0]; - + setTimeout(()=>{ payway = payways[0]; accounts[inputId]=null; @@ -55,17 +55,30 @@ $: autoMemo = genAutoMemo(payway, accountComplete && accounts[inputId], realAmount) + let lightningAddress; + $: lightningAddress = accountComplete ? + genAddress(payway, accounts[inputId], realAmount):"" function lnurlEncode(url) { return bech32.encode("LNURL", bech32.toWords(UTF8.setBytesFromString(url)),2048) } - + function toHexString(byteArray) { return Array.from(byteArray, function(byte) { return ('0' + (byte & 0xFF).toString(16)).slice(-2); }).join('') } + function genAddress(payway,account,amount) { + if (!account || !payway) + return "" + const prefix = amount? + ((amount == Math.floor(amount)? ""+amount: + amount.toFixed(2))+payway.currency.toLowerCase()+"-"):"" + if (account[0]=='+') + account=account.slice(1) + return prefix + account + "@" + payway.id + ".lnurl-pay.me" + } function genLNURL(payway,account,amount,memo) { let params = new URLSearchParams(); @@ -125,7 +138,7 @@ {#key payway} - {#if lnurl} @@ -177,45 +189,56 @@
Expecting: {payway.acc.toLowerCase()}
{/if}
- - - - - -
- -
-

You might want to save image and share it - as you like. All form data are present in lnurl: don't share what you wanted to hide.

-
- -
- - - - {#if canShare} - - {/if} - - Pay -
open in your wallet
-
+ class:invisible={!lnurl}> + + + + + +
+
+ + + + {#if canShare} + + {/if} + + Pay +
open in your wallet
+
+ + + +
get an invoice for wallets with no lnurl-pay
+
+
+ + {#if lightningAddress} + +
+ +
{lightningAddress} +
+
+
+ {/if} + - - -
get an invoice for wallets with no lnurl-pay
-
-