review changes
This commit is contained in:
parent
b9b9989647
commit
82851800bf
@ -32,6 +32,8 @@ export default function Poll(props: PollProps) {
|
|||||||
|
|
||||||
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(opt: number) {
|
||||||
|
if (voting) return;
|
||||||
|
|
||||||
const amount = prefs.defaultZapAmount;
|
const amount = prefs.defaultZapAmount;
|
||||||
try {
|
try {
|
||||||
setVoting(opt);
|
setVoting(opt);
|
||||||
@ -39,6 +41,14 @@ export default function Poll(props: PollProps) {
|
|||||||
["poll_option", opt.toString()],
|
["poll_option", opt.toString()],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (!zap) {
|
||||||
|
throw new Error(
|
||||||
|
formatMessage({
|
||||||
|
defaultMessage: "Can't create vote, maybe you're not logged in?",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const lnurl = props.ev.tags.find(a => a[0] === "zap")?.[1] || pollerProfile?.lud16 || pollerProfile?.lud06;
|
const lnurl = props.ev.tags.find(a => a[0] === "zap")?.[1] || pollerProfile?.lud16 || pollerProfile?.lud06;
|
||||||
if (!lnurl) return;
|
if (!lnurl) return;
|
||||||
|
|
||||||
@ -46,7 +56,11 @@ export default function Poll(props: PollProps) {
|
|||||||
await svc.load();
|
await svc.load();
|
||||||
|
|
||||||
if (!svc.canZap) {
|
if (!svc.canZap) {
|
||||||
throw new Error("Cant vote because LNURL service does not support zaps");
|
throw new Error(
|
||||||
|
formatMessage({
|
||||||
|
defaultMessage: "Can't vote because LNURL service does not support zaps",
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const invoice = await svc.getInvoice(amount, undefined, zap);
|
const invoice = await svc.getInvoice(amount, undefined, zap);
|
||||||
@ -58,12 +72,13 @@ export default function Poll(props: PollProps) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
setError(e.message);
|
setError(e.message);
|
||||||
|
} else {
|
||||||
|
setError(
|
||||||
|
formatMessage({
|
||||||
|
defaultMessage: "Failed to send vote",
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
setError(
|
|
||||||
formatMessage({
|
|
||||||
defaultMessage: "Failed to send vote",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} finally {
|
} finally {
|
||||||
setVoting(undefined);
|
setVoting(undefined);
|
||||||
}
|
}
|
||||||
@ -78,7 +93,7 @@ export default function Poll(props: PollProps) {
|
|||||||
const desc = a[2];
|
const desc = a[2];
|
||||||
const zapsOnOption = props.zaps.filter(b => b.pollOption === opt);
|
const zapsOnOption = props.zaps.filter(b => b.pollOption === opt);
|
||||||
const total = zapsOnOption.reduce((acc, v) => (acc += v.amount), 0);
|
const total = zapsOnOption.reduce((acc, v) => (acc += v.amount), 0);
|
||||||
const weight = 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={() => zapVote(opt)}>
|
||||||
<div className="f-grow">
|
<div className="f-grow">
|
||||||
|
@ -33,6 +33,10 @@ export default function useEventPublisher() {
|
|||||||
const hasNip07 = "nostr" in window;
|
const hasNip07 = "nostr" in window;
|
||||||
|
|
||||||
async function signEvent(ev: RawEvent): Promise<RawEvent> {
|
async function signEvent(ev: RawEvent): Promise<RawEvent> {
|
||||||
|
if (!pubKey) {
|
||||||
|
throw new Error("Cant sign events when logged out");
|
||||||
|
}
|
||||||
|
|
||||||
if (hasNip07 && !privKey) {
|
if (hasNip07 && !privKey) {
|
||||||
ev.id = await EventExt.createId(ev);
|
ev.id = await EventExt.createId(ev);
|
||||||
const tmpEv = (await barrierNip07(() => window.nostr.signEvent(ev))) as RawEvent;
|
const tmpEv = (await barrierNip07(() => window.nostr.signEvent(ev))) as RawEvent;
|
||||||
@ -92,7 +96,6 @@ export default function useEventPublisher() {
|
|||||||
},
|
},
|
||||||
broadcast: (ev: RawEvent | undefined) => {
|
broadcast: (ev: RawEvent | undefined) => {
|
||||||
if (ev) {
|
if (ev) {
|
||||||
console.debug("Sending event: ", ev);
|
|
||||||
System.BroadcastEvent(ev);
|
System.BroadcastEvent(ev);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user