qt: fix PayToEdit.parse_amount (#6951)
nicer error messages for malformed inputs
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import decimal
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import NamedTuple, Sequence, Optional, List, TYPE_CHECKING
|
from typing import NamedTuple, Sequence, Optional, List, TYPE_CHECKING
|
||||||
|
|
||||||
@@ -127,10 +128,16 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, Logger):
|
|||||||
return script
|
return script
|
||||||
|
|
||||||
def parse_amount(self, x):
|
def parse_amount(self, x):
|
||||||
if x.strip() == '!':
|
x = x.strip()
|
||||||
|
if not x:
|
||||||
|
raise Exception("Amount is empty")
|
||||||
|
if x == '!':
|
||||||
return '!'
|
return '!'
|
||||||
p = pow(10, self.amount_edit.decimal_point())
|
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):
|
def parse_address(self, line):
|
||||||
r = line.strip()
|
r = line.strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user