fix(Airdrop): Use remaining supply to display and validate amounts

Closes: #11917
This commit is contained in:
Michał Cieślak 2023-08-18 12:00:46 +02:00 committed by Michał
parent 678f751121
commit 02d16cb22f
4 changed files with 33 additions and 24 deletions

View File

@ -99,19 +99,20 @@ StatusListView {
showSubItemsIcon: !!model.subItems && model.subItems.count > 0
selected: root.checkedKeys.includes(model.key)
amount: {
if (model.supply === undefined
if (model.remainingSupply === undefined
|| model.multiplierIndex === undefined)
return ""
if (model.infiniteSupply)
return "∞"
if (model.supply === "1")
if (model.remainingSupply === "1" && model.multiplierIndex === 0)
return qsTr("Max. 1")
if (root.showTokenAmount)
return SQUtils.AmountsArithmetic.toNumber(model.supply,
model.multiplierIndex)
return LocaleUtils.numberToLocaleString(
SQUtils.AmountsArithmetic.toNumber(
model.remainingSupply, model.multiplierIndex))
return ""
}

View File

@ -53,15 +53,19 @@ QtObject {
return ""
}
function getTokenAmountByKey(model, key) {
function getTokenRemainingSupplyByKey(model, key) {
const item = getTokenByKey(model, key)
if (item) {
if (item.infiniteSupply === true)
return "∞"
return item.supply ?? ""
}
return ""
if (!item || item.remainingSupply === undefined
|| item.multiplierIndex === undefined)
return ""
if (item.infiniteSupply)
return "∞"
return LocaleUtils.numberToLocaleString(
AmountsArithmetic.toNumber(item.remainingSupply,
item.multiplierIndex))
}
function getUniquePermissionTokenKeys(model) {

View File

@ -331,13 +331,16 @@ StatusDropdown {
else
{
root.collectibleKey = key
const amount = PermissionsHelpers.getTokenAmountByKey(root.collectiblesModel, root.collectibleKey)
const item = PermissionsHelpers.getTokenByKey(root.collectiblesModel, root.collectibleKey)
//When the collectible is unique, there is no need for the user to select amount
//Just send the add/update events
if(amount == 1) {
root.collectibleAmount = amount
d.updateSelected ? root.updateCollectible(root.collectibleKey, amount)
: root.addCollectible(root.collectibleKey, amount)
if(item.supply.toString() === "1"
|| (item.remainingSupply
&& item.remainingSupply.toString() === "1")) {
root.collectibleAmount = "1"
d.updateSelected ? root.updateCollectible(root.collectibleKey, "1")
: root.addCollectible(root.collectibleKey, "1")
return
}
}
@ -397,6 +400,7 @@ StatusDropdown {
tokenName: PermissionsHelpers.getTokenNameByKey(root.assetsModel, root.assetKey)
tokenShortName: PermissionsHelpers.getTokenShortNameByKey(root.assetsModel, root.assetKey)
tokenImage: PermissionsHelpers.getTokenIconByKey(root.assetsModel, root.assetKey)
tokenAmount: PermissionsHelpers.getTokenRemainingSupplyByKey(root.assetsModel, root.assetKey)
amountText: d.assetAmountText
tokenCategoryText: qsTr("Asset")
addOrUpdateButtonEnabled: d.assetsReady
@ -421,7 +425,7 @@ StatusDropdown {
append({
name: chainName,
icon: chainIcon,
amount: asset.supply,
amount: asset.remainingSupply,
multiplierIndex: asset.multiplierIndex,
infiniteAmount: asset.infiniteSupply
})
@ -469,7 +473,7 @@ StatusDropdown {
tokenName: PermissionsHelpers.getTokenNameByKey(root.collectiblesModel, root.collectibleKey)
tokenShortName: ""
tokenImage: PermissionsHelpers.getTokenIconByKey(root.collectiblesModel, root.collectibleKey)
tokenAmount: PermissionsHelpers.getTokenAmountByKey(root.collectiblesModel, root.collectibleKey)
tokenAmount: PermissionsHelpers.getTokenRemainingSupplyByKey(root.collectiblesModel, root.collectibleKey)
amountText: d.collectibleAmountText
tokenCategoryText: qsTr("Collectible")
addOrUpdateButtonEnabled: d.collectiblesReady
@ -495,7 +499,7 @@ StatusDropdown {
append({
name:chainName,
icon: chainIcon,
amount: collectible.supply,
amount: collectible.remainingSupply,
multiplierIndex: collectible.multiplierIndex,
infiniteAmount: collectible.infiniteSupply
})

View File

@ -191,7 +191,7 @@ StatusScrollView {
tokenImage: modelItem.iconSource,
networkText: modelItem.chainName,
networkImage: Style.svg(modelItem.chainIcon),
supply: modelItem.supply,
remainingSupply: modelItem.remainingSupply,
multiplierIndex: modelItem.multiplierIndex,
infiniteSupply: modelItem.infiniteSupply,
contractUniqueKey: modelItem.contractUniqueKey,
@ -277,7 +277,7 @@ StatusScrollView {
if (!item || item.infiniteSupply)
continue
const dividient = AmountsArithmetic.fromString(item.supply)
const dividient = AmountsArithmetic.fromString(item.remainingSupply)
const divisor = AmountsArithmetic.fromString(item.amount)
const quotient = AmountsArithmetic.toNumber(
@ -291,7 +291,7 @@ StatusScrollView {
}
delegate: QtObject {
readonly property string supply: model.supply
readonly property string remainingSupply: model.remainingSupply
readonly property string amount: model.amount
readonly property bool infiniteSupply: model.infiniteSupply
@ -304,13 +304,13 @@ StatusScrollView {
AmountsArithmetic.fromString(amount),
recipientsCount)
const available = AmountsArithmetic.fromString(supply)
const available = AmountsArithmetic.fromString(remainingSupply)
return AmountsArithmetic.cmp(demand, available) <= 0
}
onSupplyChanged: recipientsCountInstantiator.findRecipientsCount()
onRemainingSupplyChanged: recipientsCountInstantiator.findRecipientsCount()
onAmountChanged: recipientsCountInstantiator.findRecipientsCount()
onInfiniteSupplyChanged: recipientsCountInstantiator.findRecipientsCount()