Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed tokens initialization. Fixed SendModal for ENS. #9330

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/modules/shared_models/token_model.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NimQml, Tables, strutils, strformat
import NimQml, Tables, strutils, strformat, json

import ./token_item
import ./currency_amount
Expand Down Expand Up @@ -153,8 +153,8 @@ QtObject:
case column:
of "name": result = $item.getName()
of "symbol": result = $item.getSymbol()
of "totalBalance": result = $item.getTotalBalance()
of "totalCurrencyBalance": result = $item.getTotalCurrencyBalance()
of "totalBalance": result = $item.getTotalBalance().toJsonNode()
igor-sirotin marked this conversation as resolved.
Show resolved Hide resolved
of "totalCurrencyBalance": result = $item.getTotalCurrencyBalance().toJsonNode()
of "enabledNetworkCurrencyBalance": result = $item.getEnabledNetworkCurrencyBalance()
of "enabledNetworkBalance": result = $item.getEnabledNetworkBalance()
of "visibleForNetwork": result = $item.getVisibleForNetwork()
Expand Down
2 changes: 1 addition & 1 deletion src/app_service/common/cache.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ proc newTimedCache*[T](): TimedCache[T] = initTable[string, Value[T]]()
proc init*[T](self: var TimedCache[T], values: Table[string, T]) =
self.clear()
for cacheKey, value in values:
self[cacheKey].value = value
self.set(cacheKey, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igor-sirotin

The original way assigned a value to the table without updating the timestamp, so whatever value we set will be considered "old" and isCached will return false immediately. If the user requires "fresh" values, they'll need to be fetched.
In the new way, calling the set method will update the timestamp, so the values will be considered "fresh" and isCached will return true for whatever duration is used, which is wrong since the values we used to init will probably be quite old.

I think the other changes should fix the issue and this one should not be necessary. I'll revert this change in a new PR and test to see that everything's still working fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this was the first place the app crashed 🙂
Because self[cacheKey].value was setting value of non-existable-in-table element.

But maybe I remember something wrong, check it out


proc getTimestamp[T](self: TimedCache[T], cacheKey: string): DateTime = self[cacheKey].timestamp

Expand Down
11 changes: 6 additions & 5 deletions src/app_service/service/token/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ QtObject:
proc init*(self: Service) =
try:
let response = backend.getCachedPrices()
self.initTokenPrices(jsonToPricesMap(response.result))
let prices = jsonToPricesMap(response.result)
self.initTokenPrices(prices)
except Exception as e:
error "Cached prices init error", errDesription = e.msg

try:
let networks = self.networkService.getNetworks()

for network in networks:
Expand All @@ -95,11 +99,8 @@ QtObject:
self.tokens[network.chainId] = default_tokens.filter(
proc(x: TokenDto): bool = x.chainId == network.chainId
)

except Exception as e:
let errDesription = e.msg
error "error: ", errDesription
return
error "Tokens init error", errDesription = e.msg

proc findTokenBySymbol*(self: Service, network: NetworkDto, symbol: string): TokenDto =
try:
Expand Down
19 changes: 10 additions & 9 deletions ui/app/AppLayouts/Profile/views/EnsTermsAndConditionsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ Item {
let assetsList = buyEnsModal.store.currentAccount.assets
for(var i=0; i< assetsList.count;i++) {
let symbol = JSON.parse(root.stickersStore.getStatusToken()).symbol
if(symbol === assetsList.rowData(i, "symbol"))
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: assetsList.rowData(i, "totalBalance"),
totalCurrencyBalance: assetsList.rowData(i, "totalCurrencyBalance"),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
if (symbol !== assetsList.rowData(i, "symbol"))
continue
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: JSON.parse(assetsList.rowData(i, "totalBalance")),
totalCurrencyBalance: JSON.parse(assetsList.rowData(i, "totalCurrencyBalance")),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
}
return {}
}
Expand Down
7 changes: 6 additions & 1 deletion ui/imports/shared/popups/SendModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ StatusDialog {
StatusListItemTag {
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
Layout.preferredHeight: 22
title: d.maxFiatBalance && d.maxFiatBalance.amount > 0 ? qsTr("Max: %1").arg(LocaleUtils.currencyAmountToLocaleString(d.maxFiatBalance)) : qsTr("No balances active")
title: {
if (!d.maxFiatBalance || d.maxFiatBalance.amount <= 0)
return qsTr("No balances active")
const balance = LocaleUtils.currencyAmountToLocaleString(d.maxFiatBalance)
return qsTr("Max: %1").arg(balance)
}
closeButtonVisible: false
titleText.font.pixelSize: 12
bgColor: amountToSendInput.input.valid ? Theme.palette.primaryColor3 : Theme.palette.dangerColor2
Expand Down