feat(zaps): show zap totals to everyone, not just logged-in users
ZapButton already fetched zap receipts for every visitor but returned null
unless you were logged in, so visitors saw no social proof. Now it renders a
read-only '⚡ <total>' whenever there are zaps (with a zap-count tooltip) and
only requires login to OPEN the zap dialog. No extra network cost — the query
already ran unconditionally.
This commit is contained in:
parent
8d8a46a73f
commit
6dc619ee91
1 changed files with 26 additions and 3 deletions
|
|
@ -24,21 +24,44 @@ export function ZapButton({
|
||||||
const { webln, activeNWC } = useWallet();
|
const { webln, activeNWC } = useWallet();
|
||||||
|
|
||||||
// Only fetch data if not provided externally
|
// Only fetch data if not provided externally
|
||||||
const { totalSats: fetchedTotalSats, isLoading } = useZaps(
|
const { totalSats: fetchedTotalSats, zapCount: fetchedZapCount, isLoading } = useZaps(
|
||||||
externalZapData ? [] : target ?? [], // Empty array prevents fetching if external data provided
|
externalZapData ? [] : target ?? [], // Empty array prevents fetching if external data provided
|
||||||
webln,
|
webln,
|
||||||
activeNWC
|
activeNWC
|
||||||
);
|
);
|
||||||
|
|
||||||
// Don't show zap button if user is not logged in, is the author, or author has no lightning address
|
if (!target) {
|
||||||
if (!user || !target || user.pubkey === target.pubkey || (!author?.metadata?.lud16 && !author?.metadata?.lud06)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use external data if provided, otherwise use fetched data
|
// Use external data if provided, otherwise use fetched data
|
||||||
const totalSats = externalZapData?.totalSats ?? fetchedTotalSats;
|
const totalSats = externalZapData?.totalSats ?? fetchedTotalSats;
|
||||||
|
const zapCount = externalZapData?.count ?? fetchedZapCount;
|
||||||
const showLoading = externalZapData?.isLoading || isLoading;
|
const showLoading = externalZapData?.isLoading || isLoading;
|
||||||
|
|
||||||
|
const hasLightning = !!(author?.metadata?.lud16 || author?.metadata?.lud06);
|
||||||
|
const canZap = !!user && user.pubkey !== target.pubkey && hasLightning;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read-only total. Zaps are social proof, so the count is shown to EVERYONE —
|
||||||
|
* logged-out visitors included — not just to people who can zap. This costs
|
||||||
|
* no extra network work: `useZaps` already runs above regardless of login.
|
||||||
|
*/
|
||||||
|
if (!canZap) {
|
||||||
|
if (!showCount || showLoading || totalSats <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={`flex items-center gap-1 ${className}`}
|
||||||
|
title={`${zapCount.toLocaleString()} zap${zapCount === 1 ? '' : 's'}`}
|
||||||
|
>
|
||||||
|
<Zap className="h-4 w-4" />
|
||||||
|
<span className="text-xs">{totalSats.toLocaleString()}</span>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ZapDialog target={target}>
|
<ZapDialog target={target}>
|
||||||
<div className={`flex items-center gap-1 ${className}`}>
|
<div className={`flex items-center gap-1 ${className}`}>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue