forked from Kieran/snort
feat: tag anon zaps
This commit is contained in:
parent
b5d7e2c58a
commit
4c1513676e
@ -20,6 +20,7 @@ export interface ProfileImageProps {
|
|||||||
defaultNip?: string;
|
defaultNip?: string;
|
||||||
verifyNip?: boolean;
|
verifyNip?: boolean;
|
||||||
linkToProfile?: boolean;
|
linkToProfile?: boolean;
|
||||||
|
overrideUsername?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ProfileImage({
|
export default function ProfileImage({
|
||||||
@ -32,6 +33,7 @@ export default function ProfileImage({
|
|||||||
defaultNip,
|
defaultNip,
|
||||||
verifyNip,
|
verifyNip,
|
||||||
linkToProfile = true,
|
linkToProfile = true,
|
||||||
|
overrideUsername,
|
||||||
}: ProfileImageProps) {
|
}: ProfileImageProps) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const user = useUserProfile(pubkey);
|
const user = useUserProfile(pubkey);
|
||||||
@ -39,8 +41,8 @@ export default function ProfileImage({
|
|||||||
const width = usePageWidth();
|
const width = usePageWidth();
|
||||||
|
|
||||||
const name = useMemo(() => {
|
const name = useMemo(() => {
|
||||||
return getDisplayName(user, pubkey);
|
return overrideUsername ?? getDisplayName(user, pubkey);
|
||||||
}, [user, pubkey]);
|
}, [user, pubkey, overrideUsername]);
|
||||||
|
|
||||||
if (!pubkey && !link) {
|
if (!pubkey && !link) {
|
||||||
link = "#";
|
link = "#";
|
||||||
|
@ -110,7 +110,12 @@ const Reactions = ({ show, setShow, positive, negative, reposts, zaps }: Reactio
|
|||||||
<ZapIcon width={17} height={20} />
|
<ZapIcon width={17} height={20} />
|
||||||
<span className="zap-amount">{formatShort(z.amount)}</span>
|
<span className="zap-amount">{formatShort(z.amount)}</span>
|
||||||
</div>
|
</div>
|
||||||
<ProfileImage autoWidth={false} pubkey={z.zapper} subHeader={<>{z.content}</>} />
|
<ProfileImage
|
||||||
|
autoWidth={false}
|
||||||
|
pubkey={z.anonZap ? "" : z.zapper}
|
||||||
|
subHeader={<>{z.content}</>}
|
||||||
|
overrideUsername={z.anonZap ? formatMessage({ defaultMessage: "Anonymous" }) : undefined}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -4,7 +4,7 @@ import { useIntl, FormattedMessage } from "react-intl";
|
|||||||
|
|
||||||
import { formatShort } from "Number";
|
import { formatShort } from "Number";
|
||||||
import { bech32ToText } from "Util";
|
import { bech32ToText } from "Util";
|
||||||
import { HexKey } from "@snort/nostr";
|
import { HexKey, Tag } from "@snort/nostr";
|
||||||
import Check from "Icons/Check";
|
import Check from "Icons/Check";
|
||||||
import Zap from "Icons/Zap";
|
import Zap from "Icons/Zap";
|
||||||
import Close from "Icons/Close";
|
import Close from "Icons/Close";
|
||||||
@ -179,6 +179,7 @@ export default function LNURLTip(props: LNURLTipProps) {
|
|||||||
console.debug("Generated new key for zap: ", randomKey);
|
console.debug("Generated new key for zap: ", randomKey);
|
||||||
ev.PubKey = randomKey.publicKey;
|
ev.PubKey = randomKey.publicKey;
|
||||||
ev.Id = "";
|
ev.Id = "";
|
||||||
|
ev.Tags.push(new Tag(["anon"], ev.Tags.length));
|
||||||
await ev.Sign(randomKey.privateKey);
|
await ev.Sign(randomKey.privateKey);
|
||||||
}
|
}
|
||||||
query.set("nostr", JSON.stringify(ev.ToObject()));
|
query.set("nostr", JSON.stringify(ev.ToObject()));
|
||||||
|
@ -38,6 +38,7 @@ function getInvoice(zap: TaggedRawEvent) {
|
|||||||
interface Zapper {
|
interface Zapper {
|
||||||
pubkey?: HexKey;
|
pubkey?: HexKey;
|
||||||
isValid: boolean;
|
isValid: boolean;
|
||||||
|
isAnon: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getZapper(zap: TaggedRawEvent, dhash: string): Zapper {
|
function getZapper(zap: TaggedRawEvent, dhash: string): Zapper {
|
||||||
@ -50,16 +51,17 @@ function getZapper(zap: TaggedRawEvent, dhash: string): Zapper {
|
|||||||
const rawEvent: TaggedRawEvent = JSON.parse(zapRequest);
|
const rawEvent: TaggedRawEvent = JSON.parse(zapRequest);
|
||||||
if (Array.isArray(rawEvent)) {
|
if (Array.isArray(rawEvent)) {
|
||||||
// old format, ignored
|
// old format, ignored
|
||||||
return { isValid: false };
|
return { isValid: false, isAnon: false };
|
||||||
}
|
}
|
||||||
|
const anonZap = rawEvent.tags.some(a => a[0] === "anon");
|
||||||
const metaHash = sha256(zapRequest);
|
const metaHash = sha256(zapRequest);
|
||||||
const ev = new Event(rawEvent);
|
const ev = new Event(rawEvent);
|
||||||
return { pubkey: ev.PubKey, isValid: dhash === metaHash };
|
return { pubkey: ev.PubKey, isValid: dhash === metaHash, isAnon: anonZap };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Invalid zap", zapRequest);
|
console.warn("Invalid zap", zapRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { isValid: false };
|
return { isValid: false, isAnon: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ParsedZap {
|
export interface ParsedZap {
|
||||||
@ -71,11 +73,12 @@ export interface ParsedZap {
|
|||||||
zapper?: HexKey;
|
zapper?: HexKey;
|
||||||
valid: boolean;
|
valid: boolean;
|
||||||
zapService: HexKey;
|
zapService: HexKey;
|
||||||
|
anonZap: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseZap(zap: TaggedRawEvent): ParsedZap {
|
export function parseZap(zap: TaggedRawEvent): ParsedZap {
|
||||||
const { amount, hash } = getInvoice(zap);
|
const { amount, hash } = getInvoice(zap);
|
||||||
const zapper = hash ? getZapper(zap, hash) : { isValid: false };
|
const zapper = hash ? getZapper(zap, hash) : ({ isValid: false } as Zapper);
|
||||||
const e = findTag(zap, "e");
|
const e = findTag(zap, "e");
|
||||||
const p = unwrap(findTag(zap, "p"));
|
const p = unwrap(findTag(zap, "p"));
|
||||||
return {
|
return {
|
||||||
@ -87,6 +90,7 @@ export function parseZap(zap: TaggedRawEvent): ParsedZap {
|
|||||||
content: zap.content,
|
content: zap.content,
|
||||||
valid: zapper.isValid,
|
valid: zapper.isValid,
|
||||||
zapService: zap.pubkey,
|
zapService: zap.pubkey,
|
||||||
|
anonZap: zapper.isAnon,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user