feat(@desktop/wallet): Use separate filter for each wallet account (#11528)

closes #11412
This commit is contained in:
Cuteivist 2023-07-19 16:16:45 +02:00 committed by GitHub
parent ae6630911e
commit db363b3782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 94 additions and 59 deletions

View File

@ -186,6 +186,7 @@ method load*(self: Module) =
let args = AccountArgs(e)
self.setTotalCurrencyBalance()
self.filter.removeAddress(args.account.address)
self.view.emitWalletAccountRemoved(args.account.address)
self.notifyFilterChanged()
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e:Args):
self.filter.updateNetworks()

View File

@ -111,6 +111,10 @@ QtObject:
proc emitDestroyAddAccountPopup*(self: View) =
self.destroyAddAccountPopup()
proc walletAccountRemoved*(self: View, address: string) {.signal.}
proc emitWalletAccountRemoved*(self: View, address: string) =
self.walletAccountRemoved(address)
proc getActivityController(self: View): QVariant {.slot.} =
return newQVariant(self.activityController)
QtProperty[QVariant] activityController:

View File

@ -52,6 +52,7 @@ StatusBaseText {
Loader {
anchors.left: parent.left
anchors.leftMargin: root.leftPadding
anchors.verticalCenter: parent.verticalCenter
active: root.loading
sourceComponent: LoadingComponent {

View File

@ -19,6 +19,37 @@ QtObject {
recentsFilters.length !== 0 ||
savedAddressFilters.length !== 0
readonly property QtObject _d: QtObject {
id: _d
function toggleFilterState(filters, attribute, allFiltersCount) {
let tempFilters = filters
// if all were selected then only select one of them
if(tempFilters.length === 0) {
tempFilters = [attribute]
}
else {
// if last one is being deselected, select all
if(tempFilters.length === 1 && tempFilters[0] === attribute) {
tempFilters = []
}
else {
let index = tempFilters.indexOf(attribute)
if(index === -1) {
if(allFiltersCount === tempFilters.length + 1)
tempFilters = []
else
tempFilters.push(attribute)
}
else {
tempFilters.splice(index, 1)
}
}
}
return tempFilters
}
}
// Time filters
property int selectedTime: Constants.TransactionTimePeriod.All
property double fromTimestamp: activityController.status.startTimestamp * 1000
@ -97,7 +128,7 @@ QtObject {
property var typeFilters: []
function toggleType(type, allFiltersCount) {
// update filters
typeFilters = toggleFilterState(typeFilters, type, allFiltersCount)
typeFilters = _d.toggleFilterState(typeFilters, type, allFiltersCount)
// Set backend values
activityController.setFilterType(JSON.stringify(typeFilters))
activityController.updateFilter()
@ -107,7 +138,7 @@ QtObject {
property var statusFilters: []
function toggleStatus(status, allFiltersCount) {
// update filters
statusFilters = toggleFilterState(statusFilters, status, allFiltersCount)
statusFilters = _d.toggleFilterState(statusFilters, status, allFiltersCount)
// Set backend values
activityController.setFilterStatus(JSON.stringify(statusFilters))
activityController.updateFilter()
@ -118,7 +149,7 @@ QtObject {
property var tokensFilter: []
function toggleToken(symbol) {
// update filters
tokensFilter = toggleFilterState(tokensFilter, symbol, tokensList.count)
tokensFilter = _d.toggleFilterState(tokensFilter, symbol, tokensList.count)
// Set backend values
activityController.setFilterAssets(JSON.stringify(tokensFilter), false)
activityController.updateFilter()
@ -129,10 +160,10 @@ QtObject {
property var collectiblesFilter: []
function toggleCollectibles(id) {
// update filters
collectiblesFilter = toggleFilterState(collectiblesFilter, id, collectiblesList.count)
// To-do go side filtering is pending
// activityController.setFilterCollectibles(JSON.stringify(collectiblesFilter))
// activityController.updateFilter()
collectiblesFilter = _d.toggleFilterState(collectiblesFilter, id, collectiblesList.count)
// TODO go side filtering is pending
// activityController.setFilterCollectibles(JSON.stringify(collectiblesFilter))
// activityController.updateFilter()
}
@ -144,7 +175,7 @@ QtObject {
}
function toggleRecents(address) {
// update filters
recentsFilters = toggleFilterState(recentsFilters, address, recentsList.count)
recentsFilters = _d.toggleFilterState(recentsFilters, address, recentsList.count)
activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters)))
activityController.updateFilter()
}
@ -163,65 +194,39 @@ QtObject {
property var savedAddressFilters: []
function toggleSavedAddress(address) {
// update filters
savedAddressFilters = toggleFilterState(savedAddressFilters, address, savedAddressList.count)
savedAddressFilters = _d.toggleFilterState(savedAddressFilters, address, savedAddressList.count)
// Set backend values
activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters)))
activityController.updateFilter()
}
function toggleFilterState(filters, attribute, allFiltersCount) {
let tempFilters = filters
// if all were selected then only select one of them
if(tempFilters.length === 0) {
tempFilters = [attribute]
}
else {
// if last one is being deselected, select all
if(tempFilters.length === 1 && tempFilters[0] === attribute) {
tempFilters = []
}
else {
let index = tempFilters.indexOf(attribute)
if(index === -1) {
if(allFiltersCount === tempFilters.length + 1)
tempFilters = []
else
tempFilters.push(attribute)
}
else {
tempFilters.splice(index, 1)
}
}
}
return tempFilters
}
function updateFilterBase() {
activityController.updateFilterBase()
}
function applyAllFilters() {
activityController.setFilterTime(fromTimestamp/1000, toTimestamp/1000)
activityController.setFilterType(JSON.stringify(typeFilters))
activityController.setFilterStatus(JSON.stringify(statusFilters))
activityController.setFilterAssets(JSON.stringify(tokensFilter), false)
activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters)))
// TODO call update filter for collectibles
activityController.updateFilter()
}
function resetAllFilters() {
selectedTime = Constants.TransactionTimePeriod.All
fromTimestamp = activityController.status.startTimestamp * 1000
toTimestamp = new Date().valueOf()
activityController.setFilterTime(fromTimestamp/1000, toTimestamp/1000)
typeFilters = []
activityController.setFilterType(JSON.stringify(typeFilters))
statusFilters = []
activityController.setFilterStatus(JSON.stringify(statusFilters))
tokensFilter = []
activityController.setFilterAssets(JSON.stringify(tokensFilter), false)
collectiblesFilter = []
// To-do call update filter for collectibles
recentsFilters = []
savedAddressFilters = []
activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters)))
// TODO reset filter for collectibles
activityController.updateFilter()
applyAllFilters()
}
}

