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
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-10-14 10:15:43 +00:00
|
|
|
import "."
|
2020-08-06 07:25:53 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
2022-01-04 12:06:05 +00:00
|
|
|
|
|
|
|
property var contactsStore
|
|
|
|
|
2020-08-06 07:25:53 +00:00
|
|
|
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
|
2022-03-01 10:14:13 +00:00
|
|
|
property bool addContactEnabled: true
|
2022-04-13 10:21:12 +00:00
|
|
|
property alias wrongInputValidationError: contactFieldAndList.wrongInputValidationError
|
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
|
2021-07-15 11:12:46 +00:00
|
|
|
width: parent.width
|
2021-04-13 17:49:24 +00:00
|
|
|
showContactList: false
|
2022-03-01 10:14:13 +00:00
|
|
|
addContactEnabled: root.addContactEnabled
|
2022-01-04 12:06:05 +00:00
|
|
|
|
|
|
|
contactsStore: root.contactsStore
|
|
|
|
|
2022-02-03 09:58:33 +00:00
|
|
|
onUserClicked: function (isContact, pubKey, ensName, address) {
|
|
|
|
chatKey.text = address
|
2021-04-13 17:49:24 +00:00
|
|
|
}
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
##^##*/
|