fix(@desktop/communities): Update UI when receiving information about token actions made by other owner/tokenmaster

Fix #13371
This commit is contained in:
Michal Iskierko 2024-05-28 11:50:33 +02:00 committed by Michał Iskierko
parent 862a1400d1
commit d0b82bc8dc
6 changed files with 58 additions and 2 deletions

View File

@ -1,9 +1,11 @@
import json, tables
import json, tables, chronicles
import base
import ../../../../app_service/service/community/dto/[community]
import ../../../../app_service/service/community_tokens/dto/community_token
import ../../../../app_service/service/chat/dto/[chat]
from ../../../../app_service/common/conversion import intToEnum
import signal_type
include app_service/common/json_utils
@ -85,6 +87,17 @@ type CommunityTokenTransactionStatusChangedSignal* = ref object of Signal
masterToken*: CommunityTokenDto
errorString*: string
type
CommunityTokenActionType* {.pure.} = enum
Unknown = 0,
Airdrop,
Burn,
RemoteDestruct,
type CommunityTokenActionSignal* = ref object of Signal
communityToken*: CommunityTokenDto
actionType*: CommunityTokenActionType
proc fromEvent*(T: type CommunitySignal, event: JsonNode): CommunitySignal =
result = CommunitySignal()
result.signalType = SignalType.CommunityFound
@ -272,4 +285,15 @@ proc fromEvent*(T: type CommunityTokenTransactionStatusChangedSignal, event: Jso
if event["event"].hasKey("masterToken"):
result.masterToken = toCommunityTokenDto(event["event"]{"masterToken"})
result.errorString = event["event"]{"errorString"}.getStr()
result.signalType = SignalType.CommunityTokenTransactionStatusChanged
result.signalType = SignalType.CommunityTokenTransactionStatusChanged
proc fromEvent*(T: type CommunityTokenActionSignal, event: JsonNode): CommunityTokenActionSignal =
result = CommunityTokenActionSignal()
result.actionType = CommunityTokenActionType.Unknown
if event["event"].hasKey("communityToken"):
result.communityToken = toCommunityTokenDto(event["event"]{"communityToken"})
try:
result.actionType = intToEnum[CommunityTokenActionType](event["event"]{"actionType"}.getInt())
except Exception as e:
error "CommunityTokenActionSignal: can't read actionType:", error=e.msg
result.signalType = SignalType.CommunityTokenAction

View File

@ -62,6 +62,7 @@ type SignalType* {.pure.} = enum
DBReEncryptionStarted = "db.reEncryption.started"
DBReEncryptionFinished = "db.reEncryption.finished"
CommunityTokenTransactionStatusChanged = "communityToken.communityTokenTransactionStatusChanged"
CommunityTokenAction = "communityToken.communityTokenAction"
Unknown
proc event*(self:SignalType):string =

View File

@ -131,6 +131,7 @@ QtObject:
# pairing
of SignalType.LocalPairing: LocalPairingSignal.fromEvent(jsonSignal)
of SignalType.CommunityTokenTransactionStatusChanged: CommunityTokenTransactionStatusChangedSignal.fromEvent(jsonSignal)
of SignalType.CommunityTokenAction: CommunityTokenActionSignal.fromEvent(jsonSignal)
else: Signal()
result.signalType = signalType

View File

@ -355,6 +355,14 @@ proc init*(self: Controller) =
self.getRemoteDestructedAmount(communityToken.chainId, communityToken.address))
self.delegate.onBurnStateChanged(communityToken.communityId, communityToken.chainId, communityToken.address, args.status)
self.events.on(SIGNAL_BURN_ACTION_RECEIVED) do(e: Args):
let args = RemoteDestructArgs(e)
let communityToken = args.communityToken
self.delegate.onCommunityTokenSupplyChanged(communityToken.communityId, communityToken.chainId,
communityToken.address, communityToken.supply,
self.getRemainingSupply(communityToken.chainId, communityToken.address),
self.getRemoteDestructedAmount(communityToken.chainId, communityToken.address))
self.events.on(SIGNAL_FINALISE_OWNERSHIP_STATUS) do(e: Args):
let args = FinaliseOwnershipStatusArgs(e)
self.delegate.onFinaliseOwnershipStatusChanged(args.isPending, args.communityId)

View File

@ -87,3 +87,5 @@ proc wei2Gwei*(input: string): string =
proc intToEnum*[T](intVal: int, defaultVal: T): T =
result = if (intVal >= ord(low(T)) and intVal <= ord(high(T))): T(intVal) else: defaultVal
proc intToEnum*[T](intVal: int): T =
result = if (intVal >= ord(low(T)) and intVal <= ord(high(T))): T(intVal) else: raise newException(ValueError, "Can't convert int to enum")

View File

@ -261,6 +261,7 @@ const SIGNAL_COMPUTE_AIRDROP_FEE* = "communityTokens-computeAirdropFee"
const SIGNAL_COMMUNITY_TOKEN_OWNERS_FETCHED* = "communityTokens-communityTokenOwnersFetched"
const SIGNAL_REMOTE_DESTRUCT_STATUS* = "communityTokens-communityTokenRemoteDestructStatus"
const SIGNAL_BURN_STATUS* = "communityTokens-communityTokenBurnStatus"
const SIGNAL_BURN_ACTION_RECEIVED* = "communityTokens-communityTokenBurnActionReceived"
const SIGNAL_AIRDROP_STATUS* = "communityTokens-airdropStatus"
const SIGNAL_REMOVE_COMMUNITY_TOKEN_FAILED* = "communityTokens-removeCommunityTokenFailed"
const SIGNAL_COMMUNITY_TOKEN_REMOVED* = "communityTokens-communityTokenRemoved"
@ -570,6 +571,21 @@ QtObject:
except Exception as e:
error "Error processing owner token deployment pending transaction event", msg=e.msg
proc processCommunityTokenAction(self: Service, signalArgs: CommunityTokenActionSignal) =
case signalArgs.actionType
of CommunityTokenActionType.Airdrop:
self.tempTokenOwnersToFetch = signalArgs.communityToken
self.tokenOwners1SecTimer.start()
of CommunityTokenActionType.Burn:
self.updateCommunityTokenCache(signalArgs.communityToken.chainId, signalArgs.communityToken.address, signalArgs.communityToken)
let data = RemoteDestructArgs(communityToken: signalArgs.communityToken)
self.events.emit(SIGNAL_BURN_ACTION_RECEIVED, data)
of CommunityTokenActionType.RemoteDestruct:
self.tempTokenOwnersToFetch = signalArgs.communityToken
self.tokenOwners1SecTimer.start()
else:
warn "Unknown token action", actionType=signalArgs.actionType
proc tryFetchOwners(self: Service) =
# both communities and tokens should be loaded
if self.allCommunityTokensLoaded and self.communityDataLoaded:
@ -590,6 +606,10 @@ QtObject:
self.communityDataLoaded = true
self.tryFetchOwners()
self.events.on(SignalType.CommunityTokenAction.event) do(e:Args):
let receivedData = CommunityTokenActionSignal(e)
self.processCommunityTokenAction(receivedData)
self.events.on(SignalType.CommunityTokenTransactionStatusChanged.event) do(e: Args):
let receivedData = CommunityTokenTransactionStatusChangedSignal(e)
if receivedData.errorString != "":