Skip to content

Commit fa5a711

Browse files
committed
feat: Support UDT destruction
1 parent 1ccb2d7 commit fa5a711

File tree

24 files changed

+641
-45
lines changed

24 files changed

+641
-45
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: 65 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,8 @@ import {
1424
LockScriptCategory,
1525
getLockTimestamp,
1626
isMainnet as isMainnetUtil,
27+
TypeScriptCategory,
28+
UDTType,
1729
} from 'utils'
1830
import { HIDE_BALANCE } from 'utils/const'
1931
import Tooltip from 'widgets/Tooltip'
@@ -27,6 +39,7 @@ import { computeScriptHash } from '@ckb-lumos/lumos/utils'
2739
import Hardware from 'widgets/Icons/Hardware.png'
2840
import Button from 'widgets/Button'
2941
import Alert from 'widgets/Alert'
42+
import RecycleUDTCellDialog from 'components/RecycleUDTCellDialog'
3043
import { Actions, useAction, useHardWallet, useLiveCells, usePassword, useSelect } from './hooks'
3144
import styles from './cellManagement.module.scss'
3245

@@ -183,39 +196,51 @@ const getColumns = ({
183196
dataIndex: 'action',
184197
title: t('cell-manage.table.head.action'),
185198
render(_, index, item) {
186-
const { locked, lockedReason } = item
199+
const { locked, lockedReason, lockScriptType, typeScriptType } = item
200+
const showRecycleAction =
201+
lockScriptType === LockScriptCategory.ANYONE_CAN_PAY &&
202+
typeScriptType &&
203+
[TypeScriptCategory.SUDT, TypeScriptCategory.XUDT].includes(typeScriptType)
187204
return (
188205
<div className={styles.actions}>
189206
<Tooltip tip={t('history.detail')} showTriangle placement="top">
190207
<DetailIcon onClick={onAction} data-action={Actions.View} data-index={index} />
191208
</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-
/>
209+
{showRecycleAction ? (
210+
<Tooltip tip={t('cell-manage.recycle')} showTriangle placement="top">
211+
<Recycle onClick={onAction} data-action={Actions.Recycle} data-index={index} />
200212
</Tooltip>
201213
) : (
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>
214+
<div className={styles.actions}>
215+
{locked ? (
216+
<Tooltip tip={t('cell-manage.unlock')} showTriangle placement="top">
217+
<UnLock
218+
data-disabled={!!lockedReason}
219+
onClick={lockedReason ? undefined : onAction}
220+
data-action={Actions.Unlock}
221+
data-index={index}
222+
/>
223+
</Tooltip>
224+
) : (
225+
<Tooltip tip={t('cell-manage.lock')} showTriangle placement="top">
226+
<LockCell
227+
data-disabled={!!lockedReason}
228+
onClick={lockedReason ? undefined : onAction}
229+
data-action={Actions.Lock}
230+
data-index={index}
231+
/>
232+
</Tooltip>
233+
)}
234+
<Tooltip tip={t('cell-manage.consume')} showTriangle placement="top">
235+
<Consume
236+
data-disabled={!!locked}
237+
onClick={locked ? undefined : onAction}
238+
data-action={Actions.Consume}
239+
data-index={index}
240+
/>
241+
</Tooltip>
242+
</div>
210243
)}
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>
219244
</div>
220245
)
221246
},
@@ -245,7 +270,9 @@ const CellManagement = () => {
245270
direction: SortType.Decrease,
246271
}
247272
: undefined
248-
const { liveCells, updateLiveCell, onSorted, updateLiveCellsLockStatus } = useLiveCells({ initSortInfo })
273+
const { liveCells, updateLiveCell, onSorted, updateLiveCellsLockStatus, fetchLiveCells } = useLiveCells({
274+
initSortInfo,
275+
})
249276
const { pageNo, pageSize, onPageChange } = usePagination()
250277
const currentPageLiveCells = useMemo(() => {
251278
return liveCells.slice(pageSize * (pageNo - 1), pageSize * pageNo)
@@ -363,6 +390,17 @@ const CellManagement = () => {
363390
onCancel={onActionCancel}
364391
isMainnet={isMainnet}
365392
/>
393+
{action === Actions.Recycle && operateCells[0] && (
394+
<RecycleUDTCellDialog
395+
data={{
396+
tokenID: operateCells[0].type.args,
397+
address: operateCells[0].lock.args,
398+
udtType: operateCells[0].typeScriptType === TypeScriptCategory.SUDT ? UDTType.SUDT : UDTType.XUDT,
399+
}}
400+
onClose={onActionCancel}
401+
onConfirm={fetchLiveCells}
402+
/>
403+
)}
366404
{wallet.device ? (
367405
<Dialog
368406
show={action === Actions.Lock || action === Actions.Unlock}

0 commit comments

Comments
 (0)