feat(wallet): toggling `include/exclude from total balance` menu action

filters out assets/collectibles/activities entries.
Fixed direction of transfers for `All accounts` selection on activity
tab.

Closes #14162 #14216
This commit is contained in:
Ivan Belyakov 2024-04-10 11:44:15 +02:00 committed by IvanBelyakoff
parent 6ba0cdfafa
commit 3843b53cc0
15 changed files with 113 additions and 33 deletions

View File

@ -30,8 +30,12 @@ proc newController*(
proc delete*(self: Controller) = proc delete*(self: Controller) =
discard discard
proc buildAllTokens*(self: Controller, addresses: seq[string]) =
self.walletAccountService.buildAllTokens(addresses, store = true)
proc init*(self: Controller) = proc init*(self: Controller) =
self.walletAccountService.buildAllTokens(self.walletAccountService.getWalletAddresses(), store = true) let walletAddresses = self.walletAccountService.getWalletAddresses()
self.buildAllTokens(walletAddresses)
discard discard
proc getChainIds*(self: Controller): seq[int] = proc getChainIds*(self: Controller): seq[int] =

View File

@ -70,3 +70,6 @@ method getGroupedAccountAssetsDataSource*(self: Module): GroupedAccountAssetsDat
return ( return (
getGroupedAccountsAssetsList: proc(): var seq[GroupedTokenItem] = self.controller.getGroupedAccountsAssetsList() getGroupedAccountsAssetsList: proc(): var seq[GroupedTokenItem] = self.controller.getGroupedAccountsAssetsList()
) )
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
self.controller.buildAllTokens(addresses)

View File

@ -23,13 +23,16 @@ proc `$`*(self: Filter): string =
chainIds: {self.chainIds}, chainIds: {self.chainIds},
)""" )"""
proc setAddresses*(self: Filter, addresses: seq[string]) =
self.addresses = addresses
proc setAddress*(self: Filter, address: string) = proc setAddress*(self: Filter, address: string) =
self.addresses = @[address] self.setAddresses(@[address])
proc removeAddress*(self: Filter, address: string) = proc removeAddress*(self: Filter, address: string) =
if len(self.addresses) == 1 and self.addresses[0] == address: if len(self.addresses) == 1 and self.addresses[0] == address:
let accounts = self.controller.getWalletAccounts() let accounts = self.controller.getWalletAccounts()
self.addresses = @[accounts[0].address] self.setAddresses(@[accounts[0].address])
return return
let ind = self.addresses.find(address) let ind = self.addresses.find(address)

View File

