From c9fd4ebceea3e10b19633aae4d5f4bdf2c10a9fd Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 27 Feb 2024 15:44:47 -0500 Subject: [PATCH] feat(communities): hook promoteSelfToControlNode to UI Fixes https://github.com/status-im/status-desktop/issues/13560 --- .../modules/main/communities/controller.nim | 5 ++++- .../modules/main/communities/io_interface.nim | 3 +++ src/app/modules/main/communities/module.nim | 3 +++ src/app/modules/main/communities/view.nim | 2 ++ src/app_service/service/community/service.nim | 18 ++++++++++++++++++ .../service/community_tokens/service.nim | 2 +- src/backend/communities.nim | 3 ++- src/backend/community_tokens.nim | 4 ---- ui/app/AppLayouts/stores/RootStore.qml | 4 ++++ ui/app/mainui/Popups.qml | 2 +- 10 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 2dbde41aef..5aada8c6d3 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -478,4 +478,7 @@ proc removeCommunityChat*(self: Controller, communityId: string, channelId: stri self.communityService.deleteCommunityChat(communityId, channelId) proc getNetworks*(self: Controller): seq[NetworkDto] = - return self.networksService.getNetworks() + return self.networksService.getNetworks() + +proc promoteSelfToControlNode*(self: Controller, communityId: string) = + self.communityService.promoteSelfToControlNode(communityId) diff --git a/src/app/modules/main/communities/io_interface.nim b/src/app/modules/main/communities/io_interface.nim index 7330f52293..d5ba4cc6a9 100644 --- a/src/app/modules/main/communities/io_interface.nim +++ b/src/app/modules/main/communities/io_interface.nim @@ -259,3 +259,6 @@ method onCommunityMemberRevealedAccountsLoaded*(self: AccessInterface, community method removeCommunityChat*(self: AccessInterface, communityId: string, channelId: string) {.base.} = raise newException(ValueError, "No implementation available") + +method promoteSelfToControlNode*(self: AccessInterface, communityId: string) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 3259ef126d..80e658ed93 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -945,3 +945,6 @@ method onCommunityMemberRevealedAccountsLoaded*(self: Module, communityId, membe airdropAddress = revealedAccount.address self.view.setMyRevealedAddressesForCurrentCommunity($(%*addresses), airdropAddress) + +method promoteSelfToControlNode*(self: Module, communityId: string) = + self.controller.promoteSelfToControlNode(communityId) diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index 0ffa972b81..6c5162318b 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -816,3 +816,5 @@ QtObject: proc sendSharedAddressesForAllNonKeycardKeypairsSignedSignal*(self: View) = self.sharedAddressesForAllNonKeycardKeypairsSigned() + proc promoteSelfToControlNode*(self: View, communityId: string) {.slot.} = + self.delegate.promoteSelfToControlNode(communityId) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index fc1a526341..7ec9b62501 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -2391,3 +2391,21 @@ QtObject: except Exception as e: error "Error setting community shard", msg = e.msg self.events.emit(SIGNAL_COMMUNITY_SHARD_SET_FAILED, CommunityShardSetArgs(communityId: rpcResponseObj["communityId"].getStr)) + + proc promoteSelfToControlNode*(self: Service, communityId: string) = + try: + let response = status_go.promoteSelfToControlNode(communityId) + if response.error != nil: + let error = Json.decode($response.error, RpcError) + raise newException(RpcException, error.message) + + if response.result == nil or response.result.kind == JNull or response.result["communities"].kind == JNull or + response.result["communities"].len == 0: + error "error: ", procName="promoteSelfToControlNode", errDesription = "result is nil" + return + + let community = response.result["communities"][0].toCommunityDto() + self.communities[communityId] = community + self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community])) + except Exception as e: + error "error promoting self to control node", msg = e.msg diff --git a/src/app_service/service/community_tokens/service.nim b/src/app_service/service/community_tokens/service.nim index 797662b66d..09a1de7915 100644 --- a/src/app_service/service/community_tokens/service.nim +++ b/src/app_service/service/community_tokens/service.nim @@ -441,7 +441,7 @@ QtObject: let contractDetails = transactionArgs.data.parseJson().toContractDetails() if transactionArgs.success: # promoteSelfToControlNode will be moved to status-go in next phase - discard tokens_backend.promoteSelfToControlNode(contractDetails.communityId) + discard communities_backend.promoteSelfToControlNode(contractDetails.communityId) let finaliseStatusArgs = FinaliseOwnershipStatusArgs(isPending: false, communityId: contractDetails.communityId) self.events.emit(SIGNAL_FINALISE_OWNERSHIP_STATUS, finaliseStatusArgs) diff --git a/src/backend/communities.nim b/src/backend/communities.nim index 15500cf3d4..a9afd871a3 100644 --- a/src/backend/communities.nim +++ b/src/backend/communities.nim @@ -520,7 +520,8 @@ proc getCommunityMembersForWalletAddresses*(communityId: string, chainId: int): return callPrivateRPC("getCommunityMembersForWalletAddresses".prefix, %* [communityId, chainId]) proc promoteSelfToControlNode*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = - return callPrivateRPC("promoteSelfToControlNode".prefix, %* [communityId]) + let payload = %*[communityId] + return core.callPrivateRPC("wakuext_promoteSelfToControlNode", payload) proc setCommunityShard*(communityId: string, index: int): RpcResponse[JsonNode] {.raises: [Exception].} = if index != -1: diff --git a/src/backend/community_tokens.nim b/src/backend/community_tokens.nim index d1d41e689f..9bbecec295 100644 --- a/src/backend/community_tokens.nim +++ b/src/backend/community_tokens.nim @@ -140,10 +140,6 @@ proc registerLostOwnershipNotification*(communityId: string): RpcResponse[JsonNo let payload = %*[communityId] return core.callPrivateRPC("wakuext_registerLostOwnershipNotification", payload) -proc promoteSelfToControlNode*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = - let payload = %*[communityId] - return core.callPrivateRPC("wakuext_promoteSelfToControlNode", payload) - proc getOwnerTokenOwnerAddress*(chainId: int, contractAddress: string): RpcResponse[JsonNode] {.raises: [Exception].} = let payload = %*[chainId, contractAddress] return core.callPrivateRPC("communitytokens_ownerTokenOwnerAddress", payload) diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index f7d8df7b56..a8c1421c2e 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -256,4 +256,8 @@ QtObject { function updatePermissionsModel(communityId, sharedAddresses) { communitiesModuleInst.checkPermissions(communityId, JSON.stringify(sharedAddresses)) } + + function promoteSelfToControlNode(communityId) { + communitiesModuleInst.promoteSelfToControlNode(communityId) + } } diff --git a/ui/app/mainui/Popups.qml b/ui/app/mainui/Popups.qml index d9d15937e8..1ce2b3411e 100644 --- a/ui/app/mainui/Popups.qml +++ b/ui/app/mainui/Popups.qml @@ -838,7 +838,7 @@ QtObject { id: importControlNodePopup ImportControlNodePopup { onClosed: destroy() - onImportControlNode: console.warn("!!! TODO importControlNode for community:", community.name) // FIXME implement moving (importing) the control node + onImportControlNode: root.rootStore.promoteSelfToControlNode(community.id) } },