From b8a8c848c79063301d37425866967c4269eefa95 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Mon, 7 Nov 2022 14:07:00 +0100 Subject: [PATCH] qml: enable first wizard page of multisig --- electrum/gui/qml/components/Constants.qml | 3 + .../gui/qml/components/wizard/WCMultisig.qml | 100 ++++++++++++++++++ .../qml/components/wizard/WCWalletType.qml | 1 - electrum/gui/qml/qewizard.py | 1 + electrum/wizard.py | 4 + 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 electrum/gui/qml/components/wizard/WCMultisig.qml diff --git a/electrum/gui/qml/components/Constants.qml b/electrum/gui/qml/components/Constants.qml index 8c35bfe60..c52bc89df 100644 --- a/electrum/gui/qml/components/Constants.qml +++ b/electrum/gui/qml/components/Constants.qml @@ -39,6 +39,9 @@ Item { property color colorPiechartFrozen: 'gray' property color colorPiechartLightning: 'orange' //Qt.darker(Material.accentColor, 1.20) + property color colorPiechartParticipant: 'gray' + property color colorPiechartSignature: 'yellow' + function colorAlpha(baseColor, alpha) { return Qt.rgba(baseColor.r, baseColor.g, baseColor.b, alpha) } diff --git a/electrum/gui/qml/components/wizard/WCMultisig.qml b/electrum/gui/qml/components/wizard/WCMultisig.qml new file mode 100644 index 000000000..204ab7f62 --- /dev/null +++ b/electrum/gui/qml/components/wizard/WCMultisig.qml @@ -0,0 +1,100 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 2.1 + +import org.electrum 1.0 + +import "../controls" + +WizardComponent { + id: root + + valid: true + + property int participants: 2 + property int signatures: 2 + + onParticipantsChanged: { + if (participants < signatures) + signatures = participants + piechart.updateSlices() + } + onSignaturesChanged: { + piechart.updateSlices() + } + + function apply() { + wizard_data['multisig_participants'] = participants + wizard_data['multisig_signatures'] = signatures + } + + ColumnLayout { + width: parent.width + + Label { text: qsTr('Multisig wallet') } + + InfoTextArea { + Layout.preferredWidth: parent.width + text: qsTr('Choose the number of participants, and the number of signatures needed to unlock funds in your wallet.') + } + + Piechart { + id: piechart + Layout.preferredWidth: parent.width * 1/2 + Layout.alignment: Qt.AlignHCenter + Layout.preferredHeight: 200 // TODO + showLegend: false + innerOffset: 3 + function updateSlices() { + var s = [] + for (let i=0; i < participants; i++) { + var item = { + v: (1/participants), + color: i < signatures ? constants.colorPiechartSignature : constants.colorPiechartParticipant + } + s.push(item) + } + piechart.slices = s + } + } + + Label { + text: qsTr('Number of cosigners: %1').arg(participants) + } + + Slider { + id: participants_slider + Layout.preferredWidth: parent.width * 4/5 + Layout.alignment: Qt.AlignHCenter + snapMode: Slider.SnapAlways + stepSize: 1 + from: 2 + to: 15 + onValueChanged: { + if (activeFocus) + participants = value + } + } + + Label { + text: qsTr('Number of signatures: %1').arg(signatures) + } + + Slider { + id: signatures_slider + Layout.preferredWidth: parent.width * 4/5 + Layout.alignment: Qt.AlignHCenter + snapMode: Slider.SnapAlways + stepSize: 1 + from: 1 + to: participants + onValueChanged: { + if (activeFocus) + signatures = value + } + } + } + + Component.onCompleted: piechart.updateSlices() + +} diff --git a/electrum/gui/qml/components/wizard/WCWalletType.qml b/electrum/gui/qml/components/wizard/WCWalletType.qml index a8fc832a4..8f7c3b3ac 100644 --- a/electrum/gui/qml/components/wizard/WCWalletType.qml +++ b/electrum/gui/qml/components/wizard/WCWalletType.qml @@ -32,7 +32,6 @@ WizardComponent { text: qsTr('Wallet with two-factor authentication') } RadioButton { - enabled: false ButtonGroup.group: wallettypegroup property string wallettype: 'multisig' text: qsTr('Multi-signature wallet') diff --git a/electrum/gui/qml/qewizard.py b/electrum/gui/qml/qewizard.py index 1f5daa8f8..90392f670 100644 --- a/electrum/gui/qml/qewizard.py +++ b/electrum/gui/qml/qewizard.py @@ -59,6 +59,7 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard): 'have_seed': { 'gui': 'WCHaveSeed' }, 'bip39_refine': { 'gui': 'WCBIP39Refine' }, 'have_master_key': { 'gui': 'WCHaveMasterKey' }, + 'multisig': { 'gui': 'WCMultisig' }, 'imported': { 'gui': 'WCImport' }, 'wallet_password': { 'gui': 'WCWalletPassword' } }) diff --git a/electrum/wizard.py b/electrum/wizard.py index ca083336a..e72327400 100644 --- a/electrum/wizard.py +++ b/electrum/wizard.py @@ -163,6 +163,9 @@ class NewWalletWizard(AbstractWizard): 'next': 'wallet_password', 'last': self.last_if_single_password }, + 'multisig': { + 'next': 'first_cosigner' + }, 'imported': { 'next': 'wallet_password', 'last': self.last_if_single_password @@ -189,6 +192,7 @@ class NewWalletWizard(AbstractWizard): return { 'standard': 'keystore_type', '2fa': 'trustedcoin_start', + 'multisig': 'multisig', 'imported': 'imported' }.get(t)