From 3c31008af8d5433661d1d5175eff1d73242d67d5 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 7 Sep 2022 17:28:33 -0600 Subject: [PATCH] added block explorer warning --- .../transaction_details_view.dart | 73 +++++++++++++++++++ lib/utilities/prefs.dart | 29 ++++++++ 2 files changed, 102 insertions(+) diff --git a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart index 516bdca3b..62b398500 100644 --- a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart @@ -143,6 +143,66 @@ class _TransactionDetailsViewState String _note = ""; + Future showExplorerWarning(String explorer) async { + final bool? shouldContinue = await showDialog( + context: context, + barrierDismissible: false, + builder: (_) => StackDialog( + title: "Attention", + message: + "You are about to view this transaction in a block explorer. The explorer may log your IP address and link it to the transaction. Only proceed if you trust $explorer.", + icon: Row( + children: [ + Consumer(builder: (_, ref, __) { + return Checkbox( + value: ref.watch(prefsChangeNotifierProvider + .select((value) => value.hideBlockExplorerWarning)), + onChanged: (value) { + if (value is bool) { + ref + .read(prefsChangeNotifierProvider) + .hideBlockExplorerWarning = value; + setState(() {}); + } + }, + ); + }), + Text( + "Never show again", + style: STextStyles.smallMed14, + ) + ], + ), + leftButton: TextButton( + onPressed: () { + Navigator.of(context).pop(false); + }, + child: Text( + "Cancel", + style: STextStyles.button.copyWith( + color: CFColors.stackAccent, + ), + ), + ), + rightButton: TextButton( + style: Theme.of(context).textButtonTheme.style?.copyWith( + backgroundColor: MaterialStateProperty.all( + CFColors.stackAccent, + ), + ), + onPressed: () { + Navigator.of(context).pop(false); + }, + child: Text( + "Continue", + style: STextStyles.button, + ), + ), + ), + ); + return shouldContinue ?? false; + } + @override Widget build(BuildContext context) { return Scaffold( @@ -492,6 +552,19 @@ class _TransactionDetailsViewState coin: coin, txid: _transaction.txid, ); + + if (ref + .read(prefsChangeNotifierProvider) + .hideBlockExplorerWarning == + false) { + final shouldContinue = + await showExplorerWarning(uri.host); + + if (!shouldContinue) { + return; + } + } + // ref // .read( // shouldShowLockscreenOnResumeStateProvider diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index 7f6006502..cd297f121 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -33,6 +33,7 @@ class Prefs extends ChangeNotifier { _autoBackupLocation = await _getAutoBackupLocation(); _backupFrequencyType = await _getBackupFrequencyType(); _lastAutoBackup = await _getLastAutoBackup(); + _hideBlockExplorerWarning = await _getHideBlockExplorerWarning(); _initialized = true; } @@ -466,4 +467,32 @@ class Prefs extends ChangeNotifier { return await DB.instance.get( boxName: DB.boxNamePrefs, key: "autoBackupFileUri") as DateTime?; } + + + + // auto backup + + bool _hideBlockExplorerWarning = false; + + bool get hideBlockExplorerWarning => _hideBlockExplorerWarning; + + set hideBlockExplorerWarning(bool hideBlockExplorerWarning) { + if (_hideBlockExplorerWarning != hideBlockExplorerWarning) { + DB.instance + .put( + boxName: DB.boxNamePrefs, + key: "hideBlockExplorerWarning", + value: hideBlockExplorerWarning) + .then((_) { + _hideBlockExplorerWarning = hideBlockExplorerWarning; + notifyListeners(); + }); + } + } + + Future _getHideBlockExplorerWarning() async { + return await DB.instance.get( + boxName: DB.boxNamePrefs, key: "hideBlockExplorerWarning") as bool? ?? + false; + } }