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) {
|
2024-06-24 14:51:18 +00:00
|
|
|
var item
|
|
|
|
// key format:
|
|
|
|
// chainId+address[+tokenId] - ERC721
|
|
|
|
// symbol - ERC20
|
|
|
|
// collectionUid model role keeps chainId+address for every ERC721
|
|
|
|
// key model role keeps: symbol for ERC20, chainId+address for community ERC721 tokens, chainId+address+tokenId for ERC721 tokens from wallet
|
|
|
|
let collectionUid = PermissionsHelpers.getCollectionUidFromKey(key)
|
|
|
|
if(collectionUid !== "") {
|
|
|
|
item = ModelUtils.getByKey(model, "collectionUid", collectionUid)
|
|
|
|
} else {
|
|
|
|
item = Internal.PermissionUtils.getTokenByKey(model, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
return item
|
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)
|
2024-06-24 14:51:18 +00:00
|
|
|
const defaultIcon = Style.png("tokens/DEFAULT-TOKEN")
|
2023-01-18 19:54:14 +00:00
|
|
|
if (item)
|
2024-06-24 14:51:18 +00:00
|
|
|
return item.iconSource ? item.iconSource : defaultIcon
|
|
|
|
return defaultIcon
|
2023-01-18 19:54:14 +00:00
|
|
|
}
|
2022-12-06 11:19:20 +00:00
|
|
|
|
2024-05-28 13:11:29 +00:00
|
|
|
function getTokenDecimalsByKey(model, key) {
|
|
|
|
const item = getTokenByKey(model, key)
|
|
|
|
if (item)
|
|
|
|
return item.decimals ?? 0
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
function getUniquePermissionTokenKeys(model, tokenType) {
|
|
|
|
return Internal.PermissionUtils.getUniquePermissionTokenKeys(model, tokenType)
|
2023-07-04 15:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getUniquePermissionChannels(model, permissionsTypesArray = []) {
|
|
|
|
return Internal.PermissionUtils.getUniquePermissionChannels(model, permissionsTypesArray)
|
|
|
|
}
|
|
|
|
|
2024-03-27 12:48:17 +00:00
|
|
|
function isEligibleToJoinAs(model) {
|
|
|
|
return Internal.PermissionUtils.isEligibleToJoinAs(model)
|
2024-02-06 09:27:51 +00:00
|
|
|
}
|
|
|
|
|
2024-05-10 14:55:20 +00:00
|
|
|
function isTokenGatedCommunity(model) {
|
|
|
|
return Internal.PermissionUtils.isTokenGatedCommunity(model)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2024-06-24 14:51:18 +00:00
|
|
|
|
|
|
|
function getCollectionUidFromKey(key) {
|
|
|
|
const parts = key.split('+');
|
|
|
|
if(parts.length === 2)
|
|
|
|
return key
|
|
|
|
else if(parts.length === 3)
|
|
|
|
return parts[0]+"+"+parts[1]
|
|
|
|
else
|
|
|
|
return ""
|
|
|
|
}
|
2022-12-06 11:19:20 +00:00
|
|
|
}
|