feat(wallet): Add asset sorting by 1 day fiat change (#13826)
This commit is contained in:
parent
1e13d8f122
commit
3188250b1d
|
@ -6,6 +6,7 @@ type
|
|||
ModelRole {.pure.} = enum
|
||||
ChainId = UserRole + 1
|
||||
Balance
|
||||
Balance1DayAgo
|
||||
Account
|
||||
|
||||
QtObject:
|
||||
|
@ -39,6 +40,7 @@ QtObject:
|
|||
{
|
||||
ModelRole.ChainId.int:"chainId",
|
||||
ModelRole.Balance.int:"balance",
|
||||
ModelRole.Balance1DayAgo.int:"balance1DayAgo",
|
||||
ModelRole.Account.int:"account",
|
||||
}.toTable
|
||||
|
||||
|
@ -55,5 +57,7 @@ QtObject:
|
|||
result = newQVariant(item.chainId)
|
||||
of ModelRole.Balance:
|
||||
result = newQVariant(item.balance.toString(10))
|
||||
of ModelRole.Balance1DayAgo:
|
||||
result = newQVariant(item.balance1DayAgo.toString(10))
|
||||
of ModelRole.Account:
|
||||
result = newQVariant(item.account)
|
||||
|
|
|
@ -4,12 +4,14 @@ type BalanceItem* = ref object of RootObj
|
|||
account*: string
|
||||
chainId*: int
|
||||
balance*: Uint256
|
||||
balance1DayAgo*: Uint256
|
||||
|
||||
proc `$`*(self: BalanceItem): string =
|
||||
result = fmt"""BalanceItem[
|
||||
account: {self.account},
|
||||
chainId: {self.chainId},
|
||||
balance: {self.balance}]"""
|
||||
balance: {self.balance},
|
||||
balance1DayAgo: {self.balance1DayAgo}]"""
|
||||
|
||||
type
|
||||
GroupedTokenItem* = ref object of RootObj
|
||||
|
|
|
@ -48,17 +48,23 @@ proc onAllTokensBuilt*(self: Service, response: string) {.slot.} =
|
|||
if not rawBalanceStr.contains("nil"):
|
||||
rawBalance = rawBalanceStr.parse(Uint256)
|
||||
|
||||
var balance1DayAgo: Uint256 = u256(0)
|
||||
let balance1DayAgoStr = balanceObj{"balance1DayAgo"}.getStr
|
||||
if not balance1DayAgoStr.contains("nil"):
|
||||
balance1DayAgo = stint.parse(balance1DayAgoStr, UInt256)
|
||||
|
||||
let token_by_symbol_key = if communityId.isEmptyOrWhitespace: symbol
|
||||
else: address
|
||||
if groupedAccountsTokensBalances.hasKey(token_by_symbol_key):
|
||||
groupedAccountsTokensBalances[token_by_symbol_key].balancesPerAccount.add(BalanceItem(account: accountAddress,
|
||||
chainId: chainId,
|
||||
balance: rawBalance))
|
||||
balance: rawBalance,
|
||||
balance1DayAgo: balance1DayAgo))
|
||||
else:
|
||||
groupedAccountsTokensBalances[token_by_symbol_key] = GroupedTokenItem(
|
||||
tokensKey: token_by_symbol_key,
|
||||
symbol: symbol,
|
||||
balancesPerAccount: @[BalanceItem(account: accountAddress, chainId: chainId, balance: rawBalance)]
|
||||
balancesPerAccount: @[BalanceItem(account: accountAddress, chainId: chainId, balance: rawBalance, balance1DayAgo: balance1DayAgo)]
|
||||
)
|
||||
|
||||
# set assetsLoading to false once the tokens are loaded
|
||||
|
|
|
@ -51,7 +51,7 @@ ComboBox {
|
|||
TokenOrderCurrencyBalance, // FIAT value of asset balance (enabledNetworkCurrencyBalance)
|
||||
TokenOrderBalance, // Number of tokens (enabledNetworkBalance)
|
||||
TokenOrderCurrencyPrice, // Value per token in FIAT (currencyPrice)
|
||||
TokenOrder1WChange, // Level of change in asset balance value (in FIAT) comp. to 7 days earlier
|
||||
TokenOrder1DChange, // Level of change in asset balance value (in FIAT) comp. to 1 day earlier
|
||||
TokenOrderAlpha, // Alphabetic by asset name (name)
|
||||
TokenOrderDateAdded, // Date added descending (newest first)
|
||||
TokenOrderGroupName, // Collection or Community name
|
||||
|
|
|
@ -62,7 +62,7 @@ ColumnLayout {
|
|||
return true // TODO handle UI threshold (#12611)
|
||||
}
|
||||
|
||||
function getTotalBalance(balances, decimals) {
|
||||
function getTotalBalance(balances, decimals, key) {
|
||||
let totalBalance = 0
|
||||
let nwFilters = root.networkFilters.split(":")
|
||||
let addrFilters = root.addressFilters.split(":")
|
||||
|
@ -70,7 +70,7 @@ ColumnLayout {
|
|||
let balancePerAddressPerChain = ModelUtils.get(balances, i)
|
||||
if (nwFilters.includes(balancePerAddressPerChain.chainId+"") &&
|
||||
addrFilters.includes(balancePerAddressPerChain.account)) {
|
||||
totalBalance+=SQUtils.AmountsArithmetic.toNumber(balancePerAddressPerChain.balance, decimals)
|
||||
totalBalance+=SQUtils.AmountsArithmetic.toNumber(balancePerAddressPerChain[key], decimals)
|
||||
}
|
||||
}
|
||||
return totalBalance
|
||||
|
@ -81,7 +81,7 @@ ColumnLayout {
|
|||
proxyRoles: [
|
||||
FastExpressionRole {
|
||||
name: "currentBalance"
|
||||
expression: d.getTotalBalance(model.balances, model.decimals, root.addressFilters, root.networkFilters)
|
||||
expression: d.getTotalBalance(model.balances, model.decimals, "balance")
|
||||
expectedRoles: ["balances", "decimals"]
|
||||
},
|
||||
FastExpressionRole {
|
||||
|
@ -105,9 +105,16 @@ ColumnLayout {
|
|||
expectedRoles: ["marketDetails"]
|
||||
},
|
||||
FastExpressionRole {
|
||||
name: "changePct24hour"
|
||||
expression: model.marketDetails.changePct24hour
|
||||
expectedRoles: ["marketDetails"]
|
||||
name: "change1DayFiat"
|
||||
expression: {
|
||||
if (!model.isCommunityAsset && !!model.marketDetails) {
|
||||
const balance1DayAgo = d.getTotalBalance(model.balances, model.decimals, "balance1DayAgo")
|
||||
const change = (model.currentBalance * model.marketDetails.currencyPrice.amount) - (balance1DayAgo * (model.marketDetails.currencyPrice.amount - model.marketDetails.change24hour))
|
||||
return change
|
||||
}
|
||||
return 0
|
||||
}
|
||||
expectedRoles: ["marketDetails", "balances", "decimals", "currentBalance", "isCommunityAsset"]
|
||||
},
|
||||
FastExpressionRole {
|
||||
name: "isCommunityAsset"
|
||||
|
@ -192,7 +199,7 @@ ColumnLayout {
|
|||
{ value: SortOrderComboBox.TokenOrderCurrencyBalance, text: qsTr("Asset balance value"), icon: "token-sale", sortRoleName: "currentCurrencyBalance" }, // custom SFPM ExpressionRole on "enabledNetworkCurrencyBalance" amount
|
||||
{ value: SortOrderComboBox.TokenOrderBalance, text: qsTr("Asset balance"), icon: "channel", sortRoleName: "currentBalance" }, // custom SFPM ExpressionRole on "enabledNetworkBalance" amount
|
||||
{ value: SortOrderComboBox.TokenOrderCurrencyPrice, text: qsTr("Asset value"), icon: "token", sortRoleName: "tokenPrice" }, // custom SFPM ExpressionRole on "currencyPrice" amount
|
||||
{ value: SortOrderComboBox.TokenOrder1WChange, text: qsTr("1d change: balance value"), icon: "history", sortRoleName: "changePct24hour" }, // FIXME changePct1week role missing in backend!!!
|
||||
{ value: SortOrderComboBox.TokenOrder1DChange, text: qsTr("1d change: balance value"), icon: "history", sortRoleName: "change1DayFiat" }, // custom SFPM ExpressionRole
|
||||
{ value: SortOrderComboBox.TokenOrderAlpha, text: qsTr("Asset name"), icon: "bold", sortRoleName: "name" },
|
||||
{ value: SortOrderComboBox.TokenOrderCustom, text: qsTr("Custom order"), icon: "exchange", sortRoleName: "" },
|
||||
{ value: SortOrderComboBox.TokenOrderNone, text: "---", icon: "", sortRoleName: "" }, // separator
|
||||
|
|
Loading…
Reference in New Issue