diff --git a/lib/features/account/account_balance_card.dart b/lib/features/account/account_balance_card.dart index 8a10d52f..24d19de2 100644 --- a/lib/features/account/account_balance_card.dart +++ b/lib/features/account/account_balance_card.dart @@ -1,7 +1,6 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:didpay/features/account/account_balance_notifier.dart'; import 'package:didpay/features/payment/payment_amount_page.dart'; -import 'package:didpay/features/payment/payment_amount_state.dart'; import 'package:didpay/features/payment/payment_state.dart'; import 'package:didpay/features/pfis/pfis_notifier.dart'; import 'package:didpay/features/transaction/transaction.dart'; @@ -111,10 +110,9 @@ class AccountBalanceCard extends HookConsumerWidget { child: FilledButton( onPressed: () => Navigator.of(context).push( MaterialPageRoute( - builder: (context) => PaymentAmountPage( + builder: (context) => const PaymentAmountPage( paymentState: PaymentState( transactionType: TransactionType.deposit, - paymentAmountState: PaymentAmountState(), ), ), fullscreenDialog: true, @@ -131,11 +129,9 @@ class AccountBalanceCard extends HookConsumerWidget { child: FilledButton( onPressed: () => Navigator.of(context).push( MaterialPageRoute( - builder: (context) => PaymentAmountPage( - paymentState: PaymentState( - transactionType: TransactionType.withdraw, - paymentAmountState: PaymentAmountState(), - ), + builder: (context) => const PaymentAmountPage( + paymentState: + PaymentState(transactionType: TransactionType.withdraw), ), fullscreenDialog: true, ), diff --git a/lib/features/countries/countries_page.dart b/lib/features/countries/countries_page.dart index f1fe82b6..192a5e82 100644 --- a/lib/features/countries/countries_page.dart +++ b/lib/features/countries/countries_page.dart @@ -1,7 +1,6 @@ import 'package:didpay/features/countries/countries.dart'; import 'package:didpay/features/countries/countries_notifier.dart'; import 'package:didpay/features/payment/payment_amount_page.dart'; -import 'package:didpay/features/payment/payment_amount_state.dart'; import 'package:didpay/features/payment/payment_state.dart'; import 'package:didpay/features/transaction/transaction.dart'; import 'package:didpay/l10n/app_localizations.dart'; @@ -37,10 +36,9 @@ class CountriesPage extends HookConsumerWidget { ? null : () => Navigator.of(context).push( MaterialPageRoute( - builder: (context) => PaymentAmountPage( + builder: (context) => const PaymentAmountPage( paymentState: PaymentState( transactionType: TransactionType.send, - paymentAmountState: PaymentAmountState(), ), ), ), diff --git a/lib/features/home/home_page.dart b/lib/features/home/home_page.dart index c56093b9..5e26c6c9 100644 --- a/lib/features/home/home_page.dart +++ b/lib/features/home/home_page.dart @@ -2,7 +2,6 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:didpay/features/account/account_balance_card.dart'; import 'package:didpay/features/did/did_provider.dart'; import 'package:didpay/features/payment/payment_amount_page.dart'; -import 'package:didpay/features/payment/payment_amount_state.dart'; import 'package:didpay/features/payment/payment_state.dart'; import 'package:didpay/features/pfis/pfi.dart'; import 'package:didpay/features/pfis/pfis_add_page.dart'; @@ -157,10 +156,9 @@ class HomePage extends HookConsumerWidget { MaterialPageRoute( builder: (context) => ref.read(pfisProvider).isEmpty ? const PfisAddPage() - : PaymentAmountPage( + : const PaymentAmountPage( paymentState: PaymentState( transactionType: TransactionType.deposit, - paymentAmountState: PaymentAmountState(), ), ), ), diff --git a/lib/features/payment/payment_amount_page.dart b/lib/features/payment/payment_amount_page.dart index 17319b71..65efe788 100644 --- a/lib/features/payment/payment_amount_page.dart +++ b/lib/features/payment/payment_amount_page.dart @@ -1,6 +1,7 @@ import 'package:didpay/features/payin/payin.dart'; import 'package:didpay/features/payment/payment_amount_state.dart'; import 'package:didpay/features/payment/payment_details_page.dart'; +import 'package:didpay/features/payment/payment_details_state.dart'; import 'package:didpay/features/payment/payment_fee_details.dart'; import 'package:didpay/features/payment/payment_method.dart'; import 'package:didpay/features/payment/payment_state.dart'; @@ -34,8 +35,9 @@ class PaymentAmountPage extends HookConsumerWidget { final keyPress = useState(NumberKeyPress(0, '')); final offerings = useState>>>(const AsyncLoading()); - final state = - useState(paymentState.paymentAmountState); + final state = useState( + paymentState.paymentAmountState ?? PaymentAmountState(), + ); useEffect( () { @@ -52,8 +54,8 @@ class PaymentAmountPage extends HookConsumerWidget { body: SafeArea( child: offerings.value.when( data: (offeringsMap) { - if (state.value?.offeringsMap == null) { - state.value = state.value?.copyWith( + if (state.value.offeringsMap == null) { + state.value = state.value.copyWith( pfiDid: offeringsMap.keys.first.did, selectedOffering: offeringsMap.values.first.first, offeringsMap: offeringsMap, @@ -128,28 +130,33 @@ class PaymentAmountPage extends HookConsumerWidget { ? null : () => Navigator.of(context).push( MaterialPageRoute( - builder: (context) => PaymentDetailsPage( - paymentState: paymentState.copyWith( - paymentAmountState: state.value, - paymentDetailsState: - paymentState.paymentDetailsState?.copyWith( - paymentCurrency: paymentState.transactionType == - TransactionType.deposit - ? state.value?.payinCurrency - : state.value?.payoutCurrency, - paymentMethods: paymentState.transactionType == - TransactionType.deposit - ? state - .value?.selectedOffering?.data.payin.methods - .map(PaymentMethod.fromPayinMethod) - .toList() - : state.value?.selectedOffering?.data.payout - .methods - .map(PaymentMethod.fromPayoutMethod) - .toList(), + builder: (context) { + final paymentDetailsState = + paymentState.paymentDetailsState ?? + PaymentDetailsState(); + + return PaymentDetailsPage( + paymentState: paymentState.copyWith( + paymentAmountState: state.value, + paymentDetailsState: paymentDetailsState.copyWith( + paymentCurrency: paymentState.transactionType == + TransactionType.deposit + ? state.value?.payinCurrency + : state.value?.payoutCurrency, + paymentMethods: paymentState.transactionType == + TransactionType.deposit + ? state.value?.selectedOffering?.data.payin + .methods + .map(PaymentMethod.fromPayinMethod) + .toList() + : state.value?.selectedOffering?.data.payout + .methods + .map(PaymentMethod.fromPayoutMethod) + .toList(), + ), ), - ), - ), + ); + }, ), ), ), diff --git a/lib/features/payment/payment_details_page.dart b/lib/features/payment/payment_details_page.dart index 5f1b9095..3b904196 100644 --- a/lib/features/payment/payment_details_page.dart +++ b/lib/features/payment/payment_details_page.dart @@ -34,9 +34,9 @@ class PaymentDetailsPage extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final rfq = useState?>(null); - final state = - useState(paymentState.paymentDetailsState!); - + final state = useState( + paymentState.paymentDetailsState ?? PaymentDetailsState(), + ); final availableMethods = state.value.filterPaymentMethods(state.value.selectedPaymentType); diff --git a/lib/features/send/send_page.dart b/lib/features/send/send_page.dart index c7d4e47c..1cb1837a 100644 --- a/lib/features/send/send_page.dart +++ b/lib/features/send/send_page.dart @@ -5,7 +5,6 @@ import 'package:didpay/features/feature_flags/feature_flag.dart'; import 'package:didpay/features/feature_flags/feature_flags_notifier.dart'; import 'package:didpay/features/feature_flags/lucid/lucid_offerings_page.dart'; import 'package:didpay/features/payment/payment_amount_page.dart'; -import 'package:didpay/features/payment/payment_amount_state.dart'; import 'package:didpay/features/payment/payment_details_state.dart'; import 'package:didpay/features/payment/payment_state.dart'; import 'package:didpay/features/transaction/transaction.dart'; @@ -57,7 +56,6 @@ class SendPage extends HookConsumerWidget { builder: (_) => PaymentAmountPage( paymentState: PaymentState( transactionType: TransactionType.send, - paymentAmountState: PaymentAmountState(), paymentDetailsState: PaymentDetailsState( paymentName: recipientDap.dap, moneyAddresses: moneyAddresses, diff --git a/lib/shared/next_button.dart b/lib/shared/next_button.dart index ef3acd79..d437aae8 100644 --- a/lib/shared/next_button.dart +++ b/lib/shared/next_button.dart @@ -11,7 +11,8 @@ class NextButton extends HookWidget { @override Widget build(BuildContext context) => Padding( - padding: const EdgeInsets.symmetric(horizontal: Grid.side), + padding: const EdgeInsets.only( + left: Grid.side, right: Grid.side, bottom: Grid.xxs,), child: FilledButton( onPressed: onPressed, child: Text(title ?? Loc.of(context).next), diff --git a/test/features/payment/payment_amount_page_test.dart b/test/features/payment/payment_amount_page_test.dart index 505df7ba..21b1baa2 100644 --- a/test/features/payment/payment_amount_page_test.dart +++ b/test/features/payment/payment_amount_page_test.dart @@ -1,7 +1,6 @@ import 'package:didpay/features/did/did_provider.dart'; import 'package:didpay/features/payin/payin.dart'; import 'package:didpay/features/payment/payment_amount_page.dart'; -import 'package:didpay/features/payment/payment_amount_state.dart'; import 'package:didpay/features/payment/payment_fee_details.dart'; import 'package:didpay/features/payment/payment_state.dart'; import 'package:didpay/features/payout/payout.dart'; @@ -46,11 +45,9 @@ void main() async { group('PaymentAmountPage', () { Widget paymentAmountPageTestWidget() => WidgetHelpers.testableWidget( - child: PaymentAmountPage( - paymentState: PaymentState( - transactionType: TransactionType.deposit, - paymentAmountState: PaymentAmountState(), - ), + child: const PaymentAmountPage( + paymentState: + PaymentState(transactionType: TransactionType.deposit), ), overrides: [ didProvider.overrideWithValue(did),