chore(@desktop/wallet): signal names stored in string constants (wallet account service)

This commit is contained in:
Sale Djenic 2022-02-07 16:38:48 +01:00 committed by saledjenic
parent cd8bd4147c
commit 58c9e15365
5 changed files with 25 additions and 19 deletions

View File

@ -49,10 +49,10 @@ method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionAccountTokens", newQVariant(self.view))
# these connections should be part of the controller's init method
self.events.on("walletAccount/currencyUpdated") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.controller.init()

View File

@ -71,19 +71,19 @@ method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionAccounts", newQVariant(self.view))
# these connections should be part of the controller's init method
self.events.on("walletAccount/accountSaved") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_SAVED) do(e:Args):
self.refreshWalletAccounts()
self.events.on("walletAccount/accountDeleted") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args):
self.refreshWalletAccounts()
self.events.on("walletAccount/currencyUpdated") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.refreshWalletAccounts()
self.events.on("walletAccount/walletAccountUpdated") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
self.refreshWalletAccounts()
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED) do(e:Args):
self.refreshWalletAccounts()
self.controller.init()

View File

@ -38,13 +38,13 @@ method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionCurrent", newQVariant(self.view))
# these connections should be part of the controller's init method
self.events.on("walletAccount/walletAccountUpdated") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on("walletAccount/currencyUpdated") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.controller.init()

View File

@ -90,13 +90,13 @@ method setTotalCurrencyBalance*[T](self: Module[T]) =
method load*[T](self: Module[T]) =
singletonInstance.engine.setRootContextProperty("walletSection", newQVariant(self.view))
self.events.on("walletAccount/accountSaved") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_SAVED) do(e:Args):
self.setTotalCurrencyBalance()
self.events.on("walletAccount/accountDeleted") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args):
self.setTotalCurrencyBalance()
self.events.on("walletAccount/currencyUpdated") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.setTotalCurrencyBalance()
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED) do(e:Args):
self.setTotalCurrencyBalance()
self.controller.init()

View File

@ -19,6 +19,12 @@ export service_interface
logScope:
topics = "wallet-account-service"
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_TOKEN_VISIBILITY_UPDATED* = "walletAccount/tokenVisibilityUpdated"
const SIGNAL_WALLET_ACCOUNT_UPDATED* = "walletAccount/walletAccountUpdated"
var
priceCache {.threadvar.}: Table[string, float64]
balanceCache {.threadvar.}: Table[string, float64]
@ -216,7 +222,7 @@ method addNewAccountToLocalStore(self: Service) =
let balances = self.fetchBalances(@[newAccount.address])
newAccount.tokens = self.buildTokens(newAccount, prices, balances{newAccount.address})
self.accounts[newAccount.address] = newAccount
self.events.emit("walletAccount/accountSaved", AccountSaved(account: newAccount))
self.events.emit(SIGNAL_WALLET_ACCOUNT_SAVED, AccountSaved(account: newAccount))
method generateNewAccount*(self: Service, password: string, accountName: string, color: string): string =
try:
@ -272,17 +278,17 @@ method deleteAccount*(self: Service, address: string) =
let accountDeleted = self.accounts[address]
self.accounts.del(address)
self.events.emit("walletAccount/accountDeleted", AccountDeleted(account: accountDeleted))
self.events.emit(SIGNAL_WALLET_ACCOUNT_DELETED, AccountDeleted(account: accountDeleted))
method updateCurrency*(self: Service, newCurrency: string) =
discard self.settingsService.saveCurrency(newCurrency)
self.refreshBalances()
self.events.emit("walletAccount/currencyUpdated", CurrencyUpdated())
self.events.emit(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED, CurrencyUpdated())
method toggleTokenVisible*(self: Service, symbol: string) =
self.tokenService.toggleVisible(symbol)
self.refreshBalances()
self.events.emit("walletAccount/tokenVisibilityToggled", TokenVisibilityToggled())
self.events.emit(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED, TokenVisibilityToggled())
method updateWalletAccount*(self: Service, address: string, accountName: string, color: string) =
let account = self.accounts[address]
@ -296,4 +302,4 @@ method updateWalletAccount*(self: Service, address: string, accountName: string,
account.name = accountName
account.color = color
self.events.emit("walletAccount/walletAccountUpdated", WalletAccountUpdated(account: account))
self.events.emit(SIGNAL_WALLET_ACCOUNT_UPDATED, WalletAccountUpdated(account: account))