fix(@desktop/wallet); Refresh transaction wallet address

This commit is contained in:
Emil Sawicki 2023-05-22 12:16:39 +02:00 committed by Iuri Matias
parent 4da388b5bc
commit f42f48b247
9 changed files with 236 additions and 54 deletions

View File

@ -37,6 +37,7 @@ QtObject:
result &= fmt"""[{i}]:({$self.items[i]})"""
proc countChanged(self: Model) {.signal.}
proc itemChanged(self: Model, address: string) {.signal.}
proc getCount*(self: Model): int {.slot.} =
self.items.len
@ -68,6 +69,9 @@ QtObject:
self.endResetModel()
self.countChanged()
for item in items:
self.itemChanged(item.address())
method data(self: Model, index: QModelIndex, role: int): QVariant =
if (not index.isValid):
return
@ -103,3 +107,15 @@ QtObject:
if(cmpIgnoreCase(item.address(), address) == 0):
return item.name()
return ""
proc getEmojiByAddress*(self: Model, address: string): string =
for item in self.items:
if(cmpIgnoreCase(item.address(), address) == 0):
return item.emoji()
return ""
proc getColorByAddress*(self: Model, address: string): string =
for item in self.items:
if(cmpIgnoreCase(item.address(), address) == 0):
return item.color()
return ""

View File

@ -47,4 +47,10 @@ QtObject:
self.delegate.updateAccount(address, accountName, color, emoji)
proc getNameByAddress(self: View, address: string): string {.slot.}=
return self.accounts.getNameByAddress(address)
return self.accounts.getNameByAddress(address)
proc getEmojiByAddress(self: View, address: string): string {.slot.}=
return self.accounts.getEmojiByAddress(address)
proc getColorByAddress(self: View, address: string): string {.slot.}=
return self.accounts.getColorByAddress(address)

View File

@ -32,6 +32,7 @@ QtObject:
result &= fmt"""[{i}]:({$self.items[i]})"""
proc countChanged(self: Model) {.signal.}
proc itemChanged(self: Model, address: string) {.signal.}
proc getCount*(self: Model): int {.slot.} =
self.items.len
@ -95,6 +96,9 @@ QtObject:
self.endResetModel()
self.countChanged()
for item in items:
self.itemChanged(item.getAddress())
proc getNameByAddress*(self: Model, address: string): string =
for item in self.items:
if(cmpIgnoreCase(item.getAddress(), address) == 0):

View File

