Skip to content

Commit

Permalink
refactor: make use of newly introduce SaveCommunityToken() API
Browse files Browse the repository at this point in the history
As discussed in status-im/status-go#3798, there
was a need to separate the logic in `AddCommunityToken()` into two API.

This commit adjust the client to these changes such that:

1. After community token deployment tx was sent, we create
   a `CommunityToken` and add it to the database for tracking purposes
2. Once the tx is mined or dropped, we add the community token to the
   community description and publish it, or we update the deployment
   state in the database

Needs: status-im/status-go#3798
  • Loading branch information
0x-r4bbit committed Jul 25, 2023
1 parent 38672ff commit 297fa6b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/app_service/service/community_tokens/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ QtObject:
error "Collectible contract not deployed", chainId=tokenDto.chainId, address=tokenDto.address
try:
discard updateCommunityTokenState(tokenDto.chainId, tokenDto.address, deployState) #update db state
# now add community token to community and publish update
let response = tokens_backend.addCommunityToken(tokenDto.communityId, tokenDto.chainId, tokenDto.address)
if response.error != nil:
let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "error adding community token: " & error.message)
except RpcException:
error "Error updating collectibles contract state", message = getCurrentExceptionMsg()
let data = CommunityTokenDeployedStatusArgs(communityId: tokenDto.communityId, contractAddress: tokenDto.address,
Expand Down Expand Up @@ -324,7 +329,7 @@ QtObject:
croppedImage{"imagePath"} = newJString(singletonInstance.utils.formatImagePath(croppedImage["imagePath"].getStr))

# save token to db
let communityTokenJson = tokens_backend.addCommunityToken(communityToken, $croppedImage)
let communityTokenJson = tokens_backend.saveCommunityToken(communityToken, $croppedImage)
communityToken = communityTokenJson.result.toCommunityTokenDto()
let data = CommunityTokenDeployedArgs(communityToken: communityToken, transactionHash: transactionHash)
self.events.emit(SIGNAL_COMMUNITY_TOKEN_DEPLOYED, data)
Expand Down
6 changes: 5 additions & 1 deletion src/backend/community_tokens.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ proc getAllCommunityTokens*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
return core.callPrivateRPC("wakuext_getAllCommunityTokens", payload)

proc addCommunityToken*(token: CommunityTokenDto, croppedImageJson: string): RpcResponse[JsonNode] {.raises: [Exception].} =
proc saveCommunityToken*(token: CommunityTokenDto, croppedImageJson: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let croppedImage = newCroppedImage(croppedImageJson)
let payload = %* [token.toJsonNode(), croppedImage]
return core.callPrivateRPC("wakuext_saveCommunityToken", payload)

proc addCommunityToken*(communityId: string, chainId: int, address: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [communityId, chainId, address]
return core.callPrivateRPC("wakuext_addCommunityToken", payload)

proc updateCommunityTokenState*(chainId: int, contractAddress: string, deployState: DeployState): RpcResponse[JsonNode] {.raises: [Exception].} =
Expand Down

0 comments on commit 297fa6b

Please sign in to comment.