diff --git a/src/app/modules/main/wallet_section/saved_addresses/item.nim b/src/app/modules/main/wallet_section/saved_addresses/item.nim index 6bb82bede4..6374f0e36a 100644 --- a/src/app/modules/main/wallet_section/saved_addresses/item.nim +++ b/src/app/modules/main/wallet_section/saved_addresses/item.nim @@ -1,5 +1,7 @@ import strformat +import app_service/common/account_constants + type Item* = object name: string @@ -38,6 +40,9 @@ proc `$`*(self: Item): string = isTest: {self.isTest}, ]""" +proc isEmpty*(self: Item): bool = + return (self.address.len == 0 or self.address == ZERO_ADDRESS) and self.ens.len == 0 + proc getName*(self: Item): string = return self.name diff --git a/src/app/modules/main/wallet_section/saved_addresses/model.nim b/src/app/modules/main/wallet_section/saved_addresses/model.nim index 4e983d4f96..47d649ed35 100644 --- a/src/app/modules/main/wallet_section/saved_addresses/model.nim +++ b/src/app/modules/main/wallet_section/saved_addresses/model.nim @@ -1,6 +1,7 @@ import NimQml, Tables, strutils, strformat import item +import app_service/common/account_constants export item @@ -107,10 +108,22 @@ QtObject: self.itemChanged(item.getAddress()) proc getItemByAddress*(self: Model, address: string): Item = + if address.len == 0 or address == ZERO_ADDRESS: + return for item in self.items: if cmpIgnoreCase(item.getAddress(), address) == 0: return item + proc getItemByEnsOrAddress*(self: Model, addrOrEns: string): Item = + if addrOrEns.len == 0: + return + for item in self.items: + if item.getEns().len > 0: + if item.getEns() == addrOrEns: + return item + if addrOrEns != ZERO_ADDRESS and cmpIgnoreCase(item.getAddress(), addrOrEns) == 0: + return item + proc nameExists*(self: Model, name: string): bool = for item in self.items: if item.getName() == name: diff --git a/src/app/modules/main/wallet_section/saved_addresses/module.nim b/src/app/modules/main/wallet_section/saved_addresses/module.nim index 8fc0be32b9..59ecb75ff5 100644 --- a/src/app/modules/main/wallet_section/saved_addresses/module.nim +++ b/src/app/modules/main/wallet_section/saved_addresses/module.nim @@ -66,8 +66,11 @@ method deleteSavedAddress*(self: Module, address: string, ens: string) = self.controller.deleteSavedAddress(address, ens) method savedAddressUpdated*(self: Module, name: string, address: string, ens: string, errorMsg: string) = + var item = self.view.getModel().getItemByEnsOrAddress(address) + if item.isEmpty(): + item = self.view.getModel().getItemByEnsOrAddress(ens) self.loadSavedAddresses() - self.view.savedAddressUpdated(name, address, ens, errorMsg) + self.view.savedAddressAddedOrUpdated(item.isEmpty(), name, address, ens, errorMsg) method savedAddressDeleted*(self: Module, address: string, ens: string, errorMsg: string) = self.loadSavedAddresses() diff --git a/src/app/modules/main/wallet_section/saved_addresses/view.nim b/src/app/modules/main/wallet_section/saved_addresses/view.nim index aa0f0daaf1..708d4094ec 100644 --- a/src/app/modules/main/wallet_section/saved_addresses/view.nim +++ b/src/app/modules/main/wallet_section/saved_addresses/view.nim @@ -40,7 +40,7 @@ QtObject: proc setItems*(self: View, items: seq[Item]) = self.model.setItems(items) - proc savedAddressUpdated*(self: View, name: string, address: string, ens: string, errorMsg: string) {.signal.} + proc savedAddressAddedOrUpdated*(self: View, added: bool, name: string, address: string, ens: string, errorMsg: string) {.signal.} proc createOrUpdateSavedAddress*(self: View, name: string, address: string, ens: string, colorId: string, favourite: bool, chainShortNames: string) {.slot.} = diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 44c7774c1f..1e442596b6 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -1715,12 +1715,17 @@ Item { Connections { target: WalletStore.RootStore.walletSectionSavedAddressesInst - function onSavedAddressUpdated(name: string, address: string, ens: string, errorMsg: string) { + function onSavedAddressAddedOrUpdated(added: bool, name: string, address: string, ens: string, errorMsg: string) { WalletStore.RootStore.addingSavedAddress = false WalletStore.RootStore.lastCreatedSavedAddress = { address: address, ens: ens, error: errorMsg } if (!!errorMsg) { - Global.displayToastMessage(qsTr("An error occurred while adding %1 addresses").arg(name), + let mode = qsTr("adding") + if (!added) { + mode = qsTr("editing") + } + + Global.displayToastMessage(qsTr("An error occurred while %1 %2 addresses").arg(mode).arg(name), "", "warning", false, @@ -1730,7 +1735,11 @@ Item { return } - Global.displayToastMessage(qsTr("%1 successfully added to your saved addresses").arg(name), + let msg = qsTr("%1 successfully added to your saved addresses") + if (!added) { + msg = qsTr("%1 saved address successfully edited") + } + Global.displayToastMessage(msg.arg(name), "", "checkmark-circle", false,