2020-08-06 07:25:53 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
import QtGraphicalEffects 1.13
|
|
|
|
import "../imports"
|
2020-09-09 11:04:01 +00:00
|
|
|
import "../shared"
|
2020-08-06 07:25:53 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
property string validationError: "Error"
|
2020-09-14 12:12:47 +00:00
|
|
|
//% "ENS Username not found"
|
|
|
|
property string ensAsyncValidationError: qsTrId("ens-username-not-found")
|
2021-04-13 17:49:24 +00:00
|
|
|
property alias input: contactFieldAndList.chatKey
|
2020-08-06 07:25:53 +00:00
|
|
|
property string selectedAddress
|
2020-08-20 04:45:29 +00:00
|
|
|
property var isValid: false
|
2021-04-13 17:49:24 +00:00
|
|
|
property alias isPending: contactFieldAndList.loading
|
2020-10-28 07:44:09 +00:00
|
|
|
property bool isResolvedAddress: false
|
2021-04-13 17:49:24 +00:00
|
|
|
property int parentWidth
|
2020-08-06 07:25:53 +00:00
|
|
|
|
2021-04-13 17:49:24 +00:00
|
|
|
height: contactFieldAndList.chatKey.height
|
2020-08-06 07:25:53 +00:00
|
|
|
|
2020-10-28 07:44:09 +00:00
|
|
|
onSelectedAddressChanged: validate()
|
|
|
|
|
2020-08-20 04:45:29 +00:00
|
|
|
function resetInternal() {
|
|
|
|
selectedAddress = ""
|
2021-04-13 17:49:24 +00:00
|
|
|
contactFieldAndList.chatKey.resetInternal()
|
2020-08-20 04:45:29 +00:00
|
|
|
metrics.text = ""
|
|
|
|
isValid = false
|
2020-10-28 07:44:09 +00:00
|
|
|
isPending = false
|
|
|
|
isResolvedAddress = false
|
|
|
|
}
|
|
|
|
|
|
|
|
function validate() {
|
2021-04-13 17:49:24 +00:00
|
|
|
let isValidEns = Utils.isValidEns(input.text)
|
2020-10-28 07:44:09 +00:00
|
|
|
let isValidAddress = Utils.isValidAddress(selectedAddress)
|
|
|
|
let isValid = (isValidEns && !isResolvedAddress) || isPending || isValidAddress
|
2021-04-13 17:49:24 +00:00
|
|
|
contactFieldAndList.chatKey.validationError = ""
|
|
|
|
if (!isValid && input.text !== "") {
|
|
|
|
contactFieldAndList.chatKey.validationError = isResolvedAddress ? ensAsyncValidationError : validationError
|
2020-10-28 07:44:09 +00:00
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
root.isValid = isValid
|
2020-08-06 07:25:53 +00:00
|
|
|
return isValid
|
|
|
|
}
|
|
|
|
|
2021-04-13 17:49:24 +00:00
|
|
|
ContactsListAndSearch {
|
|
|
|
id: contactFieldAndList
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
showContactList: false
|
|
|
|
onUserClicked: function (isContact, pubKey, ensName, address) {
|
|
|
|
chatKey.text = address
|
|
|
|
}
|
|
|
|
searchResultsWidth: parentWidth
|
|
|
|
chatKey.customHeight: 56
|
|
|
|
chatKey.onFocusChanged: {
|
|
|
|
root.validate()
|
|
|
|
if (chatKey.text !== "" && Utils.isValidAddress(metrics.text)) {
|
|
|
|
if (chatKey.focus) {
|
|
|
|
chatKey.text = metrics.text
|
2020-10-28 07:44:09 +00:00
|
|
|
} else {
|
2021-04-13 17:49:24 +00:00
|
|
|
chatKey.text = metrics.elidedText
|
2020-10-28 07:44:09 +00:00
|
|
|
}
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-13 17:49:24 +00:00
|
|
|
chatKey.onTextChanged: {
|
|
|
|
metrics.text = chatKey.text
|
|
|
|
if (Utils.isValidAddress(chatKey.text)) {
|
|
|
|
root.selectedAddress = chatKey.text
|
|
|
|
} else {
|
|
|
|
root.selectedAddress = ""
|
|
|
|
}
|
|
|
|
}
|
2020-08-06 07:25:53 +00:00
|
|
|
TextMetrics {
|
|
|
|
id: metrics
|
|
|
|
elideWidth: 97
|
|
|
|
elide: Text.ElideMiddle
|
|
|
|
}
|
2020-09-09 11:04:01 +00:00
|
|
|
}
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;autoSize:true;height:480;width:640}
|
|
|
|
}
|
|
|
|
##^##*/
|