fix(stickers): fix getting installed and recent stickers
This commit is contained in:
parent
206e0e5504
commit
05eb8abf04
|
@ -1,4 +1,4 @@
|
|||
import json, options, tables, strutils
|
||||
import json, options, tables, strutils, sequtils
|
||||
import ../../stickers/dto/stickers
|
||||
|
||||
include ../../../common/json_utils
|
||||
|
@ -99,7 +99,7 @@ type
|
|||
walletVisibleTokens*: WalletVisibleTokens
|
||||
nodeConfig*: JsonNode
|
||||
wakuBloomFilterMode*: bool
|
||||
recentStickers*: seq[StickerDto]
|
||||
recentStickerHashes*: seq[string]
|
||||
installedStickerPacks*: Table[int, StickerPackDto]
|
||||
|
||||
proc toUpstreamConfig*(jsonObj: JsonNode): UpstreamConfig =
|
||||
|
@ -151,12 +151,6 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
|
|||
for networkObj in networksArr:
|
||||
result.availableNetworks.add(toNetwork(networkObj))
|
||||
|
||||
var recentStickersArr: JsonNode
|
||||
if(jsonObj.getProp(KEY_RECENT_STICKERS, recentStickersArr)):
|
||||
if(recentStickersArr.kind == JArray):
|
||||
for recentStickerObj in recentStickersArr:
|
||||
result.recentStickers.add(recentStickerObj.toStickerDto)
|
||||
|
||||
var installedStickerPacksArr: JsonNode
|
||||
if(jsonObj.getProp(KEY_INSTALLED_STICKER_PACKS, installedStickerPacksArr)):
|
||||
if(installedStickerPacksArr.kind == JObject):
|
||||
|
@ -165,6 +159,13 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
|
|||
let packId = parseInt(i)
|
||||
result.installedStickerPacks[packId] = installedStickerPacksArr[i].toStickerPackDto
|
||||
|
||||
|
||||
var recentStickersArr: JsonNode
|
||||
if(jsonObj.getProp(KEY_RECENT_STICKERS, recentStickersArr)):
|
||||
if(recentStickersArr.kind == JArray):
|
||||
for stickerHash in recentStickersArr:
|
||||
result.recentStickerHashes.add(stickerHash.getStr)
|
||||
|
||||
discard jsonObj.getProp(KEY_DAPPS_ADDRESS, result.dappsAddress)
|
||||
discard jsonObj.getProp(KEY_EIP1581_ADDRESS, result.eip1581Address)
|
||||
discard jsonObj.getProp(KEY_INSTALLATION_ID, result.installationId)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import chronicles, json, sequtils, tables
|
||||
import chronicles, json, sequtils, tables, sugar
|
||||
|
||||
import service_interface, ./dto/settings
|
||||
import status/statusgo_backend_new/settings as status_go
|
||||
|
@ -357,12 +357,12 @@ method isEIP1559Enabled*(self: Service, blockNumber: int): bool =
|
|||
method isEIP1559Enabled*(self: Service): bool =
|
||||
result = self.eip1559Enabled
|
||||
|
||||
method getRecentStickers*(self: Service): seq[StickerDto] =
|
||||
result = self.settings.recentStickers
|
||||
method getRecentStickers*(self: Service): seq[string] =
|
||||
result = self.settings.recentStickerHashes
|
||||
|
||||
method saveRecentStickers*(self: Service, recentStickers: seq[StickerDto]): bool =
|
||||
if(self.saveSetting(KEY_RECENT_STICKERS, %(recentStickers.mapIt($it.hash)))):
|
||||
self.settings.recentStickers = recentStickers
|
||||
self.settings.recentStickerHashes = recentStickers.map(s => s.hash)
|
||||
return true
|
||||
return false
|
||||
|
||||
|
@ -374,7 +374,7 @@ method saveRecentStickers*(self: Service, installedStickerPacks: Table[int, Stic
|
|||
for packId, pack in installedStickerPacks.pairs:
|
||||
json[$packId] = %(pack)
|
||||
|
||||
if(self.saveSetting(KEY_INSTALLED_STICKER_PACKS, $json)):
|
||||
if(self.saveSetting(KEY_INSTALLED_STICKER_PACKS, json)):
|
||||
self.settings.installedStickerPacks = installedStickerPacks
|
||||
return true
|
||||
return false
|
||||
|
|
|
@ -213,7 +213,7 @@ method isEIP1559Enabled*(self: ServiceInterface, blockNumber: int): bool {.base.
|
|||
method isEIP1559Enabled*(self: ServiceInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getRecentStickers*(self: ServiceInterface): seq[StickerDto] {.base.} =
|
||||
method getRecentStickers*(self: ServiceInterface): seq[string] {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method saveRecentStickers*(self: ServiceInterface, recentStickers: seq[StickerDto]): bool {.base.} =
|
||||
|
|
|
@ -1,28 +1,10 @@
|
|||
include ../../common/json_utils
|
||||
include ../../../app/core/tasks/common
|
||||
|
||||
# type
|
||||
# EstimateTaskArg = ref object of QObjectTaskArg
|
||||
# packId: int
|
||||
# address: string
|
||||
# price: string
|
||||
# uuid: string
|
||||
# ObtainAvailableStickerPacksTaskArg = ref object of QObjectTaskArg
|
||||
# running*: ByteAddress # pointer to threadpool's `.running` Atomic[bool]
|
||||
# contract*: ContractDto
|
||||
|
||||
type
|
||||
# EstimateTaskArg = ref object of QObjectTaskArg
|
||||
# packId: int
|
||||
# address: string
|
||||
# price: string
|
||||
# uuid: string
|
||||
EstimateTaskArg = ref object of QObjectTaskArg
|
||||
data: JsonNode
|
||||
uuid: string
|
||||
# tx: TransactionDataDto
|
||||
# approveAndCall: ApproveAndCall[100]
|
||||
# sntContract: Erc20ContractDto
|
||||
ObtainAvailableStickerPacksTaskArg = ref object of QObjectTaskArg
|
||||
running*: ByteAddress # pointer to threadpool's `.running` Atomic[bool]
|
||||
contract*: ContractDto
|
||||
|
|
|
@ -345,11 +345,11 @@ QtObject:
|
|||
var stickers = newSeq[StickerDto]()
|
||||
for hash in recentStickers:
|
||||
# pack id is not returned from status-go settings, populate here
|
||||
let packId = getPackIdForSticker(installedStickers, $hash)
|
||||
let packId = getPackIdForSticker(installedStickers, hash)
|
||||
# .insert instead of .add to effectively reverse the order stickers because
|
||||
# stickers are re-reversed when added to the view due to the nature of
|
||||
# inserting recent stickers at the front of the list
|
||||
stickers.insert(StickerDto(hash: $hash, packId: packId), 0)
|
||||
stickers.insert(StickerDto(hash: hash, packId: packId), 0)
|
||||
|
||||
for sticker in stickers:
|
||||
self.addStickerToRecent(sticker)
|
||||
|
|
Loading…
Reference in New Issue