Skip to content

Commit a3e81fb

Browse files
feat: ui to copy lnaddress + npub from home screen (#3150)
* feat: ui to copy lnaddress + npub from home screen * fix: margins on home page * fix: gaps --------- Co-authored-by: René Aaron <[email protected]> Co-authored-by: René Aaron <[email protected]>
1 parent bee0bb3 commit a3e81fb

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

src/app/components/BalanceBox/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function BalanceBox({ className }: Props) {
1313
return (
1414
<div
1515
className={classNames(
16-
"w-full flex flex-col items-center justify-center dark:text-white p-4",
16+
"w-full flex flex-col items-center justify-center dark:text-white mt-4",
1717
className ?? ""
1818
)}
1919
>

src/app/screens/Home/DefaultView/index.tsx

+44-19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
PopiconsBulbLine,
88
PopiconsCircleExclamationLine,
99
PopiconsKeyLine,
10+
PopiconsOstrichSolid,
1011
} from "@popicons/react";
1112
import dayjs from "dayjs";
1213
import relativeTime from "dayjs/plugin/relativeTime";
@@ -17,14 +18,14 @@ import Alert from "~/app/components/Alert";
1718
import BalanceBox from "~/app/components/BalanceBox";
1819
import Hyperlink from "~/app/components/Hyperlink";
1920
import { IconLinkCard } from "~/app/components/IconLinkCard/IconLinkCard";
20-
import SkeletonLoader from "~/app/components/SkeletonLoader";
2121
import toast from "~/app/components/Toast";
2222
import { useAccount } from "~/app/context/AccountContext";
2323
import { useTransactions } from "~/app/hooks/useTransactions";
2424
import { PublisherLnData } from "~/app/screens/Home/PublisherLnData";
2525
import { isAlbyLNDHubAccount } from "~/app/utils";
2626
import api, { GetAccountRes } from "~/common/lib/api";
2727
import msg from "~/common/lib/msg";
28+
import { default as nostr } from "~/common/lib/nostr";
2829
import utils from "~/common/lib/utils";
2930
import type { Battery } from "~/types";
3031

@@ -50,6 +51,7 @@ const DefaultView: FC<Props> = (props) => {
5051

5152
const [isBlockedUrl, setIsBlockedUrl] = useState<boolean>(false);
5253
const [currentAccount, setCurrentAccount] = useState<GetAccountRes>();
54+
const [nostrPublicKey, setNostrPublicKey] = useState("");
5355

5456
const { transactions, isLoadingTransactions, loadTransactions } =
5557
useTransactions();
@@ -78,6 +80,11 @@ const DefaultView: FC<Props> = (props) => {
7880
(async () => {
7981
try {
8082
const account = await api.getAccount();
83+
const nostrPrivateKey = await api.nostr.getPrivateKey(account.id);
84+
85+
setNostrPublicKey(
86+
nostrPrivateKey ? await nostr.derivePublicKey(nostrPrivateKey) : ""
87+
);
8188
setCurrentAccount(account);
8289
} catch (e) {
8390
console.error(e);
@@ -192,24 +199,42 @@ const DefaultView: FC<Props> = (props) => {
192199
<BalanceBox />
193200
)}
194201

195-
{(accountLoading || lightningAddress) && (
196-
<div className="flex justify-center">
197-
<a
198-
className="cursor-pointer flex flex-row items-center mb-6 px-3 py-1 bg-white dark:bg-surface-01dp border border-gray-200 dark:border-neutral-700 text-gray-800 dark:text-white rounded-full text-xs font-medium hover:border-primary hover:bg-yellow-50 dark:hover:border-primary dark:hover:dark:bg-surface-16dp transition-all duration-250 select-none"
199-
onClick={() => {
200-
navigator.clipboard.writeText(lightningAddress);
201-
toast.success(tCommon("actions.copied_to_clipboard"));
202-
}}
203-
>
204-
<img src="assets/icons/popicons/bolt.svg" className="mr-1" />
205-
{!accountLoading ? (
206-
lightningAddress
207-
) : (
208-
<SkeletonLoader className="w-32" />
209-
)}
210-
</a>
202+
{(lightningAddress || nostrPublicKey) && (
203+
<div className="flex justify-center gap-3 mb-2">
204+
{lightningAddress && (
205+
<a
206+
className="relative group cursor-pointer flex flex-row items-center p-1 bg-white dark:bg-surface-01dp border border-gray-200 dark:border-neutral-700 text-gray-800 dark:text-white rounded-full text-xs font-medium hover:border-primary hover:bg-yellow-50 dark:hover:border-primary dark:hover:dark:bg-surface-16dp transition-all duration-250 select-none"
207+
onClick={() => {
208+
navigator.clipboard.writeText(lightningAddress);
209+
toast.success(tCommon("actions.copied_to_clipboard"));
210+
}}
211+
>
212+
<img src="assets/icons/popicons/bolt.svg" className="w-5 h-5" />
213+
<span className="max-w-64 hidden group-hover:block truncate mr-1">
214+
{lightningAddress}
215+
</span>
216+
</a>
217+
)}
218+
219+
{nostrPublicKey && (
220+
<a
221+
className="relative group cursor-pointer flex flex-row items-center p-1 bg-white dark:bg-surface-01dp border border-gray-200 dark:border-neutral-700 text-gray-800 dark:text-white rounded-full text-xs font-medium hover:border-primary hover:bg-yellow-50 dark:hover:border-primary dark:hover:dark:bg-surface-16dp transition-all duration-250 select-none"
222+
onClick={() => {
223+
navigator.clipboard.writeText(nostrPublicKey);
224+
toast.success(tCommon("actions.copied_to_clipboard"));
225+
}}
226+
>
227+
<PopiconsOstrichSolid className="w-5 h-5 text-purple-500" />
228+
<span className="max-w-64 hidden group-hover:block truncate mr-1">
229+
{nostrPublicKey.substring(0, 11)}
230+
...
231+
{nostrPublicKey.substring(nostrPublicKey.length - 11)}
232+
</span>
233+
</a>
234+
)}
211235
</div>
212236
)}
237+
213238
<div className="flex space-x-3 justify-between">
214239
<HomeButton
215240
icon={<img src="assets/icons/popicons/receive.svg" />}
@@ -238,13 +263,13 @@ const DefaultView: FC<Props> = (props) => {
238263
</div>
239264

240265
{isLoading && (
241-
<div className="flex justify-center mt-4">
266+
<div className="flex justify-center">
242267
<Loading />
243268
</div>
244269
)}
245270

246271
{!isLoading && (
247-
<div className="mt-4 flex flex-col gap-4">
272+
<div className="flex flex-col gap-4">
248273
{(transactions.length === 0 || needsKeySetup) && (
249274
<div className="flex flex-col gap-2 md:gap-3">
250275
{transactions.length === 0 && (

0 commit comments

Comments
 (0)