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