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