Skip to content

Commit

Permalink
pass data from withdraw or deposit page to payment details page
Browse files Browse the repository at this point in the history
  • Loading branch information
kirahsapong committed Feb 15, 2024
1 parent 5476b77 commit 64f683c
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 26 deletions.
19 changes: 14 additions & 5 deletions lib/features/deposit/deposit_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -25,6 +26,8 @@ class DepositPage extends HookWidget {
final isValidKeyPress = useState<bool>(true);
final selectedCurrencyItem =
useState<Map<String, Object>>(supportedCurrencyList[1]);
final outputAmount = double.parse('0${depositAmount.value}') /
double.parse(selectedCurrencyItem.value['exchangeRate'].toString());

return Scaffold(
appBar: AppBar(),
Expand All @@ -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(
Expand Down Expand Up @@ -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,
),
),
);
},
Expand Down
45 changes: 43 additions & 2 deletions lib/features/payments/payment_details_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) {
Expand Down Expand Up @@ -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<String, String> formData,
ValueNotifier<PaymentMethod?> selectedPaymentMethod) {
return formData['accountNumber'] != null &&
selectedPaymentMethod.value!.kind.split('_').lastOrNull != null;
}

Widget _buildDisabledButton(BuildContext context) {
return Expanded(
child: Column(
Expand Down
20 changes: 14 additions & 6 deletions lib/features/withdraw/withdraw_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -25,6 +26,8 @@ class WithdrawPage extends HookWidget {
final isValidKeyPress = useState<bool>(true);
final selectedCurrencyItem =
useState<Map<String, Object>>(supportedCurrencyList[1]);
final outputAmount = double.parse('0${withdrawAmount.value}') *
double.parse(selectedCurrencyItem.value['exchangeRate'].toString());

return Scaffold(
appBar: AppBar(),
Expand All @@ -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(
Expand Down Expand Up @@ -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,
),
),
);
},
Expand Down
117 changes: 104 additions & 13 deletions test/features/payments/payment_details_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
),
);

Expand All @@ -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',
),
),
);

Expand All @@ -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) => [
Expand All @@ -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) => [
Expand All @@ -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) => [
Expand All @@ -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) => [
Expand All @@ -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) => [
Expand Down Expand Up @@ -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) => [
Expand Down Expand Up @@ -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) => [
Expand All @@ -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) => [
Expand Down Expand Up @@ -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) => [
Expand Down Expand Up @@ -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) => [
Expand Down Expand Up @@ -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) => [
Expand Down

0 comments on commit 64f683c

Please sign in to comment.