diff --git a/src/components/Decoder/index.tsx b/src/components/Decoder/index.tsx index cf9de5429..32ffa3d5c 100644 --- a/src/components/Decoder/index.tsx +++ b/src/components/Decoder/index.tsx @@ -7,7 +7,7 @@ import { hexToUtf8 } from '../../utils/string' import { useSetToast } from '../Toast' import { ReactComponent as CopyIcon } from '../../assets/copy_icon.svg' import styles from './styles.module.scss' -import { parseSporeCellData } from '../../utils/spore' +import { parseSporeCellData, parseSporeClusterData } from '../../utils/spore' import { parseBtcTimeLockArgs } from '../../utils/rgbpp' enum DecodeMethod { @@ -18,6 +18,7 @@ enum DecodeMethod { TokenInfo = 'token-info', XudtData = 'xudt-data', BTCTimeLock = 'btc-time-lock', + SporeCluster = 'spore-cluster', Spore = 'spore', JSON = 'json', } @@ -217,6 +218,10 @@ const Decoder = () => { const script = addressToScript(v) return { display: JSON.stringify(script, null, 2), copy: script } } + case DecodeMethod.SporeCluster: { + const data = parseSporeClusterData(v) + return { display: jsonToList(data), copy: data } + } case DecodeMethod.Spore: { const data = parseSporeCellData(v) switch (data.contentType) { diff --git a/src/locales/en.json b/src/locales/en.json index ea5b1c8bf..9e0ed6747 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1060,6 +1060,7 @@ "token-info": "Token Info", "xudt-data": "XUDT Data", "btc-time-lock": "BTC Time Lock", + "spore-cluster": "Spore Cluster", "spore": "Spore", "json": "JSON", "select-x-from-y": "Selected {{x}} chars from {{y}}", diff --git a/src/locales/zh.json b/src/locales/zh.json index 98763e2d1..d7f0c8952 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -1035,6 +1035,7 @@ "token-info": "Token Info", "xudt-data": "XUDT Data", "btc-time-lock": "BTC Time Lock", + "spore-cluster": "Spore Cluster", "spore": "Spore", "json": "JSON", "select-x-from-y": "从 {{y}} 字符起选择了 {{x}} 个字符", diff --git a/src/utils/spore.ts b/src/utils/spore.ts index b789e4501..8e5cc0d4a 100644 --- a/src/utils/spore.ts +++ b/src/utils/spore.ts @@ -11,7 +11,21 @@ export function parseSporeClusterData(hexData: string) { const name = hexToUtf8(`0x${data.slice(nameOffset + 8, descriptionOffset)}`) const description = hexToUtf8(`0x${data.slice(descriptionOffset + 8)}`) - + try { + const parsed = JSON.parse(description) + if (typeof parsed === 'object') { + const v: Record = { name } + Object.keys(parsed).forEach(key => { + if (key === 'name') { + throw new Error('name key is reserved') + } + v[key] = JSON.stringify(parsed[key], null, 2) + }) + return v + } + } catch { + // ignore + } return { name, description } }