feat: nip05 on profile page

This commit is contained in:
Alejandro Gomez 2023-01-09 19:33:46 +01:00
parent 643d35531b
commit 81d00975a0
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817
3 changed files with 64 additions and 1 deletions

18
src/element/Nip05.css Normal file
View File

@ -0,0 +1,18 @@
.nip05 {
align-items: center;
font-size: 14px;
justify-content: flex-start;
margin: .2em 0;
}
.nip05 .nick {
color: #999;
}
.nip05 .domain {
color: #DDD;
}
.nip05 .badge {
margin-left: .2em;
}

43
src/element/Nip05.js Normal file
View File

@ -0,0 +1,43 @@
import { useState, useEffect } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCheck } from "@fortawesome/free-solid-svg-icons";
import './Nip05.css'
const Nip05 = ({ nip05, pubkey }) => {
const [nip05pubkey, setNip05pubkey] = useState()
const isVerified = nip05pubkey === pubkey
const [nick, domain] = nip05.split('@')
useEffect(() => {
fetch(`https://${domain}/.well-known/nostr.json`)
.then((res) => res.json())
.then(({ names }) => {
if (names && names[nick]) {
setNip05pubkey(names[nick])
}
})
.catch((err) => {
console.error("Couldn't verifiy nip05")
})
}, [nip05, nick, domain])
return (
<div className="flex nip05">
<div className="nick">{nick}</div>
<div className="domain">@{domain}</div>
{isVerified && (
<span className="badge">
<FontAwesomeIcon
color={"green"}
icon={faCheck}
size="xs"
/>
</span>
)}
</div>
)
}
export default Nip05

View File

@ -13,6 +13,7 @@ import { extractLnAddress, parseId } from "../Util";
import Timeline from "../element/Timeline";
import { extractLinks } from '../Text'
import LNURLTip from "../element/LNURLTip";
import Nip05 from "../element/Nip05";
import Copy from "../element/Copy";
export default function ProfilePage() {
@ -30,13 +31,14 @@ export default function ProfilePage() {
<>
<div className="flex name">
<div className="f-grow">
<h2>{user?.name}</h2>
<h2>{user?.display_name || user?.name}</h2>
<Copy text={params.id} />
</div>
<div>
{isMe ? <div className="btn" onClick={() => navigate("/settings")}>Settings</div> : <FollowButton pubkey={id} />}
</div>
</div>
{user?.nip05 && <Nip05 nip05={user.nip05} pubkey={user.pubkey} />}
<p>{extractLinks([user?.about])}</p>
{user?.website ? <a href={user?.website} target="_blank" rel="noreferrer">{user?.website}</a> : null}