@ -62,7 +62,7 @@ SplitView {
name: "",
alias: "",
localNickname: "",
isContact: true
isContact: d.isContact
})
}
function isEnsVerified(publicKey) { return false }
@ -82,8 +82,48 @@ SplitView {
property string addressPrefixString: "eth:opt:arb:"
property string addressName: "Ariana Pearlona"
property bool isContact: true
property bool isWallet: false
property bool isSavedAccount: false
property bool showPrefix: true
property bool showAddressName: true
readonly property string displayAddress: (d.showPrefix ? d.addressPrefixString : "") + "0x29D7d1dd5B6f9C864d9db560D72a247c178aE86B"
}
QtObject {
id: contactsStoreMockup
readonly property var myContactsModel: QtObject {
signal itemChanged(address: string)
}
function getContactPublicKeyByAddress(address) {
return d.isContact ? "zQ3shWU7xpM5YoG19KP5JDRiSs1AdWtjpnrWEerMkxfQnYo7x" : ""
}
}
QtObject {
id: rootStoreMockup
readonly property var accounts: QtObject {
signal itemChanged(address: string)
}
readonly property var savedAddresses: QtObject {
readonly property var sourceModel: QtObject {
signal itemChanged(address: string)
}
}
function getNameForSavedWalletAddress(address) {
return d.isSavedAccount ? d.addressName : ""
}
function getEmojiForWalletAddress(address) {
return '<img class="emoji" draggable="false" alt="??" src="' + Style.emoji("1f61b") + '?72x72" width="16" height="16" style="vertical-align: top"/>'
}
function getColorForWalletAddress(address) {
return "blue"
}
function getNameForWalletAddress(address) {
return d.isWallet ? d.addressName : ""
}
}
Loader {
@ -93,9 +133,9 @@ SplitView {
active: root.globalUtilsReady && root.mainModuleReady
sourceComponent: TransactionAddress {
width: parent.width
address: (d.showPrefix ? d.addressPrefixString : "") + "0x29D7d1dd5B6f9C864d9db560D72a247c178aE86B"
addressName: d.showAddressName ? d.addressName : ""
contactPubKey: d.isContact ? "zQ3shWU7xpM5YoG19KP5JDRiSs1AdWtjpnrWEerMkxfQnYo7x" : ""
address: d.displayAddress
rootStore: rootStoreMockup
contactsStore: contactsStoreMockup
}
}
}
@ -108,10 +148,64 @@ SplitView {
ColumnLayout {
spacing: 5
CheckBox {
text: "is contact"
Label {
text: "Account type"
}
RadioButton {
text: "contact"
checked: d.isContact
onCheckedChanged: d.isContact = checked
onClicked: {
d.isContact = true
d.isWallet = false
d.isSavedAccount = false
rootStoreMockup.accounts.itemChanged(d.displayAddress)
rootStoreMockup.savedAddresses.sourceModel.itemChanged(d.displayAddress)
contactsStoreMockup.myContactsModel.itemChanged(d.displayAddress)
}
}
RadioButton {
text: "wallet"
checked: d.isWallet
onClicked: {
d.isContact = false
d.isWallet = true
d.isSavedAccount = false
rootStoreMockup.accounts.itemChanged(d.displayAddress)
rootStoreMockup.savedAddresses.sourceModel.itemChanged(d.displayAddress)
contactsStoreMockup.myContactsModel.itemChanged(d.displayAddress)
}
}
RadioButton {
text: "saved address"
checked: d.isSavedAccount
onClicked: {
d.isContact = false
d.isWallet = false
d.isSavedAccount = true
rootStoreMockup.accounts.itemChanged(d.displayAddress)
rootStoreMockup.savedAddresses.sourceModel.itemChanged(d.displayAddress)
contactsStoreMockup.myContactsModel.itemChanged(d.displayAddress)
}
}
RadioButton {
text: "unkown"
onClicked: {
d.isContact = false
d.isWallet = false
d.isSavedAccount = false
rootStoreMockup.accounts.itemChanged(d.displayAddress)
rootStoreMockup.savedAddresses.sourceModel.itemChanged(d.displayAddress)
contactsStoreMockup.myContactsModel.itemChanged(d.displayAddress)
}
}
Label {
text: "Name:"
}
RowLayout {
TextField {
text: d.addressName
onTextChanged: d.addressName = text
}
}
Label {
text: "Address prefix:"
@ -127,20 +221,6 @@ SplitView {
onCheckedChanged: d.showPrefix = checked
}
}
Label {
text: "Address name:"
}
RowLayout {
TextField {
text: d.addressName
onTextChanged: d.addressName = text
}
CheckBox {
text: "use"
checked: d.showAddressName
onCheckedChanged: d.showAddressName = checked
}
}
}
}
}

View File

