feat(@StatusAssetSelector): Use asset selector per symbol and not (#715)

address
This commit is contained in:
Anthony Laibe 2022-06-09 15:10:45 +02:00 committed by GitHub
parent 648406c442
commit 18d385cf2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 12 deletions

View File

@ -26,6 +26,7 @@ Item {
property var assetFound property var assetFound
property double minRequiredAssetBalance: 0 property double minRequiredAssetBalance: 0
property int dropdownWidth: width property int dropdownWidth: width
property int chainId: 0
property alias dropdownAlignment: select.menuAlignment property alias dropdownAlignment: select.menuAlignment
property bool isValid: true property bool isValid: true
property bool readOnly: false property bool readOnly: false
@ -46,7 +47,7 @@ Item {
if (showBalanceForAssetSymbol == "" || minRequiredAssetBalance == 0 || !assetFound) { if (showBalanceForAssetSymbol == "" || minRequiredAssetBalance == 0 || !assetFound) {
return root.isValid return root.isValid
} }
root.isValid = assetFound.balance >= minRequiredAssetBalance root.isValid = assetFound.totalBalance >= minRequiredAssetBalance
return root.isValid return root.isValid
} }
@ -67,7 +68,7 @@ Item {
textSelectedAddressFiatBalance.text = selectedAccount.currencyBalance + " " + currency.toUpperCase() textSelectedAddressFiatBalance.text = selectedAccount.currencyBalance + " " + currency.toUpperCase()
} }
if (selectedAccount.assets && showBalanceForAssetSymbol) { if (selectedAccount.assets && showBalanceForAssetSymbol) {
assetFound = Utils.findAssetBySymbol(selectedAccount.assets, showBalanceForAssetSymbol) assetFound = Utils.findAssetByChainAndSymbol(root.chainId, selectedAccount.assets, showBalanceForAssetSymbol)
if (!assetFound) { if (!assetFound) {
console.warn("Cannot find asset '", showBalanceForAssetSymbol, "'. Ensure this asset has been added to the token list.") console.warn("Cannot find asset '", showBalanceForAssetSymbol, "'. Ensure this asset has been added to the token list.")
} }
@ -82,7 +83,7 @@ Item {
if (!assetFound) { if (!assetFound) {
return return
} }
txtAssetBalance.text = root.assetBalanceTextFn(assetFound.balance) txtAssetBalance.text = root.assetBalanceTextFn(assetFound.totalBalance)
txtAssetSymbol.text = " " + assetFound.symbol txtAssetSymbol.text = " " + assetFound.symbol
} }

View File

@ -116,12 +116,12 @@ Item {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
StatusBaseText { StatusBaseText {
font.pixelSize: 15 font.pixelSize: 15
text: parseFloat(balance).toFixed(4) + " " + symbol text: parseFloat(totalBalance).toFixed(4) + " " + symbol
} }
StatusBaseText { StatusBaseText {
font.pixelSize: 15 font.pixelSize: 15
anchors.right: parent.right anchors.right: parent.right
text: getCurrencyBalanceString(currencyBalance) text: getCurrencyBalanceString(totalCurrencyBalance)
color: Theme.palette.baseColor1 color: Theme.palette.baseColor1
} }
} }
@ -130,14 +130,14 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
if(index === 0 ) { if(index === 0 ) {
selectedAsset = { name: name, symbol: symbol, address: address, balance: balance, currencyBalance: currencyBalance} selectedAsset = { name: name, symbol: symbol, totalBalance: totalBalance, totalCurrencyBalance: totalCurrencyBalance}
} }
} }
MouseArea { MouseArea {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
anchors.fill: itemContainer anchors.fill: itemContainer
onClicked: { onClicked: {
selectedAsset = {name: name, symbol: symbol, address: address, balance: balance, currencyBalance: currencyBalance} selectedAsset = {name: name, symbol: symbol, totalBalance: totalBalance, totalCurrencyBalance: totalCurrencyBalance}
select.selectMenu.close() select.selectMenu.close()
} }
} }

View File

@ -45,16 +45,17 @@ QtObject {
return false return false
} }
function findAssetBySymbol(assets, symbolToFind) { function findAssetByChainAndSymbol(chainIdToFind, assets, symbolToFind) {
for(var i=0; i<assets.rowCount(); i++) { for(var i=0; i<assets.rowCount(); i++) {
const symbol = assets.rowData(i, "symbol") const symbol = assets.rowData(i, "symbol")
if (symbol.toLowerCase() === symbolToFind.toLowerCase()) { if (symbol.toLowerCase() === symbolToFind.toLowerCase() && assets.hasChain(i, parseInt(chainIdToFind))) {
return { return {
name: assets.rowData(i, "name"), name: assets.rowData(i, "name"),
symbol, symbol,
balance: assets.rowData(i, "balance"), totalBalance: assets.rowData(i, "totalBalance"),
address: assets.rowData(i, "address"), totalCurrencyBalance: assets.rowData(i, "totalCurrencyBalance"),
currencyBalance: assets.rowData(i, "currencyBalance") fiatBalance: assets.rowData(i, "totalCurrencyBalance"),
chainId: chainIdToFind,
} }
} }
} }