diff --git a/src/app/modules/main/stickers/controller.nim b/src/app/modules/main/stickers/controller.nim index c54fa35b2e..9c1f933586 100644 --- a/src/app/modules/main/stickers/controller.nim +++ b/src/app/modules/main/stickers/controller.nim @@ -82,6 +82,9 @@ proc init*(self: Controller) = self.events.on(SIGNAL_ALL_STICKER_PACKS_LOADED) do(e: Args): self.delegate.allPacksLoaded() + self.events.on(SIGNAL_ALL_STICKER_PACKS_LOAD_FAILED) do(e: Args): + self.delegate.allPacksLoadFailed() + self.events.on(SIGNAL_STICKER_GAS_ESTIMATED) do(e: Args): let args = StickerGasEstimatedArgs(e) self.delegate.gasEstimateReturned(args.estimate, args.uuid) diff --git a/src/app/modules/main/stickers/io_interface.nim b/src/app/modules/main/stickers/io_interface.nim index 0546f24311..7f3cd5ed9e 100644 --- a/src/app/modules/main/stickers/io_interface.nim +++ b/src/app/modules/main/stickers/io_interface.nim @@ -40,6 +40,9 @@ method getNumInstalledStickerPacks*(self: AccessInterface): int {.base.} = method allPacksLoaded*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method allPacksLoadFailed*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + method estimate*(self: AccessInterface, packId: string, address: string, price: string, uuid: string) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/stickers/module.nim b/src/app/modules/main/stickers/module.nim index 18b1762182..40e0c14a76 100644 --- a/src/app/modules/main/stickers/module.nim +++ b/src/app/modules/main/stickers/module.nim @@ -158,6 +158,9 @@ method clearStickerPacks*(self: Module) = method allPacksLoaded*(self: Module) = self.view.allPacksLoaded() +method allPacksLoadFailed*(self: Module) = + self.view.allPacksLoadFailed() + method populateInstalledStickerPacks*(self: Module, stickers: Table[string, StickerPackDto]) = var stickerPackItems: seq[PackItem] = @[] for stickerPack in stickers.values: diff --git a/src/app/modules/main/stickers/view.nim b/src/app/modules/main/stickers/view.nim index 8ac77af0a3..b690982b0e 100644 --- a/src/app/modules/main/stickers/view.nim +++ b/src/app/modules/main/stickers/view.nim @@ -9,6 +9,7 @@ QtObject: View* = ref object of QObject delegate: io_interface.AccessInterface packsLoaded*: bool + packsLoadFailed*: bool stickerPacks*: StickerPackList recentStickers*: StickerList signingPhrase: string @@ -66,6 +67,8 @@ QtObject: proc stickerPacksLoaded*(self: View) {.signal.} + proc packsLoadFailedChanged*(self: View) {.signal.} + proc installedStickerPacksUpdated*(self: View) {.signal.} proc clearStickerPacks*(self: View) = @@ -110,9 +113,23 @@ QtObject: proc allPacksLoaded*(self: View) = self.packsLoaded = true + self.packsLoadFailed = false + self.stickerPacksLoaded() + self.packsLoadFailedChanged() self.installedStickerPacksUpdated() + proc allPacksLoadFailed*(self: View) = + self.packsLoadFailed = true + self.packsLoadFailedChanged() + + proc getPacksLoadFailed(self: View): bool {.slot.} = + self.packsLoadFailed + + QtProperty[bool] packsLoadFailed: + read = getPacksLoadFailed + notify = packsLoadFailedChanged + proc send*(self: View, channelId: string, hash: string, replyTo: string, pack: string, url: string) {.slot.} = let sticker = initItem(hash, pack, url) self.addRecentStickerToList(sticker) diff --git a/src/app_service/service/stickers/async_tasks.nim b/src/app_service/service/stickers/async_tasks.nim index 3219cf3062..66ddf2387c 100644 --- a/src/app_service/service/stickers/async_tasks.nim +++ b/src/app_service/service/stickers/async_tasks.nim @@ -11,18 +11,18 @@ type chainId*: int running*: ByteAddress # pointer to threadpool's `.running` Atomic[bool] -proc getMarketStickerPacks*(running: var Atomic[bool], chainId: int): Table[string, StickerPackDto] = - result = initTable[string, StickerPackDto]() +proc getMarketStickerPacks*(running: var Atomic[bool], chainId: int): + tuple[stickers: Table[string, StickerPackDto], error: string] = + result = (initTable[string, StickerPackDto](), "") try: let marketResponse = status_stickers.market(chainId) if marketResponse.result.kind != JArray: return for currItem in marketResponse.result.items(): let stickerPack = currItem.toStickerPackDto() - result[stickerPack.id] = stickerPack + result.stickers[stickerPack.id] = stickerPack except RpcException: error "Error in getMarketStickerPacks", message = getCurrentExceptionMsg() - result = initTable[string, StickerPackDto]() - + result.error = getCurrentExceptionMsg() # The pragmas `{.gcsafe, nimcall.}` in this context do not force the compiler # to accept unsafe code, rather they work in conjunction with the proc @@ -45,8 +45,9 @@ const estimateTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const obtainMarketStickerPacksTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[ObtainMarketStickerPacksTaskArg](argEncoded) var running = cast[ptr Atomic[bool]](arg.running) - let marketStickerPacks = getMarketStickerPacks(running[], arg.chainId) + let (marketStickerPacks, error) = getMarketStickerPacks(running[], arg.chainId) var packs: seq[StickerPackDto] = @[] for packId, stickerPack in marketStickerPacks.pairs: packs.add(stickerPack) - arg.finish(%*(packs)) \ No newline at end of file + let tpl: tuple[packs: seq[StickerPackDto], error: string] = (packs, error) + arg.finish(tpl) diff --git a/src/app_service/service/stickers/service.nim b/src/app_service/service/stickers/service.nim index 4370b15ccd..a5dd17b423 100644 --- a/src/app_service/service/stickers/service.nim +++ b/src/app_service/service/stickers/service.nim @@ -54,8 +54,8 @@ type # Signals which may be emitted by this service: const SIGNAL_STICKER_PACK_LOADED* = "stickerPackLoaded" const SIGNAL_ALL_STICKER_PACKS_LOADED* = "allStickerPacksLoaded" +const SIGNAL_ALL_STICKER_PACKS_LOAD_FAILED* = "allStickerPacksLoadFailed" const SIGNAL_STICKER_GAS_ESTIMATED* = "stickerGasEstimated" -const SIGNAL_INSTALLED_STICKER_PACKS_LOADED* = "installedStickerPacksLoaded" const SIGNAL_STICKER_TRANSACTION_CONFIRMED* = "stickerTransactionConfirmed" const SIGNAL_STICKER_TRANSACTION_REVERTED* = "stickerTransactionReverted" @@ -245,8 +245,14 @@ QtObject: result = (response: $response, success: success) - proc setMarketStickerPacks*(self: Service, availableStickersJSON: string) {.slot.} = - let availableStickers = JSON.decode($availableStickersJSON, seq[StickerPackDto]) + proc setMarketStickerPacks*(self: Service, strickersJSON: string) {.slot.} = + let stickersResult = Json.decode(strickersJSON, tuple[packs: seq[StickerPackDto], error: string]) + + if stickersResult.error != "": + self.events.emit(SIGNAL_ALL_STICKER_PACKS_LOAD_FAILED, Args()) + return + + let availableStickers = stickersResult.packs for stickerPack in availableStickers: if self.marketStickerPacks.contains(stickerPack.id): continue @@ -259,7 +265,6 @@ QtObject: isPending: false )) - let chainId = self.networkService.getNetworkForStickers().chainId let pendingStickerPacksResponse = status_stickers.pending() for (packID, stickerPackJson) in pendingStickerPacksResponse.result.pairs():