Files
pallectrum/electrum/gui/qml/components/OpenWalletDialog.qml

143 lines
3.8 KiB
QML
Raw Normal View History

import QtQuick 2.6
import QtQuick.Layouts 1.0
2022-08-17 11:49:57 +02:00
import QtQuick.Controls 2.3
import QtQuick.Controls.Material 2.0
import org.electrum 1.0
import "controls"
2022-08-17 11:49:57 +02:00
ElDialog {
id: openwalletdialog
2022-08-17 11:49:57 +02:00
property string name
property string path
property bool _unlockClicked: false
title: qsTr('Open Wallet')
iconSource: Qt.resolvedUrl('../../icons/wallet.png')
2022-08-17 11:49:57 +02:00
focus: true
width: parent.width * 4/5
anchors.centerIn: parent
padding: 0
2022-08-17 11:49:57 +02:00
ColumnLayout {
spacing: 0
2022-08-17 11:49:57 +02:00
width: parent.width
ColumnLayout {
id: rootLayout
Layout.fillWidth: true
Layout.leftMargin: constants.paddingXXLarge
Layout.rightMargin: constants.paddingXXLarge
spacing: constants.paddingLarge
2023-01-03 18:22:15 +01:00
2022-08-17 11:49:57 +02:00
InfoTextArea {
id: notice
2023-03-09 16:13:24 +01:00
text: Daemon.singlePasswordEnabled
? qsTr('Please enter password')
: qsTr('Wallet <b>%1</b> requires password to unlock').arg(name)
visible: wallet_db.needsPassword
2022-08-17 11:49:57 +02:00
iconStyle: InfoTextArea.IconStyle.Warn
Layout.fillWidth: true
2022-08-17 11:49:57 +02:00
}
2022-07-26 20:36:43 +02:00
Label {
text: qsTr('Password')
visible: wallet_db.needsPassword
Layout.fillWidth: true
color: Material.accentColor
}
2022-07-26 20:36:43 +02:00
PasswordField {
id: password
Layout.fillWidth: true
Layout.leftMargin: constants.paddingXLarge
visible: wallet_db.needsPassword
2022-07-26 20:36:43 +02:00
onTextChanged: {
unlockButton.enabled = true
_unlockClicked = false
}
onAccepted: {
unlock()
}
}
Label {
Layout.alignment: Qt.AlignHCenter
text: !wallet_db.validPassword && _unlockClicked ? qsTr("Invalid Password") : ''
color: constants.colorError
font.pixelSize: constants.fontSizeLarge
}
Label {
Layout.alignment: Qt.AlignHCenter
visible: wallet_db.requiresSplit
text: qsTr('Wallet requires splitting')
font.pixelSize: constants.fontSizeLarge
}
FlatButton {
Layout.alignment: Qt.AlignHCenter
visible: wallet_db.requiresSplit
text: qsTr('Split wallet')
onClicked: wallet_db.doSplit()
}
2022-08-17 11:49:57 +02:00
}
2023-01-09 18:15:53 +01:00
FlatButton {
id: unlockButton
Layout.fillWidth: true
visible: wallet_db.needsPassword
2023-01-09 18:15:53 +01:00
icon.source: '../../icons/unlock.png'
text: qsTr("Unlock")
onClicked: {
unlock()
}
}
}
function unlock() {
unlockButton.enabled = false
_unlockClicked = true
wallet_db.password = password.text
2022-07-12 16:49:07 +02:00
wallet_db.verify()
}
2022-08-17 11:49:57 +02:00
WalletDB {
id: wallet_db
path: openwalletdialog.path
onSplitFinished: {
// if wallet needed splitting, we close the pane and refresh the wallet list
Daemon.availableWallets.reload()
2022-08-17 11:49:57 +02:00
openwalletdialog.close()
}
onReadyChanged: {
if (ready) {
Daemon.load_wallet(openwalletdialog.path, password.text)
2022-08-17 11:49:57 +02:00
openwalletdialog.close()
}
}
onInvalidPassword: {
2022-08-17 11:49:57 +02:00
password.tf.forceActiveFocus()
}
onNeedsPasswordChanged: {
notice.visible = needsPassword
}
onWalletOpenProblem: {
openwalletdialog.close()
Daemon.onWalletOpenProblem(error)
}
}
2022-08-17 11:49:57 +02:00
Component.onCompleted: {
2022-07-12 16:49:07 +02:00
wallet_db.verify()
}
}