@@ -23,6 +23,7 @@ import '../../utilities/assets.dart';
2323import '../../utilities/constants.dart' ;
2424import '../../utilities/show_loading.dart' ;
2525import '../../utilities/text_styles.dart' ;
26+ import '../../wallets/crypto_currency/coins/firo.dart' ;
2627import '../../wallets/isar/providers/wallet_info_provider.dart' ;
2728import '../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart' ;
2829import '../../widgets/background.dart' ;
@@ -59,6 +60,7 @@ class _BuySparkNameViewState extends ConsumerState<BuySparkNameView> {
5960 String get _title => isRenewal ? "Renew name" : "Buy name" ;
6061
6162 int _years = 1 ;
63+ late bool _buttonEnabled;
6264
6365 bool _lockAddressFill = false ;
6466 Future <void > _fillCurrentReceiving () async {
@@ -80,9 +82,21 @@ class _BuySparkNameViewState extends ConsumerState<BuySparkNameView> {
8082 }
8183
8284 Future <TxData > _preRegFuture () async {
85+ final chosenAddress = addressController.text;
86+
87+ if (chosenAddress.isEmpty) {
88+ throw Exception (
89+ "Please select the Spark address you want to link to your Spark Name" ,
90+ );
91+ }
92+
8393 final wallet =
8494 ref.read (pWallets).getWallet (widget.walletId) as SparkInterface ;
8595
96+ if (! (wallet.cryptoCurrency as Firo ).validateSparkAddress (chosenAddress)) {
97+ throw Exception ("Invalid Spark address selected" );
98+ }
99+
86100 final myAddresses =
87101 await wallet.mainDB.isar.addresses
88102 .where ()
@@ -94,10 +108,8 @@ class _BuySparkNameViewState extends ConsumerState<BuySparkNameView> {
94108 .valueProperty ()
95109 .findAll ();
96110
97- final chosenAddress = addressController.text;
98-
99111 if (! myAddresses.contains (chosenAddress)) {
100- throw Exception ("Address does not belong to this wallet" );
112+ throw Exception ("Selected Spark address does not belong to this wallet" );
101113 }
102114
103115 final txData = await wallet.prepareSparkNameTransaction (
@@ -174,10 +186,19 @@ class _BuySparkNameViewState extends ConsumerState<BuySparkNameView> {
174186 @override
175187 void initState () {
176188 super .initState ();
189+
177190 if (isRenewal) {
178191 additionalInfoController.text = widget.nameToRenew! .additionalInfo ?? "" ;
179192 addressController.text = widget.nameToRenew! .address;
180193 }
194+ _buttonEnabled = addressController.text.isNotEmpty;
195+ addressController.addListener (() {
196+ if (mounted) {
197+ setState (() {
198+ _buttonEnabled = addressController.text.isNotEmpty;
199+ });
200+ }
201+ });
181202 }
182203
183204 @override
@@ -274,7 +295,7 @@ class _BuySparkNameViewState extends ConsumerState<BuySparkNameView> {
274295 mainAxisAlignment: MainAxisAlignment .spaceBetween,
275296 children: [
276297 Text (
277- "Address " ,
298+ "Spark address " ,
278299 style:
279300 Util .isDesktop
280301 ? STextStyles .w500_14 (context).copyWith (
@@ -311,7 +332,7 @@ class _BuySparkNameViewState extends ConsumerState<BuySparkNameView> {
311332 isDense: true ,
312333 contentPadding: const EdgeInsets .all (16 ),
313334 hintStyle: STextStyles .fieldLabel (context),
314- hintText: "Address " ,
335+ hintText: "Spark address (required) " ,
315336 border: InputBorder .none,
316337 enabledBorder: InputBorder .none,
317338 focusedBorder: InputBorder .none,
@@ -360,7 +381,7 @@ class _BuySparkNameViewState extends ConsumerState<BuySparkNameView> {
360381 isDense: true ,
361382 contentPadding: const EdgeInsets .all (16 ),
362383 hintStyle: STextStyles .fieldLabel (context),
363- hintText: "Additional info" ,
384+ hintText: "Additional info (optional) " ,
364385 border: InputBorder .none,
365386 enabledBorder: InputBorder .none,
366387 focusedBorder: InputBorder .none,
@@ -516,7 +537,8 @@ class _BuySparkNameViewState extends ConsumerState<BuySparkNameView> {
516537 PrimaryButton (
517538 label: isRenewal ? "Renew" : "Buy" ,
518539 buttonHeight: Util .isDesktop ? ButtonHeight .l : null ,
519- onPressed: _prepareNameTx,
540+ enabled: _buttonEnabled,
541+ onPressed: _buttonEnabled ? _prepareNameTx : null ,
520542 ),
521543 SizedBox (height: Util .isDesktop ? 32 : 16 ),
522544 ],
0 commit comments