Fix some zap bugs

This commit is contained in:
Jon Staab
2025-07-07 13:58:43 -07:00
parent 63d6b362c7
commit 1d07097350
5 changed files with 53 additions and 21 deletions
@@ -3,6 +3,7 @@
import Button from "@lib/components/Button.svelte" import Button from "@lib/components/Button.svelte"
import Icon from "@lib/components/Icon.svelte" import Icon from "@lib/components/Icon.svelte"
import Zap from "@app/components/Zap.svelte" import Zap from "@app/components/Zap.svelte"
import InfoZapperError from "@app/components/InfoZapperError.svelte"
import WalletConnect from "@app/components/WalletConnect.svelte" import WalletConnect from "@app/components/WalletConnect.svelte"
import {pushModal} from "@app/modal" import {pushModal} from "@app/modal"
import {wallet} from "@app/state" import {wallet} from "@app/state"
@@ -12,7 +13,9 @@
const zapper = deriveZapperForPubkey(event.pubkey) const zapper = deriveZapperForPubkey(event.pubkey)
const onClick = () => { const onClick = () => {
if ($wallet) { if (!$zapper?.allowsNostr) {
pushModal(InfoZapperError, {url, pubkey: event.pubkey, eventId: event.id})
} else if ($wallet) {
pushModal(Zap, {url, pubkey: event.pubkey, eventId: event.id}) pushModal(Zap, {url, pubkey: event.pubkey, eventId: event.id})
} else { } else {
pushModal(WalletConnect) pushModal(WalletConnect)
@@ -20,8 +23,6 @@
} }
</script> </script>
{#if $zapper?.allowsNostr} <Button onclick={onClick} class="btn join-item btn-xs">
<Button onclick={onClick} class="btn join-item btn-xs"> <Icon icon="bolt" size={4} />
<Icon icon="bolt" size={4} /> </Button>
</Button>
{/if}
+36
View File
@@ -0,0 +1,36 @@
<script lang="ts">
import {deriveZapperForPubkey} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import ModalHeader from "@lib/components/ModalHeader.svelte"
import ModalFooter from "@lib/components/ModalFooter.svelte"
import ProfileLink from "@app/components/ProfileLink.svelte"
const {pubkey} = $props()
const zapper = deriveZapperForPubkey(pubkey)
const back = () => history.back()
</script>
<div class="column gap-4">
<ModalHeader>
{#snippet title()}
<div>Unable to Zap</div>
{/snippet}
</ModalHeader>
<p>
Zapping <ProfileLink {pubkey} class="!text-primary" /> isn't possible right now because
{#if $zapper}
their zap receiver isn't correctly set up.
{:else}
they don't currently have a zap receiver set up.
{/if}
</p>
<ModalFooter>
<Button class="btn btn-link" onclick={back}>
<Icon icon="alt-arrow-left" />
Go back
</Button>
</ModalFooter>
</div>
+4 -8
View File
@@ -8,6 +8,7 @@
getReplyFilters, getReplyFilters,
getEmojiTags, getEmojiTags,
getEmojiTag, getEmojiTag,
fromMsats,
getTag, getTag,
REPORT, REPORT,
DELETE, DELETE,
@@ -84,12 +85,7 @@
), ),
) )
const groupedZaps = $derived( const groupedZaps = $derived(groupBy(e => getReactionKey(e.request), $zaps))
groupBy(
e => getReactionKey(e.request),
uniqBy(e => `${e.request.pubkey}${getReactionKey(e.request)}`, $zaps),
),
)
onMount(() => { onMount(() => {
const controller = new AbortController() const controller = new AbortController()
@@ -128,8 +124,8 @@
</button> </button>
{/if} {/if}
{#each groupedZaps.entries() as [key, zaps]} {#each groupedZaps.entries() as [key, zaps]}
{@const amount = sum(zaps.map(zap => zap.invoiceAmount))} {@const amount = fromMsats(sum(zaps.map(zap => zap.invoiceAmount)))}
{@const pubkeys = zaps.map(zap => zap.request.pubkey)} {@const pubkeys = uniq(zaps.map(zap => zap.request.pubkey))}
{@const isOwn = $pubkey && pubkeys.includes($pubkey)} {@const isOwn = $pubkey && pubkeys.includes($pubkey)}
{@const info = displayList(pubkeys.map(pubkey => displayProfileByPubkey(pubkey)))} {@const info = displayList(pubkeys.map(pubkey => displayProfileByPubkey(pubkey)))}
{@const tooltip = `${info} zapped`} {@const tooltip = `${info} zapped`}
-1
View File
@@ -63,7 +63,6 @@
const params = {pubkey, content, eventId, msats, relays, zapper} const params = {pubkey, content, eventId, msats, relays, zapper}
const event = await $signer!.sign(makeZapRequest(params)) const event = await $signer!.sign(makeZapRequest(params))
const res = await requestZap({zapper, event}) const res = await requestZap({zapper, event})
console.log({event, zapper, res})
if (!res.invoice) { if (!res.invoice) {
return pushToast({ return pushToast({
+6 -6
View File
@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import {nwc} from "@getalby/sdk" import {nwc} from "@getalby/sdk"
import {LOCALE} from "@welshman/lib" import {LOCALE} from "@welshman/lib"
import {displayRelayUrl} from "@welshman/util" import {displayRelayUrl, fromMsats} from "@welshman/util"
import Icon from "@lib/components/Icon.svelte" import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte" import Button from "@lib/components/Button.svelte"
import WalletConnect from "@app/components/WalletConnect.svelte" import WalletConnect from "@app/components/WalletConnect.svelte"
@@ -22,7 +22,7 @@
Wallet Wallet
</strong> </strong>
{#if $wallet} {#if $wallet}
<div class="flex items-center gap-2 text-sm"> <div class="flex items-center gap-2 text-sm text-success">
<Icon icon="check-circle" size={4} /> <Icon icon="check-circle" size={4} />
Connected Connected
</div> </div>
@@ -42,14 +42,14 @@
Connected to <strong>{node?.alias || version || "unknown wallet"}</strong> Connected to <strong>{node?.alias || version || "unknown wallet"}</strong>
via <strong>{$wallet.type}</strong> via <strong>{$wallet.type}</strong>
</p> </p>
<p class="flex items-center gap-2"> <p class="flex gap-2 whitespace-nowrap">
Balance: Balance:
{#await getWebLn() {#await getWebLn()
?.enable() ?.enable()
.then(() => getWebLn().getBalance())} .then(() => getWebLn().getBalance())}
<span class="loading loading-spinner loading-sm"></span> <span class="loading loading-spinner loading-sm"></span>
{:then res} {:then res}
{new Intl.NumberFormat(LOCALE).format(res?.balance || 0)} {new Intl.NumberFormat(LOCALE).format(fromMsats(res?.balance || 0))}
{:catch} {:catch}
[unknown] [unknown]
{/await} {/await}
@@ -62,12 +62,12 @@
<p> <p>
Connected to <strong>{lud16}</strong> via <strong>{displayRelayUrl(relayUrl)}</strong> Connected to <strong>{lud16}</strong> via <strong>{displayRelayUrl(relayUrl)}</strong>
</p> </p>
<p class="flex items-center gap-2"> <p class="flex gap-2 whitespace-nowrap">
Balance: Balance:
{#await new nwc.NWCClient({nostrWalletConnectUrl}).getBalance()} {#await new nwc.NWCClient({nostrWalletConnectUrl}).getBalance()}
<span class="loading loading-spinner loading-sm"></span> <span class="loading loading-spinner loading-sm"></span>
{:then res} {:then res}
{new Intl.NumberFormat(LOCALE).format(res?.balance || 0)} {new Intl.NumberFormat(LOCALE).format(fromMsats(res?.balance || 0))}
{:catch} {:catch}
[unknown] [unknown]
{/await} {/await}