2022-12-06 11:19:20 +00:00
|
|
|
pragma Singleton
|
|
|
|
|
|
|
|
import QtQml 2.14
|
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
import StatusQ.Core 0.1
|
2023-02-17 13:36:58 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
2023-01-18 19:54:14 +00:00
|
|
|
|
2023-06-23 06:17:04 +00:00
|
|
|
import AppLayouts.Communities.controls 1.0
|
2023-01-18 19:54:14 +00:00
|
|
|
|
2022-12-06 11:19:20 +00:00
|
|
|
QtObject {
|
2023-01-18 19:54:14 +00:00
|
|
|
function getTokenByKey(model, key) {
|
|
|
|
if (!model)
|
2022-12-06 11:19:20 +00:00
|
|
|
return null
|
2023-01-18 19:54:14 +00:00
|
|
|
|
2023-02-17 13:36:58 +00:00
|
|
|
const count = model.rowCount()
|
|
|
|
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
const item = ModelUtils.get(model, i)
|
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
if (item.key === key)
|
|
|
|
return item
|
|
|
|
|
|
|
|
if (item.subItems) {
|
|
|
|
const subitem = getTokenByKey(item.subItems, key)
|
2023-02-17 13:36:58 +00:00
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
if (subitem !== null)
|
|
|
|
return subitem
|
|
|
|
}
|
2022-12-06 11:19:20 +00:00
|
|
|
}
|
2023-02-17 13:36:58 +00:00
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
return null
|
2022-12-06 11:19:20 +00:00
|
|
|
}
|
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
function getTokenNameByKey(model, key) {
|
|
|
|
const item = getTokenByKey(model, key)
|
|
|
|
if (item)
|
|
|
|
return item.name
|
|
|
|
return ""
|
2022-12-06 11:19:20 +00:00
|
|
|
}
|
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
function getTokenShortNameByKey(model, key) {
|
|
|
|
const item = getTokenByKey(model, key)
|
|
|
|
if (item)
|
2023-02-21 20:00:39 +00:00
|
|
|
return item.shortName ?? ""
|
2023-01-18 19:54:14 +00:00
|
|
|
return ""
|
|
|
|
}
|
2022-12-06 11:19:20 +00:00
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
function getTokenIconByKey(model, key) {
|
|
|
|
const item = getTokenByKey(model, key)
|
|
|
|
if (item)
|
2023-02-21 20:00:39 +00:00
|
|
|
return item.iconSource ?? ""
|
2023-01-18 19:54:14 +00:00
|
|
|
return ""
|
|
|
|
}
|
2022-12-06 11:19:20 +00:00
|
|
|
|
2023-04-25 20:27:33 +00:00
|
|
|
function getTokenAmountByKey(model, key) {
|
|
|
|
const item = getTokenByKey(model, key)
|
|
|
|
if (item) {
|
|
|
|
if (item.infiniteSupply === true)
|
|
|
|
return "∞"
|
|
|
|
|
|
|
|
return item.supply ?? ""
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
function setHoldingsTextFormat(type, name, amount) {
|
|
|
|
switch (type) {
|
|
|
|
case HoldingTypes.Type.Asset:
|
|
|
|
return `${LocaleUtils.numberToLocaleString(amount)} ${name}`
|
|
|
|
case HoldingTypes.Type.Collectible:
|
|
|
|
if (amount === 1)
|
|
|
|
return name
|
|
|
|
return `${LocaleUtils.numberToLocaleString(amount)} ${name}`
|
|
|
|
case HoldingTypes.Type.Ens:
|
|
|
|
if (name === "*.eth")
|
|
|
|
return qsTr("Any ENS username")
|
|
|
|
if (name.startsWith("*."))
|
|
|
|
return qsTr("ENS username on '%1' domain").arg(name.substring(2))
|
|
|
|
|
|
|
|
return qsTr("ENS username '%1'").arg(name)
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
2022-12-06 11:19:20 +00:00
|
|
|
}
|
|
|
|
}
|