From 8aed425a861a2ebac404c21cc8edda664a0c29b8 Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 10 Apr 2023 16:25:41 +0100 Subject: [PATCH] review changes --- packages/app/src/Element/Poll.tsx | 34 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/app/src/Element/Poll.tsx b/packages/app/src/Element/Poll.tsx index e6d522e9..426e1d4b 100644 --- a/packages/app/src/Element/Poll.tsx +++ b/packages/app/src/Element/Poll.tsx @@ -25,17 +25,33 @@ export default function Poll(props: PollProps) { const publisher = useEventPublisher(); const { wallet } = useWallet(); const prefs = useSelector((s: RootState) => s.login.preferences); + const myPubKey = useSelector((s: RootState) => s.login.publicKey); const pollerProfile = useUserProfile(props.ev.pubkey); const [error, setError] = useState(""); const [invoice, setInvoice] = useState(""); const [voting, setVoting] = useState(); + const didVote = props.zaps.some(a => a.sender === myPubKey); const options = props.ev.tags.filter(a => a[0] === "poll_option").sort((a, b) => Number(a[1]) - Number(b[1])); - async function zapVote(opt: number) { + async function zapVote(ev: React.MouseEvent, opt: number) { + ev.stopPropagation(); if (voting) return; const amount = prefs.defaultZapAmount; try { + if (amount <= 0) { + throw new Error( + formatMessage( + { + defaultMessage: "Can't vote with {amount} sats, please set a different default zap amount", + }, + { + amount, + } + ) + ); + } + setVoting(opt); const zap = await publisher.zap(amount * 1000, props.ev.pubkey, props.ev.id, undefined, [ ["poll_option", opt.toString()], @@ -103,15 +119,19 @@ export default function Poll(props: PollProps) { const total = zapsOnOption.reduce((acc, v) => (acc += v.amount), 0); const weight = allTotal === 0 ? 0 : total / allTotal; return ( -
zapVote(opt)}> +
zapVote(e, opt)}>
{opt === voting ? : }
-
- %   - ({formatShort(total)}) -
-
+ {didVote && ( + <> +
+ %   + ({formatShort(total)}) +
+
+ + )}
); })}