App: show lightning address

Some formatting fixes also sneaked in.
This commit is contained in:
Anton Kovalenko 2021-09-24 05:28:10 +03:00
parent ae70ec80b1
commit 8663e85c5c

@ -55,6 +55,9 @@
$: autoMemo = genAutoMemo(payway, $: autoMemo = genAutoMemo(payway,
accountComplete && accounts[inputId], accountComplete && accounts[inputId],
realAmount) realAmount)
let lightningAddress;
$: lightningAddress = accountComplete ?
genAddress(payway, accounts[inputId], realAmount):""
function lnurlEncode(url) { function lnurlEncode(url) {
return bech32.encode("LNURL", return bech32.encode("LNURL",
@ -66,6 +69,16 @@
return ('0' + (byte & 0xFF).toString(16)).slice(-2); return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('') }).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) { function genLNURL(payway,account,amount,memo) {
let params = new URLSearchParams(); let params = new URLSearchParams();
@ -163,7 +176,6 @@
<input bind:value={memo} placeholder="{autoMemo}" <input bind:value={memo} placeholder="{autoMemo}"
class="form-control"/> class="form-control"/>
</label> </label>
</SiteCard> </SiteCard>
<SiteCard> <SiteCard>
{#if lnurl} {#if lnurl}
@ -184,13 +196,6 @@
</a> </a>
<!-- {/key} --> <!-- {/key} -->
</div> </div>
<div class="d-flex justify-content-center align-items-stretch"
class:invisible={!lnurl}>
<p class="form-text">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.</p>
</div>
<div class="btn-group flex-wrap mt-auto mb-2" <div class="btn-group flex-wrap mt-auto mb-2"
role="group" class:invisible={!lnurl}> role="group" class:invisible={!lnurl}>
<CTC let:id let:action text={lnurl}> <CTC let:id let:action text={lnurl}>
@ -216,6 +221,24 @@
<div slot="tip">get an invoice for wallets with no lnurl-pay</div> <div slot="tip">get an invoice for wallets with no lnurl-pay</div>
</Tipped> </Tipped>
</div> </div>
{#if lightningAddress}
<CTC let:id let:action force text={lightningAddress}}>
<div class="input-group mt-3">
<div class="input-group-prepend">
<span class="input-group-text">
<a href="https://lightningaddress.com/">Lightning address:</a>
</span>
</div>
<div class="user-select-all form-control"
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis"
on:click={action} id={id}>{lightningAddress}
</div>
</div>
</CTC>
{/if}
</SiteCard> </SiteCard>
</SiteDeck> </SiteDeck>