Skip to content

Commit

Permalink
fix: payment methods (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tbd authored Jul 12, 2024
1 parent dd5bf3c commit 139a56e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 51 deletions.
12 changes: 4 additions & 8 deletions lib/features/account/account_balance_card.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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,
),
Expand Down
4 changes: 1 addition & 3 deletions lib/features/countries/countries_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(),
),
),
),
Expand Down
4 changes: 1 addition & 3 deletions lib/features/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
),
),
),
Expand Down
57 changes: 32 additions & 25 deletions lib/features/payment/payment_amount_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -34,8 +35,9 @@ class PaymentAmountPage extends HookConsumerWidget {
final keyPress = useState(NumberKeyPress(0, ''));
final offerings =
useState<AsyncValue<Map<Pfi, List<Offering>>>>(const AsyncLoading());
final state =
useState<PaymentAmountState?>(paymentState.paymentAmountState);
final state = useState<PaymentAmountState>(
paymentState.paymentAmountState ?? PaymentAmountState(),
);

useEffect(
() {
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
),
),
),
),
);
},
),
),
),
Expand Down
6 changes: 3 additions & 3 deletions lib/features/payment/payment_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class PaymentDetailsPage extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final rfq = useState<AsyncValue<Rfq>?>(null);
final state =
useState<PaymentDetailsState>(paymentState.paymentDetailsState!);

final state = useState<PaymentDetailsState>(
paymentState.paymentDetailsState ?? PaymentDetailsState(),
);
final availableMethods =
state.value.filterPaymentMethods(state.value.selectedPaymentType);

Expand Down
2 changes: 0 additions & 2 deletions lib/features/send/send_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -57,7 +56,6 @@ class SendPage extends HookConsumerWidget {
builder: (_) => PaymentAmountPage(
paymentState: PaymentState(
transactionType: TransactionType.send,
paymentAmountState: PaymentAmountState(),
paymentDetailsState: PaymentDetailsState(
paymentName: recipientDap.dap,
moneyAddresses: moneyAddresses,
Expand Down
3 changes: 2 additions & 1 deletion lib/shared/next_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 3 additions & 6 deletions test/features/payment/payment_amount_page_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 139a56e

Please sign in to comment.