fix(@desktop/sync): settings/currency sync&backup handling
Part of #10389 issue.
This commit is contained in:
parent
4c29343a4a
commit
1e406269df
|
@ -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()
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
@ -154,7 +157,7 @@ method load*(self: Module) =
|
|||
singletonInstance.engine.setRootContextProperty("walletSection", newQVariant(self.view))
|
||||
|
||||
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
|
||||
self.notifyFilterChanged()
|
||||
self.notifyFilterChanged()
|
||||
self.events.on(SIGNAL_WALLET_ACCOUNT_SAVED) do(e:Args):
|
||||
let args = AccountSaved(e)
|
||||
self.setTotalCurrencyBalance()
|
||||
|
@ -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()
|
||||
|
@ -274,20 +272,20 @@ method networksModuleDidLoad*(self: Module) =
|
|||
method destroyAddAccountPopup*(self: Module) =
|
||||
if self.addAccountModule.isNil:
|
||||
return
|
||||
|
||||
|
||||
self.view.emitDestroyAddAccountPopup()
|
||||
self.addAccountModule.delete
|
||||
self.addAccountModule = nil
|
||||
|
||||
method runAddAccountPopup*(self: Module, addingWatchOnlyAccount: bool) =
|
||||
self.destroyAddAccountPopup()
|
||||
self.addAccountModule = add_account_module.newModule(self, self.events, self.keycardService, self.accountsService,
|
||||
self.addAccountModule = add_account_module.newModule(self, self.events, self.keycardService, self.accountsService,
|
||||
self.walletAccountService)
|
||||
self.addAccountModule.loadForAddingAccount(addingWatchOnlyAccount)
|
||||
|
||||
method runEditAccountPopup*(self: Module, address: string) =
|
||||
self.destroyAddAccountPopup()
|
||||
self.addAccountModule = add_account_module.newModule(self, self.events, self.keycardService, self.accountsService,
|
||||
self.addAccountModule = add_account_module.newModule(self, self.events, self.keycardService, self.accountsService,
|
||||
self.walletAccountService)
|
||||
self.addAccountModule.loadForEditingAccount(address)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
@ -150,13 +147,13 @@ method authenticateAndTransfer*(
|
|||
|
||||
##################################
|
||||
## Do Not Delete
|
||||
##
|
||||
##
|
||||
## Once we start with signing a transactions we shold check if the address we want to send a transaction from is migrated
|
||||
## or not. In case it's not we should just authenticate logged in user, otherwise we should use one of the keycards that
|
||||
## address (key pair) is migrated to and sign the transaction using it.
|
||||
##
|
||||
##
|
||||
## The code bellow is an example how we can achieve that in future, when we start with signing transactions.
|
||||
##
|
||||
##
|
||||
## let acc = self.controller.getAccountByAddress(from_addr)
|
||||
## if acc.isNil:
|
||||
## echo "error: selected account to send a transaction from is not known"
|
||||
|
@ -166,7 +163,7 @@ method authenticateAndTransfer*(
|
|||
## self.controller.authenticateUser()
|
||||
## else:
|
||||
## self.controller.authenticateUser(acc.keyUid, acc.path)
|
||||
##
|
||||
##
|
||||
##################################
|
||||
|
||||
method onUserAuthenticated*(self: Module, password: string) =
|
||||
|
@ -176,14 +173,14 @@ method onUserAuthenticated*(self: Module, password: string) =
|
|||
else:
|
||||
self.controller.transfer(
|
||||
self.tmpSendTransactionDetails.fromAddr, self.tmpSendTransactionDetails.toAddr,
|
||||
self.tmpSendTransactionDetails.tokenSymbol, self.tmpSendTransactionDetails.value, self.tmpSendTransactionDetails.uuid,
|
||||
self.tmpSendTransactionDetails.tokenSymbol, self.tmpSendTransactionDetails.value, self.tmpSendTransactionDetails.uuid,
|
||||
self.tmpSendTransactionDetails.selectedRoutes, password
|
||||
)
|
||||
|
||||
method transactionWasSent*(self: Module, result: string) =
|
||||
self.view.transactionWasSent(result)
|
||||
|
||||
method suggestedFees*(self: Module, chainId: int): string =
|
||||
method suggestedFees*(self: Module, chainId: int): string =
|
||||
return self.controller.suggestedFees(chainId)
|
||||
|
||||
method suggestedRoutes*(self: Module, account: string, amount: UInt256, token: string, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs: seq[uint64], sendType: int, lockedInAmounts: string): string =
|
||||
|
@ -192,7 +189,7 @@ method suggestedRoutes*(self: Module, account: string, amount: UInt256, token: s
|
|||
method suggestedRoutesReady*(self: Module, suggestedRoutes: string) =
|
||||
self.view.suggestedRoutesReady(suggestedRoutes)
|
||||
|
||||
method getEstimatedTime*(self: Module, chainId: int, maxFeePerGas: string): int =
|
||||
method getEstimatedTime*(self: Module, chainId: int, maxFeePerGas: string): int =
|
||||
return self.controller.getEstimatedTime(chainId, maxFeePerGas).int
|
||||
|
||||
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
@ -79,7 +80,7 @@ QtObject:
|
|||
|
||||
self.events.on(SignalType.Message.event) do(e: Args):
|
||||
var receivedData = MessageSignal(e)
|
||||
|
||||
|
||||
if receivedData.currentStatus.len > 0:
|
||||
var statusUpdate = receivedData.currentStatus[0]
|
||||
self.events.emit(SIGNAL_CURRENT_USER_STATUS_UPDATED, CurrentUserStatusArgs(statusType: statusUpdate.statusType, text: statusUpdate.text))
|
||||
|
@ -88,7 +89,8 @@ 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
|
||||
|
||||
proc initNotificationSettings(self: Service) =
|
||||
|
@ -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
|
||||
|
||||
|
@ -477,7 +480,7 @@ QtObject:
|
|||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "saving allow notification setting error: ", errDesription
|
||||
|
||||
|
||||
QtProperty[bool] notifSettingAllowNotifications:
|
||||
read = getNotifSettingAllowNotifications
|
||||
write = setNotifSettingAllowNotifications
|
||||
|
@ -511,7 +514,7 @@ QtObject:
|
|||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "saving one to one setting error: ", errDesription
|
||||
|
||||
|
||||
QtProperty[string] notifSettingOneToOneChats:
|
||||
read = getNotifSettingOneToOneChats
|
||||
write = setNotifSettingOneToOneChats
|
||||
|
@ -545,7 +548,7 @@ QtObject:
|
|||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "saving group chats setting error: ", errDesription
|
||||
|
||||
|
||||
QtProperty[string] notifSettingGroupChats:
|
||||
read = getNotifSettingGroupChats
|
||||
write = setNotifSettingGroupChats
|
||||
|
@ -613,7 +616,7 @@ QtObject:
|
|||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "saving global mentions setting error: ", errDesription
|
||||
|
||||
|
||||
QtProperty[string] notifSettingGlobalMentions:
|
||||
read = getNotifSettingGlobalMentions
|
||||
write = setNotifSettingGlobalMentions
|
||||
|
@ -681,7 +684,7 @@ QtObject:
|
|||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "saving contact request setting error: ", errDesription
|
||||
|
||||
|
||||
QtProperty[string] notifSettingContactRequests:
|
||||
read = getNotifSettingContactRequests
|
||||
write = setNotifSettingContactRequests
|
||||
|
@ -715,7 +718,7 @@ QtObject:
|
|||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "saving identity verification request setting error: ", errDesription
|
||||
|
||||
|
||||
QtProperty[string] notifSettingIdentityVerificationRequests:
|
||||
read = getNotifSettingIdentityVerificationRequests
|
||||
write = setNotifSettingIdentityVerificationRequests
|
||||
|
@ -827,7 +830,7 @@ QtObject:
|
|||
proc setNotifSettingExemptions*(self: Service, id: string, exemptions: NotificationsExemptions): bool =
|
||||
result = false
|
||||
try:
|
||||
let response = status_settings.setExemptions(id, exemptions.muteAllMessages, exemptions.personalMentions,
|
||||
let response = status_settings.setExemptions(id, exemptions.muteAllMessages, exemptions.personalMentions,
|
||||
exemptions.globalMentions, exemptions.otherMessages)
|
||||
if(not response.error.isNil):
|
||||
error "error saving exemptions setting: ", id = id, errDescription = response.error.message
|
||||
|
@ -883,7 +886,7 @@ QtObject:
|
|||
error "error reading exemptions other messages request setting: ", id = id, errDescription = response.error.message
|
||||
return
|
||||
result.otherMessages = response.result.getStr
|
||||
|
||||
|
||||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "reading exemptions setting error: ", id = id, errDesription
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue