2025-07-07 22:28:36 +00:00
|
|
|
<script lang="ts">
|
2025-07-17 22:29:26 +00:00
|
|
|
import type {Snippet} from "svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {ZAP_GOAL} from "@welshman/util"
|
2025-07-17 22:29:26 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {ZapGoal} from "@welshman/domain"
|
|
|
|
|
import {Zappers} from "@welshman/app"
|
2025-07-07 22:28:36 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Zap from "@app/components/Zap.svelte"
|
2026-02-25 22:25:59 +00:00
|
|
|
import ZapInvoice from "@app/components/ZapInvoice.svelte"
|
2025-07-07 22:28:36 +00:00
|
|
|
import InfoZapperError from "@app/components/InfoZapperError.svelte"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {app, reader} from "@app/core"
|
|
|
|
|
import {wallet} from "@app/lightning"
|
2025-07-07 22:28:36 +00:00
|
|
|
|
2025-07-17 22:29:26 +00:00
|
|
|
type Props = {
|
2025-10-06 18:23:19 +00:00
|
|
|
url?: string
|
2025-07-17 22:29:26 +00:00
|
|
|
event: TrustedEvent
|
|
|
|
|
children: Snippet
|
|
|
|
|
replaceState?: boolean
|
|
|
|
|
class?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {url, event, children, replaceState, ...props}: Props = $props()
|
2025-07-07 22:28:36 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const goal = event.kind === ZAP_GOAL ? reader(ZapGoal)(event) : undefined
|
|
|
|
|
|
|
|
|
|
const zapperPromise = $app.use(Zappers).loadForPubkey(event.pubkey)
|
|
|
|
|
|
|
|
|
|
const goalRelays = goal?.urls() ?? []
|
2025-07-07 22:28:36 +00:00
|
|
|
|
2025-10-27 20:36:29 +00:00
|
|
|
const onClick = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const zapper = await zapperPromise
|
|
|
|
|
|
|
|
|
|
if (!zapper?.allowsNostr) {
|
|
|
|
|
pushModal(InfoZapperError, {url, pubkey: event.pubkey, eventId: event.id}, {replaceState})
|
2026-07-28 16:16:26 +00:00
|
|
|
} else if ($wallet) {
|
|
|
|
|
pushModal(Zap, {url, pubkey: event.pubkey, eventId: event.id, goalRelays}, {replaceState})
|
2025-10-27 20:36:29 +00:00
|
|
|
} else {
|
2026-07-28 16:16:26 +00:00
|
|
|
pushModal(
|
|
|
|
|
ZapInvoice,
|
|
|
|
|
{url, pubkey: event.pubkey, eventId: event.id, goalRelays},
|
|
|
|
|
{replaceState},
|
|
|
|
|
)
|
2025-10-27 20:36:29 +00:00
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
2025-07-07 22:28:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-10-27 20:36:29 +00:00
|
|
|
|
|
|
|
|
let loading = $state(false)
|
2025-07-07 22:28:36 +00:00
|
|
|
</script>
|
|
|
|
|
|
2025-10-27 20:36:29 +00:00
|
|
|
<Button onclick={onClick} disabled={loading} {...props}>
|
2025-07-07 22:28:36 +00:00
|
|
|
{@render children?.()}
|
|
|
|
|
</Button>
|