fix(stickers): fix crash in async task + clean up + set bought status
Fixes #12664
This commit is contained in:
parent
3b06ae5893
commit
cf74fc2111
|
@ -122,8 +122,11 @@ QtObject:
|
||||||
self.packs.apply(proc(it: var StickerPackView) =
|
self.packs.apply(proc(it: var StickerPackView) =
|
||||||
if it.pack.id == packId:
|
if it.pack.id == packId:
|
||||||
it.installed = installed
|
it.installed = installed
|
||||||
|
if installed:
|
||||||
|
it.bought = true
|
||||||
it.pending = pending)
|
it.pending = pending)
|
||||||
self.dataChanged(index, index, @[StickerPackRoles.Installed.int, StickerPackRoles.Pending.int])
|
self.dataChanged(index, index, @[StickerPackRoles.Installed.int, StickerPackRoles.Bought.int,
|
||||||
|
StickerPackRoles.Pending.int])
|
||||||
|
|
||||||
proc getStickers*(self: StickerPackList): QVariant {.slot.} =
|
proc getStickers*(self: StickerPackList): QVariant {.slot.} =
|
||||||
let packInfo = self.packs[self.packIdToRetrieve]
|
let packInfo = self.packs[self.packIdToRetrieve]
|
||||||
|
|
|
@ -120,7 +120,8 @@ method onUserAuthenticated*(self: Module, password: string) =
|
||||||
self.tmpBuyStickersTransactionDetails.eip1559Enabled
|
self.tmpBuyStickersTransactionDetails.eip1559Enabled
|
||||||
)
|
)
|
||||||
if response.error.isEmptyOrWhitespace():
|
if response.error.isEmptyOrWhitespace():
|
||||||
self.view.stickerPacks.updateStickerPackInList(self.tmpBuyStickersTransactionDetails.packId, false, true)
|
self.view.stickerPacks.updateStickerPackInList(self.tmpBuyStickersTransactionDetails.packId, installed = false,
|
||||||
|
pending = true)
|
||||||
self.view.transactionWasSent(chainId = response.chainId, txHash = response.txHash, error = response.error)
|
self.view.transactionWasSent(chainId = response.chainId, txHash = response.txHash, error = response.error)
|
||||||
|
|
||||||
method obtainMarketStickerPacks*(self: Module) =
|
method obtainMarketStickerPacks*(self: Module) =
|
||||||
|
@ -250,10 +251,10 @@ method getChainIdForStickers*(self: Module): int =
|
||||||
return self.controller.getChainIdForStickers()
|
return self.controller.getChainIdForStickers()
|
||||||
|
|
||||||
method stickerTransactionConfirmed*(self: Module, trxType: string, packID: string, transactionHash: string) =
|
method stickerTransactionConfirmed*(self: Module, trxType: string, packID: string, transactionHash: string) =
|
||||||
self.view.stickerPacks.updateStickerPackInList(packID, true, false)
|
self.view.stickerPacks.updateStickerPackInList(packID, installed = true, pending = false)
|
||||||
self.controller.installStickerPack(packID)
|
self.controller.installStickerPack(packID)
|
||||||
self.view.emitTransactionCompletedSignal(true, transactionHash, packID, trxType)
|
self.view.emitTransactionCompletedSignal(true, transactionHash, packID, trxType)
|
||||||
|
|
||||||
method stickerTransactionReverted*(self: Module, trxType: string, packID: string, transactionHash: string) =
|
method stickerTransactionReverted*(self: Module, trxType: string, packID: string, transactionHash: string) =
|
||||||
self.view.stickerPacks.updateStickerPackInList(packID, false, false)
|
self.view.stickerPacks.updateStickerPackInList(packID, installed = false, pending = false)
|
||||||
self.view.emitTransactionCompletedSignal(false, transactionHash, packID, trxType)
|
self.view.emitTransactionCompletedSignal(false, transactionHash, packID, trxType)
|
||||||
|
|
|
@ -7,12 +7,13 @@ type
|
||||||
packId*: string
|
packId*: string
|
||||||
fromAddress*: string
|
fromAddress*: string
|
||||||
uuid*: string
|
uuid*: string
|
||||||
|
|
||||||
ObtainMarketStickerPacksTaskArg = ref object of QObjectTaskArg
|
ObtainMarketStickerPacksTaskArg = ref object of QObjectTaskArg
|
||||||
chainId*: int
|
chainId*: int
|
||||||
InstallStickerPackTaskArg = ref object of QObjectTaskArg
|
InstallStickerPackTaskArg = ref object of QObjectTaskArg
|
||||||
packId*: string
|
packId*: string
|
||||||
chainId*: int
|
chainId*: int
|
||||||
hasKey*: bool
|
|
||||||
AsyncGetRecentStickersTaskArg* = ref object of QObjectTaskArg
|
AsyncGetRecentStickersTaskArg* = ref object of QObjectTaskArg
|
||||||
AsyncGetInstalledStickerPacksTaskArg* = ref object of QObjectTaskArg
|
AsyncGetInstalledStickerPacksTaskArg* = ref object of QObjectTaskArg
|
||||||
|
|
||||||
|
@ -68,9 +69,7 @@ const obtainMarketStickerPacksTask: Task = proc(argEncoded: string) {.gcsafe, ni
|
||||||
|
|
||||||
const installStickerPackTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
const installStickerPackTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||||
let arg = decode[InstallStickerPackTaskArg](argEncoded)
|
let arg = decode[InstallStickerPackTaskArg](argEncoded)
|
||||||
if not arg.hasKey:
|
|
||||||
arg.finish(false)
|
|
||||||
return
|
|
||||||
var installed = false
|
var installed = false
|
||||||
try:
|
try:
|
||||||
let installResponse = status_stickers.install(arg.chainId, arg.packId)
|
let installResponse = status_stickers.install(arg.chainId, arg.packId)
|
||||||
|
|
|
@ -174,10 +174,6 @@ QtObject:
|
||||||
error "Error reverting sticker transaction", message = getCurrentExceptionMsg()
|
error "Error reverting sticker transaction", message = getCurrentExceptionMsg()
|
||||||
|
|
||||||
proc init*(self: Service) =
|
proc init*(self: Service) =
|
||||||
# TODO redo the connect check when the network is refactored
|
|
||||||
# if self.status.network.isConnected:
|
|
||||||
self.obtainMarketStickerPacks() # TODO: rename this to obtain sticker market items
|
|
||||||
|
|
||||||
self.events.on(PendingTransactionTypeDto.BuyStickerPack.event) do(e: Args):
|
self.events.on(PendingTransactionTypeDto.BuyStickerPack.event) do(e: Args):
|
||||||
var receivedData = TransactionMinedArgs(e)
|
var receivedData = TransactionMinedArgs(e)
|
||||||
if receivedData.success:
|
if receivedData.success:
|
||||||
|
@ -258,16 +254,16 @@ QtObject:
|
||||||
|
|
||||||
for stickerPack in availableStickers:
|
for stickerPack in availableStickers:
|
||||||
if self.marketStickerPacks.contains(stickerPack.id): continue
|
if self.marketStickerPacks.contains(stickerPack.id): continue
|
||||||
let isBought = stickerPack.status == StickerPackStatus.Purchased
|
|
||||||
self.marketStickerPacks[stickerPack.id] = stickerPack
|
self.marketStickerPacks[stickerPack.id] = stickerPack
|
||||||
self.events.emit(SIGNAL_STICKER_PACK_LOADED, StickerPackLoadedArgs(
|
self.events.emit(SIGNAL_STICKER_PACK_LOADED, StickerPackLoadedArgs(
|
||||||
stickerPack: stickerPack,
|
stickerPack: stickerPack,
|
||||||
isInstalled: false,
|
isInstalled: false,
|
||||||
isBought: isBought,
|
isBought: stickerPack.status == StickerPackStatus.Purchased,
|
||||||
isPending: false
|
isPending: false
|
||||||
))
|
))
|
||||||
|
|
||||||
let chainId = self.networkService.getNetworkForStickers().chainId
|
# TODO move this to be async
|
||||||
let pendingStickerPacksResponse = status_stickers.pending()
|
let pendingStickerPacksResponse = status_stickers.pending()
|
||||||
for (packID, stickerPackJson) in pendingStickerPacksResponse.result.pairs():
|
for (packID, stickerPackJson) in pendingStickerPacksResponse.result.pairs():
|
||||||
if self.marketStickerPacks.contains(packID): continue
|
if self.marketStickerPacks.contains(packID): continue
|
||||||
|
@ -379,7 +375,6 @@ QtObject:
|
||||||
error "error loading installed sticker packs", msg = error.message
|
error "error loading installed sticker packs", msg = error.message
|
||||||
return
|
return
|
||||||
|
|
||||||
var stickerPacks: Table[string, StickerPackDto] = initTable[string, StickerPackDto]()
|
|
||||||
for (packID, stickerPackJson) in rpcResponseObj{"result"}.pairs():
|
for (packID, stickerPackJson) in rpcResponseObj{"result"}.pairs():
|
||||||
self.installedStickerPacks[packID] = stickerPackJson.toStickerPackDto()
|
self.installedStickerPacks[packID] = stickerPackJson.toStickerPackDto()
|
||||||
self.events.emit(SIGNAL_LOAD_INSTALLED_STICKER_PACKS_DONE, StickerPacksArgs(packs: self.installedStickerPacks))
|
self.events.emit(SIGNAL_LOAD_INSTALLED_STICKER_PACKS_DONE, StickerPacksArgs(packs: self.installedStickerPacks))
|
||||||
|
@ -403,20 +398,23 @@ QtObject:
|
||||||
slot: "onStickerPackInstalled",
|
slot: "onStickerPackInstalled",
|
||||||
chainId: self.networkService.getNetworkForStickers().chainId,
|
chainId: self.networkService.getNetworkForStickers().chainId,
|
||||||
packId: packId,
|
packId: packId,
|
||||||
hasKey: self.marketStickerPacks.hasKey(packId)
|
|
||||||
)
|
)
|
||||||
self.threadpool.start(arg)
|
self.threadpool.start(arg)
|
||||||
|
|
||||||
proc onStickerPackInstalled*(self: Service, installedPackJson: string) {.slot.} =
|
proc onStickerPackInstalled*(self: Service, installedPackJson: string) {.slot.} =
|
||||||
let installedPack = Json.decode(installedPackJson, tuple[packId: string, installed: bool])
|
let installedPack = Json.decode(installedPackJson, tuple[packId: string, installed: bool])
|
||||||
if installedPack.installed:
|
if installedPack.installed:
|
||||||
|
if self.marketStickerPacks.hasKey(installedPack.packId):
|
||||||
|
self.marketStickerPacks[installedPack.packId].status = StickerPackStatus.Installed
|
||||||
self.events.emit(SIGNAL_STICKER_PACK_INSTALLED, StickerPackInstalledArgs(
|
self.events.emit(SIGNAL_STICKER_PACK_INSTALLED, StickerPackInstalledArgs(
|
||||||
packId: installedPack.packId
|
packId: installedPack.packId
|
||||||
))
|
))
|
||||||
|
else:
|
||||||
|
error "Sticker pack did not get installed", packId = installedPack.packId
|
||||||
|
|
||||||
proc uninstallStickerPack*(self: Service, packId: string) =
|
proc uninstallStickerPack*(self: Service, packId: string) =
|
||||||
try:
|
try:
|
||||||
let installedResponse = status_stickers.uninstall(packId)
|
discard status_stickers.uninstall(packId)
|
||||||
except RpcException:
|
except RpcException:
|
||||||
error "Error removing installed sticker", message = getCurrentExceptionMsg()
|
error "Error removing installed sticker", message = getCurrentExceptionMsg()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue