From d8f579ccfc5210f22025285871cfc3a219bea204 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 16 Jan 2024 16:25:33 +0100 Subject: [PATCH] Consistently use translated strings for UserFacingException raises --- electrum/plugins/bitbox02/bitbox02.py | 16 ++++++---------- electrum/plugins/ledger/ledger.py | 17 ++++++++--------- electrum/qrscanner.py | 2 +- electrum/wallet.py | 6 +++--- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/electrum/plugins/bitbox02/bitbox02.py b/electrum/plugins/bitbox02/bitbox02.py index a97e72beb..159cd0180 100644 --- a/electrum/plugins/bitbox02/bitbox02.py +++ b/electrum/plugins/bitbox02/bitbox02.py @@ -326,7 +326,7 @@ class BitBox02Client(HardwareClientBase): except bitbox02.DuplicateEntryException: raise except Exception: - raise UserFacingException("Failed to register multisig\naccount configuration on BitBox02") + raise UserFacingException(_('Failed to register multisig\naccount configuration on BitBox02')) return multisig_config @runs_in_hwd_thread @@ -464,9 +464,7 @@ class BitBox02Client(HardwareClientBase): raise Exception("Can only use p2wsh-p2sh or p2wsh with multisig wallets") else: raise UserFacingException( - "invalid input script type: {} is not supported by the BitBox02".format( - tx_script_type - ) + _('Invalid input script type: {} is not supported by the BitBox02').format(tx_script_type) ) # Build BTCOutputType list @@ -495,7 +493,7 @@ class BitBox02Client(HardwareClientBase): output_type = bitbox02.btc.P2TR else: raise UserFacingException( - "Received unsupported output type during transaction signing: {} is not supported by the BitBox02".format( + _('Received unsupported output type during transaction signing: {} is not supported by the BitBox02').format( addrtype ) ) @@ -546,9 +544,9 @@ class BitBox02Client(HardwareClientBase): "p2wpkh": bitbox02.btc.BTCScriptConfig.P2WPKH, }[script_type] except KeyError: - raise UserFacingException("The BitBox02 does not support signing messages for this address type: {}".format(script_type)) + raise UserFacingException(_('The BitBox02 does not support signing messages for this address type: {}').format(script_type)) - _, _, signature = self.bitbox02_device.btc_sign_msg( + _a, _b, signature = self.bitbox02_device.btc_sign_msg( self._get_coin(), bitbox02.btc.BTCScriptConfigWithKeypath( script_config=bitbox02.btc.BTCScriptConfig( @@ -580,9 +578,7 @@ class BitBox02_KeyStore(Hardware_KeyStore): def decrypt_message(self, pubkey, message, password): raise UserFacingException( - _( - "Message encryption, decryption and signing are currently not supported for {}" - ).format(self.device) + _('Message encryption, decryption and signing are currently not supported for {}').format(self.device) ) def sign_message(self, sequence, message, password, *, script_type=None): diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py index fc042fdc8..8d62650c9 100644 --- a/electrum/plugins/ledger/ledger.py +++ b/electrum/plugins/ledger/ledger.py @@ -867,18 +867,17 @@ class Ledger_Client_Legacy_HW1(Ledger_Client_Legacy): msg = "Enter your Ledger PIN - WARNING : LAST ATTEMPT. If the PIN is not correct, the dongle will be wiped." confirmed, p, pin = self.password_dialog(msg) if not confirmed: - raise UserFacingException('Aborted by user - please unplug the dongle and plug it again before retrying') + raise UserFacingException(_('Aborted by user - please unplug the dongle and plug it again before retrying')) pin = pin.encode() self.dongleObject.verifyPin(pin) except BTChipException as e: if (e.sw == 0x6faa): - raise UserFacingException("Dongle is temporarily locked - please unplug it and replug it again") + raise UserFacingException(_('Dongle is temporarily locked - please unplug it and replug it again')) if ((e.sw & 0xFFF0) == 0x63c0): - raise UserFacingException("Invalid PIN - please unplug the dongle and plug it again before retrying") + raise UserFacingException(_('Invalid PIN - please unplug the dongle and plug it again before retrying')) if e.sw == 0x6f00 and e.message == 'Invalid channel': # based on docs 0x6f00 might be a more general error, hence we also compare message to be sure - raise UserFacingException("Invalid channel.\n" - "Please make sure that 'Browser support' is disabled on your device.") + raise UserFacingException(_("Invalid channel.\nPlease make sure that 'Browser support' is disabled on your device.")) if e.sw == 0x6d00 or e.sw == 0x6700: raise UserFacingException(_("Device not in Bitcoin mode")) from e raise e @@ -1002,7 +1001,7 @@ class Ledger_Client_New(Ledger_Client): path_parts = path.split("/") if not 5 <= len(path_parts) <= 6: - raise UserFacingException(f"Unsupported path: {path}") + raise UserFacingException(_('Unsupported derivation path: {}').format(path)) path_root = "/".join(path_parts[:-2]) @@ -1097,14 +1096,14 @@ class Ledger_Client_New(Ledger_Client): wallets: Dict[bytes, Tuple[AddressType, WalletPolicy, Optional[bytes]]] = {} for input_num, (electrum_txin, psbt_in) in enumerate(zip(tx.inputs(), psbt.inputs)): if electrum_txin.is_coinbase_input(): - raise UserFacingException("Coinbase not supported") # should never happen + raise UserFacingException(_('Coinbase not supported')) # should never happen utxo = None if psbt_in.witness_utxo: utxo = psbt_in.witness_utxo if psbt_in.non_witness_utxo: if psbt_in.prev_txid != psbt_in.non_witness_utxo.hash: - raise UserFacingException(f"Input {input_num} has a non_witness_utxo with the wrong hash") + raise UserFacingException(_('Input {} has a non_witness_utxo with the wrong hash').format(input_num)) assert psbt_in.prev_out is not None utxo = psbt_in.non_witness_utxo.vout[psbt_in.prev_out] @@ -1125,7 +1124,7 @@ class Ledger_Client_New(Ledger_Client): if wit_ver == 0: script_addrtype = AddressType.SH_WIT else: - raise UserFacingException("Cannot have witness v1+ in p2sh") + raise UserFacingException(_('Cannot have witness v1+ in p2sh')) else: if wit_ver == 0: script_addrtype = AddressType.WIT diff --git a/electrum/qrscanner.py b/electrum/qrscanner.py index 424dd4186..5fe1734ab 100644 --- a/electrum/qrscanner.py +++ b/electrum/qrscanner.py @@ -59,7 +59,7 @@ except BaseException as e1: def scan_barcode(device='', timeout=-1, display=True, threaded=False) -> Optional[str]: if libzbar is None: - raise UserFacingException("Cannot start QR scanner: zbar not available.") + raise UserFacingException(_('Cannot start QR scanner: zbar not available.')) libzbar.zbar_symbol_get_data.restype = ctypes.c_char_p libzbar.zbar_processor_create.restype = ctypes.POINTER(ctypes.c_int) libzbar.zbar_processor_get_results.restype = ctypes.POINTER(ctypes.c_int) diff --git a/electrum/wallet.py b/electrum/wallet.py index 97eb08104..5c82eb647 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -811,9 +811,9 @@ class Abstract_Wallet(ABC, Logger, EventListener): if self.is_watching_only(): raise UserFacingException(_("This is a watching-only wallet")) if not is_address(address): - raise UserFacingException(f"Invalid bitcoin address: {address}") + raise UserFacingException(_('Invalid bitcoin address: {}').format(address)) if not self.is_mine(address): - raise UserFacingException(_('Address not in wallet.') + f' {address}') + raise UserFacingException(_('Address not in wallet: {}').format(address)) index = self.get_address_index(address) pk, compressed = self.keystore.get_private_key(index, password) txin_type = self.get_txin_type(address) @@ -3380,7 +3380,7 @@ class Imported_Wallet(Simple_Wallet): if not self.db.has_imported_address(address): return if len(self.get_addresses()) <= 1: - raise UserFacingException("cannot delete last remaining address from wallet") + raise UserFacingException(_('Cannot delete last remaining address from wallet')) transactions_to_remove = set() # only referred to by this address transactions_new = set() # txs that are not only referred to by address with self.lock: