[#2376] Removed invalid error message when adding new contact

* Also removed from adding new chat

Closes #2376
This commit is contained in:
Alexandra Betouni 2021-07-13 19:05:44 +03:00 committed by Iuri Matias
parent b31bd265c5
commit d866a9f59e
2 changed files with 52 additions and 44 deletions

View File

@ -135,9 +135,9 @@ Item {
} else if (profileModel.profile.pubKey === value) { } else if (profileModel.profile.pubKey === value) {
addContactModal.validationError = qsTr("You can't add yourself"); addContactModal.validationError = qsTr("You can't add yourself");
} else { } else {
addContactModal.validationError = "" addContactModal.validationError = "";
} }
return addContactModal.validationError === "" return addContactModal.validationError === "";
} }
property var lookupContact: Backpressure.debounce(addContactSearchInput, 400, function (value) { property var lookupContact: Backpressure.debounce(addContactSearchInput, 400, function (value) {
@ -158,13 +158,17 @@ Item {
customHeight: 44 customHeight: 44
fontPixelSize: 15 fontPixelSize: 15
Keys.onReleased: { Keys.onReleased: {
if (!addContactModal.validate(addContactSearchInput.text)) { if (text !== "") {
searchResults.reset() if (!addContactModal.validate(addContactSearchInput.text)) {
contactsContainer.isPending = false searchResults.reset();
return; contactsContainer.isPending = false;
} return;
}
Qt.callLater(addContactModal.lookupContact, addContactSearchInput.text) Qt.callLater(addContactModal.lookupContact, addContactSearchInput.text);
} else {
addContactModal.validationError = "";
}
} }

View File

@ -34,16 +34,16 @@ Item {
function validate() { function validate() {
if (!Utils.isChatKey(chatKey.text) && !Utils.isValidETHNamePrefix(chatKey.text)) { if (!Utils.isChatKey(chatKey.text) && !Utils.isValidETHNamePrefix(chatKey.text)) {
//% "Enter a valid chat key or ENS username" //% "Enter a valid chat key or ENS username"
validationError = qsTrId("enter-a-valid-chat-key-or-ens-username"); root.validationError = "enter-a-valid-chat-key-or-ens-username";
pubKey = "" pubKey = ""
ensUsername = ""; ensUsername = "";
} else if (profileModel.profile.pubKey === chatKey.text) { } else if (profileModel.profile.pubKey === chatKey.text) {
//% "Can't chat with yourself" //% "Can't chat with yourself"
validationError = qsTrId("can-t-chat-with-yourself"); root.validationError = qsTrId("can-t-chat-with-yourself");
} else { } else {
validationError = "" root.validationError = "";
} }
return validationError === "" return root.validationError === "";
} }
Input { Input {
@ -51,35 +51,39 @@ Item {
//% "Enter ENS username or chat key" //% "Enter ENS username or chat key"
placeholderText: qsTrId("enter-contact-code") placeholderText: qsTrId("enter-contact-code")
Keys.onReleased: { Keys.onReleased: {
successMessage = "" successMessage = "";
searchResults.pubKey = "" searchResults.pubKey = "";
if (!validate()) { if (chatKey.text !== "") {
searchResults.showProfileNotFoundMessage = false if (!validate()) {
noContactsRect.visible = false searchResults.showProfileNotFoundMessage = false;
return; noContactsRect.visible = false;
} return;
chatKey.text = chatKey.text.trim();
if (Utils.isChatKey(chatKey.text)){
pubKey = chatKey.text;
if (!profileModel.contacts.isAdded(pubKey)) {
searchResults.username = utilsModel.generateAlias(pubKey)
searchResults.userAlias = Utils.compactAddress(pubKey, 4)
searchResults.pubKey = pubKey
} }
noContactsRect.visible = false
return;
}
Qt.callLater(resolveENS, chatKey.text) chatKey.text = chatKey.text.trim();
if (Utils.isChatKey(chatKey.text)) {
pubKey = chatKey.text;
if (!profileModel.contacts.isAdded(pubKey)) {
searchResults.username = utilsModel.generateAlias(pubKey);
searchResults.userAlias = Utils.compactAddress(pubKey, 4);
searchResults.pubKey = pubKey
}
noContactsRect.visible = false;
return;
}
Qt.callLater(resolveENS, chatKey.text);
} else {
root.validationError = "";
}
} }
textField.anchors.rightMargin: clearBtn.width + Style.current.padding + 2 textField.anchors.rightMargin: clearBtn.width + Style.current.padding + 2
Connections { Connections {
target: chatsModel.ensView target: chatsModel.ensView
onEnsWasResolved: { onEnsWasResolved: {
if(chatKey.text == ""){ if (chatKey.text == "") {
ensUsername.text = ""; ensUsername.text = "";
pubKey = ""; pubKey = "";
} else if(resolvedPubKey == ""){ } else if(resolvedPubKey == ""){
@ -90,7 +94,7 @@ Item {
} else { } else {
if (profileModel.profile.pubKey === resolvedPubKey) { if (profileModel.profile.pubKey === resolvedPubKey) {
//% "Can't chat with yourself" //% "Can't chat with yourself"
validationError = qsTrId("can-t-chat-with-yourself"); root.validationError = qsTrId("can-t-chat-with-yourself");
} else { } else {
searchResults.username = chatsModel.ensView.formatENSUsername(chatKey.text) searchResults.username = chatsModel.ensView.formatENSUsername(chatKey.text)
let userAlias = utilsModel.generateAlias(resolvedPubKey) let userAlias = utilsModel.generateAlias(resolvedPubKey)
@ -119,23 +123,23 @@ Item {
anchors.rightMargin: Style.current.padding anchors.rightMargin: Style.current.padding
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
onClicked: { onClicked: {
chatKey.text = "" chatKey.text = "";
chatKey.forceActiveFocus(Qt.MouseFocusReason) chatKey.forceActiveFocus(Qt.MouseFocusReason);
searchResults.showProfileNotFoundMessage = false searchResults.showProfileNotFoundMessage = false;
searchResults.pubKey = pubKey = "" searchResults.pubKey = pubKey = "";
noContactsRect.visible = false noContactsRect.visible = false;
searchResults.loading = false searchResults.loading = false;
validationError = "" root.validationError = "";
} }
} }
} }
StyledText { StyledText {
id: message id: message
text: validationError || successMessage text: root.validationError || successMessage
visible: validationError !== "" || successMessage !== "" visible: root.validationError !== "" || successMessage !== ""
font.pixelSize: 13 font.pixelSize: 13
color: !!validationError ? Style.current.danger : Style.current.success color: !!root.validationError ? Style.current.danger : Style.current.success
anchors.top: chatKey.bottom anchors.top: chatKey.bottom
anchors.topMargin: Style.current.smallPadding anchors.topMargin: Style.current.smallPadding
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter