From f601e88b8fc12ce8917fb346bbba8952cf3e5f68 Mon Sep 17 00:00:00 2001 From: kieran Date: Fri, 12 Apr 2024 11:56:10 +0100 Subject: [PATCH] refactor: cleanup ecash nuts embed closes #718 --- packages/app/src/Components/Copy/Copy.tsx | 5 +- .../app/src/Components/Embed/CashuNuts.css | 5 - .../app/src/Components/Embed/CashuNuts.tsx | 100 ++++-------------- packages/app/src/Components/Icons/ECash.tsx | 55 ++++++++++ 4 files changed, 79 insertions(+), 86 deletions(-) create mode 100644 packages/app/src/Components/Icons/ECash.tsx diff --git a/packages/app/src/Components/Copy/Copy.tsx b/packages/app/src/Components/Copy/Copy.tsx index 70ec3125..1ef8e9b2 100644 --- a/packages/app/src/Components/Copy/Copy.tsx +++ b/packages/app/src/Components/Copy/Copy.tsx @@ -9,15 +9,16 @@ export interface CopyProps { text: string; maxSize?: number; className?: string; + showText?: boolean; } -export default function Copy({ text, maxSize = 32, className }: CopyProps) { +export default function Copy({ text, maxSize = 32, className, showText }: CopyProps) { const { copy, copied } = useCopy(); const sliceLength = maxSize / 2; const trimmed = text.length > maxSize ? `${text.slice(0, sliceLength)}...${text.slice(-sliceLength)}` : text; return (
copy(text)}> - {trimmed} + {(showText ?? true) && {trimmed}} {copied ? : } diff --git a/packages/app/src/Components/Embed/CashuNuts.css b/packages/app/src/Components/Embed/CashuNuts.css index f82778b6..b437d9af 100644 --- a/packages/app/src/Components/Embed/CashuNuts.css +++ b/packages/app/src/Components/Embed/CashuNuts.css @@ -1,8 +1,3 @@ .cashu { background: var(--cashu-gradient); } - -.cashu h1 { - font-size: 44px; - line-height: 1em; -} diff --git a/packages/app/src/Components/Embed/CashuNuts.tsx b/packages/app/src/Components/Embed/CashuNuts.tsx index 6bf405b5..d650d22a 100644 --- a/packages/app/src/Components/Embed/CashuNuts.tsx +++ b/packages/app/src/Components/Embed/CashuNuts.tsx @@ -4,7 +4,10 @@ import { useUserProfile } from "@snort/system-react"; import { useEffect, useState } from "react"; import { FormattedMessage, FormattedNumber } from "react-intl"; +import AsyncButton from "@/Components/Button/AsyncButton"; +import ECashIcon from "@/Components/Icons/ECash"; import Icon from "@/Components/Icons/Icon"; +import { useCopy } from "@/Hooks/useCopy"; import useLogin from "@/Hooks/useLogin"; interface Token { @@ -20,13 +23,9 @@ interface Token { export default function CashuNuts({ token }: { token: string }) { const { publicKey } = useLogin(s => ({ publicKey: s.publicKey })); const profile = useUserProfile(publicKey); + const { copy } = useCopy(); - async function copyToken(e: React.MouseEvent, token: string) { - e.stopPropagation(); - await navigator.clipboard.writeText(token); - } - async function redeemToken(e: React.MouseEvent, token: string) { - e.stopPropagation(); + async function redeemToken(token: string) { const lnurl = profile?.lud16 ?? ""; const url = `https://redeem.cashu.me?token=${encodeURIComponent(token)}&lightning=${encodeURIComponent( lnurl, @@ -53,87 +52,30 @@ export default function CashuNuts({ token }: { token: string }) { const amount = cashu.token[0].proofs.reduce((acc, v) => acc + v.amount, 0); return ( -
-
-
- - - - - - - - - - - - - - - - - - - - - +
+
+
+

{c}

, - n: , + n: ( + + + + ), }} />
- - {c}, - url: new URL(cashu.token[0].mint).hostname, - }} - /> -
-
- - +
); diff --git a/packages/app/src/Components/Icons/ECash.tsx b/packages/app/src/Components/Icons/ECash.tsx new file mode 100644 index 00000000..f7e7c665 --- /dev/null +++ b/packages/app/src/Components/Icons/ECash.tsx @@ -0,0 +1,55 @@ +export default function ECashIcon(props: { width?: number; height?: number }) { + return ( + + + + + + + + + + + + + + + + + + + + + + ); +}