From 5f9068d7b0de51973e8a0bdbf1fa335e3397b943 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 27 Sep 2022 12:25:21 +0200 Subject: [PATCH] add default request expiry to preferences/config --- electrum/gui/qml/components/Preferences.qml | 12 +++++++ .../qml/components/ReceiveDetailsDialog.qml | 19 +--------- .../controls/RequestExpiryComboBox.qml | 36 +++++++++++++++++++ electrum/gui/qml/qeconfig.py | 13 +++++++ 4 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 electrum/gui/qml/components/controls/RequestExpiryComboBox.qml diff --git a/electrum/gui/qml/components/Preferences.qml b/electrum/gui/qml/components/Preferences.qml index 354704a9a..b4d6924fa 100644 --- a/electrum/gui/qml/components/Preferences.qml +++ b/electrum/gui/qml/components/Preferences.qml @@ -148,6 +148,18 @@ Pane { } } + Label { + text: qsTr('Default request expiry') + Layout.fillWidth: false + } + + RequestExpiryComboBox { + onCurrentValueChanged: { + if (activeFocus) + Config.requestExpiry = currentValue + } + } + Label { text: qsTr('PIN') } diff --git a/electrum/gui/qml/components/ReceiveDetailsDialog.qml b/electrum/gui/qml/components/ReceiveDetailsDialog.qml index 97f5c4a00..6c59f209e 100644 --- a/electrum/gui/qml/components/ReceiveDetailsDialog.qml +++ b/electrum/gui/qml/components/ReceiveDetailsDialog.qml @@ -84,26 +84,9 @@ ElDialog { Layout.fillWidth: false } - ElComboBox { + RequestExpiryComboBox { id: expires Layout.columnSpan: 2 - - textRole: 'text' - valueRole: 'value' - - model: ListModel { - id: expiresmodel - Component.onCompleted: { - // we need to fill the model like this, as ListElement can't evaluate script - expiresmodel.append({'text': qsTr('10 minutes'), 'value': 10*60}) - expiresmodel.append({'text': qsTr('1 hour'), 'value': 60*60}) - expiresmodel.append({'text': qsTr('1 day'), 'value': 24*60*60}) - expiresmodel.append({'text': qsTr('1 week'), 'value': 7*24*60*60}) - expiresmodel.append({'text': qsTr('1 month'), 'value': 31*24*60*60}) - expiresmodel.append({'text': qsTr('Never'), 'value': 0}) - expires.currentIndex = 0 - } - } } Item { width: 1; height: 1; Layout.fillWidth: true } diff --git a/electrum/gui/qml/components/controls/RequestExpiryComboBox.qml b/electrum/gui/qml/components/controls/RequestExpiryComboBox.qml new file mode 100644 index 000000000..3a0e161b4 --- /dev/null +++ b/electrum/gui/qml/components/controls/RequestExpiryComboBox.qml @@ -0,0 +1,36 @@ +import QtQuick 2.6 +import QtQuick.Controls 2.3 + +import org.electrum 1.0 + +ElComboBox { + id: expires + + textRole: 'text' + valueRole: 'value' + + model: ListModel { + id: expiresmodel + Component.onCompleted: { + // we need to fill the model like this, as ListElement can't evaluate script + expiresmodel.append({'text': qsTr('10 minutes'), 'value': 10*60}) + expiresmodel.append({'text': qsTr('1 hour'), 'value': 60*60}) + expiresmodel.append({'text': qsTr('1 day'), 'value': 24*60*60}) + expiresmodel.append({'text': qsTr('1 week'), 'value': 7*24*60*60}) + expiresmodel.append({'text': qsTr('1 month'), 'value': 31*24*60*60}) + expiresmodel.append({'text': qsTr('Never'), 'value': 0}) + expires.currentIndex = 0 + for (let i=0; i < expiresmodel.count; i++) { + if (expiresmodel.get(i).value == Config.requestExpiry) { + expires.currentIndex = i + break + } + } + } + } + + onCurrentValueChanged: { + if (activeFocus) + Config.requestExpiry = currentValue + } +} diff --git a/electrum/gui/qml/qeconfig.py b/electrum/gui/qml/qeconfig.py index 0e2333e82..7ef75dbf1 100644 --- a/electrum/gui/qml/qeconfig.py +++ b/electrum/gui/qml/qeconfig.py @@ -4,6 +4,7 @@ from decimal import Decimal from electrum.logging import get_logger from electrum.util import DECIMAL_POINT_DEFAULT, format_satoshis +from electrum.invoices import PR_DEFAULT_EXPIRATION_WHEN_CREATING from .qetypes import QEAmount from .auth import AuthMixin, auth_protect @@ -81,6 +82,18 @@ class QEConfig(AuthMixin, QObject): self.config.set_key('confirmed_only', not checked, True) self.spendUnconfirmedChanged.emit() + requestExpiryChanged = pyqtSignal() + @pyqtProperty(int, notify=requestExpiryChanged) + def requestExpiry(self): + a = self.config.get('request_expiry', PR_DEFAULT_EXPIRATION_WHEN_CREATING) + self._logger.debug(f'request expiry {a}') + return a + + @requestExpiry.setter + def requestExpiry(self, expiry): + self.config.set_key('request_expiry', expiry) + self.requestExpiryChanged.emit() + pinCodeChanged = pyqtSignal() @pyqtProperty(str, notify=pinCodeChanged) def pinCode(self):