From d970e7c3f2aa51ed482f9ef48330f44659bb76fb Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Tue, 13 Feb 2024 14:23:58 +0100 Subject: [PATCH] fix(@desktop/wallet): Fix issues in adding minted collectible as permision in a community --- .../modules/main/chat_section/controller.nim | 18 +++++++++++++++-- src/app/modules/main/chat_section/module.nim | 20 ++++++++----------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 2b28f980e0..0192fcf1d7 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -678,8 +678,22 @@ proc deleteCommunityTokenPermission*(self: Controller, communityId: string, perm proc allAccountsTokenBalance*(self: Controller, symbol: string): float64 = return self.walletAccountService.allAccountsTokenBalance(symbol) -proc findTokenBySymbol*(self: Controller, symbol: string): TokenBySymbolItem = - return self.tokenService.findTokenBySymbol(symbol) +proc getTokenDecimals*(self: Controller, symbol: string): int = + let asset = self.tokenService.findTokenBySymbol(symbol) + if asset != nil: + return asset.decimals + return 0 + +proc getContractAddressesForToken*(self: Controller, symbol: string): Table[int, string] = + var contractAddresses = initTable[int, string]() + let token = self.tokenService.findTokenBySymbol(symbol) + if token != nil: + for addrPerChain in token.addressPerChainId: + contractAddresses[addrPerChain.chainId] = addrPerChain.address + let communityToken = self.communityService.getCommunityTokenBySymbol(self.getMySectionId(), symbol) + if communityToken.address != "": + contractAddresses[communityToken.chainId] = communityToken.address + return contractAddresses proc getCommunityTokenList*(self: Controller): seq[CommunityTokenDto] = return self.communityTokensService.getCommunityTokens(self.getMySectionId()) diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index ffb8fa23e5..373b7cbea7 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -1309,22 +1309,18 @@ method createOrEditCommunityTokenPermission*(self: Module, communityId: string, let viewAmount = tokenCriteria{"amount"}.getFloat var tokenCriteriaDto = tokenCriteria.toTokenCriteriaDto - let token = self.controller.findTokenBySymbol(tokenCriteriaDto.symbol) - if token != nil: - if tokenCriteriaDto.`type` == TokenType.ERC20: - tokenCriteriaDto.decimals = token.decimals + if tokenCriteriaDto.`type` == TokenType.ERC20: + tokenCriteriaDto.decimals = self.controller.getTokenDecimals(tokenCriteriaDto.symbol) - if token.addressPerChainId.len == 0 and tokenCriteriaDto.`type` != TokenType.ENS: - if permissionId == "": - self.onCommunityTokenPermissionCreationFailed(communityId) - return - self.onCommunityTokenPermissionUpdateFailed(communityId) + let contractAddresses = self.controller.getContractAddressesForToken(tokenCriteriaDto.symbol) + if contractAddresses.len == 0 and tokenCriteriaDto.`type` != TokenType.ENS: + if permissionId == "": + self.onCommunityTokenPermissionCreationFailed(communityId) return + self.onCommunityTokenPermissionUpdateFailed(communityId) + return tokenCriteriaDto.amount = viewAmount.formatBiggestFloat(ffDecimal) - var contractAddresses = initTable[int, string]() - for addrPerChain in token.addressPerChainId: - contractAddresses[addrPerChain.chainId] = addrPerChain.address tokenCriteriaDto.contractAddresses = contractAddresses tokenPermission.tokenCriteria.add(tokenCriteriaDto)