feat: implement delelete community token functionality

This partially addresses #11186 as it implements the delete
functionality for community tokens.

If a deployment failed, users have the ability to delete the added
community token from the list.

The retry functionality will be implemented in a follow up commit.

Needs: https://github.com/status-im/status-go/pull/3794
This commit is contained in:
Pascal Precht 2023-07-24 15:09:45 +02:00 committed by r4bbit
parent ed13b61c3a
commit 7e714e33fc
13 changed files with 68 additions and 2 deletions

View File

@ -74,6 +74,9 @@ proc init*(self: Controller) =
proc deployContract*(self: Controller, communityId: string, addressFrom: string, password: string, deploymentParams: DeploymentParameters, tokenMetadata: CommunityTokensMetadataDto, tokenImageCropInfoJson: string, chainId: int) = proc deployContract*(self: Controller, communityId: string, addressFrom: string, password: string, deploymentParams: DeploymentParameters, tokenMetadata: CommunityTokensMetadataDto, tokenImageCropInfoJson: string, chainId: int) =
self.communityTokensService.deployContract(communityId, addressFrom, password, deploymentParams, tokenMetadata, tokenImageCropInfoJson, chainId) self.communityTokensService.deployContract(communityId, addressFrom, password, deploymentParams, tokenMetadata, tokenImageCropInfoJson, chainId)
proc removeCommunityToken*(self: Controller, communityId: string, chainId: int, address: string) =
self.communityTokensService.removeCommunityToken(communityId, chainId, address)
proc airdropTokens*(self: Controller, communityId: string, password: string, tokensAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string]) = proc airdropTokens*(self: Controller, communityId: string, password: string, tokensAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string]) =
self.communityTokensService.airdropTokens(communityId, password, tokensAndAmounts, walletAddresses) self.communityTokensService.airdropTokens(communityId, password, tokensAndAmounts, walletAddresses)

View File

