@@ -35,7 +35,7 @@ import '../../../widgets/desktop/desktop_app_bar.dart';
3535import '../../../widgets/desktop/desktop_scaffold.dart' ;
3636import '../../../widgets/desktop/primary_button.dart' ;
3737import '../../../widgets/stack_text_field.dart' ;
38- import '../../../widgets/toggle .dart' ;
38+ import '../../../widgets/options .dart' ;
3939import '../../home_view/home_view.dart' ;
4040import 'confirm_recovery_dialog.dart' ;
4141import 'sub_widgets/restore_failed_dialog.dart' ;
@@ -67,13 +67,13 @@ class _RestoreViewOnlyWalletViewState
6767 extends ConsumerState <RestoreViewOnlyWalletView > {
6868 late final TextEditingController addressController;
6969 late final TextEditingController viewKeyController;
70+ late final TextEditingController sparkViewKeyController;
7071
71- late String _currentDropDownValue ;
72+ late ViewOnlyWalletType _walletType ;
7273
7374 bool _enableRestoreButton = false ;
74- bool _addressOnly = false ;
75-
7675 bool _buttonLock = false ;
76+ late String _currentDropDownValue;
7777
7878 Future <void > _requestRestore () async {
7979 if (_buttonLock) return ;
@@ -106,20 +106,16 @@ class _RestoreViewOnlyWalletViewState
106106 WalletInfoKeys .isViewOnlyKey: true ,
107107 };
108108
109- final ViewOnlyWalletType viewOnlyWalletType;
109+ ViewOnlyWalletType viewOnlyWalletType = _walletType ;
110110 if (widget.coin is Bip39HDCurrency ) {
111- viewOnlyWalletType = _addressOnly
112- ? ViewOnlyWalletType .addressOnly
113- : ViewOnlyWalletType .xPub;
114111 } else if (widget.coin is CryptonoteCurrency ) {
115112 viewOnlyWalletType = ViewOnlyWalletType .cryptonote;
116113 } else {
117114 throw Exception (
118115 "Unsupported view only wallet currency type found: ${widget .coin .runtimeType }" ,
119116 );
120117 }
121- otherDataJson[WalletInfoKeys .viewOnlyTypeIndexKey] =
122- viewOnlyWalletType.index;
118+ otherDataJson[WalletInfoKeys .viewOnlyTypeIndexKey] = _walletType.index;
123119
124120 if (! Platform .isLinux && ! Util .isDesktop) await WakelockPlus .enable ();
125121
@@ -190,6 +186,16 @@ class _RestoreViewOnlyWalletViewState
190186 ],
191187 );
192188 break ;
189+
190+ case ViewOnlyWalletType .spark:
191+ if (sparkViewKeyController.text.isEmpty) {
192+ throw Exception ("Spark View Key is empty" );
193+ }
194+ viewOnlyData = SparkViewOnlyWalletData (
195+ walletId: info.walletId,
196+ viewKey: sparkViewKeyController.text,
197+ );
198+ break ;
193199 }
194200
195201 var node = ref
@@ -308,18 +314,23 @@ class _RestoreViewOnlyWalletViewState
308314 super .initState ();
309315 addressController = TextEditingController ();
310316 viewKeyController = TextEditingController ();
317+ sparkViewKeyController = TextEditingController ();
311318
312319 if (widget.coin is Bip39HDCurrency ) {
313320 _currentDropDownValue = (widget.coin as Bip39HDCurrency )
314321 .supportedHardenedDerivationPaths
315322 .last;
323+ _walletType = ViewOnlyWalletType .xPub;
324+ } else if (widget.coin is CryptonoteCurrency ) {
325+ _walletType = ViewOnlyWalletType .cryptonote;
316326 }
317327 }
318328
319329 @override
320330 void dispose () {
321331 addressController.dispose ();
322332 viewKeyController.dispose ();
333+ sparkViewKeyController.dispose ();
323334 super .dispose ();
324335 }
325336
@@ -384,21 +395,25 @@ class _RestoreViewOnlyWalletViewState
384395 if (isElectrumX)
385396 SizedBox (
386397 height: isDesktop ? 56 : 48 ,
387- width: isDesktop ? 490 : null ,
388- child: Toggle (
398+ width: isDesktop ? 490 : double .infinity ,
399+ child: Options (
389400 key: UniqueKey (),
390- onText: "Extended pub key" ,
391- offText: "Single address" ,
392- onColor: Theme .of (
393- context,
394- ).extension < StackColors > ()! .popupBG,
395- offColor: Theme .of (
396- context,
397- ).extension < StackColors > ()! .textFieldDefaultBG,
398- isOn: _addressOnly,
401+ texts: [
402+ "Single address" ,
403+ "Extended pub key" ,
404+ if (widget.coin is Firo )
405+ isDesktop ? "Spark View Key" : "View Key"
406+ ],
407+ onColor: Theme .of (context)
408+ .extension < StackColors > ()!
409+ .popupBG,
410+ offColor: Theme .of (context)
411+ .extension < StackColors > ()!
412+ .textFieldDefaultBG,
413+ selectedIndex: _walletType.index- 1 ,
399414 onValueChanged: (value) {
400415 setState (() {
401- _addressOnly = value;
416+ _walletType = ViewOnlyWalletType .values[ value+ 1 ] ;
402417 });
403418 },
404419 decoration: BoxDecoration (
@@ -409,8 +424,10 @@ class _RestoreViewOnlyWalletViewState
409424 ),
410425 ),
411426 ),
412- SizedBox (height: isDesktop ? 24 : 16 ),
413- if (! isElectrumX || _addressOnly)
427+ SizedBox (
428+ height: isDesktop ? 24 : 16 ,
429+ ),
430+ if (! isElectrumX || _walletType == ViewOnlyWalletType .addressOnly)
414431 FullTextField (
415432 key: const Key ("viewOnlyAddressRestoreFieldKey" ),
416433 label: "Address" ,
@@ -430,8 +447,11 @@ class _RestoreViewOnlyWalletViewState
430447 }
431448 },
432449 ),
433- if (! isElectrumX) SizedBox (height: isDesktop ? 16 : 12 ),
434- if (isElectrumX && ! _addressOnly)
450+ if (! isElectrumX)
451+ SizedBox (
452+ height: isDesktop ? 16 : 12 ,
453+ ),
454+ if (isElectrumX && _walletType == ViewOnlyWalletType .xPub)
435455 DropdownButtonHideUnderline (
436456 child: DropdownButton2 <String >(
437457 value: _currentDropDownValue,
@@ -499,9 +519,11 @@ class _RestoreViewOnlyWalletViewState
499519 ),
500520 ),
501521 ),
502- if (isElectrumX && ! _addressOnly)
503- SizedBox (height: isDesktop ? 16 : 12 ),
504- if (! isElectrumX || ! _addressOnly)
522+ if (isElectrumX && _walletType == ViewOnlyWalletType .xPub)
523+ SizedBox (
524+ height: isDesktop ? 16 : 12 ,
525+ ),
526+ if (! isElectrumX || _walletType == ViewOnlyWalletType .xPub)
505527 FullTextField (
506528 key: const Key ("viewOnlyKeyRestoreFieldKey" ),
507529 label:
@@ -522,6 +544,21 @@ class _RestoreViewOnlyWalletViewState
522544 }
523545 },
524546 ),
547+ if (_walletType == ViewOnlyWalletType .spark)
548+ SizedBox (
549+ height: isDesktop ? 16 : 12 ,
550+ ),
551+ if (_walletType == ViewOnlyWalletType .spark)
552+ FullTextField (
553+ key: const Key ("viewOnlySparkViewKeyRestoreFieldKey" ),
554+ label: "Spark View Key" ,
555+ controller: sparkViewKeyController,
556+ onChanged: (value) {
557+ setState (() {
558+ _enableRestoreButton = value.isNotEmpty;
559+ });
560+ },
561+ ),
525562 if (! isDesktop) const Spacer (),
526563 SizedBox (height: isDesktop ? 24 : 16 ),
527564 PrimaryButton (
0 commit comments