Skip to content

Commit

Permalink
feat: Consolidate Cells (nervosnetwork#3167)
Browse files Browse the repository at this point in the history
  • Loading branch information
devchenyan authored Jun 6, 2024
1 parent 24624ee commit ee2fa9b
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $noticeHeight: 60px;
.left {
flex: 1;
position: relative;
min-width: 480px;

.addressCell {
margin-bottom: 10px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $noticeHeight: 60px;
.left {
flex: 1;
position: relative;
min-width: 480px;

.addressCell {
margin-bottom: 10px;
Expand Down
29 changes: 25 additions & 4 deletions packages/neuron-ui/src/components/CellManagement/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export enum Actions {
Lock = 'lock',
Unlock = 'unlock',
Consume = 'consume',
Consolidate = 'consolidate',
}

export const useAction = ({
Expand All @@ -213,6 +214,7 @@ export const useAction = ({
setError,
password,
verifyDeviceStatus,
wallet,
}: {
liveCells: State.LiveCellWithLocalInfo[]
currentPageLiveCells: State.LiveCellWithLocalInfo[]
Expand All @@ -222,6 +224,7 @@ export const useAction = ({
setError: (error: string) => void
password: string
verifyDeviceStatus: () => Promise<boolean>
wallet: State.Wallet
}) => {
const dispatch = useDispatch()
const navigate = useNavigate()
Expand Down Expand Up @@ -253,10 +256,21 @@ export const useAction = ({
},
[liveCells, selectedOutPoints, setOperateCells, dispatch, navigate]
)

const getConsolidateAddress = useCallback(() => {
const { addresses } = wallet
if (addresses.length === 1) {
return addresses[0].address
}
const unusedReceiveAddress = addresses.find(a => a.type === 0 && a.txCount === 0)?.address ?? ''

return unusedReceiveAddress
}, [wallet])

const onActionConfirm = useCallback(async () => {
switch (action) {
case 'lock':
case 'unlock':
case Actions.Lock:
case Actions.Unlock:
if (!(await verifyDeviceStatus())) return
setLoading(true)
updateLiveCellsLockStatus({
Expand All @@ -276,17 +290,24 @@ export const useAction = ({
setLoading(false)
})
break
case 'consume':
case Actions.Consume:
dispatch({
type: AppActions.UpdateConsumeCells,
payload: operateCells.map(v => ({ outPoint: v.outPoint, capacity: v.capacity })),
})
navigate(`${RoutePath.Send}?isSendMax=true`)
break
case Actions.Consolidate:
dispatch({
type: AppActions.UpdateConsumeCells,
payload: operateCells.map(v => ({ outPoint: v.outPoint, capacity: v.capacity })),
})
navigate(`${RoutePath.Send}?isSendMax=true&toAddress=${getConsolidateAddress()}`)
break
default:
break
}
}, [action, operateCells, dispatch, navigate, password])
}, [action, operateCells, dispatch, navigate, password, getConsolidateAddress])
const onActionCancel = useCallback(() => {
setAction(undefined)
setOperateCells([])
Expand Down
16 changes: 15 additions & 1 deletion packages/neuron-ui/src/components/CellManagement/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useMemo, useState } from 'react'
import { Attention, Consume, DetailIcon, EyesClose, EyesOpen, LockCell, UnLock } from 'widgets/Icons/icon'
import { Attention, Consume, DetailIcon, EyesClose, EyesOpen, LockCell, UnLock, Consolidate } from 'widgets/Icons/icon'
import PageContainer from 'components/PageContainer'
import { useTranslation } from 'react-i18next'
import Breadcrum from 'widgets/Breadcrum'
Expand Down Expand Up @@ -273,6 +273,7 @@ const CellManagement = () => {
resetPassword,
password,
verifyDeviceStatus,
wallet,
})
const columns = useMemo(
() =>
Expand Down Expand Up @@ -339,6 +340,10 @@ const CellManagement = () => {
<Consume />
{t('cell-manage.consume')}
</button>
<button type="button" disabled={hasSelectLocked} onClick={onMultiAction} data-action={Actions.Consolidate}>
<Consolidate />
{t('cell-manage.consolidate')}
</button>
</div>
) : null}
</div>
Expand Down Expand Up @@ -440,6 +445,15 @@ const CellManagement = () => {
>
<span className={styles.consumeNotice}>{t('cell-manage.cell-consume-dialog.warn-consume')}</span>
</Dialog>
<Dialog
show={action === Actions.Consolidate}
title={t('cell-manage.cell-consolidate-dialog.title')}
onCancel={onActionCancel}
onConfirm={onActionConfirm}
confirmText={t('cell-manage.consolidate')}
>
<span className={styles.consumeNotice}>{t('cell-manage.cell-consolidate-dialog.warn-consume')}</span>
</Dialog>
</PageContainer>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ $right-min-width: 476px;

.left {
flex: 1;
min-width: 480px;
position: relative;
max-width: calc(100% - $right-min-width);

Expand Down
6 changes: 5 additions & 1 deletion packages/neuron-ui/src/components/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ const Send = () => {
if (searchParams.get('isSendMax')) {
updateIsSendMax(true)
}
const toAddress = searchParams.get('toAddress')
if (toAddress) {
updateTransactionOutput('address')(0)(toAddress)
}
// only when router change init send max
}, [searchParams, updateIsSendMax])
}, [searchParams, updateIsSendMax, updateTransactionOutput])

const [locktimeIndex, setLocktimeIndex] = useState<number>(-1)

Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/components/Send/send.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $noticeHeight: 60px;
.left {
flex: 1;
position: relative;
min-width: 480px;

.leftFooter {
position: absolute;
Expand Down
7 changes: 6 additions & 1 deletion packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1271,12 +1271,17 @@
"title": "Consume Cell",
"warn-consume": "Consume cell will not keep any data and use all of the ckb, please ensure that no important data needs to be retained"
},
"cell-consolidate-dialog": {
"title": "Consolidate Cells",
"warn-consume": "All selected cells will be consolidated into a new cell, make sure that selected cells do not contain important data."
},
"enter-password": "Enter Password",
"password-placeholder": "Please input wallet password",
"lock": "Lock",
"unlock": "Unlock",
"consume": "Consume",
"verify": "Verify"
"verify": "Verify",
"consolidate": "Consolidate"
},
"send-tx-detail": {
"page-title": "Transaction Detail",
Expand Down
7 changes: 6 additions & 1 deletion packages/neuron-ui/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1251,12 +1251,17 @@
"title": "Consumir Cell",
"warn-consume": "Al consumir la Cell, no se retendrá ningún dato y se utilizará todo el ckb, asegúrese de que no haya datos importantes que necesiten ser retenidos"
},
"cell-consolidate-dialog": {
"title": "Consolidar",
"warn-consume": "Todas las celdas seleccionadas se consolidarán en una nueva celda, asegúrese de que las celdas seleccionadas no contienen datos importantes."
},
"enter-password": "Ingresar Contraseña",
"password-placeholder": "Ingrese la contraseña de la billetera",
"lock": "Bloquear",
"unlock": "Desbloquear",
"consume": "Consumir",
"verify": "Verificar"
"verify": "Verificar",
"consolidate": "Consolidar"
},
"send-tx-detail": {
"page-title": "Detalles de la transacción",
Expand Down
7 changes: 6 additions & 1 deletion packages/neuron-ui/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1261,12 +1261,17 @@
"title": "Consommer la cellule",
"warn-consume": "La consommation de la cellule ne conservera aucune donnée et utilisera tout le CKB. Veuillez vous assurer qu'aucune donnée importante ne doit être conservée."
},
"cell-consolidate-dialog": {
"title": "Consolider",
"warn-consume": "Toutes les cellules sélectionnées seront consolidées dans une nouvelle cellule. Assurez-vous que les cellules sélectionnées ne contiennent pas de données importantes."
},
"enter-password": "Entrez le mot de passe",
"password-placeholder": "Veuillez entrer le mot de passe du Wallet",
"lock": "Verrouiller",
"unlock": "Déverrouiller",
"consume": "Consommer",
"verify": "Vérifier"
"verify": "Vérifier",
"consolidate": "Consolider"
},
"send-tx-detail": {
"page-title": "Détail de l'historique",
Expand Down
7 changes: 6 additions & 1 deletion packages/neuron-ui/src/locales/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -1260,12 +1260,17 @@
"title": "消耗 Cell",
"warn-consume": "消耗Cell不會保留任何數據,並將花費全部的CKB,請確保沒有重要數據需要保留。"
},
"cell-consolidate-dialog": {
"title": "合並",
"warn-consume": "所有選中的Cell都將合並到一個新Cell中,請確保沒有重要數據需要保留。"
},
"enter-password": "輸入密碼",
"password-placeholder": "請輸入錢包密碼",
"lock": "鎖定",
"unlock": "解鎖",
"consume": "消耗",
"verify": "驗證"
"verify": "驗證",
"consolidate": "合並"
},
"send-tx-detail": {
"page-title": "交易詳情",
Expand Down
7 changes: 6 additions & 1 deletion packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1263,12 +1263,17 @@
"title": "消耗 Cell",
"warn-consume": "消耗Cell不会保留任何数据,并将花费全部的CKB,请确保没有重要数据需要保留。"
},
"cell-consolidate-dialog": {
"title": "合并 Cells",
"warn-consume": "所有选中的Cell都将合并到一个新Cell中,请确保没有重要数据需要保留。"
},
"enter-password": "输入密码",
"password-placeholder": "请输入钱包密码",
"lock": "锁定",
"unlock": "解锁",
"consume": "消耗",
"verify": "验证"
"verify": "验证",
"consolidate": "合并"
},
"send-tx-detail": {
"page-title": "交易详情",
Expand Down
4 changes: 4 additions & 0 deletions packages/neuron-ui/src/widgets/Icons/Consolidate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/neuron-ui/src/widgets/Icons/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { ReactComponent as LockSvg } from './Lock.svg'
import { ReactComponent as LockCellSvg } from './LockCell.svg'
import { ReactComponent as UnLockSvg } from './Unlock.svg'
import { ReactComponent as ConsumeSvg } from './Consume.svg'
import { ReactComponent as ConsolidateSvg } from './Consolidate.svg'
import { ReactComponent as DetectSvg } from './Detect.svg'
import { ReactComponent as DeleteSvg } from './Delete.svg'
import { ReactComponent as ImportKeystoreSvg } from './SoftWalletImportKeystore.svg'
Expand Down Expand Up @@ -129,6 +130,7 @@ export const Lock = WrapSvg(LockSvg, styles.withTheme)
export const LockCell = WrapSvg(LockCellSvg)
export const UnLock = WrapSvg(UnLockSvg)
export const Consume = WrapSvg(ConsumeSvg)
export const Consolidate = WrapSvg(ConsolidateSvg)
export const Detect = WrapSvg(DetectSvg)
export const Delete = WrapSvg(DeleteSvg)
export const ImportKeystore = WrapSvg(ImportKeystoreSvg)
Expand Down

0 comments on commit ee2fa9b

Please sign in to comment.