From 5159955de4e3a436fb858519e1e82b25f2c0425c Mon Sep 17 00:00:00 2001 From: devchenyan Date: Tue, 12 Nov 2024 10:23:45 +0800 Subject: [PATCH 1/2] feat: handle hash_type:data2 --- packages/neuron-ui/src/components/SpecialAssetList/hooks.ts | 2 +- packages/neuron-ui/src/types/Controller/index.d.ts | 2 +- packages/neuron-ui/src/utils/scriptAndAddress.ts | 3 +++ packages/neuron-wallet/src/models/asset-account-info.ts | 1 + packages/neuron-wallet/src/models/chain/live-cell.ts | 1 + packages/neuron-wallet/src/models/chain/script.ts | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/neuron-ui/src/components/SpecialAssetList/hooks.ts b/packages/neuron-ui/src/components/SpecialAssetList/hooks.ts index d1ff65cc43..1e0b9c82cf 100644 --- a/packages/neuron-ui/src/components/SpecialAssetList/hooks.ts +++ b/packages/neuron-ui/src/components/SpecialAssetList/hooks.ts @@ -30,7 +30,7 @@ export interface SpecialAssetCell { lock: { args: string codeHash: string - hashType: 'type' | 'data' + hashType: 'type' | 'data' | 'data1' | 'data2' } lockHash: string multiSignBlake160: string diff --git a/packages/neuron-ui/src/types/Controller/index.d.ts b/packages/neuron-ui/src/types/Controller/index.d.ts index 380129f808..6a1b6f22b2 100644 --- a/packages/neuron-ui/src/types/Controller/index.d.ts +++ b/packages/neuron-ui/src/types/Controller/index.d.ts @@ -215,7 +215,7 @@ declare namespace Controller { interface Response { cellDep: any codeHash: string - hashType: 'data' | 'type' + hashType: 'data' | 'type' | 'data1' | 'data2' } } interface SUDTAccount { diff --git a/packages/neuron-ui/src/utils/scriptAndAddress.ts b/packages/neuron-ui/src/utils/scriptAndAddress.ts index dfc0965bcc..4a6d9034bc 100644 --- a/packages/neuron-ui/src/utils/scriptAndAddress.ts +++ b/packages/neuron-ui/src/utils/scriptAndAddress.ts @@ -13,6 +13,9 @@ export const scriptToAddress = ( { isMainnet = true, deprecated = false }: { isMainnet?: boolean; deprecated?: boolean } ) => { const config = { config: isMainnet ? MAINNET : TESTNET } + if (['data1', 'data2'].includes(script.hashType)) { + return encodeToAddress(script, config) + } return deprecated ? generateAddress(script, config) : encodeToAddress(script, config) } diff --git a/packages/neuron-wallet/src/models/asset-account-info.ts b/packages/neuron-wallet/src/models/asset-account-info.ts index b4cb7a8d82..dee91b2426 100644 --- a/packages/neuron-wallet/src/models/asset-account-info.ts +++ b/packages/neuron-wallet/src/models/asset-account-info.ts @@ -401,6 +401,7 @@ function toScriptInfo(sporeConfig: SporeScript): ScriptCellInfo { if (sporeScriptHashType === 'type') return ScriptHashType.Type if (sporeScriptHashType === 'data') return ScriptHashType.Data if (sporeScriptHashType === 'data1') return ScriptHashType.Data1 + if (sporeScriptHashType === 'data2') return ScriptHashType.Data2 throw new Error(`Invalid hash type: ${sporeScriptHashType}`) })() diff --git a/packages/neuron-wallet/src/models/chain/live-cell.ts b/packages/neuron-wallet/src/models/chain/live-cell.ts index 4efc95dd60..4d85cedd47 100644 --- a/packages/neuron-wallet/src/models/chain/live-cell.ts +++ b/packages/neuron-wallet/src/models/chain/live-cell.ts @@ -6,6 +6,7 @@ const LUMOS_HASH_TYPE_MAP: Record = { type: ScriptHashType.Type, data1: ScriptHashType.Data1, data: ScriptHashType.Data, + data2: ScriptHashType.Data2, } export type CellWithOutPoint = Cell & { outPoint: IOutPoint } diff --git a/packages/neuron-wallet/src/models/chain/script.ts b/packages/neuron-wallet/src/models/chain/script.ts index 40034ea46f..03dcc0880c 100644 --- a/packages/neuron-wallet/src/models/chain/script.ts +++ b/packages/neuron-wallet/src/models/chain/script.ts @@ -6,6 +6,7 @@ export enum ScriptHashType { Data = 'data', Type = 'type', Data1 = 'data1', + Data2 = 'data2', } export default class Script { From a5fb9a1f6e80046977e2606ab4bedd8bbbb2d13a Mon Sep 17 00:00:00 2001 From: devchenyan Date: Tue, 12 Nov 2024 16:08:13 +0800 Subject: [PATCH 2/2] fix --- packages/neuron-ui/src/utils/scriptAndAddress.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/neuron-ui/src/utils/scriptAndAddress.ts b/packages/neuron-ui/src/utils/scriptAndAddress.ts index 4a6d9034bc..dfc0965bcc 100644 --- a/packages/neuron-ui/src/utils/scriptAndAddress.ts +++ b/packages/neuron-ui/src/utils/scriptAndAddress.ts @@ -13,9 +13,6 @@ export const scriptToAddress = ( { isMainnet = true, deprecated = false }: { isMainnet?: boolean; deprecated?: boolean } ) => { const config = { config: isMainnet ? MAINNET : TESTNET } - if (['data1', 'data2'].includes(script.hashType)) { - return encodeToAddress(script, config) - } return deprecated ? generateAddress(script, config) : encodeToAddress(script, config) }