feat(@desktop/wallet): Apply flat assets model into SendModal

fixes #13016
This commit is contained in:
Khushboo Mehta 2023-11-28 20:16:18 +01:00 committed by Khushboo-dev-cpp
parent 21a33cabd9
commit 087601e28e
26 changed files with 306 additions and 84 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.groupedAccountAssetsModel
filterVisible: ctrlFilterVisible.checked
currencyStore: d.currencyStore
networkFilters: d.networksChainsCurrentlySelected

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,11 @@
import QtQuick 2.15
QtObject {
id: root
property var tokensList
property var collectiblesList
property var savedAddressesModel
property var activityController
property bool areTestNetworksEnabled
}

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 groupedAccountAssetsModel: LeftJoinModel {
leftModel: jointModel
rightModel: communityModel
joinRole: "communityId"
}
}

View File

@ -0,0 +1,3 @@
WalletAssetsStore 1.0 WalletAssetsStore.qml
TokensStore 1.0 TokensStore.qml
ActivityFiltersStore 1.0 ActivityFiltersStore.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.groupedAccountAssetsModel, 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.groupedAccountAssetsModel, 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

@ -15,6 +15,7 @@ import shared.controls 1.0
import shared 1.0
import shared.status 1.0
import shared.popups.send 1.0
import shared.stores.send 1.0
import "popups"
import "controls"
@ -30,6 +31,7 @@ StatusSectionLayout {
property var globalStore
property var sendTransactionModal
required property TransactionStore transactionStore
function openUrlInNewTab(url) {
var tab = _internal.addNewTab()
@ -65,6 +67,7 @@ StatusSectionLayout {
anchors.centerIn: parent
preSelectedHoldingID: "ETH"
preSelectedHoldingType: Constants.TokenType.ERC20
store: root.transactionStore
}
property Component signMessageModalComponent: SignMessageModal {}

View File

@ -4,6 +4,7 @@ import QtQuick.Layouts 1.14
import utils 1.0
import shared.popups 1.0
import shared.stores.send 1.0
import "views"
import "stores"
@ -26,6 +27,7 @@ StackLayout {
readonly property var permissionsStore: rootStore.permissionsStore
property var communitiesStore
required property WalletStore.TokensStore tokensStore
required property TransactionStore transactionStore
property var sectionItemModel
property var sendModalPopup
@ -139,6 +141,7 @@ StackLayout {
stickersPopup: root.stickersPopup
contactsStore: root.contactsStore
rootStore: root.rootStore
transactionStore: root.transactionStore
createChatPropertiesStore: root.createChatPropertiesStore
communitiesStore: root.communitiesStore
sectionItemModel: root.sectionItemModel
@ -193,6 +196,7 @@ StackLayout {
walletAccountsModel: WalletStore.RootStore.nonWatchAccounts
tokensStore: root.tokensStore
sendModalPopup: root.sendModalPopup
transactionStore: root.transactionStore
isPendingOwnershipRequest: root.isPendingOwnershipRequest

View File

@ -8,6 +8,7 @@ import shared.panels 1.0
import shared.popups 1.0
import shared.status 1.0
import shared.views.chat 1.0
import shared.stores.send 1.0
import StatusQ.Layout 0.1
import StatusQ.Popups 0.1
@ -29,6 +30,7 @@ StatusSectionLayout {
property bool hasAddedContacts: contactsStore.myContactsModel.count > 0
property RootStore rootStore
required property TransactionStore transactionStore
property var createChatPropertiesStore
property var communitiesStore
property var sectionItemModel
@ -256,6 +258,7 @@ StatusSectionLayout {
Component {
id: statusStickerPackClickPopup
StatusStickerPackClickPopup{
transactionStore: root.transactionStore
onClosed: {
destroy();
}

View File

@ -36,7 +36,7 @@ StatusSectionLayout {
property var chatCommunitySectionModule
required property TokensStore tokensStore
property var community
property var transactionStore: TransactionStore {}
required property var transactionStore
property bool communitySettingsDisabled
property var sendModalPopup

View File

@ -7,6 +7,7 @@ import shared 1.0
import shared.panels 1.0
import shared.stores 1.0 as SharedStores
import shared.popups.keycard 1.0
import shared.stores.send 1.0
import AppLayouts.Wallet.controls 1.0
import AppLayouts.Wallet.stores 1.0
@ -32,6 +33,7 @@ StatusSectionLayout {
property var emojiPopup
property var networkConnectionStore
required property TokensStore tokensStore
required property TransactionStore transactionStore
backButtonName: root.store.backButtonName
notificationCount: activityCenterStore.unreadNotificationsCount
@ -159,6 +161,7 @@ StatusSectionLayout {
contactsStore: root.store.contactsStore
stickersStore: root.store.stickersStore
networkConnectionStore: root.networkConnectionStore
transactionStore: root.transactionStore
profileContentWidth: d.contentWidth
}
}

View File

@ -11,11 +11,13 @@ import utils 1.0
import shared.status 1.0
import shared.popups 1.0
import shared.popups.send 1.0
import shared.stores.send 1.0
Item {
id: root
property var ensUsernamesStore
property var contactsStore
required property TransactionStore transactionStore
property string username: ""
property string chainId: ""
property string walletAddress: "-"
@ -118,6 +120,7 @@ Item {
id: releaseEnsModal
modalHeader: qsTr("Release your username")
interactive: false
store: root.transactionStore
preSelectedSendType: Constants.SendType.ENSRelease
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0)

View File

@ -13,12 +13,14 @@ import shared.panels 1.0
import shared.status 1.0
import shared.controls 1.0
import shared.popups.send 1.0
import shared.stores.send 1.0
Item {
id: root
property var ensUsernamesStore
property var contactsStore
required property TransactionStore transactionStore
property int profileContentWidth
signal continueClicked(string output, string username)
@ -63,6 +65,7 @@ Item {
id: connectEnsModal
modalHeader: qsTr("Connect username with your pubkey")
interactive: false
store: root.transactionStore
preSelectedSendType: Constants.SendType.ENSSetPubKey
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0)

View File

@ -7,6 +7,7 @@ import utils 1.0
import shared.popups 1.0
import shared.status 1.0
import shared.popups.send 1.0
import shared.stores.send 1.0
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
@ -19,6 +20,7 @@ Item {
property var ensUsernamesStore
property var contactsStore
property var stickersStore
required property TransactionStore transactionStore
property string username: ""
signal backBtnClicked();
@ -48,6 +50,7 @@ Item {
sourceComponent: SendModal {
id: buyEnsModal
interactive: false
store: root.transactionStore
preSelectedSendType: Constants.SendType.ENSRegister
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(10)

View File

@ -5,6 +5,7 @@ import QtQml.StateMachine 1.14 as DSM
import utils 1.0
import shared 1.0
import shared.stores.send 1.0
import "../stores"
@ -16,6 +17,7 @@ Item {
property var contactsStore
property var stickersStore
property var networkConnectionStore
required property TransactionStore transactionStore
property int profileContentWidth
property bool showSearchScreen: false
@ -222,6 +224,7 @@ Item {
EnsSearchView {
ensUsernamesStore: ensView.ensUsernamesStore
contactsStore: ensView.contactsStore
transactionStore: ensView.transactionStore
profileContentWidth: ensView.profileContentWidth
onContinueClicked: {
if(output === "connected"){
@ -244,6 +247,7 @@ Item {
ensUsernamesStore: ensView.ensUsernamesStore
contactsStore: ensView.contactsStore
stickersStore: ensView.stickersStore
transactionStore: ensView.transactionStore
username: selectedUsername
onBackBtnClicked: back();
onUsernameRegistered: done(userName);
@ -302,6 +306,7 @@ Item {
EnsDetailsView {
ensUsernamesStore: ensView.ensUsernamesStore
contactsStore: ensView.contactsStore
transactionStore: ensView.transactionStore
username: selectedUsername
chainId: selectedChainId
onBackBtnClicked: back()

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,10 @@ 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{}
readonly property TransactionStore transactionStore: TransactionStore{
walletAssetStore: appMain.walletAssetsStore
}
// set from main.qml
property var sysPalette
@ -488,6 +493,7 @@ Item {
sourceComponent: StatusStickersPopup {
id: statusStickersPopup
store: appMain.rootChatStore
transactionStore: appMain.transactionStore
}
}
@ -1198,6 +1204,7 @@ Item {
}
createChatPropertiesStore: appMain.createChatPropertiesStore
tokensStore: appMain.tokensStore
transactionStore: appMain.transactionStore
emojiPopup: statusEmojiPopup.item
stickersPopup: statusStickersPopupLoader.item
@ -1270,6 +1277,7 @@ Item {
sourceComponent: BrowserLayout {
globalStore: appMain.rootStore
sendTransactionModal: sendModal
transactionStore: appMain.transactionStore
}
// Loaders do not have access to the context, so props need to be set
// Adding a "_" to avoid a binding loop
@ -1292,6 +1300,7 @@ Item {
emojiPopup: statusEmojiPopup.item
networkConnectionStore: appMain.networkConnectionStore
tokensStore: appMain.tokensStore
transactionStore: appMain.transactionStore
}
}
@ -1372,6 +1381,7 @@ Item {
}
}
tokensStore: appMain.tokensStore
transactionStore: appMain.transactionStore
onProfileButtonClicked: {
Global.changeAppSectionBySectionType(Constants.appSection.profile);
@ -1466,7 +1476,8 @@ Item {
property bool onlyAssets: false
sourceComponent: SendModal {
onlyAssets: sendModal.onlyAssets
onlyAssets: sendModal.onlyAssets
store: appMain.transactionStore
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 {}
required 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
@ -147,6 +149,21 @@ StatusDialog {
}
}
SumAggregator {
id: selectedHoldingAggregator
model: SortFilterProxyModel {
sourceModel: d.isSelectedHoldingValidAsset ? d.selectedHolding.balances: d.isHoveredHoldingValidAsset && !!d.hoveredHolding.symbol ? d.hoveredHolding.balances: null
filters: FastExpressionFilter {
expression: {
store.selectedSenderAccount
return store.selectedSenderAccount.address === model.account
}
expectedRoles: ["account"]
}
}
roleName: "balance"
}
width: 556
padding: 0
@ -201,7 +218,9 @@ StatusDialog {
getNetworkShortNames: function(chainIds) {return store.getNetworkShortNames(chainIds)}
onSelectedIndexChanged: {
store.switchSenderAccount(selectedIndex)
d.setSelectedHoldingId(d.selectedHolding.symbol, d.selectedHoldingType)
if (d.isSelectedHoldingValidAsset) {
d.setSelectedHoldingId(d.selectedHolding.symbol, d.selectedHoldingType)
}
popup.recalculateRoutesAndFees()
}
}
@ -262,7 +281,8 @@ StatusDialog {
id: holdingSelector
Layout.fillWidth: true
Layout.fillHeight: true
assetsModel: popup.preSelectedAccount && popup.preSelectedAccount.assets ? popup.preSelectedAccount.assets : null
selectedSenderAccount: store.selectedSenderAccount.address
assetsModel: popup.store.walletAssetStore.groupedAccountAssetsModel
collectiblesModel: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null
networksModel: popup.store.allNetworksModel
currentCurrencySymbol: d.currencyStore.currentCurrencySymbol
@ -271,6 +291,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 {
@ -280,20 +306,20 @@ StatusDialog {
visible: d.isSelectedHoldingValidAsset || d.isHoveredHoldingValidAsset && !d.isERC721Transfer
title: {
if(d.isHoveredHoldingValidAsset && !!d.hoveredHolding.symbol) {
const input = amountToSendInput.inputIsFiat ? d.hoveredHolding.totalCurrencyBalance.amount : d.hoveredHolding.totalBalance.amount
let totalAmount = !d.hoveredHolding.communityId ? selectedHoldingAggregator.value/(10 ** d.hoveredHolding.decimals): selectedHoldingAggregator.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 +344,7 @@ StatusDialog {
maxInputBalance: d.maxInputBalance
currentCurrency: d.currencyStore.currentCurrency
multiplierIndex: holdingSelector.selectedItem
multiplierIndex: !!holdingSelector.selectedItem
? holdingSelector.selectedItem.decimals
: 0
@ -397,7 +423,8 @@ StatusDialog {
anchors.rightMargin: Style.current.bigPadding
visible: !d.selectedHolding
assets: popup.preSelectedAccount && popup.preSelectedAccount.assets ? popup.preSelectedAccount.assets : null
selectedSenderAccount: store.selectedSenderAccount.address
assets: popup.store.walletAssetStore.groupedAccountAssetsModel
collectibles: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null
networksModel: popup.store.allNetworksModel
onlyAssets: holdingSelector.onlyAssets
@ -415,6 +442,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,23 @@
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 SortFilterProxyModel 0.2
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
property string selectedSenderAccount
QtObject {
id: d
@ -21,16 +27,33 @@ 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})
}
readonly property string balanceRoleName: "balance"
property string roleName: balanceRoleName
}
property var filteredBalances : SortFilterProxyModel {
sourceModel: root.balancesModel
filters: FastExpressionFilter {
expression: {
root.selectedSenderAccount
return root.selectedSenderAccount === model.account
}
expectedRoles: ["account"]
}
onCountChanged: {
// Added because the SumAggregator is not evaluated after the filters are applied
d.roleName = ""
d.roleName = d.balanceRoleName
}
}
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 +63,13 @@ StatusListItem {
statusListItemTitleAside.font.pixelSize: 15
statusListItemTitleAside.width: statusListItemTitleArea.width - statusListItemTitle.width
statusListItemTitleAside.elide: Text.ElideRight
label: LocaleUtils.currencyAmountToLocaleString(totalCurrencyBalance)
label: {
if (!!model && !!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
@ -48,13 +77,13 @@ StatusListItem {
statusListItemLabel.anchors.verticalCenterOffset: -12
statusListItemLabel.color: Theme.palette.directColor1
statusListItemInlineTagsSlot.spacing: 0
tagsModel: root.balancesModel
tagsModel: filteredBalances
tagsDelegate: expandedItem
statusListItemInlineTagsSlot.children: Row {
id: compactRow
spacing: -6
Repeater {
model: root.balancesModel
model: filteredBalances
delegate: compactItem
}
}
@ -64,13 +93,19 @@ StatusListItem {
onClicked: d.selectToken()
SumAggregator {
id: aggregator
model: filteredBalances
roleName: d.roleName
}
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 +114,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

@ -17,7 +17,9 @@ import "../controls"
Item {
id: root
property var assetsModel
property string selectedSenderAccount
property var collectiblesModel
property var networksModel
property string currentCurrencySymbol
@ -29,6 +31,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)
@ -189,7 +193,7 @@ Item {
// asset
property var symbol: model.symbol
property var totalBalance: model.totalBalance
property var totalCurrencyBalance: model.totalCurrencyBalance
property var marketDetails: model.marketDetails
property var decimals: model.decimals
property var balances: model.balances
// collectible
@ -291,6 +295,7 @@ Item {
TokenBalancePerChainDelegate {
objectName: "AssetSelector_ItemDelegate_" + symbol
width: holdingItemSelector.comboBoxControl.popup.width
selectedSenderAccount: root.selectedSenderAccount
balancesModel: LeftJoinModel {
leftModel: balances
rightModel: root.networksModel
@ -302,6 +307,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

@ -16,6 +16,7 @@ import "../controls"
Item {
id: root
property string selectedSenderAccount
property var assets: null
property var collectibles: null
property var networksModel
@ -26,6 +27,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)
@ -170,6 +173,7 @@ Item {
id: tokenDelegate
TokenBalancePerChainDelegate {
width: ListView.view.width
selectedSenderAccount: root.selectedSenderAccount
balancesModel: LeftJoinModel {
leftModel: model.balances
rightModel: root.networksModel
@ -177,6 +181,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

@ -14,6 +14,7 @@ import shared.popups 1.0
import shared.status 1.0
import shared.stores 1.0 as SharedStores
import shared.popups.send 1.0
import shared.stores.send 1.0
//TODO remove this dependency!
import AppLayouts.Chat.stores 1.0
@ -23,6 +24,7 @@ Item {
property var store
property var stickerPacks: StickerPackData {}
required property TransactionStore transactionStore
property string packId
property bool marketVisible
@ -200,6 +202,7 @@ Item {
required property string packId
interactive: false
store: root.transactionStore
preSelectedSendType: Constants.SendType.StickersBuy
preSelectedRecipient: root.store.stickersStore.getStickersMarketAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price))

View File

@ -11,6 +11,7 @@ import shared.popups 1.0
import shared.status 1.0
import shared.stores 1.0 as SharedStores
import shared.popups.send 1.0
import shared.stores.send 1.0
//TODO remove this dependency!
import "../../../app/AppLayouts/Chat/stores"
@ -22,6 +23,7 @@ ModalPopup {
property string packId
property var store
required property TransactionStore transactionStore
property string thumbnail: ""
property string name: ""
property string author: ""
@ -69,6 +71,7 @@ ModalPopup {
SendModal {
id: buyStickersPackModal
interactive: false
store: stickerPackDetailsPopup.transactionStore
preSelectedSendType: Constants.SendType.StickersBuy
preSelectedRecipient: stickerPackDetailsPopup.store.stickersStore.getStickersMarketAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price))

View File

@ -5,6 +5,7 @@ import QtGraphicalEffects 1.0
import utils 1.0
import shared.panels 1.0
import shared.stores.send 1.0
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
@ -17,6 +18,7 @@ Popup {
id: root
property var store
required property TransactionStore transactionStore
signal stickerSelected(string hashId, string packId, string url)
@ -95,6 +97,7 @@ Popup {
Layout.fillWidth: true
Layout.fillHeight: true
store: root.store
transactionStore: root.transactionStore
stickerPacks: d.stickerPackList
packId: stickerPackListView.selectedPackId
marketVisible: d.stickerPacksLoaded && d.online

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 decimalBalance = AmountsArithmetic.toNumber(bigIntBalance, decimals)
return currencyStore.getCurrencyAmount(decimalBalance, symbol)
}
function getCurrentCurrencyAmount(balance) {
return currencyStore.getCurrencyAmount(balance, currencyStore.currentCurrency)
}
}