From 05eb8abf047b947ef30b4b2cd2913113035c6a01 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 1 Dec 2021 16:07:08 -0500 Subject: [PATCH] fix(stickers): fix getting installed and recent stickers --- .../service/settings/dto/settings.nim | 17 +++++++++-------- src/app_service/service/settings/service.nim | 10 +++++----- .../service/settings/service_interface.nim | 2 +- .../service/stickers/async_tasks.nim | 18 ------------------ src/app_service/service/stickers/service.nim | 4 ++-- 5 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/app_service/service/settings/dto/settings.nim b/src/app_service/service/settings/dto/settings.nim index 2fbfc1820c..a79f9e0d9c 100644 --- a/src/app_service/service/settings/dto/settings.nim +++ b/src/app_service/service/settings/dto/settings.nim @@ -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) diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index f8214943e0..1b1eb5e055 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -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 diff --git a/src/app_service/service/settings/service_interface.nim b/src/app_service/service/settings/service_interface.nim index 4aff2dbe95..03a3bec4ad 100644 --- a/src/app_service/service/settings/service_interface.nim +++ b/src/app_service/service/settings/service_interface.nim @@ -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.} = diff --git a/src/app_service/service/stickers/async_tasks.nim b/src/app_service/service/stickers/async_tasks.nim index edba908656..b06c53155a 100644 --- a/src/app_service/service/stickers/async_tasks.nim +++ b/src/app_service/service/stickers/async_tasks.nim @@ -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 diff --git a/src/app_service/service/stickers/service.nim b/src/app_service/service/stickers/service.nim index 69cdad2fb9..a6ec025fee 100644 --- a/src/app_service/service/stickers/service.nim +++ b/src/app_service/service/stickers/service.nim @@ -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)