feat(@wallet): collectible multi address
This commit is contained in:
parent
92a9c41238
commit
9738a3eec8
|
@ -637,8 +637,9 @@ proc ownsCollectible*(self: Controller, chainId: int, contractAddress: string, t
|
|||
let addresses = self.walletAccountService.getWalletAccounts().filter(a => a.walletType != WalletTypeWatch).map(a => a.address)
|
||||
|
||||
for address in addresses:
|
||||
let data = self.collectibleService.getOwnedCollectibles(chainId, address)
|
||||
for collectible in data.collectibles:
|
||||
let data = self.collectibleService.getOwnedCollectibles(chainId, @[address])
|
||||
|
||||
for collectible in data[0].collectibles:
|
||||
if collectible.id.contractAddress == contractAddress.toLowerAscii:
|
||||
return true
|
||||
|
||||
|
|
|
@ -17,9 +17,6 @@ type
|
|||
nodeService: node_service.Service
|
||||
networkConnectionService: network_connection_service.Service
|
||||
|
||||
# Forward declaration
|
||||
proc refetchOwnedCollectibles*(self: Controller, chainId: int, address: string)
|
||||
|
||||
proc newController*(
|
||||
delegate: io_interface.AccessInterface,
|
||||
events: EventEmitter,
|
||||
|
@ -41,18 +38,14 @@ proc newController*(
|
|||
proc delete*(self: Controller) =
|
||||
discard
|
||||
|
||||
proc resetCollectibles(self: Controller, chainId: int, address: string) =
|
||||
let data = self.collectibleService.getOwnedCollectibles(chainId, address)
|
||||
self.delegate.setCollectibles(chainId, address, data)
|
||||
|
||||
proc updateCollectibles(self: Controller, chainId: int, address: string) =
|
||||
let data = self.collectibleService.getOwnedCollectibles(chainId, address)
|
||||
self.delegate.appendCollectibles(chainId, address, data)
|
||||
let data = self.collectibleService.getOwnedCollectibles(chainId, @[address])
|
||||
self.delegate.appendCollectibles(chainId, address, data[0])
|
||||
|
||||
proc init*(self: Controller) =
|
||||
self.events.on(SIGNAL_OWNED_COLLECTIBLES_REFETCH) do(e:Args):
|
||||
let args = OwnedCollectiblesUpdateArgs(e)
|
||||
self.resetCollectibles(args.chainId, args.address)
|
||||
self.delegate.resetCollectibles()
|
||||
|
||||
self.events.on(SIGNAL_OWNED_COLLECTIBLES_UPDATE_ERROR) do(e:Args):
|
||||
let args = OwnedCollectiblesUpdateArgs(e)
|
||||
|
@ -69,20 +62,14 @@ proc init*(self: Controller) =
|
|||
self.events.on(SIGNAL_REFRESH_COLLECTIBLES) do(e:Args):
|
||||
self.collectibleService.refetchAllOwnedCollectibles()
|
||||
|
||||
proc getWalletAccountByAddress*(self: Controller, address: string): wallet_account_service.WalletAccountDto =
|
||||
return self.walletAccountService.getAccountByAddress(address)
|
||||
|
||||
proc getNetwork*(self: Controller): network_service.NetworkDto =
|
||||
return self.networkService.getNetworkForCollectibles()
|
||||
|
||||
proc getOwnedCollectibles*(self: Controller, chainId: int, address: string): CollectiblesData =
|
||||
return self.collectibleService.getOwnedCollectibles(chainId, address)
|
||||
proc getOwnedCollectibles*(self: Controller, chainId: int, addresses: seq[string]): seq[CollectiblesData] =
|
||||
return self.collectibleService.getOwnedCollectibles(chainId, addresses)
|
||||
|
||||
proc refetchOwnedCollectibles*(self: Controller, chainId: int, address: string) =
|
||||
self.collectibleService.refetchOwnedCollectibles(chainId, address)
|
||||
|
||||
proc fetchOwnedCollectibles*(self: Controller, chainId: int, address: string) =
|
||||
self.collectibleService.fetchOwnedCollectibles(chainId, address)
|
||||
proc fetchOwnedCollectibles*(self: Controller, chainId: int, addresses: seq[string]) =
|
||||
self.collectibleService.fetchOwnedCollectibles(chainId, addresses)
|
||||
|
||||
proc getCollectible*(self: Controller, chainId: int, id: UniqueID) : CollectibleDto =
|
||||
self.collectibleService.getCollectible(chainId, id)
|
||||
|
|
|
@ -9,7 +9,6 @@ type
|
|||
delegate: io_interface.AccessInterface
|
||||
collectibleService: collectible_service.Service
|
||||
network: network_dto.NetworkDto
|
||||
address: string
|
||||
|
||||
proc newController*(
|
||||
delegate: io_interface.AccessInterface,
|
||||
|
@ -25,9 +24,8 @@ proc delete*(self: Controller) =
|
|||
proc init*(self: Controller) =
|
||||
discard
|
||||
|
||||
method setCurrentAddress*(self: Controller, network: network_dto.NetworkDto, address: string) =
|
||||
method setCurrentNetwork*(self: Controller, network: network_dto.NetworkDto) =
|
||||
self.network = network
|
||||
self.address = address
|
||||
|
||||
proc update*(self: Controller, id: collectible_service.UniqueID) =
|
||||
let collectible = self.collectibleService.getCollectible(self.network.chainId, id)
|
||||
|
|
|
@ -15,7 +15,7 @@ method load*(self: AccessInterface) {.base.} =
|
|||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method setCurrentAddress*(self: AccessInterface, network: network_dto.NetworkDto, address: string) {.base.} =
|
||||
method setCurrentNetwork*(self: AccessInterface, network: network_dto.NetworkDto) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method update*(self: AccessInterface, address: string, tokenId: Uint256) {.base.} =
|
||||
|
|
|
@ -45,8 +45,8 @@ method viewDidLoad*(self: Module) =
|
|||
self.moduleLoaded = true
|
||||
self.delegate.currentCollectibleModuleDidLoad()
|
||||
|
||||
method setCurrentAddress*(self: Module, network: network_dto.NetworkDto, address: string) =
|
||||
self.controller.setCurrentAddress(network, address)
|
||||
method setCurrentNetwork*(self: Module, network: network_dto.NetworkDto) =
|
||||
self.controller.setCurrentNetwork(network)
|
||||
|
||||
method update*(self: Module, address: string, tokenId: Uint256) =
|
||||
let id = collectible_dto.UniqueID(
|
||||
|
|
|
@ -22,12 +22,15 @@ method fetchOwnedCollectibles*(self: AccessInterface) {.base.} =
|
|||
method onFetchStarted*(self: AccessInterface, chainId: int, address: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method setCollectibles*(self: AccessInterface, chainId: int, address: string, data: CollectiblesData) {.base.} =
|
||||
method setCollectibles*(self: AccessInterface, data: seq[CollectiblesData]) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method appendCollectibles*(self: AccessInterface, chainId: int, address: string, data: CollectiblesData) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method resetCollectibles*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method viewDidLoad*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ type
|
|||
moduleLoaded: bool
|
||||
|
||||
chainId: int
|
||||
address: string
|
||||
addresses: seq[string]
|
||||
|
||||
currentCollectibleModule: current_collectible_module.AccessInterface
|
||||
|
||||
|
@ -47,7 +47,7 @@ proc newModule*(
|
|||
result.controller = newController(result, events, collectibleService, walletAccountService, networkService, nodeService, networkConnectionService)
|
||||
result.moduleLoaded = false
|
||||
result.chainId = 0
|
||||
result.address = ""
|
||||
result.addresses = @[]
|
||||
result.currentCollectibleModule = currentCollectibleModule.newModule(result, collectibleService)
|
||||
|
||||
method delete*(self: Module) =
|
||||
|
@ -81,22 +81,21 @@ method currentCollectibleModuleDidLoad*(self: Module) =
|
|||
self.checkIfModuleDidLoad()
|
||||
|
||||
method fetchOwnedCollectibles*(self: Module) =
|
||||
self.controller.fetchOwnedCollectibles(self.chainId, self.address)
|
||||
self.controller.fetchOwnedCollectibles(self.chainId, self.addresses)
|
||||
|
||||
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
|
||||
let network = self.controller.getNetwork()
|
||||
let account = self.controller.getWalletAccountByAddress(addresses[0])
|
||||
self.chainId = network.chainId
|
||||
self.address = account.address
|
||||
self.currentCollectibleModule.setCurrentAddress(network, self.address)
|
||||
self.addresses = addresses
|
||||
self.currentCollectibleModule.setCurrentNetwork(network)
|
||||
self.view.setCollectibles(@[])
|
||||
let data = self.controller.getOwnedCollectibles(self.chainId, self.addresses)
|
||||
|
||||
let data = self.controller.getOwnedCollectibles(self.chainId, self.address)
|
||||
for i, addressData in data.pairs:
|
||||
if not addressData.anyLoaded:
|
||||
self.controller.fetchOwnedCollectibles(self.chainId, @[self.addresses[i]])
|
||||
|
||||
# Trigger a fetch the first time we switch to an account
|
||||
if not data.anyLoaded:
|
||||
self.controller.fetchOwnedCollectibles(self.chainId, self.address)
|
||||
|
||||
self.setCollectibles(self.chainId, self.address, data)
|
||||
self.setCollectibles(data)
|
||||
|
||||
proc ownedCollectibleToItem(self: Module, oc: OwnedCollectible): Item =
|
||||
let c = self.controller.getCollectible(self.chainId, oc.id)
|
||||
|
@ -104,45 +103,40 @@ proc ownedCollectibleToItem(self: Module, oc: OwnedCollectible): Item =
|
|||
return collectibleToItem(c, col, oc.isFromWatchedContract)
|
||||
|
||||
method onFetchStarted*(self: Module, chainId: int, address: string) =
|
||||
if self.chainId == chainId and self.address == address:
|
||||
if self.chainId == chainId and address in self.addresses:
|
||||
self.view.setIsFetching(true)
|
||||
|
||||
method setCollectibles*(self: Module, chainId: int, address: string, data: CollectiblesData) =
|
||||
if self.chainId == chainId and self.address == address:
|
||||
self.view.setIsError(data.isError)
|
||||
|
||||
if data.isError and not data.anyLoaded:
|
||||
# If fetching failed before being able to get any collectibles info,
|
||||
# show loading animation
|
||||
self.view.setIsFetching(true)
|
||||
else:
|
||||
self.view.setIsFetching(data.isFetching)
|
||||
|
||||
var newCollectibles = data.collectibles.map(oc => self.ownedCollectibleToItem(oc))
|
||||
self.view.setCollectibles(newCollectibles)
|
||||
self.view.setAllLoaded(data.allLoaded)
|
||||
method resetCollectibles*(self: Module) =
|
||||
let data = self.controller.getOwnedCollectibles(self.chainId, self.addresses)
|
||||
self.setCollectibles(data)
|
||||
|
||||
method appendCollectibles*(self: Module, chainId: int, address: string, data: CollectiblesData) =
|
||||
if self.chainId == chainId and self.address == address:
|
||||
self.view.setIsError(data.isError)
|
||||
if not (self.chainId == chainId and address in self.addresses):
|
||||
return
|
||||
|
||||
if data.isError and not data.anyLoaded:
|
||||
# If fetching failed before being able to get any collectibles info,
|
||||
# show loading animation
|
||||
self.view.setIsFetching(true)
|
||||
else:
|
||||
self.view.setIsFetching(data.isFetching)
|
||||
self.view.setIsError(data.isError)
|
||||
|
||||
if data.lastLoadCount > 0:
|
||||
var ownedCollectiblesToAdd = newSeq[OwnedCollectible]()
|
||||
for i in data.collectibles.len - data.lastLoadCount ..< data.collectibles.len:
|
||||
ownedCollectiblesToAdd.add(data.collectibles[i])
|
||||
if data.isError and not data.anyLoaded:
|
||||
# If fetching failed before being able to get any collectibles info,
|
||||
# show loading animation
|
||||
self.view.setIsFetching(true)
|
||||
else:
|
||||
self.view.setIsFetching(data.isFetching)
|
||||
|
||||
let newCollectibles = ownedCollectiblesToAdd.map(oc => self.ownedCollectibleToItem(oc))
|
||||
if data.lastLoadCount > 0:
|
||||
var ownedCollectiblesToAdd = newSeq[OwnedCollectible]()
|
||||
for i in data.collectibles.len - data.lastLoadCount ..< data.collectibles.len:
|
||||
ownedCollectiblesToAdd.add(data.collectibles[i])
|
||||
|
||||
self.view.appendCollectibles(newCollectibles)
|
||||
let newCollectibles = ownedCollectiblesToAdd.map(oc => self.ownedCollectibleToItem(oc))
|
||||
|
||||
self.view.setAllLoaded(data.allLoaded)
|
||||
self.view.appendCollectibles(newCollectibles)
|
||||
|
||||
self.view.setAllLoaded(data.allLoaded)
|
||||
|
||||
method setCollectibles*(self: Module, data: seq[CollectiblesData]) =
|
||||
for index, address in self.addresses:
|
||||
self.appendCollectibles(self.chainId, address, data[index])
|
||||
|
||||
method getHasCollectiblesCache*(self: Module): bool =
|
||||
return self.controller.getHasCollectiblesCache(self.address)
|
||||
return self.controller.getHasCollectiblesCache(self.addresses[0])
|
|
@ -307,9 +307,10 @@ QtObject:
|
|||
# Re-fetch
|
||||
self.refetchOwnedCollectibles(chainId, address)
|
||||
|
||||
proc getOwnedCollectibles*(self: Service, chainId: int, address: string) : CollectiblesData =
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
return self.accountsOwnershipData[chainId][address].data
|
||||
proc getOwnedCollectibles*(self: Service, chainId: int, addresses: seq[string]) : seq[CollectiblesData] =
|
||||
for address in addresses:
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
result.add(self.accountsOwnershipData[chainId][address].data)
|
||||
|
||||
proc getCollectible*(self: Service, chainId: int, id: UniqueID) : CollectibleDto =
|
||||
try:
|
||||
|
@ -466,28 +467,29 @@ QtObject:
|
|||
)
|
||||
self.threadpool.start(arg)
|
||||
|
||||
proc fetchOwnedCollectibles*(self: Service, chainId: int, address: string, limit: int = ownedCollectiblesFetchLimit) =
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
proc fetchOwnedCollectibles*(self: Service, chainId: int, addresses: seq[string], limit: int = ownedCollectiblesFetchLimit) =
|
||||
for address in addresses:
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
|
||||
let ownershipData = self.accountsOwnershipData[chainId][address]
|
||||
let watchedContractAddresses = ownershipData.watchedContractAddresses
|
||||
let collectiblesData = ownershipData.data
|
||||
let ownershipData = self.accountsOwnershipData[chainId][address]
|
||||
let watchedContractAddresses = ownershipData.watchedContractAddresses
|
||||
let collectiblesData = ownershipData.data
|
||||
|
||||
let state = collectiblesData.state
|
||||
let state = collectiblesData.state
|
||||
|
||||
if state == State.Init and len(watchedContractAddresses) > 0:
|
||||
collectiblesData.state = State.WatchedContractsLoading
|
||||
self.fetchOwnedCollectiblesFromWatchedContracts(chainId, address)
|
||||
elif state == State.Init or state == State.WatchedContractsLoaded or state == State.ChunkLoaded:
|
||||
collectiblesData.state = State.ChunkLoading
|
||||
self.fetchNextOwnedCollectiblesChunk(chainId, address)
|
||||
else:
|
||||
return
|
||||
if state == State.Init and len(watchedContractAddresses) > 0:
|
||||
collectiblesData.state = State.WatchedContractsLoading
|
||||
self.fetchOwnedCollectiblesFromWatchedContracts(chainId, address)
|
||||
elif state == State.Init or state == State.WatchedContractsLoaded or state == State.ChunkLoaded:
|
||||
collectiblesData.state = State.ChunkLoading
|
||||
self.fetchNextOwnedCollectiblesChunk(chainId, address)
|
||||
else:
|
||||
return
|
||||
|
||||
var data = OwnedCollectiblesUpdateArgs()
|
||||
data.chainId = chainId
|
||||
data.address = address
|
||||
self.events.emit(SIGNAL_OWNED_COLLECTIBLES_UPDATE_STARTED, data)
|
||||
var data = OwnedCollectiblesUpdateArgs()
|
||||
data.chainId = chainId
|
||||
data.address = address
|
||||
self.events.emit(SIGNAL_OWNED_COLLECTIBLES_UPDATE_STARTED, data)
|
||||
|
||||
proc refetchOwnedCollectibles*(self: Service, chainId: int, address: string) =
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
|
@ -500,7 +502,7 @@ QtObject:
|
|||
data.address = address
|
||||
self.events.emit(SIGNAL_OWNED_COLLECTIBLES_REFETCH, data)
|
||||
|
||||
self.fetchOwnedCollectibles(chainId, address)
|
||||
self.fetchOwnedCollectibles(chainId, @[address])
|
||||
|
||||
proc refetchAllOwnedCollectibles*(self: Service) =
|
||||
for chainId, addressesData in self.accountsOwnershipData:
|
||||
|
|
Loading…
Reference in New Issue