1010
1111import 'package:flutter/material.dart' ;
1212import 'package:flutter_riverpod/flutter_riverpod.dart' ;
13+ import 'package:stack_wallet_backup/secure_storage.dart' ;
1314import 'package:tuple/tuple.dart' ;
1415
1516import '../../../../app_config.dart' ;
1617import '../../../../pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/delete_view_only_wallet_keys_view.dart' ;
1718import '../../../../providers/global/wallets_provider.dart' ;
19+ import '../../../../route_generator.dart' ;
1820import '../../../../themes/stack_colors.dart' ;
21+ import '../../../../utilities/logger.dart' ;
1922import '../../../../utilities/text_styles.dart' ;
2023import '../../../../wallets/wallet/wallet_mixin_interfaces/mnemonic_interface.dart' ;
2124import '../../../../wallets/wallet/wallet_mixin_interfaces/view_only_option_interface.dart' ;
@@ -24,13 +27,11 @@ import '../../../../widgets/desktop/desktop_dialog_close_button.dart';
2427import '../../../../widgets/desktop/primary_button.dart' ;
2528import '../../../../widgets/desktop/secondary_button.dart' ;
2629import '../../../../widgets/rounded_container.dart' ;
30+ import '../../../../widgets/rounded_white_container.dart' ;
2731import 'delete_wallet_keys_popup.dart' ;
2832
2933class DesktopAttentionDeleteWallet extends ConsumerStatefulWidget {
30- const DesktopAttentionDeleteWallet ({
31- super .key,
32- required this .walletId,
33- });
34+ const DesktopAttentionDeleteWallet ({super .key, required this .walletId});
3435
3536 final String walletId;
3637
@@ -55,10 +56,7 @@ class _DesktopAttentionDeleteWallet
5556 children: [
5657 DesktopDialogCloseButton (
5758 onPressedOverride: () {
58- Navigator .of (
59- context,
60- rootNavigator: true ,
61- ).pop ();
59+ Navigator .of (context, rootNavigator: true ).pop ();
6260 },
6361 ),
6462 ],
@@ -67,29 +65,27 @@ class _DesktopAttentionDeleteWallet
6765 padding: const EdgeInsets .symmetric (horizontal: 32 , vertical: 26 ),
6866 child: Column (
6967 children: [
70- Text (
71- "Attention!" ,
72- style: STextStyles .desktopH2 (context),
73- ),
74- const SizedBox (
75- height: 16 ,
76- ),
68+ Text ("Attention!" , style: STextStyles .desktopH2 (context)),
69+ const SizedBox (height: 16 ),
7770 RoundedContainer (
78- color: Theme .of (context)
79- .extension < StackColors > ()!
80- .snackBarBackError,
71+ color:
72+ Theme .of (
73+ context,
74+ ).extension < StackColors > ()! .snackBarBackError,
8175 child: Padding (
8276 padding: const EdgeInsets .all (10.0 ),
8377 child: Text (
8478 "You are going to permanently delete your wallet.\n\n If you delete your wallet, "
8579 "the only way you can have access to your funds is by using your backup key."
8680 "\n\n ${AppConfig .appName } does not keep nor is able to restore your backup key or your wallet."
8781 "\n\n PLEASE SAVE YOUR BACKUP KEY." ,
88- style: STextStyles .desktopTextExtraExtraSmall (context)
89- .copyWith (
90- color: Theme .of (context)
91- .extension < StackColors > ()!
92- .snackBarTextError,
82+ style: STextStyles .desktopTextExtraExtraSmall (
83+ context,
84+ ).copyWith (
85+ color:
86+ Theme .of (
87+ context,
88+ ).extension < StackColors > ()! .snackBarTextError,
9389 ),
9490 ),
9591 ),
@@ -103,10 +99,7 @@ class _DesktopAttentionDeleteWallet
10399 buttonHeight: ButtonHeight .xl,
104100 label: "Cancel" ,
105101 onPressed: () {
106- Navigator .of (
107- context,
108- rootNavigator: true ,
109- ).pop ();
102+ Navigator .of (context, rootNavigator: true ).pop ();
110103 },
111104 ),
112105 const SizedBox (width: 16 ),
@@ -115,71 +108,96 @@ class _DesktopAttentionDeleteWallet
115108 buttonHeight: ButtonHeight .xl,
116109 label: "View Backup Key" ,
117110 onPressed: () async {
118- final wallet =
119- ref.read (pWallets).getWallet (widget.walletId);
111+ try {
112+ final wallet = ref
113+ .read (pWallets)
114+ .getWallet (widget.walletId);
120115
121- if (wallet is ViewOnlyOptionInterface &&
122- wallet.isViewOnly) {
123- final data = await wallet.getViewOnlyWalletData ();
124- if (context.mounted) {
125- await Navigator .of (context).push (
126- MaterialPageRoute <void >(
127- builder: (builder) => DesktopDialog (
128- maxWidth: 614 ,
129- maxHeight: double .infinity,
130- child: Column (
131- children: [
132- Row (
133- mainAxisAlignment:
134- MainAxisAlignment .spaceBetween,
135- children: [
136- Padding (
137- padding: const EdgeInsets .only (
138- left: 32 ,
116+ if (wallet is ViewOnlyOptionInterface &&
117+ wallet.isViewOnly) {
118+ final data = await wallet.getViewOnlyWalletData ();
119+ if (context.mounted) {
120+ await Navigator .of (context).push (
121+ MaterialPageRoute <void >(
122+ builder:
123+ (builder) => DesktopDialog (
124+ maxWidth: 614 ,
125+ maxHeight: double .infinity,
126+ child: Column (
127+ children: [
128+ Row (
129+ mainAxisAlignment:
130+ MainAxisAlignment
131+ .spaceBetween,
132+ children: [
133+ Padding (
134+ padding:
135+ const EdgeInsets .only (
136+ left: 32 ,
137+ ),
138+ child: Text (
139+ "Wallet keys" ,
140+ style:
141+ STextStyles .desktopH3 (
142+ context,
143+ ),
144+ ),
145+ ),
146+ DesktopDialogCloseButton (
147+ onPressedOverride: () {
148+ Navigator .of (
149+ context,
150+ rootNavigator: true ,
151+ ).pop ();
152+ },
153+ ),
154+ ],
139155 ),
140- child: Text (
141- "Wallet keys" ,
142- style: STextStyles .desktopH3 (
143- context,
144- ),
156+ Padding (
157+ padding: const EdgeInsets .all (32 ),
158+ child:
159+ DeleteViewOnlyWalletKeysView (
160+ walletId: widget.walletId,
161+ data: data,
162+ ),
145163 ),
146- ),
147- DesktopDialogCloseButton (
148- onPressedOverride: () {
149- Navigator .of (
150- context,
151- rootNavigator: true ,
152- ).pop ();
153- },
154- ),
155- ],
156- ),
157- Padding (
158- padding: const EdgeInsets .all (32 ),
159- child: DeleteViewOnlyWalletKeysView (
160- walletId: widget.walletId,
161- data: data,
164+ ],
162165 ),
163166 ),
164- ],
165- ),
166167 ),
167- ),
168- );
169- }
170- } else
168+ );
169+ }
170+ } else
171+ // TODO: [prio=med] handle other types wallet deletion
172+ // All wallets currently are mnemonic based
173+ if (wallet is MnemonicInterface ) {
174+ final words = await wallet.getMnemonicAsWords ();
171175
172- // TODO: [prio=med] handle other types wallet deletion
173- // All wallets currently are mnemonic based
174- if (wallet is MnemonicInterface ) {
175- final words = await wallet.getMnemonicAsWords ();
176+ if (context.mounted) {
177+ await Navigator .of (context).pushNamed (
178+ DeleteWalletKeysPopup .routeName,
179+ arguments: Tuple2 (widget.walletId, words),
180+ );
181+ }
182+ }
183+ } on BadDecryption catch (e, s) {
184+ Logging .instance.f (
185+ "Desktop wallet delete error. Showing decryption error continue dialog." ,
186+ error: e,
187+ stackTrace: s,
188+ );
176189
177190 if (context.mounted) {
178- await Navigator .of (context).pushNamed (
179- DeleteWalletKeysPopup .routeName,
180- arguments: Tuple2 (
181- widget.walletId,
182- words,
191+ await Navigator .of (context).push (
192+ RouteGenerator .getRoute (
193+ builder: (context) {
194+ return ErrorLoadingKeysDialog (
195+ walletId: widget.walletId,
196+ );
197+ },
198+ settings: const RouteSettings (
199+ name: "/desktopErrorLoadingKeysDialog" ,
200+ ),
183201 ),
184202 );
185203 }
@@ -196,3 +214,69 @@ class _DesktopAttentionDeleteWallet
196214 );
197215 }
198216}
217+
218+ class ErrorLoadingKeysDialog extends StatelessWidget {
219+ const ErrorLoadingKeysDialog ({super .key, required this .walletId});
220+
221+ final String walletId;
222+
223+ @override
224+ Widget build (BuildContext context) {
225+ return DesktopDialog (
226+ maxWidth: 614 ,
227+ maxHeight: double .infinity,
228+ child: Column (
229+ children: [
230+ Row (
231+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
232+ children: [
233+ Padding (
234+ padding: const EdgeInsets .only (left: 32 ),
235+ child: Text (
236+ "Decryption error" ,
237+ style: STextStyles .desktopH3 (context),
238+ ),
239+ ),
240+ DesktopDialogCloseButton (
241+ onPressedOverride: () {
242+ Navigator .of (context, rootNavigator: true ).pop ();
243+ },
244+ ),
245+ ],
246+ ),
247+ Padding (
248+ padding: const EdgeInsets .all (32 ),
249+ child: Column (
250+ crossAxisAlignment: CrossAxisAlignment .stretch,
251+ children: [
252+ RoundedWhiteContainer (
253+ child: Text (
254+ "Could not retrieve wallet keys/mnemonic phrase/seed.\n\n "
255+ "Are you certain you would like to continue with wallet deletion?" ,
256+ style: STextStyles .label (context).copyWith (fontSize: 16 ),
257+ ),
258+ ),
259+ const SizedBox (height: 40 ),
260+ PrimaryButton (
261+ label: "Continue" ,
262+ onPressed: () async {
263+ await Navigator .of (context).push (
264+ RouteGenerator .getRoute (
265+ builder: (context) {
266+ return ConfirmDelete (walletId: walletId);
267+ },
268+ settings: const RouteSettings (
269+ name: "/desktopConfirmDelete" ,
270+ ),
271+ ),
272+ );
273+ },
274+ ),
275+ ],
276+ ),
277+ ),
278+ ],
279+ ),
280+ );
281+ }
282+ }
0 commit comments