feat(wallet) api to retrieve last activity timestamp

Bumps status-go to include the new API endpoint.

Integrate the new API endpoint with the ActivityFilterPanel.

Closes #11169
This commit is contained in:
Stefan 2023-06-21 10:02:14 +02:00 committed by Stefan Dunca
parent bea4c8c2ad
commit eb0406b556
6 changed files with 48 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import NimQml, logging, std/json, sequtils, sugar, options, strutils import NimQml, logging, std/json, sequtils, sugar, options, strutils, times
import tables, stint, sets import tables, stint, sets
import model import model
@ -52,6 +52,8 @@ QtObject:
# call updateAssetsIdentities after updating chainIds # call updateAssetsIdentities after updating chainIds
chainIds: seq[int] chainIds: seq[int]
startTimestamp: int
proc setup(self: Controller) = proc setup(self: Controller) =
self.QObject.setup self.QObject.setup
@ -224,6 +226,22 @@ QtObject:
self.currentActivityFilter.types = types self.currentActivityFilter.types = types
proc startTimestampChanged*(self: Controller) {.signal.}
proc getOldestActivityTimestamp(self: Controller): int {.slot.} =
let resJson = backend_activity.getOldestActivityTimestamp(self.addresses)
if resJson.error != nil or resJson.result.kind != JInt:
error "error fetching oldest activity timestamp: ", resJson.error, ", ", resJson.result.kind
return
return resJson.result.getInt()
# Call this method on every data update (ideally only if updates are before the last timestamp retrieved)
# This depends on self.addresses being set, call on every address change
proc updateStartTimestamp*(self: Controller) {.slot.} =
self.startTimestamp = self.getOldestActivityTimestamp()
self.startTimestampChanged()
proc newController*(transactionsModule: transactions_module.AccessInterface, proc newController*(transactionsModule: transactions_module.AccessInterface,
currencyService: currency_service.Service, currencyService: currency_service.Service,
tokenService: token_service.Service, tokenService: token_service.Service,
@ -322,6 +340,7 @@ QtObject:
proc setFilterAddresses*(self: Controller, addresses: seq[string]) = proc setFilterAddresses*(self: Controller, addresses: seq[string]) =
self.addresses = addresses self.addresses = addresses
self.updateStartTimestamp()
proc setFilterToAddresses*(self: Controller, addresses: seq[string]) = proc setFilterToAddresses*(self: Controller, addresses: seq[string]) =
self.currentActivityFilter.counterpartyAddresses = addresses self.currentActivityFilter.counterpartyAddresses = addresses
@ -362,3 +381,16 @@ QtObject:
let result = json.to(response.result, backend_activity.GetAllRecipientsResponse) let result = json.to(response.result, backend_activity.GetAllRecipientsResponse)
self.recipientsModel.addAddresses(result.addresses, self.recipientsModel.getCount(), result.hasMore) self.recipientsModel.addAddresses(result.addresses, self.recipientsModel.getCount(), result.hasMore)
proc getStartTimestamp*(self: Controller): int {.slot.} =
return if self.startTimestamp > 0:
self.startTimestamp
else:
int(times.parse("2000-01-01", "yyyy-MM-dd").toTime().toUnix())
QtProperty[int] startTimestamp:
read = getStartTimestamp
notify = startTimestampChanged
proc updateFilterBase(self: Controller) {.slot.} =
self.updateStartTimestamp()

View File

@ -314,3 +314,6 @@ type GetAllRecipientsResponse* = object
rpc(getAllRecipients, "wallet"): rpc(getAllRecipients, "wallet"):
offset: int offset: int
limit: int limit: int
rpc(getOldestActivityTimestamp, "wallet"):
addresses: seq[string]

View File

@ -18,6 +18,10 @@ Flow {
spacing: 8 spacing: 8
Component.onCompleted: {
activityFilterStore.updateFilterBase()
}
StatusRoundButton { StatusRoundButton {
id: filterButton id: filterButton
width: 32 width: 32

View File

@ -18,8 +18,7 @@ QtObject {
// Time filters // Time filters
property int selectedTime: Constants.TransactionTimePeriod.All property int selectedTime: Constants.TransactionTimePeriod.All
// To-do get this from the backend once oldest Tx timestamp is available property double fromTimestamp: activityController.startTimestamp * 1000
property double fromTimestamp
property double toTimestamp: new Date().valueOf() property double toTimestamp: new Date().valueOf()
function setSelectedTimestamp(selcTime) { function setSelectedTimestamp(selcTime) {
selectedTime = selcTime selectedTime = selcTime
@ -173,4 +172,8 @@ QtObject {
} }
return tempFilters return tempFilters
} }
function updateFilterBase() {
activityController.updateFilterBase()
}
} }

View File

@ -241,7 +241,6 @@ QtObject {
property bool marketHistoryIsLoading: Global.appIsReady? walletSectionAllTokens.marketHistoryIsLoading : false property bool marketHistoryIsLoading: Global.appIsReady? walletSectionAllTokens.marketHistoryIsLoading : false
// TODO: range until we optimize to cache the data and abuse the requests
function fetchHistoricalBalanceForTokenAsJson(address, tokenSymbol, currencySymbol, timeIntervalEnum) { function fetchHistoricalBalanceForTokenAsJson(address, tokenSymbol, currencySymbol, timeIntervalEnum) {
if (Global.appIsReady) if (Global.appIsReady)
walletSectionAllTokens.fetchHistoricalBalanceForTokenAsJson(address, tokenSymbol, currencySymbol, timeIntervalEnum) walletSectionAllTokens.fetchHistoricalBalanceForTokenAsJson(address, tokenSymbol, currencySymbol, timeIntervalEnum)

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit bf54a577805671df7f07c69b414184764b79e091 Subproject commit ea7a3890755b25856ec8f8da7bdda0189a3fcc68