From 6d39f8e13bfea757a9712ecbacb2ac37df56b7ce Mon Sep 17 00:00:00 2001 From: Oscar Merry Date: Tue, 2 Jul 2024 09:23:49 +0100 Subject: [PATCH] Render Embedded Zap Amount --- .../EmbeddedNote/EmbeddedNote.module.scss | 17 ++++- src/components/EmbeddedNote/EmbeddedNote.tsx | 67 ++++++++++++------- 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/src/components/EmbeddedNote/EmbeddedNote.module.scss b/src/components/EmbeddedNote/EmbeddedNote.module.scss index 9fb4ada..92ea55b 100644 --- a/src/components/EmbeddedNote/EmbeddedNote.module.scss +++ b/src/components/EmbeddedNote/EmbeddedNote.module.scss @@ -1,3 +1,16 @@ +.embeddedZapInfo { + display: flex; +} + +.embeddedZapIcon { + width: 18px; + height: 18px; + background-color: var(--active-zap); + -webkit-mask: url(../../assets/icons/feed_zap_fill_2.svg) no-repeat center 0 / + auto 100%; + mask: url(../../assets/icons/feed_zap_fill_2.svg) no-repeat center 0 / auto + 100%; +} .mentionedNote { border: none; @@ -58,7 +71,7 @@ } } - .time{ + .time { margin: 0px 2px; min-width: 40px; font-size: 14px; @@ -107,7 +120,6 @@ text-overflow: ellipsis; white-space: nowrap; overflow: hidden; - } } } @@ -116,3 +128,4 @@ .noteContent { overflow: hidden; } + diff --git a/src/components/EmbeddedNote/EmbeddedNote.tsx b/src/components/EmbeddedNote/EmbeddedNote.tsx index c1933ba..aece83a 100644 --- a/src/components/EmbeddedNote/EmbeddedNote.tsx +++ b/src/components/EmbeddedNote/EmbeddedNote.tsx @@ -7,22 +7,22 @@ import { useThreadContext } from '../../contexts/ThreadContext'; import { date } from '../../lib/dates'; import { trimVerification } from '../../lib/profile'; import { nip05Verification, userName } from '../../stores/profile'; -import { note as t } from '../../translations'; +import { note as t, profile as tProfile } from '../../translations'; import { PrimalNote, PrimalUser } from '../../types/primal'; import Avatar from '../Avatar/Avatar'; import ParsedNote from '../ParsedNote/ParsedNote'; import VerificationCheck from '../VerificationCheck/VerificationCheck'; import styles from './EmbeddedNote.module.scss'; +import { humanizeNumber } from '../../lib/stats'; const EmbeddedNote: Component<{ - note: PrimalNote, - mentionedUsers?: Record, - includeEmbeds?: boolean, - isLast?: boolean, - alternativeBackground?: boolean, + note: PrimalNote; + mentionedUsers?: Record; + includeEmbeds?: boolean; + isLast?: boolean; + alternativeBackground?: boolean; }> = (props) => { - const threadContext = useThreadContext(); const intl = useIntl(); @@ -30,6 +30,26 @@ const EmbeddedNote: Component<{ const noteId = () => nip19.noteEncode(props.note.post.id); + const isEmbeddedZap = (props.note.post.kind as number) === 9735; + const getEmbeddedZapAmount = () => { + try { + if (!isEmbeddedZap) return null; + const embeddedZapRequest = JSON.parse( + props.note.post.tags.find((t) => t[0] === 'description')![1] + ); + const embeddedZapAmount = Math.round( + parseInt( + embeddedZapRequest.tags.find((t: any) => t[0] === 'amount')[1], + 10 + ) / 1000 + ); + return embeddedZapAmount; + } catch (error) { + return null; + } + }; + const embeddedZapAmount = getEmbeddedZapAmount(); + const navToThread = () => { threadContext?.actions.setPrimaryNote(props.note); }; @@ -41,11 +61,11 @@ const EmbeddedNote: Component<{ const klass = () => { let k = styles.mentionedNote; k += ' embeddedNote'; - if (props.isLast) k+= ' noBottomMargin'; - if (props.alternativeBackground) k+= ` ${styles.altBack}`; + if (props.isLast) k += ' noBottomMargin'; + if (props.alternativeBackground) k += ` ${styles.altBack}`; return k; - } + }; const wrapper = (children: JSXElement) => { if (props.includeEmbeds) { @@ -75,29 +95,26 @@ const EmbeddedNote: Component<{ return wrapper( <> + {embeddedZapAmount ? ( +
+
+ {humanizeNumber(embeddedZapAmount)} sats +
+ ) : null} +
- + - {userName(props.note.user)} - + {userName(props.note.user)} } > - - {verification()[0]} - + {verification()[0]} - + {nip05Verification(props.note.user)} @@ -122,6 +139,6 @@ const EmbeddedNote: Component<{
); -} +}; export default EmbeddedNote;