@@ -36,12 +36,13 @@ import '../../../widgets/desktop/desktop_app_bar.dart';
3636import '../../../widgets/desktop/desktop_scaffold.dart' ;
3737import '../../../widgets/desktop/primary_button.dart' ;
3838import '../../../widgets/stack_text_field.dart' ;
39- import '../../../widgets/toggle .dart' ;
39+ import '../../../widgets/options .dart' ;
4040import '../../home_view/home_view.dart' ;
4141import 'confirm_recovery_dialog.dart' ;
4242import 'sub_widgets/restore_failed_dialog.dart' ;
4343import 'sub_widgets/restore_succeeded_dialog.dart' ;
4444import 'sub_widgets/restoring_dialog.dart' ;
45+ import '../../../wallets/wallet/impl/firo_wallet.dart' ;
4546
4647class RestoreViewOnlyWalletView extends ConsumerStatefulWidget {
4748 const RestoreViewOnlyWalletView ({
@@ -68,13 +69,13 @@ class _RestoreViewOnlyWalletViewState
6869 extends ConsumerState <RestoreViewOnlyWalletView > {
6970 late final TextEditingController addressController;
7071 late final TextEditingController viewKeyController;
72+ late final TextEditingController sparkViewKeyController;
7173
72- late String _currentDropDownValue ;
74+ late ViewOnlyWalletType _walletType ;
7375
7476 bool _enableRestoreButton = false ;
75- bool _addressOnly = false ;
76-
7777 bool _buttonLock = false ;
78+ late String _currentDropDownValue;
7879
7980 Future <void > _requestRestore () async {
8081 if (_buttonLock) return ;
@@ -107,21 +108,16 @@ class _RestoreViewOnlyWalletViewState
107108 WalletInfoKeys .isViewOnlyKey: true ,
108109 };
109110
110- final ViewOnlyWalletType viewOnlyWalletType;
111+ ViewOnlyWalletType viewOnlyWalletType = _walletType ;
111112 if (widget.coin is Bip39HDCurrency ) {
112- viewOnlyWalletType =
113- _addressOnly
114- ? ViewOnlyWalletType .addressOnly
115- : ViewOnlyWalletType .xPub;
116113 } else if (widget.coin is CryptonoteCurrency ) {
117114 viewOnlyWalletType = ViewOnlyWalletType .cryptonote;
118115 } else {
119116 throw Exception (
120117 "Unsupported view only wallet currency type found: ${widget .coin .runtimeType }" ,
121118 );
122119 }
123- otherDataJson[WalletInfoKeys .viewOnlyTypeIndexKey] =
124- viewOnlyWalletType.index;
120+ otherDataJson[WalletInfoKeys .viewOnlyTypeIndexKey] = _walletType.index;
125121
126122 if (! Platform .isLinux && ! Util .isDesktop) await WakelockPlus .enable ();
127123
@@ -192,6 +188,16 @@ class _RestoreViewOnlyWalletViewState
192188 ],
193189 );
194190 break ;
191+
192+ case ViewOnlyWalletType .spark:
193+ if (sparkViewKeyController.text.isEmpty) {
194+ throw Exception ("Spark View Key is empty" );
195+ }
196+ viewOnlyData = SparkViewOnlyWalletData (
197+ walletId: info.walletId,
198+ viewKey: sparkViewKeyController.text,
199+ );
200+ break ;
195201 }
196202
197203 var node = ref
@@ -237,6 +243,10 @@ class _RestoreViewOnlyWalletViewState
237243 await (wallet as XelisWallet ).init (isRestore: true );
238244 break ;
239245
246+ case const (FiroWallet ):
247+ await (wallet as FiroWallet ).init ();
248+ break ;
249+
240250 default :
241251 await wallet.init ();
242252 }
@@ -314,19 +324,23 @@ class _RestoreViewOnlyWalletViewState
314324 super .initState ();
315325 addressController = TextEditingController ();
316326 viewKeyController = TextEditingController ();
327+ sparkViewKeyController = TextEditingController ();
317328
318329 if (widget.coin is Bip39HDCurrency ) {
319- _currentDropDownValue =
320- (widget.coin as Bip39HDCurrency )
321- .supportedHardenedDerivationPaths
322- .last;
330+ _currentDropDownValue = (widget.coin as Bip39HDCurrency )
331+ .supportedHardenedDerivationPaths
332+ .last;
333+ _walletType = ViewOnlyWalletType .xPub;
334+ } else if (widget.coin is CryptonoteCurrency ) {
335+ _walletType = ViewOnlyWalletType .cryptonote;
323336 }
324337 }
325338
326339 @override
327340 void dispose () {
328341 addressController.dispose ();
329342 viewKeyController.dispose ();
343+ sparkViewKeyController.dispose ();
330344 super .dispose ();
331345 }
332346
@@ -393,23 +407,25 @@ class _RestoreViewOnlyWalletViewState
393407 if (isElectrumX)
394408 SizedBox (
395409 height: isDesktop ? 56 : 48 ,
396- width: isDesktop ? 490 : null ,
397- child: Toggle (
410+ width: isDesktop ? 490 : double .infinity ,
411+ child: Options (
398412 key: UniqueKey (),
399- onText: "Extended pub key" ,
400- offText: "Single address" ,
401- onColor:
402- Theme .of (
403- context,
404- ).extension < StackColors > ()! .popupBG,
405- offColor:
406- Theme .of (context)
407- .extension < StackColors > ()!
408- .textFieldDefaultBG,
409- isOn: _addressOnly,
413+ texts: [
414+ "Single address" ,
415+ "Extended pub key" ,
416+ if (widget.coin is Firo )
417+ isDesktop ? "Spark View Key" : "View Key"
418+ ],
419+ onColor: Theme .of (context)
420+ .extension < StackColors > ()!
421+ .popupBG,
422+ offColor: Theme .of (context)
423+ .extension < StackColors > ()!
424+ .textFieldDefaultBG,
425+ selectedIndex: _walletType.index- 1 ,
410426 onValueChanged: (value) {
411427 setState (() {
412- _addressOnly = value;
428+ _walletType = ViewOnlyWalletType .values[ value+ 1 ] ;
413429 });
414430 },
415431 decoration: BoxDecoration (
@@ -420,8 +436,10 @@ class _RestoreViewOnlyWalletViewState
420436 ),
421437 ),
422438 ),
423- SizedBox (height: isDesktop ? 24 : 16 ),
424- if (! isElectrumX || _addressOnly)
439+ SizedBox (
440+ height: isDesktop ? 24 : 16 ,
441+ ),
442+ if (! isElectrumX || _walletType == ViewOnlyWalletType .addressOnly)
425443 FullTextField (
426444 key: const Key ("viewOnlyAddressRestoreFieldKey" ),
427445 label: "Address" ,
@@ -441,8 +459,11 @@ class _RestoreViewOnlyWalletViewState
441459 }
442460 },
443461 ),
444- if (! isElectrumX) SizedBox (height: isDesktop ? 16 : 12 ),
445- if (isElectrumX && ! _addressOnly)
462+ if (! isElectrumX)
463+ SizedBox (
464+ height: isDesktop ? 16 : 12 ,
465+ ),
466+ if (isElectrumX && _walletType == ViewOnlyWalletType .xPub)
446467 DropdownButtonHideUnderline (
447468 child: DropdownButton2 <String >(
448469 value: _currentDropDownValue,
@@ -513,9 +534,11 @@ class _RestoreViewOnlyWalletViewState
513534 ),
514535 ),
515536 ),
516- if (isElectrumX && ! _addressOnly)
517- SizedBox (height: isDesktop ? 16 : 12 ),
518- if (! isElectrumX || ! _addressOnly)
537+ if (isElectrumX && _walletType == ViewOnlyWalletType .xPub)
538+ SizedBox (
539+ height: isDesktop ? 16 : 12 ,
540+ ),
541+ if (! isElectrumX || _walletType == ViewOnlyWalletType .xPub)
519542 FullTextField (
520543 key: const Key ("viewOnlyKeyRestoreFieldKey" ),
521544 label:
@@ -536,6 +559,21 @@ class _RestoreViewOnlyWalletViewState
536559 }
537560 },
538561 ),
562+ if (_walletType == ViewOnlyWalletType .spark)
563+ SizedBox (
564+ height: isDesktop ? 16 : 12 ,
565+ ),
566+ if (_walletType == ViewOnlyWalletType .spark)
567+ FullTextField (
568+ key: const Key ("viewOnlySparkViewKeyRestoreFieldKey" ),
569+ label: "Spark View Key" ,
570+ controller: sparkViewKeyController,
571+ onChanged: (value) {
572+ setState (() {
573+ _enableRestoreButton = value.isNotEmpty;
574+ });
575+ },
576+ ),
539577 if (! isDesktop) const Spacer (),
540578 SizedBox (height: isDesktop ? 24 : 16 ),
541579 PrimaryButton (
0 commit comments