Skip to content

Commit

Permalink
feat(@wallet): do not change value of symbol
Browse files Browse the repository at this point in the history
fixes #9201
  • Loading branch information
alaibe committed Mar 29, 2023
1 parent 2728515 commit 063198f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app_service/service/settings/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ QtObject:

proc saveCurrency*(self: Service, value: string): bool =
if(self.saveSetting(KEY_CURRENCY, value)):
self.settings.currency = value
self.settings.currency = value.toLowerAscii()
return true
return false

Expand Down
18 changes: 6 additions & 12 deletions src/app_service/service/token/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,11 @@ QtObject:
return token.symbol
return ""

# Token
proc renameSymbol(symbol: string) : string =
return toUpperAscii(symbol)

proc getTokenPriceCacheKey(crypto: string, fiat: string) : string =
return renameSymbol(crypto) & renameSymbol(fiat)
return crypto & fiat

proc getCryptoKeyAndFactor(crypto: string) : (string, float64) =
let cryptoKey = renameSymbol(crypto)
return CRYPTO_SUB_UNITS_TO_FACTOR.getOrDefault(cryptoKey, (cryptoKey, 1.0))
return CRYPTO_SUB_UNITS_TO_FACTOR.getOrDefault(crypto, (crypto, 1.0))

proc jsonToPricesMap(node: JsonNode) : Table[string, Table[string, float64]] =
result = initTable[string, Table[string, float64]]()
Expand All @@ -213,19 +208,18 @@ QtObject:
return self.priceCache.isCached(cacheKey)

proc getTokenPrice*(self: Service, crypto: string, fiat: string): float64 =
let fiatKey = renameSymbol(fiat)
let (cryptoKey, factor) = getCryptoKeyAndFactor(crypto)

let cacheKey = getTokenPriceCacheKey(cryptoKey, fiatKey)
let cacheKey = getTokenPriceCacheKey(cryptoKey, fiat)
if self.priceCache.isCached(cacheKey):
return self.priceCache.get(cacheKey) * factor

try:
let response = backend.fetchPrices(@[cryptoKey], @[fiatKey])
let response = backend.fetchPrices(@[cryptoKey], @[fiat])
let prices = jsonToPricesMap(response.result)

self.updateCachedTokenPrice(cryptoKey, fiatKey, prices[cryptoKey][fiatKey])
return prices[cryptoKey][fiatKey] * factor
self.updateCachedTokenPrice(cryptoKey, fiat, prices[cryptoKey][fiat])
return prices[cryptoKey][fiat] * factor
except Exception as e:
let errDesription = e.msg
error "error: ", errDesription
Expand Down
2 changes: 1 addition & 1 deletion ui/StatusQ/src/StatusQ/Controls/StatusAccountSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Item {
property bool showAccountDetails: !!selectedAccount
property var accounts
property var selectedAccount
property string currency: "usd"
property string currency: "USD"

// set to asset symbol to display asset's balance top right
// NOTE: if this asset is not selected as a wallet token in the UI, then
Expand Down
2 changes: 1 addition & 1 deletion ui/imports/shared/controls/AssetAndAmountInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Item {

StyledText {
id: txtFiatSymbol
text: root.currentCurrency.toUpperCase()
text: root.currentCurrency
font.weight: Font.Medium
font.pixelSize: 12
color: Style.current.secondaryText
Expand Down
4 changes: 2 additions & 2 deletions ui/imports/shared/panels/StatusAssetSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Item {

onSelectedAssetChanged: {
if (selectedAsset && selectedAsset.symbol) {
d.iconSource = tokenAssetSourceFn(selectedAsset.symbol.toUpperCase())
d.text = selectedAsset.symbol.toUpperCase()
d.iconSource = tokenAssetSourceFn(selectedAsset.symbol)
d.text = selectedAsset.symbol
}
}

Expand Down
4 changes: 2 additions & 2 deletions ui/imports/shared/views/TransactionPreview.qml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Item {
id: txtAmountCurrency
font.pixelSize: 15
height: 22
text: root.currency.toUpperCase()
text: root.currency
color: Style.current.secondaryText
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
Expand Down Expand Up @@ -444,7 +444,7 @@ Item {
id: txtFeeCurrency
font.pixelSize: 15
height: 22
text: root.currency.toUpperCase()
text: root.currency
color: Style.current.secondaryText
anchors.verticalCenter: parent.verticalCenter
horizontalAlignment: Text.AlignRight
Expand Down
2 changes: 1 addition & 1 deletion ui/imports/shared/views/chat/TransactionBubbleView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Item {
return "0"
}
var defaultFiatSymbol = root.store.currentCurrency
return root.store.getFiatValue(tokenAmount, token.symbol, defaultFiatSymbol) + " " + defaultFiatSymbol.toUpperCase()
return root.store.getFiatValue(tokenAmount, token.symbol, defaultFiatSymbol) + " " + defaultFiatSymbol
}
property int state: transactionParamsObject.commandState

Expand Down

0 comments on commit 063198f

Please sign in to comment.