feat(Wallet): sync saved addresses

Main changes:

- Bump status-go to include the sync saved addresses implementation
- Use saved addresses modifier API from messaging instead of wallet
in order to have incremental sync
- Update saved addresses model on sync changes for saved addresses

Closes #7229
This commit is contained in:
Stefan 2022-09-22 16:00:48 +02:00 committed by Stefan Dunca
parent 76d50b5b90
commit b348527edc
7 changed files with 24 additions and 11 deletions

View File

@ -54,7 +54,7 @@ void saveAddress(const SavedAddress &address)
std::vector<json> params = { address };
json inputJson = {
{"jsonrpc", "2.0"},
{"method", "wallet_addSavedAddress"},
{"method", "wakuext_upsertSavedAddress"},
{"params", params}
};

View File

@ -31,7 +31,7 @@ DerivedAddresses getDerivedAddressesForPath(const HashedPassword &password,
SavedAddresses getSavedAddresses();
/// \brief Add a new or update existing saved wallet address
/// \see \c addSavedAddress
/// \see wakuext_upsertSavedAddress RPC method
/// \throws \c CallPrivateRpcError
void saveAddress(const SavedAddress &address);

View File

@ -10,6 +10,7 @@ import ../../../../app_service/service/activity_center/dto/[notification]
import ../../../../app_service/service/contacts/dto/[contacts, status_update]
import ../../../../app_service/service/devices/dto/[device]
import ../../../../app_service/service/settings/dto/[settings]
import ../../../../app_service/service/saved_address/[dto]
type MessageSignal* = ref object of Signal
bookmarks*: seq[BookmarkDto]
@ -29,6 +30,7 @@ type MessageSignal* = ref object of Signal
settings*: seq[SettingsFieldDto]
clearedHistories*: seq[ClearedHistoryDto]
verificationRequests*: seq[VerificationRequest]
savedAddresses*: seq[SavedAddressDto]
type MessageDeliveredSignal* = ref object of Signal
chatId*: string
@ -118,5 +120,9 @@ proc fromEvent*(T: type MessageSignal, event: JsonNode): MessageSignal =
for jsonVerificationRequest in event["event"]["verificationRequests"]:
signal.verificationRequests.add(jsonVerificationRequest.toVerificationRequest())
if event["event"]{"savedAddresses"} != nil:
for jsonSavedAddress in event["event"]["savedAddresses"]:
signal.savedAddresses.add(jsonSavedAddress.toSavedAddressDto())
result = signal

View File

@ -2,7 +2,6 @@ import io_interface
import ../../../../core/eventemitter
import ../../../../../app_service/service/saved_address/service as saved_address_service
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface

View File

@ -4,6 +4,7 @@ import dto
import ../../../app/core/eventemitter
import ../../../backend/backend
import ../../../app/core/[main]
export dto
@ -37,19 +38,25 @@ proc fetchAddresses(self: Service) =
except Exception as e:
error "error: ", procName="fetchAddress", errName = e.name, errDesription = e.msg
proc init*(self: Service) =
self.fetchAddresses()
proc updateAddresses(self: Service) =
self.fetchAddresses()
self.events.emit(SIGNAL_SAVED_ADDRESS_CHANGED, Args())
proc init*(self: Service) =
# Subscribe to sync events and check for changes
self.events.on(SignalType.Message.event) do(e:Args):
var data = MessageSignal(e)
if(len(data.savedAddresses) > 0):
self.updateAddresses()
self.fetchAddresses()
proc getSavedAddresses*(self: Service): seq[SavedAddressDto] =
return self.savedAddresses
proc createOrUpdateSavedAddress*(self: Service, name: string, address: string, favourite: bool): string =
try:
discard backend.addSavedAddress(backend.SavedAddress(name: name, address: address, favourite: favourite))
discard backend.upsertSavedAddress(backend.SavedAddress(name: name, address: address, favourite: favourite))
self.updateAddresses()
return ""
except Exception as e:
@ -59,7 +66,7 @@ proc createOrUpdateSavedAddress*(self: Service, name: string, address: string, f
proc deleteSavedAddress*(self: Service, address: string): string =
try:
var response = backend.deleteSavedAddress(address)
var response = backend.deleteSavedAddress(0, address)
if not response.error.isNil:
raise newException(Exception, response.error.message)

View File

@ -77,10 +77,11 @@ rpc(addEthereumChain, "wallet"):
rpc(deleteEthereumChain, "wallet"):
chainId: int
rpc(addSavedAddress, "wallet"):
rpc(upsertSavedAddress, "wakuext"):
savedAddress: SavedAddress
rpc(deleteSavedAddress, "wallet"):
rpc(deleteSavedAddress, "wakuext"):
chainId: int
address: string
rpc(getSavedAddresses, "wallet"):

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 73a45dd58ebd16538e4b8e5ef2700ee78dc51325
Subproject commit b9d6e6d8c83d9a597332247dafcb999ae79f67bf