View File

@ -44,8 +44,22 @@ QtObject {
]
}
readonly property var currentActivityFiltersStore: {
const address = root.overview.mixedcaseAddress
if (address in d.activityFiltersStoreDictionary) {
return d.activityFiltersStoreDictionary[address]
}
let store = d.activityFilterStoreComponent.createObject(root)
d.activityFiltersStoreDictionary[address] = store
return store
}
property QtObject _d: QtObject {
id: d
property var activityFiltersStoreDictionary: ({})
readonly property Component activityFilterStoreComponent: ActivityFiltersStore{}
property var chainColors: ({})
function initChainColors(model) {
@ -53,6 +67,19 @@ QtObject {
chainColors[model.rowData(i, "shortName")] = model.rowData(i, "chainColor")
}
}
readonly property Connections walletSectionConnections: Connections {
target: root.walletSectionInst
function onWalletAccountRemoved(address) {
address = address.toLowerCase();
for (var addressKey in d.activityFiltersStoreDictionary){
if (address === addressKey.toLowerCase()){
delete d.activityFiltersStoreDictionary[addressKey]
return
}
}
}
}
}
function colorForChainShortName(chainShortName) {

View File

@ -314,9 +314,7 @@ Rectangle {
id: walletAmountValue
objectName: "walletLeftListAmountValue"
customColor: Style.current.textColor
text: {
LocaleUtils.currencyAmountToLocaleString(RootStore.totalCurrencyBalance)
}
text: LocaleUtils.currencyAmountToLocaleString(RootStore.totalCurrencyBalance)
font.pixelSize: 22
loading: RootStore.assetsLoading
visible: !networkConnectionStore.accountBalanceNotAvailable

View File

@ -434,9 +434,9 @@ Item {
if (d.loadingInputDate) {
return ""
} else if (!!d.decodedInputData) {
return d.decodedInputData.substring(0, 100)
return d.decodedInputData.substring(0, 200)
} else if (root.isTransactionValid) {
return String(root.transaction.input).substring(0, 100)
return String(root.transaction.input).substring(0, 200)
}
return ""
}

View File

@ -32,8 +32,7 @@ ColumnLayout {
onVisibleChanged: {
if (visible && RootStore.isTransactionFilterDirty) {
// TODO(#11412) restore filter for selected wallet account
d.activityFiltersStore.resetAllFilters()
WalletStores.RootStore.currentActivityFiltersStore.applyAllFilters()
}
}
@ -48,7 +47,7 @@ ColumnLayout {
QtObject {
id: d
readonly property bool isInitialLoading: RootStore.loadingHistoryTransactions && transactionListRoot.count === 0
property var activityFiltersStore: WalletStores.ActivityFiltersStore{}
readonly property int loadingSectionWidth: 56
readonly property int topSectionMargin: 20
@ -75,16 +74,16 @@ ColumnLayout {
id: noTxs
Layout.fillWidth: true
Layout.preferredHeight: 42
visible: !d.isInitialLoading && !d.activityFiltersStore.filtersSet && transactionListRoot.count === 0
visible: !d.isInitialLoading && !WalletStores.RootStore.currentActivityFiltersStore.filtersSet && transactionListRoot.count === 0
font.pixelSize: Style.current.primaryTextFontSize
text: qsTr("Activity for this account will appear here")
}
ActivityFilterPanel {
id: filterComponent
visible: d.isInitialLoading || transactionListRoot.count > 0 || d.activityFiltersStore.filtersSet
visible: d.isInitialLoading || transactionListRoot.count > 0 || WalletStores.RootStore.currentActivityFiltersStore.filtersSet
Layout.fillWidth: true
activityFilterStore: d.activityFiltersStore
activityFilterStore: WalletStores.RootStore.currentActivityFiltersStore
store: WalletStores.RootStore
isLoading: d.isInitialLoading
}