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