From 64f683c6a8f9ceb0b9211974c250b1bf363fcce8 Mon Sep 17 00:00:00 2001 From: Kirah Sapong Date: Thu, 15 Feb 2024 11:21:31 -0800 Subject: [PATCH] pass data from withdraw or deposit page to payment details page --- lib/features/deposit/deposit_page.dart | 19 ++- .../payments/payment_details_page.dart | 45 ++++++- lib/features/withdraw/withdraw_page.dart | 20 ++- .../payments/payment_details_page_test.dart | 117 ++++++++++++++++-- 4 files changed, 175 insertions(+), 26 deletions(-) diff --git a/lib/features/deposit/deposit_page.dart b/lib/features/deposit/deposit_page.dart index 16f34cf3..dac955d5 100644 --- a/lib/features/deposit/deposit_page.dart +++ b/lib/features/deposit/deposit_page.dart @@ -1,3 +1,4 @@ +import 'package:didpay/features/home/transaction.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:didpay/features/currency/currency_converter.dart'; @@ -25,6 +26,8 @@ class DepositPage extends HookWidget { final isValidKeyPress = useState(true); final selectedCurrencyItem = useState>(supportedCurrencyList[1]); + final outputAmount = double.parse('0${depositAmount.value}') / + double.parse(selectedCurrencyItem.value['exchangeRate'].toString()); return Scaffold( appBar: AppBar(), @@ -45,10 +48,7 @@ class DepositPage extends HookWidget { inputSelectedCurrency: selectedCurrencyItem.value['label'].toString(), inputLabel: Loc.of(context).youDeposit, - outputAmount: (double.parse('0${depositAmount.value}') / - double.parse(selectedCurrencyItem - .value['exchangeRate'] - .toString())), + outputAmount: outputAmount, isValidKeyPress: isValidKeyPress.value, onDropdownTap: () { CurrencyModal.show( @@ -83,7 +83,16 @@ class DepositPage extends HookWidget { onPressed: () { Navigator.of(context).push( MaterialPageRoute( - builder: (context) => const PaymentDetailsPage(), + builder: (context) => PaymentDetailsPage( + inputAmount: depositAmount.value, + inputCurrency: + selectedCurrencyItem.value['label'].toString(), + exchangeRate: selectedCurrencyItem.value['exchangeRate'] + .toString(), + outputAmount: outputAmount.toString(), + outputCurrency: Loc.of(context).usd, + transactionType: Type.deposit, + ), ), ); }, diff --git a/lib/features/payments/payment_details_page.dart b/lib/features/payments/payment_details_page.dart index ec6ed6a3..0f94a00e 100644 --- a/lib/features/payments/payment_details_page.dart +++ b/lib/features/payments/payment_details_page.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; +import 'package:didpay/features/payments/review_request_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:didpay/features/payments/payment_method.dart'; @@ -8,7 +10,21 @@ import 'package:didpay/shared/json_schema_form.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; class PaymentDetailsPage extends HookConsumerWidget { - const PaymentDetailsPage({super.key}); + final String inputCurrency; + final String inputAmount; + final String outputCurrency; + final String outputAmount; + final String exchangeRate; + final String transactionType; + + const PaymentDetailsPage( + {required this.inputCurrency, + required this.inputAmount, + required this.outputCurrency, + required this.outputAmount, + required this.exchangeRate, + required this.transactionType, + super.key}); @override Widget build(BuildContext context, WidgetRef ref) { @@ -174,12 +190,37 @@ class PaymentDetailsPage extends HookConsumerWidget { child: JsonSchemaForm( schema: selectedPaymentMethod.value!.requiredPaymentDetails, onSubmit: (formData) { - // TODO: save payment details here + if (isValidOnSubmit(formData, selectedPaymentMethod)) { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => ReviewRequestPage( + formData: formData, + bankName: selectedPaymentMethod.value!.kind + .split('_') + .lastOrNull ?? + '', + inputAmount: inputAmount, + outputAmount: outputAmount, + inputCurrency: inputCurrency, + outputCurrency: outputCurrency, + exchangeRate: exchangeRate, + serviceFee: selectedPaymentMethod.value!.fee ?? '0.00', + transactionType: transactionType, + ), + ), + ); + } }, ), ); } + bool isValidOnSubmit(Map formData, + ValueNotifier selectedPaymentMethod) { + return formData['accountNumber'] != null && + selectedPaymentMethod.value!.kind.split('_').lastOrNull != null; + } + Widget _buildDisabledButton(BuildContext context) { return Expanded( child: Column( diff --git a/lib/features/withdraw/withdraw_page.dart b/lib/features/withdraw/withdraw_page.dart index 4a70de01..7e820ddc 100644 --- a/lib/features/withdraw/withdraw_page.dart +++ b/lib/features/withdraw/withdraw_page.dart @@ -1,3 +1,4 @@ +import 'package:didpay/features/home/transaction.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:didpay/features/currency/currency_converter.dart'; @@ -25,6 +26,8 @@ class WithdrawPage extends HookWidget { final isValidKeyPress = useState(true); final selectedCurrencyItem = useState>(supportedCurrencyList[1]); + final outputAmount = double.parse('0${withdrawAmount.value}') * + double.parse(selectedCurrencyItem.value['exchangeRate'].toString()); return Scaffold( appBar: AppBar(), @@ -45,11 +48,7 @@ class WithdrawPage extends HookWidget { inputLabel: Loc.of(context).youWithdraw, outputSelectedCurrency: selectedCurrencyItem.value['label'].toString(), - outputAmount: - (double.parse('0${withdrawAmount.value}') * - double.parse(selectedCurrencyItem - .value['exchangeRate'] - .toString())), + outputAmount: outputAmount, isValidKeyPress: isValidKeyPress.value, onDropdownTap: () { CurrencyModal.show( @@ -84,7 +83,16 @@ class WithdrawPage extends HookWidget { onPressed: () { Navigator.of(context).push( MaterialPageRoute( - builder: (context) => const PaymentDetailsPage(), + builder: (context) => PaymentDetailsPage( + inputAmount: withdrawAmount.value, + inputCurrency: Loc.of(context).usd, + exchangeRate: selectedCurrencyItem.value['exchangeRate'] + .toString(), + outputAmount: outputAmount.toString(), + outputCurrency: + selectedCurrencyItem.value['label'].toString(), + transactionType: Type.withdrawal, + ), ), ); }, diff --git a/test/features/payments/payment_details_page_test.dart b/test/features/payments/payment_details_page_test.dart index 9447fd98..c5fdb3c7 100644 --- a/test/features/payments/payment_details_page_test.dart +++ b/test/features/payments/payment_details_page_test.dart @@ -12,7 +12,14 @@ void main() { (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), ), ); @@ -24,7 +31,14 @@ void main() { (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), ), ); @@ -35,7 +49,14 @@ void main() { testWidgets('should show enter your momo details', (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -55,7 +76,14 @@ void main() { testWidgets('should show enter your bank details', (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -75,7 +103,14 @@ void main() { testWidgets('should show enter your wallet details', (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -95,7 +130,14 @@ void main() { testWidgets('should show no payment type segments', (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -116,7 +158,14 @@ void main() { (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -145,7 +194,14 @@ void main() { (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -181,7 +237,14 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -205,7 +268,14 @@ void main() { (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -233,7 +303,14 @@ void main() { testWidgets('should show momo schema form', (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -261,7 +338,14 @@ void main() { testWidgets('should show bank schema form', (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [ @@ -289,7 +373,14 @@ void main() { testWidgets('should show wallet schema form', (tester) async { await tester.pumpWidget( WidgetHelpers.testableWidget( - child: const PaymentDetailsPage(), + child: const PaymentDetailsPage( + inputAmount: '1.00', + inputCurrency: 'USD', + exchangeRate: '17', + outputAmount: '17.00', + outputCurrency: 'MXN', + transactionType: 'Deposit', + ), overrides: [ paymentMethodProvider.overrideWith( (ref) => [