Let welshman decide where a zap receipt should land
This commit is contained in:
parent
801fbb8918
commit
0aeca3af3e
3 changed files with 18 additions and 26 deletions
|
|
@ -119,7 +119,7 @@
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
showReactors(pubkeys, info.replace(" zapped", ""), "Zapped this message")
|
showReactors(pubkeys, info.replace(" zapped", ""), "Zapped this message")
|
||||||
} else {
|
} else {
|
||||||
pushModal(ZapModal, {url, pubkey: event.pubkey, eventId: event.id})
|
pushModal(ZapModal, {url, pubkey: event.pubkey, event})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {onDestroy} from "svelte"
|
import {onDestroy} from "svelte"
|
||||||
import {first, removeUndefined, uniq} from "@welshman/lib"
|
import {first, removeUndefined} from "@welshman/lib"
|
||||||
import {inbox} from "@welshman/util"
|
import {relay} from "@welshman/util"
|
||||||
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
import {ZapRequest} from "@welshman/domain"
|
import {ZapRequest} from "@welshman/domain"
|
||||||
import {Zappers} from "@welshman/app"
|
import {Zappers} from "@welshman/app"
|
||||||
import Bolt from "@assets/icons/bolt.svg?dataurl"
|
import Bolt from "@assets/icons/bolt.svg?dataurl"
|
||||||
|
|
@ -21,7 +22,7 @@
|
||||||
import QRCode from "@app/components/QRCode.svelte"
|
import QRCode from "@app/components/QRCode.svelte"
|
||||||
import WalletConnect from "@app/components/WalletConnect.svelte"
|
import WalletConnect from "@app/components/WalletConnect.svelte"
|
||||||
import ZapForm from "@app/components/ZapForm.svelte"
|
import ZapForm from "@app/components/ZapForm.svelte"
|
||||||
import {app, domain, network, router} from "@app/core"
|
import {app, domain, network} from "@app/core"
|
||||||
import {payInvoice, wallet} from "@app/lightning"
|
import {payInvoice, wallet} from "@app/lightning"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
import {zapAmounts} from "@app/settings"
|
import {zapAmounts} from "@app/settings"
|
||||||
|
|
@ -30,12 +31,10 @@
|
||||||
type Props = {
|
type Props = {
|
||||||
url?: string
|
url?: string
|
||||||
pubkey: string
|
pubkey: string
|
||||||
eventId?: string
|
event?: TrustedEvent
|
||||||
// NIP-75 requires a zap to a goal to request its receipt on the goal's own relays.
|
|
||||||
goalRelays?: string[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const {url, pubkey, eventId, goalRelays = []}: Props = $props()
|
const {url, pubkey, event}: Props = $props()
|
||||||
|
|
||||||
const zapper = $app.use(Zappers).forPubkey(pubkey, removeUndefined([url]))
|
const zapper = $app.use(Zappers).forPubkey(pubkey, removeUndefined([url]))
|
||||||
|
|
||||||
|
|
@ -43,20 +42,19 @@
|
||||||
|
|
||||||
const requestInvoice = async () => {
|
const requestInvoice = async () => {
|
||||||
const currentZapper = zapper.get()!
|
const currentZapper = zapper.get()!
|
||||||
const relays = uniq([
|
|
||||||
...(url ? [url] : await $router.resolver.relays([inbox(pubkey)])),
|
|
||||||
...goalRelays,
|
|
||||||
])
|
|
||||||
const writer = $domain
|
const writer = $domain
|
||||||
.writer(ZapRequest)
|
.writer(ZapRequest)
|
||||||
.setContent(content)
|
.setContent(content)
|
||||||
.setAmount(amount * 1000)
|
.setAmount(amount * 1000)
|
||||||
.setLnurl(currentZapper.lnurl)
|
.setLnurl(currentZapper.lnurl)
|
||||||
.setRecipient(pubkey)
|
.setRecipient(pubkey)
|
||||||
.setUrls(relays)
|
|
||||||
|
|
||||||
if (eventId) {
|
if (url) {
|
||||||
writer.setEventId(eventId)
|
writer.forceRoutes(relay(url))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
writer.setEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await writer.requestInvoice(currentZapper)
|
const res = await writer.requestInvoice(currentZapper)
|
||||||
|
|
@ -66,9 +64,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
relays,
|
relays: await writer.relays(),
|
||||||
invoice: res.invoice,
|
invoice: res.invoice,
|
||||||
filters: [currentZapper.getResponseFilter(pubkey, eventId)],
|
filters: [currentZapper.getResponseFilter(pubkey, event?.id)],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Snippet} from "svelte"
|
import type {Snippet} from "svelte"
|
||||||
import {removeUndefined} from "@welshman/lib"
|
import {removeUndefined} from "@welshman/lib"
|
||||||
import {ZAP_GOAL} from "@welshman/util"
|
|
||||||
import type {TrustedEvent} from "@welshman/util"
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
import {ZapGoal} from "@welshman/domain"
|
|
||||||
import {Zappers} from "@welshman/app"
|
import {Zappers} from "@welshman/app"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import Zap from "@app/components/Zap.svelte"
|
import Zap from "@app/components/Zap.svelte"
|
||||||
import InfoZapperError from "@app/components/InfoZapperError.svelte"
|
import InfoZapperError from "@app/components/InfoZapperError.svelte"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
import {app, reader} from "@app/core"
|
import {app} from "@app/core"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
url?: string
|
url?: string
|
||||||
|
|
@ -23,12 +21,8 @@
|
||||||
|
|
||||||
const {url, event, children, replaceState, ...props}: Props = $props()
|
const {url, event, children, replaceState, ...props}: Props = $props()
|
||||||
|
|
||||||
const goal = event.kind === ZAP_GOAL ? reader(ZapGoal)(event) : undefined
|
|
||||||
|
|
||||||
const zapperPromise = $app.use(Zappers).loadForPubkey(event.pubkey, removeUndefined([url]))
|
const zapperPromise = $app.use(Zappers).loadForPubkey(event.pubkey, removeUndefined([url]))
|
||||||
|
|
||||||
const goalRelays = goal?.urls() ?? []
|
|
||||||
|
|
||||||
const onClick = async () => {
|
const onClick = async () => {
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
|
|
@ -36,9 +30,9 @@
|
||||||
const zapper = await zapperPromise
|
const zapper = await zapperPromise
|
||||||
|
|
||||||
if (zapper?.allowsNostr) {
|
if (zapper?.allowsNostr) {
|
||||||
pushModal(Zap, {url, pubkey: event.pubkey, eventId: event.id, goalRelays}, {replaceState})
|
pushModal(Zap, {url, pubkey: event.pubkey, event}, {replaceState})
|
||||||
} else {
|
} else {
|
||||||
pushModal(InfoZapperError, {url, pubkey: event.pubkey, eventId: event.id}, {replaceState})
|
pushModal(InfoZapperError, {url, pubkey: event.pubkey}, {replaceState})
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
loading = false
|
loading = false
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue