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:
parent
0b47412889
commit
64422afed7
|
@ -1,5 +1,6 @@
|
||||||
import ../../../../../app_service/service/community_tokens/service
|
import ../../../../../app_service/service/community_tokens/service
|
||||||
import ../../../../../app_service/service/community/dto/community
|
import ../../../../../app_service/service/community/dto/community
|
||||||
|
import ../../../../../app_service/common/types
|
||||||
import ../../../shared_models/currency_amount
|
import ../../../shared_models/currency_amount
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -2,6 +2,7 @@ import strformat, sequtils, stint
|
||||||
import ../../../../../../app_service/service/community_tokens/dto/community_token
|
import ../../../../../../app_service/service/community_tokens/dto/community_token
|
||||||
import ../../../../../../app_service/service/collectible/dto
|
import ../../../../../../app_service/service/collectible/dto
|
||||||
import ../../../../../../app_service/service/network/dto
|
import ../../../../../../app_service/service/network/dto
|
||||||
|
import ../../../../../../app_service/common/types
|
||||||
|
|
||||||
import token_owners_model
|
import token_owners_model
|
||||||
import token_owners_item
|
import token_owners_item
|
||||||
|
@ -15,6 +16,7 @@ type
|
||||||
chainIcon*: string
|
chainIcon*: string
|
||||||
accountName*: string
|
accountName*: string
|
||||||
remainingSupply*: Uint256
|
remainingSupply*: Uint256
|
||||||
|
burnState*: ContractTransactionStatus
|
||||||
tokenOwnersModel*: token_owners_model.TokenOwnersModel
|
tokenOwnersModel*: token_owners_model.TokenOwnersModel
|
||||||
|
|
||||||
proc initTokenItem*(
|
proc initTokenItem*(
|
||||||
|
@ -22,6 +24,7 @@ proc initTokenItem*(
|
||||||
network: NetworkDto,
|
network: NetworkDto,
|
||||||
tokenOwners: seq[CollectibleOwner],
|
tokenOwners: seq[CollectibleOwner],
|
||||||
accountName: string,
|
accountName: string,
|
||||||
|
burnState: ContractTransactionStatus,
|
||||||
remainingSupply: Uint256
|
remainingSupply: Uint256
|
||||||
): TokenItem =
|
): TokenItem =
|
||||||
result.tokenDto = tokenDto
|
result.tokenDto = tokenDto
|
||||||
|
@ -30,6 +33,7 @@ proc initTokenItem*(
|
||||||
result.chainIcon = network.iconURL
|
result.chainIcon = network.iconURL
|
||||||
result.accountName = accountName
|
result.accountName = accountName
|
||||||
result.remainingSupply = remainingSupply
|
result.remainingSupply = remainingSupply
|
||||||
|
result.burnState = burnState
|
||||||
result.tokenOwnersModel = newTokenOwnersModel()
|
result.tokenOwnersModel = newTokenOwnersModel()
|
||||||
result.tokenOwnersModel.setItems(tokenOwners.map(proc(owner: CollectibleOwner): TokenOwnersItem =
|
result.tokenOwnersModel.setItems(tokenOwners.map(proc(owner: CollectibleOwner): TokenOwnersItem =
|
||||||
# TODO find member with the address - later when airdrop to member will be added
|
# 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},
|
chainName: {self.chainName},
|
||||||
chainIcon: {self.chainIcon},
|
chainIcon: {self.chainIcon},
|
||||||
remainingSupply: {self.remainingSupply},
|
remainingSupply: {self.remainingSupply},
|
||||||
|
burnState: {self.burnState},
|
||||||
tokenOwnersModel: {self.tokenOwnersModel}
|
tokenOwnersModel: {self.tokenOwnersModel}
|
||||||
]"""
|
]"""
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import token_owners_model
|
||||||
import ../../../../../../app_service/service/community_tokens/dto/community_token
|
import ../../../../../../app_service/service/community_tokens/dto/community_token
|
||||||
import ../../../../../../app_service/service/collectible/dto
|
import ../../../../../../app_service/service/collectible/dto
|
||||||
import ../../../../../../app_service/common/utils
|
import ../../../../../../app_service/common/utils
|
||||||
|
import ../../../../../../app_service/common/types
|
||||||
|
|
||||||
type
|
type
|
||||||
ModelRole {.pure.} = enum
|
ModelRole {.pure.} = enum
|
||||||
|
@ -27,6 +28,7 @@ type
|
||||||
AccountName
|
AccountName
|
||||||
RemainingSupply
|
RemainingSupply
|
||||||
Decimals
|
Decimals
|
||||||
|
BurnState
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type TokenModel* = ref object of QAbstractListModel
|
type TokenModel* = ref object of QAbstractListModel
|
||||||
|
@ -52,6 +54,15 @@ QtObject:
|
||||||
self.dataChanged(index, index, @[ModelRole.DeployState.int])
|
self.dataChanged(index, index, @[ModelRole.DeployState.int])
|
||||||
return
|
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) =
|
proc updateSupply*(self: TokenModel, chainId: int, contractAddress: string, supply: Uint256) =
|
||||||
for i in 0 ..< self.items.len:
|
for i in 0 ..< self.items.len:
|
||||||
if((self.items[i].tokenDto.address == contractAddress) and (self.items[i].tokenDto.chainId == chainId)):
|
if((self.items[i].tokenDto.address == contractAddress) and (self.items[i].tokenDto.chainId == chainId)):
|
||||||
|
@ -132,6 +143,7 @@ QtObject:
|
||||||
ModelRole.AccountName.int:"accountName",
|
ModelRole.AccountName.int:"accountName",
|
||||||
ModelRole.RemainingSupply.int:"remainingSupply",
|
ModelRole.RemainingSupply.int:"remainingSupply",
|
||||||
ModelRole.Decimals.int:"decimals",
|
ModelRole.Decimals.int:"decimals",
|
||||||
|
ModelRole.BurnState.int:"burnState",
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
method data(self: TokenModel, index: QModelIndex, role: int): QVariant =
|
method data(self: TokenModel, index: QModelIndex, role: int): QVariant =
|
||||||
|
@ -180,6 +192,8 @@ QtObject:
|
||||||
result = newQVariant(supplyByType(item.remainingSupply, item.tokenDto.tokenType))
|
result = newQVariant(supplyByType(item.remainingSupply, item.tokenDto.tokenType))
|
||||||
of ModelRole.Decimals:
|
of ModelRole.Decimals:
|
||||||
result = newQVariant(item.tokenDto.decimals)
|
result = newQVariant(item.tokenDto.decimals)
|
||||||
|
of ModelRole.BurnState:
|
||||||
|
result = newQVariant(item.burnState.int)
|
||||||
|
|
||||||
proc `$`*(self: TokenModel): string =
|
proc `$`*(self: TokenModel): string =
|
||||||
for i in 0 ..< self.items.len:
|
for i in 0 ..< self.items.len:
|
||||||
|
|
|
@ -6,6 +6,7 @@ import ../../../../../app_service/service/network/service as networks_service
|
||||||
import ../../../../../app_service/service/community/dto/community
|
import ../../../../../app_service/service/community/dto/community
|
||||||
import ../../../../../app_service/service/accounts/utils as utl
|
import ../../../../../app_service/service/accounts/utils as utl
|
||||||
import ../../../../../app_service/common/conversion
|
import ../../../../../app_service/common/conversion
|
||||||
|
import ../../../../../app_service/common/types
|
||||||
import ../../../../core/eventemitter
|
import ../../../../core/eventemitter
|
||||||
import ../../../../global/global_singleton
|
import ../../../../global/global_singleton
|
||||||
import ../../../shared_models/currency_amount
|
import ../../../shared_models/currency_amount
|
||||||
|
|
|
@ -349,6 +349,7 @@ proc init*(self: Controller) =
|
||||||
let communityToken = args.communityToken
|
let communityToken = args.communityToken
|
||||||
self.delegate.onCommunityTokenSupplyChanged(communityToken.communityId, communityToken.chainId,
|
self.delegate.onCommunityTokenSupplyChanged(communityToken.communityId, communityToken.chainId,
|
||||||
communityToken.address, communityToken.supply, self.getRemainingSupply(communityToken.chainId, communityToken.address))
|
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):
|
self.events.on(SIGNAL_AIRDROP_STATUS) do(e: Args):
|
||||||
let args = AirdropArgs(e)
|
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 =
|
proc getCommunityTokenOwnerName*(self: Controller, chainId: int, contractAddress: string): string =
|
||||||
return self.communityTokensService.contractOwnerName(chainId, contractAddress)
|
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 =
|
proc getRemainingSupply*(self: Controller, chainId: int, contractAddress: string): Uint256 =
|
||||||
return self.communityTokensService.getRemainingSupply(chainId, contractAddress)
|
return self.communityTokensService.getRemainingSupply(chainId, contractAddress)
|
||||||
|
|
||||||
|
|
|
@ -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/token/service as token_service
|
||||||
import ../../../app_service/service/collectible/service as collectible_service
|
import ../../../app_service/service/collectible/service as collectible_service
|
||||||
import ../../../app_service/service/community_tokens/service as community_tokens_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 ../../global/app_signals
|
||||||
import ../../core/eventemitter
|
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.} =
|
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 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.} =
|
method onAcceptRequestToJoinFailed*(self: AccessInterface, communityId: string, memberKey: string, requestId: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -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 tokenOwners = self.controller.getCommunityTokenOwners(tokenDto.communityId, tokenDto.chainId, tokenDto.address)
|
||||||
let ownerAddressName = self.controller.getCommunityTokenOwnerName(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)
|
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 =
|
proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto): SectionItem =
|
||||||
let isCommunity = channelGroup.channelGroupType == ChannelGroupType.Community
|
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.updateCommunityTokenSupply(chainId, contractAddress, supply)
|
||||||
item.updateCommunityRemainingSupply(chainId, contractAddress, remainingSupply)
|
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) =
|
method onAcceptRequestToJoinLoading*[T](self: Module[T], communityId: string, memberKey: string) =
|
||||||
let item = self.view.model().getItemById(communityId)
|
let item = self.view.model().getItemById(communityId)
|
||||||
if item.id != "":
|
if item.id != "":
|
||||||
|
|
|
@ -334,6 +334,9 @@ proc updateCommunityTokenSupply*(self: SectionItem, chainId: int, contractAddres
|
||||||
proc updateCommunityRemainingSupply*(self: SectionItem, chainId: int, contractAddress: string, remainingSupply: Uint256) {.inline.} =
|
proc updateCommunityRemainingSupply*(self: SectionItem, chainId: int, contractAddress: string, remainingSupply: Uint256) {.inline.} =
|
||||||
self.communityTokensModel.updateRemainingSupply(chainId, contractAddress, remainingSupply)
|
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.} =
|
proc setCommunityTokenOwners*(self: SectionItem, chainId: int, contractAddress: string, owners: seq[CollectibleOwner]) {.inline.} =
|
||||||
self.communityTokensModel.setCommunityTokenOwners(chainId, contractAddress, owners)
|
self.communityTokensModel.setCommunityTokenOwners(chainId, contractAddress, owners)
|
||||||
|
|
||||||
|
|
|
@ -52,4 +52,10 @@ type MemberRole* {.pure} = enum
|
||||||
Owner
|
Owner
|
||||||
ManageUsers
|
ManageUsers
|
||||||
ModerateContent
|
ModerateContent
|
||||||
Admin
|
Admin
|
||||||
|
|
||||||
|
type
|
||||||
|
ContractTransactionStatus* {.pure.} = enum
|
||||||
|
Failed,
|
||||||
|
InProgress,
|
||||||
|
Completed
|
|
@ -77,12 +77,6 @@ type
|
||||||
communityToken*: CommunityTokenDto
|
communityToken*: CommunityTokenDto
|
||||||
transactionHash*: string
|
transactionHash*: string
|
||||||
|
|
||||||
type
|
|
||||||
ContractTransactionStatus* {.pure.} = enum
|
|
||||||
Failed,
|
|
||||||
InProgress,
|
|
||||||
Completed
|
|
||||||
|
|
||||||
type
|
type
|
||||||
RemoteDestructArgs* = ref object of Args
|
RemoteDestructArgs* = ref object of Args
|
||||||
communityToken*: CommunityTokenDto
|
communityToken*: CommunityTokenDto
|
||||||
|
@ -371,6 +365,17 @@ QtObject:
|
||||||
if token.symbol == symbol:
|
if token.symbol == symbol:
|
||||||
return token
|
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 =
|
proc contractOwner*(self: Service, chainId: int, contractAddress: string): string =
|
||||||
try:
|
try:
|
||||||
let response = tokens_backend.contractOwner(chainId, contractAddress)
|
let response = tokens_backend.contractOwner(chainId, contractAddress)
|
||||||
|
|
|
@ -167,6 +167,10 @@ QtObject:
|
||||||
error "error: ", errDescription
|
error "error: ", errDescription
|
||||||
return
|
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] =
|
proc getAllTransactions*(self: Service, address: string): seq[TransactionDto] =
|
||||||
if not self.allTransactions.hasKey(address):
|
if not self.allTransactions.hasKey(address):
|
||||||
return @[]
|
return @[]
|
||||||
|
|
|
@ -616,10 +616,9 @@ StackView {
|
||||||
token.symbol: model.symbol
|
token.symbol: model.symbol
|
||||||
token.transferable: model.transferable
|
token.transferable: model.transferable
|
||||||
token.type: model.tokenType
|
token.type: model.tokenType
|
||||||
|
token.burnState: model.burnState
|
||||||
// TODO: Backend
|
// TODO: Backend
|
||||||
//token.accountAddress: model.accountAddress
|
//token.accountAddress: model.accountAddress
|
||||||
//token.burnState: model.burnState
|
|
||||||
//token.remotelyDestructState: model.remotelyDestructState
|
//token.remotelyDestructState: model.remotelyDestructState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue