fix(@desktop/sync): settings/currency sync&backup handling

Part of #10389 issue.
This commit is contained in:
Sale Djenic 2023-05-30 12:52:11 +02:00 committed by saledjenic
parent 4c29343a4a
commit 1e406269df
7 changed files with 42 additions and 63 deletions

View File

@ -71,9 +71,6 @@ method load*(self: Module) =
self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args):
self.refreshWalletAccounts()
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.refreshWalletAccounts()
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
self.refreshWalletAccounts()

View File

@ -27,6 +27,9 @@ method toggleWatchOnlyAccounts*(self: AccessInterface) {.base.} =
method updateCurrency*(self: AccessInterface, currency: string) {.base.} =
raise newException(ValueError, "No implementation available")
method getCurrentCurrency*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method setTotalCurrencyBalance*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -124,6 +124,9 @@ method delete*(self: Module) =
method updateCurrency*(self: Module, currency: string) =
self.controller.updateCurrency(currency)
method getCurrentCurrency*(self: Module): string =
self.controller.getCurrency()
method setTotalCurrencyBalance*(self: Module) =
self.view.setTotalCurrencyBalance(self.controller.getCurrencyBalance(self.filter.addresses))
@ -166,10 +169,6 @@ method load*(self: Module) =
self.setTotalCurrencyBalance()
self.filter.removeAddress(args.address)
self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.view.setCurrentCurrency(self.controller.getCurrency())
self.setTotalCurrencyBalance()
self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e:Args):
self.filter.updateNetworks()
self.setTotalCurrencyBalance()
@ -228,10 +227,9 @@ proc checkIfModuleDidLoad(self: Module) =
if(not self.networksModule.isLoaded()):
return
let currency = self.controller.getCurrency()
let signingPhrase = self.controller.getSigningPhrase()
let mnemonicBackedUp = self.controller.isMnemonicBackedUp()
self.view.setData(currency, signingPhrase, mnemonicBackedUp)
self.view.setData(signingPhrase, mnemonicBackedUp)
self.setTotalCurrencyBalance()
self.filter.load()
self.notifyFilterChanged()

View File

@ -91,9 +91,6 @@ method load*(self: Module) =
self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args):
self.refreshWalletAccounts()
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.refreshWalletAccounts()
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
self.refreshWalletAccounts()

View File

@ -8,7 +8,6 @@ QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
currentCurrency: string
totalCurrencyBalance: CurrencyAmount
signingPhrase: string
isMnemonicBackedUp: bool
@ -33,19 +32,12 @@ QtObject:
proc showToastAccountAdded*(self: View, name: string) {.signal.}
proc currentCurrencyChanged*(self: View) {.signal.}
proc updateCurrency*(self: View, currency: string) {.slot.} =
self.delegate.updateCurrency(currency)
self.currentCurrency = currency
self.currentCurrencyChanged()
proc getCurrentCurrency(self: View): QVariant {.slot.} =
return newQVariant(self.currentCurrency)
QtProperty[QVariant] currentCurrency:
proc getCurrentCurrency(self: View): string {.slot.} =
return self.delegate.getCurrentCurrency()
QtProperty[string] currentCurrency:
read = getCurrentCurrency
notify = currentCurrencyChanged
proc totalCurrencyBalanceChanged*(self: View) {.signal.}
@ -81,10 +73,6 @@ QtObject:
self.totalCurrencyBalance = totalCurrencyBalance
self.totalCurrencyBalanceChanged()
proc setCurrentCurrency*(self: View, currency: string) =
self.currentCurrency = currency
self.currentCurrencyChanged()
# Returning a QVariant from a slot with parameters other than "self" won't compile
# proc getCurrencyAmount*(self: View, amount: float, symbol: string): QVariant {.slot.} =
# return newQVariant(self.delegate.getCurrencyAmount(amount, symbol))
@ -100,11 +88,9 @@ QtObject:
self.tmpSymbol = "ERROR"
return newQVariant(currencyAmount)
proc setData*(self: View, currency, signingPhrase: string, mnemonicBackedUp: bool) =
self.currentCurrency = currency
proc setData*(self: View, signingPhrase: string, mnemonicBackedUp: bool) =
self.signingPhrase = signingPhrase
self.isMnemonicBackedUp = mnemonicBackedUp
self.currentCurrencyChanged()
proc runAddAccountPopup*(self: View, addingWatchOnlyAccount: bool) {.slot.} =
self.delegate.runAddAccountPopup(addingWatchOnlyAccount)

View File

@ -20,20 +20,21 @@ const DEFAULT_CURRENCY* = "USD"
const DEFAULT_TELEMETRY_SERVER_URL* = "https://telemetry.status.im"
const DEFAULT_FLEET* = $Fleet.StatusProd
# Signals:
const SIGNAL_CURRENCY_UPDATED* = "currencyUpdated"
const SIGNAL_CURRENT_USER_STATUS_UPDATED* = "currentUserStatusUpdated"
logScope:
topics = "settings-service"
type
SettingsTextValueArgs* = ref object of Args
value*: string
CurrentUserStatusArgs* = ref object of Args
statusType*: StatusType
text*: string
type
SettingProfilePictureArgs* = ref object of Args
value*: int
QtObject:
type Service* = ref object of QObject
events: EventEmitter
@ -88,6 +89,7 @@ QtObject:
for settingsField in receivedData.settings:
if settingsField.name == KEY_CURRENCY:
self.settings.currency = settingsField.value
self.events.emit(SIGNAL_CURRENCY_UPDATED, SettingsTextValueArgs(value: settingsField.value))
self.initialized = true
@ -131,6 +133,7 @@ QtObject:
proc saveCurrency*(self: Service, value: string): bool =
if(self.saveSetting(KEY_CURRENCY, value)):
self.settings.currency = value.toLowerAscii()
self.events.emit(SIGNAL_CURRENCY_UPDATED, SettingsTextValueArgs(value: self.settings.currency))
return true
return false

View File

@ -26,7 +26,6 @@ logScope:
const SIGNAL_WALLET_ACCOUNT_SAVED* = "walletAccount/accountSaved"
const SIGNAL_WALLET_ACCOUNT_DELETED* = "walletAccount/accountDeleted"
const SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED* = "walletAccount/currencyUpdated"
const SIGNAL_WALLET_ACCOUNT_UPDATED* = "walletAccount/walletAccountUpdated"
const SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED* = "walletAccount/networkEnabledUpdated"
const SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT* = "walletAccount/tokensRebuilt"
@ -333,11 +332,6 @@ QtObject:
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())
if receivedData.walletAccounts.len > 0:
for acc in receivedData.walletAccounts:
self.handleWalletAccount(acc)
@ -351,6 +345,9 @@ QtObject:
self.buildAllTokens(self.getAddresses(), store = true)
self.checkRecentHistory()
self.events.on(SIGNAL_CURRENCY_UPDATED) do(e:Args):
self.buildAllTokens(self.getAddresses(), store = true)
proc reloadAccountTokens*(self: Service) =
self.buildAllTokens(self.getAddresses(), store = true)
self.checkRecentHistory()
@ -523,8 +520,6 @@ QtObject:
proc updateCurrency*(self: Service, newCurrency: string) =
discard self.settingsService.saveCurrency(newCurrency)
self.buildAllTokens(self.getAddresses(), store = true)
self.events.emit(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED, CurrencyUpdated())
proc setNetworksState*(self: Service, chainIds: seq[int], enabled: bool) =
self.networkService.setNetworksState(chainIds, enabled)