Polls (NIP-69) #489
@ -1,7 +1,7 @@
|
|||||||
import { TaggedRawEvent } from "@snort/nostr";
|
import { TaggedRawEvent } from "@snort/nostr";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useIntl } from "react-intl";
|
import { FormattedNumber, useIntl } from "react-intl";
|
||||||
|
|
||||||
import { ParsedZap } from "Element/Zap";
|
import { ParsedZap } from "Element/Zap";
|
||||||
import Text from "Element/Text";
|
import Text from "Element/Text";
|
||||||
@ -35,7 +35,7 @@ export default function Poll(props: PollProps) {
|
|||||||
const amount = prefs.defaultZapAmount;
|
const amount = prefs.defaultZapAmount;
|
||||||
try {
|
try {
|
||||||
setVoting(opt);
|
setVoting(opt);
|
||||||
const zap = await publisher.zap(amount, 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()],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -79,18 +79,16 @@ export default function Poll(props: PollProps) {
|
|||||||
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 = total / allTotal;
|
||||||
const percent = `${Math.floor(weight * 100)}%`;
|
|
||||||
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">
|
||||||
{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">
|
<div className="flex">
|
||||||
{percent}
|
<FormattedNumber value={weight * 100} maximumFractionDigits={0} />%
|
||||||
|
|
||||||
<small>({formatShort(total)})</small>
|
<small>({formatShort(total)})</small>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ width: percent }} className="progress"></div>
|
<div style={{ width: `${weight * 100}%` }} className="progress"></div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@ -188,6 +188,15 @@ export default function useEventPublisher() {
|
|||||||
return await signEvent(ev);
|
return await signEvent(ev);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Create a zap request event for a given target event/profile
|
||||||
|
* @param amount Millisats amout!
|
||||||
|
* @param author Author pubkey to tag in the zap
|
||||||
|
* @param note Note Id to tag in the zap
|
||||||
|
* @param msg Custom message to be included in the zap
|
||||||
|
* @param extraTags Any extra tags to include on the zap request event
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
zap: async (amount: number, author: HexKey, note?: HexKey, msg?: string, extraTags?: Array<Array<string>>) => {
|
zap: async (amount: number, author: HexKey, note?: HexKey, msg?: string, extraTags?: Array<Array<string>>) => {
|
||||||
if (pubKey) {
|
if (pubKey) {
|
||||||
const ev = EventExt.forPubKey(pubKey, EventKind.ZapRequest);
|
const ev = EventExt.forPubKey(pubKey, EventKind.ZapRequest);
|
||||||
|
Loading…
Reference in New Issue
Block a user