Retrieve community token contract addresses from token metadata

Prior to this change, the control node would try to fetch the community
token data from its database entries.

However, when a community has been recovered from importing an account
via seedphrase, the database for community tokens will be empty.

So it's better to retrieve the contract addresses from the community
description's metadata (which should always be there).

This change determines the community token from the community metadata.
This commit is contained in:
Pascal Precht 2023-06-07 10:57:41 +02:00 committed by Follow the white rabbit
parent 59796b938f
commit a465417981
2 changed files with 18 additions and 1 deletions

View File

@ -653,7 +653,7 @@ proc getTokenDecimals*(self: Controller, symbol: string): int =
proc getContractAddressesForToken*(self: Controller, symbol: string): Table[int, string] =
var contractAddresses = self.tokenService.getContractAddressesForToken(symbol)
let communityToken = self.communityTokensService.getCommunityTokenBySymbol(self.getMySectionId(), symbol)
let communityToken = self.communityService.getCommunityTokenBySymbol(self.getMySectionId(), symbol)
if communityToken.address != "":
contractAddresses[communityToken.chainId] = communityToken.address
return contractAddresses

View File

@ -2,6 +2,7 @@ import NimQml, Tables, json, sequtils, std/sets, std/algorithm, strformat, strut
import json_serialization/std/tables as ser_tables
import ./dto/community as community_dto
import ../community_tokens/dto/community_token as community_token_dto
import ../activity_center/service as activity_center_service
import ../message/service as message_service
@ -682,6 +683,22 @@ QtObject:
proc getCommunityIds*(self: Service): seq[string] =
return toSeq(self.communities.keys)
proc getCommunityTokenBySymbol*(self: Service, communityId: string, symbol: string): CommunityTokenDto =
let community = self.getCommunityById(communityId)
for metadata in community.communityTokensMetadata:
if metadata.symbol == symbol:
var communityToken = CommunityTokenDto()
communityToken.name = metadata.name
communityToken.symbol = metadata.symbol
communityToken.description = metadata.description
communityToken.tokenType = metadata.tokenType
for chainId, contractAddress in metadata.addresses:
communityToken.chainId = chainId
communityToken.address = contractAddress
break
return communityToken
proc sortAsc[T](t1, t2: T): int =
if(t1.position > t2.position):
return 1