fix(stickers): fix getting installed and recent stickers

This commit is contained in:
Jonathan Rainville 2021-12-01 16:07:08 -05:00 committed by Sale Djenic
parent 206e0e5504
commit 05eb8abf04
5 changed files with 17 additions and 34 deletions

View File

@ -1,4 +1,4 @@
import json, options, tables, strutils import json, options, tables, strutils, sequtils
import ../../stickers/dto/stickers import ../../stickers/dto/stickers
include ../../../common/json_utils include ../../../common/json_utils
@ -99,7 +99,7 @@ type
walletVisibleTokens*: WalletVisibleTokens walletVisibleTokens*: WalletVisibleTokens
nodeConfig*: JsonNode nodeConfig*: JsonNode
wakuBloomFilterMode*: bool wakuBloomFilterMode*: bool
recentStickers*: seq[StickerDto] recentStickerHashes*: seq[string]
installedStickerPacks*: Table[int, StickerPackDto] installedStickerPacks*: Table[int, StickerPackDto]
proc toUpstreamConfig*(jsonObj: JsonNode): UpstreamConfig = proc toUpstreamConfig*(jsonObj: JsonNode): UpstreamConfig =
@ -151,12 +151,6 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
for networkObj in networksArr: for networkObj in networksArr:
result.availableNetworks.add(toNetwork(networkObj)) 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 var installedStickerPacksArr: JsonNode
if(jsonObj.getProp(KEY_INSTALLED_STICKER_PACKS, installedStickerPacksArr)): if(jsonObj.getProp(KEY_INSTALLED_STICKER_PACKS, installedStickerPacksArr)):
if(installedStickerPacksArr.kind == JObject): if(installedStickerPacksArr.kind == JObject):
@ -165,6 +159,13 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
let packId = parseInt(i) let packId = parseInt(i)
result.installedStickerPacks[packId] = installedStickerPacksArr[i].toStickerPackDto 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_DAPPS_ADDRESS, result.dappsAddress)
discard jsonObj.getProp(KEY_EIP1581_ADDRESS, result.eip1581Address) discard jsonObj.getProp(KEY_EIP1581_ADDRESS, result.eip1581Address)
discard jsonObj.getProp(KEY_INSTALLATION_ID, result.installationId) discard jsonObj.getProp(KEY_INSTALLATION_ID, result.installationId)

View File

@ -1,4 +1,4 @@
import chronicles, json, sequtils, tables import chronicles, json, sequtils, tables, sugar
import service_interface, ./dto/settings import service_interface, ./dto/settings
import status/statusgo_backend_new/settings as status_go 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 = method isEIP1559Enabled*(self: Service): bool =
result = self.eip1559Enabled result = self.eip1559Enabled
method getRecentStickers*(self: Service): seq[StickerDto] = method getRecentStickers*(self: Service): seq[string] =
result = self.settings.recentStickers result = self.settings.recentStickerHashes
method saveRecentStickers*(self: Service, recentStickers: seq[StickerDto]): bool = method saveRecentStickers*(self: Service, recentStickers: seq[StickerDto]): bool =
if(self.saveSetting(KEY_RECENT_STICKERS, %(recentStickers.mapIt($it.hash)))): 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 true
return false return false
@ -374,7 +374,7 @@ method saveRecentStickers*(self: Service, installedStickerPacks: Table[int, Stic
for packId, pack in installedStickerPacks.pairs: for packId, pack in installedStickerPacks.pairs:
json[$packId] = %(pack) json[$packId] = %(pack)
if(self.saveSetting(KEY_INSTALLED_STICKER_PACKS, $json)): if(self.saveSetting(KEY_INSTALLED_STICKER_PACKS, json)):
self.settings.installedStickerPacks = installedStickerPacks self.settings.installedStickerPacks = installedStickerPacks
return true return true
return false return false

View File

@ -213,7 +213,7 @@ method isEIP1559Enabled*(self: ServiceInterface, blockNumber: int): bool {.base.
method isEIP1559Enabled*(self: ServiceInterface): bool {.base.} = method isEIP1559Enabled*(self: ServiceInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") 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") raise newException(ValueError, "No implementation available")
method saveRecentStickers*(self: ServiceInterface, recentStickers: seq[StickerDto]): bool {.base.} = method saveRecentStickers*(self: ServiceInterface, recentStickers: seq[StickerDto]): bool {.base.} =

View File

@ -1,28 +1,10 @@
include ../../common/json_utils include ../../common/json_utils
include ../../../app/core/tasks/common 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 type
# EstimateTaskArg = ref object of QObjectTaskArg
# packId: int
# address: string
# price: string
# uuid: string
EstimateTaskArg = ref object of QObjectTaskArg EstimateTaskArg = ref object of QObjectTaskArg
data: JsonNode data: JsonNode
uuid: string uuid: string
# tx: TransactionDataDto
# approveAndCall: ApproveAndCall[100]
# sntContract: Erc20ContractDto
ObtainAvailableStickerPacksTaskArg = ref object of QObjectTaskArg ObtainAvailableStickerPacksTaskArg = ref object of QObjectTaskArg
running*: ByteAddress # pointer to threadpool's `.running` Atomic[bool] running*: ByteAddress # pointer to threadpool's `.running` Atomic[bool]
contract*: ContractDto contract*: ContractDto

View File

@ -345,11 +345,11 @@ QtObject:
var stickers = newSeq[StickerDto]() var stickers = newSeq[StickerDto]()
for hash in recentStickers: for hash in recentStickers:
# pack id is not returned from status-go settings, populate here # 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 # .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 # stickers are re-reversed when added to the view due to the nature of
# inserting recent stickers at the front of the list # 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: for sticker in stickers:
self.addStickerToRecent(sticker) self.addStickerToRecent(sticker)