diff --git a/src/app/modules/main/wallet_section/activity/controller.nim b/src/app/modules/main/wallet_section/activity/controller.nim index 01edb9e68c..7540cb9d48 100644 --- a/src/app/modules/main/wallet_section/activity/controller.nim +++ b/src/app/modules/main/wallet_section/activity/controller.nim @@ -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) @@ -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) diff --git a/src/app/modules/main/wallet_section/activity/events_handler.nim b/src/app/modules/main/wallet_section/activity/events_handler.nim index b227f939cc..1696c2de13 100644 --- a/src/app/modules/main/wallet_section/activity/events_handler.nim +++ b/src/app/modules/main/wallet_section/activity/events_handler.nim @@ -48,7 +48,12 @@ 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 + + # Ignore message requested by other sessions + if self.sessionId.isSome() and data.requestId.get() != self.sessionId.get(): return if self.walletEventHandlers.hasKey(data.eventType): @@ -74,7 +79,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) diff --git a/src/app/modules/main/wallet_section/activity/status.nim b/src/app/modules/main/wallet_section/activity/status.nim index 32045cb6f3..34b392fa0c 100644 --- a/src/app/modules/main/wallet_section/activity/status.nim +++ b/src/app/modules/main/wallet_section/activity/status.nim @@ -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 @@ -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.} @@ -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.} @@ -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.} @@ -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