parent
104d7b0a90
commit
e35bc9db40
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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.} =
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue