qt: fix PayToEdit.parse_amount (#6951)
nicer error messages for malformed inputs
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user