feat: redesign blockchain info box
This commit is contained in:
@@ -200,9 +200,7 @@ export default async function SiteLayout({
|
||||
{children}
|
||||
</main>
|
||||
{site && !onlyContent && (
|
||||
<section className="xlog-blockchain-info max-w-screen-lg mx-auto pt-12 pb-10">
|
||||
<BlockchainInfo site={site} page={page || undefined} />
|
||||
</section>
|
||||
<BlockchainInfo site={site} page={page || undefined} />
|
||||
)}
|
||||
{!onlyContent && <SiteFooter site={site || undefined} />}
|
||||
<FABContainer>
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
"use client"
|
||||
|
||||
import { Disclosure } from "@headlessui/react"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
|
||||
import { CSB_SCAN } from "~/lib/env"
|
||||
import { CSB_SCAN, SITE_URL } from "~/lib/env"
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import { toGateway, toIPFS } from "~/lib/ipfs-parser"
|
||||
import { ExpandedCharacter, ExpandedNote } from "~/lib/types"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { useGetBlockNumber } from "~/queries/site"
|
||||
|
||||
export const BlockchainInfo = ({
|
||||
site,
|
||||
@@ -26,101 +27,125 @@ export const BlockchainInfo = ({
|
||||
: "page"
|
||||
: "blog"
|
||||
|
||||
const [realBlockNumber, setRealBlockNumber] = useState<bigint | null>(null)
|
||||
const { data: blockNumber } = useGetBlockNumber()
|
||||
|
||||
useEffect(() => {
|
||||
if (blockNumber) {
|
||||
setRealBlockNumber(blockNumber)
|
||||
}
|
||||
}, [blockNumber])
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setRealBlockNumber((prevCount) => (prevCount || BigInt(0)) + BigInt(1))
|
||||
}, 1000)
|
||||
|
||||
return () => clearInterval(interval)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="text-sm">
|
||||
<Disclosure defaultOpen={true}>
|
||||
{({ open }: { open: boolean }) => (
|
||||
<>
|
||||
<Disclosure.Button
|
||||
className="flex w-full justify-between items-center rounded-lg px-4 py-2 text-left text-gray-900 hover:bg-hover transition-colors md:rounded-xl focus-visible:ring focus-visible:ring-accent focus-visible:ring-opacity-50"
|
||||
aria-label="toggle chain info"
|
||||
data-hide-print
|
||||
>
|
||||
<span className="flex items-center">
|
||||
<BlockchainIcon className="mr-1" />
|
||||
<span>
|
||||
{t("signed and stored on the blockchain", {
|
||||
ns: "site",
|
||||
name: t(type),
|
||||
})}
|
||||
<section className="xlog-blockchain-info max-w-screen-lg mx-auto mt-20 mb-10 px-5 cursor-default">
|
||||
<div className="text-sm bg-zinc-50 rounded-xl py-6 p-8">
|
||||
<span className="flex items-center text-gray-900 mb-4">
|
||||
<BlockchainIcon className="mr-1" />
|
||||
<span>
|
||||
{t("signed and stored on the blockchain", {
|
||||
ns: "site",
|
||||
name: t(type),
|
||||
})}
|
||||
</span>
|
||||
<a
|
||||
className="inline-flex items-center"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
href={`${SITE_URL}/about`}
|
||||
>
|
||||
<i className="icon-[mingcute--question-line]" />
|
||||
</a>
|
||||
</span>
|
||||
<ul className="space-y-2 text-[13px] text-gray-500 overflow-hidden">
|
||||
<li>
|
||||
<div className="font-medium">{t("Blockchain ID")}</div>
|
||||
<div>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/tx/${
|
||||
site?.transactionHash || page?.transactionHash
|
||||
}`}
|
||||
>
|
||||
#{site?.characterId}
|
||||
{page?.noteId && `-${page?.noteId}`}
|
||||
<span className="ml-2">
|
||||
{!!blockNumber &&
|
||||
!!realBlockNumber &&
|
||||
`(${t("Confirmed by {{blockNumber}} blocks", {
|
||||
blockNumber:
|
||||
realBlockNumber -
|
||||
BigInt(page?.blockNumber || site?.blockNumber || 0),
|
||||
})})`}
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
className={cn(
|
||||
"icon-[mingcute--up-line] text-lg text-gray-500 transform transition-transform",
|
||||
open ? "" : "rotate-180",
|
||||
)}
|
||||
></span>
|
||||
</Disclosure.Button>
|
||||
<Disclosure.Panel className="px-5 py-2 text-[13px] text-gray-500 w-full overflow-hidden">
|
||||
<ul className="space-y-2">
|
||||
<li>
|
||||
<div className="font-medium">{t("Owner")}</div>
|
||||
<div>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/address/${page?.owner || site?.owner}`}
|
||||
key={page?.owner || site?.owner}
|
||||
>
|
||||
{page?.owner || site?.owner}
|
||||
</BlockchainInfoLink>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div className="font-medium">{t("Transaction Hash")}</div>
|
||||
<div>
|
||||
{page ? (
|
||||
<>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/tx/${page?.transactionHash}`}
|
||||
key={`create_${page?.transactionHash}`}
|
||||
>
|
||||
{t("Creation")} {page?.transactionHash.slice(0, 10)}
|
||||
...{page?.transactionHash.slice(-10)}
|
||||
</BlockchainInfoLink>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/tx/${page?.updatedTransactionHash}`}
|
||||
key={`update_${page?.updatedTransactionHash}`}
|
||||
>
|
||||
{t("Last Update")}{" "}
|
||||
{page?.updatedTransactionHash.slice(0, 10)}...
|
||||
{page?.updatedTransactionHash.slice(-10)}
|
||||
</BlockchainInfoLink>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/tx/${site?.transactionHash}`}
|
||||
key={`create_${site?.transactionHash}`}
|
||||
>
|
||||
{t("Creation")} {site?.transactionHash.slice(0, 10)}
|
||||
...{site?.transactionHash.slice(-10)}
|
||||
</BlockchainInfoLink>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/tx/${site?.updatedTransactionHash}`}
|
||||
key={`update_${site?.transactionHash}`}
|
||||
>
|
||||
{t("Last Update")}{" "}
|
||||
{site?.updatedTransactionHash.slice(0, 10)}...
|
||||
{site?.updatedTransactionHash.slice(-10)}
|
||||
</BlockchainInfoLink>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div className="font-medium">{t("IPFS Address")}</div>
|
||||
<div>
|
||||
<BlockchainInfoLink href={toGateway(ipfs)}>
|
||||
{toIPFS(ipfs)}
|
||||
</BlockchainInfoLink>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</Disclosure.Panel>
|
||||
</>
|
||||
)}
|
||||
</Disclosure>
|
||||
</div>
|
||||
</BlockchainInfoLink>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div className="font-medium">{t("Owner")}</div>
|
||||
<div>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/address/${page?.owner || site?.owner}`}
|
||||
>
|
||||
{page?.owner || site?.owner}
|
||||
</BlockchainInfoLink>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div className="font-medium">{t("Transaction Hash")}</div>
|
||||
<div>
|
||||
{page ? (
|
||||
<>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/tx/${page?.transactionHash}`}
|
||||
>
|
||||
{t("Creation")} {page?.transactionHash.slice(0, 10)}
|
||||
...{page?.transactionHash.slice(-10)}
|
||||
</BlockchainInfoLink>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/tx/${page?.updatedTransactionHash}`}
|
||||
>
|
||||
{t("Last Update")}{" "}
|
||||
{page?.updatedTransactionHash.slice(0, 10)}...
|
||||
{page?.updatedTransactionHash.slice(-10)}
|
||||
</BlockchainInfoLink>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/tx/${site?.transactionHash}`}
|
||||
>
|
||||
{t("Creation")} {site?.transactionHash.slice(0, 10)}
|
||||
...{site?.transactionHash.slice(-10)}
|
||||
</BlockchainInfoLink>
|
||||
<BlockchainInfoLink
|
||||
href={`${CSB_SCAN}/tx/${site?.updatedTransactionHash}`}
|
||||
>
|
||||
{t("Last Update")}{" "}
|
||||
{site?.updatedTransactionHash.slice(0, 10)}...
|
||||
{site?.updatedTransactionHash.slice(-10)}
|
||||
</BlockchainInfoLink>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div className="font-medium">{t("IPFS Address")}</div>
|
||||
<div>
|
||||
<BlockchainInfoLink href={toGateway(ipfs)}>
|
||||
{toIPFS(ipfs)}
|
||||
</BlockchainInfoLink>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -71,10 +71,15 @@ const Comment = ({
|
||||
setTotalListHeight(Math.min(height + 71, 900))
|
||||
}
|
||||
}}
|
||||
itemContent={(_, p) =>
|
||||
itemContent={(index, p) =>
|
||||
p?.list?.map((comment, idx) => (
|
||||
<CommentItem
|
||||
className="mt-6"
|
||||
className={cn("mt-6", {
|
||||
"border-b-0":
|
||||
data &&
|
||||
index === data.length - 1 &&
|
||||
idx === p.list?.length - 1,
|
||||
})}
|
||||
originalCharacterId={page?.characterId}
|
||||
originalNoteId={page?.noteId}
|
||||
comment={comment}
|
||||
|
||||
@@ -16,7 +16,7 @@ import { Skeleton } from "../ui/Skeleton"
|
||||
const key = ["PostFooterInView"]
|
||||
|
||||
const CommentSkeleton = () => (
|
||||
<div className="xlog-comment comment" id="comments" data-hide-print>
|
||||
<div className="xlog-comment comment mb-10" id="comments" data-hide-print>
|
||||
<Skeleton.Container>
|
||||
<>
|
||||
<div className="xlog-comment-count border-b pb-2 mb-6">
|
||||
@@ -89,7 +89,7 @@ export const PostFooter = ({
|
||||
<ReactionShare noteId={page?.noteId} />
|
||||
</div>
|
||||
{inited || isInView ? (
|
||||
<DynamicComment page={page} fixHeight={fixHeight} />
|
||||
<DynamicComment page={page} fixHeight={fixHeight} className="mb-10" />
|
||||
) : (
|
||||
<CommentSkeleton />
|
||||
)}
|
||||
|
||||
@@ -94,5 +94,7 @@
|
||||
"Share": "分享",
|
||||
"Share Message": "嘿,我发现了一篇宝藏文章「{{title}}」哩,快来看看吧!",
|
||||
"min": "分钟",
|
||||
"Pinned": "置顶"
|
||||
"Pinned": "置顶",
|
||||
"Blockchain ID": "区块链标识",
|
||||
"Confirmed by {{blockNumber}} blocks": "已被 {{blockNumber}} 个区块确认"
|
||||
}
|
||||
|
||||
@@ -499,3 +499,21 @@ export async function checkDomain(domain: string, handle: string) {
|
||||
|
||||
return check.data
|
||||
}
|
||||
|
||||
export async function getBlockNumber() {
|
||||
const result = await (
|
||||
await fetch("https://scan.crossbell.io/api/eth-rpc", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
method: "eth_blockNumber",
|
||||
params: [],
|
||||
id: 0,
|
||||
}),
|
||||
})
|
||||
).json()
|
||||
return BigInt(result.result)
|
||||
}
|
||||
|
||||
@@ -528,3 +528,9 @@ export const useGetCharacterCard = ({
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export const useGetBlockNumber = () => {
|
||||
return useQuery(["getBlockNumber"], async () => {
|
||||
return siteModel.getBlockNumber()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user