From e1a76949dd99338a1d0b1a84afd12bd8f8394391 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Thu, 7 Mar 2024 08:24:15 -0800 Subject: [PATCH] warning fix pt.2 --- lib/entities/main_actions.dart | 8 +- lib/entities/preferences_key.dart | 4 +- lib/store/settings_store.dart | 165 ++++++++++++++++++------------ 3 files changed, 104 insertions(+), 73 deletions(-) diff --git a/lib/entities/main_actions.dart b/lib/entities/main_actions.dart index 7fbdee038..4d8190a4a 100644 --- a/lib/entities/main_actions.dart +++ b/lib/entities/main_actions.dart @@ -44,7 +44,8 @@ class MainActions { return; } - if (viewModel.isTorEnabled) { + if (viewModel.isTorEnabled && viewModel.settingsStore.shouldShowTorBuyWarning) { + viewModel.settingsStore.shouldShowTorBuyWarning = false; await _showErrorDialog(context, S.of(context).warning, S.of(context).tor_enabled_warning); } @@ -76,7 +77,7 @@ class MainActions { if (!viewModel.isEnabledExchangeAction) { return; } - + await Navigator.of(context).pushNamed(Routes.exchange); }, ); @@ -104,7 +105,8 @@ class MainActions { return; } - if (viewModel.isTorEnabled) { + if (viewModel.isTorEnabled && viewModel.settingsStore.shouldShowTorSellWarning) { + viewModel.settingsStore.shouldShowTorSellWarning = false; await _showErrorDialog(context, S.of(context).warning, S.of(context).tor_enabled_warning); } diff --git a/lib/entities/preferences_key.dart b/lib/entities/preferences_key.dart index f738135b0..7734cdc31 100644 --- a/lib/entities/preferences_key.dart +++ b/lib/entities/preferences_key.dart @@ -61,8 +61,8 @@ class PreferencesKey { static const lookupsUnstoppableDomains = 'looks_up_mastodon'; static const lookupsOpenAlias = 'looks_up_mastodon'; static const lookupsENS = 'looks_up_ens'; - static const shownTorSellWarning = 'shown_tor_sell_warning'; - static const shownTorBuyWarning = 'shown_tor_buy_warning'; + static const shouldShowTorSellWarning = 'shown_tor_sell_warning'; + static const shouldShowTorBuyWarning = 'shown_tor_buy_warning'; static String moneroWalletUpdateV1Key(String name) => diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index c41495b44..3610f034a 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -80,6 +80,8 @@ abstract class SettingsStoreBase with Store { required Map nodes, required Map powNodes, required this.shouldShowYatPopup, + required this.shouldShowTorBuyWarning, + required this.shouldShowTorSellWarning, required this.isBitcoinBuyEnabled, required this.actionlistDisplayMode, required this.pinTimeOutDuration, @@ -225,6 +227,16 @@ abstract class SettingsStoreBase with Store { (bool shouldShowYatPopup) => sharedPreferences.setBool(PreferencesKey.shouldShowYatPopup, shouldShowYatPopup)); + reaction( + (_) => shouldShowTorBuyWarning, + (bool shouldShowTorBuyWarning) => sharedPreferences.setBool( + PreferencesKey.shouldShowTorBuyWarning, shouldShowTorBuyWarning)); + + reaction( + (_) => shouldShowTorSellWarning, + (bool shouldShowTorSellWarning) => sharedPreferences.setBool( + PreferencesKey.shouldShowTorSellWarning, shouldShowTorSellWarning)); + defaultBuyProviders.observe((change) { final String key = 'buyProvider_${change.key.toString()}'; if (change.newValue != null) { @@ -530,6 +542,12 @@ abstract class SettingsStoreBase with Store { @observable bool shouldShowYatPopup; + @observable + bool shouldShowTorBuyWarning; + + @observable + bool shouldShowTorSellWarning; + @observable bool shouldShowMarketPlaceInDashboard; @@ -870,6 +888,10 @@ abstract class SettingsStoreBase with Store { final packageInfo = await PackageInfo.fromPlatform(); final deviceName = await _getDeviceName() ?? ''; final shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? true; + final shouldShowTorBuyWarning = + sharedPreferences.getBool(PreferencesKey.shouldShowTorBuyWarning) ?? true; + final shouldShowTorSellWarning = + sharedPreferences.getBool(PreferencesKey.shouldShowTorSellWarning) ?? true; final generateSubaddresses = sharedPreferences.getInt(PreferencesKey.autoGenerateSubaddressStatusKey); @@ -1026,74 +1048,77 @@ abstract class SettingsStoreBase with Store { ''; return SettingsStore( - secureStorage: secureStorage, - sharedPreferences: sharedPreferences, - initialShouldShowMarketPlaceInDashboard: shouldShowMarketPlaceInDashboard, - nodes: nodes, - powNodes: powNodes, - appVersion: packageInfo.version, - deviceName: deviceName, - isBitcoinBuyEnabled: isBitcoinBuyEnabled, - initialFiatCurrency: currentFiatCurrency, - initialBalanceDisplayMode: currentBalanceDisplayMode, - initialSaveRecipientAddress: shouldSaveRecipientAddress, - initialAutoGenerateSubaddressStatus: autoGenerateSubaddressStatus, - initialMoneroSeedType: moneroSeedType, - initialAppSecure: isAppSecure, - initialDisableBuy: disableBuy, - initialDisableSell: disableSell, - initialWalletListOrder: walletListOrder, - initialWalletListAscending: walletListAscending, - initialFiatMode: currentFiatApiMode, - initialTorConnectionMode: currentTorConnectionMode, - initialAllowBiometricalAuthentication: allowBiometricalAuthentication, - initialCake2FAPresetOptions: selectedCake2FAPreset, - initialUseTOTP2FA: useTOTP2FA, - initialTotpSecretKey: totpSecretKey, - initialFailedTokenTrial: tokenTrialNumber, - initialExchangeStatus: exchangeStatus, - initialTheme: savedTheme, - actionlistDisplayMode: actionListDisplayMode, - initialPinLength: pinLength, - pinTimeOutDuration: pinCodeTimeOutDuration, - seedPhraseLength: seedPhraseWordCount, - initialLanguageCode: savedLanguageCode, - sortBalanceBy: sortBalanceBy, - pinNativeTokenAtTop: pinNativeTokenAtTop, - useEtherscan: useEtherscan, - usePolygonScan: usePolygonScan, - defaultNanoRep: defaultNanoRep, - defaultBananoRep: defaultBananoRep, - lookupsTwitter: lookupsTwitter, - lookupsMastodon: lookupsMastodon, - lookupsYatService: lookupsYatService, - lookupsUnstoppableDomains: lookupsUnstoppableDomains, - lookupsOpenAlias: lookupsOpenAlias, - lookupsENS: lookupsENS, - initialMoneroTransactionPriority: moneroTransactionPriority, - initialBitcoinTransactionPriority: bitcoinTransactionPriority, - initialHavenTransactionPriority: havenTransactionPriority, - initialLitecoinTransactionPriority: litecoinTransactionPriority, - initialBitcoinCashTransactionPriority: bitcoinCashTransactionPriority, - initialShouldRequireTOTP2FAForAccessingWallet: shouldRequireTOTP2FAForAccessingWallet, - initialShouldRequireTOTP2FAForSendsToContact: shouldRequireTOTP2FAForSendsToContact, - initialShouldRequireTOTP2FAForSendsToNonContact: shouldRequireTOTP2FAForSendsToNonContact, - initialShouldRequireTOTP2FAForSendsToInternalWallets: - shouldRequireTOTP2FAForSendsToInternalWallets, - initialShouldRequireTOTP2FAForExchangesToInternalWallets: - shouldRequireTOTP2FAForExchangesToInternalWallets, - initialShouldRequireTOTP2FAForExchangesToExternalWallets: - shouldRequireTOTP2FAForExchangesToExternalWallets, - initialShouldRequireTOTP2FAForAddingContacts: shouldRequireTOTP2FAForAddingContacts, - initialShouldRequireTOTP2FAForCreatingNewWallets: shouldRequireTOTP2FAForCreatingNewWallets, - initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings: - shouldRequireTOTP2FAForAllSecurityAndBackupSettings, - initialEthereumTransactionPriority: ethereumTransactionPriority, - initialPolygonTransactionPriority: polygonTransactionPriority, - backgroundTasks: backgroundTasks, - initialSyncMode: savedSyncMode, - initialSyncAll: savedSyncAll, - shouldShowYatPopup: shouldShowYatPopup); + secureStorage: secureStorage, + sharedPreferences: sharedPreferences, + initialShouldShowMarketPlaceInDashboard: shouldShowMarketPlaceInDashboard, + nodes: nodes, + powNodes: powNodes, + appVersion: packageInfo.version, + deviceName: deviceName, + isBitcoinBuyEnabled: isBitcoinBuyEnabled, + initialFiatCurrency: currentFiatCurrency, + initialBalanceDisplayMode: currentBalanceDisplayMode, + initialSaveRecipientAddress: shouldSaveRecipientAddress, + initialAutoGenerateSubaddressStatus: autoGenerateSubaddressStatus, + initialMoneroSeedType: moneroSeedType, + initialAppSecure: isAppSecure, + initialDisableBuy: disableBuy, + initialDisableSell: disableSell, + initialWalletListOrder: walletListOrder, + initialWalletListAscending: walletListAscending, + initialFiatMode: currentFiatApiMode, + initialTorConnectionMode: currentTorConnectionMode, + initialAllowBiometricalAuthentication: allowBiometricalAuthentication, + initialCake2FAPresetOptions: selectedCake2FAPreset, + initialUseTOTP2FA: useTOTP2FA, + initialTotpSecretKey: totpSecretKey, + initialFailedTokenTrial: tokenTrialNumber, + initialExchangeStatus: exchangeStatus, + initialTheme: savedTheme, + actionlistDisplayMode: actionListDisplayMode, + initialPinLength: pinLength, + pinTimeOutDuration: pinCodeTimeOutDuration, + seedPhraseLength: seedPhraseWordCount, + initialLanguageCode: savedLanguageCode, + sortBalanceBy: sortBalanceBy, + pinNativeTokenAtTop: pinNativeTokenAtTop, + useEtherscan: useEtherscan, + usePolygonScan: usePolygonScan, + defaultNanoRep: defaultNanoRep, + defaultBananoRep: defaultBananoRep, + lookupsTwitter: lookupsTwitter, + lookupsMastodon: lookupsMastodon, + lookupsYatService: lookupsYatService, + lookupsUnstoppableDomains: lookupsUnstoppableDomains, + lookupsOpenAlias: lookupsOpenAlias, + lookupsENS: lookupsENS, + initialMoneroTransactionPriority: moneroTransactionPriority, + initialBitcoinTransactionPriority: bitcoinTransactionPriority, + initialHavenTransactionPriority: havenTransactionPriority, + initialLitecoinTransactionPriority: litecoinTransactionPriority, + initialBitcoinCashTransactionPriority: bitcoinCashTransactionPriority, + initialShouldRequireTOTP2FAForAccessingWallet: shouldRequireTOTP2FAForAccessingWallet, + initialShouldRequireTOTP2FAForSendsToContact: shouldRequireTOTP2FAForSendsToContact, + initialShouldRequireTOTP2FAForSendsToNonContact: shouldRequireTOTP2FAForSendsToNonContact, + initialShouldRequireTOTP2FAForSendsToInternalWallets: + shouldRequireTOTP2FAForSendsToInternalWallets, + initialShouldRequireTOTP2FAForExchangesToInternalWallets: + shouldRequireTOTP2FAForExchangesToInternalWallets, + initialShouldRequireTOTP2FAForExchangesToExternalWallets: + shouldRequireTOTP2FAForExchangesToExternalWallets, + initialShouldRequireTOTP2FAForAddingContacts: shouldRequireTOTP2FAForAddingContacts, + initialShouldRequireTOTP2FAForCreatingNewWallets: shouldRequireTOTP2FAForCreatingNewWallets, + initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings: + shouldRequireTOTP2FAForAllSecurityAndBackupSettings, + initialEthereumTransactionPriority: ethereumTransactionPriority, + initialPolygonTransactionPriority: polygonTransactionPriority, + backgroundTasks: backgroundTasks, + initialSyncMode: savedSyncMode, + initialSyncAll: savedSyncAll, + shouldShowYatPopup: shouldShowYatPopup, + shouldShowTorBuyWarning: shouldShowTorBuyWarning, + shouldShowTorSellWarning: shouldShowTorSellWarning, + ); } Future reload({required Box nodeSource}) async { @@ -1187,6 +1212,10 @@ abstract class SettingsStoreBase with Store { languageCode = sharedPreferences.getString(PreferencesKey.currentLanguageCode) ?? languageCode; shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? shouldShowYatPopup; + shouldShowTorBuyWarning = + sharedPreferences.getBool(PreferencesKey.shouldShowTorBuyWarning) ?? shouldShowTorBuyWarning; + shouldShowTorSellWarning = + sharedPreferences.getBool(PreferencesKey.shouldShowTorSellWarning) ?? shouldShowTorSellWarning; sortBalanceBy = SortBalanceBy .values[sharedPreferences.getInt(PreferencesKey.sortBalanceBy) ?? sortBalanceBy.index]; pinNativeTokenAtTop = sharedPreferences.getBool(PreferencesKey.pinNativeTokenAtTop) ?? true;