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-07-04 15:11:41 +00:00
|
|
|
import StatusQ.Internal 0.1 as Internal
|
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
|
|
|
|
2023-11-07 22:45:47 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
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-08-18 10:00:46 +00:00
|
|
|
function getTokenRemainingSupplyByKey(model, key) {
|
2023-04-25 20:27:33 +00:00
|
|
|
const item = getTokenByKey(model, key)
|
|
|
|
|
2023-08-18 10:00:46 +00:00
|
|
|
if (!item || item.remainingSupply === undefined
|
|
|
|
|| item.multiplierIndex === undefined)
|
|
|
|
return ""
|
|
|
|
|
|
|
|
if (item.infiniteSupply)
|
|
|
|
return "∞"
|
|
|
|
|
|
|
|
return LocaleUtils.numberToLocaleString(
|
|
|
|
AmountsArithmetic.toNumber(item.remainingSupply,
|
|
|
|
item.multiplierIndex))
|
2023-04-25 20:27:33 +00:00
|
|
|
}
|
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
function getUniquePermissionTokenKeys(model) {
|
|
|
|
return Internal.PermissionUtils.getUniquePermissionTokenKeys(model)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUniquePermissionChannels(model, permissionsTypesArray = []) {
|
|
|
|
return Internal.PermissionUtils.getUniquePermissionChannels(model, permissionsTypesArray)
|
|
|
|
}
|
|
|
|
|
2024-02-06 09:27:51 +00:00
|
|
|
function getUniqueChannelPermission(model, channelKey) {
|
|
|
|
return Internal.PermissionUtils.getUniquePermissionChannels(model, channelKey)
|
|
|
|
}
|
|
|
|
|
2024-02-13 10:24:24 +00:00
|
|
|
function setHoldingsTextFormat(type, name, amount, decimals) {
|
|
|
|
if (typeof amount === "string") {
|
|
|
|
amount = AmountsArithmetic.toNumber(AmountsArithmetic.fromString(amount), decimals)
|
|
|
|
}
|
2023-08-10 12:23:59 +00:00
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
switch (type) {
|
2023-11-07 22:45:47 +00:00
|
|
|
case Constants.TokenType.ERC20:
|
2023-01-18 19:54:14 +00:00
|
|
|
return `${LocaleUtils.numberToLocaleString(amount)} ${name}`
|
2023-11-07 22:45:47 +00:00
|
|
|
case Constants.TokenType.ERC721:
|
2023-01-18 19:54:14 +00:00
|
|
|
if (amount === 1)
|
|
|
|
return name
|
|
|
|
return `${LocaleUtils.numberToLocaleString(amount)} ${name}`
|
2023-11-07 22:45:47 +00:00
|
|
|
case Constants.TokenType.ENS:
|
2023-01-18 19:54:14 +00:00
|
|
|
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
|
|
|
}
|
2023-07-18 12:39:38 +00:00
|
|
|
|
2023-07-18 17:34:57 +00:00
|
|
|
// OWNER AND TMASTER TOKENS related helpers:
|
|
|
|
readonly property string ownerTokenNameTag: "Owner-"
|
|
|
|
readonly property string tMasterTokenNameTag: "TMaster-"
|
|
|
|
readonly property string ownerTokenSymbolTag: "OWN"
|
|
|
|
readonly property string tMasterTokenSymbolTag: "TM"
|
|
|
|
|
2023-07-18 12:39:38 +00:00
|
|
|
// It generates a symbol from a given community name.
|
|
|
|
// It will be used to autogenerate the Owner and Token Master token symbols.
|
2023-07-18 17:34:57 +00:00
|
|
|
function communityNameToSymbol(isOwner, communityName) {
|
2023-07-18 12:39:38 +00:00
|
|
|
const shortName = communityName.substring(0, 3)
|
|
|
|
if(isOwner)
|
2023-07-18 17:34:57 +00:00
|
|
|
return ownerTokenSymbolTag + shortName.toUpperCase()
|
2023-07-18 12:39:38 +00:00
|
|
|
else
|
2023-07-18 17:34:57 +00:00
|
|
|
return tMasterTokenSymbolTag + shortName.toUpperCase()
|
2023-07-18 12:39:38 +00:00
|
|
|
}
|
2022-12-06 11:19:20 +00:00
|
|
|
}
|