Files
purple-electrumwallet/electrum/gui/qml/components/OpenWalletDialog.qml
T

144 lines
4.3 KiB
QML
Raw Normal View History

2023-07-17 10:49:06 +02:00
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
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 isStartup
property bool _invalidPassword: false
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
needsSystemBarPadding: false
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
text: Daemon.singlePasswordEnabled || isStartup
2023-03-09 16:13:24 +01:00
? qsTr('Please enter password')
: qsTr('Wallet <b>%1</b> requires password to unlock').arg(name)
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')
Layout.fillWidth: true
color: Material.accentColor
}
2022-07-26 20:36:43 +02:00
PasswordField {
id: password
Layout.fillWidth: true
Layout.leftMargin: constants.paddingXLarge
2022-07-26 20:36:43 +02:00
onTextChanged: {
unlockButton.enabled = true
_unlockClicked = false
2023-11-13 11:35:30 +01:00
_invalidPassword = false
2022-07-26 20:36:43 +02:00
}
onAccepted: {
unlock()
}
}
Label {
Layout.alignment: Qt.AlignHCenter
text: _invalidPassword && _unlockClicked ? qsTr("Invalid Password") : ''
color: constants.colorError
font.pixelSize: constants.fontSizeLarge
}
2022-08-17 11:49:57 +02:00
}
2023-01-09 18:15:53 +01:00
FlatButton {
id: unlockButton
Layout.fillWidth: true
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
Daemon.loadWallet(openwalletdialog.path, password.text)
}
2022-08-17 11:49:57 +02:00
function maybeUnlockAnyOtherWallet() {
// try to open any other wallet with the password the user entered, hack to improve ux for
// users with non-unified wallet password.
// we should only fall back to opening a random wallet if:
// - the user did not select a specific wallet, otherwise this is confusing
// - there can be more than one password, otherwise this scan would be pointless
if (Daemon.availableWallets.rowCount() <= 1 || password.text === '') {
return false
}
if (Config.walletDidUseSinglePassword) {
// the last time the wallet was unlocked all wallets used the same password.
// trying to decrypt all of them now is most probably useless.
return false
}
if (!openwalletdialog.isStartup) {
return false // this dialog got opened because the user clicked on a specific wallet
}
let wallet_paths = Daemon.getWalletsUnlockableWithPassword(password.text)
if (wallet_paths && wallet_paths.length > 0) {
console.log('could not unlock recent wallet, falling back to: ' + wallet_paths[0])
Daemon.loadWallet(wallet_paths[0], password.text)
return true
}
return false
}
Connections {
target: Daemon
function onWalletRequiresPassword() {
if (maybeUnlockAnyOtherWallet()) {
password.text = '' // reset pw so we cannot end up in a loop
return
}
console.log('invalid password')
_invalidPassword = true
2022-08-17 11:49:57 +02:00
password.tf.forceActiveFocus()
}
function onWalletLoaded() {
2023-02-28 14:11:52 +01:00
openwalletdialog.close()
}
}
2022-08-17 11:49:57 +02:00
Component.onCompleted: {
password.tf.forceActiveFocus()
}
}