feat(@desktop/wallet): remove isWalletEnabled from local settings and

use ENABLE_WALLET env instead
This commit is contained in:
Ivan Belyakov 2023-03-15 16:35:03 +03:00 committed by IvanBelyakoff
parent ee3d92c12b
commit 02ebc8744c
12 changed files with 29 additions and 51 deletions

View File

@ -6,8 +6,6 @@ import ../../constants
const LSS_KEY_CHAT_SPLIT_VIEW* = "chatSplitView" const LSS_KEY_CHAT_SPLIT_VIEW* = "chatSplitView"
const LSS_KEY_WALLET_SPLIT_VIEW* = "walletSplitView" const LSS_KEY_WALLET_SPLIT_VIEW* = "walletSplitView"
const LSS_KEY_PROFILE_SPLIT_VIEW* = "profileSplitView" 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 LSS_KEY_IS_COMMUNITY_PERMISSIONS_ENABLED* = "isExperimentalCommunityPermissionsEnabled"
const DEFAULT_IS_COMMUNITY_PERMISSIONS_ENABLED = false const DEFAULT_IS_COMMUNITY_PERMISSIONS_ENABLED = false
const LSS_KEY_IS_COMMUNITY_TOKENS_ENABLED* = "isExperimentalCommunityTokensEnabled" const LSS_KEY_IS_COMMUNITY_TOKENS_ENABLED* = "isExperimentalCommunityTokensEnabled"
@ -253,18 +251,6 @@ QtObject:
write = setIsCommunityTokensEnabled write = setIsCommunityTokensEnabled
notify = isCommunityTokensEnabledChanged 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 nodeManagementEnabledChanged*(self: LocalAccountSensitiveSettings) {.signal.}
proc getNodeManagementEnabled*(self: LocalAccountSensitiveSettings): bool {.slot.} = proc getNodeManagementEnabled*(self: LocalAccountSensitiveSettings): bool {.slot.} =
getSettingsProp[bool](self, LSS_KEY_NODE_MANAGEMENT_ENABLED, newQVariant(DEFAULT_NODE_MANAGEMENT_ENABLED)) 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_CHAT_SPLIT_VIEW: self.chatSplitViewChanged()
of LSS_KEY_WALLET_SPLIT_VIEW: self.walletSplitViewChanged() of LSS_KEY_WALLET_SPLIT_VIEW: self.walletSplitViewChanged()
of LSS_KEY_PROFILE_SPLIT_VIEW: self.profileSplitViewChanged() 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_IS_COMMUNITY_PERMISSIONS_ENABLED: self.isCommunityPermissionsEnabledChanged()
of LSS_KEY_NODE_MANAGEMENT_ENABLED: self.nodeManagementEnabledChanged() of LSS_KEY_NODE_MANAGEMENT_ENABLED: self.nodeManagementEnabledChanged()
of LSS_KEY_IS_BROWSER_ENABLED: self.isBrowserEnabledChanged() of LSS_KEY_IS_BROWSER_ENABLED: self.isBrowserEnabledChanged()

View File

