From fad0bb858e1d01003896c29da9a13e468832c549 Mon Sep 17 00:00:00 2001 From: hydrogen Date: Fri, 4 Dec 2020 00:26:05 +0200 Subject: [PATCH] fix: password count and disable repeat until first is valid cleanup --- .../components/AddAccountWithPrivateKey.qml | 5 +-- .../Wallet/components/AddAccountWithSeed.qml | 5 +-- .../components/GenerateAccountModal.qml | 5 +-- ui/imports/Utils.qml | 27 ++++++++++++ ui/onboarding/CreatePasswordModal.qml | 41 ++++++------------- ui/shared/TransactionSigner.qml | 5 +-- 6 files changed, 47 insertions(+), 41 deletions(-) diff --git a/ui/app/AppLayouts/Wallet/components/AddAccountWithPrivateKey.qml b/ui/app/AppLayouts/Wallet/components/AddAccountWithPrivateKey.qml index 92eda2eb84..f51daa44d9 100644 --- a/ui/app/AppLayouts/Wallet/components/AddAccountWithPrivateKey.qml +++ b/ui/app/AppLayouts/Wallet/components/AddAccountWithPrivateKey.qml @@ -20,9 +20,8 @@ ModalPopup { if (passwordInput.text === "") { //% "You need to enter a password" passwordValidationError = qsTrId("you-need-to-enter-a-password") - } else if (passwordInput.text.length < 4) { - //% "Password needs to be 4 characters or more" - passwordValidationError = qsTrId("password-needs-to-be-4-characters-or-more") + } else if (passwordInput.text.length < 6) { + passwordValidationError = qsTr("Password needs to be 6 characters or more") } else { passwordValidationError = "" } diff --git a/ui/app/AppLayouts/Wallet/components/AddAccountWithSeed.qml b/ui/app/AppLayouts/Wallet/components/AddAccountWithSeed.qml index 1f4dca8a10..452955056d 100644 --- a/ui/app/AppLayouts/Wallet/components/AddAccountWithSeed.qml +++ b/ui/app/AppLayouts/Wallet/components/AddAccountWithSeed.qml @@ -24,9 +24,8 @@ ModalPopup { if (passwordInput.text === "") { //% "You need to enter a password" passwordValidationError = qsTrId("you-need-to-enter-a-password") - } else if (passwordInput.text.length < 4) { - //% "Password needs to be 4 characters or more" - passwordValidationError = qsTrId("password-needs-to-be-4-characters-or-more") + } else if (passwordInput.text.length < 6) { + passwordValidationError = qsTr("Password needs to be 6 characters or more") } else { passwordValidationError = "" } diff --git a/ui/app/AppLayouts/Wallet/components/GenerateAccountModal.qml b/ui/app/AppLayouts/Wallet/components/GenerateAccountModal.qml index 6ec66aa2e4..c28231ec3e 100644 --- a/ui/app/AppLayouts/Wallet/components/GenerateAccountModal.qml +++ b/ui/app/AppLayouts/Wallet/components/GenerateAccountModal.qml @@ -18,9 +18,8 @@ ModalPopup { if (passwordInput.text === "") { //% "You need to enter a password" passwordValidationError = qsTrId("you-need-to-enter-a-password") - } else if (passwordInput.text.length < 4) { - //% "Password needs to be 4 characters or more" - passwordValidationError = qsTrId("password-needs-to-be-4-characters-or-more") + } else if (passwordInput.text.length < 6) { + passwordValidationError = qsTr("Password needs to be 6 characters or more") } else { passwordValidationError = "" } diff --git a/ui/imports/Utils.qml b/ui/imports/Utils.qml index 87549cc3cd..38cd90b22e 100644 --- a/ui/imports/Utils.qml +++ b/ui/imports/Utils.qml @@ -197,4 +197,31 @@ QtObject { default: return network } } + + function validate(item, firstPasswordField, repeatPasswordField) { + console.log("validate"); + switch (item) { + case "first": + if (firstPasswordField.text === "") { + //% "You need to enter a password" + return [false, qsTrId("you-need-to-enter-a-password")]; + } else if (firstPasswordField.text.length < 6) { + return [false, qsTrId("Password needs to be 6 characters or more")]; + } + return [true, ""]; + + case "repeat": + if (repeatPasswordField.text === "") { + //% "You need to repeat your password" + return [false, qsTrId("you-need-to-repeat-your-password")]; + } else if (repeatPasswordField.text !== firstPasswordField.text) { + //% Both passwords must match + return [true, qsTrId("both-passwords-must-match")]; + } + return [true, ""]; + + default: + return [false, ""]; + } + } } diff --git a/ui/onboarding/CreatePasswordModal.qml b/ui/onboarding/CreatePasswordModal.qml index b9bf278052..fd9df3c9ba 100644 --- a/ui/onboarding/CreatePasswordModal.qml +++ b/ui/onboarding/CreatePasswordModal.qml @@ -7,33 +7,11 @@ import "../shared/status" ModalPopup { property bool loading: false + property bool firstPasswordFieldValid: false + property bool repeatPasswordFieldValid: false property string passwordValidationError: "" property string repeatPasswordValidationError: "" - function validate() { - if (firstPasswordField.text === "") { - //% "You need to enter a password" - passwordValidationError = qsTrId("you-need-to-enter-a-password") - } else if (firstPasswordField.text.length < 4) { - //% "Password needs to be 4 characters or more" - passwordValidationError = qsTrId("password-needs-to-be-4-characters-or-more") - } else { - passwordValidationError = "" - } - - if (repeatPasswordField.text === "") { - //% "You need to repeat your password" - repeatPasswordValidationError = qsTrId("you-need-to-repeat-your-password") - } else if (repeatPasswordField.text !== firstPasswordField.text) { - //% "Both passwords must match" - repeatPasswordValidationError = qsTrId("both-passwords-must-match") - } else { - repeatPasswordValidationError = "" - } - - return passwordValidationError === "" && repeatPasswordValidationError === "" - } - id: popup //% "Create a password" title: qsTrId("intro-wizard-title-alt4") @@ -54,10 +32,15 @@ ModalPopup { placeholderText: qsTrId("new-password...") textField.echoMode: TextInput.Password validationError: popup.passwordValidationError + onTextChanged: { + [firstPasswordFieldValid, passwordValidationError] = + Utils.validate("first", firstPasswordField, repeatPasswordField); + } } Input { id: repeatPasswordField + enabled: firstPasswordFieldValid anchors.rightMargin: 0 anchors.leftMargin: 0 anchors.right: firstPasswordField.right @@ -71,6 +54,10 @@ ModalPopup { Keys.onReturnPressed: { submitBtn.clicked() } + onTextChanged: { + [repeatPasswordFieldValid, repeatPasswordValidationError] = + Utils.validate("repeat", firstPasswordField, repeatPasswordField); + } } StyledText { @@ -103,7 +90,7 @@ ModalPopup { //% "Create password" text: qsTrId("create-password") - enabled: firstPasswordField.text !== "" && repeatPasswordField.text !== "" && !loading + enabled: firstPasswordFieldValid && repeatPasswordFieldValid && !loading MessageDialog { id: importError @@ -144,10 +131,6 @@ ModalPopup { } onClicked: { - if (!validate()) { - errorSound.play() - return - } loading = true loginModel.isCurrentFlow = false; onboardingModel.isCurrentFlow = true; diff --git a/ui/shared/TransactionSigner.qml b/ui/shared/TransactionSigner.qml index b3f6d45799..47ce3cfa01 100644 --- a/ui/shared/TransactionSigner.qml +++ b/ui/shared/TransactionSigner.qml @@ -13,8 +13,7 @@ Item { property alias validationError: txtPassword.validationError //% "You need to enter a password" property string noInputErrorMessage: qsTrId("you-need-to-enter-a-password") - //% "Password needs to be 4 characters or more" - property string invalidInputErrorMessage: qsTrId("password-needs-to-be-4-characters-or-more") + property string invalidInputErrorMessage: qsTr("Password needs to be 6 characters or more") property bool isValid: false function forceActiveFocus(reason) { @@ -26,7 +25,7 @@ Item { const noInput = txtPassword.text === "" if (noInput) { txtPassword.validationError = noInputErrorMessage - } else if (txtPassword.text.length < 4) { + } else if (txtPassword.text.length < 6) { txtPassword.validationError = invalidInputErrorMessage } isValid = txtPassword.validationError === ""