Skip to content

Commit 3fbdbfd

Browse files
committed
feat: update
1 parent 9566a4d commit 3fbdbfd

File tree

14 files changed

+152
-105
lines changed

14 files changed

+152
-105
lines changed

packages/neuron-ui/src/components/HistoryDetailPage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ const HistoryDetailPage = () => {
289289
title: t('transaction.address'),
290290
dataIndex: 'type',
291291
align: 'left',
292-
width: '560px',
292+
width: '600px',
293293
render: (_, __, item) => {
294294
const { address } = handleListData(item)
295295
return (

packages/neuron-ui/src/components/MultisigAddress/index.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
useGoBack,
88
useOnWindowResize,
99
calculateFee,
10+
clsx,
1011
} from 'utils'
1112
import appState from 'states/init/app'
1213
import { useState as useGlobalState } from 'states'
@@ -22,6 +23,7 @@ import Table from 'widgets/Table'
2223
import Tooltip from 'widgets/Tooltip'
2324
import Toast from 'widgets/Toast'
2425
import AlertDialog from 'widgets/AlertDialog'
26+
import CopyZone from 'widgets/CopyZone'
2527
import {
2628
Download,
2729
Search,
@@ -39,6 +41,8 @@ import {
3941
DAOWithdrawal,
4042
Attention,
4143
Regenerate,
44+
LockCodeHash,
45+
Copy,
4246
} from 'widgets/Icons/icon'
4347
import { getHeader } from 'services/chain'
4448
import AttentionCloseDialog from 'widgets/Icons/Attention.png'
@@ -372,9 +376,8 @@ const MultisigAddress = () => {
372376
<button
373377
type="button"
374378
onClick={() => openExternal('https://github.com/Magickbase/neuron-public-issues/issues/457')}
375-
>
376-
{' '}
377-
</button>,
379+
aria-label=" "
380+
/>,
378381
]}
379382
/>
380383
</div>
@@ -437,8 +440,30 @@ const MultisigAddress = () => {
437440
render(_, __, item) {
438441
return (
439442
<div className={styles.address}>
443+
<Tooltip
444+
tip={
445+
<div>
446+
<div className={styles.titleWrap}>
447+
<p>Code_hash</p>
448+
<div className={clsx(styles.tag, item.isLegacy && styles.legacy)}>
449+
{item.isLegacy ? 'Legacy' : 'Recommended'}
450+
</div>
451+
</div>
452+
<CopyZone content={item.lockCodeHash} className={styles.copyLockCodeHash}>
453+
{item.lockCodeHash}
454+
<Copy />
455+
</CopyZone>
456+
</div>
457+
}
458+
isTriggerNextToChild
459+
tipClassName={styles.lockCodeHashTip}
460+
>
461+
<div className={clsx(styles.lockCodeHash, item.isLegacy && styles.legacy)}>
462+
<LockCodeHash />
463+
<span>@{item.lockCodeHash.slice(2, 10)}</span>
464+
</div>
465+
</Tooltip>
440466
{item.fullPayload.slice(0, 5)}...{item.fullPayload.slice(-5)}
441-
{item.isLegacy && <div className={styles.legacy}>Legacy</div>}
442467
</div>
443468
)
444469
},

packages/neuron-ui/src/components/MultisigAddress/multisigAddress.module.scss

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
height: 44px;
1616
border-bottom: 1px solid var(--warn-border-color);
1717
padding: 0 16px;
18-
max-width: 648px;
18+
max-width: 780px;
1919
& > svg {
2020
width: 16px;
2121
flex-shrink: 0;
@@ -112,7 +112,7 @@
112112
.tableWrap {
113113
margin-top: 16px;
114114
min-height: 360px;
115-
min-width: 648px;
115+
min-width: 748px;
116116
border: 1px solid var(--table-head-border-color);
117117
border-radius: 16px;
118118
border-top: none;
@@ -130,18 +130,58 @@
130130
.address {
131131
font-family: 'JetBrains Mono';
132132
position: relative;
133+
display: flex;
134+
align-items: center;
135+
column-gap: 4px;
133136

134-
.legacy {
135-
font-size: 10px;
136-
height: 16px;
137-
color: var(--third-text-color);
137+
.titleWrap {
138+
display: flex;
139+
align-items: center;
140+
column-gap: 4px;
141+
color: var(--main-text-color);
138142
font-weight: 500;
139-
position: absolute;
140-
top: -16px;
141-
right: -10px;
142-
background: var(--table-head-border-color);
143+
144+
.tag {
145+
font-size: 12px;
146+
line-height: 18px;
147+
color: var(--tabs-active);
148+
font-weight: 500;
149+
background: var(--tag-background-color);
150+
padding: 0 4px;
151+
border-radius: 2px;
152+
}
153+
.legacy {
154+
color: var(--third-text-color);
155+
background: var(--input-border-color);
156+
}
157+
}
158+
.lockCodeHash {
159+
display: flex;
160+
align-items: center;
161+
font-size: 13px;
162+
border: 1px solid var(--tabs-active);
163+
border-radius: 4px;
143164
padding: 0 4px;
144-
border-radius: 48px;
165+
line-height: 24px;
166+
color: var(--tabs-active);
167+
font-weight: 500;
168+
&.legacy {
169+
border: 1px solid var(--divide-line-color);
170+
color: var(--input-second-color);
171+
svg {
172+
path {
173+
stroke: var(--input-second-color);
174+
}
175+
}
176+
}
177+
}
178+
179+
.copyLockCodeHash {
180+
@include copyAddress;
181+
}
182+
183+
.lockCodeHashTip {
184+
margin-left: 50px;
145185
}
146186
}
147187

packages/neuron-ui/src/utils/enums.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ export enum LegacyMultiSigLockInfo {
155155
HashType = 'type',
156156
CodeHashIndex = '0x01',
157157
ArgsLen = '20',
158-
TagName = 'secp256k1/multisig/legacy',
158+
TagName = 'secp256k1/multisig/@5c5069eb',
159159
}
160160

161161
export enum MultiSigLockInfo {
162162
CodeHash = '0x36c971b8d41fbd94aabca77dc75e826729ac98447b46f91e00796155dddb0d29',
163163
HashType = 'data1',
164164
CodeHashIndex = '0x01',
165165
ArgsLen = '20',
166-
TagName = 'secp256k1/multisig',
166+
TagName = 'secp256k1/multisig/@36c971b8',
167167
}
168168

169169
export enum LocktimeLockInfo {
Lines changed: 11 additions & 0 deletions
Loading

packages/neuron-ui/src/widgets/Icons/icon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import DAOWithdrawalSvg from './DAOWithdrawal.svg?react'
6868
import RecycleSvg from './Recycle.svg?react'
6969
import MoreSvg from './More.svg?react'
7070
import RegenerateSvg from './Regenerate.svg?react'
71+
import LockCodeHashSvg from './LockCodeHash.svg?react'
7172

7273
import styles from './icon.module.scss'
7374

@@ -152,3 +153,4 @@ export const DAOWithdrawal = WrapSvg(DAOWithdrawalSvg)
152153
export const Recycle = WrapSvg(RecycleSvg)
153154
export const More = WrapSvg(MoreSvg)
154155
export const Regenerate = WrapSvg(RegenerateSvg)
156+
export const LockCodeHash = WrapSvg(LockCodeHashSvg)

packages/neuron-wallet/src/block-sync-renderer/sync/light-synchronizer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Multisig from '../../services/multisig'
1212
import SyncProgress, { SyncAddressType } from '../../database/chain/entities/sync-progress'
1313
import WalletService from '../../services/wallets'
1414
import AssetAccountInfo from '../../models/asset-account-info'
15+
import SystemScriptInfo from '../../models/system-script-info'
1516
import { DepType } from '../../models/chain/cell-dep'
1617
import { vector, blockchain } from '@ckb-lumos/lumos/codec'
1718
import type { Base } from '@ckb-lumos/lumos/rpc'
@@ -39,6 +40,9 @@ export default class LightSynchronizer extends Synchronizer {
3940

4041
private async getDepTxs(): Promise<string[]> {
4142
const assetAccountInfo = new AssetAccountInfo()
43+
const multiSignCellDep = await SystemScriptInfo.getInstance().getMultiSignCellDep(
44+
SystemScriptInfo.MULTISIG_CODE_HASH
45+
)
4246
const fetchCellDeps = [
4347
assetAccountInfo.anyoneCanPayCellDep,
4448
assetAccountInfo.sudtCellDep,
@@ -48,6 +52,8 @@ export default class LightSynchronizer extends Synchronizer {
4852
assetAccountInfo.getNftIssuerInfo().cellDep,
4953
assetAccountInfo.getLegacyAnyoneCanPayInfo().cellDep,
5054
assetAccountInfo.getChequeInfo().cellDep,
55+
multiSignCellDep,
56+
5157
...assetAccountInfo.getSporeInfos().map(info => info.cellDep),
5258
...assetAccountInfo.getSporeClusterInfo().map(info => info.cellDep),
5359
]

packages/neuron-wallet/src/controllers/multisig.ts

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ interface MultisigConfigItem {
2424
sighash_addresses: string[]
2525
require_first_n: number
2626
threshold: number
27-
alias?: string | string[]
28-
lockCodeHash: string | string[]
27+
alias?: string
28+
lockCodeHash: string
2929
}
3030

3131
interface MultisigConfigOutput {
3232
multisig_configs: Record<string, MultisigConfigItem>
3333
}
3434

3535
interface MultisigConfigInput {
36-
multisig_configs: Record<string, Omit<MultisigConfigItem, 'lockCodeHash'> & { lockCodeHash?: string | string[] }>
36+
multisig_configs: Record<string, Omit<MultisigConfigItem, 'lockCodeHash'> & { lockCodeHash?: string }>
3737
}
3838

3939
const validateImportConfig = (configOutput: MultisigConfigInput) => {
@@ -157,7 +157,7 @@ export default class MultisigController {
157157
}
158158
try {
159159
const json = fs.readFileSync(filePaths[0], 'utf-8')
160-
const configOutput: MultisigConfigInput = JSON.parse(json)
160+
const configOutput: MultisigConfigOutput = JSON.parse(json)
161161
if (!validateImportConfig(configOutput)) {
162162
ShowGlobalDialogSubject.next({
163163
type: 'failed',
@@ -166,40 +166,15 @@ export default class MultisigController {
166166
})
167167
return
168168
}
169-
const saveConfigs: {
170-
r: number
171-
m: number
172-
n: number
173-
blake160s: string[]
174-
walletId: string
175-
alias?: string
176-
lockCodeHash?: string
177-
}[] = []
178-
Object.values(configOutput.multisig_configs).forEach(config => {
179-
if (Array.isArray(config.lockCodeHash)) {
180-
config.lockCodeHash.forEach((lockCodeHash, index) => {
181-
saveConfigs.push({
182-
r: +config.require_first_n,
183-
m: +config.threshold,
184-
n: config.sighash_addresses.length,
185-
blake160s: config.sighash_addresses.map(v => addressToScript(v).args),
186-
walletId,
187-
alias: config.alias?.[index],
188-
lockCodeHash,
189-
})
190-
})
191-
} else {
192-
saveConfigs.push({
193-
r: +config.require_first_n,
194-
m: +config.threshold,
195-
n: config.sighash_addresses.length,
196-
blake160s: config.sighash_addresses.map(v => addressToScript(v).args),
197-
walletId,
198-
alias: config.alias as string,
199-
lockCodeHash: config.lockCodeHash,
200-
})
201-
}
202-
})
169+
const saveConfigs = Object.values(configOutput.multisig_configs).map(config => ({
170+
r: +config.require_first_n,
171+
m: +config.threshold,
172+
n: config.sighash_addresses.length,
173+
blake160s: config.sighash_addresses.map(v => addressToScript(v).args),
174+
walletId,
175+
alias: config.alias,
176+
lockCodeHash: config.lockCodeHash,
177+
}))
203178
const savedResult = await Promise.allSettled(saveConfigs.map(config => this.saveConfig(config)))
204179
const saveSuccessConfigs: MultisigConfig[] = []
205180
for (let idx = 0; idx < savedResult.length; idx++) {
@@ -251,27 +226,14 @@ export default class MultisigController {
251226
const isMainnet = NetworksService.getInstance().isMainnet()
252227
const output: MultisigConfigOutput = { multisig_configs: {} }
253228
configs.forEach(v => {
254-
const hash = Multisig.hash(v.blake160s, v.r, v.m, v.n)
255-
if (output.multisig_configs[hash]) {
256-
const existingLockCodeHash = output.multisig_configs[hash].lockCodeHash
257-
output.multisig_configs[hash].lockCodeHash = Array.isArray(existingLockCodeHash)
258-
? [...existingLockCodeHash, v.lockCodeHash]
259-
: [existingLockCodeHash, v.lockCodeHash]
260-
261-
const existingAlias = output.multisig_configs[hash].alias || ''
262-
output.multisig_configs[hash].alias = Array.isArray(existingAlias)
263-
? [...existingAlias, v.alias || '']
264-
: [existingAlias, v.alias || '']
265-
} else {
266-
output.multisig_configs[hash] = {
267-
sighash_addresses: v.blake160s.map(args =>
268-
scriptToAddress(SystemScriptInfo.generateSecpScript(args), isMainnet)
269-
),
270-
require_first_n: v.r,
271-
threshold: v.m,
272-
lockCodeHash: v.lockCodeHash,
273-
alias: v.alias,
274-
}
229+
output.multisig_configs[`${Multisig.hash(v.blake160s, v.r, v.m, v.n)}_${v.lockCodeHash.slice(2, 10)}`] = {
230+
sighash_addresses: v.blake160s.map(args =>
231+
scriptToAddress(SystemScriptInfo.generateSecpScript(args), isMainnet)
232+
),
233+
require_first_n: v.r,
234+
threshold: v.m,
235+
alias: v.alias,
236+
lockCodeHash: v.lockCodeHash,
275237
}
276238
})
277239

packages/neuron-wallet/src/models/system-script-info.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default class SystemScriptInfo {
1515

1616
static SECP_HASH_TYPE = ScriptHashType.Type
1717
static DAO_HASH_TYPE = ScriptHashType.Type
18-
static LEGACY_MULTI_SIGN_HASH_TYPE = ScriptHashType.Type
19-
static MULTI_SIGN_HASH_TYPE = ScriptHashType.Data1
18+
static LEGACY_MULTISIGN_HASH_TYPE = ScriptHashType.Type
19+
static MULTISIGN_HASH_TYPE = ScriptHashType.Data1
2020

2121
static DAO_SCRIPT_HASH = new Script(
2222
systemScripts.DAO.CODE_HASH,
@@ -41,11 +41,12 @@ export default class SystemScriptInfo {
4141
private legacyMultiSignOutPointInfo = new Map<string, OutPoint>()
4242
private multiSignOutPointInfo = new Map<string, OutPoint>()
4343

44-
public static getMultiSignHashType(lockCodeHash: string): ScriptHashType {
45-
if (lockCodeHash === SystemScriptInfo.MULTISIG_CODE_HASH) {
46-
return SystemScriptInfo.MULTI_SIGN_HASH_TYPE
44+
public static getMultiSignHashType(lockCodeHash: string) {
45+
if (!SystemScriptInfo.isMultiSignCodeHash(lockCodeHash)) {
46+
throw new Error('Unknown Multisig Code Hash')
4747
}
48-
return SystemScriptInfo.LEGACY_MULTI_SIGN_HASH_TYPE
48+
if (lockCodeHash === SystemScriptInfo.MULTISIG_CODE_HASH) return SystemScriptInfo.MULTISIGN_HASH_TYPE
49+
if (lockCodeHash === SystemScriptInfo.LEGACY_MULTISIG_CODE_HASH) return SystemScriptInfo.LEGACY_MULTISIGN_HASH_TYPE
4950
}
5051

5152
// need network url and genesisBlockHash
@@ -105,7 +106,7 @@ export default class SystemScriptInfo {
105106
}
106107

107108
public static generateMultiSignScript(args: string, lockCodeHash: string): Script {
108-
return new Script(lockCodeHash, args, SystemScriptInfo.getMultiSignHashType(lockCodeHash))
109+
return new Script(lockCodeHash, args, SystemScriptInfo.getMultiSignHashType(lockCodeHash) as ScriptHashType)
109110
}
110111

111112
public static isSecpScript(script: Script): boolean {
@@ -119,9 +120,9 @@ export default class SystemScriptInfo {
119120
public static isMultiSignScript(script: Script): boolean {
120121
return (
121122
(script.codeHash === SystemScriptInfo.LEGACY_MULTISIG_CODE_HASH &&
122-
script.hashType === SystemScriptInfo.LEGACY_MULTI_SIGN_HASH_TYPE) ||
123+
script.hashType === SystemScriptInfo.LEGACY_MULTISIGN_HASH_TYPE) ||
123124
(script.codeHash === SystemScriptInfo.MULTISIG_CODE_HASH &&
124-
script.hashType === SystemScriptInfo.MULTI_SIGN_HASH_TYPE)
125+
script.hashType === SystemScriptInfo.MULTISIGN_HASH_TYPE)
125126
)
126127
}
127128

0 commit comments

Comments
 (0)