mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-11 14:54:48 +00:00
chore(chat/stickers): propagate stickers loading failure
This commit is contained in:
parent
d5478babfb
commit
8b4d527651
@ -82,6 +82,9 @@ proc init*(self: Controller) =
|
|||||||
self.events.on(SIGNAL_ALL_STICKER_PACKS_LOADED) do(e: Args):
|
self.events.on(SIGNAL_ALL_STICKER_PACKS_LOADED) do(e: Args):
|
||||||
self.delegate.allPacksLoaded()
|
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):
|
self.events.on(SIGNAL_STICKER_GAS_ESTIMATED) do(e: Args):
|
||||||
let args = StickerGasEstimatedArgs(e)
|
let args = StickerGasEstimatedArgs(e)
|
||||||
self.delegate.gasEstimateReturned(args.estimate, args.uuid)
|
self.delegate.gasEstimateReturned(args.estimate, args.uuid)
|
||||||
|
@ -40,6 +40,9 @@ method getNumInstalledStickerPacks*(self: AccessInterface): int {.base.} =
|
|||||||
method allPacksLoaded*(self: AccessInterface) {.base.} =
|
method allPacksLoaded*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
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.} =
|
method estimate*(self: AccessInterface, packId: string, address: string, price: string, uuid: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
@ -158,6 +158,9 @@ method clearStickerPacks*(self: Module) =
|
|||||||
method allPacksLoaded*(self: Module) =
|
method allPacksLoaded*(self: Module) =
|
||||||
self.view.allPacksLoaded()
|
self.view.allPacksLoaded()
|
||||||
|
|
||||||
|
method allPacksLoadFailed*(self: Module) =
|
||||||
|
self.view.allPacksLoadFailed()
|
||||||
|
|
||||||
method populateInstalledStickerPacks*(self: Module, stickers: Table[string, StickerPackDto]) =
|
method populateInstalledStickerPacks*(self: Module, stickers: Table[string, StickerPackDto]) =
|
||||||
var stickerPackItems: seq[PackItem] = @[]
|
var stickerPackItems: seq[PackItem] = @[]
|
||||||
for stickerPack in stickers.values:
|
for stickerPack in stickers.values:
|
||||||
|
@ -9,6 +9,7 @@ QtObject:
|
|||||||
View* = ref object of QObject
|
View* = ref object of QObject
|
||||||
delegate: io_interface.AccessInterface
|
delegate: io_interface.AccessInterface
|
||||||
packsLoaded*: bool
|
packsLoaded*: bool
|
||||||
|
packsLoadFailed*: bool
|
||||||
stickerPacks*: StickerPackList
|
stickerPacks*: StickerPackList
|
||||||
recentStickers*: StickerList
|
recentStickers*: StickerList
|
||||||
signingPhrase: string
|
signingPhrase: string
|
||||||
@ -66,6 +67,8 @@ QtObject:
|
|||||||
|
|
||||||
proc stickerPacksLoaded*(self: View) {.signal.}
|
proc stickerPacksLoaded*(self: View) {.signal.}
|
||||||
|
|
||||||
|
proc packsLoadFailedChanged*(self: View) {.signal.}
|
||||||
|
|
||||||
proc installedStickerPacksUpdated*(self: View) {.signal.}
|
proc installedStickerPacksUpdated*(self: View) {.signal.}
|
||||||
|
|
||||||
proc clearStickerPacks*(self: View) =
|
proc clearStickerPacks*(self: View) =
|
||||||
@ -110,9 +113,23 @@ QtObject:
|
|||||||
|
|
||||||
proc allPacksLoaded*(self: View) =
|
proc allPacksLoaded*(self: View) =
|
||||||
self.packsLoaded = true
|
self.packsLoaded = true
|
||||||
|
self.packsLoadFailed = false
|
||||||
|
|
||||||
self.stickerPacksLoaded()
|
self.stickerPacksLoaded()
|
||||||
|
self.packsLoadFailedChanged()
|
||||||
self.installedStickerPacksUpdated()
|
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.} =
|
proc send*(self: View, channelId: string, hash: string, replyTo: string, pack: string, url: string) {.slot.} =
|
||||||
let sticker = initItem(hash, pack, url)
|
let sticker = initItem(hash, pack, url)
|
||||||
self.addRecentStickerToList(sticker)
|
self.addRecentStickerToList(sticker)
|
||||||
|
@ -11,18 +11,18 @@ type
|
|||||||
chainId*: int
|
chainId*: int
|
||||||
running*: ByteAddress # pointer to threadpool's `.running` Atomic[bool]
|
running*: ByteAddress # pointer to threadpool's `.running` Atomic[bool]
|
||||||
|
|
||||||
proc getMarketStickerPacks*(running: var Atomic[bool], chainId: int): Table[string, StickerPackDto] =
|
proc getMarketStickerPacks*(running: var Atomic[bool], chainId: int):
|
||||||
result = initTable[string, StickerPackDto]()
|
tuple[stickers: Table[string, StickerPackDto], error: string] =
|
||||||
|
result = (initTable[string, StickerPackDto](), "")
|
||||||
try:
|
try:
|
||||||
let marketResponse = status_stickers.market(chainId)
|
let marketResponse = status_stickers.market(chainId)
|
||||||
if marketResponse.result.kind != JArray: return
|
if marketResponse.result.kind != JArray: return
|
||||||
for currItem in marketResponse.result.items():
|
for currItem in marketResponse.result.items():
|
||||||
let stickerPack = currItem.toStickerPackDto()
|
let stickerPack = currItem.toStickerPackDto()
|
||||||
result[stickerPack.id] = stickerPack
|
result.stickers[stickerPack.id] = stickerPack
|
||||||
except RpcException:
|
except RpcException:
|
||||||
error "Error in getMarketStickerPacks", message = getCurrentExceptionMsg()
|
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
|
# The pragmas `{.gcsafe, nimcall.}` in this context do not force the compiler
|
||||||
# to accept unsafe code, rather they work in conjunction with the proc
|
# 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.} =
|
const obtainMarketStickerPacksTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||||
let arg = decode[ObtainMarketStickerPacksTaskArg](argEncoded)
|
let arg = decode[ObtainMarketStickerPacksTaskArg](argEncoded)
|
||||||
var running = cast[ptr Atomic[bool]](arg.running)
|
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] = @[]
|
var packs: seq[StickerPackDto] = @[]
|
||||||
for packId, stickerPack in marketStickerPacks.pairs:
|
for packId, stickerPack in marketStickerPacks.pairs:
|
||||||
packs.add(stickerPack)
|
packs.add(stickerPack)
|
||||||
arg.finish(%*(packs))
|
let tpl: tuple[packs: seq[StickerPackDto], error: string] = (packs, error)
|
||||||
|
arg.finish(tpl)
|
||||||
|
@ -54,8 +54,8 @@ type
|
|||||||
# Signals which may be emitted by this service:
|
# Signals which may be emitted by this service:
|
||||||
const SIGNAL_STICKER_PACK_LOADED* = "stickerPackLoaded"
|
const SIGNAL_STICKER_PACK_LOADED* = "stickerPackLoaded"
|
||||||
const SIGNAL_ALL_STICKER_PACKS_LOADED* = "allStickerPacksLoaded"
|
const SIGNAL_ALL_STICKER_PACKS_LOADED* = "allStickerPacksLoaded"
|
||||||
|
const SIGNAL_ALL_STICKER_PACKS_LOAD_FAILED* = "allStickerPacksLoadFailed"
|
||||||
const SIGNAL_STICKER_GAS_ESTIMATED* = "stickerGasEstimated"
|
const SIGNAL_STICKER_GAS_ESTIMATED* = "stickerGasEstimated"
|
||||||
const SIGNAL_INSTALLED_STICKER_PACKS_LOADED* = "installedStickerPacksLoaded"
|
|
||||||
const SIGNAL_STICKER_TRANSACTION_CONFIRMED* = "stickerTransactionConfirmed"
|
const SIGNAL_STICKER_TRANSACTION_CONFIRMED* = "stickerTransactionConfirmed"
|
||||||
const SIGNAL_STICKER_TRANSACTION_REVERTED* = "stickerTransactionReverted"
|
const SIGNAL_STICKER_TRANSACTION_REVERTED* = "stickerTransactionReverted"
|
||||||
|
|
||||||
@ -245,8 +245,14 @@ QtObject:
|
|||||||
|
|
||||||
result = (response: $response, success: success)
|
result = (response: $response, success: success)
|
||||||
|
|
||||||
proc setMarketStickerPacks*(self: Service, availableStickersJSON: string) {.slot.} =
|
proc setMarketStickerPacks*(self: Service, strickersJSON: string) {.slot.} =
|
||||||
let availableStickers = JSON.decode($availableStickersJSON, seq[StickerPackDto])
|
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:
|
for stickerPack in availableStickers:
|
||||||
if self.marketStickerPacks.contains(stickerPack.id): continue
|
if self.marketStickerPacks.contains(stickerPack.id): continue
|
||||||
@ -259,7 +265,6 @@ QtObject:
|
|||||||
isPending: false
|
isPending: false
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
let chainId = self.networkService.getNetworkForStickers().chainId
|
let chainId = self.networkService.getNetworkForStickers().chainId
|
||||||
let pendingStickerPacksResponse = status_stickers.pending()
|
let pendingStickerPacksResponse = status_stickers.pending()
|
||||||
for (packID, stickerPackJson) in pendingStickerPacksResponse.result.pairs():
|
for (packID, stickerPackJson) in pendingStickerPacksResponse.result.pairs():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user