From a50f4145e1d7d814d6ccb36302d9e338afe8a0eb Mon Sep 17 00:00:00 2001 From: overtorment Date: Mon, 3 Jun 2024 22:51:38 +0100 Subject: [PATCH] REF: better error handling on BIP47 notification tx --- class/wallets/abstract-hd-electrum-wallet.ts | 10 +++++----- screen/wallets/PaymentCodesList.tsx | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/class/wallets/abstract-hd-electrum-wallet.ts b/class/wallets/abstract-hd-electrum-wallet.ts index f430c7e7a..bb731df05 100644 --- a/class/wallets/abstract-hd-electrum-wallet.ts +++ b/class/wallets/abstract-hd-electrum-wallet.ts @@ -1634,8 +1634,8 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { createBip47NotificationTransaction(utxos: CreateTransactionUtxo[], receiverPaymentCode: string, feeRate: number, changeAddress: string) { const aliceBip47 = BIP47Factory(ecc).fromBip39Seed(this.getSecret(), undefined, this.getPassphrase()); const bobBip47 = BIP47Factory(ecc).fromPaymentCode(receiverPaymentCode); - assert(utxos[0]); - assert(utxos[0].wif); + assert(utxos[0], 'No UTXO'); + assert(utxos[0].wif, 'No UTXO WIF'); // constructing targets: notification address, _dummy_ payload (+potential change might be added later) @@ -1662,7 +1662,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { false, 0, ); - assert(inputsTemp?.[0]?.wif); + assert(inputsTemp?.[0]?.wif, 'inputsTemp?.[0]?.wif assert failed'); // utxo selected. lets create op_return payload using the correct (first!) utxo and correct targets with that payload @@ -1701,8 +1701,8 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { false, 0, ); - assert(inputs && inputs[0] && inputs[0].wif); - assert(inputs[0].txid === inputsTemp[0].txid); // making sure that no funky business happened under the hood (its supposed to stay the same) + assert(inputs && inputs[0] && inputs[0].wif, 'inputs && inputs[0] && inputs[0].wif assert failed'); + assert(inputs[0].txid === inputsTemp[0].txid, 'inputs[0].txid === inputsTemp[0].txid assert failed'); // making sure that no funky business happened under the hood (its supposed to stay the same) return { tx, inputs, outputs, fee, psbt }; } diff --git a/screen/wallets/PaymentCodesList.tsx b/screen/wallets/PaymentCodesList.tsx index 6ef2f1020..8700d63ab 100644 --- a/screen/wallets/PaymentCodesList.tsx +++ b/screen/wallets/PaymentCodesList.tsx @@ -249,6 +249,11 @@ export default function PaymentCodesList() { setLoadingText('Fetching change address...'); const changeAddress = await foundWallet.getChangeAddressAsync(); setLoadingText('Crafting notification transaction...'); + if (foundWallet.getUtxo().length === 0) { + // no balance..? + presentAlert({ message: loc.send.details_total_exceeds_balance }); + return; + } const { tx, fee } = foundWallet.createBip47NotificationTransaction(foundWallet.getUtxo(), newPc, fees.fast, changeAddress); if (!tx) {