feat: add validation to seed modal
This commit is contained in:
parent
300caf22a2
commit
051eeea3df
|
@ -18,7 +18,6 @@ ModalPopup {
|
||||||
anchors.rightMargin: Theme.padding
|
anchors.rightMargin: Theme.padding
|
||||||
label: qsTr("Add custom token")
|
label: qsTr("Add custom token")
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.topMargin: Theme.padding
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
popup.close()
|
popup.close()
|
||||||
addCustomTokenModal.open()
|
addCustomTokenModal.open()
|
||||||
|
|
|
@ -8,6 +8,35 @@ ModalPopup {
|
||||||
|
|
||||||
property int marginBetweenInputs: 38
|
property int marginBetweenInputs: 38
|
||||||
property string selectedColor: Constants.accountColors[0]
|
property string selectedColor: Constants.accountColors[0]
|
||||||
|
property string passwordValidationError: ""
|
||||||
|
property string seedValidationError: ""
|
||||||
|
property string accountNameValidationError: ""
|
||||||
|
|
||||||
|
function validate() {
|
||||||
|
if (passwordInput.text === "") {
|
||||||
|
passwordValidationError = qsTr("You need to enter a password")
|
||||||
|
} else if (passwordInput.text.length < 4) {
|
||||||
|
passwordValidationError = qsTr("Password needs to be 4 characters or more")
|
||||||
|
} else {
|
||||||
|
passwordValidationError = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accountNameInput.text === "") {
|
||||||
|
accountNameValidationError = qsTr("You need to enter an account name")
|
||||||
|
} else {
|
||||||
|
accountNameValidationError = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accountSeedInput.text === "") {
|
||||||
|
seedValidationError = qsTr("You need to enter a seed phrase")
|
||||||
|
} else if (!Utils.isMnemonic(accountSeedInput.text)) {
|
||||||
|
seedValidationError = qsTr("Enter a valid mnemonic")
|
||||||
|
} else {
|
||||||
|
seedValidationError = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return passwordValidationError === "" && seedValidationError === "" && accountNameValidationError === ""
|
||||||
|
}
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
passwordInput.text = ""
|
passwordInput.text = ""
|
||||||
|
@ -21,6 +50,7 @@ ModalPopup {
|
||||||
placeholderText: qsTr("Enter your password…")
|
placeholderText: qsTr("Enter your password…")
|
||||||
label: qsTr("Password")
|
label: qsTr("Password")
|
||||||
textField.echoMode: TextInput.Password
|
textField.echoMode: TextInput.Password
|
||||||
|
validationError: popup.passwordValidationError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +61,7 @@ ModalPopup {
|
||||||
placeholderText: qsTr("Enter your seed phrase, separate words with commas or spaces...")
|
placeholderText: qsTr("Enter your seed phrase, separate words with commas or spaces...")
|
||||||
label: qsTr("Seed phrase")
|
label: qsTr("Seed phrase")
|
||||||
customHeight: 88
|
customHeight: 88
|
||||||
|
validationError: popup.seedValidationError
|
||||||
}
|
}
|
||||||
|
|
||||||
Input {
|
Input {
|
||||||
|
@ -39,6 +70,7 @@ ModalPopup {
|
||||||
anchors.topMargin: marginBetweenInputs
|
anchors.topMargin: marginBetweenInputs
|
||||||
placeholderText: qsTr("Enter an account name...")
|
placeholderText: qsTr("Enter an account name...")
|
||||||
label: qsTr("Account name")
|
label: qsTr("Account name")
|
||||||
|
validationError: popup.accountNameValidationError
|
||||||
}
|
}
|
||||||
|
|
||||||
Select {
|
Select {
|
||||||
|
@ -61,16 +93,16 @@ ModalPopup {
|
||||||
|
|
||||||
footer: StyledButton {
|
footer: StyledButton {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.topMargin: Theme.padding
|
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: Theme.padding
|
anchors.rightMargin: Theme.padding
|
||||||
label: "Add account 00>"
|
label: "Add account >"
|
||||||
|
|
||||||
disabled: passwordInput.text === "" || accountNameInput.text === "" || accountSeedInput.text === ""
|
disabled: passwordInput.text === "" || accountNameInput.text === "" || accountSeedInput.text === ""
|
||||||
|
|
||||||
onClicked : {
|
onClicked : {
|
||||||
// TODO add message to show validation errors
|
if (!validate()) {
|
||||||
if (passwordInput.text === "" || accountNameInput.text === "" || accountSeedInput.text === "") return;
|
return
|
||||||
|
}
|
||||||
|
|
||||||
walletModel.addAccountsFromSeed(accountSeedInput.text, passwordInput.text, accountNameInput.text, selectedColor)
|
walletModel.addAccountsFromSeed(accountSeedInput.text, passwordInput.text, accountNameInput.text, selectedColor)
|
||||||
// TODO manage errors adding account
|
// TODO manage errors adding account
|
||||||
|
|
|
@ -23,4 +23,9 @@ QtObject {
|
||||||
return isHex(value) && ((startsWith0x(value) && value.length === 66) ||
|
return isHex(value) && ((startsWith0x(value) && value.length === 66) ||
|
||||||
(!startsWith0x(value) && value.length === 64))
|
(!startsWith0x(value) && value.length === 64))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isMnemonic(value) {
|
||||||
|
// Do we support other length than 12?
|
||||||
|
return value.split(/\s|,/).length === 12
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue