mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-15 09:24:01 +01:00
cw-1683-prepare-zano-removal (#3668)
* wip zano removal * add zano removal popup * constantly show popup if user keeps using deprecated wallet * add confirmation before viewing seed * fix viewed check * prevent wallet staying open after seed backup * Update lib/entities/default_settings_migration.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * add passphrase * make popup scrollable * delete deprecated seeds when wallet is deleted * encrypt seeds * also deprecate decred * remove decred from available types * remove backup logic * showArrow: false, * Remove deprecated wallet seeds deletion Removed deprecated wallet seeds deletion from delete method. --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
@@ -2,7 +2,10 @@ import 'dart:convert';
|
||||
import 'dart:io' show Directory, File, Platform;
|
||||
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import "package:cake_wallet/core/key_service.dart";
|
||||
import 'package:cake_wallet/core/secure_storage.dart';
|
||||
import "package:cake_wallet/decred/decred.dart";
|
||||
import "package:cake_wallet/di.dart";
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/contact.dart';
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
@@ -14,6 +17,9 @@ import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
import 'package:cake_wallet/entities/secret_store_key.dart';
|
||||
import 'package:cake_wallet/monero/monero.dart';
|
||||
import 'package:cake_wallet/new-ui/model/charts/charts_asset.dart';
|
||||
import "package:cake_wallet/store/settings_store.dart";
|
||||
import "package:cake_wallet/zano/zano.dart";
|
||||
import "package:cw_core/cake_hive.dart";
|
||||
import 'package:cake_wallet/wownero/wownero.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
@@ -23,8 +29,10 @@ import 'package:cw_core/node_list.dart';
|
||||
import 'package:cw_core/pathForWallet.dart';
|
||||
import 'package:cw_core/root_dir.dart';
|
||||
import 'package:cw_core/spl_token.dart';
|
||||
import "package:cw_core/unspent_coins_info.dart";
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_core/wallet_info.dart';
|
||||
import "package:cw_core/wallet_service.dart";
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:encrypt/encrypt.dart' as encrypt;
|
||||
import 'package:hive/hive.dart';
|
||||
@@ -1377,4 +1385,4 @@ Future<void> _addTbbTokenToExistingSolanaWallets() async {
|
||||
} catch (e) {
|
||||
printV("Error in TBB migration: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import "package:cw_core/wallet_type.dart";
|
||||
|
||||
class PreferencesKey {
|
||||
static const currentWalletType = 'current_wallet_type';
|
||||
static const currentWalletName = 'current_wallet_name';
|
||||
@@ -147,4 +149,6 @@ class PreferencesKey {
|
||||
static const balanceHideCounter = "balance_hide_counter";
|
||||
static const zcashMigrationModalViewed = "zcash_migration_modal_viewed";
|
||||
static const showCiBuildOverlay = "show_ci_build_overlay";
|
||||
static String deprecationPopupViewed(WalletType type) =>
|
||||
"deprecation_popup_viewed_${walletTypeToString(type)}";
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import "package:cake_wallet/new-ui/page_open_listener.dart";
|
||||
import 'package:cake_wallet/new-ui/pages/charts_page.dart';
|
||||
import 'package:cake_wallet/new-ui/pages/home_page.dart';
|
||||
import 'package:cake_wallet/new-ui/widgets/changelog_modal.dart';
|
||||
import "package:cake_wallet/new-ui/widgets/wallet_removal_popup.dart";
|
||||
import 'package:cake_wallet/src/screens/contact/contact_list_page.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/pages/cake_features_page.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/widgets/new_main_navbar_widget.dart';
|
||||
@@ -55,6 +56,7 @@ class _NewDashboardState extends State<NewDashboard> {
|
||||
setState(() {
|
||||
_selectedPage = 0;
|
||||
});
|
||||
_showWalletRemovalPopup(context);
|
||||
});
|
||||
|
||||
Future.delayed(Duration(milliseconds: 300)).then((_) {
|
||||
@@ -63,6 +65,7 @@ class _NewDashboardState extends State<NewDashboard> {
|
||||
});
|
||||
});
|
||||
_showVulnerableSeedsPopup(context);
|
||||
_showWalletRemovalPopup(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -182,4 +185,14 @@ class _NewDashboardState extends State<NewDashboard> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showWalletRemovalPopup(BuildContext context) async {
|
||||
if(await widget.dashboardViewModel.shouldShowRemovalPopup()) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
final toBeRemoved = await widget.dashboardViewModel.walletsToBeRemoved;
|
||||
if(context.mounted) {
|
||||
await showPopUp<void>(context: context, builder: (context)=>WalletRemovalPopup(affectedWallets: toBeRemoved,));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import "package:cake_wallet/entities/new_ui_entities/list_item/list_item_regular_row.dart";
|
||||
import "package:cake_wallet/generated/i18n.dart";
|
||||
import "package:cake_wallet/new-ui/widgets/new_primary_button.dart";
|
||||
import "package:cake_wallet/src/widgets/cake_image_widget.dart";
|
||||
import "package:cake_wallet/src/widgets/new_list_row/new_list_section.dart";
|
||||
import "package:cake_wallet/themes/core/theme_extension.dart";
|
||||
import "package:cw_core/currency_for_wallet_type.dart";
|
||||
import "package:cw_core/wallet_info.dart";
|
||||
import "package:cw_core/wallet_type.dart";
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
class WalletRemovalPopup extends StatelessWidget {
|
||||
const WalletRemovalPopup({required this.affectedWallets, super.key});
|
||||
|
||||
final List<WalletInfo> affectedWallets;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final types = affectedWallets.map((item) => item.type).toSet().toList();
|
||||
final iconPaths = types.map((item) => walletTypeToCryptoCurrency(item).iconPath ?? "").toList();
|
||||
final typeNames = types.map(walletTypeToDisplayName).toList();
|
||||
|
||||
return Center(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 18,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 8,
|
||||
children: iconPaths
|
||||
.map(
|
||||
(item) => CakeImageWidget(
|
||||
imageUrl: item,
|
||||
width: 64,
|
||||
height: 64,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.center,
|
||||
S.of(context).support_will_soon_be_removed(typeNames.join(", ")),
|
||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.center,
|
||||
types.map(deprecationReasonForType).whereType<String>().join("\n\n"),
|
||||
),
|
||||
Text(
|
||||
textAlign: TextAlign.center,
|
||||
S.of(context).make_sure_you_migrated(typeNames.join("/")),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: context.currentTheme.customColors.warningOutlineColor,
|
||||
),
|
||||
),
|
||||
NewListSections(
|
||||
sections: {
|
||||
"": affectedWallets
|
||||
.map(
|
||||
(item) => ListItemRegularRow(
|
||||
iconPath: walletTypeToCryptoCurrency(item.type).iconPath ?? "",
|
||||
keyValue: item.name,
|
||||
label: item.name,
|
||||
showArrow: false,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
},
|
||||
),
|
||||
NewPrimaryButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
text: S.of(context).close,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
textColor: Theme.of(context).colorScheme.onPrimary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String? deprecationReasonForType(WalletType type) =>
|
||||
switch (type) { WalletType.zano => S.current.zano_removal_reason, _ => null };
|
||||
}
|
||||
@@ -1697,4 +1697,25 @@ abstract class DashboardViewModelBase with Store {
|
||||
Future<void> refreshDashboard() async {
|
||||
reconnect();
|
||||
}
|
||||
|
||||
|
||||
static const walletTypesToBeRemoved = [
|
||||
WalletType.zano,
|
||||
WalletType.decred,
|
||||
];
|
||||
|
||||
Future<bool> shouldShowRemovalPopup() async {
|
||||
final show = (await WalletInfo.getAll()).any((item) =>
|
||||
walletTypesToBeRemoved.contains(item.type) &&
|
||||
!(sharedPreferences.getBool(PreferencesKey.deprecationPopupViewed(item.type)) ?? false),);
|
||||
for (final type in walletTypesToBeRemoved) {
|
||||
await sharedPreferences.setBool(PreferencesKey.deprecationPopupViewed(type), true);
|
||||
}
|
||||
// if user is actively using a wallet type that's about to be removed, keep nagging them
|
||||
return show || walletTypesToBeRemoved.contains(wallet.type);
|
||||
}
|
||||
|
||||
Future<List<WalletInfo>> get walletsToBeRemoved async => (await WalletInfo.getAll())
|
||||
.where((item) => walletTypesToBeRemoved.contains(item.type))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user