From 02ebc8744cc91b514e662d6bae36d1bfab4c9acf Mon Sep 17 00:00:00 2001 From: Ivan Belyakov Date: Wed, 15 Mar 2023 16:35:03 +0300 Subject: [PATCH] feat(@desktop/wallet): remove isWalletEnabled from local settings and use ENABLE_WALLET env instead --- .../global/local_account_sensitive_settings.nim | 15 --------------- src/app/modules/main/module.nim | 9 +++------ src/app/modules/shared_models/section_model.nim | 4 ++++ src/app_service/service/token/service.nim | 7 ++----- src/app_service/service/transaction/service.nim | 8 ++------ .../service/wallet_account/service.nim | 16 +++++----------- src/constants.nim | 6 ++++++ .../Profile/stores/ProfileSectionStore.qml | 2 +- .../AppLayouts/Profile/stores/ProfileStore.qml | 2 ++ .../views/profile/MyProfileSettingsView.qml | 2 +- ui/imports/shared/status/StatusStickerMarket.qml | 2 +- ui/imports/shared/stores/RootStore.qml | 7 ++----- 12 files changed, 29 insertions(+), 51 deletions(-) diff --git a/src/app/global/local_account_sensitive_settings.nim b/src/app/global/local_account_sensitive_settings.nim index 0beb338c7c..7e769a4311 100644 --- a/src/app/global/local_account_sensitive_settings.nim +++ b/src/app/global/local_account_sensitive_settings.nim @@ -6,8 +6,6 @@ import ../../constants const LSS_KEY_CHAT_SPLIT_VIEW* = "chatSplitView" const LSS_KEY_WALLET_SPLIT_VIEW* = "walletSplitView" const LSS_KEY_PROFILE_SPLIT_VIEW* = "profileSplitView" -const LSS_KEY_IS_WALLET_ENABLED* = "isExperimentalWalletEnabled" -const DEFAULT_IS_WALLET_ENABLED = true const LSS_KEY_IS_COMMUNITY_PERMISSIONS_ENABLED* = "isExperimentalCommunityPermissionsEnabled" const DEFAULT_IS_COMMUNITY_PERMISSIONS_ENABLED = false const LSS_KEY_IS_COMMUNITY_TOKENS_ENABLED* = "isExperimentalCommunityTokensEnabled" @@ -253,18 +251,6 @@ QtObject: write = setIsCommunityTokensEnabled notify = isCommunityTokensEnabledChanged - proc isWalletEnabledChanged*(self: LocalAccountSensitiveSettings) {.signal.} - proc getIsWalletEnabled*(self: LocalAccountSensitiveSettings): bool {.slot.} = - getSettingsProp[bool](self, LSS_KEY_IS_WALLET_ENABLED, newQVariant(DEFAULT_IS_WALLET_ENABLED)) - proc setIsWalletEnabled*(self: LocalAccountSensitiveSettings, value: bool) {.slot.} = - setSettingsProp(self, LSS_KEY_IS_WALLET_ENABLED, newQVariant(value)): - self.isWalletEnabledChanged() - - QtProperty[bool] isWalletEnabled: - read = getIsWalletEnabled - write = setIsWalletEnabled - notify = isWalletEnabledChanged - proc nodeManagementEnabledChanged*(self: LocalAccountSensitiveSettings) {.signal.} proc getNodeManagementEnabled*(self: LocalAccountSensitiveSettings): bool {.slot.} = getSettingsProp[bool](self, LSS_KEY_NODE_MANAGEMENT_ENABLED, newQVariant(DEFAULT_NODE_MANAGEMENT_ENABLED)) @@ -788,7 +774,6 @@ QtObject: of LSS_KEY_CHAT_SPLIT_VIEW: self.chatSplitViewChanged() of LSS_KEY_WALLET_SPLIT_VIEW: self.walletSplitViewChanged() of LSS_KEY_PROFILE_SPLIT_VIEW: self.profileSplitViewChanged() - of LSS_KEY_IS_WALLET_ENABLED: self.isWalletEnabledChanged() of LSS_KEY_IS_COMMUNITY_PERMISSIONS_ENABLED: self.isCommunityPermissionsEnabledChanged() of LSS_KEY_NODE_MANAGEMENT_ENABLED: self.nodeManagementEnabledChanged() of LSS_KEY_IS_BROWSER_ENABLED: self.isBrowserEnabledChanged() diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index ae7ea2c9a7..eeee1d970e 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -8,6 +8,7 @@ import ../shared_modules/keycard_popup/module as keycard_shared_module import ../../global/app_sections_config as conf import ../../global/app_signals import ../../global/global_singleton +import ../../../constants as main_constants import chat_section/model as chat_model import chat_section/item as chat_item @@ -414,7 +415,7 @@ method load*[T]( hasNotification = false, notificationsCount = 0, active = false, - enabled = singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled(), + enabled = main_constants.WALLET_ENABLED, ) self.view.model().addItem(walletSectionItem) if(activeSectionId == walletSectionItem.id): @@ -710,11 +711,7 @@ proc setSectionAvailability[T](self: Module[T], sectionType: SectionType, availa self.view.model().disableSection(sectionType) method toggleSection*[T](self: Module[T], sectionType: SectionType) = - if (sectionType == SectionType.Wallet): - let enabled = singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled() - self.setSectionAvailability(sectionType, not enabled) - singletonInstance.localAccountSensitiveSettings.setIsWalletEnabled(not enabled) - elif (sectionType == SectionType.Browser): + if (sectionType == SectionType.Browser): let enabled = singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled() self.setSectionAvailability(sectionType, not enabled) singletonInstance.localAccountSensitiveSettings.setIsBrowserEnabled(not enabled) diff --git a/src/app/modules/shared_models/section_model.nim b/src/app/modules/shared_models/section_model.nim index e207cf0847..9194d9b3ce 100644 --- a/src/app/modules/shared_models/section_model.nim +++ b/src/app/modules/shared_models/section_model.nim @@ -312,6 +312,10 @@ QtObject: if(it.sectionType == sectionType): return it + proc getItemEnabledBySectionType*(self: SectionModel, sectionType: int): bool {.slot.} = + let item = self.getItemBySectionType((SectionType)sectionType) + return not item.isEmpty() and item.enabled() + proc setActiveSection*(self: SectionModel, id: string) = for i in 0 ..< self.items.len: if(self.items[i].active): diff --git a/src/app_service/service/token/service.nim b/src/app_service/service/token/service.nim index 1522977aed..4d760c3620 100644 --- a/src/app_service/service/token/service.nim +++ b/src/app_service/service/token/service.nim @@ -12,6 +12,7 @@ import ../../../app/global/global_singleton import ../../../app/core/eventemitter import ../../../app/core/tasks/[qt, threadpool] import ../../common/cache +import ../../../constants as main_constants import ./dto export dto @@ -78,7 +79,7 @@ QtObject: result.tokensToAddressesMap = initTable[string, TokenData]() proc loadData*(self: Service) = - if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): + if(not main_constants.WALLET_ENABLED): return try: @@ -135,7 +136,6 @@ QtObject: error "Tokens init error", errDesription = e.msg proc init*(self: Service) = - signalConnect(singletonInstance.localAccountSensitiveSettings, "isWalletEnabledChanged()", self, "onIsWalletEnabledChanged()", 2) self.loadData() proc getTokenList*(self: Service): seq[TokenDto] = @@ -152,9 +152,6 @@ QtObject: if self.hasContractAddressesForToken(symbol): return self.tokensToAddressesMap[symbol].addresses - proc onIsWalletEnabledChanged*(self: Service) {.slot.} = - self.loadData() - proc findTokenBySymbol*(self: Service, network: NetworkDto, symbol: string): TokenDto = try: for token in self.tokens[network.chainId]: diff --git a/src/app_service/service/transaction/service.nim b/src/app_service/service/transaction/service.nim index a3d25703bc..056a819f9e 100644 --- a/src/app_service/service/transaction/service.nim +++ b/src/app_service/service/transaction/service.nim @@ -24,6 +24,7 @@ import ./dto as transaction_dto import ./cryptoRampDto import ../eth/utils as eth_utils import ../../common/conversion +import ../../../constants as main_constants export transaction_dto @@ -129,8 +130,6 @@ QtObject: result.allTxLoaded = initTable[string, bool]() proc init*(self: Service) = - signalConnect(singletonInstance.localAccountSensitiveSettings, "isWalletEnabledChanged()", self, "onIsWalletEnabledChanged()", 2) - self.events.on(SignalType.Wallet.event) do(e:Args): var data = WalletSignal(e) case data.eventType: @@ -511,7 +510,7 @@ QtObject: self.events.emit(SIGNAL_CRYPTO_SERVICES_READY, CryptoServicesArgs(data: cryptoServices)) proc fetchCryptoServices*(self: Service) = - if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): + if(not main_constants.WALLET_ENABLED): return let arg = GetCryptoServicesTaskArg( @@ -536,6 +535,3 @@ QtObject: except Exception as e: error "Error getting latest block number", message = e.msg return "" - - proc onIsWalletEnabledChanged*(self: Service) {.slot.} = - self.fetchCryptoServices() \ No newline at end of file diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index 44e4f8ed4c..4ab3d7a227 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -18,6 +18,7 @@ import ../../../backend/accounts as status_go_accounts import ../../../backend/backend as backend import ../../../backend/eth as status_go_eth import ../../../backend/transactions as status_go_transactions +import ../../../constants as main_constants export dto, derived_address, key_pair_dto @@ -221,8 +222,6 @@ QtObject: result = toSeq(self.walletAccounts.keys()) proc init*(self: Service) = - signalConnect(singletonInstance.localAccountSensitiveSettings, "isWalletEnabledChanged()", self, "onIsWalletEnabledChanged()", 2) - try: let accounts = self.fetchAccounts() for account in accounts: @@ -270,13 +269,13 @@ QtObject: return i proc startWallet(self: Service) = - if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): + if(not main_constants.WALLET_ENABLED): return discard backend.startWallet() proc checkConnected(self: Service) = - if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): + if(not main_constants.WALLET_ENABLED): return try: @@ -289,7 +288,7 @@ QtObject: proc checkRecentHistory*(self: Service) = - if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): + if(not main_constants.WALLET_ENABLED): return try: @@ -581,7 +580,7 @@ QtObject: error "error: ", procName="onAllTokensBuilt", errName = e.name, errDesription = e.msg proc buildAllTokens(self: Service, accounts: seq[string], store: bool) = - if not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled() or + if not main_constants.WALLET_ENABLED or accounts.len == 0: return @@ -594,11 +593,6 @@ QtObject: ) self.threadpool.start(arg) - proc onIsWalletEnabledChanged*(self: Service) {.slot.} = - self.buildAllTokens(self.getAddresses(), store = true) - self.checkRecentHistory() - self.startWallet() - proc getCurrentCurrencyIfEmpty(self: Service, currency = ""): string = if currency != "": return currency diff --git a/src/constants.nim b/src/constants.nim index 52c6384e17..bf83ae7ad0 100644 --- a/src/constants.nim +++ b/src/constants.nim @@ -3,6 +3,12 @@ import os, sequtils, strutils, strformat import # vendor libs confutils +const DEFAULT_WALLET_ENABLED = true +let WALLET_ENABLED* = if (existsEnv("ENABLE_WALLET")): + parseInt($getEnv("ENABLE_WALLET")) != 0 + else: + DEFAULT_WALLET_ENABLED + ## Added a constant here cause it's easier to check the app how it behaves ## on other platform if we just change the value here const IS_MACOS* = defined(macosx) diff --git a/ui/app/AppLayouts/Profile/stores/ProfileSectionStore.qml b/ui/app/AppLayouts/Profile/stores/ProfileSectionStore.qml index 536e0f3976..6ef72f7a09 100644 --- a/ui/app/AppLayouts/Profile/stores/ProfileSectionStore.qml +++ b/ui/app/AppLayouts/Profile/stores/ProfileSectionStore.qml @@ -68,7 +68,7 @@ QtObject { } property bool browserMenuItemEnabled: Global.appIsReady? localAccountSensitiveSettings.isBrowserEnabled : false - property bool walletMenuItemEnabled: Global.appIsReady? localAccountSensitiveSettings.isWalletEnabled : false + property bool walletMenuItemEnabled: profileStore.isWalletEnabled property var communitiesModuleInst: Global.appIsReady? communitiesModule : null property var communitiesList: !!communitiesModuleInst? communitiesModuleInst.model : null diff --git a/ui/app/AppLayouts/Profile/stores/ProfileStore.qml b/ui/app/AppLayouts/Profile/stores/ProfileStore.qml index f3f9692f4e..fc0132fed1 100644 --- a/ui/app/AppLayouts/Profile/stores/ProfileStore.qml +++ b/ui/app/AppLayouts/Profile/stores/ProfileStore.qml @@ -25,6 +25,8 @@ QtObject { readonly property var temporarySocialLinksJson: profileModule.temporarySocialLinksJson readonly property bool socialLinksDirty: profileModule.socialLinksDirty + readonly property bool isWalletEnabled: Global.appIsReady? mainModule.sectionsModel.getItemEnabledBySectionType(Constants.appSection.wallet) : false + onUserDeclinedBackupBannerChanged: { if (userDeclinedBackupBanner !== localAccountSensitiveSettings.userDeclinedBackupBanner) { localAccountSensitiveSettings.userDeclinedBackupBanner = userDeclinedBackupBanner diff --git a/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml b/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml index f5aa5cd4db..0eab21a3fa 100644 --- a/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml +++ b/ui/app/AppLayouts/Profile/views/profile/MyProfileSettingsView.qml @@ -180,7 +180,7 @@ ColumnLayout { } StatusTabButton { - enabled: localAccountSensitiveSettings.isWalletEnabled + enabled: root.profileStore.isWalletEnabled width: enabled ? implicitWidth : 0 text: qsTr("Accounts") onEnabledChanged: showcaseTabBar.validateCurrentIndex() diff --git a/ui/imports/shared/status/StatusStickerMarket.qml b/ui/imports/shared/status/StatusStickerMarket.qml index da1cc3dd34..fbc33e12c5 100644 --- a/ui/imports/shared/status/StatusStickerMarket.qml +++ b/ui/imports/shared/status/StatusStickerMarket.qml @@ -71,7 +71,7 @@ Item { } } - readonly property bool walletEnabled: localAccountSensitiveSettings.isWalletEnabled + readonly property bool walletEnabled: SharedStores.RootStore.isWalletEnabled onWalletEnabledChanged: { update() } diff --git a/ui/imports/shared/stores/RootStore.qml b/ui/imports/shared/stores/RootStore.qml index d47e240c30..05a103cb8d 100644 --- a/ui/imports/shared/stores/RootStore.qml +++ b/ui/imports/shared/stores/RootStore.qml @@ -17,7 +17,8 @@ QtObject { property var appSettingsInst: Global.appIsReady && !!appSettings? appSettings : null property var accountSensitiveSettings: Global.appIsReady && !!localAccountSensitiveSettings? localAccountSensitiveSettings : null property real volume: !!appSettingsInst ? appSettingsInst.volume * 0.01 : 0.5 - property bool isWalletEnabled: !!accountSensitiveSettings ? accountSensitiveSettings.isWalletEnabled : false + property bool isWalletEnabled: Global.appIsReady? mainModule.sectionsModel.getItemEnabledBySectionType(Constants.appSection.wallet) : false + property bool notificationSoundsEnabled: !!appSettingsInst ? appSettingsInst.notificationSoundsEnabled : true property bool neverAskAboutUnfurlingAgain: !!accountSensitiveSettings ? accountSensitiveSettings.neverAskAboutUnfurlingAgain : false property bool isGifWidgetEnabled: !!accountSensitiveSettings ? accountSensitiveSettings.isGifWidgetEnabled : false @@ -91,10 +92,6 @@ QtObject { localAccountSensitiveSettings.neverAskAboutUnfurlingAgain = value; } - function enableWallet() { - localAccountSensitiveSettings.isWalletEnabled = true; - } - function setIsTenorWarningAccepted(value) { localAccountSensitiveSettings.isTenorWarningAccepted = value; }