apply lelantus rescan on desktop

This commit is contained in:
julian 2023-07-28 13:53:14 -06:00
parent bd090a3e92
commit 64d946e752
2 changed files with 213 additions and 87 deletions

View file

@ -4,6 +4,8 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:stackwallet/pages/pinpad_views/lock_screen_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_backup_views/wallet_backup_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/delete_wallet_warning_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_delete_wallet_dialog.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/unlock_wallet_keys_desktop.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/route_generator.dart';
import 'package:stackwallet/themes/stack_colors.dart';
@ -13,6 +15,9 @@ import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
@ -48,7 +53,47 @@ class _FiroRescanRecoveryErrorViewState
child: ConditionalParent(
condition: Util.isDesktop,
builder: (child) {
return child;
return DesktopScaffold(
appBar: DesktopAppBar(
background: Theme.of(context).extension<StackColors>()!.popupBG,
isCompactHeight: true,
// useSpacers: false,
trailing: Padding(
padding: const EdgeInsets.only(right: 16),
child: CustomTextButton(
text: "Delete wallet",
onTap: () async {
final result = await showDialog<bool?>(
context: context,
barrierDismissible: false,
builder: (context) => Navigator(
initialRoute: DesktopDeleteWalletDialog.routeName,
onGenerateRoute: RouteGenerator.generateRoute,
onGenerateInitialRoutes: (_, __) {
return [
RouteGenerator.generateRoute(
RouteSettings(
name: DesktopDeleteWalletDialog.routeName,
arguments: widget.walletId,
),
),
];
},
),
);
if (result == true) {
if (context.mounted) {
Navigator.of(context).pop();
Navigator.of(context).pop();
}
}
},
),
),
),
body: SizedBox(width: 328, child: child),
);
},
child: ConditionalParent(
condition: !Util.isDesktop,
@ -164,13 +209,50 @@ class _FiroRescanRecoveryErrorViewState
"Failed to rescan firo wallet",
style: STextStyles.pageTitleH2(context),
),
if (!Util.isDesktop) const Spacer(),
Row(
Util.isDesktop
? const SizedBox(
height: 60,
)
: const Spacer(),
BranchedParent(
condition: Util.isDesktop,
conditionBranchBuilder: (children) => Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: children,
),
otherBranchBuilder: (children) => Row(
children: [
Expanded(child: children[0]),
children[1],
Expanded(child: children[2]),
],
),
children: [
Expanded(
child: SecondaryButton(
label: "Show mnemonic",
onPressed: () async {
SecondaryButton(
label: "Show mnemonic",
buttonHeight: Util.isDesktop ? ButtonHeight.l : null,
onPressed: () async {
if (Util.isDesktop) {
await showDialog<void>(
context: context,
barrierDismissible: false,
builder: (context) => Navigator(
initialRoute: UnlockWalletKeysDesktop.routeName,
onGenerateRoute: RouteGenerator.generateRoute,
onGenerateInitialRoutes: (_, __) {
return [
RouteGenerator.generateRoute(
RouteSettings(
name: UnlockWalletKeysDesktop.routeName,
arguments: widget.walletId,
),
)
];
},
),
);
} else {
final mnemonic = await ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
@ -198,24 +280,24 @@ class _FiroRescanRecoveryErrorViewState
),
);
}
},
),
}
},
),
const SizedBox(
width: 16,
height: 16,
),
Expanded(
child: PrimaryButton(
label: "Retry",
onPressed: () {
Navigator.of(context).pop(
true,
);
},
),
PrimaryButton(
label: "Retry",
buttonHeight: Util.isDesktop ? ButtonHeight.l : null,
onPressed: () {
Navigator.of(context).pop(
true,
);
},
),
],
)
),
],
),
),

View file

