Browse Source

follow-up prev

PaymentRequest.error is really not intuitive.........
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 6 years ago
parent
commit
0553ab7f3f
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/gui/qt/main_window.py
  2. 11
      electrum/paymentrequest.py

9
electrum/gui/qt/main_window.py

@ -37,6 +37,7 @@ import base64
from functools import partial from functools import partial
import queue import queue
import asyncio import asyncio
from typing import Optional
from PyQt5.QtGui import QPixmap, QKeySequence, QIcon, QCursor from PyQt5.QtGui import QPixmap, QKeySequence, QIcon, QCursor
from PyQt5.QtCore import Qt, QRect, QStringListModel, QSize, pyqtSignal from PyQt5.QtCore import Qt, QRect, QStringListModel, QSize, pyqtSignal
@ -71,6 +72,7 @@ from electrum.network import Network, TxBroadcastError, BestEffortRequestFailed
from electrum.exchange_rate import FxThread from electrum.exchange_rate import FxThread
from electrum.simple_config import SimpleConfig from electrum.simple_config import SimpleConfig
from electrum.logging import Logger from electrum.logging import Logger
from electrum.paymentrequest import PR_PAID
from .exception_window import Exception_Hook from .exception_window import Exception_Hook
from .amountedit import AmountEdit, BTCAmountEdit, MyLineEdit, FeerateEdit from .amountedit import AmountEdit, BTCAmountEdit, MyLineEdit, FeerateEdit
@ -109,9 +111,6 @@ class StatusBarButton(QPushButton):
self.func() self.func()
from electrum.paymentrequest import PR_PAID
class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
payment_request_ok_signal = pyqtSignal() payment_request_ok_signal = pyqtSignal()
@ -141,7 +140,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.tray = gui_object.tray self.tray = gui_object.tray
self.app = gui_object.app self.app = gui_object.app
self.cleaned_up = False self.cleaned_up = False
self.payment_request = None self.payment_request = None # type: Optional[paymentrequest.PaymentRequest]
self.checking_accounts = False self.checking_accounts = False
self.qr_window = None self.qr_window = None
self.not_enough_funds = False self.not_enough_funds = False
@ -1604,8 +1603,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
""" """
pr = self.payment_request pr = self.payment_request
if pr: if pr:
if pr.error:
return True
if pr.has_expired(): if pr.has_expired():
self.show_error(_('Payment request has expired')) self.show_error(_('Payment request has expired'))
return True return True

11
electrum/paymentrequest.py

@ -27,6 +27,7 @@ import sys
import time import time
import traceback import traceback
import json import json
from typing import Optional
import certifi import certifi
import urllib.parse import urllib.parse
@ -106,15 +107,15 @@ async def get_payment_request(url: str) -> 'PaymentRequest':
else: else:
data = None data = None
error = f"Unknown scheme for payment request. URL: {url}" error = f"Unknown scheme for payment request. URL: {url}"
pr = PaymentRequest(data, error) pr = PaymentRequest(data, error=error)
return pr return pr
class PaymentRequest: class PaymentRequest:
def __init__(self, data, error=None): def __init__(self, data, *, error=None):
self.raw = data self.raw = data
self.error = error self.error = error # FIXME overloaded and also used when 'verify' succeeds
self.parse(data) self.parse(data)
self.requestor = None # known after verify self.requestor = None # known after verify
self.tx = None self.tx = None
@ -235,7 +236,9 @@ class PaymentRequest:
self.error = "unknown algo" self.error = "unknown algo"
return False return False
def has_expired(self): def has_expired(self) -> Optional[bool]:
if not hasattr(self, 'details'):
return None
return self.details.expires and self.details.expires < int(time.time()) return self.details.expires and self.details.expires < int(time.time())
def get_expiration_date(self): def get_expiration_date(self):

Loading…
Cancel
Save