@ -8,6 +8,7 @@ import ../shared_modules/keycard_popup/module as keycard_shared_module
import ../../global/app_sections_config as conf import ../../global/app_sections_config as conf
import ../../global/app_signals import ../../global/app_signals
import ../../global/global_singleton import ../../global/global_singleton
import ../../../constants as main_constants
import chat_section/model as chat_model import chat_section/model as chat_model
import chat_section/item as chat_item import chat_section/item as chat_item
@ -414,7 +415,7 @@ method load*[T](
hasNotification = false, hasNotification = false,
notificationsCount = 0, notificationsCount = 0,
active = false, active = false,
enabled = singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled(), enabled = main_constants.WALLET_ENABLED,
) )
self.view.model().addItem(walletSectionItem) self.view.model().addItem(walletSectionItem)
if(activeSectionId == walletSectionItem.id): if(activeSectionId == walletSectionItem.id):
@ -710,11 +711,7 @@ proc setSectionAvailability[T](self: Module[T], sectionType: SectionType, availa
self.view.model().disableSection(sectionType) self.view.model().disableSection(sectionType)
method toggleSection*[T](self: Module[T], sectionType: SectionType) = method toggleSection*[T](self: Module[T], sectionType: SectionType) =
if (sectionType == SectionType.Wallet): if (sectionType == SectionType.Browser):
let enabled = singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()
self.setSectionAvailability(sectionType, not enabled)
singletonInstance.localAccountSensitiveSettings.setIsWalletEnabled(not enabled)
elif (sectionType == SectionType.Browser):
let enabled = singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled() let enabled = singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled()
self.setSectionAvailability(sectionType, not enabled) self.setSectionAvailability(sectionType, not enabled)
singletonInstance.localAccountSensitiveSettings.setIsBrowserEnabled(not enabled) singletonInstance.localAccountSensitiveSettings.setIsBrowserEnabled(not enabled)

View File

@ -312,6 +312,10 @@ QtObject:
if(it.sectionType == sectionType): if(it.sectionType == sectionType):
return it 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) = proc setActiveSection*(self: SectionModel, id: string) =
for i in 0 ..< self.items.len: for i in 0 ..< self.items.len:
if(self.items[i].active): if(self.items[i].active):

View File

@ -12,6 +12,7 @@ import ../../../app/global/global_singleton
import ../../../app/core/eventemitter import ../../../app/core/eventemitter
import ../../../app/core/tasks/[qt, threadpool] import ../../../app/core/tasks/[qt, threadpool]
import ../../common/cache import ../../common/cache
import ../../../constants as main_constants
import ./dto import ./dto
export dto export dto
@ -78,7 +79,7 @@ QtObject:
result.tokensToAddressesMap = initTable[string, TokenData]() result.tokensToAddressesMap = initTable[string, TokenData]()
proc loadData*(self: Service) = proc loadData*(self: Service) =
if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): if(not main_constants.WALLET_ENABLED):
return return
try: try:
@ -135,7 +136,6 @@ QtObject:
error "Tokens init error", errDesription = e.msg error "Tokens init error", errDesription = e.msg
proc init*(self: Service) = proc init*(self: Service) =
signalConnect(singletonInstance.localAccountSensitiveSettings, "isWalletEnabledChanged()", self, "onIsWalletEnabledChanged()", 2)
self.loadData() self.loadData()
proc getTokenList*(self: Service): seq[TokenDto] = proc getTokenList*(self: Service): seq[TokenDto] =
@ -152,9 +152,6 @@ QtObject:
if self.hasContractAddressesForToken(symbol): if self.hasContractAddressesForToken(symbol):
return self.tokensToAddressesMap[symbol].addresses return self.tokensToAddressesMap[symbol].addresses
proc onIsWalletEnabledChanged*(self: Service) {.slot.} =
self.loadData()
proc findTokenBySymbol*(self: Service, network: NetworkDto, symbol: string): TokenDto = proc findTokenBySymbol*(self: Service, network: NetworkDto, symbol: string): TokenDto =
try: try:
for token in self.tokens[network.chainId]: for token in self.tokens[network.chainId]:

View File