@ -70,3 +70,6 @@ method onBurnStateChanged*(self: AccessInterface, communityId: string, tokenName
method onAirdropStateChanged*(self: AccessInterface, communityId: string, tokenName: string, chainId: int, transactionHash: string, status: ContractTransactionStatus) {.base.} = method onAirdropStateChanged*(self: AccessInterface, communityId: string, tokenName: string, chainId: int, transactionHash: string, status: ContractTransactionStatus) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method removeCommunityToken*(self: AccessInterface, communityId: string, chainId: int, address: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -112,6 +112,18 @@ QtObject:
self.endInsertRows() self.endInsertRows()
self.countChanged() self.countChanged()
proc removeItemByChainIdAndAddress*(self: TokenModel, chainId: int, address: string) =
for i in 0 ..< self.items.len:
if((self.items[i].tokenDto.address == address) and (self.items[i].tokenDto.chainId == chainId)):
let parentModelIndex = newQModelIndex()
defer: parentModelIndex.delete
self.beginRemoveRows(parentModelIndex, i, i)
self.items.delete(i)
self.endRemoveRows()
self.countChanged()
return
proc getCount*(self: TokenModel): int {.slot.} = proc getCount*(self: TokenModel): int {.slot.} =
self.items.len self.items.len

View File

@ -184,6 +184,9 @@ method deployAssets*(self: Module, communityId: string, fromAddress: string, nam
self.tempContractAction = ContractAction.Deploy self.tempContractAction = ContractAction.Deploy
self.authenticate() self.authenticate()
method removeCommunityToken*(self: Module, communityId: string, chainId: int, address: string) =
self.controller.removeCommunityToken(communityId, chainId, address)
method onUserAuthenticated*(self: Module, password: string) = method onUserAuthenticated*(self: Module, password: string) =
defer: self.resetTempValues() defer: self.resetTempValues()
if password.len == 0: if password.len == 0:

View File

@ -27,6 +27,9 @@ QtObject:
proc deployAssets*(self: View, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: float, infiniteSupply: bool, decimals: int, chainId: int, imageCropInfoJson: string) {.slot.} = proc deployAssets*(self: View, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: float, infiniteSupply: bool, decimals: int, chainId: int, imageCropInfoJson: string) {.slot.} =
self.communityTokensModule.deployAssets(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, decimals, chainId, imageCropInfoJson) self.communityTokensModule.deployAssets(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, decimals, chainId, imageCropInfoJson)
proc removeCommunityToken*(self: View, communityId: string, chainId: int, address: string) {.slot.} =
self.communityTokensModule.removeCommunityToken(communityId, chainId, address)
proc airdropTokens*(self: View, communityId: string, tokensJsonString: string, walletsJsonString: string) {.slot.} = proc airdropTokens*(self: View, communityId: string, tokensJsonString: string, walletsJsonString: string) {.slot.} =
self.communityTokensModule.airdropTokens(communityId, tokensJsonString, walletsJsonString) self.communityTokensModule.airdropTokens(communityId, tokensJsonString, walletsJsonString)

View File

@ -348,6 +348,10 @@ proc init*(self: Controller) =
let args = CommunityTokenDeployedStatusArgs(e) let args = CommunityTokenDeployedStatusArgs(e)
self.delegate.onCommunityTokenDeployStateChanged(args.communityId, args.chainId, args.contractAddress, args.deployState) self.delegate.onCommunityTokenDeployStateChanged(args.communityId, args.chainId, args.contractAddress, args.deployState)
self.events.on(SIGNAL_COMMUNITY_TOKEN_REMOVED) do(e: Args):
let args = CommunityTokenRemovedArgs(e)
self.delegate.onCommunityTokenRemoved(args.communityId, args.chainId, args.contractAddress)
self.events.on(SIGNAL_BURN_STATUS) do(e: Args): self.events.on(SIGNAL_BURN_STATUS) do(e: Args):
let args = RemoteDestructArgs(e) let args = RemoteDestructArgs(e)
let communityToken = args.communityToken let communityToken = args.communityToken

View File

@ -303,6 +303,9 @@ method onCommunityTokenDeployStateChanged*(self: AccessInterface, communityId: s
method onCommunityTokenSupplyChanged*(self: AccessInterface, communityId: string, chainId: int, contractAddress: string, supply: Uint256, remainingSupply: Uint256) {.base.} = method onCommunityTokenSupplyChanged*(self: AccessInterface, communityId: string, chainId: int, contractAddress: string, supply: Uint256, remainingSupply: Uint256) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method onCommunityTokenRemoved*(self: AccessInterface, communityId: string, chainId: int, contractAddress: string) =
raise newException(ValueError, "No implementation available")
method onBurnStateChanged*(self: AccessInterface, communityId: string, chainId: int, contractAddress: string, burnState: ContractTransactionStatus) {.base.} = method onBurnStateChanged*(self: AccessInterface, communityId: string, chainId: int, contractAddress: string, burnState: ContractTransactionStatus) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -1014,6 +1014,11 @@ method onCommunityTokenDeploymentStarted*[T](self: Module[T], communityToken: Co
if item.id != "": if item.id != "":
item.appendCommunityToken(self.createTokenItem(communityToken)) item.appendCommunityToken(self.createTokenItem(communityToken))
method onCommunityTokenRemoved*[T](self: Module[T], communityId: string, chainId: int, address: string) =
let item = self.view.model().getItemById(communityId)
if item.id != "":
item.removeCommunityToken(chainId, address)
method onCommunityTokenOwnersFetched*[T](self: Module[T], communityId: string, chainId: int, contractAddress: string, owners: seq[CollectibleOwner]) = method onCommunityTokenOwnersFetched*[T](self: Module[T], communityId: string, chainId: int, contractAddress: string, owners: seq[CollectibleOwner]) =
let item = self.view.model().getItemById(communityId) let item = self.view.model().getItemById(communityId)
if item.id != "": if item.id != "":

View File

@ -332,6 +332,9 @@ proc encrypted*(self: SectionItem): bool {.inline.} =
proc appendCommunityToken*(self: SectionItem, item: TokenItem) {.inline.} = proc appendCommunityToken*(self: SectionItem, item: TokenItem) {.inline.} =
self.communityTokensModel.appendItem(item) self.communityTokensModel.appendItem(item)
proc removeCommunityToken*(self: SectionItem, chainId: int, contractAddress: string) {.inline.} =
self.communityTokensModel.removeItemByChainIdAndAddress(chainId, contractAddress)
proc updateCommunityTokenDeployState*(self: SectionItem, chainId: int, contractAddress: string, deployState: DeployState) {.inline.} = proc updateCommunityTokenDeployState*(self: SectionItem, chainId: int, contractAddress: string, deployState: DeployState) {.inline.} =
self.communityTokensModel.updateDeployState(chainId, contractAddress, deployState) self.communityTokensModel.updateDeployState(chainId, contractAddress, deployState)

View File

@ -77,6 +77,12 @@ type
communityToken*: CommunityTokenDto communityToken*: CommunityTokenDto
transactionHash*: string transactionHash*: string
type
CommunityTokenRemovedArgs* = ref object of Args
communityId*: string
contractAddress*: string
chainId*: int
type type
RemoteDestructArgs* = ref object of Args RemoteDestructArgs* = ref object of Args
communityToken*: CommunityTokenDto communityToken*: CommunityTokenDto
@ -150,6 +156,9 @@ const SIGNAL_COMMUNITY_TOKEN_OWNERS_FETCHED* = "communityTokenOwnersFetched"
const SIGNAL_REMOTE_DESTRUCT_STATUS* = "communityTokenRemoteDestructStatus" const SIGNAL_REMOTE_DESTRUCT_STATUS* = "communityTokenRemoteDestructStatus"
const SIGNAL_BURN_STATUS* = "communityTokenBurnStatus" const SIGNAL_BURN_STATUS* = "communityTokenBurnStatus"
const SIGNAL_AIRDROP_STATUS* = "airdropStatus" const SIGNAL_AIRDROP_STATUS* = "airdropStatus"
const SIGNAL_REMOVE_COMMUNITY_TOKEN_FAILED* = "removeCommunityTokenFailed"
const SIGNAL_COMMUNITY_TOKEN_REMOVED* = "communityTokenRemoved"
QtObject: QtObject:
type type
@ -364,6 +373,19 @@ QtObject:
except RpcException: except RpcException:
error "Error getting all community tokens", message = getCurrentExceptionMsg() error "Error getting all community tokens", message = getCurrentExceptionMsg()
proc removeCommunityToken*(self: Service, communityId: string, chainId: int, address: string) =
try:
let response = tokens_backend.removeCommunityToken(chainId, address)
if response.error != nil:
let error = Json.decode($response.error, RpcError)
raise newException(RpcException, "error removing community token: " & error.message)
return
self.events.emit(SIGNAL_COMMUNITY_TOKEN_REMOVED, CommunityTokenRemovedArgs(communityId: communityId, contractAddress: address, chainId: chainId))
except RpcException as e:
error "Error removing community token", message = getCurrentExceptionMsg()
self.events.emit(SIGNAL_REMOVE_COMMUNITY_TOKEN_FAILED, Args())
proc getCommunityTokenBySymbol*(self: Service, communityId: string, symbol: string): CommunityTokenDto = proc getCommunityTokenBySymbol*(self: Service, communityId: string, symbol: string): CommunityTokenDto =
let communityTokens = self.getCommunityTokens(communityId) let communityTokens = self.getCommunityTokens(communityId)
for token in communityTokens: for token in communityTokens:

View File

@ -15,6 +15,10 @@ proc deployAssets*(chainId: int, deploymentParams: JsonNode, txData: JsonNode, p
let payload = %* [chainId, deploymentParams, txData, utils.hashPassword(password)] let payload = %* [chainId, deploymentParams, txData, utils.hashPassword(password)]
return core.callPrivateRPC("collectibles_deployAssets", payload) return core.callPrivateRPC("collectibles_deployAssets", payload)
proc removeCommunityToken*(chainId: int, address: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [chainId, address]
return core.callPrivateRPC("wakuext_removeCommunityToken", payload)
proc getCommunityTokens*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc getCommunityTokens*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [communityId] let payload = %* [communityId]
return core.callPrivateRPC("wakuext_getCommunityTokens", payload) return core.callPrivateRPC("wakuext_getCommunityTokens", payload)

View File

@ -55,7 +55,8 @@ QtObject {
} }
function deleteToken(communityId, contractUniqueKey) { function deleteToken(communityId, contractUniqueKey) {
console.log("TODO: Delete token bakend!") let parts = contractUniqueKey.split("_");
communityTokensModuleInst.removeCommunityToken(communityId, parts[0], parts[1])
} }
readonly property Connections connections: Connections { readonly property Connections connections: Connections {

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit e8bac916ecf3a5771c77d020a636165942694afd Subproject commit 3d1b1bab572eeedb7028abf2486dec3d9fe04858