From b499942eea6218d65a1efc20ca52e204613e6fb2 Mon Sep 17 00:00:00 2001 From: Stefan Date: Mon, 29 Aug 2022 19:02:36 +0100 Subject: [PATCH] fix(Wallet/AddAccountModal): fix status-go error messages Remove the unneeded native error dialog showing internal status-go error strings. Instead redirect the error message for wrong private key as specific error message. Fixes: #6984 --- .../Wallet/panels/DerivedAddressesPanel.qml | 2 +- .../Wallet/panels/ImportPrivateKeyPanel.qml | 43 +++++++++++++------ .../Wallet/popups/AddAccountModal.qml | 10 +---- ui/imports/utils/Utils.qml | 4 ++ 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/ui/app/AppLayouts/Wallet/panels/DerivedAddressesPanel.qml b/ui/app/AppLayouts/Wallet/panels/DerivedAddressesPanel.qml index b0e54935a8..010ffbfe65 100644 --- a/ui/app/AppLayouts/Wallet/panels/DerivedAddressesPanel.qml +++ b/ui/app/AppLayouts/Wallet/panels/DerivedAddressesPanel.qml @@ -186,7 +186,7 @@ Item { selectedDerivedAddress.pathSubFix = actualIndex selectedDerivedAddress.hasActivity = element.hasActivity derivedAddressPopup.close() - } + } Component.onCompleted: { if(RootStore.derivedAddressesList.count === 1 && index === 0) { selectedDerivedAddress.title = title diff --git a/ui/app/AppLayouts/Wallet/panels/ImportPrivateKeyPanel.qml b/ui/app/AppLayouts/Wallet/panels/ImportPrivateKeyPanel.qml index 7b9e160241..830f97a920 100644 --- a/ui/app/AppLayouts/Wallet/panels/ImportPrivateKeyPanel.qml +++ b/ui/app/AppLayouts/Wallet/panels/ImportPrivateKeyPanel.qml @@ -17,27 +17,28 @@ ColumnLayout { property bool valid: privateKey.valid function resetMe() { - _internal.errorString = "" + d.errorString = "" privateKey.text = "" privateKey.reset() } - function validateMe() { + function validateMe() { if (privateKey.text === "") { - _internal.errorString = qsTr("You need to enter a private key") + d.errorString = qsTr("You need to enter a private key") } else if (!Utils.isPrivateKey(privateKey.text)) { - _internal.errorString = qsTr("Enter a valid private key (64 characters hexadecimal string)") + d.errorString = qsTr("Enter a valid private key (64 characters hexadecimal string)") } else { - _internal.errorString = "" + d.errorString = "" } - return _internal.errorString === "" + return d.errorString === "" && !d.invalidPrivateKeyError } QtObject { - id: _internal - property int privateKeyCharLimit: 66 + id: d + readonly property int privateKeyCharLimit: 66 property string errorString: "" - property bool accountAreadyAddedError: Utils.accountAlreadyExistsError(RootStore.derivedAddressesError) + readonly property bool accountAreadyAddedError: Utils.accountAlreadyExistsError(RootStore.derivedAddressesError) + readonly property bool invalidPrivateKeyError: Utils.isInvalidPrivateKey(RootStore.derivedAddressesError) } spacing: 24 @@ -46,12 +47,12 @@ ColumnLayout { id: privateKey label: qsTr("Private key") - charLimit: _internal.privateKeyCharLimit + charLimit: d.privateKeyCharLimit input.multiline: true minimumHeight: 80 maximumHeight: 108 placeholderText: qsTr("Paste the contents of your private key") - errorMessage: _internal.errorString + errorMessage: d.errorString validators: [ StatusMinLengthValidator { minLength: 1 @@ -64,6 +65,20 @@ ColumnLayout { errorMessage: qsTr("Enter a valid private key (64 characters hexadecimal string)") } ] + asyncValidators: [ + StatusAsyncValidator { + id: privateKeyAsyncValidator + Connections { + target: d + function onInvalidPrivateKeyErrorChanged() { + privateKeyAsyncValidator.validationComplete("", !d.invalidPrivateKeyError) + } + } + validate: (value) => !d.invalidPrivateKeyError + name: "asyncPKCheck" + errorMessage: qsTr("Enter a valid private key") + } + ] onTextChanged: { if(valid) { RootStore.getDerivedAddressForPrivateKey(text) @@ -95,10 +110,10 @@ ColumnLayout { icon.background.color: "transparent" border.width: 1 border.color: Theme.palette.baseColor2 - type: _internal.accountAreadyAddedError ? StatusListItem.Type.Danger : StatusListItem.Type.Primary + type: d.accountAreadyAddedError ? StatusListItem.Type.Danger : StatusListItem.Type.Primary statusListItemSubTitle.color: derivedAddress.hasActivity ? Theme.palette.primaryColor1 : Theme.palette.baseColor1 - title: _internal.accountAreadyAddedError ? qsTr("Account already added") : RootStore.derivedAddressesLoading ? qsTr("Pending") : derivedAddress.address - subTitle: RootStore.derivedAddressesLoading || _internal.accountAreadyAddedError ? "" : derivedAddress.hasActivity ? qsTr("Has Activity"): qsTr("No Activity") + title: d.accountAreadyAddedError ? qsTr("Account already added") : RootStore.derivedAddressesLoading ? qsTr("Pending") : derivedAddress.address + subTitle: RootStore.derivedAddressesLoading || d.accountAreadyAddedError ? "" : derivedAddress.hasActivity ? qsTr("Has Activity"): qsTr("No Activity") sensor.enabled: false } } diff --git a/ui/app/AppLayouts/Wallet/popups/AddAccountModal.qml b/ui/app/AppLayouts/Wallet/popups/AddAccountModal.qml index c563ce9e4a..3bcc6a07e9 100644 --- a/ui/app/AppLayouts/Wallet/popups/AddAccountModal.qml +++ b/ui/app/AppLayouts/Wallet/popups/AddAccountModal.qml @@ -32,13 +32,6 @@ StatusModal { signal afterAddAccount() - MessageDialog { - id: accountError - title: qsTr("Adding the account failed") - icon: StandardIcon.Critical - standardButtons: StandardButton.Ok - } - Timer { id: waitTimer @@ -98,8 +91,7 @@ StatusModal { d.passwordValidationError = qsTr("Wrong password") scroll.contentY = -scroll.padding } else { - accountError.text = errMessage - accountError.open() + console.warn(`Unhandled error case. Status-go message: ${errMessage}`) } } } diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index 239993db34..a703db216b 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -685,6 +685,10 @@ QtObject { ); } + function isInvalidPrivateKey(msg) { + return msg.includes("invalid private key"); + } + function isInvalidPath(msg) { return msg.includes("error parsing derivation path") }