Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet): counterparty loading forever in activity history #14092

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/modules/main/wallet_section/activity/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ QtObject:

proc updateRecipientsModel*(self: Controller) {.slot.} =
self.status.setLoadingRecipients(true)
# Recipients don't change with filers so we can use the same request id
let res = backend_activity.getRecipientsAsync(self.sessionId(), self.chainIds, self.addresses, 0, FETCH_RECIPIENTS_BATCH_COUNT_DEFAULT)
if res.error != nil or res.result.kind != JBool:
self.status.setLoadingRecipients(false)
Expand All @@ -483,6 +484,7 @@ QtObject:

proc loadMoreRecipients(self: Controller) {.slot.} =
self.status.setLoadingRecipients(true)
# Recipients don't change with filers so we can use the same request id
let res = backend_activity.getRecipientsAsync(self.sessionId(), self.chainIds, self.addresses, self.recipientsModel.getCount(), FETCH_RECIPIENTS_BATCH_COUNT_DEFAULT)
if res.error != nil:
self.status.setLoadingRecipients(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import app/core/signals/types
import backend/activity as backend_activity

type EventCallbackProc = proc (eventObject: JsonNode)
type WalletEventCallbackProc = proc (data: WalletSignal)

# EventsHandler responsible for catching activity related backend events and reporting them
# Events are processed on the main thread and don't overlap with UI calls; see src/app/core/signals/signals_manager.nim
QtObject:
type
EventsHandler* = ref object of QObject
events: EventEmitter
eventHandlers: Table[string, EventCallbackProc]
walletEventHandlers: Table[string, WalletEventCallbackProc]

sessionId: Option[int32]

Expand Down Expand Up @@ -48,13 +47,15 @@ QtObject:
proc handleApiEvents(self: EventsHandler, e: Args) =
var data = WalletSignal(e)

if not data.requestId.isSome() or not self.sessionId.isSome() or data.requestId.get() != self.sessionId.get():
# All activiy messages have a requestId matching the session ID or static request ID
if not data.requestId.isSome():
return

if self.walletEventHandlers.hasKey(data.eventType):
let callback = self.walletEventHandlers[data.eventType]
callback(data)
elif self.eventHandlers.hasKey(data.eventType):
# Ignore message requested by other sessions
if self.sessionId.isSome() and data.requestId.get() != self.sessionId.get():
return

if self.eventHandlers.hasKey(data.eventType):
let callback = self.eventHandlers[data.eventType]
let responseJson = parseJson(data.message)
callback(responseJson)
Expand All @@ -74,7 +75,7 @@ QtObject:
)

proc getSessionId*(self: EventsHandler): int32 =
self.sessionId.get(-1)
return self.sessionId.get(-1)

proc setSessionId*(self: EventsHandler, sessionId: int32) =
self.sessionId = some(sessionId)
Expand Down
21 changes: 12 additions & 9 deletions src/app/modules/main/wallet_section/activity/status.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ QtObject:
loadingData: bool
errorCode: backend_activity.ErrorCode

loadingRecipients: Atomic[int]
loadingCollectibles: Atomic[int]
loadingStartTimestamp: Atomic[int]
# No need for synchronization primitives, all operations are serialized on the main thread; see events_handler.nim
loadingRecipients: bool
loadingStartTimestamp: bool

startTimestamp: int

Expand All @@ -30,7 +31,7 @@ QtObject:

proc filterChainsChanged*(self: Status) {.signal.}

proc emitFilterChainsChanged*(self: Status) =
proc emitFilterChainsChanged*(self: Status) =
self.filterChainsChanged()

proc loadingDataChanged*(self: Status) {.signal.}
Expand All @@ -42,8 +43,9 @@ QtObject:
proc loadingRecipientsChanged*(self: Status) {.signal.}

proc setLoadingRecipients*(self: Status, loadingData: bool) =
discard fetchAdd(self.loadingRecipients, if loadingData: 1 else: -1)
self.loadingRecipientsChanged()
if self.loadingRecipients != loadingData:
self.loadingRecipients = loadingData
self.loadingRecipientsChanged()

proc loadingCollectiblesChanged*(self: Status) {.signal.}

Expand All @@ -54,8 +56,9 @@ QtObject:
proc loadingStartTimestampChanged*(self: Status) {.signal.}

proc setLoadingStartTimestamp*(self: Status, loadingData: bool) =
discard fetchAdd(self.loadingStartTimestamp, if loadingData: 1 else: -1)
self.loadingStartTimestampChanged()
if self.loadingStartTimestamp != loadingData:
self.loadingStartTimestamp = loadingData
self.loadingStartTimestampChanged()

proc errorCodeChanged*(self: Status) {.signal.}

Expand Down Expand Up @@ -86,14 +89,14 @@ QtObject:
notify = errorCodeChanged

proc getLoadingRecipients*(self: Status): bool {.slot.} =
return load(self.loadingRecipients) > 0
return self.loadingRecipients

QtProperty[bool] loadingRecipients:
read = getLoadingRecipients
notify = loadingRecipientsChanged

proc getLoadingStartTimestamp*(self: Status): bool {.slot.} =
return load(self.loadingStartTimestamp) > 0
return self.loadingStartTimestamp

QtProperty[bool] loadingStartTimestamp:
read = getLoadingStartTimestamp
Expand Down