fix(savedaddresses): saved addresses are not in sync between devices

Closes: #9567
This commit is contained in:
Sale Djenic 2024-02-12 17:03:11 +01:00 committed by saledjenic
parent 1de573ada7
commit 3e3452c8db
10 changed files with 43 additions and 17 deletions

View File

@ -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()

View File

@ -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.} =

View File

@ -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)

View File

@ -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:

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -424,7 +424,6 @@ StatusModal {
// Update root values
if (Utils.isLikelyEnsName(plainText)) {
d.ens = plainText
d.address = Constants.zeroAddress
d.chainShortNames = ""
}
else {

View File

@ -83,7 +83,7 @@ ColumnLayout {
}
Item {
visible: noSavedAddresses.visible || emptySearchResult.visible || loadingIndicator.visible
visible: noSavedAddresses.visible || emptySearchResult.visible
Layout.fillWidth: true
Layout.fillHeight: true
}

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit e9ff0fbefe11d57f03f0ef6cb7d30cb0b5ebe44e
Subproject commit 598d58f0d6625a4f7feb726fb32ae3c972cfafd6