Fix WalletPay

This commit is contained in:
Jon Staab
2026-02-26 13:06:34 -08:00
parent e0c5f0d4f1
commit f6245c712d
2 changed files with 35 additions and 41 deletions
+24 -38
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import {gt} from "@welshman/lib"
import {Invoice} from "@getalby/lightning-tools/bolt11"
import {debounce} from "throttle-debounce"
import {session} from "@welshman/app"
import Bolt from "@assets/icons/bolt.svg?dataurl"
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
@@ -30,7 +30,7 @@
loading = true
try {
if (hasAmount) {
if (gt(invoice!.satoshi, 0)) {
await payInvoice(invoice!.paymentRequest)
} else {
await payInvoice(invoice!.paymentRequest, sats * 1000)
@@ -55,7 +55,6 @@
let loading = $state(false)
let invoice: Invoice | undefined = $state()
let sats = $state(0)
const hasAmount = $derived((invoice?.satoshi ?? 0) > 0)
</script>
<Modal>
@@ -66,34 +65,27 @@
</ModalHeader>
{#if invoice}
<div class="card2 bg-alt flex flex-col gap-2">
{#if $session?.wallet?.type === "webln" && !hasAmount}
<p class="text-sm opacity-75">
Uh oh! It looks like your current wallet doesn't support invoices without an amount. See
if you can get a lightning invoice with a pre-set amount.
</p>
{:else}
<FieldInline>
{#snippet label()}
Amount (satoshis)
{/snippet}
{#snippet input()}
<div class="flex flex-grow justify-end">
<label class="input input-bordered flex items-center gap-2">
<Icon icon={Bolt} />
<input
bind:value={sats}
type="number"
class="w-14"
disabled={invoice!.satoshi > 0} />
</label>
</div>
{/snippet}
</FieldInline>
<p class="text-sm opacity-75">
You're about to pay a bitcoin lightning invoice with the following description:
<strong>{invoice.description || "[no description]"}</strong>"
</p>
{/if}
<FieldInline>
{#snippet label()}
Amount (satoshis)
{/snippet}
{#snippet input()}
<div class="flex flex-grow justify-end">
<label class="input input-bordered flex items-center gap-2">
<Icon icon={Bolt} />
<input
bind:value={sats}
type="number"
class="w-14"
disabled={invoice!.satoshi > 0} />
</label>
</div>
{/snippet}
</FieldInline>
<p class="text-sm opacity-75">
You're about to pay a bitcoin lightning invoice with the following description:
<strong>{invoice.description || "[no description]"}</strong>"
</p>
</div>
{:else}
<Scanner onscan={onScan} />
@@ -107,13 +99,7 @@
<Icon icon={AltArrowLeft} />
Go back
</Button>
<Button
class="btn btn-primary"
onclick={confirm}
disabled={!invoice ||
sats === 0 ||
loading ||
($session?.wallet?.type === "webln" && !hasAmount)}>
<Button class="btn btn-primary" onclick={confirm} disabled={!invoice || sats === 0 || loading}>
{#if loading}
<span class="loading loading-spinner loading-sm"></span>
{:else}
+11 -3
View File
@@ -1,6 +1,6 @@
<script lang="ts">
import cx from "classnames"
import {LOCALE, always, sleep} from "@welshman/lib"
import {LOCALE, always, call, sleep} from "@welshman/lib"
import {WalletType, displayRelayUrl, isNWCWallet, fromMsats} from "@welshman/util"
import {session, pubkey, profilesByPubkey} from "@welshman/app"
import DownloadMinimalistic from "@assets/icons/download-minimalistic.svg?dataurl"
@@ -42,7 +42,7 @@
}
}
let walletStatus = $state<"checking" | "connected" | "unavailable">("checking")
let walletStatus = $state("checking")
const isWalletAvailable = $derived(Boolean($session?.wallet) && walletStatus === "connected")
const statusClass = $derived(
@@ -58,7 +58,15 @@
if (wallet) {
const promise =
wallet.type === WalletType.NWC ? getNwcClient().getInfo() : getWebLn().getInfo()
wallet.type === WalletType.NWC
? getNwcClient().getInfo()
: call(async () => {
const client = getWebLn()
await client.enable()
return client.getInfo()
})
walletStatus = await Promise.race([
promise.then(always("connected")).catch(always("unavailable")),