feat(@desktop/wallet): adapt to multiclient collectibles api
This commit is contained in:
parent
e9d0727ea1
commit
21eea92d34
|
@ -19,6 +19,8 @@ QtObject:
|
|||
|
||||
eventsHandler: EventsHandler
|
||||
|
||||
requestId: int32
|
||||
|
||||
proc setup(self: Controller) =
|
||||
self.QObject.setup
|
||||
|
||||
|
@ -91,7 +93,7 @@ QtObject:
|
|||
self.detailedEntry = newCollectibleDetailsBasicEntry(id, extradata)
|
||||
self.detailedEntryChanged()
|
||||
|
||||
let response = backend_collectibles.getCollectiblesDetailsAsync(@[id])
|
||||
let response = backend_collectibles.getCollectiblesDetailsAsync(self.requestId, @[id])
|
||||
if response.error != nil:
|
||||
self.setIsDetailedEntryLoading(false)
|
||||
error "error fetching collectible details: ", response.error
|
||||
|
@ -102,16 +104,20 @@ QtObject:
|
|||
self.processGetCollectiblesDetailsResponse(jsonObj)
|
||||
)
|
||||
|
||||
proc newController*(networkService: network_service.Service,
|
||||
proc newController*(requestId: int32,
|
||||
networkService: network_service.Service,
|
||||
events: EventEmitter
|
||||
): Controller =
|
||||
new(result, delete)
|
||||
|
||||
result.requestId = requestId
|
||||
|
||||
result.networkService = networkService
|
||||
|
||||
result.detailedEntry = newCollectibleDetailsEmptyEntry()
|
||||
result.isDetailedEntryLoading = false
|
||||
|
||||
result.eventsHandler = newEventsHandler(events)
|
||||
result.eventsHandler = newEventsHandler(result.requestId, events)
|
||||
|
||||
result.setup()
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import NimQml, logging, std/json, sequtils, strutils
|
||||
import NimQml, logging, std/json, sequtils, strutils, options
|
||||
import tables, stint
|
||||
|
||||
import app/core/eventemitter
|
||||
|
@ -15,6 +15,8 @@ QtObject:
|
|||
events: EventEmitter
|
||||
eventHandlers: Table[string, EventCallbackProc]
|
||||
|
||||
requestId: int32
|
||||
|
||||
proc setup(self: EventsHandler) =
|
||||
self.QObject.setup
|
||||
|
||||
|
@ -27,6 +29,9 @@ QtObject:
|
|||
proc handleApiEvents(self: EventsHandler, e: Args) =
|
||||
var data = WalletSignal(e)
|
||||
|
||||
if data.requestId.isSome and data.requestId.get() != self.requestId:
|
||||
return
|
||||
|
||||
if self.eventHandlers.hasKey(data.eventType):
|
||||
var responseJson: JsonNode
|
||||
responseJson = parseJson(data.message)
|
||||
|
@ -39,8 +44,11 @@ QtObject:
|
|||
else:
|
||||
discard
|
||||
|
||||
proc newEventsHandler*(events: EventEmitter): EventsHandler =
|
||||
proc newEventsHandler*(requestId: int32, events: EventEmitter): EventsHandler =
|
||||
new(result, delete)
|
||||
|
||||
result.requestId = requestId
|
||||
|
||||
result.events = events
|
||||
result.eventHandlers = initTable[string, EventCallbackProc]()
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ QtObject:
|
|||
addresses: seq[string]
|
||||
chainIds: seq[int]
|
||||
|
||||
requestId: int32
|
||||
|
||||
proc setup(self: Controller) =
|
||||
self.QObject.setup
|
||||
|
||||
|
@ -68,7 +70,7 @@ QtObject:
|
|||
offset = self.model.getCollectiblesCount()
|
||||
self.fetchFromStart = false
|
||||
|
||||
let response = backend_collectibles.filterOwnedCollectiblesAsync(self.chainIds, self.addresses, offset, FETCH_BATCH_COUNT_DEFAULT)
|
||||
let response = backend_collectibles.filterOwnedCollectiblesAsync(self.requestId, self.chainIds, self.addresses, offset, FETCH_BATCH_COUNT_DEFAULT)
|
||||
if response.error != nil:
|
||||
self.model.setIsFetching(false)
|
||||
self.model.setIsError(true)
|
||||
|
@ -89,13 +91,15 @@ QtObject:
|
|||
self.model.setIsUpdating(false)
|
||||
)
|
||||
|
||||
proc newController*(events: EventEmitter): Controller =
|
||||
proc newController*(requestId: int32, events: EventEmitter): Controller =
|
||||
new(result, delete)
|
||||
|
||||
result.requestId = requestId
|
||||
|
||||
result.model = newModel()
|
||||
result.fetchFromStart = true
|
||||
|
||||
result.eventsHandler = newEventsHandler(events)
|
||||
result.eventsHandler = newEventsHandler(result.requestId, events)
|
||||
|
||||
result.addresses = @[]
|
||||
result.chainIds = @[]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import NimQml, logging, std/json, sequtils, strutils
|
||||
import NimQml, logging, std/json, sequtils, strutils, options
|
||||
import tables, stint, sets
|
||||
|
||||
import app/core/eventemitter
|
||||
|
@ -23,6 +23,8 @@ QtObject:
|
|||
collectiblesOwnershipUpdateStartedFn: proc()
|
||||
collectiblesOwnershipUpdateFinishedFn: proc()
|
||||
|
||||
requestId: int32
|
||||
|
||||
proc setup(self: EventsHandler) =
|
||||
self.QObject.setup
|
||||
|
||||
|
@ -41,6 +43,9 @@ QtObject:
|
|||
proc handleApiEvents(self: EventsHandler, e: Args) =
|
||||
var data = WalletSignal(e)
|
||||
|
||||
if data.requestId.isSome and data.requestId.get() != self.requestId:
|
||||
return
|
||||
|
||||
if self.walletEventHandlers.hasKey(data.eventType):
|
||||
let callback = self.walletEventHandlers[data.eventType]
|
||||
callback(data)
|
||||
|
@ -74,8 +79,11 @@ QtObject:
|
|||
return
|
||||
self.collectiblesOwnershipUpdateFinishedFn()
|
||||
|
||||
proc newEventsHandler*(events: EventEmitter): EventsHandler =
|
||||
proc newEventsHandler*(requestId: int32, events: EventEmitter): EventsHandler =
|
||||
new(result, delete)
|
||||
|
||||
result.requestId = requestId
|
||||
|
||||
result.events = events
|
||||
result.eventHandlers = initTable[string, EventCallbackProc]()
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ import ../../../../app_service/service/accounts/service as accounts_service
|
|||
import ../../../../app_service/service/node/service as node_service
|
||||
import ../../../../app_service/service/network_connection/service as network_connection_service
|
||||
|
||||
import backend/collectibles as backend_collectibles
|
||||
|
||||
logScope:
|
||||
topics = "wallet-section-module"
|
||||
|
||||
|
@ -108,8 +110,8 @@ proc newModule*(
|
|||
result.transactionService = transactionService
|
||||
result.activityController = activityc.newController(int32(ActivityID.History), currencyService, tokenService, events)
|
||||
result.tmpActivityController = activityc.newController(int32(ActivityID.Temporary), currencyService, tokenService, events)
|
||||
result.collectiblesController = collectiblesc.newController(events)
|
||||
result.collectibleDetailsController = collectible_detailsc.newController(networkService, events)
|
||||
result.collectiblesController = collectiblesc.newController(int32(backend_collectibles.CollectiblesRequestID.WalletAccount), events)
|
||||
result.collectibleDetailsController = collectible_detailsc.newController(int32(backend_collectibles.CollectiblesRequestID.WalletAccount), networkService, events)
|
||||
result.filter = initFilter(result.controller)
|
||||
|
||||
result.view = newView(result, result.activityController, result.tmpActivityController, result.collectiblesController, result.collectibleDetailsController)
|
||||
|
|
|
@ -8,6 +8,11 @@ from ./gen import rpc
|
|||
|
||||
export response_type, collectibles_types
|
||||
|
||||
type
|
||||
CollectiblesRequestID* = enum
|
||||
WalletAccount
|
||||
ProfileShowcase
|
||||
|
||||
# Declared in services/wallet/collectibles/service.go
|
||||
const eventCollectiblesOwnershipUpdateStarted*: string = "wallet-collectibles-ownership-update-started"
|
||||
const eventCollectiblesOwnershipUpdateFinished*: string = "wallet-collectibles-ownership-update-finished"
|
||||
|
@ -86,10 +91,12 @@ rpc(getCollectibleOwnersByContractAddress, "wallet"):
|
|||
contractAddress: string
|
||||
|
||||
rpc(filterOwnedCollectiblesAsync, "wallet"):
|
||||
requestId: int32
|
||||
chainIDs: seq[int]
|
||||
addresses: seq[string]
|
||||
offset: int
|
||||
limit: int
|
||||
|
||||
rpc(getCollectiblesDetailsAsync, "wallet"):
|
||||
requestId: int32
|
||||
uniqueIds: seq[CollectibleUniqueID]
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9d0acc2265bc19bbd3c5b6555ca538e678c7677f
|
||||
Subproject commit 25ff1dd75899e697aa80ccf795c32fcb6ed60c33
|
Loading…
Reference in New Issue