@ -18,6 +18,9 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method setFilterAddress*(self: AccessInterface, address: string) {.base.} = method setFilterAddress*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method setFilterAllAddresses*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method updateCurrency*(self: AccessInterface, currency: string) {.base.} = method updateCurrency*(self: AccessInterface, currency: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -192,20 +192,32 @@ method updateCurrency*(self: Module, currency: string) =
method getCurrentCurrency*(self: Module): string = method getCurrentCurrency*(self: Module): string =
self.controller.getCurrency() self.controller.getCurrency()
method setTotalCurrencyBalance*(self: Module) = proc getWalletAddressesNotHidden(self: Module): seq[string] =
let walletAccounts = self.controller.getWalletAccounts() let walletAccounts = self.controller.getWalletAccounts()
var addresses = walletAccounts.filter(a => not a.hideFromTotalBalance).map(a => a.address) return walletAccounts.filter(a => not a.hideFromTotalBalance).map(a => a.address)
method setTotalCurrencyBalance*(self: Module) =
let addresses = self.getWalletAddressesNotHidden()
self.view.setTotalCurrencyBalance(self.controller.getTotalCurrencyBalance(addresses, self.filter.chainIds)) self.view.setTotalCurrencyBalance(self.controller.getTotalCurrencyBalance(addresses, self.filter.chainIds))
proc notifyFilterChanged(self: Module) = proc notifyModulesOnFilterChanged(self: Module) =
self.overviewModule.filterChanged(self.filter.addresses, self.filter.chainIds) self.overviewModule.filterChanged(self.filter.addresses, self.filter.chainIds)
self.accountsModule.filterChanged(self.filter.addresses, self.filter.chainIds) self.accountsModule.filterChanged(self.filter.addresses, self.filter.chainIds)
self.sendModule.filterChanged(self.filter.addresses, self.filter.chainIds) self.sendModule.filterChanged(self.filter.addresses, self.filter.chainIds)
self.activityController.globalFilterChanged(self.filter.addresses, self.filter.chainIds, self.filter.allChainsEnabled) self.activityController.globalFilterChanged(self.filter.addresses, self.filter.chainIds, self.filter.allChainsEnabled)
self.allTokensModule.filterChanged(self.filter.addresses) self.allTokensModule.filterChanged(self.filter.addresses)
self.view.setAddressFilters(self.filter.addresses.join(":")) self.allCollectiblesModule.refreshWalletAccounts()
if self.filter.addresses.len > 0: self.assetsModule.filterChanged(self.filter.addresses, self.filter.chainIds)
self.view.filterChanged(self.filter.addresses[0])
proc updateViewWithAddressFilterChanged(self: Module) =
if self.overviewModule.getIsAllAccounts():
self.view.filterChanged("")
else:
self.view.filterChanged(self.view.getAddressFilters())
proc notifyFilterChanged(self: Module) =
self.updateViewWithAddressFilterChanged()
self.notifyModulesOnFilterChanged()
method getCurrencyAmount*(self: Module, amount: float64, symbol: string): CurrencyAmount = method getCurrencyAmount*(self: Module, amount: float64, symbol: string): CurrencyAmount =
return self.controller.getCurrencyAmount(amount, symbol) return self.controller.getCurrencyAmount(amount, symbol)
@ -218,7 +230,17 @@ proc setKeypairOperabilityForObservedAccount(self: Module, address: string) =
self.view.setKeypairOperabilityForObservedAccount(keypair.getOperability()) self.view.setKeypairOperabilityForObservedAccount(keypair.getOperability())
method setFilterAddress*(self: Module, address: string) = method setFilterAddress*(self: Module, address: string) =
self.setKeypairOperabilityForObservedAccount(address)
self.filter.setAddress(address) self.filter.setAddress(address)
self.overviewModule.setIsAllAccounts(false)
self.view.setAddressFilters(address)
self.notifyFilterChanged()
method setFilterAllAddresses*(self: Module) =
self.view.setKeypairOperabilityForObservedAccount("")
self.filter.setAddresses(self.getWalletAddressesNotHidden())
self.view.setAddressFilters(self.filter.addresses.join(":"))
self.overviewModule.setIsAllAccounts(true)
self.notifyFilterChanged() self.notifyFilterChanged()
method load*(self: Module) = method load*(self: Module) =
@ -249,7 +271,7 @@ method load*(self: Module) =
self.notifyFilterChanged() self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args): self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args):
self.setTotalCurrencyBalance() self.setTotalCurrencyBalance()
self.notifyFilterChanged() # self.notifyFilterChanged()
self.events.on(SIGNAL_TOKENS_PRICES_UPDATED) do(e:Args): self.events.on(SIGNAL_TOKENS_PRICES_UPDATED) do(e:Args):
self.setTotalCurrencyBalance() self.setTotalCurrencyBalance()
self.notifyFilterChanged() self.notifyFilterChanged()
@ -285,6 +307,9 @@ method load*(self: Module) =
let data = LocalPairingStatus(e) let data = LocalPairingStatus(e)
self.onLocalPairingStatusUpdate(data) self.onLocalPairingStatusUpdate(data)
self.events.on(SIGNAL_WALLET_ACCOUNT_HIDDEN_UPDATED) do(e: Args): self.events.on(SIGNAL_WALLET_ACCOUNT_HIDDEN_UPDATED) do(e: Args):
if self.overviewModule.getIsAllAccounts():
self.filter.setAddresses(self.getWalletAddressesNotHidden())
self.view.setAddressFilters(self.filter.addresses.join(":"))
self.notifyFilterChanged() self.notifyFilterChanged()
self.setTotalCurrencyBalance() self.setTotalCurrencyBalance()
@ -339,6 +364,7 @@ proc checkIfModuleDidLoad(self: Module) =
let mnemonicBackedUp = self.controller.isMnemonicBackedUp() let mnemonicBackedUp = self.controller.isMnemonicBackedUp()
self.view.setData(signingPhrase, mnemonicBackedUp) self.view.setData(signingPhrase, mnemonicBackedUp)
self.setTotalCurrencyBalance() self.setTotalCurrencyBalance()
self.filter.setAddresses(self.getWalletAddressesNotHidden())
self.filter.load() self.filter.load()
self.notifyFilterChanged() self.notifyFilterChanged()
self.moduleLoaded = true self.moduleLoaded = true

