feat(@desktop/communities): Add burning state logic

Expose burningState in the model.
Update burningState when burning operation changes its status.

Issue #11076
This commit is contained in:
Michal Iskierko 2023-07-04 13:05:43 +02:00 committed by Michał Iskierko
parent 0b47412889
commit 64422afed7
12 changed files with 62 additions and 11 deletions

View File

@ -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

View File

@ -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}
]"""

View File

@ -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:

View File

@ -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

View File

@ -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)

View File

@ -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")

View File

@ -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 != "":

View File

@ -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)

View File

@ -52,4 +52,10 @@ type MemberRole* {.pure} = enum
Owner
ManageUsers
ModerateContent
Admin
Admin
type
ContractTransactionStatus* {.pure.} = enum
Failed,
InProgress,
Completed

View File

@ -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)

View File

@ -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 @[]

View File

@ -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
}