@ -24,6 +24,7 @@ import ./dto as transaction_dto
import ./cryptoRampDto import ./cryptoRampDto
import ../eth/utils as eth_utils import ../eth/utils as eth_utils
import ../../common/conversion import ../../common/conversion
import ../../../constants as main_constants
export transaction_dto export transaction_dto
@ -129,8 +130,6 @@ QtObject:
result.allTxLoaded = initTable[string, bool]() result.allTxLoaded = initTable[string, bool]()
proc init*(self: Service) = proc init*(self: Service) =
signalConnect(singletonInstance.localAccountSensitiveSettings, "isWalletEnabledChanged()", self, "onIsWalletEnabledChanged()", 2)
self.events.on(SignalType.Wallet.event) do(e:Args): self.events.on(SignalType.Wallet.event) do(e:Args):
var data = WalletSignal(e) var data = WalletSignal(e)
case data.eventType: case data.eventType:
@ -511,7 +510,7 @@ QtObject:
self.events.emit(SIGNAL_CRYPTO_SERVICES_READY, CryptoServicesArgs(data: cryptoServices)) self.events.emit(SIGNAL_CRYPTO_SERVICES_READY, CryptoServicesArgs(data: cryptoServices))
proc fetchCryptoServices*(self: Service) = proc fetchCryptoServices*(self: Service) =
if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): if(not main_constants.WALLET_ENABLED):
return return
let arg = GetCryptoServicesTaskArg( let arg = GetCryptoServicesTaskArg(
@ -536,6 +535,3 @@ QtObject:
except Exception as e: except Exception as e:
error "Error getting latest block number", message = e.msg error "Error getting latest block number", message = e.msg
return "" return ""
proc onIsWalletEnabledChanged*(self: Service) {.slot.} =
self.fetchCryptoServices()

View File

@ -18,6 +18,7 @@ import ../../../backend/accounts as status_go_accounts
import ../../../backend/backend as backend import ../../../backend/backend as backend
import ../../../backend/eth as status_go_eth import ../../../backend/eth as status_go_eth
import ../../../backend/transactions as status_go_transactions import ../../../backend/transactions as status_go_transactions
import ../../../constants as main_constants
export dto, derived_address, key_pair_dto export dto, derived_address, key_pair_dto
@ -221,8 +222,6 @@ QtObject:
result = toSeq(self.walletAccounts.keys()) result = toSeq(self.walletAccounts.keys())
proc init*(self: Service) = proc init*(self: Service) =
signalConnect(singletonInstance.localAccountSensitiveSettings, "isWalletEnabledChanged()", self, "onIsWalletEnabledChanged()", 2)
try: try:
let accounts = self.fetchAccounts() let accounts = self.fetchAccounts()
for account in accounts: for account in accounts:
@ -270,13 +269,13 @@ QtObject:
return i return i
proc startWallet(self: Service) = proc startWallet(self: Service) =
if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): if(not main_constants.WALLET_ENABLED):
return return
discard backend.startWallet() discard backend.startWallet()
proc checkConnected(self: Service) = proc checkConnected(self: Service) =
if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): if(not main_constants.WALLET_ENABLED):
return return
try: try:
@ -289,7 +288,7 @@ QtObject:
proc checkRecentHistory*(self: Service) = proc checkRecentHistory*(self: Service) =
if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): if(not main_constants.WALLET_ENABLED):
return return
try: try:
@ -581,7 +580,7 @@ QtObject:
error "error: ", procName="onAllTokensBuilt", errName = e.name, errDesription = e.msg error "error: ", procName="onAllTokensBuilt", errName = e.name, errDesription = e.msg
proc buildAllTokens(self: Service, accounts: seq[string], store: bool) = 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: accounts.len == 0:
return return
@ -594,11 +593,6 @@ QtObject:
) )
self.threadpool.start(arg) 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 = proc getCurrentCurrencyIfEmpty(self: Service, currency = ""): string =
if currency != "": if currency != "":
return currency return currency

View File

@ -3,6 +3,12 @@ import os, sequtils, strutils, strformat
import # vendor libs import # vendor libs
confutils 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 ## 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 ## on other platform if we just change the value here
const IS_MACOS* = defined(macosx) const IS_MACOS* = defined(macosx)

View File

@ -68,7 +68,7 @@ QtObject {
} }
property bool browserMenuItemEnabled: Global.appIsReady? localAccountSensitiveSettings.isBrowserEnabled : false 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 communitiesModuleInst: Global.appIsReady? communitiesModule : null
property var communitiesList: !!communitiesModuleInst? communitiesModuleInst.model : null property var communitiesList: !!communitiesModuleInst? communitiesModuleInst.model : null

