diff --git a/src/app/modules/main/profile_section/contacts/controller.nim b/src/app/modules/main/profile_section/contacts/controller.nim index cc08579f9b..735d664ce0 100644 --- a/src/app/modules/main/profile_section/contacts/controller.nim +++ b/src/app/modules/main/profile_section/contacts/controller.nim @@ -204,5 +204,8 @@ proc requestProfileShowcaseForContact*(self: Controller, contactId: string, vali proc fetchProfileShowcaseAccountsByAddress*(self: Controller, address: string) = self.contactsService.fetchProfileShowcaseAccountsByAddress(address) +proc fetchProfileShowcaseAssetsForAContact*(self: Controller, chainIds: seq[int], accountsAddresses, contractAddresses: seq[string]) = + self.contactsService.fetchProfileShowcaseAssetsForAContact(chainIds, accountsAddresses, contractAddresses) + proc getEnabledChainIds*(self: Controller): seq[int] = - return self.networkService.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId) \ No newline at end of file + return self.networkService.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId) diff --git a/src/app/modules/main/profile_section/contacts/module.nim b/src/app/modules/main/profile_section/contacts/module.nim index 1417cff846..0162bd448e 100644 --- a/src/app/modules/main/profile_section/contacts/module.nim +++ b/src/app/modules/main/profile_section/contacts/module.nim @@ -391,11 +391,16 @@ method loadProfileShowcase(self: Module, profileShowcase: ProfileShowcaseDto, va showcaseKey: token.symbol, showcasePosition: token.order )) + var tokenChainIds: seq[int] = @[] + var tokenContractAddresses: seq[string] = @[] for token in profileShowcase.unverifiedTokens: assetItems.add(ShowcaseContactGenericItem( showcaseKey: token.toCombinedTokenId(), showcasePosition: token.order )) + tokenContractAddresses.add(token.contractAddress) + if not tokenChainIds.contains(token.chainId): + tokenChainIds.add(token.chainId) self.view.loadProfileShowcaseContactAssets(assetItems) var socialLinkItems: seq[ShowcaseContactSocialLinkItem] = @[] @@ -413,8 +418,14 @@ method loadProfileShowcase(self: Module, profileShowcase: ProfileShowcaseDto, va else: let enabledChainIds = self.controller.getEnabledChainIds() - let combinedNetworks = utils.intersectSeqs(collectibleChainIds, enabledChainIds) - self.collectiblesController.setFilterAddressesAndChains(accountAddresses, combinedNetworks) + # fetch collectibles for contact's accounts + let combinedCollectibleChainIds = utils.intersectSeqs(collectibleChainIds, enabledChainIds) + self.collectiblesController.setFilterAddressesAndChains(accountAddresses, combinedCollectibleChainIds) + + # fetch assets for contact's accounts + let combinedTokenChainIds = utils.intersectSeqs(tokenChainIds, enabledChainIds) + self.controller.fetchProfileShowcaseAssetsForAContact(combinedTokenChainIds, accountAddresses, tokenContractAddresses) + self.controller.requestProfileShowcaseForContact(self.showcasePublicKey, true) method fetchProfileShowcaseAccountsByAddress*(self: Module, address: string) = diff --git a/src/app_service/service/contacts/async_tasks.nim b/src/app_service/service/contacts/async_tasks.nim index 37c0de84c6..92609043e2 100644 --- a/src/app_service/service/contacts/async_tasks.nim +++ b/src/app_service/service/contacts/async_tasks.nim @@ -6,6 +6,7 @@ from ../../common/conversion import isCompressedPubKey include ../../../app/core/tasks/common import ../../../backend/contacts as status_go +import ../../../backend/backend as backend ################################################# # Async lookup ENS contact @@ -115,4 +116,25 @@ const fetchProfileShowcaseAccountsTask: Task = proc(argEncoded: string) {.gcsafe response["response"] = rpcResponse.result except Exception as e: response["error"] = %* e.msg - arg.finish(response) \ No newline at end of file + arg.finish(response) + +type + FetchAssetsForAContactShowcaseArg = ref object of QObjectTaskArg + chainIds*: seq[int] + accountsAddresses*: seq[string] + contractAddresses*: seq[string] + +const fetchAssetsForAContactShowcaseTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = + let arg = decode[FetchAssetsForAContactShowcaseArg](argEncoded) + var response = %* { + "response": "", + "error": "", + } + try: + let rpcResponse = backend.getBalancesByChain(arg.chainIds, arg.accountsAddresses, arg.contractAddresses) + if not rpcResponse.error.isNil: + raise newException(CatchableError, rpcResponse.error.message) + response["response"] = rpcResponse.result + except Exception as e: + response["error"] = %* e.msg + arg.finish(response) diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 9f5518f02b..032c117be8 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -953,4 +953,27 @@ QtObject: data.profileShowcase.accounts = map(rpcResponseObj{"response"}.getElems(), proc(x: JsonNode): ProfileShowcaseAccount = toProfileShowcaseAccount(x)) except Exception as e: error "onProfileShowcaseAccountsByAddressFetched", msg = e.msg - self.events.emit(SIGNAL_CONTACT_SHOWCASE_ACCOUNTS_BY_ADDRESS_FETCHED, data) \ No newline at end of file + self.events.emit(SIGNAL_CONTACT_SHOWCASE_ACCOUNTS_BY_ADDRESS_FETCHED, data) + + proc fetchProfileShowcaseAssetsForAContact*(self: Service, chainIds: seq[int], accountsAddresses, contractAddresses: seq[string]) = + let arg = FetchAssetsForAContactShowcaseArg( + chainIds: chainIds, + accountsAddresses: accountsAddresses, + contractAddresses: contractAddresses, + tptr: cast[ByteAddress](fetchAssetsForAContactShowcaseTask), + vptr: cast[ByteAddress](self.vptr), + slot: "onProfileShowcaseAssetsForAContactFetched", + ) + self.threadpool.start(arg) + + proc onProfileShowcaseAssetsForAContactFetched*(self: Service, rpcResponse: string) {.slot.} = + try: + let rpcResponseObj = rpcResponse.parseJson + if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "": + error "Error fetching assets for a contact", msg = rpcResponseObj{"error"} + return + + # TODO: get tokens data from the response + echo "-------------------->", rpcResponseObj["response"]["result"] + except Exception as e: + error "Error fetching assets for a contact", msg = e.msg \ No newline at end of file