From f0b53875bb5ee57a74caac79d4d7eb7cc5b95ff2 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Fri, 2 Aug 2024 09:24:03 +0800 Subject: [PATCH] fix: Exception on checking addresses (#3216) * fix: Exception on checking addresses * fix: comment --------- Co-authored-by: Chen Yu --- packages/neuron-ui/src/locales/en.json | 3 ++- packages/neuron-ui/src/locales/es.json | 1 + packages/neuron-ui/src/locales/fr.json | 1 + packages/neuron-ui/src/locales/zh-tw.json | 1 + packages/neuron-ui/src/locales/zh.json | 1 + packages/neuron-wallet/src/controllers/wallets.ts | 5 +++++ packages/neuron-wallet/src/exceptions/address.ts | 8 ++++++++ packages/neuron-wallet/src/locales/en.ts | 1 + packages/neuron-wallet/src/locales/es.ts | 1 + packages/neuron-wallet/src/locales/fr.ts | 1 + packages/neuron-wallet/src/locales/zh-tw.ts | 1 + packages/neuron-wallet/src/locales/zh.ts | 1 + packages/neuron-wallet/src/services/cells.ts | 2 +- packages/neuron-wallet/tests/services/cells.test.ts | 2 +- 14 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index a403c2f639..e9e8e74d39 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -687,6 +687,7 @@ "308": "Amount is not enough", "309": "The receiver needs to upgrade her account address to accept more transfer.", "310": "Please enter a {{tagName}} address", + "311": "Please enter address", "402": "CKB App does not open. Please open the CKB App on your device.", "403": "No device detected. Please connect your device", "404": "Multiple device detected. Only one device of the same model can be connected.", @@ -1237,7 +1238,7 @@ }, "import-exist-xpubkey-dialog": { "replace-tip": "The watch-wallet has been imported before, would you replace it?", - "delete-tip": "The same original wallet existed. If you want to continue with the import, please delete it.." + "delete-tip": "The same original wallet existed. If you want to continue with the import, please delete it." } }, "cell-manage": { diff --git a/packages/neuron-ui/src/locales/es.json b/packages/neuron-ui/src/locales/es.json index 8078c667f2..77c7261a60 100644 --- a/packages/neuron-ui/src/locales/es.json +++ b/packages/neuron-ui/src/locales/es.json @@ -670,6 +670,7 @@ "308": "La cantidad no es suficiente", "309": "El destinatario debe actualizar la dirección de su cuenta para aceptar más transferencias.", "310": "Por favor introduzca una dirección {{tagName}}", + "311": "Por favor introduzca una dirección", "402": "La aplicación CKB no se abre. Abra la aplicación CKB en su dispositivo.", "403": "No se detectó ningún dispositivo. Por favor conecte su dispositivo", "404": "Se detectaron varios dispositivos. Sólo se puede conectar un dispositivo del mismo modelo.", diff --git a/packages/neuron-ui/src/locales/fr.json b/packages/neuron-ui/src/locales/fr.json index 87586f292f..28eedd730d 100644 --- a/packages/neuron-ui/src/locales/fr.json +++ b/packages/neuron-ui/src/locales/fr.json @@ -677,6 +677,7 @@ "308": "Le montant n'est pas suffisant", "309": "Le destinataire doit mettre à niveau son adresse de compte pour accepter davantage de transferts.", "310": "Veuillez entrer une adresse {{tagName}}", + "311": "Veuillez entrer une adresse", "402": "L'application CKB n'est pas ouverte. Veuillez ouvrir l'application CKB sur votre appareil.", "403": "Aucun appareil détecté. Veuillez connecter votre appareil", "404": "Plusieurs appareils détectés. Un seul appareil du même modèle peut être connecté.", diff --git a/packages/neuron-ui/src/locales/zh-tw.json b/packages/neuron-ui/src/locales/zh-tw.json index b630e971a6..8fa1bbc4e2 100644 --- a/packages/neuron-ui/src/locales/zh-tw.json +++ b/packages/neuron-ui/src/locales/zh-tw.json @@ -681,6 +681,7 @@ "308": "餘額不足", "309": "收款人需要升級資產賬戶才能繼續接收轉賬。", "310": "請輸入 {{tagName}} 地址", + "311": "請輸入地址", "402": "CKB 應用未打開。請在妳的設備打開 CKB 應用。", "403": "未檢測到設備,請檢查妳的設備連接", "404": "檢測到多個設備,同一型號的設備只能同時連接一個。", diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 5dcb60bf89..b6e0b16b36 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -680,6 +680,7 @@ "308": "余额不足", "309": "收款人需要升级资产账户才能继续接收转账。", "310": "请输入 {{tagName}} 地址", + "311": "请输入地址", "402": "CKB 应用未打开。请在你的设备打开 CKB 应用。", "403": "未检测到设备,请检查你的设备连接", "404": "检查到多个设备,同一型号的设备只能同时连接一个。", diff --git a/packages/neuron-wallet/src/controllers/wallets.ts b/packages/neuron-wallet/src/controllers/wallets.ts index b46d67b2ac..a47f3c2015 100644 --- a/packages/neuron-wallet/src/controllers/wallets.ts +++ b/packages/neuron-wallet/src/controllers/wallets.ts @@ -23,6 +23,7 @@ import { TestnetAddressRequired, UnsupportedCkbCliKeystore, DuplicateImportWallet, + AddressRequired, } from '../exceptions' import AddressService from '../services/addresses' import TransactionSender from '../services/transaction-sender' @@ -620,6 +621,10 @@ export default class WalletsController { private checkAddresses = (addresses: string[]) => { const isMainnet = NetworksService.getInstance().isMainnet() addresses.forEach(address => { + if (!address) { + throw new AddressRequired() + } + if (isMainnet && !address.startsWith('ckb')) { throw new MainnetAddressRequired(address) } diff --git a/packages/neuron-wallet/src/exceptions/address.ts b/packages/neuron-wallet/src/exceptions/address.ts index 5263214b63..080ce9d679 100644 --- a/packages/neuron-wallet/src/exceptions/address.ts +++ b/packages/neuron-wallet/src/exceptions/address.ts @@ -39,10 +39,18 @@ export class NoMatchAddressForSign extends Error { } } +export class AddressRequired extends Error { + public code = 311 + constructor() { + super(t('messages.address-required')) + } +} + export default { InvalidAddress, MainnetAddressRequired, TestnetAddressRequired, AddressNotFound, NoMatchAddressForSign, + AddressRequired, } diff --git a/packages/neuron-wallet/src/locales/en.ts b/packages/neuron-wallet/src/locales/en.ts index 6a7dad241b..fec1bc382c 100644 --- a/packages/neuron-wallet/src/locales/en.ts +++ b/packages/neuron-wallet/src/locales/en.ts @@ -141,6 +141,7 @@ export default { '{{path}} has no CKB Node config and storage, press confirm to synchronize from scratch', 'light-client-sudt-acp-error': "Light client mode doesn't support sending assets to other's asset account", 'could-not-connect-service': 'Could not connect to the service, please try again later.', + 'address-required': 'The address cannot be empty.', }, messageBox: { button: { diff --git a/packages/neuron-wallet/src/locales/es.ts b/packages/neuron-wallet/src/locales/es.ts index 001e571013..9d70452efd 100644 --- a/packages/neuron-wallet/src/locales/es.ts +++ b/packages/neuron-wallet/src/locales/es.ts @@ -143,6 +143,7 @@ export default { 'light-client-sudt-acp-error': 'El modo cliente ligero no admite el envío de activos a la cuenta de activos de otra persona', 'could-not-connect-service': 'No se pudo conectar al servicio, por favor, inténtalo nuevamente más tarde.', + 'address-required': 'La dirección no puede estar vacía.', }, messageBox: { button: { diff --git a/packages/neuron-wallet/src/locales/fr.ts b/packages/neuron-wallet/src/locales/fr.ts index bcc1a30316..58e11e3d3a 100644 --- a/packages/neuron-wallet/src/locales/fr.ts +++ b/packages/neuron-wallet/src/locales/fr.ts @@ -144,6 +144,7 @@ export default { "{{path}} n'a pas de configuration et de stockage de noeud CKB, appuyez sur Confirmer pour synchroniser à partir de zéro", 'light-client-sudt-acp-error': "Le mode client léger ne prend pas en charge l'envoi d'actifs vers le compte d'actifs d'autrui", + 'address-required': "L'adresse ne peut pas être vide.", }, messageBox: { button: { diff --git a/packages/neuron-wallet/src/locales/zh-tw.ts b/packages/neuron-wallet/src/locales/zh-tw.ts index a3c0d5c876..cc75c175f4 100644 --- a/packages/neuron-wallet/src/locales/zh-tw.ts +++ b/packages/neuron-wallet/src/locales/zh-tw.ts @@ -129,6 +129,7 @@ export default { 'no-exist-ckb-node-data': '{{path}} 目錄下沒有找到 CKB Node 配置和數據, 點擊確認重新同步', 'light-client-sudt-acp-error': '輕節點模式不支持發送資產給其他用戶的資產賬戶', 'could-not-connect-service': '無法連接到服務,請稍後再試。', + 'address-required': '地址不可為空', }, messageBox: { button: { diff --git a/packages/neuron-wallet/src/locales/zh.ts b/packages/neuron-wallet/src/locales/zh.ts index 77812478eb..5200e52497 100644 --- a/packages/neuron-wallet/src/locales/zh.ts +++ b/packages/neuron-wallet/src/locales/zh.ts @@ -130,6 +130,7 @@ export default { 'no-exist-ckb-node-data': '{{path}} 目录下没有找到 CKB Node 配置和数据, 点击确认重新同步', 'light-client-sudt-acp-error': '轻节点模式不支持发送资产给其他用户的资产账户', 'could-not-connect-service': '无法连接到服务,请稍后再试。', + 'address-required': '地址不可为空', }, messageBox: { button: { diff --git a/packages/neuron-wallet/src/services/cells.ts b/packages/neuron-wallet/src/services/cells.ts index 48c876e88d..04012b9d39 100644 --- a/packages/neuron-wallet/src/services/cells.ts +++ b/packages/neuron-wallet/src/services/cells.ts @@ -1420,7 +1420,7 @@ export default class CellsService { typeHashType: SystemScriptInfo.DAO_HASH_TYPE, }) .getMany() - if (!inputEntities.length) throw new Error(`No unlock transaction use ${unlockHash} as input`) + if (!inputEntities.length) throw new Error(`This is not an unlock dao transaction ${unlockHash}`) const inputPreviousTxHashes = inputEntities.map(v => v.outPointTxHash) const outputEntities = await getConnection() .getRepository(OutputEntity) diff --git a/packages/neuron-wallet/tests/services/cells.test.ts b/packages/neuron-wallet/tests/services/cells.test.ts index d2f7f90637..a50acacc32 100644 --- a/packages/neuron-wallet/tests/services/cells.test.ts +++ b/packages/neuron-wallet/tests/services/cells.test.ts @@ -1897,7 +1897,7 @@ describe('CellsService', () => { it('no input', async () => { const input = await saveTxAndInput() await expect(CellsService.getDaoWithdrawAndDeposit(input.transactionHash)).rejects.toThrow( - new Error(`No unlock transaction use ${input.transactionHash} as input`) + new Error(`This is not an unlock dao transaction ${input.transactionHash}`) ) }) it('can not find output', async () => {