@ -17,6 +17,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/pages/add_wallet_views/add_token_view/edit_wallet_tokens_view.dart';
import 'package:stackwallet/pages/special/firo_rescan_recovery_error_dialog.dart';
import 'package:stackwallet/pages/token_view/my_tokens_view.dart';
import 'package:stackwallet/pages/wallet_view/sub_widgets/transactions_list.dart';
import 'package:stackwallet/pages/wallet_view/transaction_views/all_transactions_view.dart';
@ -30,6 +31,7 @@ import 'package:stackwallet/providers/global/auto_swb_service_provider.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/providers/ui/transaction_filter_provider.dart';
import 'package:stackwallet/services/coins/banano/banano_wallet.dart';
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
import 'package:stackwallet/themes/coin_icon_provider.dart';
@ -78,6 +80,7 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
late final bool _shouldDisableAutoSyncOnLogOut;
bool _rescanningOnOpen = false;
bool _lelantusRescanRecovery = false;
Future<void> onBackPressed() async {
await _logout();
@ -103,6 +106,38 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
ref.read(managerProvider.notifier).isActiveWallet = false;
}
Future<void> _firoRescanRecovery() async {
final success = await (ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
.wallet as FiroWallet)
.firoRescanRecovery();
if (success) {
// go into wallet
WidgetsBinding.instance.addPostFrameCallback(
(_) => setState(() {
_rescanningOnOpen = false;
_lelantusRescanRecovery = false;
}),
);
} else {
// show error message dialog w/ options
if (mounted) {
final shouldRetry = await Navigator.of(context).pushNamed(
FiroRescanRecoveryErrorView.routeName,
arguments: widget.walletId,
);
if (shouldRetry is bool && shouldRetry) {
await _firoRescanRecovery();
}
} else {
return await _firoRescanRecovery();
}
}
}
@override
void initState() {
controller = TextEditingController();
@ -124,7 +159,13 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
_shouldDisableAutoSyncOnLogOut = false;
}
if (ref.read(managerProvider).coin != Coin.ethereum &&
if (ref.read(managerProvider).coin == Coin.firo &&
(ref.read(managerProvider).wallet as FiroWallet)
.lelantusCoinIsarRescanRequired) {
_rescanningOnOpen = true;
_lelantusRescanRecovery = true;
_firoRescanRecovery();
} else if (ref.read(managerProvider).coin != Coin.ethereum &&
ref.read(managerProvider).rescanOnOpenVersion == Constants.rescanV1) {
_rescanningOnOpen = true;
ref.read(managerProvider).fullRescan(20, 1000).then(
@ -172,83 +213,86 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
subMessage: "This only needs to run once per wallet",
eventBus: null,
textColor: Theme.of(context).extension<StackColors>()!.textDark,
actionButton: SecondaryButton(
label: "Skip",
buttonHeight: ButtonHeight.l,
onPressed: () async {
await showDialog<void>(
context: context,
builder: (context) => DesktopDialog(
maxWidth: 500,
maxHeight: double.infinity,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(left: 32),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
actionButton: _lelantusRescanRecovery
? null
: SecondaryButton(
label: "Skip",
buttonHeight: ButtonHeight.l,
onPressed: () async {
await showDialog<void>(
context: context,
builder: (context) => DesktopDialog(
maxWidth: 500,
maxHeight: double.infinity,
child: Column(
children: [
Text(
"Warning!",
style: STextStyles.desktopH3(context),
Padding(
padding: const EdgeInsets.only(left: 32),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"Warning!",
style: STextStyles.desktopH3(context),
),
const DesktopDialogCloseButton(),
],
),
),
const DesktopDialogCloseButton(),
],
),
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 32),
child: Text(
"Skipping this process can completely"
" break your wallet. It is only meant to be done in"
" emergency situations where the migration fails"
" and will not let you continue. Still skip?",
style: STextStyles.desktopTextSmall(context),
),
),
const SizedBox(
height: 32,
),
Padding(
padding: const EdgeInsets.all(32),
child: Row(
children: [
Expanded(
child: SecondaryButton(
label: "Cancel",
buttonHeight: ButtonHeight.l,
onPressed: Navigator.of(context,
rootNavigator: true)
.pop,
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 32),
child: Text(
"Skipping this process can completely"
" break your wallet. It is only meant to be done in"
" emergency situations where the migration fails"
" and will not let you continue. Still skip?",
style:
STextStyles.desktopTextSmall(context),
),
),
const SizedBox(
width: 16,
height: 32,
),
Expanded(
child: PrimaryButton(
label: "Ok",
buttonHeight: ButtonHeight.l,
onPressed: () {
Navigator.of(context,
rootNavigator: true)
.pop();
setState(
() => _rescanningOnOpen = false);
},
Padding(
padding: const EdgeInsets.all(32),
child: Row(
children: [
Expanded(
child: SecondaryButton(
label: "Cancel",
buttonHeight: ButtonHeight.l,
onPressed: Navigator.of(context,
rootNavigator: true)
.pop,
),
),
const SizedBox(
width: 16,
),
Expanded(
child: PrimaryButton(
label: "Ok",
buttonHeight: ButtonHeight.l,
onPressed: () {
Navigator.of(context,
rootNavigator: true)
.pop();
setState(() =>
_rescanningOnOpen = false);
},
),
),
],
),
),
)
],
),
)
],
),
),
);
},
),
);
},
),
),
)
],