feat(@desktop/wallet): Apply flayt vassets model into SendModal and ProfileViews

This commit is contained in:
Khushboo Mehta 2023-11-28 20:16:18 +01:00
parent a975e55271
commit b4002a7120
20 changed files with 272 additions and 83 deletions

View File

@ -18,6 +18,8 @@ import Storybook 1.0
import Models 1.0
import AppLayouts.Wallet.views 1.0
import AppLayouts.Wallet.stores 1.0
SplitView {
id: root
@ -56,13 +58,13 @@ SplitView {
readonly property var currencyStore: CurrenciesStore {}
readonly property var groupedAccountsAssetsModel: GroupedAccountsAssetsModel {}
readonly property var tokensBySymbolModel: TokensBySymbolModel {}
readonly property CommunitiesModel communityModel: CommunitiesModel {}
property WalletAssetsStore walletAssetStore: WalletAssetsStore {
assetsWithFilteredBalances: d.assetsWithFilteredBalances
}
// Added this here simply because the network and address filtering wont work in Storybook applied in AssetsView
readonly property SubmodelProxyModel assetsWithFilteredBalances: SubmodelProxyModel {
sourceModel: d.groupedAccountsAssetsModel
sourceModel: d.walletAssetStore.groupedAccountsAssetsModel
submodelRoleName: "balances"
delegateModel: SortFilterProxyModel {
sourceModel: submodel
@ -71,36 +73,11 @@ SplitView {
d.networksChainsCurrentlySelected
d.addressesSelected
return d.networksChainsCurrentlySelected.split(":").includes(chainId+"") &&
(!! d.addressesSelected ? d.addressesSelected.toUpperCase() === account.toUpperCase() : true)
(!!d.addressesSelected ? d.addressesSelected.toUpperCase() === account.toUpperCase() : true)
}
}
}
}
// renaming tokens by symbol key so that can be used to join models
readonly property var renamedTokensBySymbolModel: RolesRenamingModel {
sourceModel: d.tokensBySymbolModel
mapping: [
RoleRename {
from: "key"
to: "tokensKey"
}
]
}
// join account assets and tokens by symbol model
property LeftJoinModel jointModel: LeftJoinModel {
leftModel: d.assetsWithFilteredBalances
rightModel: d.renamedTokensBySymbolModel
joinRole: "tokensKey"
}
// combining community model with assets to get community meta data
property LeftJoinModel builtAccountAssetsModel: LeftJoinModel {
leftModel: d.jointModel
rightModel: d.communityModel
joinRole: "communityId"
}
}
Popups {
@ -121,7 +98,7 @@ SplitView {
Layout.fillHeight: true
Layout.fillWidth: true
areAssetsLoading: loadingCheckbox.checked
assets: d.builtAccountAssetsModel
assets: d.walletAssetStore.builtAccountAssetsModel
filterVisible: ctrlFilterVisible.checked
currencyStore: d.currencyStore
networkFilters: d.networksChainsCurrentlySelected

View File

@ -13,6 +13,8 @@ import utils 1.0
import Storybook 1.0
import Models 1.0
import AppLayouts.Wallet.stores 1.0
SplitView {
id: root
@ -26,6 +28,8 @@ SplitView {
communityTokensStore: CommunityTokensStore {}
}
readonly property WalletAssetsStore walletAssetStore: WalletAssetsStore{}
ListModel {
id: assetsModel
@ -126,8 +130,14 @@ SplitView {
ProfileShowcaseAssetsPanel {
id: showcasePanel
width: 500
baseModel: assetsModel
baseModel: walletAssetStore.builtAccountAssetsModel
showcaseModel: inShowcaseAssetsModel
getCurrencyAmount: function (amount, symbol) {
return ({amount: amount,
symbol: symbol.toUpperCase(),
displayDecimals: 4,
stripTrailingZeroes: false})
}
}
}

View File

@ -2,6 +2,7 @@ import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import StatusQ 0.1
import StatusQ.Core 0.1
import StatusQ.Controls 0.1
@ -12,13 +13,33 @@ import shared.popups.send 1.0
import shared.stores 1.0
import shared.stores.send 1.0
import SortFilterProxyModel 0.2
import AppLayouts.Wallet.stores 1.0
SplitView {
id: root
orientation: Qt.Horizontal
property WalletAssetsStore walletAssetStore: WalletAssetsStore {
assetsWithFilteredBalances: root.assetsWithFilteredBalances
}
property SubmodelProxyModel assetsWithFilteredBalances: SubmodelProxyModel {
sourceModel: root.walletAssetStore.groupedAccountsAssetsModel
submodelRoleName: "balances"
delegateModel: SortFilterProxyModel {
sourceModel: submodel
filters: ExpressionFilter {
expression: txStore.selectedSenderAccount.address === account
}
}
}
TransactionStore {
id: txStore
walletAssetStore: root.walletAssetStore
}
QtObject {

View File

@ -13,7 +13,6 @@ ListModel {
address: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
walletType: "",
position: 0,
assets: assetsModel
},
{
name: "Hot wallet (generated)",
@ -23,7 +22,6 @@ ListModel {
address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881",
walletType: Constants.generatedWalletType,
position: 3,
assets: assetsModel
},
{
name: "Family (seed)",
@ -33,7 +31,6 @@ ListModel {
address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8882",
walletType: Constants.seedWalletType,
position: 1,
assets: assetsModel
},
{
name: "Tag Heuer (watch)",
@ -43,7 +40,6 @@ ListModel {
address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8883",
walletType: Constants.watchWalletType,
position: 2,
assets: []
},
{
name: "Fab (key)",
@ -53,7 +49,6 @@ ListModel {
address: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8884",
walletType: Constants.keyWalletType,
position: 4,
assets: assetsModel
}
]

View File

@ -0,0 +1,5 @@
import QtQuick 2.15
QtObject {
id: root
}

View File

@ -0,0 +1,44 @@
import QtQuick 2.15
import SortFilterProxyModel 0.2
import StatusQ 0.1
import StatusQ.Core.Utils 0.1 as SQUtils
import Storybook 1.0
import Models 1.0
QtObject {
id: root
property TokensStore walletTokensStore
readonly property var groupedAccountsAssetsModel: GroupedAccountsAssetsModel {}
property var assetsWithFilteredBalances
readonly property var tokensBySymbolModel: TokensBySymbolModel {}
readonly property CommunitiesModel communityModel: CommunitiesModel{}
// renaming tokens by symbol key so that can be used to join models
readonly property var renamedTokensBySymbolModel: RolesRenamingModel {
sourceModel: tokensBySymbolModel
mapping: [
RoleRename {
from: "key"
to: "tokensKey"
}
]
}
// join account assets and tokens by symbol model
property LeftJoinModel jointModel: LeftJoinModel {
leftModel: assetsWithFilteredBalances
rightModel: renamedTokensBySymbolModel
joinRole: "tokensKey"
}
// combining community model with assets to get community meta data
property LeftJoinModel builtAccountAssetsModel: LeftJoinModel {
leftModel: jointModel
rightModel: communityModel
joinRole: "communityId"
}
}

View File

@ -0,0 +1,2 @@
WalletAssetsStore 1.0 WalletAssetsStore.qml
TokensStore 1.0 TokensStore.qml

View File

@ -2,8 +2,12 @@ import QtQuick 2.15
import Models 1.0
import utils 1.0
import StatusQ.Core.Utils 0.1
import StatusQ 0.1
import StatusQ.Core.Utils 0.1 as SQUtils
import shared.stores 1.0
import SortFilterProxyModel 0.2
import AppLayouts.Wallet.stores 1.0
QtObject {
id: root
@ -13,6 +17,9 @@ QtObject {
Component.onCompleted: selectedSenderAccount = senderAccounts.get(0)
}
property var accounts: senderAccounts
property WalletAssetsStore walletAssetStore
property QtObject tmpActivityController: QtObject {
property ListModel model: ListModel{}
}
@ -58,32 +65,32 @@ QtObject {
}
function getAsset(assetsList, symbol) {
const idx = ModelUtils.indexOf(assetsList, "symbol", symbol)
const idx = SQUtils.ModelUtils.indexOf(assetsList, "symbol", symbol)
if (idx < 0) {
return {}
}
return ModelUtils.get(assetsList, idx)
return SQUtils.ModelUtils.get(assetsList, idx)
}
function getCollectible(uid) {
const idx = ModelUtils.indexOf(collectiblesModel, "uid", uid)
const idx = SQUtils.ModelUtils.indexOf(collectiblesModel, "uid", uid)
if (idx < 0) {
return {}
}
return ModelUtils.get(collectiblesModel, idx)
return SQUtils.ModelUtils.get(collectiblesModel, idx)
}
function getSelectorCollectible(uid) {
const idx = ModelUtils.indexOf(nestedCollectiblesModel, "uid", uid)
const idx = SQUtils.ModelUtils.indexOf(nestedCollectiblesModel, "uid", uid)
if (idx < 0) {
return {}
}
return ModelUtils.get(nestedCollectiblesModel, idx)
return SQUtils.ModelUtils.get(nestedCollectiblesModel, idx)
}
function getHolding(holdingId, holdingType) {
if (holdingType === Constants.TokenType.ERC20) {
return getAsset(selectedSenderAccount.assets, holdingId)
return getAsset(walletAssetStore.builtAccountAssetsModel, holdingId)
} else if (holdingType === Constants.TokenType.ERC721) {
return getCollectible(holdingId)
} else {
@ -93,7 +100,7 @@ QtObject {
function getSelectorHolding(holdingId, holdingType) {
if (holdingType === Constants.TokenType.ERC20) {
return getAsset(selectedSenderAccount.assets, holdingId)
return getAsset(walletAssetStore.builtAccountAssetsModel, holdingId)
} else if (holdingType === Constants.TokenType.ERC721) {
return getSelectorCollectible(holdingId)
} else {
@ -118,9 +125,9 @@ QtObject {
}
function holdingToSelectorHolding(holding, holdingType) {
if (holdingType === Constants.TokenType.Asset) {
if (holdingType === Constants.TokenType.ERC20) {
return assetToSelectorAsset(holding)
} else if (holdingType === Constants.TokenType.Collectible) {
} else if (holdingType === Constants.TokenType.ERC721) {
return collectibleToSelectorCollectible(holding)
} else {
return {}
@ -179,7 +186,7 @@ QtObject {
let listOfChains = chainIds.split(":")
let listOfChainIds = []
for (let k =0;k<listOfChains.length;k++) {
listOfChainIds.push(ModelUtils.getByKey(NetworksModel.allNetworks, "shortName", listOfChains[k], "chainId"))
listOfChainIds.push(SQUtils.ModelUtils.getByKey(NetworksModel.allNetworks, "shortName", listOfChains[k], "chainId"))
}
return listOfChainIds
}
@ -249,6 +256,17 @@ QtObject {
}
function getNetworkName(chainId) {
return ModelUtils.getByKey(NetworksModel.allNetworks, "chainId", chainId, "chainName")
return SQUtils.ModelUtils.getByKey(NetworksModel.allNetworks, "chainId", chainId, "chainName")
}
function getCurrencyAmountFromBigInt(balance, symbol, decimals) {
let bigIntBalance = SQUtils.AmountsArithmetic.fromString(balance)
let balance123 = SQUtils.AmountsArithmetic.toNumber(bigIntBalance, decimals)
return currencyStore.getCurrencyAmount(balance123, symbol)
}
function getCurrentCurrencyAmount(balance) {
return currencyStore.getCurrencyAmount(balance, currencyStore.currentCurrency)
}
}

View File

@ -32,6 +32,8 @@ StatusSectionLayout {
property var emojiPopup
property var networkConnectionStore
required property TokensStore tokensStore
required property WalletAssetsStore walletAssetsStore
required property SharedStores.CurrenciesStore currencyStore
backButtonName: root.store.backButtonName
notificationCount: activityCenterStore.unreadNotificationsCount
@ -122,6 +124,8 @@ StatusSectionLayout {
implicitWidth: parent.width
implicitHeight: parent.height
walletAssetsStore: root.walletAssetsStore
currencyStore: root.currencyStore
walletStore: root.store.walletStore
profileStore: root.store.profileStore
privacyStore: root.store.privacyStore

View File

@ -1,12 +1,22 @@
import QtQuick 2.15
import StatusQ 0.1
import StatusQ.Core 0.1
import utils 1.0
ShowcaseDelegate {
property var getCurrencyAmount: function(){}
title: !!showcaseObj && !!showcaseObj.name ? showcaseObj.name : ""
secondaryTitle: !!showcaseObj ? LocaleUtils.currencyAmountToLocaleString(showcaseObj.enabledNetworkBalance) : Qt.locale().zeroDigit
secondaryTitle: !!showcaseObj && !!showcaseObj.decimals && !!showcaseObj.symbol ?
LocaleUtils.currencyAmountToLocaleString(root.getCurrencyAmount(balancesAggregator.value/(10 ** showcaseObj.decimals), showcaseObj.symbol)) :
Qt.locale().zeroDigit
hasImage: true
icon.source: !!showcaseObj ? Constants.tokenIcon(showcaseObj.symbol) : ""
SumAggregator {
id: balancesAggregator
model: !!showcaseObj && !!showcaseObj.balances ? showcaseObj.balances: null
roleName: "balance"
}
}

View File

@ -7,6 +7,8 @@ import AppLayouts.Profile.controls 1.0
ProfileShowcasePanel {
id: root
property var getCurrencyAmount: function(){}
keyRole: "symbol"
roleNames: ["symbol", "name", "enabledNetworkBalance"].concat(showcaseRoles)
filterFunc: (modelData) => modelData.symbol !== "" && !showcaseModel.hasItemInShowcase(modelData.symbol)
@ -18,6 +20,7 @@ ProfileShowcasePanel {
showcaseObj: modelData
dragParent: dragParentData
visualIndex: visualIndexData
getCurrencyAmount: root.getCurrencyAmount()
onShowcaseVisibilityRequested: {
var tmpObj = Object()
root.roleNames.forEach(role => tmpObj[role] = showcaseObj[role])

View File

@ -25,7 +25,6 @@ QtObject {
}
// TODO(alaibe): there should be no access to wallet section, create collectible in profile
property var overview: walletSectionOverview
property var assets: walletSectionAssets.assets
property var accounts: Global.appIsReady? accountsModule.accounts : null
property var originModel: accountsModule.keyPairModel

View File

@ -6,6 +6,7 @@ import utils 1.0
import shared 1.0
import shared.panels 1.0
import shared.popups 1.0
import shared.stores 1.0
import shared.controls.chat 1.0
import "../popups"
@ -18,6 +19,8 @@ import StatusQ.Core.Theme 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import AppLayouts.Wallet.stores 1.0
SettingsContentBase {
id: root
@ -25,6 +28,9 @@ SettingsContentBase {
property ProfileStore profileStore
property PrivacyStore privacyStore
property ContactsStore contactsStore
required property WalletAssetsStore walletAssetsStore
required property CurrenciesStore currencyStore
property var communitiesModel
titleRowComponentLoader.sourceComponent: StatusButton {
@ -75,6 +81,8 @@ SettingsContentBase {
privacyStore: root.privacyStore
walletStore: root.walletStore
communitiesModel: root.communitiesModel
walletAssetsStore: root.walletAssetsStore
currencyStore: root.currencyStore
onVisibleChanged: if (visible) stackLayout.Layout.preferredHeight = settingsView.implicitHeight
Component.onCompleted: stackLayout.Layout.preferredHeight = Qt.binding(() => settingsView.implicitHeight)

View File

@ -4,6 +4,7 @@ import QtQuick.Layouts 1.13
import utils 1.0
import shared 1.0
import shared.stores 1.0
import shared.panels 1.0
import shared.popups 1.0
import shared.controls.chat 1.0
@ -18,6 +19,8 @@ import StatusQ.Core.Theme 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import AppLayouts.Wallet.stores 1.0
ColumnLayout {
id: root
@ -26,6 +29,8 @@ ColumnLayout {
property PrivacyStore privacyStore
property ProfileStore profileStore
property WalletStore walletStore
required property WalletAssetsStore walletAssetsStore
required property CurrenciesStore currencyStore
property var communitiesModel
property bool hasAnyProfileShowcaseChanges: false
@ -244,9 +249,12 @@ ColumnLayout {
id: profileShowcaseAssetsPanel
Layout.minimumHeight: implicitHeight
Layout.maximumHeight: implicitHeight
baseModel: root.walletStore.assets
baseModel: root.walletAssetsStore.groupedAccountAssetsModel
showcaseModel: root.profileStore.profileShowcaseAssetsModel
onShowcaseEntryChanged: hasAnyProfileShowcaseChanges = true
getCurrencyAmount: function(amount, symbol) {
return root.currencyStore.getCurrencyAmount(amount, symbol)
}
}
}
}

View File

@ -26,6 +26,7 @@ import shared.status 1.0
import shared.stores 1.0
import shared.popups.send 1.0
import shared.popups.send.views 1.0
import shared.stores.send 1.0
import StatusQ.Core.Theme 0.1
import StatusQ.Components 0.1
@ -71,6 +72,7 @@ Item {
property CommunitiesStore communitiesStore: CommunitiesStore {}
readonly property WalletStore.TokensStore tokensStore: WalletStore.RootStore.tokensStore
readonly property WalletStore.WalletAssetsStore walletAssetsStore: WalletStore.RootStore.walletAssetsStore
readonly property CurrenciesStore currencyStore: CurrenciesStore{}
// set from main.qml
property var sysPalette
@ -1277,6 +1279,8 @@ Item {
emojiPopup: statusEmojiPopup.item
networkConnectionStore: appMain.networkConnectionStore
tokensStore: appMain.tokensStore
walletAssetsStore: appMain.walletAssetsStore
currencyStore: appMain.currencyStore
}
}
@ -1451,7 +1455,10 @@ Item {
property bool onlyAssets: false
sourceComponent: SendModal {
onlyAssets: sendModal.onlyAssets
onlyAssets: sendModal.onlyAssets
store: TransactionStore {
walletAssetStore: appMain.walletAssetsStore
}
onClosed: {
sendModal.closed()
sendModal.preSelectedSendType = Constants.SendType.Unknown

View File

@ -8,6 +8,7 @@ import SortFilterProxyModel 0.2
import utils 1.0
import shared.stores.send 1.0
import StatusQ 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Controls.Validators 0.1
@ -38,7 +39,7 @@ StatusDialog {
property alias modalHeader: modalHeader.text
property TransactionStore store: TransactionStore {}
property TransactionStore store
property var nestedCollectiblesModel: store.nestedCollectiblesModel
property var bestRoutes
property bool isLoading: false
@ -76,8 +77,9 @@ StatusDialog {
(popup.bestRoutes && popup.bestRoutes.count === 0 &&
!!amountToSendInput.input.text && recipientLoader.ready && !popup.isLoading) ?
Constants.NoRoute : Constants.NoError
readonly property double maxFiatBalance: isSelectedHoldingValidAsset ? selectedHolding.totalCurrencyBalance.amount : 0
readonly property double maxCryptoBalance: isSelectedHoldingValidAsset ? selectedHolding.totalBalance.amount : 0
readonly property double totalSelectedHoldingBalance: isSelectedHoldingValidAsset ? !d.selectedHolding.communityId ? selectedHoldingAggregator.value/(10 ** d.selectedHolding.decimals): selectedHoldingAggregator.value: 0
readonly property double maxFiatBalance: isSelectedHoldingValidAsset && selectedHolding.marketDetails ? totalSelectedHoldingBalance * selectedHolding.marketDetails.currencyPrice.amount : 0
readonly property double maxCryptoBalance: isSelectedHoldingValidAsset ? totalSelectedHoldingBalance : 0
readonly property double maxInputBalance: amountToSendInput.inputIsFiat ? maxFiatBalance : maxCryptoBalance
readonly property string inputSymbol: amountToSendInput.inputIsFiat ? currencyStore.currentCurrency : store.selectedAssetSymbol
readonly property bool errorMode: popup.isLoading || !recipientLoader.ready ? false : errorType !== Constants.NoError || networkSelector.errorMode || !amountToSendInput.inputNumberValid
@ -145,6 +147,23 @@ StatusDialog {
return value - Math.max(0.0001, Math.min(0.01, value * 0.1))
}
property SubmodelProxyModel assetsWithFilteredBalances: SubmodelProxyModel {
sourceModel: popup.store.walletAssetStore.groupedAccountAssetsModel
submodelRoleName: "balances"
delegateModel: SortFilterProxyModel {
sourceModel: submodel
filters: ExpressionFilter {
expression: store.selectedSenderAccount.address === account
}
}
}
}
SumAggregator {
id: selectedHoldingAggregator
model: d.isSelectedHoldingValidAsset ? d.selectedHolding.balances: null
roleName: "balance"
}
width: 556
@ -262,7 +281,7 @@ StatusDialog {
id: holdingSelector
Layout.fillWidth: true
Layout.fillHeight: true
assetsModel: popup.preSelectedAccount && popup.preSelectedAccount.assets ? popup.preSelectedAccount.assets : null
assetsModel: d.assetsWithFilteredBalances
collectiblesModel: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null
networksModel: popup.store.allNetworksModel
currentCurrencySymbol: d.currencyStore.currentCurrencySymbol
@ -271,6 +290,12 @@ StatusDialog {
onItemSelected: {
d.setSelectedHoldingId(holdingId, holdingType)
}
getCurrencyAmountFromBigInt: function(balance, symbol, decimals){
return store.getCurrencyAmountFromBigInt(balance, symbol, decimals)
}
getCurrentCurrencyAmount: function(balance){
return store.getCurrentCurrencyAmount(balance)
}
}
StatusListItemTag {
@ -278,22 +303,27 @@ StatusDialog {
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
Layout.preferredHeight: 22
visible: d.isSelectedHoldingValidAsset || d.isHoveredHoldingValidAsset && !d.isERC721Transfer
SumAggregator {
id: aggregator
model: d.isHoveredHoldingValidAsset && !!d.hoveredHolding.symbol ? d.hoveredHolding.balances: null
roleName: "balance"
}
title: {
if(d.isHoveredHoldingValidAsset && !!d.hoveredHolding.symbol) {
const input = amountToSendInput.inputIsFiat ? d.hoveredHolding.totalCurrencyBalance.amount : d.hoveredHolding.totalBalance.amount
let totalAmount = !d.hoveredHolding.communityId ? aggregator.value/(10 ** d.hoveredHolding.decimals): aggregator.value
const input = amountToSendInput.inputIsFiat ? totalAmount * d.hoveredHolding.marketDetails.currencyPrice.amount : totalAmount
const max = d.prepareForMaxSend(input, d.hoveredHolding.symbol)
if (max <= 0)
return qsTr("No balances active")
const balance = d.currencyStore.formatCurrencyAmount(max , d.hoveredHolding.symbol)
return qsTr("Max: %1").arg(balance)
return qsTr("Max: %1").arg(balance.toString())
}
const max = d.prepareForMaxSend(d.maxInputBalance, d.inputSymbol)
if (max <= 0)
return qsTr("No balances active")
const balance = d.currencyStore.formatCurrencyAmount(max, d.inputSymbol)
return qsTr("Max: %1").arg(balance)
return qsTr("Max: %1").arg(balance.toString())
}
tagClickable: true
closeButtonVisible: false
@ -318,7 +348,7 @@ StatusDialog {
maxInputBalance: d.maxInputBalance
currentCurrency: d.currencyStore.currentCurrency
multiplierIndex: holdingSelector.selectedItem
multiplierIndex: !!holdingSelector.selectedItem
? holdingSelector.selectedItem.decimals
: 0
@ -397,7 +427,7 @@ StatusDialog {
anchors.rightMargin: Style.current.bigPadding
visible: !d.selectedHolding
assets: popup.preSelectedAccount && popup.preSelectedAccount.assets ? popup.preSelectedAccount.assets : null
assets: d.assetsWithFilteredBalances
collectibles: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null
networksModel: popup.store.allNetworksModel
onlyAssets: holdingSelector.onlyAssets
@ -415,6 +445,12 @@ StatusDialog {
d.setHoveredHoldingId("", Constants.TokenType.Unknown)
}
}
getCurrencyAmountFromBigInt: function(balance, symbol, decimals){
return store.getCurrencyAmountFromBigInt(balance, symbol, decimals)
}
getCurrentCurrencyAmount: function(balance){
return store.getCurrentCurrencyAmount(balance)
}
}
ColumnLayout {

View File

@ -1,17 +1,21 @@
import QtQuick 2.13
import StatusQ 0.1
import StatusQ.Core 0.1
import StatusQ.Components 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Core.Utils 0.1 as SQUtils
import utils 1.0
StatusListItem {
id: root
property var balancesModel
signal tokenSelected(var selectedToken)
signal tokenHovered(var selectedToken, bool hovered)
property var getCurrencyAmountFromBigInt: function(balance, symbol, decimals){}
property var getCurrentCurrencyAmount: function(balance){}
property var balancesModel
QtObject {
id: d
@ -21,16 +25,14 @@ StatusListItem {
- compactRow.width) / statusListItemInlineTagsSlot.children[0].width) - 1
function selectToken() {
root.tokenSelected({name, symbol, totalRawBalance, totalBalance,
totalCurrencyBalance, balances, decimals})
root.tokenSelected({name, symbol, balances, decimals})
}
}
Connections {
target: root.sensor
function onContainsMouseChanged() {
root.tokenHovered({name, symbol, totalRawBalance, totalBalance,
totalCurrencyBalance, balances, decimals},
root.tokenHovered({name, symbol, balances, decimals},
root.sensor.containsMouse)
}
}
@ -40,7 +42,13 @@ StatusListItem {
statusListItemTitleAside.font.pixelSize: 15
statusListItemTitleAside.width: statusListItemTitleArea.width - statusListItemTitle.width
statusListItemTitleAside.elide: Text.ElideRight
label: LocaleUtils.currencyAmountToLocaleString(totalCurrencyBalance)
label: {
if (!!model.marketDetails && !!model.marketDetails.currencyPrice) {
let totalCurrencyBalance = aggregator.value/(10 ** decimals) * model.marketDetails.currencyPrice.amount
return LocaleUtils.currencyAmountToLocaleString(root.getCurrentCurrencyAmount(totalCurrencyBalance))
}
return LocaleUtils.currencyAmountToLocaleString(root.getCurrentCurrencyAmount(0))
}
asset.name: symbol ? Style.png("tokens/" + symbol) : ""
asset.isImage: true
asset.width: 32
@ -64,13 +72,19 @@ StatusListItem {
onClicked: d.selectToken()
SumAggregator {
id: aggregator
model: root.balancesModel ? root.balancesModel : null
roleName: "balance"
}
Component {
id: compactItem
StatusRoundedImage {
z: index + 1
width: 16
height: 16
image.source: Style.svg("tiny/%1".arg(iconUrl))
image.source: Style.svg("tiny/%1".arg(model.iconUrl))
visible: !root.sensor.containsMouse || index > d.indexesThatCanBeShown
}
}
@ -79,7 +93,7 @@ StatusListItem {
StatusListItemTag {
height: 16
leftPadding: 0
title: LocaleUtils.currencyAmountToLocaleString(balance)
title: LocaleUtils.currencyAmountToLocaleString(root.getCurrencyAmountFromBigInt(balance, symbol, decimals))
titleText.font.pixelSize: 12
closeButtonVisible: false
bgColor: "transparent"

View File

@ -29,6 +29,8 @@ Item {
property var searchAssetSymbolByAddressFn: function (address) {
return ""
}
property var getCurrencyAmountFromBigInt: function(balance, symbol, decimals){}
property var getCurrentCurrencyAmount: function(balance){}
signal itemHovered(string holdingId, var holdingType)
signal itemSelected(string holdingId, var holdingType)
@ -302,6 +304,12 @@ Item {
root.itemSelected(selectedToken.symbol, Constants.TokenType.ERC20)
holdingItemSelector.comboBoxControl.popup.close()
}
getCurrencyAmountFromBigInt: function(balance, symbol, decimals){
return root.getCurrencyAmountFromBigInt(balance, symbol, decimals)
}
getCurrentCurrencyAmount: function(balance){
return root.getCurrentCurrencyAmount(balance)
}
}
}

View File

@ -26,6 +26,8 @@ Item {
}
property bool onlyAssets: false
property int browsingHoldingType: Constants.TokenType.ERC20
property var getCurrencyAmountFromBigInt: function(balance, symbol, decimals){}
property var getCurrentCurrencyAmount: function(balance){}
onVisibleChanged: {
if(!visible && root.collectibles)
@ -177,6 +179,12 @@ Item {
}
onTokenSelected: root.tokenSelected(symbol, Constants.TokenType.ERC20)
onTokenHovered: root.tokenHovered(symbol, Constants.TokenType.ERC20, hovered)
getCurrencyAmountFromBigInt: function(balance, symbol, decimals){
return root.getCurrencyAmountFromBigInt(balance, symbol, decimals)
}
getCurrentCurrencyAmount: function(balance){
return root.getCurrentCurrencyAmount(balance)
}
}
}
Component {

View File

@ -8,15 +8,17 @@ import utils 1.0
import StatusQ.Core.Utils 0.1
import AppLayouts.Wallet.stores 1.0
QtObject {
id: root
property CurrenciesStore currencyStore: CurrenciesStore {}
property WalletAssetsStore walletAssetStore
property var mainModuleInst: mainModule
property var walletSectionSendInst: walletSectionSend
property var assets: walletSectionAssets.assets
property var fromNetworksModel: walletSectionSendInst.fromNetworksModel
property var toNetworksModel: walletSectionSendInst.toNetworksModel
property var allNetworksModel: networksModule.all
@ -108,15 +110,15 @@ QtObject {
}
function getAsset(assetsList, symbol) {
for(var i=0; i< assetsList.count;i++) {
if(symbol === assetsList.rowData(i, "symbol")) {
for(var i=0; i< assetsList.rowCount();i++) {
let asset = ModelUtils.get(assetsList, i)
if(symbol === asset.symbol) {
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: JSON.parse(assetsList.rowData(i, "totalBalance")),
totalCurrencyBalance: JSON.parse(assetsList.rowData(i, "totalCurrencyBalance")),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
name: asset.name,
symbol: asset.symbol,
totalBalance: asset.totalBalance,
balances: asset.balances,
decimals: asset.decimals
}
}
}
@ -141,7 +143,7 @@ QtObject {
function getHolding(holdingId, holdingType) {
if (holdingType === Constants.TokenType.ERC20) {
return getAsset(selectedSenderAccount.assets, holdingId)
return getAsset(walletAssetStore.groupedAccountAssetsModel, holdingId)
} else if (holdingType === Constants.TokenType.ERC721) {
return getCollectible(holdingId)
} else {
@ -151,7 +153,7 @@ QtObject {
function getSelectorHolding(holdingId, holdingType) {
if (holdingType === Constants.TokenType.ERC20) {
return getAsset(selectedSenderAccount.assets, holdingId)
return getAsset(walletAssetStore.groupedAccountAssetsModel, holdingId)
} else if (holdingType === Constants.TokenType.ERC721) {
return getSelectorCollectible(holdingId)
} else {
@ -256,4 +258,14 @@ QtObject {
function getShortChainIds(chainShortNames) {
return walletSectionSendInst.getShortChainIds(chainShortNames)
}
function getCurrencyAmountFromBigInt(balance, symbol, decimals) {
let bigIntBalance = AmountsArithmetic.fromString(balance)
let balance123 = AmountsArithmetic.toNumber(bigIntBalance, decimals)
return currencyStore.getCurrencyAmount(balance123, symbol)
}
function getCurrentCurrencyAmount(balance) {
return currencyStore.getCurrencyAmount(balance, currencyStore.currentCurrency)
}
}