Browse Source
qt: fix PayToEdit.parse_amount (#6951)
nicer error messages for malformed inputs
patch-4
zebra-lucky
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
9 additions and
2 deletions
-
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() |
|
|
|