@@ -3,6 +3,7 @@ import 'dart:async';
33import 'package:cake_wallet/core/execution_state.dart' ;
44import 'package:cake_wallet/generated/i18n.dart' ;
55import 'package:cake_wallet/src/screens/send/send_page.dart' ;
6+ import 'package:cake_wallet/src/widgets/base_text_form_field.dart' ;
67import 'package:cake_wallet/src/widgets/primary_button.dart' ;
78import 'package:cake_wallet/view_model/send/send_view_model_state.dart' ;
89import 'package:cw_core/crypto_currency.dart' ;
@@ -146,27 +147,59 @@ class SendPageRobot {
146147 await commonTestCases.defaultSleepTime ();
147148 }
148149
149- Future <void > enterAmount (String amount) async {
150- await commonTestCases.enterText (amount, 'send_page_amount_textfield_key' );
150+ Future <void > enterSendAmount (String amount, {bool isFiat = false }) async {
151+ await commonTestCases.enterText (
152+ amount,
153+ isFiat ? 'send_page_fiat_amount_textfield_key' : 'send_page_amount_textfield_key' ,
154+ );
155+ }
156+
157+ String _getTextFromField (ValueKey <String > key) {
158+ final field = find.byKey (key);
159+ if (! field.tryEvaluate ()) return '' ;
160+ final baseTextFormField = tester.widget <BaseTextFormField >(field);
161+ return baseTextFormField.controller? .text ?? '' ;
151162 }
152163
153- Future <void > validateWalletBalance () async {
164+ /// Validates wallet balance for $1 send by checking against the converted crypto amount
165+ /// Returns true if wallet has sufficient balance, false otherwise
166+ Future <bool > validateWalletBalanceForOneDollarSend () async {
154167 SendPage sendPage = tester.widget (find.byType (SendPage ));
155168 final sendViewModel = sendPage.sendViewModel;
156169
157170 final balance = await sendViewModel.sendingBalance;
158- final amount = double .tryParse (CommonTestConstants .sendTestAmount) ?? 0.0 ;
159171
160- tester.printToConsole ('Wallet balance: $balance , sending amount: $amount ' );
172+ await setupOneDollarSend ();
173+
174+ // Get the crypto amount that was set for the $1 send
175+ String cryptoAmount = _getTextFromField (ValueKey ('send_page_amount_textfield_key' ));
176+ if (cryptoAmount.isEmpty || cryptoAmount == '0' || cryptoAmount == '0.0' ) {
177+ cryptoAmount = '0.001' ; // fallback amount
178+ }
179+
180+ final amount = double .tryParse (cryptoAmount) ?? 0.0 ;
181+
182+ tester.printToConsole (
183+ 'Wallet balance: $balance , sending amount for \$ ${CommonTestConstants .sendTestFiatAmount }: $cryptoAmount ' ,
184+ );
161185
162186 if (balance.isEmpty || double .tryParse (balance) == null ) {
163- throw Exception ('Invalid wallet balance: $balance ' );
187+ tester.printToConsole ('Invalid wallet balance: $balance ' );
188+ return false ;
164189 }
165190
166191 final balanceValue = double .parse (balance);
167192 if (balanceValue < amount) {
168- throw Exception ('Insufficient balance: $balanceValue < $amount ' );
193+ tester.printToConsole (
194+ 'Insufficient balance for \$ ${CommonTestConstants .sendTestFiatAmount } send: $balanceValue < $amount ' ,
195+ );
196+ return false ;
169197 }
198+
199+ tester.printToConsole (
200+ 'Wallet has sufficient balance for \$ ${CommonTestConstants .sendTestFiatAmount } send' ,
201+ );
202+ return true ;
170203 }
171204
172205 Future <void > selectTransactionPriority ({TransactionPriority ? priority}) async {
@@ -596,4 +629,92 @@ class SendPageRobot {
596629 await commonTestCases.defaultSleepTime ();
597630 }
598631 }
632+
633+ //* ---- Fiat/Crypto Amount Validation -----
634+ Future <void > testFiatAmountEntry () async {
635+ tester.printToConsole ('Testing fiat amount entry...' );
636+
637+ await enterSendAmount ('' );
638+ await enterSendAmount ('' , isFiat: true );
639+ await commonTestCases.defaultSleepTime ();
640+
641+ await enterSendAmount (CommonTestConstants .sendTestFiatAmount, isFiat: true );
642+ await commonTestCases.defaultSleepTime ();
643+
644+ // Wait for conversion to complete
645+ await tester.pump (Duration (seconds: 3 ));
646+ await tester.pumpAndSettle ();
647+
648+ // Next we get the crypto amount value and validate it's not 0
649+ final cryptoAmount = _getTextFromField (ValueKey ('send_page_amount_textfield_key' ));
650+
651+ tester.printToConsole (
652+ 'Crypto amount after entering \$ ${CommonTestConstants .sendTestFiatAmount }: $cryptoAmount ' ,
653+ );
654+
655+ if (cryptoAmount.isNotEmpty && cryptoAmount != '0' && cryptoAmount != '0.0' ) {
656+ tester.printToConsole ('Fiat to crypto conversion working - crypto amount: $cryptoAmount ' );
657+ } else {
658+ tester.printToConsole (
659+ 'Fiat to crypto conversion may not be working - crypto amount: $cryptoAmount ' ,
660+ );
661+ }
662+ }
663+
664+ Future <void > testCryptoAmountEntry () async {
665+ tester.printToConsole ('Testing crypto amount entry...' );
666+
667+ await enterSendAmount ('' );
668+ await enterSendAmount ('' , isFiat: true );
669+ await commonTestCases.defaultSleepTime ();
670+
671+ String cryptoAmount = '0.001' ;
672+
673+ await enterSendAmount (cryptoAmount);
674+ await commonTestCases.defaultSleepTime ();
675+
676+ // Wait for conversion to complete
677+ await tester.pump (Duration (seconds: 3 ));
678+ await tester.pumpAndSettle ();
679+
680+ // Get the fiat amount value and validate it's not 0
681+ final fiatAmount = _getTextFromField (ValueKey ('send_page_fiat_amount_textfield_key' ));
682+
683+ tester.printToConsole ('Fiat amount after entering $cryptoAmount : $fiatAmount ' );
684+
685+ if (fiatAmount.isNotEmpty && fiatAmount != '0' && fiatAmount != '0.0' ) {
686+ tester.printToConsole ('Crypto to fiat conversion working, fiat amount: $fiatAmount ' );
687+ } else {
688+ tester.printToConsole (
689+ 'Crypto to fiat conversion may not be working - fiat amount: $fiatAmount ' );
690+ }
691+ }
692+
693+ Future <void > setupOneDollarSend () async {
694+ // Clear existing amounts
695+ await enterSendAmount ('' );
696+ await enterSendAmount ('' , isFiat: true );
697+ await commonTestCases.defaultSleepTime ();
698+
699+ await enterSendAmount (CommonTestConstants .sendTestFiatAmount, isFiat: true );
700+ await commonTestCases.defaultSleepTime ();
701+
702+ // Wait for conversion to complete
703+ await tester.pump (Duration (seconds: 3 ));
704+ await tester.pumpAndSettle ();
705+
706+ // Get the converted crypto amount
707+ String cryptoAmount = _getTextFromField (ValueKey ('send_page_amount_textfield_key' ));
708+ if (cryptoAmount.isEmpty || cryptoAmount == '0' || cryptoAmount == '0.0' ) {
709+ cryptoAmount = '0.001' ; // fallback amount
710+ }
711+
712+ tester.printToConsole (
713+ 'Sending $cryptoAmount (equivalent to \$ ${CommonTestConstants .sendTestFiatAmount }) to test wallet' ,
714+ );
715+
716+ // Update the amount field with the converted value
717+ await enterSendAmount (cryptoAmount);
718+ await commonTestCases.defaultSleepTime ();
719+ }
599720}
0 commit comments