From eede2c7ec7c34a03a88c60a466cda22987b63c58 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 20 Apr 2023 00:56:52 +0100 Subject: [PATCH] feat: support greenfield --- public/locales/en/site.json | 2 +- public/locales/zh-TW/common.json | 1 + public/locales/zh-TW/site.json | 2 +- public/locales/zh/common.json | 1 + public/locales/zh/site.json | 2 +- src/components/common/BlockchainInfo.tsx | 93 ++++++++++-------------- src/lib/upload-file.ts | 2 +- src/models/site.model.ts | 8 ++ src/queries/site.ts | 9 +++ src/queries/unidata.ts | 1 + 10 files changed, 64 insertions(+), 57 deletions(-) diff --git a/public/locales/en/site.json b/public/locales/en/site.json index 1c8a1111..0fe088ce 100644 --- a/public/locales/en/site.json +++ b/public/locales/en/site.json @@ -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." } \ No newline at end of file diff --git a/public/locales/zh-TW/common.json b/public/locales/zh-TW/common.json index 104a3883..0cc9defd 100644 --- a/public/locales/zh-TW/common.json +++ b/public/locales/zh-TW/common.json @@ -22,6 +22,7 @@ "Owner": "擁有者", "Transaction Hash": "交易雜湊值", "IPFS Address": "IPFS 位址", + "Greenfield Address": "Greenfield 位址", "Creation": "創建", "Last Update": "最後更新", "Create Character": "創建身份", diff --git a/public/locales/zh-TW/site.json b/public/locales/zh-TW/site.json index 83727df8..5e04dd16 100644 --- a/public/locales/zh-TW/site.json +++ b/public/locales/zh-TW/site.json @@ -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": " 提供支援", "This address is in local editing preview mode and cannot be viewed by the public.": "此地址處於本地編輯預覽模式,尚未公開。", diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index bc68bf6b..a87e050b 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -22,6 +22,7 @@ "Owner": "所有者", "Transaction Hash": "交易哈希", "IPFS Address": "IPFS 地址", + "Greenfield Address": "Greenfield 地址", "Creation": "创建", "Last Update": "最后更新", "Create Character": "创建角色", diff --git a/public/locales/zh/site.json b/public/locales/zh/site.json index b90215e8..c4975472 100644 --- a/public/locales/zh/site.json +++ b/public/locales/zh/site.json @@ -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": " 提供支持", "This address is in local editing preview mode and cannot be viewed by the public.": diff --git a/src/components/common/BlockchainInfo.tsx b/src/components/common/BlockchainInfo.tsx index b5c128fd..1658d112 100644 --- a/src/components/common/BlockchainInfo.tsx +++ b/src/components/common/BlockchainInfo.tsx @@ -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 (
@@ -29,13 +37,7 @@ export const BlockchainInfo: React.FC<{ {t("signed and stored on the blockchain", { ns: "site", - name: t( - page - ? page.tags?.includes("post") - ? "post" - : "page" - : "blog", - ), + name: t(type), })} @@ -46,24 +48,8 @@ export const BlockchainInfo: React.FC<{ )} > - + diff --git a/src/lib/upload-file.ts b/src/lib/upload-file.ts index 41e27509..b7d51dd6 100644 --- a/src/lib/upload-file.ts +++ b/src/lib/upload-file.ts @@ -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: { diff --git a/src/models/site.model.ts b/src/models/site.model.ts index 5c353829..467ab596 100644 --- a/src/models/site.model.ts +++ b/src/models/site.model.ts @@ -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 +} diff --git a/src/queries/site.ts b/src/queries/site.ts index 105f7c45..90a7fe67 100644 --- a/src/queries/site.ts +++ b/src/queries/site.ts @@ -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) + }) +} diff --git a/src/queries/unidata.ts b/src/queries/unidata.ts index 8082e82c..34093d3a 100644 --- a/src/queries/unidata.ts +++ b/src/queries/unidata.ts @@ -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 {