feat: nip05 skeleton
This commit is contained in:
@@ -1,17 +1,29 @@
|
|||||||
|
import { Skeleton } from '@/components/ui/skeleton'
|
||||||
import { useFetchProfile } from '@/hooks'
|
import { useFetchProfile } from '@/hooks'
|
||||||
import { useFetchNip05 } from '@/hooks/useFetchNip05'
|
import { useFetchNip05 } from '@/hooks/useFetchNip05'
|
||||||
import { BadgeAlert, BadgeCheck } from 'lucide-react'
|
import { BadgeAlert, BadgeCheck } from 'lucide-react'
|
||||||
|
|
||||||
export default function Nip05({ pubkey }: { pubkey: string }) {
|
export default function Nip05({ pubkey }: { pubkey: string }) {
|
||||||
const { profile } = useFetchProfile(pubkey)
|
const { profile } = useFetchProfile(pubkey)
|
||||||
const { nip05IsVerified, nip05Name, nip05Domain } = useFetchNip05(profile?.nip05, pubkey)
|
const { nip05IsVerified, nip05Name, nip05Domain, isFetching } = useFetchNip05(
|
||||||
|
profile?.nip05,
|
||||||
|
pubkey
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isFetching) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center py-1">
|
||||||
|
<Skeleton className="h-3 w-20" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (!profile?.nip05) return null
|
if (!profile?.nip05) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
nip05Name &&
|
nip05Name &&
|
||||||
nip05Domain && (
|
nip05Domain && (
|
||||||
<div className="flex items-center space-x-1 truncate">
|
<div className="flex items-center space-x-1 truncate [&_svg]:size-5">
|
||||||
{nip05Name !== '_' ? (
|
{nip05Name !== '_' ? (
|
||||||
<div className="text-sm text-muted-foreground truncate">@{nip05Name}</div>
|
<div className="text-sm text-muted-foreground truncate">@{nip05Name}</div>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -21,7 +33,7 @@ export default function Nip05({ pubkey }: { pubkey: string }) {
|
|||||||
className={`flex items-center space-x-1 hover:underline truncate ${nip05IsVerified ? 'text-highlight' : 'text-muted-foreground'}`}
|
className={`flex items-center space-x-1 hover:underline truncate ${nip05IsVerified ? 'text-highlight' : 'text-muted-foreground'}`}
|
||||||
rel="noreferrer"
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
{nip05IsVerified ? <BadgeCheck size={16} /> : <BadgeAlert size={16} />}
|
{nip05IsVerified ? <BadgeCheck /> : <BadgeAlert />}
|
||||||
<div className="text-sm truncate">{nip05Domain}</div>
|
<div className="text-sm truncate">{nip05Domain}</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ export default function Username({
|
|||||||
}) {
|
}) {
|
||||||
const { profile } = useFetchProfile(userId)
|
const { profile } = useFetchProfile(userId)
|
||||||
if (!profile && !withoutSkeleton) {
|
if (!profile && !withoutSkeleton) {
|
||||||
return <Skeleton className={cn('w-16 my-1', skeletonClassName)} />
|
return (
|
||||||
|
<div className="py-1">
|
||||||
|
<Skeleton className={cn('w-16', skeletonClassName)} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (!profile) return null
|
if (!profile) return null
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,20 @@ export function useFetchNip05(nip05?: string, pubkey?: string) {
|
|||||||
const [nip05IsVerified, setNip05IsVerified] = useState(false)
|
const [nip05IsVerified, setNip05IsVerified] = useState(false)
|
||||||
const [nip05Name, setNip05Name] = useState<string>('')
|
const [nip05Name, setNip05Name] = useState<string>('')
|
||||||
const [nip05Domain, setNip05Domain] = useState<string>('')
|
const [nip05Domain, setNip05Domain] = useState<string>('')
|
||||||
|
const [isFetching, setIsFetching] = useState(true)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!nip05 || !pubkey) return
|
if (!nip05 || !pubkey) {
|
||||||
|
setIsFetching(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
verifyNip05(nip05, pubkey).then(({ isVerified, nip05Name, nip05Domain }) => {
|
verifyNip05(nip05, pubkey).then(({ isVerified, nip05Name, nip05Domain }) => {
|
||||||
setNip05IsVerified(isVerified)
|
setNip05IsVerified(isVerified)
|
||||||
setNip05Name(nip05Name)
|
setNip05Name(nip05Name)
|
||||||
setNip05Domain(nip05Domain)
|
setNip05Domain(nip05Domain)
|
||||||
|
setIsFetching(false)
|
||||||
})
|
})
|
||||||
}, [nip05, pubkey])
|
}, [nip05, pubkey])
|
||||||
|
|
||||||
return { nip05IsVerified, nip05Name, nip05Domain }
|
return { nip05IsVerified, nip05Name, nip05Domain, isFetching }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user