parent
27285151bb
commit
063198fc1f
|
@ -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
|
||||
|
||||
|
|
|
@ -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]]()
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue