[UI - Swap] Update / improve AccountsSelector component to cover swap design specs

- sort accounts by total currency balance, irrespective of the tokens
held
- fixup 0 sub-balance formatting

Fixes #14779
This commit is contained in:
Lukáš Tinkl 2024-06-25 13:10:46 +02:00 committed by Lukáš Tinkl
parent c6fd0f41db
commit 531252fd73
8 changed files with 40 additions and 16 deletions

View File

@ -20,7 +20,7 @@ SplitView {
emoji: emojiField.text emoji: emojiField.text
walletColor: walletColorField.text walletColor: walletColorField.text
currencyBalance: QtObject { currencyBalance: QtObject {
readonly property double amount: parseInt(currencyBalanceField.text) readonly property double amount: parseFloat(currencyBalanceField.text)
readonly property string symbol: "USD" readonly property string symbol: "USD"
readonly property int displayDecimals: 4 readonly property int displayDecimals: 4
readonly property bool stripTrailingZeroes: false readonly property bool stripTrailingZeroes: false
@ -129,4 +129,4 @@ SplitView {
} }
} }
} }
} }

View File

@ -351,6 +351,8 @@ Rectangle {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
padding: 0 padding: 0
ScrollBar.horizontal.policy: root.tagsScrollBarVisible ? ScrollBar.AsNeeded : ScrollBar.AlwaysOff
Row { Row {
id: row id: row
spacing: 4 spacing: 4

View File

@ -227,7 +227,7 @@ QtObject {
} }
function elideAndFormatWalletAddress(address) { function elideAndFormatWalletAddress(address) {
return elideText(address, 5, 3).replace( return elideText(address, 6, 4).replace(
"0x", "0" + String.fromCodePoint(0x00D7)) "0x", "0" + String.fromCodePoint(0x00D7))
} }

View File

@ -34,13 +34,21 @@ QObject {
value: Constants.watchWalletType value: Constants.watchWalletType
inverted: true inverted: true
} }
sorters: RoleSorter { roleName: "position"; sortOrder: Qt.AscendingOrder } sorters: [
RoleSorter { roleName: "currencyBalanceDouble"; sortOrder: Qt.DescendingOrder },
RoleSorter { roleName: "position"; sortOrder: Qt.AscendingOrder }
]
proxyRoles: [ proxyRoles: [
FastExpressionRole { FastExpressionRole {
name: "accountBalance" name: "accountBalance"
expression: d.processAccountBalance(model.address) expression: d.processAccountBalance(model.address)
expectedRoles: ["address"] expectedRoles: ["address"]
}, },
FastExpressionRole {
name: "currencyBalanceDouble"
expression: model.currencyBalance.amount
expectedRoles: ["currencyBalance"]
},
FastExpressionRole { FastExpressionRole {
name: "fromToken" name: "fromToken"
expression: root.fromToken expression: root.fromToken
@ -88,7 +96,7 @@ QObject {
property string uuid property string uuid
readonly property SubmodelProxyModel filteredBalancesModel: SubmodelProxyModel { readonly property SubmodelProxyModel filteredBalancesModel: SubmodelProxyModel {
sourceModel: root.walletAssetsStore.baseGroupedAccountAssetModel sourceModel: root.walletAssetsStore.baseGroupedAccountAssetModel
submodelRoleName: "balances" submodelRoleName: "balances"
delegateModel: SortFilterProxyModel { delegateModel: SortFilterProxyModel {
@ -119,10 +127,8 @@ QObject {
let balancesModel = ModelUtils.getByKey(filteredBalancesModel, "tokensKey", root.swapFormData.fromTokensKey, "balances") let balancesModel = ModelUtils.getByKey(filteredBalancesModel, "tokensKey", root.swapFormData.fromTokensKey, "balances")
let accountBalance = ModelUtils.getByKey(balancesModel, "account", address) let accountBalance = ModelUtils.getByKey(balancesModel, "account", address)
if(accountBalance) { if(accountBalance && accountBalance.balance !== "0") {
let balance = AmountsArithmetic.toNumber(accountBalance.balance, root.fromToken.decimals) accountBalance.formattedBalance = root.formatCurrencyAmountFromBigInt(accountBalance.balance, root.fromToken.symbol, root.fromToken.decimals)
let formattedBalance = root.formatCurrencyAmount(balance, root.fromToken.symbol)
accountBalance.formattedBalance = formattedBalance
return accountBalance return accountBalance
} }
@ -130,7 +136,7 @@ QObject {
balance: "0", balance: "0",
iconUrl: network.iconUrl, iconUrl: network.iconUrl,
chainColor: network.chainColor, chainColor: network.chainColor,
formattedBalance: root.formatCurrencyAmount(.0 , root.fromToken.symbol) formattedBalance: "0 %1".arg(root.fromToken.symbol)
} }
} }
} }

View File

@ -24,7 +24,7 @@ import shared.controls 1.0
currencyBalance [var] - fiat currency balance currencyBalance [var] - fiat currency balance
amount [number] - amount of currency e.g. 1234 amount [number] - amount of currency e.g. 1234
symbol [string] - currency symbol e.g. "USD" symbol [string] - currency symbol e.g. "USD"
optDisplayDecimals [number] - optional number of decimals to display displayDecimals [number] - optional number of decimals to display
stripTrailingZeroes [bool] - strip trailing zeroes stripTrailingZeroes [bool] - strip trailing zeroes
walletType [string] - wallet type e.g. Constants.watchWalletType. See `Constants` for possible values walletType [string] - wallet type e.g. Constants.watchWalletType. See `Constants` for possible values
migratedToKeycard [bool] - whether account is migrated to keycard migratedToKeycard [bool] - whether account is migrated to keycard
@ -42,7 +42,7 @@ StatusComboBox {
property string selectedAddress: "" property string selectedAddress: ""
// output property for selected account // output property for selected account
readonly property alias currentAccount: selectedEntry.item readonly property alias currentAccount: selectedEntry.item
readonly property string currentAccountAddress: root.control.currentValue ?? "" readonly property string currentAccountAddress: d.currentAccountSelection
// styling options // styling options
type: StatusComboBox.Type.Secondary type: StatusComboBox.Type.Secondary
@ -99,6 +99,8 @@ StatusComboBox {
required property var model required property var model
tagsScrollBarVisible: false
width: ListView.view.width width: ListView.view.width
name: model.name name: model.name
address: model.address address: model.address
@ -122,7 +124,7 @@ StatusComboBox {
id: selectedEntry id: selectedEntry
sourceModel: root.model ?? null sourceModel: root.model ?? null
key: "address" key: "address"
value: control.currentValue value: d.currentAccountSelection
} }
QtObject { QtObject {

View File

@ -20,6 +20,10 @@ AccountSelector {
objectName: "headerBackground" objectName: "headerBackground"
radius: 8 radius: 8
color: d.headerStyleBackgroundColor color: d.headerStyleBackgroundColor
HoverHandler {
cursorShape: root.enabled ? Qt.PointingHandCursor : undefined
}
} }
contentItem: RowLayout { contentItem: RowLayout {
@ -48,8 +52,7 @@ AccountSelector {
horizontalAlignment: Text.AlignLeft horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight elide: Text.ElideRight
font.pixelSize: 15 color: Utils.getContrastingColor(d.headerStyleBackgroundColor)
color: Theme.palette.indirectColor1
} }
} }

View File

@ -40,12 +40,13 @@ StatusListItem {
title: root.name title: root.name
subTitle:{ subTitle:{
if(!!root.address) { if(!!root.address) {
let elidedAddress = StatusQUtils.Utils.elideText(root.address,6,4) let elidedAddress = StatusQUtils.Utils.elideAndFormatWalletAddress(root.address)
return sensor.containsMouse ? root.chainShortNames || Utils.richColorText(elidedAddress, Theme.palette.directColor1) : elidedAddress return sensor.containsMouse ? root.chainShortNames || Utils.richColorText(elidedAddress, Theme.palette.directColor1) : elidedAddress
} }
return "" return ""
} }
statusListItemSubTitle.wrapMode: Text.NoWrap statusListItemSubTitle.wrapMode: Text.NoWrap
statusListItemSubTitle.font.family: Theme.palette.monoFont.name
asset.emoji: root.emoji asset.emoji: root.emoji
asset.color: root.walletColor asset.color: root.walletColor
asset.name: root.emoji ? "filled-account": "" asset.name: root.emoji ? "filled-account": ""
@ -82,6 +83,7 @@ StatusListItem {
} }
] ]
tagsScrollBarVisible: false
inlineTagModel: !!root.accountBalance && !!root.accountBalance.formattedBalance ? 1 : 0 inlineTagModel: !!root.accountBalance && !!root.accountBalance.formattedBalance ? 1 : 0
inlineTagDelegate: StatusListItemTag { inlineTagDelegate: StatusListItemTag {
objectName: "inlineTagDelegate_" + index objectName: "inlineTagDelegate_" + index

View File

@ -834,6 +834,15 @@ QtObject {
return 0 return 0
} }
function getContrastingColor(color) {
const hexcolor = color.toString()
const r = parseInt(hexcolor.substring(1,3), 16);
const g = parseInt(hexcolor.substring(3,5), 16);
const b = parseInt(hexcolor.substring(5,7), 16);
const yiq = ((r*299)+(g*587)+(b*114))/1000;
return (yiq >= 128) ? Theme.palette.black : Theme.palette.white;
}
function getPathForDisplay(path) { function getPathForDisplay(path) {
return path.split("/").join(" / ") return path.split("/").join(" / ")
} }