feat: improve ens search in wallet send by showing the result
This commit is contained in:
parent
57ac94c4ac
commit
1983fa79aa
|
@ -84,7 +84,7 @@ proc asyncMessageLoad[T](self: T, slot: string, chatId: string) =
|
|||
const resolveEnsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let
|
||||
arg = decode[ResolveEnsTaskArg](argEncoded)
|
||||
output = status_ens.pubkey(arg.ens)
|
||||
output = %* { "address": status_ens.address(arg.ens), "pubkey": status_ens.pubkey(arg.ens) }
|
||||
arg.finish(output)
|
||||
|
||||
proc resolveEns[T](self: T, slot: string, ens: string) =
|
||||
|
@ -729,10 +729,14 @@ QtObject:
|
|||
proc resolveENS*(self: ChatsView, ens: string) {.slot.} =
|
||||
self.resolveEns("ensResolved", ens) # Call self.ensResolved(string) when ens is resolved
|
||||
|
||||
proc ensWasResolved*(self: ChatsView, resolvedPubKey: string) {.signal.}
|
||||
proc ensWasResolved*(self: ChatsView, resolvedPubKey: string, resolvedAddress: string) {.signal.}
|
||||
|
||||
proc ensResolved(self: ChatsView, pubKey: string) {.slot.} =
|
||||
self.ensWasResolved(pubKey)
|
||||
proc ensResolved(self: ChatsView, addressPubkeyJson: string) {.slot.} =
|
||||
var
|
||||
parsed = addressPubkeyJson.parseJson
|
||||
address = parsed["address"].to(string)
|
||||
pubkey = parsed["pubkey"].to(string)
|
||||
self.ensWasResolved(pubKey, address)
|
||||
|
||||
proc isConnected*(self: ChatsView): bool {.slot.} =
|
||||
result = self.status.network.isConnected
|
||||
|
|
|
@ -119,3 +119,4 @@ QtObject:
|
|||
close(f)
|
||||
else:
|
||||
raise newException(IOError, "cannot open: " & filename)
|
||||
|
|
@ -280,7 +280,7 @@ RowLayout {
|
|||
id: toastMessage
|
||||
}
|
||||
|
||||
// Add SenmdModal here as it is used by the Wallet as well as the Browser
|
||||
// Add SendModal here as it is used by the Wallet as well as the Browser
|
||||
Loader {
|
||||
id: sendModal
|
||||
|
||||
|
|
|
@ -10,32 +10,20 @@ Item {
|
|||
property string validationError: "Error"
|
||||
//% "ENS Username not found"
|
||||
property string ensAsyncValidationError: qsTrId("ens-username-not-found")
|
||||
property alias label: inpAddress.label
|
||||
property alias text: inpAddress.text
|
||||
property alias input: contactFieldAndList.chatKey
|
||||
property string selectedAddress
|
||||
property var isValid: false
|
||||
property alias isPending: ensResolver.isPending
|
||||
property alias readOnly: inpAddress.readOnly
|
||||
property alias isPending: contactFieldAndList.loading
|
||||
property bool isResolvedAddress: false
|
||||
property int parentWidth
|
||||
|
||||
height: inpAddress.height
|
||||
height: contactFieldAndList.chatKey.height
|
||||
|
||||
onSelectedAddressChanged: validate()
|
||||
onTextChanged: {
|
||||
metrics.text = text
|
||||
root.isResolvedAddress = false
|
||||
if (Utils.isValidAddress(text)) {
|
||||
root.selectedAddress = text
|
||||
} else {
|
||||
root.selectedAddress = ""
|
||||
root.validate()
|
||||
}
|
||||
ensResolver.resolveEns(text)
|
||||
}
|
||||
|
||||
function resetInternal() {
|
||||
selectedAddress = ""
|
||||
inpAddress.resetInternal()
|
||||
contactFieldAndList.chatKey.resetInternal()
|
||||
metrics.text = ""
|
||||
isValid = false
|
||||
isPending = false
|
||||
|
@ -43,72 +31,50 @@ Item {
|
|||
}
|
||||
|
||||
function validate() {
|
||||
let isValidEns = Utils.isValidEns(text)
|
||||
let isValidEns = Utils.isValidEns(input.text)
|
||||
let isValidAddress = Utils.isValidAddress(selectedAddress)
|
||||
let isValid = (isValidEns && !isResolvedAddress) || isPending || isValidAddress
|
||||
inpAddress.validationError = ""
|
||||
if (!isValid){
|
||||
inpAddress.validationError = isResolvedAddress ? ensAsyncValidationError : validationError
|
||||
contactFieldAndList.chatKey.validationError = ""
|
||||
if (!isValid && input.text !== "") {
|
||||
contactFieldAndList.chatKey.validationError = isResolvedAddress ? ensAsyncValidationError : validationError
|
||||
}
|
||||
root.isValid = isValid
|
||||
return isValid
|
||||
}
|
||||
|
||||
Input {
|
||||
id: inpAddress
|
||||
//% "eg. 0x1234 or ENS"
|
||||
placeholderText: qsTrId("eg--0x1234-or-ens")
|
||||
customHeight: 56
|
||||
validationErrorAlignment: TextEdit.AlignRight
|
||||
validationErrorTopMargin: 8
|
||||
textField.onFocusChanged: {
|
||||
let isValid = true
|
||||
if (text !== "" && Utils.isValidAddress(metrics.text)) {
|
||||
if (textField.focus) {
|
||||
text = metrics.text
|
||||
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
|
||||
} else {
|
||||
text = metrics.elidedText
|
||||
chatKey.text = metrics.elidedText
|
||||
}
|
||||
}
|
||||
}
|
||||
textField.rightPadding: 73
|
||||
chatKey.onTextChanged: {
|
||||
metrics.text = chatKey.text
|
||||
if (Utils.isValidAddress(chatKey.text)) {
|
||||
root.selectedAddress = chatKey.text
|
||||
} else {
|
||||
root.selectedAddress = ""
|
||||
}
|
||||
}
|
||||
TextMetrics {
|
||||
id: metrics
|
||||
elideWidth: 97
|
||||
elide: Text.ElideMiddle
|
||||
}
|
||||
TertiaryButton {
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 8
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 14
|
||||
visible: !root.readOnly
|
||||
//% "Paste"
|
||||
label: qsTrId("paste")
|
||||
onClicked: {
|
||||
if (inpAddress.textField.canPaste) {
|
||||
inpAddress.textField.paste()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EnsResolver {
|
||||
id: ensResolver
|
||||
anchors.top: inpAddress.bottom
|
||||
anchors.right: inpAddress.right
|
||||
anchors.topMargin: Style.current.halfPadding
|
||||
debounceDelay: root.readOnly ? 0 : 600
|
||||
onResolved: {
|
||||
root.isResolvedAddress = true
|
||||
root.selectedAddress = resolvedAddress
|
||||
root.validate()
|
||||
}
|
||||
onIsPendingChanged: {
|
||||
if (isPending) {
|
||||
root.selectedAddress = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,12 @@ Item {
|
|||
property alias existingContacts: existingContacts
|
||||
property alias noContactsRect: noContactsRect
|
||||
property string pubKey : ""
|
||||
property int searchResultsWidth : 0
|
||||
property alias loading : searchResults.loading
|
||||
property string ensUsername : ""
|
||||
property bool showCheckbox: false
|
||||
signal userClicked(bool isContact, string pubKey, string ensName)
|
||||
property bool showContactList: true
|
||||
signal userClicked(bool isContact, string pubKey, string ensName, string address)
|
||||
property var pubKeys: ([])
|
||||
|
||||
id: root
|
||||
|
@ -79,6 +82,7 @@ Item {
|
|||
} else if(resolvedPubKey == ""){
|
||||
ensUsername.text = "";
|
||||
searchResults.pubKey = pubKey = "";
|
||||
searchResults.address = "";
|
||||
searchResults.showProfileNotFoundMessage = true
|
||||
} else {
|
||||
if (profileModel.profile.pubKey === resolvedPubKey) {
|
||||
|
@ -90,6 +94,7 @@ Item {
|
|||
userAlias = userAlias.length > 20 ? userAlias.substring(0, 19) + "..." : userAlias
|
||||
searchResults.userAlias = userAlias + " • " + Utils.compactAddress(resolvedPubKey, 4)
|
||||
searchResults.pubKey = pubKey = resolvedPubKey;
|
||||
searchResults.address = resolvedAddress;
|
||||
}
|
||||
searchResults.showProfileNotFoundMessage = false
|
||||
}
|
||||
|
@ -117,6 +122,7 @@ Item {
|
|||
searchResults.pubKey = pubKey = ""
|
||||
noContactsRect.visible = false
|
||||
searchResults.loading = false
|
||||
validationError = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,6 +140,7 @@ Item {
|
|||
|
||||
ExistingContacts {
|
||||
id: existingContacts
|
||||
visible: showContactList
|
||||
anchors.topMargin: this.height > 0 ? Style.current.xlPadding : 0
|
||||
anchors.top: chatKey.bottom
|
||||
showCheckbox: root.showCheckbox
|
||||
|
@ -152,7 +159,7 @@ Item {
|
|||
}
|
||||
root.pubKeys = pubKeysCopy
|
||||
|
||||
userClicked(true, contact.pubKey, profileModel.contacts.addedContacts.userName(contact.pubKey, contact.name))
|
||||
userClicked(true, contact.pubKey, profileModel.contacts.addedContacts.userName(contact.pubKey, contact.name), contact.address)
|
||||
}
|
||||
expanded: !searchResults.loading && pubKey === "" && !searchResults.showProfileNotFoundMessage
|
||||
}
|
||||
|
@ -163,18 +170,20 @@ Item {
|
|||
anchors.topMargin: Style.current.padding
|
||||
hasExistingContacts: existingContacts.visible
|
||||
loading: false
|
||||
width: searchResultsWidth > 0 ? searchResultsWidth : parent.width
|
||||
|
||||
onResultClicked: {
|
||||
if (!validate()) {
|
||||
return
|
||||
}
|
||||
userClicked(false, pubKey, chatKey.text)
|
||||
userClicked(false, pubKey, chatKey.text, searchResults.address)
|
||||
}
|
||||
onAddToContactsButtonClicked: profileModel.contacts.addContact(pubKey)
|
||||
}
|
||||
|
||||
NoFriendsRectangle {
|
||||
id: noContactsRect
|
||||
visible: showContactList
|
||||
anchors.top: chatKey.bottom
|
||||
anchors.topMargin: Style.current.xlPadding * 3
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
|
|
@ -81,7 +81,7 @@ Item {
|
|||
}
|
||||
switch (root.selectedType) {
|
||||
case RecipientSelector.Type.Address:
|
||||
inpAddress.text = selectedRecipient.name || ""
|
||||
inpAddress.input.text = selectedRecipient.name || ""
|
||||
inpAddress.visible = true
|
||||
selContact.visible = selAccount.visible = false
|
||||
if(!!selectedRecipient.address){
|
||||
|
@ -140,13 +140,14 @@ Item {
|
|||
AddressInput {
|
||||
id: inpAddress
|
||||
width: root.inputWidth
|
||||
label: ""
|
||||
readOnly: root.readOnly
|
||||
input.label: ""
|
||||
input.readOnly: root.readOnly
|
||||
visible: true
|
||||
Layout.preferredWidth: selAddressSource.visible ? root.inputWidth : parent.width
|
||||
Layout.alignment: Qt.AlignTop
|
||||
Layout.fillWidth: true
|
||||
validationError: root.addressValidationError
|
||||
parentWidth: parent.width
|
||||
onSelectedAddressChanged: {
|
||||
if (!selAddressSource.selectedSource || (selAddressSource.selectedSource && selAddressSource.selectedSource.value !== RecipientSelector.Type.Address)) {
|
||||
return
|
||||
|
|
|
@ -17,6 +17,7 @@ Item {
|
|||
property string username: ""
|
||||
property string userAlias: ""
|
||||
property string pubKey: ""
|
||||
property string address: ""
|
||||
property bool resultClickable: true
|
||||
|
||||
signal resultClicked(string pubKey)
|
||||
|
|
Loading…
Reference in New Issue