@ -69,6 +69,17 @@ SplitView {
}
}
QtObject {
id: contactsStoreMockup
readonly property var myContactsModel: QtObject {
signal itemChanged(address: string)
}
function getContactPublicKeyByAddress(address) {
return address.includes("0x29D7d1dd5B6f9C864d9db560D72a247c178aE86C") ? "zQ3shWU7xpM5YoG19KP5JDRiSs1AdWtjpnrWEerMkxfQnYo7x" : ""
}
}
QtObject {
id: mockupRootStore
@ -77,6 +88,26 @@ SplitView {
const randomIndex = Math.floor(Math.random() * nameList.length);
return nameList[randomIndex];
}
function getNameForSavedWalletAddress(address) {
if (address.includes("0x4de3f6278C0DdFd3F29df9DcD979038F5c7bbc35")) {
return ""
}
return getNameForAddress(address)
}
function getEmojiForWalletAddress(address) {
return '<img class="emoji" draggable="false" alt="??" src="' + Style.emoji("1f61b") + '?72x72" width="16" height="16" style="vertical-align: top"/>'
}
function getColorForWalletAddress(address) {
return "blue"
}
function getNameForWalletAddress(address) {
if (address.includes("0x4de3f6278C0DdFd3F29df9DcD979038F5c7bbc35") || address.includes("0x4de3f6278C0DdFd3F29df9DcD979038F5c7bbc36")) {
return ""
}
return getNameForAddress(address)
}
}
Loader {
@ -91,6 +122,7 @@ SplitView {
title: "From"
width: parent.width
rootStore: mockupRootStore
contactsStore: contactsStoreMockup
addresses: [
"0x29D7d1dd5B6f9C864d9db560D72a247c178aE86B"
]
@ -99,14 +131,15 @@ SplitView {
title: "To"
width: parent.width
rootStore: mockupRootStore
contactsStore: contactsStoreMockup
addresses: [
"0x29D7d1dd5B6f9C864d9db560D72a247c178aE86B",
"0x29D7d1dd5B6f9C864d9db560D72a247c178aE86C",
"eth:arb:opt:0x4de3f6278C0DdFd3F29df9DcD979038F5c7bbc35",
"0x4de3f6278C0DdFd3F29df9DcD979038F5c7bbc35",
"eth:opt:arb:0x4de3f6278C0DdFd3F29df9DcD979038F5c7bbc35",
"eth:opt:arb:0x29D7d1dd5B6f9C864d9db560D72a247c178aE86B",
"0x29D7d1dd5B6f9C864d9db560D72a247c178aE86B",
"eth:opt:arb:0x4de3f6278C0DdFd3F29df9DcD979038F5c7bbc35"
"eth:opt:arb:0x4de3f6278C0DdFd3F29df9DcD979038F5c7bbc36"
]
}
}

View File

@ -122,4 +122,8 @@ QtObject {
function requestContactInfo(publicKey) {
root.contactsModule.requestContactInfo(publicKey)
}
function getContactPublicKeyByAddress(address) {
return "" // TODO retrive contact public key from address
}
}

View File

@ -187,6 +187,14 @@ QtObject {
return name
}
function getEmojiForWalletAddress(address) {
return walletSectionAccounts.getEmojiByAddress(address)
}
function getColorForWalletAddress(address) {
return walletSectionAccounts.getColorByAddress(address)
}
function createOrUpdateSavedAddress(name, address, favourite, chainShortNames, ens) {
return walletSectionSavedAddresses.createOrUpdateSavedAddress(name, address, favourite, chainShortNames, ens)
}

View File

@ -22,8 +22,6 @@ import utils 1.0
\qml
TransactionAddress {
address: "0x29D7d1dd5B6f9C864d9db560D72a247c208aE86B"
addressName: "Test Name"
contactPubKey: "zQ3shWU7xpM5YoG19KP5JDRiSs1AdWtjpnrWEerMkxfQnYo8x"
}
\endqml
*/
@ -36,22 +34,13 @@ Item {
This property holds wallet address.
*/
property string address
/*!
\qmlproperty string TransactionAddress::addressName
This property holds wallet address name.
If contact public key is not provided this name will be used for display.
*/
property string addressName
/*!
\qmlproperty string TransactionAddress::contactPubKey
This property hold contact public key used to identify contact wallet.
Contact icon will be displayed. Display name take place of \l{addressName}.
*/
property string contactPubKey
/* /internal Property hold reference to contacts store to refresh contact data on any change. */
property var contactsStore
/* /internal Property hold reference to root store to refresh wallet data on any change. */
property var rootStore
/*!
\qmlproperty \l{StatusAssetSettings} TransactionAddress::asset
Property holds asset settings for contact icon.
@ -59,9 +48,17 @@ Item {
property StatusAssetSettings asset: StatusAssetSettings {
width: 36
height: 36
color: Utils.colorForPubkey(root.contactPubKey)
name: isImage ? d.contactData.displayIcon : nameText.text
color: d.isContact ? Utils.colorForPubkey(root.contactPubKey) : d.walletAddressColor
name: {
if (d.isContact) {
return isImage ? d.contactData.displayIcon : nameText.text
} else if (d.isWallet && !d.walletAddressEmoji) {
return "filled-account"
}
return ""
}
isImage: d.isContact && d.contactData.displayIcon.includes("data")
emoji: d.isWallet && !!d.walletAddressEmoji ? d.walletAddressEmoji : ""
isLetterIdenticon: d.isContact && !isImage
charactersLen: 2
}
@ -70,13 +67,53 @@ Item {
QtObject {
id: d
property string contactPubKey: !!root.contactsStore ? root.contactsStore.getContactPublicKeyByAddress(root.address) : ""
readonly property var prefixAndAddress: Utils.splitToChainPrefixAndAddress(root.address)
readonly property bool isContactPubKeyValid: !!root.contactPubKey
readonly property bool isContact: isContactPubKeyValid && contactData.isContact
property var contactData: Utils.getContactDetailsAsJson(root.contactPubKey)
readonly property bool isContact: contactData.isContact
readonly property bool isWallet: !isContact && !!walletAddressName
property var contactData: Utils.getContactDetailsAsJson(d.contactPubKey)
property string savedAddressName: !!root.rootStore ? root.rootStore.getNameForSavedWalletAddress(root.address) : ""
property string walletAddressName: !!root.rootStore ? root.rootStore.getNameForWalletAddress(root.address) : ""
property string walletAddressEmoji: !!root.rootStore ? root.rootStore.getEmojiForWalletAddress(root.address) : ""
property string walletAddressColor: !!root.rootStore ? root.rootStore.getColorForWalletAddress(root.address) : ""
function refreshContactData() {
d.contactData = Utils.getContactDetailsAsJson(root.contactPubKey)
d.contactData = Utils.getContactDetailsAsJson(d.contactPubKey)
}
function refreshSavedAddressName() {
d.savedAddressName = !!root.rootStore ? root.rootStore.getNameForSavedWalletAddress(root.address) : ""
}
function refreshWalletAddress() {
d.walletAddressName = !!root.rootStore ? root.rootStore.getNameForWalletAddress(root.address) : ""
d.walletAddressEmoji = !!root.rootStore ? root.rootStore.getEmojiForWalletAddress(root.address) : ""
d.walletAddressColor = !!root.rootStore ? root.rootStore.getColorForWalletAddress(root.address) : ""
}
function getName() {
let name = ""
if (d.isContact) {
name = ProfileUtils.displayName(d.contactData.localNickname, d.contactData.name, d.contactData.displayName, d.contactData.alias)
}
return name || d.walletAddressName || d.savedAddressName
}
readonly property Connections savedAccountsConnection: Connections {
target: !!root.rootStore && !!root.rootStore.savedAddresses ? root.rootStore.savedAddresses.sourceModel ?? null : null
function onItemChanged(address) {
if (address === root.address)
d.refreshSavedAddressName()
}
}
readonly property Connections walletAccountsConnection: Connections {
target: !!root.rootStore ? root.rootStore.accounts ?? null : null
function onItemChanged(address) {
if (address === root.address)
d.refreshWalletAddress()
}
}
readonly property Connections myContactsModelConnection: Connections {
@ -119,7 +156,7 @@ Item {
ringSpecModel: d.isContact ? Utils.getColorHashAsJson(d.contactData.publicKey) : []
ringPxSize: asset.width / 24
}
visible: d.isContact
visible: d.isContact || d.isWallet
}
ColumnLayout {
@ -132,13 +169,7 @@ Item {
Layout.fillWidth: true
font.pixelSize: 15
color: Theme.palette.directColor1
text: {
let name = ""
if (d.isContact) {
name = ProfileUtils.displayName(d.contactData.localNickname, d.contactData.name, d.contactData.displayName, d.contactData.alias)
}
return name || root.addressName
}
text: d.getName()
visible: !!text
elide: Text.ElideRight
}

View File

@ -107,7 +107,7 @@ StatusListItem {
delegate: TransactionAddress {
width: parent.width
address: modelData
addressName: !!root.rootStore ? root.rootStore.getNameForAddress(address) : ""
rootStore: root.rootStore
contactsStore: root.contactsStore
}
}