import "./ZapPool.css"; import { useMemo, useSyncExternalStore } from "react"; import { FormattedMessage, FormattedNumber } from "react-intl"; import { useUserProfile } from "@snort/system-react"; import { SnortPubKey } from "@/Const"; import ProfilePreview from "@/Element/User/ProfilePreview"; import useLogin from "@/Hooks/useLogin"; import { UploaderServices } from "@/Upload"; import { bech32ToHex, getRelayName, trackEvent, unwrap } from "@/SnortUtils"; import { ZapPoolController, ZapPoolRecipient, ZapPoolRecipientType } from "@/ZapPoolController"; import AsyncButton from "@/Element/Button/AsyncButton"; import { useWallet } from "@/Wallet"; import useEventPublisher from "@/Hooks/useEventPublisher"; const DataProviders = [ { name: "nostr.band", owner: bech32ToHex("npub1sx9rnd03vs34lp39fvfv5krwlnxpl90f3dzuk8y3cuwutk2gdhdqjz6g8m"), }, ]; function ZapTarget({ target }: { target: ZapPoolRecipient }) { if (!ZapPoolController) return; const login = useLogin(); const profile = useUserProfile(target.pubkey); const hasAddress = profile?.lud16 || profile?.lud06; const defaultZapMount = Math.ceil(login.appData.item.preferences.defaultZapAmount * (target.split / 100)); return (
% ( )
ZapPoolController?.set({ ...target, split: e.target.valueAsNumber, }) } /> ) : ( ) } /> ); } export default function ZapPoolPage() { if (!ZapPoolController) return; const login = useLogin(); const { system } = useEventPublisher(); const zapPool = useSyncExternalStore( c => unwrap(ZapPoolController).hook(c), () => unwrap(ZapPoolController).snapshot(), ); const { wallet } = useWallet(); const relayConnections = useMemo(() => { return system.Sockets.map(a => { if (a.info?.pubkey && !a.ephemeral) { return { address: a.address, pubkey: a.info.pubkey, }; } }) .filter(a => a !== undefined) .map(unwrap); }, [login.relays]); const sumPending = zapPool.reduce((acc, v) => acc + v.sum, 0); return (

), }} />

), nOut: ( ), }} />

), }} />

{wallet && ( { trackEvent("ZapPool:Manual") await ZapPoolController?.payout(wallet); }}> )}

b.pubkey === bech32ToHex(SnortPubKey) && b.type === ZapPoolRecipientType.Generic) ?? { type: ZapPoolRecipientType.Generic, pubkey: bech32ToHex(SnortPubKey), split: 0, sum: 0, } } />

{relayConnections.map(a => (

{getRelayName(a.address)}

b.pubkey === a.pubkey && b.type === ZapPoolRecipientType.Relay) ?? { type: ZapPoolRecipientType.Relay, pubkey: a.pubkey, split: 0, sum: 0, } } />
))}

{UploaderServices.map(a => (

{a.name}

b.pubkey === a.owner && b.type === ZapPoolRecipientType.FileHost) ?? { type: ZapPoolRecipientType.FileHost, pubkey: a.owner, split: 0, sum: 0, } } />
))}

{DataProviders.map(a => (

{a.name}

b.pubkey === a.owner && b.type === ZapPoolRecipientType.DataProvider) ?? { type: ZapPoolRecipientType.DataProvider, pubkey: a.owner, split: 0, sum: 0, } } />
))}
); }