From 6d9be9b49d516f63f9f4785ca2027a3a37a8e175 Mon Sep 17 00:00:00 2001 From: Mikhail Rogachev Date: Thu, 15 Feb 2024 14:28:20 +0300 Subject: [PATCH] fix(Profile): fix requesting empty profile showcase (#13564) --- .../service/profile/dto/profile_showcase.nim | 25 +++++++++++-------- .../dto/profile_showcase_preferences.nim | 25 +++++++++++-------- src/app_service/service/profile/service.nim | 2 +- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/app_service/service/profile/dto/profile_showcase.nim b/src/app_service/service/profile/dto/profile_showcase.nim index 2f09465f43..869ccc93fd 100644 --- a/src/app_service/service/profile/dto/profile_showcase.nim +++ b/src/app_service/service/profile/dto/profile_showcase.nim @@ -78,16 +78,21 @@ proc toProfileShowcaseDto*(jsonObj: JsonNode): ProfileShowcaseDto = discard jsonObj.getProp("contactId", result.contactId) - for jsonMsg in jsonObj["communities"]: - result.communities.add(jsonMsg.toProfileShowcaseCommunity()) - for jsonMsg in jsonObj["accounts"]: - result.accounts.add(jsonMsg.toProfileShowcaseAccount()) - for jsonMsg in jsonObj["collectibles"]: - result.collectibles.add(jsonMsg.toProfileShowcaseCollectible()) - for jsonMsg in jsonObj["verifiedTokens"]: - result.verifiedTokens.add(jsonMsg.toProfileShowcaseVerifiedToken()) - for jsonMsg in jsonObj["unverifiedTokens"]: - result.unverifiedTokens.add(jsonMsg.toProfileShowcaseUnverifiedToken()) + if jsonObj["communities"].kind != JNull: + for jsonMsg in jsonObj["communities"]: + result.communities.add(jsonMsg.toProfileShowcaseCommunity()) + if jsonObj["accounts"].kind != JNull: + for jsonMsg in jsonObj["accounts"]: + result.accounts.add(jsonMsg.toProfileShowcaseAccount()) + if jsonObj["collectibles"].kind != JNull: + for jsonMsg in jsonObj["collectibles"]: + result.collectibles.add(jsonMsg.toProfileShowcaseCollectible()) + if jsonObj["verifiedTokens"].kind != JNull: + for jsonMsg in jsonObj["verifiedTokens"]: + result.verifiedTokens.add(jsonMsg.toProfileShowcaseVerifiedToken()) + if jsonObj["unverifiedTokens"].kind != JNull: + for jsonMsg in jsonObj["unverifiedTokens"]: + result.unverifiedTokens.add(jsonMsg.toProfileShowcaseUnverifiedToken()) proc `%`*(x: ProfileShowcaseAccount): JsonNode = result = newJobject() diff --git a/src/app_service/service/profile/dto/profile_showcase_preferences.nim b/src/app_service/service/profile/dto/profile_showcase_preferences.nim index d0c4dae5b2..3be0181c4f 100644 --- a/src/app_service/service/profile/dto/profile_showcase_preferences.nim +++ b/src/app_service/service/profile/dto/profile_showcase_preferences.nim @@ -141,16 +141,21 @@ proc toJsonNode*(self: ProfileShowcaseUnverifiedTokenPreference): JsonNode = proc toProfileShowcasePreferencesDto*(jsonObj: JsonNode): ProfileShowcasePreferencesDto = result = ProfileShowcasePreferencesDto() - for jsonMsg in jsonObj["communities"]: - result.communities.add(jsonMsg.toProfileShowcaseCommunityPreference()) - for jsonMsg in jsonObj["accounts"]: - result.accounts.add(jsonMsg.toProfileShowcaseAccountPreference()) - for jsonMsg in jsonObj["collectibles"]: - result.collectibles.add(jsonMsg.toProfileShowcaseCollectiblePreference()) - for jsonMsg in jsonObj["verifiedTokens"]: - result.verifiedTokens.add(jsonMsg.toProfileShowcaseVerifiedTokenPreference()) - for jsonMsg in jsonObj["unverifiedTokens"]: - result.unverifiedTokens.add(jsonMsg.toProfileShowcaseUnverifiedTokenPreference()) + if jsonObj["communities"].kind != JNull: + for jsonMsg in jsonObj["communities"]: + result.communities.add(jsonMsg.toProfileShowcaseCommunityPreference()) + if jsonObj["accounts"].kind != JNull: + for jsonMsg in jsonObj["accounts"]: + result.accounts.add(jsonMsg.toProfileShowcaseAccountPreference()) + if jsonObj["collectibles"].kind != JNull: + for jsonMsg in jsonObj["collectibles"]: + result.collectibles.add(jsonMsg.toProfileShowcaseCollectiblePreference()) + if jsonObj["verifiedTokens"].kind != JNull: + for jsonMsg in jsonObj["verifiedTokens"]: + result.verifiedTokens.add(jsonMsg.toProfileShowcaseVerifiedTokenPreference()) + if jsonObj["unverifiedTokens"].kind != JNull: + for jsonMsg in jsonObj["unverifiedTokens"]: + result.unverifiedTokens.add(jsonMsg.toProfileShowcaseUnverifiedTokenPreference()) proc toJsonNode*(self: ProfileShowcasePreferencesDto): JsonNode = let communities = self.communities.map(entry => entry.toJsonNode()) diff --git a/src/app_service/service/profile/service.nim b/src/app_service/service/profile/service.nim index a6437b5150..78a658d633 100644 --- a/src/app_service/service/profile/service.nim +++ b/src/app_service/service/profile/service.nim @@ -119,7 +119,7 @@ QtObject: try: let rpcResponseObj = rpcResponse.parseJson if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "": - error "Error requesting profile showcase preferences", msg = rpcResponseObj{"error"} + error "Error requesting profile showcase for a contact", msg = rpcResponseObj{"error"} return let profileShowcase = rpcResponseObj["response"]["result"].toProfileShowcaseDto()