From 95a1945bffa63f7b0b8cd47f8e89f79984e10e72 Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+PascalPrecht@users.noreply.github.com> Date: Thu, 16 Jun 2022 15:14:54 +0200 Subject: [PATCH] fix: handle sync currency settings This updates the desktop client with a newly emitted currency settings that might originate from synchronization Partially addresses #5201 --- src/app/modules/main/wallet_section/module.nim | 1 + src/app/modules/main/wallet_section/view.nim | 6 +++++- src/app_service/service/settings/service.nim | 3 +++ src/app_service/service/wallet_account/service.nim | 8 ++++++++ ui/app/AppLayouts/Wallet/stores/CurrenciesStore.qml | 3 +-- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app/modules/main/wallet_section/module.nim b/src/app/modules/main/wallet_section/module.nim index b57529688f..d014a06d78 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -102,6 +102,7 @@ method load*(self: Module) = self.switchAccount(0) self.setTotalCurrencyBalance() self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args): + self.view.setCurrentCurrency(self.controller.getCurrency()) self.setTotalCurrencyBalance() self.events.on(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED) do(e:Args): self.setTotalCurrencyBalance() diff --git a/src/app/modules/main/wallet_section/view.nim b/src/app/modules/main/wallet_section/view.nim index 4c79c4d392..4883c0a486 100644 --- a/src/app/modules/main/wallet_section/view.nim +++ b/src/app/modules/main/wallet_section/view.nim @@ -70,8 +70,12 @@ QtObject: self.totalCurrencyBalance = totalCurrencyBalance self.totalCurrencyBalanceChanged() + proc setCurrentCurrency*(self: View, currency: string) = + self.currentCurrency = currency + self.currentCurrencyChanged() + proc setData*(self: View, currency, signingPhrase: string, mnemonicBackedUp: bool) = self.currentCurrency = currency self.signingPhrase = signingPhrase self.isMnemonicBackedUp = mnemonicBackedUp - self.currentCurrencyChanged() \ No newline at end of file + self.currentCurrencyChanged() diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index f3f1968059..8ffdacb1d5 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -74,6 +74,9 @@ QtObject: self.settings.profilePicturesVisibility = settingsfield.value.parseInt self.events.emit(SIGNAL_SETTING_PROFILE_PICTURES_VISIBILITY_CHANGED, SettingProfilePictureArgs(value: self.settings.profilePicturesVisibility)) + if settingsField.name == KEY_CURRENCY: + self.settings.currency = settingsField.value + proc saveSetting(self: Service, attribute: string, value: string | JsonNode | bool | int): bool = try: let response = status_settings.saveSettings(attribute, value) diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index 24008d2ee5..2c415ad9ea 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -12,6 +12,7 @@ import dto import derived_address import ../../../app/core/eventemitter +import ../../../app/core/signals/types import ../../../app/core/tasks/[qt, threadpool] import ../../../backend/accounts as status_go_accounts import ../../../backend/backend as backend @@ -160,6 +161,13 @@ QtObject: error "error: ", errDesription return + self.events.on(SignalType.Message.event) do(e: Args): + var receivedData = MessageSignal(e) + if receivedData.settings.len > 0: + for settingsField in receivedData.settings: + if settingsField.name == KEY_CURRENCY: + self.events.emit(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED, CurrencyUpdated()) + proc getAccountByAddress*(self: Service, address: string): WalletAccountDto = if not self.walletAccounts.hasKey(address): return diff --git a/ui/app/AppLayouts/Wallet/stores/CurrenciesStore.qml b/ui/app/AppLayouts/Wallet/stores/CurrenciesStore.qml index 36f7f93e5b..2dd8f650d7 100644 --- a/ui/app/AppLayouts/Wallet/stores/CurrenciesStore.qml +++ b/ui/app/AppLayouts/Wallet/stores/CurrenciesStore.qml @@ -843,8 +843,7 @@ QtObject { var isSelected = false for(var i = 0; i < currenciesModel.count; i++) { if(root.currentCurrency === root.currenciesModel.get(i).key) { - isSelected = true - root.currenciesModel.get(i).selected = true + root.currenciesModel.get(i).selected = isSelected = true } else { root.currenciesModel.get(i).selected = false