fix: fix settings not being refetched when they had been edited before

This commit is contained in:
Jonathan Rainville 2021-03-23 10:02:44 -04:00 committed by Michael Bradley
parent e1a4a47636
commit 2a9f9118a1
5 changed files with 21 additions and 18 deletions

View File

@ -321,15 +321,15 @@ QtObject:
write = setDefaultCurrency
notify = defaultCurrencyChanged
proc hasAsset*(self: WalletView, account: string, symbol: string): bool {.slot.} =
self.status.wallet.hasAsset(account, symbol)
proc hasAsset*(self: WalletView, symbol: string): bool {.slot.} =
self.status.wallet.hasAsset(symbol)
proc toggleAsset*(self: WalletView, symbol: string) {.slot.} =
self.status.wallet.toggleAsset(symbol)
for account in self.status.wallet.accounts:
if account.address == self.currentAccount.address:
self.currentAccount.setAccountItem(account)
else:
else:
self.accounts.updateAssetsInList(account.address, account.assetList)
self.accountListChanged()
self.currentAccountChanged()

View File

@ -23,9 +23,9 @@ proc saveSetting*(key: Setting, value: string | JsonNode): StatusGoError =
if responseResult == "null":
result.error = ""
else: result = Json.decode(response, StatusGoError)
dirty.store(true)
except Exception as e:
error "Error saving setting", key=key, value=value, msg=e.msg
dirty.store(true)
proc getWeb3ClientVersion*(): string =
parseJson(callPrivateRPC("web3_clientVersion"))["result"].getStr
@ -34,7 +34,7 @@ proc getSettings*(useCached: bool = true, keepSensitiveData: bool = false): Json
let cacheIsDirty = (not settingsInited) or dirty.load
if useCached and (not cacheIsDirty) and (not keepSensitiveData):
result = settings
else:
else:
result = callPrivateRPC("settings_getSettings").parseJSON()["result"]
if not keepSensitiveData:
dirty.store(false)

View File

@ -47,7 +47,15 @@ proc visibleTokensSNTDefault(): JsonNode =
return response
proc toggleAsset*(symbol: string) =
proc convertStringSeqToERC20ContractSeq*(stringSeq: seq[string]): seq[Erc20Contract] =
result = @[]
for v in stringSeq:
let t = getErc20Contract(v)
if t != nil: result.add t
let ct = customTokens.getErc20ContractBySymbol(v)
if ct != nil: result.add ct
proc toggleAsset*(symbol: string): seq[Erc20Contract] =
let currentNetwork = getCurrentNetwork()
let visibleTokens = visibleTokensSNTDefault()
var visibleTokenList = visibleTokens[$currentNetwork].to(seq[string])
@ -58,7 +66,9 @@ proc toggleAsset*(symbol: string) =
visibleTokenList.add symbol
visibleTokens[$currentNetwork] = newJArray()
visibleTokens[$currentNetwork] = %* visibleTokenList
discard saveSetting(Setting.VisibleTokens, $visibleTokens)
let saved = saveSetting(Setting.VisibleTokens, $visibleTokens)
convertStringSeqToERC20ContractSeq(visibleTokenList)
proc hideAsset*(symbol: string) =
let currentNetwork = getCurrentNetwork()
@ -77,12 +87,7 @@ proc getVisibleTokens*(): seq[Erc20Contract] =
var visibleTokenList = visibleTokens[$currentNetwork].to(seq[string])
let customTokens = getCustomTokens()
result = @[]
for v in visibleTokenList:
let t = getErc20Contract(v)
if t != nil: result.add t
let ct = customTokens.getErc20ContractBySymbol(v)
if ct != nil: result.add ct
result = convertStringSeqToERC20ContractSeq(visibleTokenList)
proc addCustomToken*(address: string, name: string, symbol: string, decimals: int, color: string) =
let payload = %* [{"address": address, "name": name, "symbol": symbol, "decimals": decimals, "color": color}]

View File

@ -290,8 +290,7 @@ proc addWatchOnlyAccount*(self: WalletModel, address: string, accountName: strin
let account = GeneratedAccount(address: address)
return self.addNewGeneratedAccount(account, "", accountName, color, constants.WATCH, false)
proc hasAsset*(self: WalletModel, account: string, symbol: string): bool =
self.tokens = status_tokens.getVisibleTokens()
proc hasAsset*(self: WalletModel, symbol: string): bool =
self.tokens.anyIt(it.symbol == symbol)
proc changeAccountSettings*(self: WalletModel, address: string, accountName: string, color: string): string =
@ -311,8 +310,7 @@ proc deleteAccount*(self: WalletModel, address: string): string =
result = status_accounts.deleteAccount(address)
proc toggleAsset*(self: WalletModel, symbol: string) =
status_tokens.toggleAsset(symbol)
self.tokens = status_tokens.getVisibleTokens()
self.tokens = status_tokens.toggleAsset(symbol)
for account in self.accounts:
account.assetList = self.generateAccountConfiguredAssets(account.address)
updateBalance(account, self.getDefaultCurrency())

View File

@ -62,7 +62,7 @@ Item {
}
StatusCheckBox {
id: assetCheck
checked: walletModel.hasAsset("0x123", symbol)
checked: walletModel.hasAsset(symbol)
anchors.right: parent.right
anchors.rightMargin: Style.current.smallPadding
onClicked: walletModel.toggleAsset(symbol)