fix(@desktop/wallet): Use LeftJoinodel to link networks with chainId in various models such collectibles model, assets models.

fixes #8923
This commit is contained in:
Khushboo Mehta 2023-10-30 23:18:58 +01:00 committed by Khushboo-dev-cpp
parent 63112545a8
commit bcdb37b0c5
11 changed files with 71 additions and 52 deletions

View File

@ -23,12 +23,9 @@ SplitView {
width: 400 width: 400
getNetworkIcon: function(chainId) {
return "network/Network=Optimism"
}
assets: WalletAssetsModel {} assets: WalletAssetsModel {}
collectibles: WalletNestedCollectiblesModel {} collectibles: WalletNestedCollectiblesModel {}
networksModel: NetworksModel.allNetworks
} }
} }

View File

@ -17,6 +17,7 @@ QtObject {
property ListModel model: ListModel{} property ListModel model: ListModel{}
} }
property var allNetworksModel: NetworksModel.allNetworks
property var fromNetworksModel: NetworksModel.sendFromNetworks property var fromNetworksModel: NetworksModel.sendFromNetworks
property var toNetworksModel: NetworksModel.sendToNetworks property var toNetworksModel: NetworksModel.sendToNetworks
property var selectedSenderAccount: senderAccounts.get(0) property var selectedSenderAccount: senderAccounts.get(0)
@ -237,10 +238,6 @@ QtObject {
} }
} }
function getNetworkIcon(chainId) {
return ModelUtils.getByKey(NetworksModel.allNetworks, "chainId", Number(chainId), "iconUrl")
}
function resetStoredProperties() { function resetStoredProperties() {
root.amountToSend = "" root.amountToSend = ""
root.sendType = Constants.SendType.Transfer root.sendType = Constants.SendType.Transfer

View File

@ -57,14 +57,9 @@ Item {
secondaryText: token ? LocaleUtils.currencyAmountToLocaleString(token.enabledNetworkBalance) : Constants.dummyText secondaryText: token ? LocaleUtils.currencyAmountToLocaleString(token.enabledNetworkBalance) : Constants.dummyText
tertiaryText: token ? LocaleUtils.currencyAmountToLocaleString(token.enabledNetworkCurrencyBalance) : Constants.dummyText tertiaryText: token ? LocaleUtils.currencyAmountToLocaleString(token.enabledNetworkCurrencyBalance) : Constants.dummyText
balances: token && token.balances ? token.balances : null balances: token && token.balances ? token.balances : null
networksModel: RootStore.allNetworks
isLoading: root.assetsLoading isLoading: root.assetsLoading
errorTooltipText: token && token.balances ? networkConnectionStore.getBlockchainNetworkDownTextForToken(token.balances): "" errorTooltipText: token && token.balances ? networkConnectionStore.getBlockchainNetworkDownTextForToken(token.balances): ""
getNetworkColor: function(chainId){
return RootStore.getNetworkColor(chainId)
}
getNetworkIcon: function(chainId){
return RootStore.getNetworkIcon(chainId)
}
formatBalance: function(balance){ formatBalance: function(balance){
return LocaleUtils.currencyAmountToLocaleString(balance) return LocaleUtils.currencyAmountToLocaleString(balance)
} }

View File

@ -4,6 +4,7 @@ import QtQuick.Controls 2.14
import utils 1.0 import utils 1.0
import shared.controls 1.0 import shared.controls 1.0
import StatusQ 0.1
import StatusQ.Components 0.1 import StatusQ.Components 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
import StatusQ.Core 0.1 import StatusQ.Core 0.1
@ -16,14 +17,13 @@ Control {
property alias secondaryText: cryptoBalance.text property alias secondaryText: cryptoBalance.text
property alias tertiaryText: fiatBalance.text property alias tertiaryText: fiatBalance.text
property var balances property var balances
property var networksModel
property bool isLoading: false property bool isLoading: false
property string errorTooltipText property string errorTooltipText
property StatusAssetSettings asset: StatusAssetSettings { property StatusAssetSettings asset: StatusAssetSettings {
width: 40 width: 40
height: 40 height: 40
} }
property var getNetworkColor: function(chainId){}
property var getNetworkIcon: function(chainId){}
property var formatBalance: function(balance){} property var formatBalance: function(balance){}
topPadding: Style.current.padding topPadding: Style.current.padding
@ -82,11 +82,15 @@ Control {
anchors.leftMargin: identiconLoader.width anchors.leftMargin: identiconLoader.width
Repeater { Repeater {
id: chainRepeater id: chainRepeater
model: balances ? balances : null model: LeftJoinModel {
leftModel: root.balances
rightModel: root.networksModel
joinRole: "chainId"
}
delegate: InformationTag { delegate: InformationTag {
tagPrimaryLabel.text: root.formatBalance(model.balance) tagPrimaryLabel.text: root.formatBalance(model.balance)
tagPrimaryLabel.color: root.getNetworkColor(model.chainId) tagPrimaryLabel.color: model.chainColor
image.source: Style.svg("tiny/%1".arg(root.getNetworkIcon(model.chainId))) image.source: Style.svg("tiny/%1".arg(model.iconUrl))
loading: root.isLoading loading: root.isLoading
rightComponent: StatusFlatRoundButton { rightComponent: StatusFlatRoundButton {
width: 14 width: 14

View File

@ -39,7 +39,6 @@ StatusDialog {
property alias modalHeader: modalHeader.text property alias modalHeader: modalHeader.text
property TransactionStore store: TransactionStore {} property TransactionStore store: TransactionStore {}
property var collectiblesModel: store.collectiblesModel
property var nestedCollectiblesModel: store.nestedCollectiblesModel property var nestedCollectiblesModel: store.nestedCollectiblesModel
property var bestRoutes property var bestRoutes
property bool isLoading: false property bool isLoading: false
@ -247,12 +246,10 @@ StatusDialog {
Layout.fillHeight: true Layout.fillHeight: true
assetsModel: popup.preSelectedAccount && popup.preSelectedAccount.assets ? popup.preSelectedAccount.assets : null assetsModel: popup.preSelectedAccount && popup.preSelectedAccount.assets ? popup.preSelectedAccount.assets : null
collectiblesModel: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null collectiblesModel: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null
networksModel: popup.store.allNetworksModel
currentCurrencySymbol: d.currencyStore.currentCurrencySymbol currentCurrencySymbol: d.currencyStore.currentCurrencySymbol
visible: (!!d.selectedHolding && d.selectedHoldingType !== Constants.HoldingType.Unknown) || visible: (!!d.selectedHolding && d.selectedHoldingType !== Constants.HoldingType.Unknown) ||
(!!d.hoveredHolding && d.hoveredHoldingType !== Constants.HoldingType.Unknown) (!!d.hoveredHolding && d.hoveredHoldingType !== Constants.HoldingType.Unknown)
getNetworkIcon: function(chainId){
return popup.store.getNetworkIcon(chainId)
}
onItemSelected: { onItemSelected: {
d.setSelectedHoldingId(holdingId, holdingType) d.setSelectedHoldingId(holdingId, holdingType)
} }
@ -376,13 +373,12 @@ StatusDialog {
visible: !d.selectedHolding visible: !d.selectedHolding
assets: popup.preSelectedAccount && popup.preSelectedAccount.assets ? popup.preSelectedAccount.assets : null assets: popup.preSelectedAccount && popup.preSelectedAccount.assets ? popup.preSelectedAccount.assets : null
collectibles: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null collectibles: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null
networksModel: popup.store.allNetworksModel
onlyAssets: holdingSelector.onlyAssets onlyAssets: holdingSelector.onlyAssets
// TODO remove this as address should be found directly in model itself
searchTokenSymbolByAddressFn: function (address) { searchTokenSymbolByAddressFn: function (address) {
return store.findTokenSymbolByAddress(address) return store.findTokenSymbolByAddress(address)
} }
getNetworkIcon: function(chainId){
return popup.store.getNetworkIcon(chainId)
}
onTokenSelected: { onTokenSelected: {
d.setSelectedHoldingId(symbol, holdingType) d.setSelectedHoldingId(symbol, holdingType)
} }

View File

@ -9,9 +9,6 @@ import utils 1.0
StatusListItem { StatusListItem {
id: root id: root
property var getNetworkIcon: function(chainId) {
return ""
}
signal itemSelected(var selectedItem) signal itemSelected(var selectedItem)
signal itemHovered(var selectedItem, bool hovered) signal itemHovered(var selectedItem, bool hovered)
@ -48,7 +45,7 @@ StatusListItem {
StatusRoundedImage { StatusRoundedImage {
width: 20 width: 20
height: 20 height: 20
image.source: Style.svg("tiny/%1".arg(root.getNetworkIcon(chainId))) image.source: Style.svg("tiny/%1".arg(networkIconUrl))
visible: !isCollection && root.sensor.containsMouse visible: !isCollection && root.sensor.containsMouse
}, },
StatusIcon { StatusIcon {

View File

@ -9,9 +9,7 @@ import utils 1.0
StatusListItem { StatusListItem {
id: root id: root
property var getNetworkIcon: function(chainId){ property var balancesModel
return ""
}
signal tokenSelected(var selectedToken) signal tokenSelected(var selectedToken)
signal tokenHovered(var selectedToken, bool hovered) signal tokenHovered(var selectedToken, bool hovered)
@ -50,13 +48,13 @@ StatusListItem {
statusListItemLabel.anchors.verticalCenterOffset: -12 statusListItemLabel.anchors.verticalCenterOffset: -12
statusListItemLabel.color: Theme.palette.directColor1 statusListItemLabel.color: Theme.palette.directColor1
statusListItemInlineTagsSlot.spacing: 0 statusListItemInlineTagsSlot.spacing: 0
tagsModel: balances.count > 0 ? balances : [] tagsModel: root.balancesModel
tagsDelegate: expandedItem tagsDelegate: expandedItem
statusListItemInlineTagsSlot.children: Row { statusListItemInlineTagsSlot.children: Row {
id: compactRow id: compactRow
spacing: -6 spacing: -6
Repeater { Repeater {
model: balances.count > 0 ? balances : [] model: root.balancesModel
delegate: compactItem delegate: compactItem
} }
} }
@ -72,7 +70,7 @@ StatusListItem {
z: index + 1 z: index + 1
width: 16 width: 16
height: 16 height: 16
image.source: Style.svg("tiny/%1".arg(root.getNetworkIcon(chainId))) image.source: Style.svg("tiny/%1".arg(iconUrl))
visible: !root.sensor.containsMouse || index > d.indexesThatCanBeShown visible: !root.sensor.containsMouse || index > d.indexesThatCanBeShown
} }
} }
@ -88,7 +86,7 @@ StatusListItem {
asset.width: 16 asset.width: 16
asset.height: 16 asset.height: 16
asset.isImage: true asset.isImage: true
asset.name: Style.svg("tiny/%1".arg(root.getNetworkIcon(chainId))) asset.name: Style.svg("tiny/%1".arg(iconUrl))
visible: root.sensor.containsMouse && index <= d.indexesThatCanBeShown visible: root.sensor.containsMouse && index <= d.indexesThatCanBeShown
} }
} }

View File

@ -8,6 +8,7 @@ import utils 1.0
import SortFilterProxyModel 0.2 import SortFilterProxyModel 0.2
import StatusQ 0.1
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
@ -18,6 +19,7 @@ Item {
id: root id: root
property var assetsModel property var assetsModel
property var collectiblesModel property var collectiblesModel
property var networksModel
property string currentCurrencySymbol property string currentCurrencySymbol
property bool onlyAssets: true property bool onlyAssets: true
@ -28,10 +30,6 @@ Item {
return "" return ""
} }
property var getNetworkIcon: function(chainId){
return ""
}
signal itemHovered(string holdingId, var holdingType) signal itemHovered(string holdingId, var holdingType)
signal itemSelected(string holdingId, var holdingType) signal itemSelected(string holdingId, var holdingType)
@ -118,8 +116,22 @@ Item {
return !!item && item.iconUrl ? item.iconUrl : "" return !!item && item.iconUrl ? item.iconUrl : ""
} }
readonly property RolesRenamingModel renamedAllNetworksModel: RolesRenamingModel {
sourceModel: root.networksModel
mapping: RoleRename {
from: "iconUrl"
to: "networkIconUrl"
}
}
readonly property LeftJoinModel collectibleNetworksJointModel: LeftJoinModel {
leftModel: root.collectiblesModel
rightModel: d.renamedAllNetworksModel
joinRole: "chainId"
}
property var collectibleComboBoxModel: SortFilterProxyModel { property var collectibleComboBoxModel: SortFilterProxyModel {
sourceModel: root.collectiblesModel sourceModel: d.collectibleNetworksJointModel
filters: [ filters: [
ExpressionFilter { ExpressionFilter {
expression: { expression: {
@ -183,6 +195,7 @@ Item {
// collectible // collectible
property var uid: model.uid property var uid: model.uid
property var iconUrl: model.iconUrl property var iconUrl: model.iconUrl
property var networkIconUrl: model.networkIconUrl
property var collectionUid: model.collectionUid property var collectionUid: model.collectionUid
property var collectionName: model.collectionName property var collectionName: model.collectionName
property var isCollection: model.isCollection property var isCollection: model.isCollection
@ -278,7 +291,11 @@ Item {
TokenBalancePerChainDelegate { TokenBalancePerChainDelegate {
objectName: "AssetSelector_ItemDelegate_" + symbol objectName: "AssetSelector_ItemDelegate_" + symbol
width: holdingItemSelector.comboBoxControl.popup.width width: holdingItemSelector.comboBoxControl.popup.width
getNetworkIcon: root.getNetworkIcon balancesModel: LeftJoinModel {
leftModel: balances
rightModel: root.networksModel
joinRole: "chainId"
}
onTokenSelected: { onTokenSelected: {
holdingItemSelector.selectedItem = selectedToken holdingItemSelector.selectedItem = selectedToken
d.currentHoldingType = Constants.HoldingType.Asset d.currentHoldingType = Constants.HoldingType.Asset
@ -293,7 +310,6 @@ Item {
CollectibleNestedDelegate { CollectibleNestedDelegate {
objectName: "CollectibleSelector_ItemDelegate_" + collectionUid objectName: "CollectibleSelector_ItemDelegate_" + collectionUid
width: holdingItemSelector.comboBoxControl.popup.width width: holdingItemSelector.comboBoxControl.popup.width
getNetworkIcon: root.getNetworkIcon
onItemSelected: { onItemSelected: {
if (isCollection) { if (isCollection) {
d.currentBrowsingCollectionName = collectionName d.currentBrowsingCollectionName = collectionName

View File

@ -3,6 +3,7 @@ import QtQuick.Layouts 1.14
import SortFilterProxyModel 0.2 import SortFilterProxyModel 0.2
import StatusQ 0.1
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
@ -17,12 +18,12 @@ Item {
property var assets: null property var assets: null
property var collectibles: null property var collectibles: null
property var networksModel
signal tokenSelected(string symbol, var holdingType) signal tokenSelected(string symbol, var holdingType)
signal tokenHovered(string symbol, var holdingType, bool hovered) signal tokenHovered(string symbol, var holdingType, bool hovered)
property var searchTokenSymbolByAddressFn: function (address) { property var searchTokenSymbolByAddressFn: function (address) {
return "" return ""
} }
property var getNetworkIcon: function(chainId){}
property bool onlyAssets: false property bool onlyAssets: false
property int browsingHoldingType: Constants.HoldingType.Asset property int browsingHoldingType: Constants.HoldingType.Asset
@ -53,6 +54,20 @@ Item {
[qsTr("Assets"), qsTr("Collectibles")] [qsTr("Assets"), qsTr("Collectibles")]
property string currentBrowsingCollectionName property string currentBrowsingCollectionName
readonly property RolesRenamingModel renamedAllNetworksModel: RolesRenamingModel {
sourceModel: root.networksModel
mapping: RoleRename {
from: "iconUrl"
to: "networkIconUrl"
}
}
readonly property LeftJoinModel collectiblesNetworksJointModel: LeftJoinModel {
leftModel: root.collectibles
rightModel: d.renamedAllNetworksModel
joinRole: "chainId"
}
} }
implicitWidth: contentLayout.implicitWidth implicitWidth: contentLayout.implicitWidth
@ -135,8 +150,9 @@ Item {
} }
] ]
} }
property var collectiblesModel: SortFilterProxyModel { property var collectiblesModel: SortFilterProxyModel {
sourceModel: root.collectibles sourceModel: d.collectiblesNetworksJointModel
filters: [ filters: [
ExpressionFilter { ExpressionFilter {
expression: { expression: {
@ -154,7 +170,11 @@ Item {
id: tokenDelegate id: tokenDelegate
TokenBalancePerChainDelegate { TokenBalancePerChainDelegate {
width: ListView.view.width width: ListView.view.width
getNetworkIcon: root.getNetworkIcon balancesModel: LeftJoinModel {
leftModel: balances
rightModel: root.networksModel
joinRole: "chainId"
}
onTokenSelected: root.tokenSelected(symbol, Constants.HoldingType.Asset) onTokenSelected: root.tokenSelected(symbol, Constants.HoldingType.Asset)
onTokenHovered: root.tokenHovered(symbol, Constants.HoldingType.Asset, hovered) onTokenHovered: root.tokenHovered(symbol, Constants.HoldingType.Asset, hovered)
} }
@ -172,7 +192,6 @@ Item {
id: collectiblesDelegate id: collectiblesDelegate
CollectibleNestedDelegate { CollectibleNestedDelegate {
width: ListView.view.width width: ListView.view.width
getNetworkIcon: root.getNetworkIcon
onItemHovered: root.tokenHovered(selectedItem.uid, Constants.HoldingType.Collectible, hovered) onItemHovered: root.tokenHovered(selectedItem.uid, Constants.HoldingType.Collectible, hovered)
onItemSelected: { onItemSelected: {
if (isCollection) { if (isCollection) {

View File

@ -30,11 +30,14 @@ QtObject {
property bool isNonArchivalNode: Global.appIsReady && walletSectionInst.isNonArchivalNode property bool isNonArchivalNode: Global.appIsReady && walletSectionInst.isNonArchivalNode
property var marketValueStore: TokenMarketValuesStore{} property var marketValueStore: TokenMarketValuesStore{}
property var allNetworks: networksModule.all
function resetFilter() { function resetFilter() {
walletSectionInst.activityController.updateFilter() walletSectionInst.activityController.updateFilter()
} }
// TODO remove all these by linking chainId for networks and activity using LeftJoinModel
// not possible currently due to the current structure of the activity model
function getNetworkColor(chainId) { function getNetworkColor(chainId) {
return networksModule.all.getChainColor(chainId) return networksModule.all.getChainColor(chainId)
} }

View File

@ -19,6 +19,7 @@ QtObject {
property var assets: walletSectionAssets.assets property var assets: walletSectionAssets.assets
property var fromNetworksModel: walletSectionSendInst.fromNetworksModel property var fromNetworksModel: walletSectionSendInst.fromNetworksModel
property var toNetworksModel: walletSectionSendInst.toNetworksModel property var toNetworksModel: walletSectionSendInst.toNetworksModel
property var allNetworksModel: networksModule.all
property var senderAccounts: walletSectionSendInst.senderAccounts property var senderAccounts: walletSectionSendInst.senderAccounts
property var selectedSenderAccount: walletSectionSendInst.selectedSenderAccount property var selectedSenderAccount: walletSectionSendInst.selectedSenderAccount
property var accounts: walletSectionSendInst.accounts property var accounts: walletSectionSendInst.accounts
@ -247,8 +248,4 @@ QtObject {
function getShortChainIds(chainShortNames) { function getShortChainIds(chainShortNames) {
return walletSectionSendInst.getShortChainIds(chainShortNames) return walletSectionSendInst.getShortChainIds(chainShortNames)
} }
function getNetworkIcon(chainId) {
return walletSectionSendInst.getIconUrl(chainId)
}
} }