Skip to content

Commit

Permalink
fix(SendModal): fix various issues with SendModal
Browse files Browse the repository at this point in the history
- Fix errors when switching between assets and collectibles tabs
  - Fix by controlling the order of instantiation between model and
    delegates not to mix models and delegates from different sources
- Fix size errors
- Various improvements

Updates: #14212
  • Loading branch information
stefandunca committed Apr 3, 2024
1 parent d86be3a commit e29ea2e
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 22 deletions.
1 change: 1 addition & 0 deletions ui/StatusQ/src/StatusQ/Core/LocaleUtils.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ QtObject {
return 0
}

console.assert(typeof num !== "undefined", "passed number should not be undefined")
return num.toString().split('.')[1].length
}

Expand Down
17 changes: 13 additions & 4 deletions ui/imports/shared/popups/send/SendModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ StatusDialog {
maxInputBalance: d.maxInputBalance
currentCurrency: d.currencyStore.currentCurrency

multiplierIndex: d.isSelectedHoldingValidAsset
// Collectibles do not have decimals
multiplierIndex: d.isSelectedHoldingValidAsset && !!holdingSelector.selectedItem && !!holdingSelector.selectedItem.decimals
? holdingSelector.selectedItem.decimals
: 0

Expand Down Expand Up @@ -402,8 +403,8 @@ StatusDialog {
collectibles: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null
networksModel: popup.store.flatNetworksModel
onlyAssets: holdingSelector.onlyAssets
onTokenSelected: {
d.setSelectedHoldingId(symbol, holdingType)
onTokenSelected: function (symbolOrTokenKey, holdingType) {
d.setSelectedHoldingId(symbolOrTokenKey, holdingType)
}
onTokenHovered: {
if(hovered) {
Expand Down Expand Up @@ -502,7 +503,15 @@ StatusDialog {
if (!!d.selectedHolding && !!d.selectedHolding.marketDetails && !!d.selectedHolding.marketDetails.currencyPrice)
totalTokenFeesInFiat = gasTimeEstimate.totalTokenFees * d.selectedHolding.marketDetails.currencyPrice.amount
d.totalFeesInFiat = d.currencyStore.getFiatValue(gasTimeEstimate.totalFeesInEth, Constants.ethToken) + totalTokenFeesInFiat
d.totalAmountToReceive = popup.store.getWei2Eth(txRoutes.amountToReceive, d.selectedHolding.decimals)

if (!!d.selectedHolding.type && (d.selectedHolding.type === Constants.TokenType.ERC20
|| d.selectedHolding.type === Constants.TokenType.ETH)) {
// If assets
d.totalAmountToReceive = popup.store.getWei2Eth(txRoutes.amountToReceive, d.selectedHolding.decimals)
} else {
// If collectible
d.totalAmountToReceive = txRoutes.amountToReceive
}
networkSelector.toNetworksList = txRoutes.toNetworksModel
popup.isLoading = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import utils 1.0
StatusListItem {
id: root

required property var model
required property string name
required property string symbol
required property int decimals
required property var balances

signal tokenSelected(var selectedToken)
signal tokenHovered(var selectedToken, bool hovered)
property var formatCurrentCurrencyAmount: function(balance){}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ StatusListItem {
width: !!icon ? 15: 0
height: !!icon ? 15 : 0
color: Theme.palette.directColor1
icon: modelData.walletType === Constants.watchWalletType ? "show" : ""
icon: !!modelData && modelData.walletType === Constants.watchWalletType ? "show" : ""
}
StatusIcon {
width: !!icon ? 15: 0
height: !!icon ? 15 : 0
color: Theme.palette.directColor1
icon: modelData.migratedToKeycard ? "keycard" : ""
icon: !!modelData && modelData.migratedToKeycard ? "keycard" : ""
}
}
},
Expand Down
22 changes: 18 additions & 4 deletions ui/imports/shared/popups/send/panels/HoldingSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,29 @@ Item {
property var groupName: model.groupName
property var isGroup: model.isGroup
property var count: model.count

sourceComponent: d.isCurrentBrowsingTypeAsset ? assetComboBoxDelegate : collectibleComboBoxDelegate
}
}

// Switch models and delegate in the right order not to mix different models and delegates
function updateComponents() {
holdingItemSelector.comboBoxModel = []
sourceComponent: d.isCurrentBrowsingTypeAsset ? assetComboBoxDelegate : collectibleComboBoxDelegate
holdingItemSelector.comboBoxModel = d.isCurrentBrowsingTypeAsset
? root.assetsModel
: d.collectibleComboBoxModel
}
Component.onCompleted: updateComponents()
Connections {
target: d
function onIsCurrentBrowsingTypeAssetChanged() {
holdingItemSelector.updateComponents()
}
}
comboBoxModel: null

comboBoxPopupHeader: headerComponent
itemTextFn: d.isCurrentBrowsingTypeAsset ? d.assetTextFn : d.collectibleTextFn
itemIconSourceFn: d.isCurrentBrowsingTypeAsset ? d.assetIconSourceFn : d.collectibleIconSourceFn
comboBoxModel: d.isCurrentBrowsingTypeAsset ? root.assetsModel : d.collectibleComboBoxModel
onComboBoxModelChanged: updateHasCommunityTokens()

function updateHasCommunityTokens() {
Expand Down Expand Up @@ -348,7 +362,7 @@ Item {
rightModel: root.networksModel
joinRole: "chainId"
}
onTokenSelected: {
onTokenSelected: function (selectedToken) {
holdingItemSelector.selectedItem = selectedToken
d.currentHoldingType = Constants.TokenType.ERC20
root.itemSelected(selectedToken.symbol, Constants.TokenType.ERC20)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Item {
QtObject {
id: d
property double customAmountToSend: 0
readonly property string selectedSymbol: !!selectedAsset ? selectedAsset.symbol : ""
// Collectibles don't have a symbol
readonly property string selectedSymbol: !!selectedAsset && !!selectedAsset.symbol ? selectedAsset.symbol : ""

function resetAllSetValues() {
for(var i = 0; i<fromNetworksRepeater.count; i++) {
Expand Down
10 changes: 8 additions & 2 deletions ui/imports/shared/popups/send/views/NetworkSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ Item {
errorMode: root.errorMode
errorType: root.errorType
toNetworksList: root.toNetworksList
selectedSymbol: !!root.selectedAsset ? root.selectedAsset.symbol: ""
// Collectibles don't have a symbol
selectedSymbol: !!root.selectedAsset && !!root.selectedAsset.symbol ? root.selectedAsset.symbol: ""
weiToEth: function(wei) {
if(!!selectedAsset && root.selectedAsset !== undefined)
return parseFloat(store.getWei2Eth(wei, root.selectedAsset.decimals))
Expand Down Expand Up @@ -124,8 +125,13 @@ Item {
isBridgeTx: root.isBridgeTx
errorType: root.errorType
weiToEth: function(wei) {
if(!!selectedAsset && selectedAsset !== undefined)
if(!!selectedAsset && !!selectedAsset.type
&& (selectedAsset.type === Constants.TokenType.Native
|| selectedAsset.type === Constants.TokenType.ERC20)
) {
return parseFloat(store.getWei2Eth(wei, selectedAsset.decimals))
}
return 0
}
}
}
Expand Down
35 changes: 26 additions & 9 deletions ui/imports/shared/popups/send/views/TokenListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Item {
if(!visible) {
if (!!root.collectibles)
root.collectibles.currentGroupId = ""
tokenList.headerItem.input.edit.clear()
// Send Modal doesn't open with a valid headerItem
if (!!tokenList.headerItem && !!tokenList.headerItem.input)
tokenList.headerItem.input.edit.clear()
}
}

Expand Down Expand Up @@ -145,9 +147,21 @@ Item {
Layout.fillWidth: true
Layout.fillHeight: true

header: d.isBrowsingTypeERC20 ? tokenHeader : collectibleHeader
model: d.isBrowsingTypeERC20 ? root.assets : collectiblesModel
delegate: d.isBrowsingTypeERC20 ? tokenDelegate : collectiblesDelegate
// Control order of components not to mix models and delegates
function resetComponents() {
tokenList.model = []
tokenList.delegate = d.isBrowsingTypeERC20 ? tokenDelegate : collectiblesDelegate
tokenList.header = d.isBrowsingTypeERC20 ? tokenHeader : collectibleHeader
tokenList.model = d.isBrowsingTypeERC20 ? root.assets : root.collectiblesModel
}

Component.onCompleted: resetComponents()
Connections {
target: d
function onIsBrowsingTypeERC20Changed() {
tokenList.resetComponents()
}
}

property bool hasCommunityTokens: false
function updateHasCommunityTokens() {
Expand Down Expand Up @@ -205,14 +219,17 @@ Item {
Component {
id: tokenDelegate
TokenBalancePerChainDelegate {
width: ListView.view.width
width: tokenList.width

selectedSenderAccount: root.selectedSenderAccount
balancesModel: LeftJoinModel {
leftModel: !!model & !!model.balances ? model.balances : null
rightModel: root.networksModel
joinRole: "chainId"
}
onTokenSelected: root.tokenSelected(symbol, Constants.TokenType.ERC20)
onTokenSelected: function (selectedToken) {
root.tokenSelected(selectedToken.symbol, Constants.TokenType.ERC20)
}
onTokenHovered: root.tokenHovered(symbol, Constants.TokenType.ERC20, hovered)
formatCurrentCurrencyAmount: function(balance){
return root.formatCurrentCurrencyAmount(balance)
Expand All @@ -227,15 +244,15 @@ Item {
SearchBoxWithRightIcon {
showTopBorder: !root.onlyAssets
showBottomBorder: false
width: ListView.view.width
width: tokenList.width
placeholderText: qsTr("Search for token or enter token address")
onTextChanged: Qt.callLater(d.updateAssetSearchText, text)
}
}
Component {
id: collectiblesDelegate
CollectibleNestedDelegate {
width: ListView.view.width
width: tokenList.width
onItemHovered: root.tokenHovered(selectedItem.uid, tokenType, hovered)
onItemSelected: {
if (isGroup) {
Expand All @@ -250,7 +267,7 @@ Item {
Component {
id: collectibleHeader
ColumnLayout {
width: parent.width
width: tokenList.width
spacing: 0
CollectibleBackButtonWithInfo {
Layout.fillWidth: true
Expand Down

0 comments on commit e29ea2e

Please sign in to comment.