From 7c36e98cf3a9ea61a9910acfc9ab84cafd671039 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Mon, 22 Nov 2021 16:31:10 +0100 Subject: [PATCH] chore(general): necessary changes applied after rebasing --- src/app/boot/app_controller.nim | 23 +++++--------- .../signals/remote_signals/mailserver.nim | 23 +++++++++++++- .../signals/remote_signals/signal_type.nim | 1 + src/app/core/signals/signals_manager.nim | 1 + .../profile_section/profile/controller.nim | 2 +- src/app/profile/view.nim | 6 ---- src/app_service/service/token/async_tasks.nim | 2 +- src/app_service/service/token/service.nim | 30 ++++++++----------- 8 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index c5ac3baf7b..ca43afaf30 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -20,7 +20,6 @@ import ../../app_service/service/privacy/service as privacy_service import ../../app_service/service/provider/service as provider_service import ../../app_service/service/ens/service as ens_service -import ../core/local_account_settings import ../../app_service/service/profile/service as profile_service import ../../app_service/service/settings/service as settings_service import ../../app_service/service/about/service as about_service @@ -45,7 +44,6 @@ import ../wallet/v1/core as wallet import ../wallet/v2/core as walletV2 import ../node/core as node import ../utilsView/core as utilsView -import ../provider/core as provider import ../keycard/core as keycard import status/types/[account, setting] ################################################# @@ -118,7 +116,6 @@ type chat: ChatController node: NodeController utilsController: UtilsController - provider: Web3ProviderController keycard: KeycardController ################################################# @@ -145,7 +142,6 @@ proc connect(self: AppController) = self.profile.init(args.account) self.wallet.init() self.wallet2.init() - self.provider.init() self.chat.init() self.utilsController.init() self.node.init() @@ -236,7 +232,6 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController = result.chat = chat.newController(statusFoundation.status, statusFoundation, OPENURI) result.node = node.newController(statusFoundation) result.utilsController = utilsView.newController(statusFoundation.status, statusFoundation) - result.provider = provider.newController(statusFoundation.status) result.keycard = keycard.newController(statusFoundation.status) result.connect() ################################################# @@ -270,7 +265,6 @@ proc delete*(self: AppController) = self.chat.delete self.node.delete self.utilsController.delete - self.provider.delete self.keycard.delete ################################################# @@ -301,7 +295,6 @@ proc startupDidLoad*(self: AppController) = singletonInstance.engine.setRootContextProperty("chatsModel", self.chat.variant) singletonInstance.engine.setRootContextProperty("nodeModel", self.node.variant) singletonInstance.engine.setRootContextProperty("utilsModel", self.utilsController.variant) - singletonInstance.engine.setRootContextProperty("web3Provider", self.provider.variant) singletonInstance.engine.setRootContextProperty("keycardModel", self.keycard.variant) ################################################# @@ -329,14 +322,7 @@ proc start*(self: AppController) = self.startupModule.load() -proc load*(self: AppController) = - ################################################# - # Once SettingService gets added, `pubKey` should be fetched from there, instead the following line: - let pubKey = self.statusFoundation.status.settings.getSetting[:string](Setting.PublicKey, "0x0") - singletonInstance.localAccountSensitiveSettings.setFileName(pubKey) - singletonInstance.engine.setRootContextProperty("localAccountSensitiveSettings", self.localAccountSensitiveSettingsVariant) - ################################################# - +proc load(self: AppController) = self.settingService.init() self.contactsService.init() self.chatService.init() @@ -351,6 +337,13 @@ proc load*(self: AppController) = self.transactionService.init() self.languageService.init() + ################################################# + # Once SettingService gets added, `pubKey` should be fetched from there, instead the following line: + let pubKey = self.settingsService.getPubKey() + singletonInstance.localAccountSensitiveSettings.setFileName(pubKey) + singletonInstance.engine.setRootContextProperty("localAccountSensitiveSettings", self.localAccountSensitiveSettingsVariant) + ################################################# + # other global instances self.buildAndRegisterLocalAccountSensitiveSettings() self.buildAndRegisterUserProfile() diff --git a/src/app/core/signals/remote_signals/mailserver.nim b/src/app/core/signals/remote_signals/mailserver.nim index d51bc9e405..55e7c49470 100644 --- a/src/app/core/signals/remote_signals/mailserver.nim +++ b/src/app/core/signals/remote_signals/mailserver.nim @@ -14,12 +14,22 @@ type MailserverRequestExpiredSignal* = ref object of Signal # TODO type HistoryRequestStartedSignal* = ref object of Signal + requestId*: string + numBatches*: int + +type HistoryRequestBatchProcessedSignal* = ref object of Signal + requestId*: string + batchIndex*: int + numBatches*: int + type HistoryRequestCompletedSignal* = ref object of Signal + requestId*: string + type HistoryRequestFailedSignal* = ref object of Signal + requestId*: string errorMessage*: string error*: bool - proc fromEvent*(T: type MailserverRequestCompletedSignal, jsonSignal: JsonNode): MailserverRequestCompletedSignal = result = MailserverRequestCompletedSignal() result.signalType = SignalType.MailserverRequestCompleted @@ -38,14 +48,25 @@ proc fromEvent*(T: type MailserverRequestExpiredSignal, jsonSignal: JsonNode): M proc fromEvent*(T: type HistoryRequestStartedSignal, jsonSignal: JsonNode): HistoryRequestStartedSignal = result = HistoryRequestStartedSignal() result.signalType = SignalType.HistoryRequestStarted + result.requestId = jsonSignal["event"]{"requestId"}.getStr() + result.numBatches = jsonSIgnal["event"]{"numBatches"}.getInt() + +proc fromEvent*(T: type HistoryRequestBatchProcessedSignal, jsonSignal: JsonNode): HistoryRequestBatchProcessedSignal = + result = HistoryRequestBatchProcessedSignal() + result.signalType = SignalType.HistoryRequestBatchProcessed + result.requestId = jsonSignal["event"]{"requestId"}.getStr() + result.batchIndex = jsonSIgnal["event"]{"batchIndex"}.getInt() + result.numBatches = jsonSIgnal["event"]{"numBatches"}.getInt() proc fromEvent*(T: type HistoryRequestCompletedSignal, jsonSignal: JsonNode): HistoryRequestCompletedSignal = result = HistoryRequestCompletedSignal() result.signalType = SignalType.HistoryRequestCompleted + result.requestId = jsonSignal["event"]{"requestId"}.getStr() proc fromEvent*(T: type HistoryRequestFailedSignal, jsonSignal: JsonNode): HistoryRequestFailedSignal = result = HistoryRequestFailedSignal() result.signalType = SignalType.HistoryRequestStarted + result.requestId = jsonSignal["event"]{"requestId"}.getStr() if jsonSignal["event"].kind != JNull: result.errorMessage = jsonSignal["event"]{"errorMessage"}.getStr() result.error = result.errorMessage != "" diff --git a/src/app/core/signals/remote_signals/signal_type.nim b/src/app/core/signals/remote_signals/signal_type.nim index c20bea5af7..ba550f5e2a 100644 --- a/src/app/core/signals/remote_signals/signal_type.nim +++ b/src/app/core/signals/remote_signals/signal_type.nim @@ -25,6 +25,7 @@ type SignalType* {.pure.} = enum HistoryRequestStarted = "history.request.started" HistoryRequestCompleted = "history.request.completed" HistoryRequestFailed = "history.request.failed" + HistoryRequestBatchProcessed = "history.request.batch.processed" KeycardConnected = "keycard.connected" Unknown diff --git a/src/app/core/signals/signals_manager.nim b/src/app/core/signals/signals_manager.nim index 5ad6e067dc..165c498f81 100644 --- a/src/app/core/signals/signals_manager.nim +++ b/src/app/core/signals/signals_manager.nim @@ -80,6 +80,7 @@ QtObject: of SignalType.HistoryRequestCompleted: HistoryRequestCompletedSignal.fromEvent(jsonSignal) of SignalType.HistoryRequestStarted: HistoryRequestStartedSignal.fromEvent(jsonSignal) of SignalType.HistoryRequestFailed: HistoryRequestFailedSignal.fromEvent(jsonSignal) + of SignalType.HistoryRequestBatchProcessed: HistoryRequestBatchProcessedSignal.fromEvent(jsonSignal) of SignalType.KeycardConnected: KeycardConnectedSignal.fromEvent(jsonSignal) else: Signal() diff --git a/src/app/modules/main/profile_section/profile/controller.nim b/src/app/modules/main/profile_section/profile/controller.nim index 2b00b609a4..b6c76b98b8 100644 --- a/src/app/modules/main/profile_section/profile/controller.nim +++ b/src/app/modules/main/profile_section/profile/controller.nim @@ -1,6 +1,6 @@ import ./controller_interface -import ../../../../core/global_singleton +import ../../../../global/global_singleton import ../../../../../app_service/service/profile/service as profile_service import ../../../../../app_service/service/accounts/service as accounts_service import ../../../../../app_service/service/settings/service as settings_service diff --git a/src/app/profile/view.nim b/src/app/profile/view.nim index 07d2ed8585..8315a0d1ad 100644 --- a/src/app/profile/view.nim +++ b/src/app/profile/view.nim @@ -172,12 +172,6 @@ QtObject: QtProperty[QVariant] mutedChats: read = getMutedChats - proc setSendUserStatus*(self: ProfileView, sendUserStatus: bool) {.slot.} = - if (sendUserStatus == self.profile.sendUserStatus): - return - self.profile.setSendUserStatus(sendUserStatus) - self.status.saveSetting(Setting.SendUserStatus, sendUserStatus) - proc showOSNotification*(self: ProfileView, title: string, message: string, notificationType: int, useOSNotifications: bool) {.slot.} = discard diff --git a/src/app_service/service/token/async_tasks.nim b/src/app_service/service/token/async_tasks.nim index afb1a26498..26280ef12e 100644 --- a/src/app_service/service/token/async_tasks.nim +++ b/src/app_service/service/token/async_tasks.nim @@ -1,6 +1,6 @@ # include strformat, json include ../../common/json_utils -include ../../tasks/common +include ../../../app/core/tasks/common import status/[utils, tokens] ################################################# diff --git a/src/app_service/service/token/service.nim b/src/app_service/service/token/service.nim index 0d95789d79..6c7235462d 100644 --- a/src/app_service/service/token/service.nim +++ b/src/app_service/service/token/service.nim @@ -3,20 +3,17 @@ import eventemitter from sugar import `=>` import web3/ethtypes from web3/conversions import `$` -import status/statusgo_backend_new/tokens as token_backend +import status/statusgo_backend_new/custom_tokens as custom_tokens import ../setting/service as setting_service import ../settings/service as settings_service - -import ./dto +import ../../../app/core/tasks/[qt, threadpool] +import ./dto, ./static_token export dto logScope: topics = "token-service" -import ../../../app_service/[main] -import ../../../app_service/tasks/[qt, threadpool] - include async_tasks # Signals which may be emitted by this service: @@ -77,21 +74,20 @@ QtObject: proc init*(self: Service) = try: - let settings = self.settingService.getSetting() - var activeTokenSymbols = settings.activeTokenSymbols + var activeTokenSymbols = self.settingService.getSetting().activeTokenSymbols if activeTokenSymbols.len == 0: activeTokenSymbols = self.getDefaultVisibleSymbols() - let response = token_backend.getTokens(settings.currentNetwork.id) - let default_tokens = map( - response.result.getElems(), - proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols, hasIcon=true, isCustom=false) + let static_tokens = static_token.all().map( + proc(x: TokenDto): TokenDto = + x.isVisible = activeTokenSymbols.contains(x.symbol) + return x ) - let customResponse = token_backend.getCustomTokens() + let response = custom_tokens.getCustomTokens() self.tokens = concat( - default_tokens, - map(customResponse.result.getElems(), proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols)) + static_tokens, + map(response.result.getElems(), proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols)) ).filter( proc(x: TokenDto): bool = x.chainId == self.settingService.getSetting().currentNetwork.id ) @@ -105,7 +101,7 @@ QtObject: return self.tokens proc addCustomToken*(self: Service, address: string, name: string, symbol: string, decimals: int) = - token_backend.addCustomToken(address, name, symbol, decimals, "") + custom_tokens.addCustomToken(address, name, symbol, decimals, "") let token = newDto( name, self.settingService.getSetting().currentNetwork.id, @@ -131,7 +127,7 @@ QtObject: self.events.emit("token/visibilityToggled", VisibilityToggled(token: tokenChanged)) proc removeCustomToken*(self: Service, address: string) = - token_backend.removeCustomToken(address) + custom_tokens.removeCustomToken(address) var index = -1 for idx, token in self.tokens.pairs():