Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Exception on checking addresses #3216

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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é.",
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@
"308": "餘額不足",
"309": "收款人需要升級資產賬戶才能繼續接收轉賬。",
"310": "請輸入 {{tagName}} 地址",
"311": "請輸入地址",
"402": "CKB 應用未打開。請在妳的設備打開 CKB 應用。",
"403": "未檢測到設備,請檢查妳的設備連接",
"404": "檢測到多個設備,同一型號的設備只能同時連接一個。",
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@
"308": "余额不足",
"309": "收款人需要升级资产账户才能继续接收转账。",
"310": "请输入 {{tagName}} 地址",
"311": "请输入地址",
"402": "CKB 应用未打开。请在你的设备打开 CKB 应用。",
"403": "未检测到设备,请检查你的设备连接",
"404": "检查到多个设备,同一型号的设备只能同时连接一个。",
Expand Down
5 changes: 5 additions & 0 deletions packages/neuron-wallet/src/controllers/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TestnetAddressRequired,
UnsupportedCkbCliKeystore,
DuplicateImportWallet,
AddressRequired,
} from '../exceptions'
import AddressService from '../services/addresses'
import TransactionSender from '../services/transaction-sender'
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions packages/neuron-wallet/src/exceptions/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
1 change: 1 addition & 0 deletions packages/neuron-wallet/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-wallet/src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-wallet/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-wallet/src/locales/zh-tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-wallet/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/services/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/tests/services/cells.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down