1
0

qml: show 2FA status and billing info in WalletDetails, expose billing schedule setting in config

This commit is contained in:
Sander van Grieken
2022-11-04 13:35:15 +01:00
parent eb2ff94104
commit 0c9d4abb82
5 changed files with 138 additions and 3 deletions

View File

@@ -39,6 +39,8 @@ class Plugin(TrustedCoinPlugin):
_otpSecret = ''
shortIdChanged = pyqtSignal()
_shortId = ''
billingModelChanged = pyqtSignal()
_billingModel = []
_remoteKeyState = ''
remoteKeyStateChanged = pyqtSignal()
@@ -91,6 +93,27 @@ class Plugin(TrustedCoinPlugin):
self._remoteKeyState = new_state
self.remoteKeyStateChanged.emit()
@pyqtProperty('QVariantList', notify=billingModelChanged)
def billingModel(self):
return self._billingModel
def updateBillingInfo(self, wallet):
billingModel = []
price_per_tx = wallet.price_per_tx
for k, v in sorted(price_per_tx.items()):
if k == 1:
continue
item = {
'text': 'Pay every %d transactions' % k,
'value': k,
'sats_per_tx': v/k
}
billingModel.append(item)
self._billingModel = billingModel
self.billingModelChanged.emit()
@pyqtSlot()
def fetchTermsAndConditions(self):
def fetch_task():
@@ -274,6 +297,8 @@ class Plugin(TrustedCoinPlugin):
# extend wizard
self.extend_wizard()
# wizard support functions
def extend_wizard(self):
wizard = self._app.daemon.newWalletWizard
self.logger.debug(repr(wizard))
@@ -367,7 +392,7 @@ class Plugin(TrustedCoinPlugin):
wizard_data['x3/'] = k3.dump()
# regular wallet prompt functions
# running wallet functions
def prompt_user_for_otp(self, wallet, tx, on_success, on_failure):
self.logger.debug('prompt_user_for_otp')
@@ -379,7 +404,12 @@ class Plugin(TrustedCoinPlugin):
qewallet.request_otp(self.on_otp)
def on_otp(self, otp):
if not otp:
self.on_failure(_('No auth code'))
return
self.logger.debug(f'on_otp {otp} for tx {repr(self.tx)}')
try:
self.wallet.on_otp(self.tx, otp)
except UserFacingException as e:
@@ -388,8 +418,15 @@ class Plugin(TrustedCoinPlugin):
if e.status_code == 400: # invalid OTP
self.on_failure(_('Invalid one-time password.'))
else:
self.on_failure(_('Error') + ':\n' + str(e))
self.on_failure(_('Service Error') + ':\n' + str(e))
except Exception as e:
self.on_failure(_('Error') + ':\n' + str(e))
else:
self.on_success(self.tx)
def billing_info_retrieved(self, wallet):
self.logger.info('billing_info_retrieved')
qewallet = QEWallet.getInstanceFor(wallet)
qewallet.billingInfoChanged.emit()
self.so.updateBillingInfo(wallet)

View File

@@ -519,8 +519,13 @@ class TrustedCoinPlugin(BasePlugin):
wallet.billing_info = billing_info
wallet.price_per_tx = dict(billing_info['price_per_tx'])
wallet.price_per_tx.pop(1, None)
self.billing_info_retrieved(wallet)
return True
def billing_info_retrieved(self, wallet):
# override to handle billing info when it becomes available
pass
def start_request_thread(self, wallet):
from threading import Thread
if self.requesting is False: