2023-02-17 16:49:01 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
2024-05-28 17:39:41 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
2023-02-17 16:49:01 +00:00
|
|
|
|
2022-07-22 14:42:21 +00:00
|
|
|
import utils 1.0
|
2023-02-22 17:44:04 +00:00
|
|
|
import AppLayouts.Profile.stores 1.0
|
2022-07-22 14:42:21 +00:00
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
2023-01-08 22:23:51 +00:00
|
|
|
// Some token+currency-related functions are implemented in the profileSectionModule.
|
|
|
|
// We should probably refactor this and move those functions to some Wallet module.
|
2024-03-15 16:03:15 +00:00
|
|
|
property var _profileSectionModuleInst: profileSectionModule
|
2023-01-08 22:23:51 +00:00
|
|
|
|
2023-02-17 16:49:01 +00:00
|
|
|
readonly property string currentCurrency: Global.appIsReady ? walletSection.currentCurrency : ""
|
2022-07-22 14:42:21 +00:00
|
|
|
|
2024-09-24 09:10:45 +00:00
|
|
|
function updateCurrency(shortName) {
|
2023-01-17 20:05:21 +00:00
|
|
|
walletSection.updateCurrency(shortName)
|
2022-07-22 14:42:21 +00:00
|
|
|
}
|
2023-01-08 22:23:51 +00:00
|
|
|
|
2023-02-17 12:56:31 +00:00
|
|
|
// The object returned by this sometimes becomes null when used as part of a binding expression.
|
|
|
|
// Will probably be solved when moving to C++, for now avoid storing the result of this function and use
|
|
|
|
// formatCurrencyAmount at the visualization point instead, or move functionality over to the NIM side.
|
2023-01-08 22:23:51 +00:00
|
|
|
function getCurrencyAmount(amount, symbol) {
|
2023-02-17 12:56:31 +00:00
|
|
|
walletSection.prepareCurrencyAmount(amount, symbol)
|
|
|
|
return walletSection.getPreparedCurrencyAmount()
|
2023-01-08 22:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-02-17 12:56:31 +00:00
|
|
|
function formatCurrencyAmount(amount, symbol, options = null, locale = null) {
|
2023-03-08 19:35:18 +00:00
|
|
|
if (isNaN(amount)) {
|
2024-05-28 17:39:41 +00:00
|
|
|
return qsTr("N/A")
|
2023-03-08 19:35:18 +00:00
|
|
|
}
|
2023-02-17 12:56:31 +00:00
|
|
|
var currencyAmount = getCurrencyAmount(amount, symbol)
|
|
|
|
return LocaleUtils.currencyAmountToLocaleString(currencyAmount, options, locale)
|
2023-01-08 22:23:51 +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-07-31 10:04:51 +00:00
|
|
|
function formatBigNumber(number: string, symbol: string, noSymbolOption: bool) {
|
|
|
|
if (!number)
|
|
|
|
return "N/A"
|
|
|
|
if (!symbol)
|
|
|
|
symbol = root.currentCurrency
|
|
|
|
let options = {}
|
|
|
|
if (!!noSymbolOption)
|
|
|
|
options = {noSymbol: true}
|
|
|
|
return formatCurrencyAmount(parseFloat(number), symbol, options)
|
|
|
|
}
|
|
|
|
|
2024-02-05 16:44:49 +00:00
|
|
|
function getFiatValue(cryptoAmount, cryptoSymbol) {
|
2024-03-15 16:03:15 +00:00
|
|
|
var amount = _profileSectionModuleInst.ensUsernamesModule.getFiatValue(cryptoAmount, cryptoSymbol)
|
2023-02-17 12:56:31 +00:00
|
|
|
return parseFloat(amount)
|
2023-01-08 22:23:51 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 16:44:49 +00:00
|
|
|
function getCryptoValue(fiatAmount, cryptoSymbol) {
|
2024-03-15 16:03:15 +00:00
|
|
|
var amount = _profileSectionModuleInst.ensUsernamesModule.getCryptoValue(fiatAmount, cryptoSymbol)
|
2023-02-17 12:56:31 +00:00
|
|
|
return parseFloat(amount)
|
2023-01-08 22:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-02-17 12:56:31 +00:00
|
|
|
function getGasEthValue(gweiValue, gasLimit) {
|
2024-03-15 16:03:15 +00:00
|
|
|
var amount = _profileSectionModuleInst.ensUsernamesModule.getGasEthValue(gweiValue, gasLimit)
|
2023-02-17 12:56:31 +00:00
|
|
|
return parseFloat(amount)
|
2023-01-08 22:23:51 +00:00
|
|
|
}
|
2023-11-24 12:16:13 +00:00
|
|
|
|
2024-09-24 10:57:09 +00:00
|
|
|
function getFeeEthValue(feeCurrency) {
|
|
|
|
if (!feeCurrency || feeCurrency.symbol !== "Gwei")
|
|
|
|
return 0
|
|
|
|
return getGasEthValue(feeCurrency.amount / Math.pow(10, feeCurrency.displayDecimals), 1)
|
|
|
|
}
|
|
|
|
|
2023-11-24 12:16:13 +00:00
|
|
|
function getCurrentCurrencyAmount(amount) {
|
|
|
|
return getCurrencyAmount(amount, currentCurrency)
|
|
|
|
}
|
2022-07-22 14:42:21 +00:00
|
|
|
}
|