feat: per event zap targets
This commit is contained in:
parent
293510069c
commit
8ef20c27b3
@ -1,6 +1,6 @@
|
||||
import "./NoteCreator.css";
|
||||
import { useState } from "react";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import { FormattedMessage, useIntl } from "react-intl";
|
||||
import { RawEvent, TaggedRawEvent } from "@snort/nostr";
|
||||
|
||||
import Icon from "Icons/Icon";
|
||||
@ -11,6 +11,7 @@ import Modal from "Element/Modal";
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import useFileUpload from "Upload";
|
||||
import Note from "Element/Note";
|
||||
import { LNURL } from "LNURL";
|
||||
|
||||
import messages from "./messages";
|
||||
|
||||
@ -40,16 +41,34 @@ export interface NoteCreatorProps {
|
||||
|
||||
export function NoteCreator(props: NoteCreatorProps) {
|
||||
const { show, setShow, replyTo, onSend, autoFocus } = props;
|
||||
const { formatMessage } = useIntl();
|
||||
const publisher = useEventPublisher();
|
||||
const [note, setNote] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [active, setActive] = useState(false);
|
||||
const [preview, setPreview] = useState<RawEvent>();
|
||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||
const [zapForward, setZapForward] = useState("");
|
||||
const uploader = useFileUpload();
|
||||
|
||||
async function sendNote() {
|
||||
if (note) {
|
||||
const ev = replyTo ? await publisher.reply(replyTo, note) : await publisher.note(note);
|
||||
let extraTags: Array<Array<string>> | undefined;
|
||||
if (zapForward) {
|
||||
try {
|
||||
const svc = new LNURL(zapForward);
|
||||
await svc.load();
|
||||
} catch {
|
||||
setError(
|
||||
formatMessage({
|
||||
defaultMessage: "Invalid LNURL",
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
extraTags = [["zap", zapForward]];
|
||||
}
|
||||
const ev = replyTo ? await publisher.reply(replyTo, note, extraTags) : await publisher.note(note, extraTags);
|
||||
console.debug("Sending note: ", ev);
|
||||
publisher.broadcast(ev);
|
||||
setNote("");
|
||||
@ -152,6 +171,9 @@ export function NoteCreator(props: NoteCreatorProps) {
|
||||
<button className="secondary" type="button" onClick={loadPreview}>
|
||||
<FormattedMessage defaultMessage="Toggle Preview" />
|
||||
</button>
|
||||
<button className="secondary" type="button" onClick={() => setShowAdvanced(s => !s)}>
|
||||
<FormattedMessage defaultMessage="Advanced" />
|
||||
</button>
|
||||
<button className="secondary" type="button" onClick={cancel}>
|
||||
<FormattedMessage {...messages.Cancel} />
|
||||
</button>
|
||||
@ -159,6 +181,25 @@ export function NoteCreator(props: NoteCreatorProps) {
|
||||
{replyTo ? <FormattedMessage {...messages.Reply} /> : <FormattedMessage {...messages.Send} />}
|
||||
</button>
|
||||
</div>
|
||||
{showAdvanced && (
|
||||
<>
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Forward Zaps" />
|
||||
</h4>
|
||||
<p>
|
||||
<FormattedMessage defaultMessage="All zaps sent to this note will be received by the following LNURL" />
|
||||
</p>
|
||||
<input
|
||||
type="text"
|
||||
className="w-max"
|
||||
placeholder={formatMessage({
|
||||
defaultMessage: "LNURL to forward zaps to",
|
||||
})}
|
||||
value={zapForward}
|
||||
onChange={e => setZapForward(e.target.value)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
)}
|
||||
</>
|
||||
|
@ -153,10 +153,18 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
}
|
||||
}
|
||||
|
||||
function getLNURL() {
|
||||
return ev.Tags.find(a => a.Key === "zap")?.LNURL || author?.lud16 || author?.lud06;
|
||||
}
|
||||
|
||||
function getTargetName() {
|
||||
return ev.Tags.find(a => a.Key === "zap")?.LNURL || author?.display_name || author?.name;
|
||||
}
|
||||
|
||||
async function fastZap(e?: React.MouseEvent) {
|
||||
if (zapping || e?.isPropagationStopped()) return;
|
||||
|
||||
const lnurl = author?.lud16 || author?.lud06;
|
||||
const lnurl = getLNURL();
|
||||
if (wallet?.isReady() && lnurl) {
|
||||
setZapping(true);
|
||||
try {
|
||||
@ -203,7 +211,7 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
|
||||
useEffect(() => {
|
||||
if (prefs.autoZap && !ZapCache.has(ev.id) && !isMine && !zapping) {
|
||||
const lnurl = author?.lud16 || author?.lud06;
|
||||
const lnurl = getLNURL();
|
||||
if (wallet?.isReady() && lnurl) {
|
||||
setZapping(true);
|
||||
queueMicrotask(async () => {
|
||||
@ -222,7 +230,7 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
}, [prefs.autoZap, author, zapping]);
|
||||
|
||||
function tipButton() {
|
||||
const service = author?.lud16 || author?.lud06;
|
||||
const service = getLNURL();
|
||||
if (service) {
|
||||
return (
|
||||
<>
|
||||
@ -418,11 +426,11 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
zaps={zaps}
|
||||
/>
|
||||
<SendSats
|
||||
lnurl={author?.lud16 || author?.lud06}
|
||||
lnurl={getLNURL()}
|
||||
onClose={() => setTip(false)}
|
||||
show={tip}
|
||||
author={author?.pubkey}
|
||||
target={author?.display_name || author?.name}
|
||||
target={getTargetName()}
|
||||
note={ev.id}
|
||||
/>
|
||||
</div>
|
||||
|
@ -176,10 +176,15 @@ export default function useEventPublisher() {
|
||||
return await signEvent(ev);
|
||||
}
|
||||
},
|
||||
note: async (msg: string) => {
|
||||
note: async (msg: string, extraTags?: Array<Array<string>>) => {
|
||||
if (pubKey) {
|
||||
const ev = EventExt.forPubKey(pubKey, EventKind.TextNote);
|
||||
processContent(ev, msg);
|
||||
if (extraTags) {
|
||||
for (const et of extraTags) {
|
||||
ev.tags.push(et);
|
||||
}
|
||||
}
|
||||
return await signEvent(ev);
|
||||
}
|
||||
},
|
||||
@ -200,7 +205,7 @@ export default function useEventPublisher() {
|
||||
/**
|
||||
* Reply to a note
|
||||
*/
|
||||
reply: async (replyTo: TaggedRawEvent, msg: string) => {
|
||||
reply: async (replyTo: TaggedRawEvent, msg: string, extraTags?: Array<Array<string>>) => {
|
||||
if (pubKey) {
|
||||
const ev = EventExt.forPubKey(pubKey, EventKind.TextNote);
|
||||
|
||||
@ -230,6 +235,11 @@ export default function useEventPublisher() {
|
||||
}
|
||||
}
|
||||
processContent(ev, msg);
|
||||
if (extraTags) {
|
||||
for (const et of extraTags) {
|
||||
ev.tags.push(et);
|
||||
}
|
||||
}
|
||||
return await signEvent(ev);
|
||||
}
|
||||
},
|
||||
|
@ -78,6 +78,9 @@
|
||||
"2k0Cv+": {
|
||||
"defaultMessage": "Dislikes ({n})"
|
||||
},
|
||||
"3Rx6Qo": {
|
||||
"defaultMessage": "Advanced"
|
||||
},
|
||||
"3cc4Ct": {
|
||||
"defaultMessage": "Light"
|
||||
},
|
||||
@ -278,6 +281,9 @@
|
||||
"FDguSC": {
|
||||
"defaultMessage": "{n} Zaps"
|
||||
},
|
||||
"FP+D3H": {
|
||||
"defaultMessage": "LNURL to forward zaps to"
|
||||
},
|
||||
"FS3b54": {
|
||||
"defaultMessage": "Done!"
|
||||
},
|
||||
@ -437,6 +443,9 @@
|
||||
"OLEm6z": {
|
||||
"defaultMessage": "Unknown login error"
|
||||
},
|
||||
"P04gQm": {
|
||||
"defaultMessage": "All zaps sent to this note will be received by the following LNURL"
|
||||
},
|
||||
"P61BTu": {
|
||||
"defaultMessage": "Copy Event JSON"
|
||||
},
|
||||
@ -472,6 +481,9 @@
|
||||
"defaultMessage": "Art by {name}",
|
||||
"description": "Artwork attribution label"
|
||||
},
|
||||
"R1fEdZ": {
|
||||
"defaultMessage": "Forward Zaps"
|
||||
},
|
||||
"R2OqnW": {
|
||||
"defaultMessage": "Delete Account"
|
||||
},
|
||||
|
@ -25,6 +25,7 @@
|
||||
"2LbrkB": "Enter password",
|
||||
"2a2YiP": "{n} Bookmarks",
|
||||
"2k0Cv+": "Dislikes ({n})",
|
||||
"3Rx6Qo": "Advanced",
|
||||
"3cc4Ct": "Light",
|
||||
"3gOsZq": "Translators",
|
||||
"3t3kok": "{n,plural,=1{{n} new note} other{{n} new notes}}",
|
||||
@ -90,6 +91,7 @@
|
||||
"Eqjl5K": "Only Snort and our integration partner identifier gives you a colorful domain name, but you are welcome to use other services too.",
|
||||
"F+B3x1": "We have also partnered with nostrplebs.com to give you more options",
|
||||
"FDguSC": "{n} Zaps",
|
||||
"FP+D3H": "LNURL to forward zaps to",
|
||||
"FS3b54": "Done!",
|
||||
"FfYsOb": "An error has occured!",
|
||||
"FmXUJg": "follows you",
|
||||
@ -142,6 +144,7 @@
|
||||
"OEW7yJ": "Zaps",
|
||||
"OKhRC6": "Share",
|
||||
"OLEm6z": "Unknown login error",
|
||||
"P04gQm": "All zaps sent to this note will be received by the following LNURL",
|
||||
"P61BTu": "Copy Event JSON",
|
||||
"P7FD0F": "System (Default)",
|
||||
"P7nJT9": "Total today (UTC): {amount} sats",
|
||||
@ -153,6 +156,7 @@
|
||||
"QTdJfH": "Create an Account",
|
||||
"QawghE": "You can change your username at any point.",
|
||||
"QxCuTo": "Art by {name}",
|
||||
"R1fEdZ": "Forward Zaps",
|
||||
"R2OqnW": "Delete Account",
|
||||
"RDZVQL": "Check",
|
||||
"RahCRH": "Expired",
|
||||
@ -321,4 +325,4 @@
|
||||
"zjJZBd": "You're ready!",
|
||||
"zonsdq": "Failed to load LNURL service",
|
||||
"zvCDao": "Automatically show latest notes"
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ export default class Tag {
|
||||
DTag?: string;
|
||||
Index: number;
|
||||
Invalid: boolean;
|
||||
LNURL?: string;
|
||||
|
||||
constructor(tag: string[], index: number) {
|
||||
this.Original = tag;
|
||||
@ -50,6 +51,10 @@ export default class Tag {
|
||||
this.PubKey = tag[1];
|
||||
break;
|
||||
}
|
||||
case "zap": {
|
||||
this.LNURL = tag[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user