View File

@ -25,6 +25,8 @@ QtObject {
readonly property var temporarySocialLinksJson: profileModule.temporarySocialLinksJson readonly property var temporarySocialLinksJson: profileModule.temporarySocialLinksJson
readonly property bool socialLinksDirty: profileModule.socialLinksDirty readonly property bool socialLinksDirty: profileModule.socialLinksDirty
readonly property bool isWalletEnabled: Global.appIsReady? mainModule.sectionsModel.getItemEnabledBySectionType(Constants.appSection.wallet) : false
onUserDeclinedBackupBannerChanged: { onUserDeclinedBackupBannerChanged: {
if (userDeclinedBackupBanner !== localAccountSensitiveSettings.userDeclinedBackupBanner) { if (userDeclinedBackupBanner !== localAccountSensitiveSettings.userDeclinedBackupBanner) {
localAccountSensitiveSettings.userDeclinedBackupBanner = userDeclinedBackupBanner localAccountSensitiveSettings.userDeclinedBackupBanner = userDeclinedBackupBanner

View File

@ -180,7 +180,7 @@ ColumnLayout {
} }
StatusTabButton { StatusTabButton {
enabled: localAccountSensitiveSettings.isWalletEnabled enabled: root.profileStore.isWalletEnabled
width: enabled ? implicitWidth : 0 width: enabled ? implicitWidth : 0
text: qsTr("Accounts") text: qsTr("Accounts")
onEnabledChanged: showcaseTabBar.validateCurrentIndex() onEnabledChanged: showcaseTabBar.validateCurrentIndex()

View File

@ -71,7 +71,7 @@ Item {
} }
} }
readonly property bool walletEnabled: localAccountSensitiveSettings.isWalletEnabled readonly property bool walletEnabled: SharedStores.RootStore.isWalletEnabled
onWalletEnabledChanged: { onWalletEnabledChanged: {
update() update()
} }

View File

@ -17,7 +17,8 @@ QtObject {
property var appSettingsInst: Global.appIsReady && !!appSettings? appSettings : null property var appSettingsInst: Global.appIsReady && !!appSettings? appSettings : null
property var accountSensitiveSettings: Global.appIsReady && !!localAccountSensitiveSettings? localAccountSensitiveSettings : null property var accountSensitiveSettings: Global.appIsReady && !!localAccountSensitiveSettings? localAccountSensitiveSettings : null
property real volume: !!appSettingsInst ? appSettingsInst.volume * 0.01 : 0.5 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 notificationSoundsEnabled: !!appSettingsInst ? appSettingsInst.notificationSoundsEnabled : true
property bool neverAskAboutUnfurlingAgain: !!accountSensitiveSettings ? accountSensitiveSettings.neverAskAboutUnfurlingAgain : false property bool neverAskAboutUnfurlingAgain: !!accountSensitiveSettings ? accountSensitiveSettings.neverAskAboutUnfurlingAgain : false
property bool isGifWidgetEnabled: !!accountSensitiveSettings ? accountSensitiveSettings.isGifWidgetEnabled : false property bool isGifWidgetEnabled: !!accountSensitiveSettings ? accountSensitiveSettings.isGifWidgetEnabled : false
@ -91,10 +92,6 @@ QtObject {
localAccountSensitiveSettings.neverAskAboutUnfurlingAgain = value; localAccountSensitiveSettings.neverAskAboutUnfurlingAgain = value;
} }
function enableWallet() {
localAccountSensitiveSettings.isWalletEnabled = true;
}
function setIsTenorWarningAccepted(value) { function setIsTenorWarningAccepted(value) {
localAccountSensitiveSettings.isTenorWarningAccepted = value; localAccountSensitiveSettings.isTenorWarningAccepted = value;
} }