mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-10 22:36:24 +00:00
feat(@desktop/wallet): react to collectibles update only for selected addresses and chains
This commit is contained in:
parent
a36f0d8ce8
commit
5bd2d8dcfd
@ -29,7 +29,7 @@ proc fromEvent*(T: type WalletSignal, jsonSignal: JsonNode): WalletSignal =
|
|||||||
for account in event["accounts"]:
|
for account in event["accounts"]:
|
||||||
result.accounts.add(account.getStr)
|
result.accounts.add(account.getStr)
|
||||||
result.at = event{"at"}.getInt
|
result.at = event{"at"}.getInt
|
||||||
result.chainID = event{"chainID"}.getInt
|
result.chainID = event{"chainId"}.getInt
|
||||||
result.message = event{"message"}.getStr
|
result.message = event{"message"}.getStr
|
||||||
const requestIdName = "requestId"
|
const requestIdName = "requestId"
|
||||||
if event.contains(requestIdName):
|
if event.contains(requestIdName):
|
||||||
|
@ -109,6 +109,11 @@ QtObject:
|
|||||||
proc globalFilterChanged*(self: Controller, addresses: seq[string], chainIds: seq[int]) =
|
proc globalFilterChanged*(self: Controller, addresses: seq[string], chainIds: seq[int]) =
|
||||||
if chainIds == self.chainIds and addresses == self.addresses:
|
if chainIds == self.chainIds and addresses == self.addresses:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.chainIds = chainIds
|
self.chainIds = chainIds
|
||||||
self.addresses = addresses
|
self.addresses = addresses
|
||||||
|
|
||||||
|
self.eventsHandler.updateSubscribedAddresses(self.addresses)
|
||||||
|
self.eventsHandler.updateSubscribedChainIDs(self.chainIds)
|
||||||
|
|
||||||
self.resetModel()
|
self.resetModel()
|
@ -1,5 +1,5 @@
|
|||||||
import NimQml, logging, std/json, sequtils, strutils
|
import NimQml, logging, std/json, sequtils, strutils
|
||||||
import tables, stint
|
import tables, stint, sets
|
||||||
|
|
||||||
import app/core/eventemitter
|
import app/core/eventemitter
|
||||||
import app/core/signals/types
|
import app/core/signals/types
|
||||||
@ -16,6 +16,10 @@ QtObject:
|
|||||||
events: EventEmitter
|
events: EventEmitter
|
||||||
eventHandlers: Table[string, EventCallbackProc]
|
eventHandlers: Table[string, EventCallbackProc]
|
||||||
walletEventHandlers: Table[string, WalletEventCallbackProc]
|
walletEventHandlers: Table[string, WalletEventCallbackProc]
|
||||||
|
|
||||||
|
subscribedAddresses: HashSet[string]
|
||||||
|
subscribedChainIDs: HashSet[int]
|
||||||
|
|
||||||
collectiblesOwnershipUpdateStartedFn: proc()
|
collectiblesOwnershipUpdateStartedFn: proc()
|
||||||
collectiblesOwnershipUpdateFinishedFn: proc()
|
collectiblesOwnershipUpdateFinishedFn: proc()
|
||||||
|
|
||||||
@ -52,16 +56,22 @@ QtObject:
|
|||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc shouldIgnoreEvent(self: EventsHandler, data: WalletSignal): bool =
|
||||||
|
if data.chainID in self.subscribedChainIDs:
|
||||||
|
for address in data.accounts:
|
||||||
|
if address in self.subscribedAddresses:
|
||||||
|
return false
|
||||||
|
return true
|
||||||
|
|
||||||
proc setupWalletEventHandlers(self: EventsHandler) =
|
proc setupWalletEventHandlers(self: EventsHandler) =
|
||||||
self.walletEventHandlers[backend_collectibles.eventCollectiblesOwnershipUpdateStarted] = proc (data: WalletSignal) =
|
self.walletEventHandlers[backend_collectibles.eventCollectiblesOwnershipUpdateStarted] = proc (data: WalletSignal) =
|
||||||
if self.collectiblesOwnershipUpdateStartedFn == nil:
|
if self.collectiblesOwnershipUpdateStartedFn == nil or self.shouldIgnoreEvent(data):
|
||||||
return
|
return
|
||||||
self.collectiblesOwnershipUpdateStartedFn()
|
self.collectiblesOwnershipUpdateStartedFn()
|
||||||
|
|
||||||
self.walletEventHandlers[backend_collectibles.eventCollectiblesOwnershipUpdateFinished] = proc (data: WalletSignal) =
|
self.walletEventHandlers[backend_collectibles.eventCollectiblesOwnershipUpdateFinished] = proc (data: WalletSignal) =
|
||||||
if self.collectiblesOwnershipUpdateFinishedFn == nil:
|
if self.collectiblesOwnershipUpdateFinishedFn == nil or self.shouldIgnoreEvent(data):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.collectiblesOwnershipUpdateFinishedFn()
|
self.collectiblesOwnershipUpdateFinishedFn()
|
||||||
|
|
||||||
proc newEventsHandler*(events: EventEmitter): EventsHandler =
|
proc newEventsHandler*(events: EventEmitter): EventsHandler =
|
||||||
@ -79,3 +89,12 @@ QtObject:
|
|||||||
eventsHandler.handleApiEvents(e)
|
eventsHandler.handleApiEvents(e)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
proc updateSubscribedAddresses*(self: EventsHandler, addresses: seq[string]) =
|
||||||
|
self.subscribedAddresses.clear()
|
||||||
|
for address in addresses:
|
||||||
|
self.subscribedAddresses.incl(address)
|
||||||
|
|
||||||
|
proc updateSubscribedChainIDs*(self: EventsHandler, chainIDs: seq[int]) =
|
||||||
|
self.subscribedChainIDs.clear()
|
||||||
|
for chainID in chainIDs:
|
||||||
|
self.subscribedChainIDs.incl(chainID)
|
Loading…
x
Reference in New Issue
Block a user