11import 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'
313import PageContainer from 'components/PageContainer'
414import { useTranslation } from 'react-i18next'
515import Breadcrum from 'widgets/Breadcrum'
@@ -14,6 +24,8 @@ import {
1424 LockScriptCategory ,
1525 getLockTimestamp ,
1626 isMainnet as isMainnetUtil ,
27+ TypeScriptCategory ,
28+ UDTType ,
1729} from 'utils'
1830import { HIDE_BALANCE } from 'utils/const'
1931import Tooltip from 'widgets/Tooltip'
@@ -27,6 +39,7 @@ import { computeScriptHash } from '@ckb-lumos/lumos/utils'
2739import Hardware from 'widgets/Icons/Hardware.png'
2840import Button from 'widgets/Button'
2941import Alert from 'widgets/Alert'
42+ import RecycleUDTCellDialog from 'components/RecycleUDTCellDialog'
3043import { Actions , useAction , useHardWallet , useLiveCells , usePassword , useSelect } from './hooks'
3144import 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