Skip to content

Commit 0cb9a1d

Browse files
authored
feat(neuron-ui): display address field of input on the transaction de… (#987)
* feat(neuron-ui): display address field of input on the transaction detail view * fix(neuron-ui): fix the typo of cellbase
1 parent e137598 commit 0cb9a1d

5 files changed

Lines changed: 66 additions & 39 deletions

File tree

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

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ import { explorerNavButton } from './style.module.scss'
1313

1414
const MIN_CELL_WIDTH = 70
1515

16+
const CompactAddress = ({ address }: { address: string }) => (
17+
<div
18+
title={address}
19+
style={{
20+
overflow: 'hidden',
21+
display: 'flex',
22+
}}
23+
className="monospacedFont"
24+
>
25+
<span className="textOverflow">{address.slice(0, -6)}</span>
26+
<span>{address.slice(-6)}</span>
27+
</div>
28+
)
29+
1630
const Transaction = () => {
1731
const [t] = useTranslation()
1832
const [transaction, setTransaction] = useState(transactionState)
@@ -27,25 +41,42 @@ const Transaction = () => {
2741
name: t('transaction.index'),
2842
minWidth: 60,
2943
maxWidth: 60,
30-
onRender: (_item?: any, index?: number) => {
44+
onRender: (_input?: State.DetailedInput, index?: number) => {
3145
if (undefined !== index) {
3246
return index
3347
}
3448
return null
3549
},
3650
},
3751
{
38-
key: 'outPointCell',
39-
name: 'OutPoint Cell',
40-
minWidth: 150,
41-
maxWidth: 600,
42-
onRender: (item: any) => {
43-
const text = item.previousOutput ? `${item.previousOutput.txHash}[${item.previousOutput.index}]` : 'none'
44-
return (
45-
<span title={text} className="textOverflow">
46-
{text}
47-
</span>
48-
)
52+
key: 'address',
53+
name: t('transaction.address'),
54+
minWidth: 200,
55+
maxWidth: 500,
56+
onRender: (input?: State.DetailedInput, _index?: number, column?: IColumn) => {
57+
if (!input) {
58+
return null
59+
}
60+
if (!input.lock) {
61+
return t('transaction.cell-from-cellbase')
62+
}
63+
try {
64+
const address = ckbCore.utils.bech32Address(input.lock.args, {
65+
prefix: addressPrefix,
66+
type: ckbCore.utils.AddressType.HashIdx,
67+
codeHashIndex: '0x00',
68+
})
69+
if (column && (column.calculatedWidth || 0) < 450) {
70+
return <CompactAddress address={address} />
71+
}
72+
return (
73+
<span title={address} className="monospacedFont">
74+
{address}
75+
</span>
76+
)
77+
} catch {
78+
return null
79+
}
4980
},
5081
},
5182
{
@@ -67,7 +98,7 @@ const Transaction = () => {
6798
...col,
6899
})
69100
),
70-
[t]
101+
[addressPrefix, t]
71102
)
72103

73104
const outputColumns: IColumn[] = useMemo(
@@ -101,19 +132,7 @@ const Transaction = () => {
101132
codeHashIndex: '0x00',
102133
})
103134
if (column && (column.calculatedWidth || 0) < 450) {
104-
return (
105-
<div
106-
title={address}
107-
style={{
108-
overflow: 'hidden',
109-
display: 'flex',
110-
}}
111-
className="monospacedFont"
112-
>
113-
<span className="textOverflow">{address.slice(0, -6)}</span>
114-
<span>{address.slice(-6)}</span>
115-
</div>
116-
)
135+
return <CompactAddress address={address} />
117136
}
118137
return (
119138
<span title={address} className="monospacedFont">

packages/neuron-ui/src/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@
150150
"inputs": "Inputs",
151151
"outputs": "Outputs",
152152
"view-in-explorer": "Explorer",
153-
"view-in-explorer-button-title": "View on explorer"
153+
"view-in-explorer-button-title": "View on explorer",
154+
"cell-from-cellbase": "From cellbase"
154155
},
155156
"addresses": {
156157
"addresses": "Addresses",

packages/neuron-ui/src/locales/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@
150150
"inputs": "输入",
151151
"outputs": "输出",
152152
"view-in-explorer": "浏览器",
153-
"view-in-explorer-button-title": "浏览器中查看详情"
153+
"view-in-explorer-button-title": "浏览器中查看详情",
154+
"cell-from-cellbase": "来自 Cellbase"
154155
},
155156
"addresses": {
156157
"addresses": "地址",

packages/neuron-ui/src/types/App/index.d.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ declare namespace State {
1111
status: 'pending' | 'success' | 'failed'
1212
}
1313

14+
interface DetailedInput {
15+
capacity: string | null
16+
lockHash: string | null
17+
previousOutput: {
18+
blockHash: string | null
19+
cell: {
20+
txHash: string
21+
index: string
22+
} | null
23+
}
24+
lock: CKBComponents.Script | null
25+
}
26+
1427
interface DetailedOutput {
1528
capacity: string
1629
lock: {
@@ -27,17 +40,7 @@ declare namespace State {
2740
blockHash: string
2841
blockNumber: string
2942
deps: any[]
30-
inputs: {
31-
capacity: string | null
32-
lockHash: string | null
33-
previousOutput: {
34-
blockHash: string | null
35-
cell: {
36-
txHash: string
37-
index: string
38-
} | null
39-
}
40-
}[]
43+
inputs: DetailedInput[]
4144
inputsCount: string
4245
outputs: DetailedOutput[]
4346
outputsCount: string

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ export const shannonToCKBFormatter = (shannon: string = '0', showPositiveSign?:
102102
console.warn(`Shannon is not a valid number`)
103103
return shannon
104104
}
105+
if (shannon === null) {
106+
return '0'
107+
}
105108
let sign = ''
106109
if (shannon.startsWith('-')) {
107110
sign = '-'

0 commit comments

Comments
 (0)