feat: support greenfield
This commit is contained in:
parent
b7167d3fce
commit
eede2c7ec7
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"load more": "There are {{count}} more {{name}}, click to load more",
|
||||
"signed and stored on the blockchain": "This {{name}} has been signed and securely stored on the blockchain by its creator."
|
||||
"signed and stored on the blockchain": "Ownership of this {{name}} data is guaranteed by blockchain and smart contracts to the creator alone."
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
"Owner": "擁有者",
|
||||
"Transaction Hash": "交易雜湊值",
|
||||
"IPFS Address": "IPFS 位址",
|
||||
"Greenfield Address": "Greenfield 位址",
|
||||
"Creation": "創建",
|
||||
"Last Update": "最後更新",
|
||||
"Create Character": "創建身份",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"About": "關於",
|
||||
"Tags": "標籤",
|
||||
"load more": "還有{{count}}篇{{name}},點選載入更多文章",
|
||||
"signed and stored on the blockchain": "此{{name}}已由它的創作者簽名並安全儲存在區塊鏈上。",
|
||||
"signed and stored on the blockchain": "區塊鏈加密技術和智能合約確保{{name}}數據所有權僅屬於創作者。",
|
||||
"Write a comment on the blockchain": "在區塊鏈上留言。",
|
||||
"powered by": "<span>由 </span><name/><span> 提供支援</span>",
|
||||
"This address is in local editing preview mode and cannot be viewed by the public.": "此地址處於本地編輯預覽模式,尚未公開。",
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
"Owner": "所有者",
|
||||
"Transaction Hash": "交易哈希",
|
||||
"IPFS Address": "IPFS 地址",
|
||||
"Greenfield Address": "Greenfield 地址",
|
||||
"Creation": "创建",
|
||||
"Last Update": "最后更新",
|
||||
"Create Character": "创建角色",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"About": "关于",
|
||||
"Tags": "标签",
|
||||
"load more": "还有 {{count}} 篇{{name}},点击加载更多",
|
||||
"signed and stored on the blockchain": "此{{name}}已经由它的创作者签名并安全地存储在区块链上。",
|
||||
"signed and stored on the blockchain": "区块链加密技术和智能合约保障{{name}}数据所有权仅属于创作者。",
|
||||
"Write a comment on the blockchain": "在区块链上写下你的评论",
|
||||
"powered by": "<span>由 </span><name/><span> 提供支持</span>",
|
||||
"This address is in local editing preview mode and cannot be viewed by the public.":
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ import { useTranslation } from "next-i18next"
|
|||
import { Disclosure } from "@headlessui/react"
|
||||
|
||||
import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
|
||||
import { CSB_IO, CSB_SCAN, IPFS_GATEWAY } from "~/lib/env"
|
||||
import { toGateway, toIPFS } from "~/lib/ipfs-parser"
|
||||
import { CSB_SCAN, IPFS_GATEWAY } from "~/lib/env"
|
||||
import { toCid, toGateway, toIPFS } from "~/lib/ipfs-parser"
|
||||
import { Note, Profile } from "~/lib/types"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { useGetGreenfieldId } from "~/queries/site"
|
||||
|
||||
export const BlockchainInfo: React.FC<{
|
||||
site?: Profile | null
|
||||
|
|
@ -14,6 +15,13 @@ export const BlockchainInfo: React.FC<{
|
|||
}> = ({ site, page }) => {
|
||||
const { t } = useTranslation(["common", "site"])
|
||||
|
||||
const ipfs = page
|
||||
? page.related_urls?.filter((url) => url.startsWith(IPFS_GATEWAY))?.[0]
|
||||
: site?.metadata?.uri
|
||||
const greenfieldId = useGetGreenfieldId(toCid(ipfs))
|
||||
|
||||
const type = page ? (page?.tags?.includes("post") ? "post" : "page") : "blog"
|
||||
|
||||
return (
|
||||
<div className="text-sm">
|
||||
<Disclosure defaultOpen={true}>
|
||||
|
|
@ -29,13 +37,7 @@ export const BlockchainInfo: React.FC<{
|
|||
<span>
|
||||
{t("signed and stored on the blockchain", {
|
||||
ns: "site",
|
||||
name: t(
|
||||
page
|
||||
? page.tags?.includes("post")
|
||||
? "post"
|
||||
: "page"
|
||||
: "blog",
|
||||
),
|
||||
name: t(type),
|
||||
})}
|
||||
</span>
|
||||
</span>
|
||||
|
|
@ -46,24 +48,8 @@ export const BlockchainInfo: React.FC<{
|
|||
)}
|
||||
></span>
|
||||
</Disclosure.Button>
|
||||
<Disclosure.Panel className="px-5 py-2 text-sm text-gray-500 w-full overflow-hidden">
|
||||
<Disclosure.Panel className="px-5 py-2 text-[13px] text-gray-500 w-full overflow-hidden">
|
||||
<ul className="space-y-2">
|
||||
{page && (
|
||||
<li>
|
||||
<div className="font-medium">Note ID</div>
|
||||
<div>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-block mr-4 break-all"
|
||||
href={`${CSB_IO}/notes/${page?.id}`}
|
||||
key={page?.id}
|
||||
>
|
||||
{page?.id}
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
)}
|
||||
<li>
|
||||
<div className="font-medium">{t("Owner")}</div>
|
||||
<div>
|
||||
|
|
@ -125,35 +111,36 @@ export const BlockchainInfo: React.FC<{
|
|||
<li>
|
||||
<div className="font-medium">{t("IPFS Address")}</div>
|
||||
<div>
|
||||
{page
|
||||
? page.related_urls
|
||||
?.filter((url) => url.startsWith(IPFS_GATEWAY))
|
||||
.map((url) => {
|
||||
return (
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-block mr-4 break-all"
|
||||
href={url}
|
||||
key={url}
|
||||
>
|
||||
{toIPFS(url)}
|
||||
</a>
|
||||
)
|
||||
})
|
||||
: site?.metadata?.uri && (
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-block mr-4 break-all"
|
||||
href={toGateway(site?.metadata?.uri)}
|
||||
key={site?.metadata?.uri}
|
||||
>
|
||||
{site?.metadata?.uri}
|
||||
</a>
|
||||
)}
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-block mr-4 break-all"
|
||||
href={toGateway(ipfs)}
|
||||
>
|
||||
{toIPFS(ipfs)}
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
{greenfieldId.data?.greenfieldId && (
|
||||
<li>
|
||||
<div className="font-medium">{t("Greenfield Address")}</div>
|
||||
<div>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-block mr-4 break-all"
|
||||
href={
|
||||
"https://greenfieldscan.com/" +
|
||||
(greenfieldId.data?.transactionHash
|
||||
? `txn/${greenfieldId.data?.transactionHash}`
|
||||
: "")
|
||||
}
|
||||
>
|
||||
{greenfieldId.data?.greenfieldId}
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
)}
|
||||
</ul>
|
||||
</Disclosure.Panel>
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ export const UploadFile = async (blob: Blob) => {
|
|||
formData.append("file", blob)
|
||||
|
||||
const res = await axios.post(
|
||||
"https://ipfs-relay.crossbell.io/upload",
|
||||
"https://ipfs-relay.crossbell.io/upload?gnfd=t",
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -716,3 +716,11 @@ export async function checkDomain(domain: string, handle: string) {
|
|||
|
||||
return check.data
|
||||
}
|
||||
|
||||
export async function getGreenfieldId(cid: string) {
|
||||
const result = await (
|
||||
await fetch(`https://ipfs-relay.crossbell.io/map/ipfs2gnfd/${cid}`)
|
||||
).json()
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -422,3 +422,12 @@ export const useGetMiraBalance = (characterId?: string) => {
|
|||
return siteModel.getMiraBalance(characterId, contract)
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetGreenfieldId = (cid?: string) => {
|
||||
return useQuery(["getGreenfieldId", cid], async () => {
|
||||
if (!cid) {
|
||||
return null
|
||||
}
|
||||
return siteModel.getGreenfieldId(cid)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export const useUnidata = () => {
|
|||
unidata = new Unidata({
|
||||
ethereumProvider: provider,
|
||||
ipfsGateway: IPFS_GATEWAY,
|
||||
ipfsRelay: "https://ipfs-relay.crossbell.io/json?gnfd=t",
|
||||
})
|
||||
})
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue