2023-05-10 13:05:45 +02:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
2024-01-30 14:15:58 +01:00
|
|
|
import StatusQ.Core 0.1
|
2024-05-28 19:39:41 +02:00
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
2024-01-30 14:15:58 +01:00
|
|
|
|
2023-09-26 15:45:44 +02:00
|
|
|
QtObject {
|
2023-12-18 11:12:57 +01:00
|
|
|
id: root
|
|
|
|
|
2023-09-26 15:45:44 +02:00
|
|
|
readonly property string currentCurrency: "USD"
|
|
|
|
property string currentCurrencySymbol: "$"
|
|
|
|
|
|
|
|
function formatCurrencyAmount(amount, symbol, options = null, locale = null) {
|
2024-01-30 14:15:58 +01:00
|
|
|
if (isNaN(amount)) {
|
|
|
|
return "N/A"
|
|
|
|
}
|
|
|
|
var currencyAmount = getCurrencyAmount(amount, symbol)
|
|
|
|
return LocaleUtils.currencyAmountToLocaleString(currencyAmount, options, locale)
|
2023-09-26 15:45:44 +02:00
|
|
|
}
|
|
|
|
|
2024-06-12 22:43:08 +02:00
|
|
|
function formatCurrencyAmountFromBigInt(balance, symbol, decimals, options = null) {
|
2024-05-28 19:39:41 +02:00
|
|
|
let bigIntBalance = SQUtils.AmountsArithmetic.fromString(balance)
|
|
|
|
let decimalBalance = SQUtils.AmountsArithmetic.toNumber(bigIntBalance, decimals)
|
2024-06-12 22:43:08 +02:00
|
|
|
return formatCurrencyAmount(decimalBalance, symbol, options)
|
2024-05-28 19:39:41 +02:00
|
|
|
}
|
|
|
|
|
2024-02-05 17:44:49 +01:00
|
|
|
function getFiatValue(balance, cryptoSymbol) {
|
2024-07-11 00:03:37 +02:00
|
|
|
return parseFloat(balance)
|
2023-09-26 15:45:44 +02:00
|
|
|
}
|
2023-12-18 11:12:57 +01:00
|
|
|
|
2024-07-10 20:35:24 +02:00
|
|
|
function getCryptoValue(balance, symbol) {
|
|
|
|
return balance
|
|
|
|
}
|
|
|
|
|
2023-12-18 11:12:57 +01:00
|
|
|
function getCurrencyAmount(amount, symbol) {
|
|
|
|
return ({
|
|
|
|
amount: amount,
|
|
|
|
symbol: symbol ? symbol.toUpperCase() : root.currentCurrency,
|
|
|
|
displayDecimals: 2,
|
|
|
|
stripTrailingZeroes: false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentCurrencyAmount(amount) {
|
2024-07-31 12:04:51 +02:00
|
|
|
return getCurrencyAmount(amount, root.currentCurrency)
|
2023-12-18 11:12:57 +01:00
|
|
|
}
|
2023-09-26 15:45:44 +02:00
|
|
|
}
|