From 3e3452c8dbacc6624d5310fe8c6210fe457d6e64 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Mon, 12 Feb 2024 17:03:11 +0100 Subject: [PATCH] fix(savedaddresses): saved addresses are not in sync between devices Closes: #9567 --- .../wallet_section/saved_addresses/controller.nim | 8 ++++++-- .../saved_addresses/io_interface.nim | 4 ++-- .../wallet_section/saved_addresses/module.nim | 12 ++++++++---- .../service/saved_address/async_tasks.nim | 12 ++++++++---- src/app_service/service/saved_address/dto.nim | 3 +++ src/app_service/service/saved_address/service.nim | 15 +++++++++++++-- src/app_service/service/settings/service.nim | 1 + .../Wallet/popups/AddEditSavedAddressPopup.qml | 1 - ui/app/AppLayouts/Wallet/views/SavedAddresses.qml | 2 +- vendor/status-go | 2 +- 10 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/app/modules/main/wallet_section/saved_addresses/controller.nim b/src/app/modules/main/wallet_section/saved_addresses/controller.nim index 2652ddaa2c..5c82430db5 100644 --- a/src/app/modules/main/wallet_section/saved_addresses/controller.nim +++ b/src/app/modules/main/wallet_section/saved_addresses/controller.nim @@ -1,5 +1,6 @@ import io_interface import app/core/eventemitter +import app_service/service/wallet_account/service as wallet_account_service import app_service/service/saved_address/service as saved_address_service type @@ -22,16 +23,19 @@ proc delete*(self: Controller) = discard proc init*(self: Controller) = + self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e:Args): + self.delegate.loadSavedAddresses() + self.events.on(SIGNAL_SAVED_ADDRESSES_UPDATED) do(e:Args): self.delegate.loadSavedAddresses() self.events.on(SIGNAL_SAVED_ADDRESS_UPDATED) do(e:Args): let args = SavedAddressArgs(e) - self.delegate.savedAddressUpdated(args.name, args.address, args.errorMsg) + self.delegate.savedAddressUpdated(args.name, args.address, args.isTestAddress, args.errorMsg) self.events.on(SIGNAL_SAVED_ADDRESS_DELETED) do(e:Args): let args = SavedAddressArgs(e) - self.delegate.savedAddressDeleted(args.address, args.errorMsg) + self.delegate.savedAddressDeleted(args.address, args.isTestAddress, args.errorMsg) proc areTestNetworksEnabled*(self: Controller): bool = return self.savedAddressService.areTestNetworksEnabled() diff --git a/src/app/modules/main/wallet_section/saved_addresses/io_interface.nim b/src/app/modules/main/wallet_section/saved_addresses/io_interface.nim index a25b6030b1..c6650c8499 100644 --- a/src/app/modules/main/wallet_section/saved_addresses/io_interface.nim +++ b/src/app/modules/main/wallet_section/saved_addresses/io_interface.nim @@ -27,10 +27,10 @@ method updatePreferredChains*(self: AccessInterface, address: string, chainShort method deleteSavedAddress*(self: AccessInterface, address: string) {.base.} = raise newException(ValueError, "No implementation available") -method savedAddressUpdated*(self: AccessInterface, name: string, address: string, errorMsg: string) {.base.} = +method savedAddressUpdated*(self: AccessInterface, name: string, address: string, isTestAddress: bool, errorMsg: string) {.base.} = raise newException(ValueError, "No implementation available") -method savedAddressDeleted*(self: AccessInterface, address: string, errorMsg: string) {.base.} = +method savedAddressDeleted*(self: AccessInterface, address: string, isTestAddress: bool, errorMsg: string) {.base.} = raise newException(ValueError, "No implementation available") method savedAddressNameExists*(self: AccessInterface, name: string): bool {.base.} = 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 1a95933720..ce7b4be648 100644 --- a/src/app/modules/main/wallet_section/saved_addresses/module.nim +++ b/src/app/modules/main/wallet_section/saved_addresses/module.nim @@ -70,13 +70,17 @@ method updatePreferredChains*(self: Module, address: string, chainShortNames: st method deleteSavedAddress*(self: Module, address: string) = self.controller.deleteSavedAddress(address) -method savedAddressUpdated*(self: Module, name: string, address: string, errorMsg: string) = - let item = self.view.getModel().getItemByAddress(address, self.controller.areTestNetworksEnabled()) +method savedAddressUpdated*(self: Module, name: string, address: string, isTestAddress: bool, errorMsg: string) = + if isTestAddress != self.controller.areTestNetworksEnabled(): + return + let item = self.view.getModel().getItemByAddress(address, isTestAddress) self.loadSavedAddresses() self.view.savedAddressAddedOrUpdated(item.isEmpty(), name, address, errorMsg) -method savedAddressDeleted*(self: Module, address: string, errorMsg: string) = - let item = self.view.getModel().getItemByAddress(address, self.controller.areTestNetworksEnabled()) +method savedAddressDeleted*(self: Module, address: string, isTestAddress: bool, errorMsg: string) = + if isTestAddress != self.controller.areTestNetworksEnabled(): + return + let item = self.view.getModel().getItemByAddress(address, isTestAddress) self.loadSavedAddresses() self.view.savedAddressDeleted(item.getName(), address, errorMsg) diff --git a/src/app_service/service/saved_address/async_tasks.nim b/src/app_service/service/saved_address/async_tasks.nim index 63736e522e..3850183de7 100644 --- a/src/app_service/service/saved_address/async_tasks.nim +++ b/src/app_service/service/saved_address/async_tasks.nim @@ -27,13 +27,15 @@ proc checkForEnsNameAndUpdate(chainId: int, savedAddress: var SavedAddressDto, u not savedAddress.isTest and chainId != Mainnet: return try: + var ensName: string try: let ensResponse = backend.getName(chainId, savedAddress.address) - if updateCriteria == UpdateCriteria.OnlyIfDifferent and savedAddress.ens == ensResponse.result.getStr(): - return - savedAddress.ens = ensResponse.result.getStr() + ensName = ensResponse.result.getStr() except: - savedAddress.ens = "" + ensName = "" + if updateCriteria == UpdateCriteria.OnlyIfDifferent and savedAddress.ens == ensName: + return + savedAddress.ens = ensName return backend.upsertSavedAddress(savedAddress) except Exception as e: raise newException(RpcException, e.msg) @@ -69,6 +71,7 @@ const upsertSavedAddressTask: Task = proc(argEncoded: string) {.gcsafe, nimcall. "response": "", "name": %* arg.name, "address": %* arg.address, + "isTestAddress": %* arg.isTestAddress, "ens": %* arg.ens, "error": "", } @@ -95,6 +98,7 @@ const deleteSavedAddressTask: Task = proc(argEncoded: string) {.gcsafe, nimcall. var response = %* { "response": "", "address": %* arg.address, + "isTestAddress": %* arg.isTestAddress, "error": "", } try: diff --git a/src/app_service/service/saved_address/dto.nim b/src/app_service/service/saved_address/dto.nim index bca0e382dc..4a690a89dc 100644 --- a/src/app_service/service/saved_address/dto.nim +++ b/src/app_service/service/saved_address/dto.nim @@ -10,6 +10,7 @@ type colorId*: string chainShortNames*: string isTest*: bool + removed*: bool createdAt*: int64 proc toSavedAddressDto*(jsonObj: JsonNode): SavedAddressDto = @@ -22,6 +23,7 @@ proc toSavedAddressDto*(jsonObj: JsonNode): SavedAddressDto = discard jsonObj.getProp("chainShortNames", result.chainShortNames) discard jsonObj.getProp("isTest", result.isTest) discard jsonObj.getProp("createdAt", result.createdAt) + discard jsonObj.getProp("removed", result.removed) proc toJsonNode*(self: SavedAddressDto): JsonNode = result = %* { @@ -32,4 +34,5 @@ proc toJsonNode*(self: SavedAddressDto): JsonNode = "chainShortNames": self.chainShortNames, "isTest": self.isTest, "createdAt": self.createdAt, + "removed": self.removed } \ No newline at end of file diff --git a/src/app_service/service/saved_address/service.nim b/src/app_service/service/saved_address/service.nim index 3fa9cb404e..3aad5b50d6 100644 --- a/src/app_service/service/saved_address/service.nim +++ b/src/app_service/service/saved_address/service.nim @@ -26,6 +26,7 @@ type SavedAddressArgs* = ref object of Args name*: string address*: string + isTestAddress*: bool errorMsg*: string QtObject: @@ -55,8 +56,16 @@ QtObject: proc init*(self: Service) = self.events.on(SignalType.Message.event) do(e:Args): var data = MessageSignal(e) - if(len(data.savedAddresses) > 0): - self.updateAddresses(SIGNAL_SAVED_ADDRESSES_UPDATED, Args()) + for sa in data.savedAddresses: + let arg = SavedAddressArgs( + name: sa.name, + address: sa.address, + isTestAddress: sa.isTest, + ) + if sa.removed: + self.updateAddresses(SIGNAL_SAVED_ADDRESS_DELETED, arg) + else: + self.updateAddresses(SIGNAL_SAVED_ADDRESS_UPDATED, arg) self.fetchSavedAddressesAndResolveEnsNames() @@ -131,6 +140,7 @@ QtObject: arg.name = rpcResponseObj{"name"}.getStr arg.address = rpcResponseObj{"address"}.getStr + arg.isTestAddress = rpcResponseObj{"isTestAddress"}.getBool except Exception as e: error "onSavedAddressCreatedOrUpdated", msg = e.msg arg.errorMsg = e.msg @@ -156,6 +166,7 @@ QtObject: raise newException(CatchableError, "invalid response") arg.address = rpcResponseObj{"address"}.getStr + arg.isTestAddress = rpcResponseObj{"isTestAddress"}.getBool except Exception as e: error "onDeleteSavedAddress", msg = e.msg arg.errorMsg = e.msg diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index 89fccb79e5..f61e68f2ab 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -456,6 +456,7 @@ QtObject: let newValue = not self.settings.testNetworksEnabled if(self.saveSetting(KEY_TEST_NETWORKS_ENABLED, newValue)): self.settings.testNetworksEnabled = newValue + self.events.emit(SIGNAL_CURRENCY_UPDATED, SettingsTextValueArgs(value: self.settings.currency)) return true return false diff --git a/ui/app/AppLayouts/Wallet/popups/AddEditSavedAddressPopup.qml b/ui/app/AppLayouts/Wallet/popups/AddEditSavedAddressPopup.qml index 81f365122a..64d3dfa8d8 100644 --- a/ui/app/AppLayouts/Wallet/popups/AddEditSavedAddressPopup.qml +++ b/ui/app/AppLayouts/Wallet/popups/AddEditSavedAddressPopup.qml @@ -424,7 +424,6 @@ StatusModal { // Update root values if (Utils.isLikelyEnsName(plainText)) { d.ens = plainText - d.address = Constants.zeroAddress d.chainShortNames = "" } else { diff --git a/ui/app/AppLayouts/Wallet/views/SavedAddresses.qml b/ui/app/AppLayouts/Wallet/views/SavedAddresses.qml index ac7e18f11c..17b5c4da87 100644 --- a/ui/app/AppLayouts/Wallet/views/SavedAddresses.qml +++ b/ui/app/AppLayouts/Wallet/views/SavedAddresses.qml @@ -83,7 +83,7 @@ ColumnLayout { } Item { - visible: noSavedAddresses.visible || emptySearchResult.visible || loadingIndicator.visible + visible: noSavedAddresses.visible || emptySearchResult.visible Layout.fillWidth: true Layout.fillHeight: true } diff --git a/vendor/status-go b/vendor/status-go index e9ff0fbefe..598d58f0d6 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit e9ff0fbefe11d57f03f0ef6cb7d30cb0b5ebe44e +Subproject commit 598d58f0d6625a4f7feb726fb32ae3c972cfafd6