From ee2fa9b40221507f4dc204a70d307684129e62b8 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Thu, 6 Jun 2024 10:48:48 +0800 Subject: [PATCH] feat: Consolidate Cells (#3167) --- .../AmendSUDTSend/amendSUDTSend.module.scss | 1 + .../AmendSend/amendSend.module.scss | 1 + .../src/components/CellManagement/hooks.ts | 29 ++++++++++++++++--- .../src/components/CellManagement/index.tsx | 16 +++++++++- .../components/SUDTSend/sUDTSend.module.scss | 1 + .../neuron-ui/src/components/Send/index.tsx | 6 +++- .../src/components/Send/send.module.scss | 1 + packages/neuron-ui/src/locales/en.json | 7 ++++- packages/neuron-ui/src/locales/es.json | 7 ++++- packages/neuron-ui/src/locales/fr.json | 7 ++++- packages/neuron-ui/src/locales/zh-tw.json | 7 ++++- packages/neuron-ui/src/locales/zh.json | 7 ++++- .../src/widgets/Icons/Consolidate.svg | 4 +++ packages/neuron-ui/src/widgets/Icons/icon.tsx | 2 ++ 14 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 packages/neuron-ui/src/widgets/Icons/Consolidate.svg diff --git a/packages/neuron-ui/src/components/AmendSUDTSend/amendSUDTSend.module.scss b/packages/neuron-ui/src/components/AmendSUDTSend/amendSUDTSend.module.scss index 2ef4fcb512..8194ab6031 100644 --- a/packages/neuron-ui/src/components/AmendSUDTSend/amendSUDTSend.module.scss +++ b/packages/neuron-ui/src/components/AmendSUDTSend/amendSUDTSend.module.scss @@ -9,6 +9,7 @@ $noticeHeight: 60px; .left { flex: 1; position: relative; + min-width: 480px; .addressCell { margin-bottom: 10px; diff --git a/packages/neuron-ui/src/components/AmendSend/amendSend.module.scss b/packages/neuron-ui/src/components/AmendSend/amendSend.module.scss index 58bd47f31f..0b823d03ec 100644 --- a/packages/neuron-ui/src/components/AmendSend/amendSend.module.scss +++ b/packages/neuron-ui/src/components/AmendSend/amendSend.module.scss @@ -9,6 +9,7 @@ $noticeHeight: 60px; .left { flex: 1; position: relative; + min-width: 480px; .addressCell { margin-bottom: 10px; diff --git a/packages/neuron-ui/src/components/CellManagement/hooks.ts b/packages/neuron-ui/src/components/CellManagement/hooks.ts index e38c6cec29..f0a746c5cb 100644 --- a/packages/neuron-ui/src/components/CellManagement/hooks.ts +++ b/packages/neuron-ui/src/components/CellManagement/hooks.ts @@ -202,6 +202,7 @@ export enum Actions { Lock = 'lock', Unlock = 'unlock', Consume = 'consume', + Consolidate = 'consolidate', } export const useAction = ({ @@ -213,6 +214,7 @@ export const useAction = ({ setError, password, verifyDeviceStatus, + wallet, }: { liveCells: State.LiveCellWithLocalInfo[] currentPageLiveCells: State.LiveCellWithLocalInfo[] @@ -222,6 +224,7 @@ export const useAction = ({ setError: (error: string) => void password: string verifyDeviceStatus: () => Promise + wallet: State.Wallet }) => { const dispatch = useDispatch() const navigate = useNavigate() @@ -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({ @@ -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([]) diff --git a/packages/neuron-ui/src/components/CellManagement/index.tsx b/packages/neuron-ui/src/components/CellManagement/index.tsx index 9aa8edd84b..186e884d6a 100644 --- a/packages/neuron-ui/src/components/CellManagement/index.tsx +++ b/packages/neuron-ui/src/components/CellManagement/index.tsx @@ -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' @@ -273,6 +273,7 @@ const CellManagement = () => { resetPassword, password, verifyDeviceStatus, + wallet, }) const columns = useMemo( () => @@ -339,6 +340,10 @@ const CellManagement = () => { {t('cell-manage.consume')} + ) : null} @@ -440,6 +445,15 @@ const CellManagement = () => { > {t('cell-manage.cell-consume-dialog.warn-consume')} + + {t('cell-manage.cell-consolidate-dialog.warn-consume')} + ) } diff --git a/packages/neuron-ui/src/components/SUDTSend/sUDTSend.module.scss b/packages/neuron-ui/src/components/SUDTSend/sUDTSend.module.scss index 0df08c4cff..faf2e957f4 100644 --- a/packages/neuron-ui/src/components/SUDTSend/sUDTSend.module.scss +++ b/packages/neuron-ui/src/components/SUDTSend/sUDTSend.module.scss @@ -27,6 +27,7 @@ $right-min-width: 476px; .left { flex: 1; + min-width: 480px; position: relative; max-width: calc(100% - $right-min-width); diff --git a/packages/neuron-ui/src/components/Send/index.tsx b/packages/neuron-ui/src/components/Send/index.tsx index c6c7a5563a..bd07c07473 100644 --- a/packages/neuron-ui/src/components/Send/index.tsx +++ b/packages/neuron-ui/src/components/Send/index.tsx @@ -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(-1) diff --git a/packages/neuron-ui/src/components/Send/send.module.scss b/packages/neuron-ui/src/components/Send/send.module.scss index cd0952d1e1..2bdcde3830 100644 --- a/packages/neuron-ui/src/components/Send/send.module.scss +++ b/packages/neuron-ui/src/components/Send/send.module.scss @@ -9,6 +9,7 @@ $noticeHeight: 60px; .left { flex: 1; position: relative; + min-width: 480px; .leftFooter { position: absolute; diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index e8100aea72..ad0395e53d 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -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", diff --git a/packages/neuron-ui/src/locales/es.json b/packages/neuron-ui/src/locales/es.json index 8bcdc744d4..a032e20bec 100644 --- a/packages/neuron-ui/src/locales/es.json +++ b/packages/neuron-ui/src/locales/es.json @@ -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", diff --git a/packages/neuron-ui/src/locales/fr.json b/packages/neuron-ui/src/locales/fr.json index bc59c94a4c..e38beafccc 100644 --- a/packages/neuron-ui/src/locales/fr.json +++ b/packages/neuron-ui/src/locales/fr.json @@ -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", diff --git a/packages/neuron-ui/src/locales/zh-tw.json b/packages/neuron-ui/src/locales/zh-tw.json index 193bd9f94e..712e024b59 100644 --- a/packages/neuron-ui/src/locales/zh-tw.json +++ b/packages/neuron-ui/src/locales/zh-tw.json @@ -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": "交易詳情", diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 58d5d508ba..b181a569f6 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -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": "交易详情", diff --git a/packages/neuron-ui/src/widgets/Icons/Consolidate.svg b/packages/neuron-ui/src/widgets/Icons/Consolidate.svg new file mode 100644 index 0000000000..824e415519 --- /dev/null +++ b/packages/neuron-ui/src/widgets/Icons/Consolidate.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/neuron-ui/src/widgets/Icons/icon.tsx b/packages/neuron-ui/src/widgets/Icons/icon.tsx index 18ede963d1..21eabcb23a 100644 --- a/packages/neuron-ui/src/widgets/Icons/icon.tsx +++ b/packages/neuron-ui/src/widgets/Icons/icon.tsx @@ -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' @@ -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)