Skip to content

Commit

Permalink
feat(HoldingsDropdown): airdrops tokens support added
Browse files Browse the repository at this point in the history
  • Loading branch information
micieslak committed May 8, 2023
1 parent da07230 commit 1eda191
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 5 deletions.
2 changes: 1 addition & 1 deletion storybook/pages/AirdropTokensSelectorPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ColumnLayout {
property int counter: 0

model: ListModel {
id:listModel
id: listModel
}

addButton.onClicked: model.append(items[(counter++) % items.length])
Expand Down
58 changes: 55 additions & 3 deletions storybook/pages/HoldingsDropdownPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import Models 1.0

import AppLayouts.Chat.controls.community 1.0

import SortFilterProxyModel 0.2

import utils 1.0

SplitView {
id: root

Expand Down Expand Up @@ -47,7 +51,49 @@ SplitView {
parent: container
anchors.centerIn: container

collectiblesModel: CollectiblesModel {}
CollectiblesModel {
id: collectiblesModel
}

SortFilterProxyModel {
id: collectiblesModelWithSupply

sourceModel: collectiblesModel

proxyRoles: [
ExpressionRole {
name: "supply"
expression: ((model.index + 1) * 115).toString()
},
ExpressionRole {
name: "infiniteSupply"
expression: !(model.index % 4)
},
ExpressionRole {
name: "chainName"
expression: model.index ? "Optimism" : "Arbitrum"
},
ExpressionRole {

readonly property string icon1: Style.svg("network/Network=Optimism")
readonly property string icon2: Style.svg("network/Network=Arbitrum")

name: "chainIcon"
expression: model.index ? icon1 : icon2
}
]

filters: ValueFilter {
roleName: "category"
value: TokenCategories.Category.Community
}
}


collectiblesModel: isAirdropMode.checked
? collectiblesModelWithSupply
: collectiblesModel

assetsModel: AssetsModel {}
isENSTab: isEnsTabChecker.checked
isCollectiblesOnly: isCollectiblesOnlyChecker.checked
Expand All @@ -68,13 +114,19 @@ SplitView {
RowLayout {
CheckBox {
id: isEnsTabChecker
text: "Is ENS tab visible?"
text: "ENS tab visible"
checked: true
}

CheckBox {
id: isCollectiblesOnlyChecker
text: "Is collectibles only visible?"
text: "Collectibles only"
checked: false
}

CheckBox {
id: isAirdropMode
text: "Airdrop mode"
checked: false
}
}
Expand Down
6 changes: 6 additions & 0 deletions storybook/src/Models/CollectiblesModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ ListModel {
name: "Anniversary",
category: TokenCategories.Category.Community
},
{
key: "Anniversary2",
iconSource: ModelsData.collectibles.anniversary,
name: "Anniversary2",
category: TokenCategories.Category.Community,
},
{
key: "CryptoKitties",
iconSource: ModelsData.collectibles.cryptoKitties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ Item {

areSectionsVisible: !root.showAllTokensMode
isFooterButtonVisible: !root.showAllTokensMode && !d.searchMode
&& filteredModel.item && d.currentModel.count > filteredModel.item.count
&& filteredModel.item && d.currentModel
&& d.currentModel.count > filteredModel.item.count

onHeaderItemClicked: root.navigateToMintTokenSettings()
onFooterButtonClicked: root.footerButtonClicked()
Expand Down
28 changes: 28 additions & 0 deletions ui/app/AppLayouts/Chat/controls/community/HoldingsDropdown.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import StatusQ.Controls 0.1
import StatusQ.Core.Utils 0.1

import AppLayouts.Chat.helpers 1.0
import utils 1.0

StatusDropdown {
id: root
Expand Down Expand Up @@ -368,6 +369,7 @@ StatusDropdown {
tokenShortName: CommunityPermissionsHelpers.getTokenShortNameByKey(root.assetsModel, root.assetKey)
tokenImage: CommunityPermissionsHelpers.getTokenIconByKey(root.assetsModel, root.assetKey)
amountText: d.assetAmountText

tokenCategoryText: qsTr("Asset")
addOrUpdateButtonEnabled: d.assetsReady
mode: d.effectiveHoldingMode
Expand Down Expand Up @@ -402,12 +404,38 @@ StatusDropdown {
tokenName: CommunityPermissionsHelpers.getTokenNameByKey(root.collectiblesModel, root.collectibleKey)
tokenShortName: ""
tokenImage: CommunityPermissionsHelpers.getTokenIconByKey(root.collectiblesModel, root.collectibleKey)
tokenAmount: CommunityPermissionsHelpers.getTokenAmountByKey(root.collectiblesModel, root.collectibleKey)
amountText: d.collectibleAmountText
tokenCategoryText: qsTr("Collectible")
addOrUpdateButtonEnabled: d.collectiblesReady
allowDecimals: false
mode: d.effectiveHoldingMode

ListModel {
Component.onCompleted: {
const collectible = CommunityPermissionsHelpers.getTokenByKey(
root.collectiblesModel,
root.collectibleKey)

if (!collectible)
return

const chainName = collectible.chainName ?? ""
const chainIcon = collectible.chainIcon
? Style.svg(collectible.chainIcon) : ""

if (!chainName)
return

append({
name:chainName,
icon: chainIcon
})

collectiblePanel.networksModel = this
}
}

onEffectiveAmountChanged: root.collectibleAmount = effectiveAmount
onAmountTextChanged: d.collectibleAmountText = amountText
onAddClicked: root.addCollectible(root.collectibleKey, root.collectibleAmount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ StatusListView {
iconSource: model.iconSource ?? ""
showSubItemsIcon: !!model.subItems && model.subItems.count > 0
selected: root.checkedKeys.includes(model.key)
amount: !!model.infiniteSupply ? "" : model.supply ?? ""

onItemClicked: root.itemClicked(
model.key, name, shortName, iconSource, model.subItems)
Expand Down
11 changes: 11 additions & 0 deletions ui/app/AppLayouts/Chat/helpers/CommunityPermissionsHelpers.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ QtObject {
return ""
}

function getTokenAmountByKey(model, key) {
const item = getTokenByKey(model, key)
if (item) {
if (item.infiniteSupply === true)
return ""

return item.supply ?? ""
}
return ""
}

function setHoldingsTextFormat(type, name, amount) {
switch (type) {
case HoldingTypes.Type.Asset:
Expand Down

0 comments on commit 1eda191

Please sign in to comment.