qml: add auth_message to AuthMixin, which is displayed above the Pin entry textfield, or
shown in a messageDialog for confirmation.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from functools import wraps, partial
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, pyqtProperty
|
||||
|
||||
from electrum.logging import get_logger
|
||||
|
||||
@@ -25,6 +25,12 @@ class AuthMixin:
|
||||
|
||||
authRequired = pyqtSignal([str],arguments=['method'])
|
||||
|
||||
auth_message = ''
|
||||
_authMixinMessageChanged = pyqtSignal()
|
||||
@pyqtProperty(str, notify=_authMixinMessageChanged)
|
||||
def authMessage(self):
|
||||
return self.auth_message
|
||||
|
||||
@pyqtSlot()
|
||||
def authProceed(self):
|
||||
self._auth_logger.debug('Proceeding with authed fn()')
|
||||
@@ -38,6 +44,7 @@ class AuthMixin:
|
||||
raise e
|
||||
finally:
|
||||
delattr(self,'__auth_fcall')
|
||||
self.auth_message = ''
|
||||
|
||||
@pyqtSlot()
|
||||
def authCancel(self):
|
||||
@@ -57,3 +64,4 @@ class AuthMixin:
|
||||
raise e
|
||||
finally:
|
||||
delattr(self, '__auth_fcall')
|
||||
self.auth_message = ''
|
||||
|
||||
@@ -10,11 +10,21 @@ import "controls"
|
||||
ElDialog {
|
||||
id: root
|
||||
|
||||
property bool canCancel: true
|
||||
property string mode // [check, enter, change]
|
||||
property string pincode // old one passed in when change, new one passed out
|
||||
property bool checkError: false
|
||||
property string authMessage
|
||||
property int _phase: mode == 'enter' ? 1 : 0 // 0 = existing pin, 1 = new pin, 2 = re-enter new pin
|
||||
property string _pin
|
||||
|
||||
title: qsTr('PIN')
|
||||
iconSource: '../../../icons/lock.png'
|
||||
z: 1000
|
||||
|
||||
width: parent.width * 3/4
|
||||
z: 1000
|
||||
focus: true
|
||||
closePolicy: canCancel ? Popup.CloseOnEscape | Popup.CloseOnPressOutside : Popup.NoAutoClose
|
||||
allowClose: canCancel
|
||||
|
||||
anchors.centerIn: parent
|
||||
|
||||
@@ -22,22 +32,6 @@ ElDialog {
|
||||
color: canCancel ? "#aa000000" : "#ff000000"
|
||||
}
|
||||
|
||||
focus: true
|
||||
|
||||
closePolicy: canCancel ? Popup.CloseOnEscape | Popup.CloseOnPressOutside : Popup.NoAutoClose
|
||||
|
||||
property bool canCancel: true
|
||||
|
||||
allowClose: canCancel
|
||||
|
||||
property string mode // [check, enter, change]
|
||||
property string pincode // old one passed in when change, new one passed out
|
||||
|
||||
property int _phase: mode == 'enter' ? 1 : 0 // 0 = existing pin, 1 = new pin, 2 = re-enter new pin
|
||||
property string _pin
|
||||
|
||||
property bool checkError: false
|
||||
|
||||
function submit() {
|
||||
if (_phase == 0) {
|
||||
if (pin.text == pincode) {
|
||||
@@ -76,6 +70,13 @@ ElDialog {
|
||||
ColumnLayout {
|
||||
width: parent.width
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
visible: authMessage
|
||||
text: authMessage
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
|
||||
Label {
|
||||
text: [qsTr('Enter PIN'), qsTr('Enter New PIN'), qsTr('Re-enter New PIN')][_phase]
|
||||
font.pixelSize: constants.fontSizeXXLarge
|
||||
|
||||
@@ -371,13 +371,6 @@ ApplicationWindow
|
||||
swaphelper: SwapHelper {
|
||||
id: _swaphelper
|
||||
wallet: Daemon.currentWallet
|
||||
onConfirm: {
|
||||
var dialog = app.messageDialog.createObject(app, {text: message, yesno: true})
|
||||
dialog.accepted.connect(function() {
|
||||
_swaphelper.executeSwap(true)
|
||||
})
|
||||
dialog.open()
|
||||
}
|
||||
onAuthRequired: {
|
||||
app.handleAuthRequired(_swaphelper, method)
|
||||
}
|
||||
@@ -558,9 +551,13 @@ ApplicationWindow
|
||||
} else if (method == 'pin') {
|
||||
if (Config.pinCode == '') {
|
||||
// no PIN configured
|
||||
qtobject.authProceed()
|
||||
handleAuthConfirmationOnly(qtobject)
|
||||
} else {
|
||||
var dialog = app.pinDialog.createObject(app, {mode: 'check', pincode: Config.pinCode})
|
||||
var dialog = app.pinDialog.createObject(app, {
|
||||
mode: 'check',
|
||||
pincode: Config.pinCode,
|
||||
authMessage: qtobject.authMessage
|
||||
})
|
||||
dialog.accepted.connect(function() {
|
||||
qtobject.authProceed()
|
||||
dialog.close()
|
||||
@@ -576,6 +573,21 @@ ApplicationWindow
|
||||
}
|
||||
}
|
||||
|
||||
function handleAuthConfirmationOnly(qtobject) {
|
||||
if (!qtobject.authMessage) {
|
||||
qtobject.authProceed()
|
||||
return
|
||||
}
|
||||
var dialog = app.messageDialog.createObject(app, {text: qtobject.authMessage, yesno: true})
|
||||
dialog.accepted.connect(function() {
|
||||
qtobject.authProceed()
|
||||
})
|
||||
dialog.rejected.connect(function() {
|
||||
qtobject.authCancel()
|
||||
})
|
||||
dialog.open()
|
||||
}
|
||||
|
||||
function startSwap() {
|
||||
var swapdialog = swapDialog.createObject(app)
|
||||
swapdialog.open()
|
||||
|
||||
@@ -419,21 +419,19 @@ class QESwapHelper(AuthMixin, QObject, QtEventListener):
|
||||
threading.Thread(target=swap_task, daemon=True).start()
|
||||
|
||||
@pyqtSlot()
|
||||
@pyqtSlot(bool)
|
||||
def executeSwap(self, confirm=False):
|
||||
def executeSwap(self):
|
||||
if not self._wallet.wallet.network:
|
||||
self.error.emit(_("You are offline."))
|
||||
return
|
||||
if confirm or self._wallet.wallet.config.get('pin_code', ''):
|
||||
self._do_execute_swap()
|
||||
return
|
||||
|
||||
if self.isReverse:
|
||||
self.confirm.emit(_('Do you want to do a reverse submarine swap?'))
|
||||
self.auth_message = _('Do you want to do a reverse submarine swap?')
|
||||
else:
|
||||
self.confirm.emit(_('Do you want to do a submarine swap? '
|
||||
self.auth_message = _('Do you want to do a submarine swap? '
|
||||
'You will need to wait for the swap transaction to confirm.'
|
||||
))
|
||||
)
|
||||
|
||||
self._do_execute_swap()
|
||||
|
||||
@auth_protect
|
||||
def _do_execute_swap(self):
|
||||
|
||||
Reference in New Issue
Block a user