forked from Kieran/snort
review changes
This commit is contained in:
parent
bf31816051
commit
8aed425a86
@ -25,17 +25,33 @@ export default function Poll(props: PollProps) {
|
|||||||
const publisher = useEventPublisher();
|
const publisher = useEventPublisher();
|
||||||
const { wallet } = useWallet();
|
const { wallet } = useWallet();
|
||||||
const prefs = useSelector((s: RootState) => s.login.preferences);
|
const prefs = useSelector((s: RootState) => s.login.preferences);
|
||||||
|
const myPubKey = useSelector((s: RootState) => s.login.publicKey);
|
||||||
const pollerProfile = useUserProfile(props.ev.pubkey);
|
const pollerProfile = useUserProfile(props.ev.pubkey);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [invoice, setInvoice] = useState("");
|
const [invoice, setInvoice] = useState("");
|
||||||
const [voting, setVoting] = useState<number>();
|
const [voting, setVoting] = useState<number>();
|
||||||
|
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]));
|
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;
|
if (voting) return;
|
||||||
|
|
||||||
const amount = prefs.defaultZapAmount;
|
const amount = prefs.defaultZapAmount;
|
||||||
try {
|
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);
|
setVoting(opt);
|
||||||
const zap = await publisher.zap(amount * 1000, props.ev.pubkey, props.ev.id, undefined, [
|
const zap = await publisher.zap(amount * 1000, props.ev.pubkey, props.ev.id, undefined, [
|
||||||
["poll_option", opt.toString()],
|
["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 total = zapsOnOption.reduce((acc, v) => (acc += v.amount), 0);
|
||||||
const weight = allTotal === 0 ? 0 : total / allTotal;
|
const weight = allTotal === 0 ? 0 : total / allTotal;
|
||||||
return (
|
return (
|
||||||
<div key={a[1]} className="flex" onClick={() => zapVote(opt)}>
|
<div key={a[1]} className="flex" onClick={e => zapVote(e, opt)}>
|
||||||
<div className="f-grow">
|
<div className="f-grow">
|
||||||
{opt === voting ? <Spinner /> : <Text content={desc} tags={props.ev.tags} creator={props.ev.pubkey} />}
|
{opt === voting ? <Spinner /> : <Text content={desc} tags={props.ev.tags} creator={props.ev.pubkey} />}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex">
|
{didVote && (
|
||||||
<FormattedNumber value={weight * 100} maximumFractionDigits={0} />%
|
<>
|
||||||
<small>({formatShort(total)})</small>
|
<div className="flex">
|
||||||
</div>
|
<FormattedNumber value={weight * 100} maximumFractionDigits={0} />%
|
||||||
<div style={{ width: `${weight * 100}%` }} className="progress"></div>
|
<small>({formatShort(total)})</small>
|
||||||
|
</div>
|
||||||
|
<div style={{ width: `${weight * 100}%` }} className="progress"></div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
Loading…
Reference in New Issue
Block a user