2026-02-25 22:25:59 +00:00
|
|
|
<script lang="ts">
|
2026-06-24 20:56:53 +00:00
|
|
|
import {onDestroy} from "svelte"
|
2026-06-10 20:00:59 +00:00
|
|
|
import {first} from "@welshman/lib"
|
2026-02-25 22:25:59 +00:00
|
|
|
import {signer, deriveZapperForPubkey} from "@welshman/app"
|
|
|
|
|
import {request} from "@welshman/net"
|
|
|
|
|
import {Router} from "@welshman/router"
|
|
|
|
|
import {requestZap, makeZapRequest, getZapResponseFilter} from "@welshman/util"
|
|
|
|
|
import Bolt from "@assets/icons/bolt.svg?dataurl"
|
|
|
|
|
import Copy from "@assets/icons/copy.svg?dataurl"
|
|
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
|
|
|
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
|
|
|
|
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
|
|
|
|
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
|
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
|
|
|
|
import {errorMessage} from "@lib/util"
|
|
|
|
|
import ProfileLink from "@app/components/ProfileLink.svelte"
|
|
|
|
|
import QRCode from "@app/components/QRCode.svelte"
|
|
|
|
|
import WalletConnect from "@app/components/WalletConnect.svelte"
|
2026-07-15 21:23:43 +00:00
|
|
|
import ZapForm from "@app/components/ZapForm.svelte"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
2026-06-10 20:00:59 +00:00
|
|
|
import {zapAmounts} from "@app/settings"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {clip, pushToast} from "@app/toast"
|
2026-02-25 22:25:59 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
2026-06-15 21:00:15 +00:00
|
|
|
url?: string
|
2026-02-25 22:25:59 +00:00
|
|
|
pubkey: string
|
|
|
|
|
eventId?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url, pubkey, eventId}: Props = $props()
|
|
|
|
|
|
|
|
|
|
const zapperStore = deriveZapperForPubkey(pubkey)
|
|
|
|
|
|
2026-06-10 20:00:59 +00:00
|
|
|
const back = () => history.back()
|
2026-02-25 22:25:59 +00:00
|
|
|
|
|
|
|
|
const createInvoice = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const zapper = $zapperStore!
|
|
|
|
|
const msats = amount * 1000
|
|
|
|
|
const relays = url ? [url] : Router.get().ForPubkey(pubkey).getUrls()
|
|
|
|
|
const params = {pubkey, content, eventId, msats, relays, zapper}
|
|
|
|
|
const event = await $signer!.sign(makeZapRequest(params))
|
|
|
|
|
const res = await requestZap({zapper, event})
|
|
|
|
|
|
|
|
|
|
if (!res.invoice) {
|
|
|
|
|
return pushToast({
|
|
|
|
|
theme: "error",
|
|
|
|
|
message: `Failed to create zap invoice: ${res.error || "no error given"}`,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
invoice = res.invoice
|
|
|
|
|
|
|
|
|
|
paymentController?.abort()
|
|
|
|
|
paymentController = new AbortController()
|
|
|
|
|
|
|
|
|
|
request({
|
|
|
|
|
relays,
|
|
|
|
|
signal: paymentController.signal,
|
|
|
|
|
filters: [getZapResponseFilter({zapper, pubkey, eventId})],
|
|
|
|
|
onEvent: () => {
|
|
|
|
|
pushToast({message: "Payment sent!"})
|
|
|
|
|
paymentController?.abort()
|
|
|
|
|
back()
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
|
|
|
|
|
const message = errorMessage(e)
|
|
|
|
|
|
|
|
|
|
pushToast({
|
|
|
|
|
theme: "error",
|
|
|
|
|
message: `Failed to create zap invoice: ${message}`,
|
|
|
|
|
})
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const connectWallet = () => {
|
|
|
|
|
pushModal(WalletConnect)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const copyInvoice = () => {
|
|
|
|
|
if (invoice) {
|
|
|
|
|
clip(invoice)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-10 20:00:59 +00:00
|
|
|
let amount = $state<number>(first($zapAmounts) ?? 21)
|
2026-02-25 22:25:59 +00:00
|
|
|
let content = $state("⚡️")
|
|
|
|
|
let loading = $state(false)
|
|
|
|
|
let invoice = $state<string>()
|
|
|
|
|
let paymentController: AbortController | undefined = $state()
|
|
|
|
|
|
|
|
|
|
onDestroy(() => {
|
|
|
|
|
paymentController?.abort()
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Modal>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<ModalHeader>
|
|
|
|
|
<ModalTitle>Send a Zap</ModalTitle>
|
2026-04-07 21:53:19 +00:00
|
|
|
<ModalSubtitle>To <ProfileLink {pubkey} class="text-primary!" /></ModalSubtitle>
|
2026-02-25 22:25:59 +00:00
|
|
|
</ModalHeader>
|
|
|
|
|
|
|
|
|
|
{#if invoice}
|
2026-07-15 21:23:43 +00:00
|
|
|
<div class="flex flex-col gap-6">
|
|
|
|
|
<div class="flex flex-col items-center gap-4">
|
|
|
|
|
<QRCode code={invoice} class="w-full max-w-56" />
|
|
|
|
|
<p class="text-content-muted text-center text-sm">
|
|
|
|
|
Scan with your lightning wallet, or copy the invoice below.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<label class="input flex w-full items-center gap-2">
|
|
|
|
|
<input readonly class="min-w-0 grow truncate" value={invoice} />
|
|
|
|
|
<Button
|
|
|
|
|
class="button button-neutral button-sm button-square shrink-0"
|
|
|
|
|
onclick={copyInvoice}>
|
|
|
|
|
<Icon icon={Copy} size={4} />
|
|
|
|
|
</Button>
|
|
|
|
|
</label>
|
2026-02-25 22:25:59 +00:00
|
|
|
</div>
|
|
|
|
|
{:else}
|
2026-07-15 21:23:43 +00:00
|
|
|
<ZapForm bind:amount bind:content>
|
|
|
|
|
{#snippet children()}
|
|
|
|
|
<div class="card card-sm card-flat flex flex-col items-center gap-3 p-4 text-center">
|
|
|
|
|
<p class="text-content-muted text-sm">
|
|
|
|
|
Connect a wallet to pay instantly without scanning a QR code.
|
|
|
|
|
</p>
|
|
|
|
|
<Button class="button button-neutral" onclick={connectWallet}>
|
|
|
|
|
Connect a lightning wallet
|
|
|
|
|
</Button>
|
2026-02-25 22:25:59 +00:00
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
2026-07-15 21:23:43 +00:00
|
|
|
</ZapForm>
|
2026-02-25 22:25:59 +00:00
|
|
|
{/if}
|
|
|
|
|
</ModalBody>
|
|
|
|
|
<ModalFooter>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-link" onclick={back}>
|
2026-02-25 22:25:59 +00:00
|
|
|
<Icon icon={AltArrowLeft} />
|
|
|
|
|
Go back
|
|
|
|
|
</Button>
|
|
|
|
|
{#if !invoice}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-primary" onclick={createInvoice} disabled={loading}>
|
2026-02-25 22:25:59 +00:00
|
|
|
<Spinner {loading}>
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
{#if !loading}
|
|
|
|
|
<Icon icon={Bolt} />
|
|
|
|
|
{/if}
|
|
|
|
|
Create invoice
|
|
|
|
|
</div>
|
|
|
|
|
</Spinner>
|
|
|
|
|
</Button>
|
|
|
|
|
{/if}
|
|
|
|
|
</ModalFooter>
|
|
|
|
|
</Modal>
|