fix: 1-on-1 send tx recipient show in tx preview

We were previously displaying an address in the "to" field for TransactionPreview. Instead, this is meant to be a contact view.
- Fix ContactSelector to trigger selectedContactChanged
- Fix RecipientSelector > ContactSelector to trigger resolveEns from outside call to prevent infinite loop from the above fix
- Add alias to pre-selected contact for the Contact view of TransactionPreview
- Add option to change debounce delay so that when values are pre-selected (readonly), there is no delay before resolution.
- Fix missing tx data param in walletModel.estimateGas
This commit is contained in:
emizzle 2020-10-30 10:08:07 +11:00 committed by Iuri Matias
parent 968477b43f
commit 76e7897e8d
7 changed files with 44 additions and 16 deletions

View File

@ -62,6 +62,17 @@ QtObject:
QtProperty[bool] ensVerified:
read = ensVerified
notify = contactsUpdated
proc alias*(self: ChatItemView): string {.slot.} =
if self.chatItem != nil and
self.chatItem.chatType.isOneToOne and
self.status.chat.contacts.hasKey(self.chatItem.id):
return self.status.chat.contacts[self.chatItem.id].alias
result = ""
QtProperty[string] alias:
read = alias
notify = contactsUpdated
proc color*(self: ChatItemView): string {.slot.} = result = ?.self.chatItem.color

View File

@ -259,6 +259,7 @@ StackLayout {
selectRecipient.selectedRecipient: {
return {
address: Constants.zeroAddress, // Setting as zero address since we don't have the address yet
alias: chatsModel.activeChannel.alias,
identicon: chatsModel.activeChannel.identicon,
name: chatsModel.activeChannel.name,
type: RecipientSelector.Type.Contact
@ -270,6 +271,7 @@ StackLayout {
selectRecipient.selectedRecipient = Qt.binding(function() {
return {
address: Constants.zeroAddress, // Setting as zero address since we don't have the address yet
alias: chatsModel.activeChannel.alias,
identicon: chatsModel.activeChannel.identicon,
name: chatsModel.activeChannel.name,
type: RecipientSelector.Type.Contact
@ -294,6 +296,7 @@ StackLayout {
selectRecipient.selectedRecipient: {
return {
address: Constants.zeroAddress, // Setting as zero address since we don't have the address yet
alias: chatsModel.activeChannel.alias,
identicon: chatsModel.activeChannel.identicon,
name: chatsModel.activeChannel.name,
type: RecipientSelector.Type.Contact
@ -305,6 +308,7 @@ StackLayout {
selectRecipient.selectedRecipient = Qt.binding(function() {
return {
address: Constants.zeroAddress, // Setting as zero address since we don't have the address yet
alias: chatsModel.activeChannel.alias,
identicon: chatsModel.activeChannel.identicon,
name: chatsModel.activeChannel.name,
type: RecipientSelector.Type.Contact
@ -326,25 +330,27 @@ StackLayout {
selectRecipient.selectedRecipient: {
return {
address: "",
alias: chatsModel.activeChannel.alias,
identicon: chatsModel.activeChannel.identicon,
name: chatsModel.activeChannel.name,
type: RecipientSelector.Type.Address,
type: RecipientSelector.Type.Contact,
ensVerified: true
}
}
selectRecipient.selectedType: RecipientSelector.Type.Address
selectRecipient.selectedType: RecipientSelector.Type.Contact
onReset: {
selectRecipient.readOnly = true
selectRecipient.selectedRecipient = Qt.binding(function() {
return {
address: "",
alias: chatsModel.activeChannel.alias,
identicon: chatsModel.activeChannel.identicon,
name: chatsModel.activeChannel.name,
type: RecipientSelector.Type.Address,
type: RecipientSelector.Type.Contact,
ensVerified: true
}
})
selectRecipient.selectedType = RecipientSelector.Type.Address
selectRecipient.selectedType = RecipientSelector.Type.Contact
}
}
}

View File

@ -139,7 +139,8 @@ ModalPopup {
selectFromAccount.selectedAccount.address,
selectRecipient.selectedRecipient.address,
txtAmount.selectedAsset.address,
txtAmount.selectedAmount))
txtAmount.selectedAmount,
""))
if (!gasEstimate.success) {
//% "Error estimating gas: %1"

View File

@ -95,6 +95,7 @@ Item {
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

View File

@ -32,6 +32,13 @@ Item {
isResolvedAddress = false
}
function resolveEns() {
if (selectedContact.ensVerified) {
root.isResolvedAddress = false
ensResolver.resolveEns(selectedContact.name)
}
}
onContactsChanged: {
if (root.readOnly) {
return
@ -39,13 +46,7 @@ Item {
root.selectedContact = { name: selectAContact }
}
onSelectedContactChanged: {
if (selectedContact && selectedContact.ensVerified) {
root.isResolvedAddress = false
ensResolver.resolveEns(selectedContact.name)
}
validate()
}
onSelectedContactChanged: validate()
function validate() {
if (!selectedContact) {
@ -138,11 +139,12 @@ Item {
anchors.top: select.bottom
anchors.right: select.right
anchors.topMargin: Style.current.halfPadding
debounceDelay: root.readOnly ? 0 : 600
onResolved: {
root.isResolvedAddress = true
const { name, alias, isContact, identicon, ensVerified } = root.selectedContact
root.selectedContact = { address: resolvedAddress, name, alias, isContact, identicon, ensVerified }
validate()
var selectedContact = root.selectedContact
selectedContact.address = resolvedAddress
root.selectedContact = selectedContact
}
onIsPendingChanged: {
if (isPending) {
@ -228,6 +230,7 @@ Item {
anchors.fill: itemContainer
onClicked: {
root.selectedContact = { address, name, alias, isContact, identicon, ensVerified }
resolveEns()
select.menu.close()
}
}

View File

@ -8,7 +8,8 @@ Item {
id: root
property bool isPending: false
readonly property string uuid: Utils.uuid()
readonly property var validateAsync: Backpressure.debounce(inpAddress, 600, function (inputValue) {
property int debounceDelay: 600
readonly property var validateAsync: Backpressure.debounce(inpAddress, debounceDelay, function (inputValue) {
root.isPending = true
var name = inputValue.startsWith("@") ? inputValue.substring(1) : inputValue
walletModel.resolveENS(name, uuid)

View File

@ -113,6 +113,11 @@ Item {
break
case RecipientSelector.Type.Contact:
selContact.selectedContact = selectedRecipient
// TODO: we shouldn't have to call resolveEns from the outside.
// It should be handled automatically when selectedContact is
// updated, however, handling it on property change causes an
// infinite loop
selContact.resolveEns()
selContact.visible = true
inpAddress.visible = selAccount.visible = false
break