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

View File

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

View File

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