View File

@ -27,6 +27,9 @@ proc init*(self: Controller) =
proc getWalletAccountsByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletAccountDto] = proc getWalletAccountsByAddresses*(self: Controller, addresses: seq[string]): seq[wallet_account_service.WalletAccountDto] =
return self.walletAccountService.getAccountsByAddresses(addresses) return self.walletAccountService.getAccountsByAddresses(addresses)
proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] =
return self.walletAccountService.getWalletAccounts()
proc getTotalCurrencyBalance*(self: Controller, addresses: seq[string], chainIds: seq[int]): float64 = proc getTotalCurrencyBalance*(self: Controller, addresses: seq[string], chainIds: seq[int]): float64 =
return self.walletAccountService.getTotalCurrencyBalance(addresses, chainIds) return self.walletAccountService.getTotalCurrencyBalance(addresses, chainIds)

View File

@ -19,3 +19,9 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
method filterChanged*(self: AccessInterface, addresses: seq[string], chainIds: seq[int]) {.base.} = method filterChanged*(self: AccessInterface, addresses: seq[string], chainIds: seq[int]) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method setIsAllAccounts*(self: AccessInterface, value: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method getIsAllAccounts*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -20,6 +20,7 @@ type
view: View view: View
controller: Controller controller: Controller
moduleLoaded: bool moduleLoaded: bool
isAllAccounts: bool
proc newModule*( proc newModule*(
delegate: delegate_interface.AccessInterface, delegate: delegate_interface.AccessInterface,
@ -33,6 +34,7 @@ proc newModule*(
result.view = newView(result) result.view = newView(result)
result.controller = newController(result, walletAccountService, currencyService) result.controller = newController(result, walletAccountService, currencyService)
result.moduleLoaded = false result.moduleLoaded = false
result.isAllAccounts = false
method delete*(self: Module) = method delete*(self: Module) =
self.view.delete self.view.delete
@ -66,20 +68,40 @@ method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int])
let walletAccounts = self.controller.getWalletAccountsByAddresses(addresses) let walletAccounts = self.controller.getWalletAccountsByAddresses(addresses)
let walletAccount = walletAccounts[0] let walletAccount = walletAccounts[0]
let loading = walletAccounts[0].assetsLoading or self.controller.getTokensMarketValuesLoading() let loading = walletAccounts[0].assetsLoading or self.controller.getTokensMarketValuesLoading()
let isWatchOnlyAccount = walletAccount.walletType == "watch" if self.isAllAccounts:
let item = initItem( let item = initItem(
walletAccount.name, "",
walletAccount.mixedCaseAddress, "",
walletAccount.ens, "",
loading, loading,
walletAccount.colorId, "",
walletAccount.emoji, "",
isWatchOnlyAccount=isWatchOnlyAccount, isWatchOnlyAccount=false,
canSend=not isWatchOnlyAccount and (walletAccount.operable==AccountFullyOperable or walletAccount.operable==AccountPartiallyOperable) isAllAccounts=true,
) self.getWalletAccoutColors(walletAccounts)
self.view.setData(item) )
self.view.setData(item)
else:
let isWatchOnlyAccount = walletAccount.walletType == "watch"
let item = initItem(
walletAccount.name,
walletAccount.mixedCaseAddress,
walletAccount.ens,
loading,
walletAccount.colorId,
walletAccount.emoji,
isWatchOnlyAccount=isWatchOnlyAccount,
canSend=not isWatchOnlyAccount and (walletAccount.operable==AccountFullyOperable or walletAccount.operable==AccountPartiallyOperable)
)
self.view.setData(item)
if loading: if loading:
self.view.setCurrencyBalance(newCurrencyAmount()) self.view.setCurrencyBalance(newCurrencyAmount())
else: else:
self.setBalance(addresses, chainIds) self.setBalance(addresses, chainIds)
method setIsAllAccounts(self: Module, value: bool) =
self.isAllAccounts = value
method getIsAllAccounts(self: Module): bool =
return self.isAllAccounts

View File

@ -94,7 +94,7 @@ QtObject:
proc setAddressFilters*(self: View, address: string) = proc setAddressFilters*(self: View, address: string) =
self.addressFilters = address self.addressFilters = address
self.addressFiltersChanged() self.addressFiltersChanged()
proc getAddressFilters(self: View): string {.slot.} = proc getAddressFilters*(self: View): string {.slot.} =
return self.addressFilters return self.addressFilters
QtProperty[string] addressFilters: QtProperty[string] addressFilters:
read = getAddressFilters read = getAddressFilters
@ -103,6 +103,9 @@ QtObject:
proc setFilterAddress(self: View, address: string) {.slot.} = proc setFilterAddress(self: View, address: string) {.slot.} =
self.delegate.setFilterAddress(address) self.delegate.setFilterAddress(address)
proc setFilterAllAddresses*(self: View) {.slot.} =
self.delegate.setFilterAllAddresses()
proc setTotalCurrencyBalance*(self: View, totalCurrencyBalance: CurrencyAmount) = proc setTotalCurrencyBalance*(self: View, totalCurrencyBalance: CurrencyAmount) =
self.totalCurrencyBalance = totalCurrencyBalance self.totalCurrencyBalance = totalCurrencyBalance
self.totalCurrencyBalanceChanged() self.totalCurrencyBalanceChanged()

View File

@ -101,7 +101,7 @@ proc getWalletAccounts*(self: Service, excludeWatchOnly: bool = false): seq[Wall
result.sort(walletAccountsCmp) result.sort(walletAccountsCmp)
proc getWalletAddresses*(self: Service): seq[string] = proc getWalletAddresses*(self: Service): seq[string] =
return self.getWalletAccounts().map(a => a.address) return self.getWalletAccounts().filter(a => not a.hideFromTotalBalance).map(a => a.address)
proc updateAssetsLoadingState(self: Service, address: string, loading: bool) = proc updateAssetsLoadingState(self: Service, address: string, loading: bool) =
var acc = self.getAccountByAddress(address) var acc = self.getAccountByAddress(address)

View File

@ -96,7 +96,6 @@ proc buildAllTokens*(self: Service, accounts: seq[string], store: bool) =
self.threadpool.start(arg) self.threadpool.start(arg)
proc getTotalCurrencyBalance*(self: Service, addresses: seq[string], chainIds: seq[int]): float64 = proc getTotalCurrencyBalance*(self: Service, addresses: seq[string], chainIds: seq[int]): float64 =
echo "+++++++ getTotalCurrencyBalance, addresses ", addresses, " chainIds: ", chainIds
var totalBalance: float64 = 0.0 var totalBalance: float64 = 0.0
for token in self.groupedAccountsTokensList: for token in self.groupedAccountsTokensList:
let price = self.tokenService.getPriceBySymbol(token.symbol) let price = self.tokenService.getPriceBySymbol(token.symbol)

View File

@ -70,9 +70,7 @@ Item {
d.displayAllAddresses() d.displayAllAddresses()
if (rightPanelStackView.currentItem && !!rightPanelStackView.currentItem.resetView) { d.resetRightPanelStackView()
rightPanelStackView.currentItem.resetView()
}
if(!hideSignPhraseModal && !RootStore.hideSignPhraseModal){ if(!hideSignPhraseModal && !RootStore.hideSignPhraseModal){
signPhrasePopup.open(); signPhrasePopup.open();
@ -139,11 +137,13 @@ Item {
function displayAllAddresses() { function displayAllAddresses() {
RootStore.showSavedAddresses = false RootStore.showSavedAddresses = false
RootStore.selectedAddress = "" RootStore.selectedAddress = ""
RootStore.setFilterAllAddresses()
} }
function displayAddress(address) { function displayAddress(address) {
RootStore.showSavedAddresses = false RootStore.showSavedAddresses = false
RootStore.selectedAddress = address RootStore.selectedAddress = address
d.resetRightPanelStackView() // Avoids crashing on asset items being destroyed while in signal handler
RootStore.setFilterAddress(address) RootStore.setFilterAddress(address)
} }
@ -151,6 +151,12 @@ Item {
RootStore.showSavedAddresses = true RootStore.showSavedAddresses = true
RootStore.selectedAddress = "" RootStore.selectedAddress = ""
} }
function resetRightPanelStackView() {
if (rightPanelStackView.currentItem && !!rightPanelStackView.currentItem.resetView) {
rightPanelStackView.currentItem.resetView()
}
}
} }
SignPhraseModal { SignPhraseModal {

View File

@ -234,6 +234,10 @@ QtObject {
walletSection.setFilterAddress(address) walletSection.setFilterAddress(address)
} }
function setFilterAllAddresses() {
walletSectionInst.setFilterAllAddresses()
}
function deleteAccount(address) { function deleteAccount(address) {
return walletSectionAccounts.deleteAccount(address) return walletSectionAccounts.deleteAccount(address)
} }

View File

@ -24,10 +24,8 @@ RightTabBaseView {
signal launchShareAddressModal() signal launchShareAddressModal()
function resetView() { function resetView() {
stack.currentIndex = 0 resetStack()
root.currentTabIndex = 0 root.currentTabIndex = 0
if (walletTabBar.currentIndex === 2)
mainViewLoader.item.resetView()
} }
function resetStack() { function resetStack() {
@ -182,7 +180,7 @@ RightTabBaseView {
RootStore.collectiblesStore.getDetailedCollectible(chainId, contractAddress, tokenId) RootStore.collectiblesStore.getDetailedCollectible(chainId, contractAddress, tokenId)
RootStore.setCurrentViewedHolding(uid, tokenType) RootStore.setCurrentViewedHolding(uid, tokenType)
d.detailedCollectibleActivityController.resetFilter() d.detailedCollectibleActivityController.resetFilter()
d.detailedCollectibleActivityController.setFilterAddressesJson(JSON.stringify(RootStore.addressFilters.split(":")), RootStore.showAllAccounts) d.detailedCollectibleActivityController.setFilterAddressesJson(JSON.stringify(RootStore.addressFilters.split(":")))
d.detailedCollectibleActivityController.setFilterChainsJson(JSON.stringify([chainId]), false) d.detailedCollectibleActivityController.setFilterChainsJson(JSON.stringify([chainId]), false)
d.detailedCollectibleActivityController.setFilterCollectibles(JSON.stringify([uid])) d.detailedCollectibleActivityController.setFilterCollectibles(JSON.stringify([uid]))
d.detailedCollectibleActivityController.updateFilter() d.detailedCollectibleActivityController.updateFilter()

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit a549529637b414621074c014d8411e9c189e484d Subproject commit 12deb2336028639ff11b6a3e08043e2961bed5c4