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
This commit is contained in:
Stefan 2022-08-29 19:02:36 +01:00 committed by Stefan Dunca
parent 41910c9a8a
commit b499942eea
4 changed files with 35 additions and 24 deletions

View File

@ -186,7 +186,7 @@ Item {
selectedDerivedAddress.pathSubFix = actualIndex selectedDerivedAddress.pathSubFix = actualIndex
selectedDerivedAddress.hasActivity = element.hasActivity selectedDerivedAddress.hasActivity = element.hasActivity
derivedAddressPopup.close() derivedAddressPopup.close()
} }
Component.onCompleted: { Component.onCompleted: {
if(RootStore.derivedAddressesList.count === 1 && index === 0) { if(RootStore.derivedAddressesList.count === 1 && index === 0) {
selectedDerivedAddress.title = title selectedDerivedAddress.title = title

View File

@ -17,27 +17,28 @@ ColumnLayout {
property bool valid: privateKey.valid property bool valid: privateKey.valid
function resetMe() { function resetMe() {
_internal.errorString = "" d.errorString = ""
privateKey.text = "" privateKey.text = ""
privateKey.reset() privateKey.reset()
} }
function validateMe() { function validateMe() {
if (privateKey.text === "") { 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)) { } 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 { } else {
_internal.errorString = "" d.errorString = ""
} }
return _internal.errorString === "" return d.errorString === "" && !d.invalidPrivateKeyError
} }
QtObject { QtObject {
id: _internal id: d
property int privateKeyCharLimit: 66 readonly property int privateKeyCharLimit: 66
property string errorString: "" 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 spacing: 24
@ -46,12 +47,12 @@ ColumnLayout {
id: privateKey id: privateKey
label: qsTr("Private key") label: qsTr("Private key")
charLimit: _internal.privateKeyCharLimit charLimit: d.privateKeyCharLimit
input.multiline: true input.multiline: true
minimumHeight: 80 minimumHeight: 80
maximumHeight: 108 maximumHeight: 108
placeholderText: qsTr("Paste the contents of your private key") placeholderText: qsTr("Paste the contents of your private key")
errorMessage: _internal.errorString errorMessage: d.errorString
validators: [ validators: [
StatusMinLengthValidator { StatusMinLengthValidator {
minLength: 1 minLength: 1
@ -64,6 +65,20 @@ ColumnLayout {
errorMessage: qsTr("Enter a valid private key (64 characters hexadecimal string)") 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: { onTextChanged: {
if(valid) { if(valid) {
RootStore.getDerivedAddressForPrivateKey(text) RootStore.getDerivedAddressForPrivateKey(text)
@ -95,10 +110,10 @@ ColumnLayout {
icon.background.color: "transparent" icon.background.color: "transparent"
border.width: 1 border.width: 1
border.color: Theme.palette.baseColor2 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 statusListItemSubTitle.color: derivedAddress.hasActivity ? Theme.palette.primaryColor1 : Theme.palette.baseColor1
title: _internal.accountAreadyAddedError ? qsTr("Account already added") : RootStore.derivedAddressesLoading ? qsTr("Pending") : derivedAddress.address title: d.accountAreadyAddedError ? qsTr("Account already added") : RootStore.derivedAddressesLoading ? qsTr("Pending") : derivedAddress.address
subTitle: RootStore.derivedAddressesLoading || _internal.accountAreadyAddedError ? "" : derivedAddress.hasActivity ? qsTr("Has Activity"): qsTr("No Activity") subTitle: RootStore.derivedAddressesLoading || d.accountAreadyAddedError ? "" : derivedAddress.hasActivity ? qsTr("Has Activity"): qsTr("No Activity")
sensor.enabled: false sensor.enabled: false
} }
} }

View File

@ -32,13 +32,6 @@ StatusModal {
signal afterAddAccount() signal afterAddAccount()
MessageDialog {
id: accountError
title: qsTr("Adding the account failed")
icon: StandardIcon.Critical
standardButtons: StandardButton.Ok
}
Timer { Timer {
id: waitTimer id: waitTimer
@ -98,8 +91,7 @@ StatusModal {
d.passwordValidationError = qsTr("Wrong password") d.passwordValidationError = qsTr("Wrong password")
scroll.contentY = -scroll.padding scroll.contentY = -scroll.padding
} else { } else {
accountError.text = errMessage console.warn(`Unhandled error case. Status-go message: ${errMessage}`)
accountError.open()
} }
} }
} }

View File

@ -685,6 +685,10 @@ QtObject {
); );
} }
function isInvalidPrivateKey(msg) {
return msg.includes("invalid private key");
}
function isInvalidPath(msg) { function isInvalidPath(msg) {
return msg.includes("error parsing derivation path") return msg.includes("error parsing derivation path")
} }