diff --git a/src/app/modules/main/communities/tokens/io_interface.nim b/src/app/modules/main/communities/tokens/io_interface.nim index a86d6572e7..10d3a1b7c9 100644 --- a/src/app/modules/main/communities/tokens/io_interface.nim +++ b/src/app/modules/main/communities/tokens/io_interface.nim @@ -1,5 +1,6 @@ import ../../../../../app_service/service/community_tokens/service import ../../../../../app_service/service/community/dto/community +import ../../../../../app_service/common/types import ../../../shared_models/currency_amount type diff --git a/src/app/modules/main/communities/tokens/models/token_item.nim b/src/app/modules/main/communities/tokens/models/token_item.nim index cd70440dfe..952255ce63 100644 --- a/src/app/modules/main/communities/tokens/models/token_item.nim +++ b/src/app/modules/main/communities/tokens/models/token_item.nim @@ -2,6 +2,7 @@ import strformat, sequtils, stint import ../../../../../../app_service/service/community_tokens/dto/community_token import ../../../../../../app_service/service/collectible/dto import ../../../../../../app_service/service/network/dto +import ../../../../../../app_service/common/types import token_owners_model import token_owners_item @@ -15,6 +16,7 @@ type chainIcon*: string accountName*: string remainingSupply*: Uint256 + burnState*: ContractTransactionStatus tokenOwnersModel*: token_owners_model.TokenOwnersModel proc initTokenItem*( @@ -22,6 +24,7 @@ proc initTokenItem*( network: NetworkDto, tokenOwners: seq[CollectibleOwner], accountName: string, + burnState: ContractTransactionStatus, remainingSupply: Uint256 ): TokenItem = result.tokenDto = tokenDto @@ -30,6 +33,7 @@ proc initTokenItem*( result.chainIcon = network.iconURL result.accountName = accountName result.remainingSupply = remainingSupply + result.burnState = burnState result.tokenOwnersModel = newTokenOwnersModel() result.tokenOwnersModel.setItems(tokenOwners.map(proc(owner: CollectibleOwner): TokenOwnersItem = # TODO find member with the address - later when airdrop to member will be added @@ -42,6 +46,7 @@ proc `$`*(self: TokenItem): string = chainName: {self.chainName}, chainIcon: {self.chainIcon}, remainingSupply: {self.remainingSupply}, + burnState: {self.burnState}, tokenOwnersModel: {self.tokenOwnersModel} ]""" diff --git a/src/app/modules/main/communities/tokens/models/token_model.nim b/src/app/modules/main/communities/tokens/models/token_model.nim index 3e33a89e79..22e3c2a122 100644 --- a/src/app/modules/main/communities/tokens/models/token_model.nim +++ b/src/app/modules/main/communities/tokens/models/token_model.nim @@ -5,6 +5,7 @@ import token_owners_model import ../../../../../../app_service/service/community_tokens/dto/community_token import ../../../../../../app_service/service/collectible/dto import ../../../../../../app_service/common/utils +import ../../../../../../app_service/common/types type ModelRole {.pure.} = enum @@ -27,6 +28,7 @@ type AccountName RemainingSupply Decimals + BurnState QtObject: type TokenModel* = ref object of QAbstractListModel @@ -52,6 +54,15 @@ QtObject: self.dataChanged(index, index, @[ModelRole.DeployState.int]) return + proc updateBurnState*(self: TokenModel, chainId: int, contractAddress: string, burnState: ContractTransactionStatus) = + for i in 0 ..< self.items.len: + if((self.items[i].tokenDto.address == contractAddress) and (self.items[i].tokenDto.chainId == chainId)): + self.items[i].burnState = burnState + let index = self.createIndex(i, 0, nil) + defer: index.delete + self.dataChanged(index, index, @[ModelRole.BurnState.int]) + return + proc updateSupply*(self: TokenModel, chainId: int, contractAddress: string, supply: Uint256) = for i in 0 ..< self.items.len: if((self.items[i].tokenDto.address == contractAddress) and (self.items[i].tokenDto.chainId == chainId)): @@ -132,6 +143,7 @@ QtObject: ModelRole.AccountName.int:"accountName", ModelRole.RemainingSupply.int:"remainingSupply", ModelRole.Decimals.int:"decimals", + ModelRole.BurnState.int:"burnState", }.toTable method data(self: TokenModel, index: QModelIndex, role: int): QVariant = @@ -180,6 +192,8 @@ QtObject: result = newQVariant(supplyByType(item.remainingSupply, item.tokenDto.tokenType)) of ModelRole.Decimals: result = newQVariant(item.tokenDto.decimals) + of ModelRole.BurnState: + result = newQVariant(item.burnState.int) proc `$`*(self: TokenModel): string = for i in 0 ..< self.items.len: diff --git a/src/app/modules/main/communities/tokens/module.nim b/src/app/modules/main/communities/tokens/module.nim index d15e799bd4..06e8c7390c 100644 --- a/src/app/modules/main/communities/tokens/module.nim +++ b/src/app/modules/main/communities/tokens/module.nim @@ -6,6 +6,7 @@ import ../../../../../app_service/service/network/service as networks_service import ../../../../../app_service/service/community/dto/community import ../../../../../app_service/service/accounts/utils as utl import ../../../../../app_service/common/conversion +import ../../../../../app_service/common/types import ../../../../core/eventemitter import ../../../../global/global_singleton import ../../../shared_models/currency_amount diff --git a/src/app/modules/main/controller.nim b/src/app/modules/main/controller.nim index bc21dad2f6..15b84ae8bc 100644 --- a/src/app/modules/main/controller.nim +++ b/src/app/modules/main/controller.nim @@ -349,6 +349,7 @@ proc init*(self: Controller) = let communityToken = args.communityToken self.delegate.onCommunityTokenSupplyChanged(communityToken.communityId, communityToken.chainId, communityToken.address, communityToken.supply, self.getRemainingSupply(communityToken.chainId, communityToken.address)) + self.delegate.onBurnStateChanged(communityToken.communityId, communityToken.chainId, communityToken.address, args.status) self.events.on(SIGNAL_AIRDROP_STATUS) do(e: Args): let args = AirdropArgs(e) @@ -491,6 +492,9 @@ proc getCommunityTokenOwners*(self: Controller, communityId: string, chainId: in proc getCommunityTokenOwnerName*(self: Controller, chainId: int, contractAddress: string): string = return self.communityTokensService.contractOwnerName(chainId, contractAddress) +proc getCommunityTokenBurnState*(self: Controller, chainId: int, contractAddress: string): ContractTransactionStatus = + return self.communityTokensService.getCommunityTokenBurnState(chainId, contractAddress) + proc getRemainingSupply*(self: Controller, chainId: int, contractAddress: string): Uint256 = return self.communityTokensService.getRemainingSupply(chainId, contractAddress) diff --git a/src/app/modules/main/io_interface.nim b/src/app/modules/main/io_interface.nim index d5d2ff11f0..164eeb6edd 100644 --- a/src/app/modules/main/io_interface.nim +++ b/src/app/modules/main/io_interface.nim @@ -13,7 +13,7 @@ import ../../../app_service/service/wallet_account/service as wallet_account_ser import ../../../app_service/service/token/service as token_service import ../../../app_service/service/collectible/service as collectible_service import ../../../app_service/service/community_tokens/service as community_tokens_service -from ../../../app_service/common/types import StatusType +from ../../../app_service/common/types import StatusType, ContractTransactionStatus import ../../global/app_signals import ../../core/eventemitter @@ -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.} = raise newException(ValueError, "No implementation available") +method onBurnStateChanged*(self: AccessInterface, communityId: string, chainId: int, contractAddress: string, burnState: ContractTransactionStatus) {.base.} = + raise newException(ValueError, "No implementation available") + method onAcceptRequestToJoinFailed*(self: AccessInterface, communityId: string, memberKey: string, requestId: string) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index a12dc3c36d..4e625b8f00 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -241,7 +241,8 @@ proc createTokenItem[T](self: Module[T], tokenDto: CommunityTokenDto) : TokenIte let tokenOwners = self.controller.getCommunityTokenOwners(tokenDto.communityId, tokenDto.chainId, tokenDto.address) let ownerAddressName = self.controller.getCommunityTokenOwnerName(tokenDto.chainId, tokenDto.address) let remainingSupply = if tokenDto.infiniteSupply: stint.parse("0", Uint256) else: self.controller.getRemainingSupply(tokenDto.chainId, tokenDto.address) - result = initTokenItem(tokenDto, network, tokenOwners, ownerAddressName, remainingSupply) + let burnState = self.controller.getCommunityTokenBurnState(tokenDto.chainId, tokenDto.address) + result = initTokenItem(tokenDto, network, tokenOwners, ownerAddressName, burnState, remainingSupply) proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto): SectionItem = let isCommunity = channelGroup.channelGroupType == ChannelGroupType.Community @@ -1028,6 +1029,11 @@ method onCommunityTokenSupplyChanged*[T](self: Module[T], communityId: string, c item.updateCommunityTokenSupply(chainId, contractAddress, supply) item.updateCommunityRemainingSupply(chainId, contractAddress, remainingSupply) +method onBurnStateChanged*[T](self: Module[T], communityId: string, chainId: int, contractAddress: string, burnState: ContractTransactionStatus) = + let item = self.view.model().getItemById(communityId) + if item.id != "": + item.updateBurnState(chainId, contractAddress, burnState) + method onAcceptRequestToJoinLoading*[T](self: Module[T], communityId: string, memberKey: string) = let item = self.view.model().getItemById(communityId) if item.id != "": diff --git a/src/app/modules/shared_models/section_item.nim b/src/app/modules/shared_models/section_item.nim index b756ce99ac..e6b646e155 100644 --- a/src/app/modules/shared_models/section_item.nim +++ b/src/app/modules/shared_models/section_item.nim @@ -334,6 +334,9 @@ proc updateCommunityTokenSupply*(self: SectionItem, chainId: int, contractAddres proc updateCommunityRemainingSupply*(self: SectionItem, chainId: int, contractAddress: string, remainingSupply: Uint256) {.inline.} = self.communityTokensModel.updateRemainingSupply(chainId, contractAddress, remainingSupply) +proc updateBurnState*(self: SectionItem, chainId: int, contractAddress: string, burnState: ContractTransactionStatus) {.inline.} = + self.communityTokensModel.updateBurnState(chainId, contractAddress, burnState) + proc setCommunityTokenOwners*(self: SectionItem, chainId: int, contractAddress: string, owners: seq[CollectibleOwner]) {.inline.} = self.communityTokensModel.setCommunityTokenOwners(chainId, contractAddress, owners) diff --git a/src/app_service/common/types.nim b/src/app_service/common/types.nim index da13c5d7d1..a2c83b4ada 100644 --- a/src/app_service/common/types.nim +++ b/src/app_service/common/types.nim @@ -52,4 +52,10 @@ type MemberRole* {.pure} = enum Owner ManageUsers ModerateContent - Admin \ No newline at end of file + Admin + +type + ContractTransactionStatus* {.pure.} = enum + Failed, + InProgress, + Completed \ No newline at end of file diff --git a/src/app_service/service/community_tokens/service.nim b/src/app_service/service/community_tokens/service.nim index 4b2edd4f78..8efa3aaf5a 100644 --- a/src/app_service/service/community_tokens/service.nim +++ b/src/app_service/service/community_tokens/service.nim @@ -77,12 +77,6 @@ type communityToken*: CommunityTokenDto transactionHash*: string -type - ContractTransactionStatus* {.pure.} = enum - Failed, - InProgress, - Completed - type RemoteDestructArgs* = ref object of Args communityToken*: CommunityTokenDto @@ -371,6 +365,17 @@ QtObject: if token.symbol == symbol: return token + proc getCommunityTokenBurnState*(self: Service, chainId: int, contractAddress: string): ContractTransactionStatus = + let burnTransactions = self.transactionService.getPendingTransactionsForType(PendingTransactionTypeDto.BurnCommunityToken) + for transaction in burnTransactions: + try: + let communityToken = toCommunityTokenDto(parseJson(transaction.additionalData)) + if communityToken.chainId == chainId and communityToken.address == contractAddress: + return ContractTransactionStatus.InProgress + except Exception: + discard + return ContractTransactionStatus.Completed + proc contractOwner*(self: Service, chainId: int, contractAddress: string): string = try: let response = tokens_backend.contractOwner(chainId, contractAddress) diff --git a/src/app_service/service/transaction/service.nim b/src/app_service/service/transaction/service.nim index 888eefae62..e85f2c0953 100644 --- a/src/app_service/service/transaction/service.nim +++ b/src/app_service/service/transaction/service.nim @@ -167,6 +167,10 @@ QtObject: error "error: ", errDescription return + proc getPendingTransactionsForType*(self: Service, transactionType: PendingTransactionTypeDto): seq[TransactionDto] = + let allPendingTransactions = self.getPendingTransactions() + return allPendingTransactions.filter(x => x.typeValue == $transactionType) + proc getAllTransactions*(self: Service, address: string): seq[TransactionDto] = if not self.allTransactions.hasKey(address): return @[] diff --git a/ui/app/AppLayouts/Communities/panels/MintTokensSettingsPanel.qml b/ui/app/AppLayouts/Communities/panels/MintTokensSettingsPanel.qml index ea768ec0f8..35ac4cb8ce 100644 --- a/ui/app/AppLayouts/Communities/panels/MintTokensSettingsPanel.qml +++ b/ui/app/AppLayouts/Communities/panels/MintTokensSettingsPanel.qml @@ -616,10 +616,9 @@ StackView { token.symbol: model.symbol token.transferable: model.transferable token.type: model.tokenType - + token.burnState: model.burnState // TODO: Backend //token.accountAddress: model.accountAddress - //token.burnState: model.burnState //token.remotelyDestructState: model.remotelyDestructState }