commit 12c9de6bf998f2a0a4cbc9c9c4bb1d11dac44dc5
parent 35c056539545ec6397ff0e63b3f50ac051de6939
Author: zebra-lucky <zebra.lucky@gmail.com>
Date: Tue, 19 Jan 2021 00:07:29 +0200
qt: fix PayToEdit.parse_amount (#6951)
nicer error messages for malformed inputs
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/electrum/gui/qt/paytoedit.py b/electrum/gui/qt/paytoedit.py
@@ -24,6 +24,7 @@
# SOFTWARE.
import re
+import decimal
from decimal import Decimal
from typing import NamedTuple, Sequence, Optional, List, TYPE_CHECKING
@@ -127,10 +128,16 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, Logger):
return script
def parse_amount(self, x):
- if x.strip() == '!':
+ x = x.strip()
+ if not x:
+ raise Exception("Amount is empty")
+ if x == '!':
return '!'
p = pow(10, self.amount_edit.decimal_point())
- return int(p * Decimal(x.strip()))
+ try:
+ return int(p * Decimal(x))
+ except decimal.InvalidOperation:
+ raise Exception("Invalid amount")
def parse_address(self, line):
r = line.strip()