diff --git a/src/app/site/[site]/layout.tsx b/src/app/site/[site]/layout.tsx index 06c6f8d0..77286ab7 100644 --- a/src/app/site/[site]/layout.tsx +++ b/src/app/site/[site]/layout.tsx @@ -200,9 +200,7 @@ export default async function SiteLayout({ {children} {site && !onlyContent && ( -
- -
+ )} {!onlyContent && } diff --git a/src/components/common/BlockchainInfo.tsx b/src/components/common/BlockchainInfo.tsx index d4fe72fe..4902a97e 100644 --- a/src/components/common/BlockchainInfo.tsx +++ b/src/components/common/BlockchainInfo.tsx @@ -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(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 ( -
- - {({ open }: { open: boolean }) => ( - <> - - - - - {t("signed and stored on the blockchain", { - ns: "site", - name: t(type), - })} +
+
+ + + + {t("signed and stored on the blockchain", { + ns: "site", + name: t(type), + })} + + + + + +
    +
  • +
    {t("Blockchain ID")}
    +
    + + #{site?.characterId} + {page?.noteId && `-${page?.noteId}`} + + {!!blockNumber && + !!realBlockNumber && + `(${t("Confirmed by {{blockNumber}} blocks", { + blockNumber: + realBlockNumber - + BigInt(page?.blockNumber || site?.blockNumber || 0), + })})`} - - - - -
      -
    • -
      {t("Owner")}
      -
      - - {page?.owner || site?.owner} - -
      -
    • -
    • -
      {t("Transaction Hash")}
      -
      - {page ? ( - <> - - {t("Creation")} {page?.transactionHash.slice(0, 10)} - ...{page?.transactionHash.slice(-10)} - - - {t("Last Update")}{" "} - {page?.updatedTransactionHash.slice(0, 10)}... - {page?.updatedTransactionHash.slice(-10)} - - - ) : ( - <> - - {t("Creation")} {site?.transactionHash.slice(0, 10)} - ...{site?.transactionHash.slice(-10)} - - - {t("Last Update")}{" "} - {site?.updatedTransactionHash.slice(0, 10)}... - {site?.updatedTransactionHash.slice(-10)} - - - )} -
      -
    • -
    • -
      {t("IPFS Address")}
      -
      - - {toIPFS(ipfs)} - -
      -
    • -
    -
    - - )} - -
    + +
+ +
  • +
    {t("Owner")}
    +
    + + {page?.owner || site?.owner} + +
    +
  • +
  • +
    {t("Transaction Hash")}
    +
    + {page ? ( + <> + + {t("Creation")} {page?.transactionHash.slice(0, 10)} + ...{page?.transactionHash.slice(-10)} + + + {t("Last Update")}{" "} + {page?.updatedTransactionHash.slice(0, 10)}... + {page?.updatedTransactionHash.slice(-10)} + + + ) : ( + <> + + {t("Creation")} {site?.transactionHash.slice(0, 10)} + ...{site?.transactionHash.slice(-10)} + + + {t("Last Update")}{" "} + {site?.updatedTransactionHash.slice(0, 10)}... + {site?.updatedTransactionHash.slice(-10)} + + + )} +
    +
  • +
  • +
    {t("IPFS Address")}
    +
    + + {toIPFS(ipfs)} + +
    +
  • + +
    + ) } diff --git a/src/components/common/Comment.tsx b/src/components/common/Comment.tsx index 6b8a7864..fb3c23e2 100644 --- a/src/components/common/Comment.tsx +++ b/src/components/common/Comment.tsx @@ -71,10 +71,15 @@ const Comment = ({ setTotalListHeight(Math.min(height + 71, 900)) } }} - itemContent={(_, p) => + itemContent={(index, p) => p?.list?.map((comment, idx) => ( ( -
    +
    <>
    @@ -89,7 +89,7 @@ export const PostFooter = ({
    {inited || isInView ? ( - + ) : ( )} diff --git a/src/lib/i18n/locales/zh/common.json b/src/lib/i18n/locales/zh/common.json index 87f4d98b..ec130f88 100644 --- a/src/lib/i18n/locales/zh/common.json +++ b/src/lib/i18n/locales/zh/common.json @@ -94,5 +94,7 @@ "Share": "分享", "Share Message": "嘿,我发现了一篇宝藏文章「{{title}}」哩,快来看看吧!", "min": "分钟", - "Pinned": "置顶" + "Pinned": "置顶", + "Blockchain ID": "区块链标识", + "Confirmed by {{blockNumber}} blocks": "已被 {{blockNumber}} 个区块确认" } diff --git a/src/models/site.model.ts b/src/models/site.model.ts index 5b9a1277..b495fd1b 100644 --- a/src/models/site.model.ts +++ b/src/models/site.model.ts @@ -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) +} diff --git a/src/queries/site.ts b/src/queries/site.ts index a3fb1e08..b653d022 100644 --- a/src/queries/site.ts +++ b/src/queries/site.ts @@ -528,3 +528,9 @@ export const useGetCharacterCard = ({ }, ) } + +export const useGetBlockNumber = () => { + return useQuery(["getBlockNumber"], async () => { + return siteModel.getBlockNumber() + }) +}