Skip to content

Commit ecd4095

Browse files
authored
feat: Support UDT destruction (nervosnetwork#3323)
* feat: Support UDT destruction * feat: HardWallet * fix * fix: comments * fix: comments * fix: comments * fix: tests * fix * fix
1 parent 9be8e22 commit ecd4095

File tree

27 files changed

+833
-49
lines changed

27 files changed

+833
-49
lines changed

packages/neuron-ui/src/components/CellManagement/hooks.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,17 @@ export const useLiveCells = ({
145145
}
146146
return liveCells
147147
}, [sortInfo, liveCells])
148-
useEffect(() => {
148+
149+
const fetchLiveCells = useCallback(() => {
149150
getLiveCells().then(res => {
150151
if (isSuccessResponse(res) && res.result) {
151152
setLiveCells(res.result.map(v => ({ ...v, ...getLockStatusAndReason(v), cellType: getCellType(v) })))
152153
}
153154
})
155+
}, [setLiveCells])
156+
157+
useEffect(() => {
158+
fetchLiveCells()
154159
}, [])
155160

156161
const updateLiveCell = useCallback((params: State.UpdateLiveCellLocalInfo) => {
@@ -199,6 +204,7 @@ export const useLiveCells = ({
199204
onSorted,
200205
updateLiveCellsLockStatus,
201206
sortInfo,
207+
fetchLiveCells,
202208
}
203209
}
204210

@@ -208,6 +214,7 @@ export enum Actions {
208214
Unlock = 'unlock',
209215
Consume = 'consume',
210216
Consolidate = 'consolidate',
217+
Recycle = 'recycle',
211218
}
212219

213220
export const useAction = ({

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

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import React, { useCallback, useMemo, useState } from 'react'
2-
import { Attention, Consume, DetailIcon, EyesClose, EyesOpen, LockCell, UnLock, Consolidate } from 'widgets/Icons/icon'
2+
import {
3+
Attention,
4+
Consume,
5+
DetailIcon,
6+
EyesClose,
7+
EyesOpen,
8+
LockCell,
9+
UnLock,
10+
Consolidate,
11+
Recycle,
12+
} from 'widgets/Icons/icon'
313
import PageContainer from 'components/PageContainer'
414
import { useTranslation } from 'react-i18next'
515
import Breadcrum from 'widgets/Breadcrum'
@@ -14,6 +24,7 @@ import {
1424
LockScriptCategory,
1525
getLockTimestamp,
1626
isMainnet as isMainnetUtil,
27+
TypeScriptCategory,
1728
} from 'utils'
1829
import { HIDE_BALANCE } from 'utils/const'
1930
import Tooltip from 'widgets/Tooltip'
@@ -27,6 +38,7 @@ import { computeScriptHash } from '@ckb-lumos/lumos/utils'
2738
import Hardware from 'widgets/Icons/Hardware.png'
2839
import Button from 'widgets/Button'
2940
import Alert from 'widgets/Alert'
41+
import RecycleUDTCellDialog from 'components/RecycleUDTCellDialog'
3042
import { Actions, useAction, useHardWallet, useLiveCells, usePassword, useSelect } from './hooks'
3143
import styles from './cellManagement.module.scss'
3244

@@ -183,39 +195,51 @@ const getColumns = ({
183195
dataIndex: 'action',
184196
title: t('cell-manage.table.head.action'),
185197
render(_, index, item) {
186-
const { locked, lockedReason } = item
198+
const { locked, lockedReason, lockScriptType, typeScriptType } = item
199+
const showRecycleAction =
200+
lockScriptType === LockScriptCategory.ANYONE_CAN_PAY &&
201+
typeScriptType &&
202+
[TypeScriptCategory.SUDT, TypeScriptCategory.XUDT].includes(typeScriptType)
187203
return (
188204
<div className={styles.actions}>
189205
<Tooltip tip={t('history.detail')} showTriangle placement="top">
190206
<DetailIcon onClick={onAction} data-action={Actions.View} data-index={index} />
191207
</Tooltip>
192-
{locked ? (
193-
<Tooltip tip={t('cell-manage.unlock')} showTriangle placement="top">
194-
<UnLock
195-
data-disabled={!!lockedReason}
196-
onClick={lockedReason ? undefined : onAction}
197-
data-action={Actions.Unlock}
198-
data-index={index}
199-
/>
208+
{showRecycleAction ? (
209+
<Tooltip tip={t('cell-manage.recycle')} showTriangle placement="top">
210+
<Recycle onClick={onAction} data-action={Actions.Recycle} data-index={index} />
200211
</Tooltip>
201212
) : (
202-
<Tooltip tip={t('cell-manage.lock')} showTriangle placement="top">
203-
<LockCell
204-
data-disabled={!!lockedReason}
205-
onClick={lockedReason ? undefined : onAction}
206-
data-action={Actions.Lock}
207-
data-index={index}
208-
/>
209-
</Tooltip>
213+
<div className={styles.actions}>
214+
{locked ? (
215+
<Tooltip tip={t('cell-manage.unlock')} showTriangle placement="top">
216+
<UnLock
217+
data-disabled={!!lockedReason}
218+
onClick={lockedReason ? undefined : onAction}
219+
data-action={Actions.Unlock}
220+
data-index={index}
221+
/>
222+
</Tooltip>
223+
) : (
224+
<Tooltip tip={t('cell-manage.lock')} showTriangle placement="top">
225+
<LockCell
226+
data-disabled={!!lockedReason}
227+
onClick={lockedReason ? undefined : onAction}
228+
data-action={Actions.Lock}
229+
data-index={index}
230+
/>
231+
</Tooltip>
232+
)}
233+
<Tooltip tip={t('cell-manage.consume')} showTriangle placement="top">
234+
<Consume
235+
data-disabled={!!locked}
236+
onClick={locked ? undefined : onAction}
237+
data-action={Actions.Consume}
238+
data-index={index}
239+
/>
240+
</Tooltip>
241+
</div>
210242
)}
211-
<Tooltip tip={t('cell-manage.consume')} showTriangle placement="top">
212-
<Consume
213-
data-disabled={!!locked}
214-
onClick={locked ? undefined : onAction}
215-
data-action={Actions.Consume}
216-
data-index={index}
217-
/>
218-
</Tooltip>
219243
</div>
220244
)
221245
},
@@ -245,7 +269,9 @@ const CellManagement = () => {
245269
direction: SortType.Decrease,
246270
}
247271
: undefined
248-
const { liveCells, updateLiveCell, onSorted, updateLiveCellsLockStatus } = useLiveCells({ initSortInfo })
272+
const { liveCells, updateLiveCell, onSorted, updateLiveCellsLockStatus, fetchLiveCells } = useLiveCells({
273+
initSortInfo,
274+
})
249275
const { pageNo, pageSize, onPageChange } = usePagination()
250276
const currentPageLiveCells = useMemo(() => {
251277
return liveCells.slice(pageSize * (pageNo - 1), pageSize * pageNo)
@@ -363,6 +389,17 @@ const CellManagement = () => {
363389
onCancel={onActionCancel}
364390
isMainnet={isMainnet}
365391
/>
392+
{action === Actions.Recycle && operateCells[0] && (
393+
<RecycleUDTCellDialog
394+
data={{
395+
tokenID: operateCells[0].type.args,
396+
lockArgs: operateCells[0].lock.args,
397+
outpoint: operateCells[0].outPoint,
398+
}}
399+
onClose={onActionCancel}
400+
onConfirm={fetchLiveCells}
401+
/>
402+
)}
366403
{wallet.device ? (
367404
<Dialog
368405
show={action === Actions.Lock || action === Actions.Unlock}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export const FormattedTokenAmount = ({ item, show, symbolClassName }: FormattedT
5858
if (item.sudtInfo.sUDT.decimal) {
5959
sudtAmount = sUDTAmountFormatter(sudtValueToAmount(item.sudtInfo.amount, item.sudtInfo.sUDT.decimal))
6060
copyText = `${sudtValueToAmount(item.sudtInfo.amount, item.sudtInfo.sUDT.decimal)} ${item.sudtInfo.sUDT.symbol}`
61+
if (!sudtAmount.includes('-') && ['destroy', 'send'].includes(item.type)) {
62+
sudtAmount = `-${sudtAmount}`
63+
}
6164
isReceive = !sudtAmount.includes('-')
6265
}
6366
} else {

0 commit comments

Comments
 (0)