import "./ZapPool.css"; import { useMemo, useSyncExternalStore } from "react"; import { FormattedMessage, FormattedNumber } from "react-intl"; import { SnortPubKey } from "Const"; import ProfilePreview from "Element/ProfilePreview"; import useLogin from "Hooks/useLogin"; import { System } from "System"; import { UploaderServices } from "Upload"; import { bech32ToHex, getRelayName, unwrap } from "Util"; import { ZapPoolController, ZapPoolRecipient, ZapPoolRecipientType } from "ZapPoolController"; import { useUserProfile } from "Hooks/useUserProfile"; import AsyncButton from "Element/AsyncButton"; import { useWallet } from "Wallet"; function ZapTarget({ target }: { target: ZapPoolRecipient }) { const login = useLogin(); const profile = useUserProfile(target.pubkey); const hasAddress = profile?.lud16 || profile?.lud06; const defaultZapMount = Math.ceil(login.preferences.defaultZapAmount * (target.split / 100)); return (
% ( )
ZapPoolController.set({ ...target, split: e.target.valueAsNumber, }) } /> ) : ( ) } /> ); } export default function ZapPoolPage() { const login = useLogin(); const zapPool = useSyncExternalStore( c => ZapPoolController.hook(c), () => ZapPoolController.snapshot() ); const { wallet } = useWallet(); const relayConnections = useMemo(() => { return [...System.Sockets.values()] .map(a => { if (a.Info?.pubkey) { 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 && ( 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, } } />
))}
); }