Skip to content

Commit

Permalink
chore: rename shared widgets (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tbd authored Jun 18, 2024
1 parent baf0648 commit 3e200c8
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 85 deletions.
15 changes: 8 additions & 7 deletions lib/features/feature_flags/lucid/lucid_offerings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:didpay/features/pfis/pfis_notifier.dart';
import 'package:didpay/features/tbdex/tbdex_service.dart';
import 'package:didpay/features/transaction/transaction.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/async/async_error_widget.dart';
import 'package:didpay/shared/async/async_loading_widget.dart';
import 'package:didpay/shared/error_message.dart';
import 'package:didpay/shared/loading_message.dart';
import 'package:didpay/shared/header.dart';
import 'package:didpay/shared/next_button.dart';
import 'package:didpay/shared/theme/grid.dart';
Expand Down Expand Up @@ -116,9 +116,9 @@ class LucidOfferingsPage extends HookConsumerWidget {
);
},
loading: () =>
AsyncLoadingWidget(text: Loc.of(context).fetchingOfferings),
error: (error, stackTrace) => AsyncErrorWidget(
text: error.toString(),
LoadingMessage(message: Loc.of(context).fetchingOfferings),
error: (error, stackTrace) => ErrorMessage(
message: error.toString(),
onRetry: () => _getOfferings(ref, offerings),
),
),
Expand All @@ -135,8 +135,9 @@ class LucidOfferingsPage extends HookConsumerWidget {
await ref
.read(tbdexServiceProvider)
.getOfferings(
const PaymentState(transactionType: TransactionType.send),
ref.read(pfisProvider),)
const PaymentState(transactionType: TransactionType.send),
ref.read(pfisProvider),
)
.then((offerings) => state.value = AsyncData(offerings));
} on Exception catch (e) {
state.value = AsyncError(e, StackTrace.current);
Expand Down
6 changes: 3 additions & 3 deletions lib/features/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:didpay/features/tbdex/tbdex_service.dart';
import 'package:didpay/features/transaction/transaction.dart';
import 'package:didpay/features/transaction/transaction_tile.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/async/async_loading_widget.dart';
import 'package:didpay/shared/loading_message.dart';
import 'package:didpay/shared/theme/grid.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
Expand Down Expand Up @@ -106,8 +106,8 @@ class HomePage extends HookConsumerWidget {
ref,
state,
),
loading: () => AsyncLoadingWidget(
text: Loc.of(context).fetchingTransactions,
loading: () => LoadingMessage(
message: Loc.of(context).fetchingTransactions,
),
),
),
Expand Down
10 changes: 5 additions & 5 deletions lib/features/kcc/kcc_retrieval_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:didpay/features/kcc/lib/idv_request.dart';
import 'package:didpay/features/pfis/pfi.dart';
import 'package:didpay/features/vcs/vcs_notifier.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/async/async_error_widget.dart';
import 'package:didpay/shared/async/async_loading_widget.dart';
import 'package:didpay/shared/error_message.dart';
import 'package:didpay/shared/loading_message.dart';
import 'package:didpay/shared/next_button.dart';
import 'package:didpay/shared/theme/grid.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -40,9 +40,9 @@ class KccRetrievalPage extends HookConsumerWidget {
body: SafeArea(
child: credential.value.when(
loading: () =>
AsyncLoadingWidget(text: Loc.of(context).verifyingYourIdentity),
error: (error, stackTrace) => AsyncErrorWidget(
text: error.toString(),
LoadingMessage(message: Loc.of(context).verifyingYourIdentity),
error: (error, stackTrace) => ErrorMessage(
message: error.toString(),
onRetry: () => _pollForCredential(ref, credential),
),
data: (data) => Column(
Expand Down
10 changes: 5 additions & 5 deletions lib/features/kcc/kcc_webview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:didpay/features/kcc/kcc_retrieval_page.dart';
import 'package:didpay/features/kcc/lib/idv_request.dart';
import 'package:didpay/features/pfis/pfi.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/async/async_error_widget.dart';
import 'package:didpay/shared/async/async_loading_widget.dart';
import 'package:didpay/shared/error_message.dart';
import 'package:didpay/shared/loading_message.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
Expand Down Expand Up @@ -51,10 +51,10 @@ class KccWebviewPage extends HookConsumerWidget {
),
),
body: idvRequest.value.when(
loading: () => AsyncLoadingWidget(text: Loc.of(context).startingIdv),
loading: () => LoadingMessage(message: Loc.of(context).startingIdv),
error: (error, stackTrace) => SafeArea(
child: AsyncErrorWidget(
text: error.toString(),
child: ErrorMessage(
message: error.toString(),
onRetry: () => _getIdvRequest(ref, idvRequest),
),
),
Expand Down
10 changes: 5 additions & 5 deletions lib/features/payment/payment_amount_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:didpay/features/pfis/pfi.dart';
import 'package:didpay/features/pfis/pfis_notifier.dart';
import 'package:didpay/features/tbdex/tbdex_service.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/async/async_error_widget.dart';
import 'package:didpay/shared/async/async_loading_widget.dart';
import 'package:didpay/shared/error_message.dart';
import 'package:didpay/shared/loading_message.dart';
import 'package:didpay/shared/next_button.dart';
import 'package:didpay/shared/number/number_key_press.dart';
import 'package:didpay/shared/number/number_pad.dart';
Expand Down Expand Up @@ -137,9 +137,9 @@ class PaymentAmountPage extends HookConsumerWidget {
);
},
loading: () =>
AsyncLoadingWidget(text: Loc.of(context).fetchingOfferings),
error: (error, stackTrace) => AsyncErrorWidget(
text: error.toString(),
LoadingMessage(message: Loc.of(context).fetchingOfferings),
error: (error, stackTrace) => ErrorMessage(
message: error.toString(),
onRetry: () =>
_getOfferings(ref, currentPaymentState.value, offerings),
),
Expand Down
18 changes: 9 additions & 9 deletions lib/features/payment/payment_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import 'package:didpay/features/tbdex/tbdex_service.dart';
import 'package:didpay/features/transaction/transaction.dart';
import 'package:didpay/features/vcs/vcs_notifier.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/async/async_error_widget.dart';
import 'package:didpay/shared/async/async_loading_widget.dart';
import 'package:didpay/shared/error_message.dart';
import 'package:didpay/shared/loading_message.dart';
import 'package:didpay/shared/header.dart';
import 'package:didpay/shared/json_schema_form.dart';
import 'package:didpay/shared/modal_flow.dart';
import 'package:didpay/shared/modal/modal_flow.dart';
import 'package:didpay/shared/theme/grid.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
Expand Down Expand Up @@ -60,14 +60,14 @@ class PaymentDetailsPage extends HookConsumerWidget {
body: SafeArea(
child: rfq.value != null
? rfq.value!.when(
data: (_) => AsyncLoadingWidget(
text: Loc.of(context).gettingYourQuote,
data: (_) => LoadingMessage(
message: Loc.of(context).gettingYourQuote,
),
loading: () => AsyncLoadingWidget(
text: Loc.of(context).sendingYourRequest,
loading: () => LoadingMessage(
message: Loc.of(context).sendingYourRequest,
),
error: (error, _) => AsyncErrorWidget(
text: error.toString(),
error: (error, _) => ErrorMessage(
message: error.toString(),
onRetry: () => _sendRfq(
context,
ref,
Expand Down
26 changes: 13 additions & 13 deletions lib/features/payment/payment_review_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:didpay/features/payment/payment_state.dart';
import 'package:didpay/features/tbdex/tbdex_service.dart';
import 'package:didpay/features/transaction/transaction.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/async/async_data_widget.dart';
import 'package:didpay/shared/async/async_error_widget.dart';
import 'package:didpay/shared/async/async_loading_widget.dart';
import 'package:didpay/shared/confirmation_message.dart';
import 'package:didpay/shared/error_message.dart';
import 'package:didpay/shared/loading_message.dart';
import 'package:didpay/shared/currency_formatter.dart';
import 'package:didpay/shared/header.dart';
import 'package:didpay/shared/next_button.dart';
Expand Down Expand Up @@ -78,22 +78,22 @@ class PaymentReviewPage extends HookConsumerWidget {
),
],
),
loading: () => AsyncLoadingWidget(
text: Loc.of(context).gettingYourQuote,
loading: () => LoadingMessage(
message: Loc.of(context).gettingYourQuote,
),
error: (error, _) => AsyncErrorWidget(
text: error.toString(),
error: (error, _) => ErrorMessage(
message: error.toString(),
onRetry: () => _pollForQuote(ref, quote),
),
)
: order.value!.when(
data: (_) =>
AsyncDataWidget(text: Loc.of(context).orderConfirmed),
loading: () => AsyncLoadingWidget(
text: Loc.of(context).confirmingYourOrder,
data: (_) => ConfirmationMessage(
message: Loc.of(context).orderConfirmed),
loading: () => LoadingMessage(
message: Loc.of(context).confirmingYourOrder,
),
error: (error, _) => AsyncErrorWidget(
text: error.toString(),
error: (error, _) => ErrorMessage(
message: error.toString(),
onRetry: () => _submitOrder(
context,
ref,
Expand Down
15 changes: 8 additions & 7 deletions lib/features/pfis/pfis_add_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:didpay/features/did/did_form.dart';
import 'package:didpay/features/pfis/pfi.dart';
import 'package:didpay/features/pfis/pfis_notifier.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/async/async_data_widget.dart';
import 'package:didpay/shared/async/async_error_widget.dart';
import 'package:didpay/shared/async/async_loading_widget.dart';
import 'package:didpay/shared/confirmation_message.dart';
import 'package:didpay/shared/error_message.dart';
import 'package:didpay/shared/loading_message.dart';
import 'package:didpay/shared/header.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
Expand All @@ -24,11 +24,12 @@ class PfisAddPage extends HookConsumerWidget {
body: SafeArea(
child: pfi.value != null
? pfi.value!.when(
data: (_) => AsyncDataWidget(text: Loc.of(context).pfiAdded),
data: (_) =>
ConfirmationMessage(message: Loc.of(context).pfiAdded),
loading: () =>
AsyncLoadingWidget(text: Loc.of(context).addingPfi),
error: (error, _) => AsyncErrorWidget(
text: error.toString(),
LoadingMessage(message: Loc.of(context).addingPfi),
error: (error, _) => ErrorMessage(
message: error.toString(),
onRetry: () => _addPfi(ref, pfiDidController.text, pfi),
),
)
Expand Down
16 changes: 8 additions & 8 deletions lib/features/send/send_details_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:didpay/features/did/did_form.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/async/async_data_widget.dart';
import 'package:didpay/shared/async/async_error_widget.dart';
import 'package:didpay/shared/async/async_loading_widget.dart';
import 'package:didpay/shared/confirmation_message.dart';
import 'package:didpay/shared/error_message.dart';
import 'package:didpay/shared/loading_message.dart';
import 'package:didpay/shared/header.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
Expand All @@ -22,12 +22,12 @@ class SendDetailsPage extends HookConsumerWidget {
body: SafeArea(
child: send.value != null
? send.value!.when(
data: (_) =>
AsyncDataWidget(text: Loc.of(context).yourPaymentWasSent),
data: (_) => ConfirmationMessage(
message: Loc.of(context).yourPaymentWasSent),
loading: () =>
AsyncLoadingWidget(text: Loc.of(context).sendingPayment),
error: (error, _) => AsyncErrorWidget(
text: error.toString(),
LoadingMessage(message: Loc.of(context).sendingPayment),
error: (error, _) => ErrorMessage(
message: error.toString(),
onRetry: () => _sendPayment(send),
),
)
Expand Down
6 changes: 6 additions & 0 deletions lib/features/tbdex/tbdex_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class TbdexService {
}
}

if (offeringsMap.isEmpty) {
throw Exception(
'No ${paymentState.transactionType.toString().toLowerCase()} offerings found for any linked PFIs',
);
}

return offeringsMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:didpay/shared/theme/grid.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

class AsyncDataWidget extends HookWidget {
final String text;
const AsyncDataWidget({required this.text, super.key});
class ConfirmationMessage extends HookWidget {
final String message;
const ConfirmationMessage({required this.message, super.key});

@override
Widget build(BuildContext context) => Column(
Expand All @@ -19,7 +19,7 @@ class AsyncDataWidget extends HookWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: Grid.xl),
Text(text, style: Theme.of(context).textTheme.titleMedium),
Text(message, style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: Grid.xs),
Icon(
Icons.check_circle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class AsyncErrorWidget extends HookConsumerWidget {
final String text;
class ErrorMessage extends HookConsumerWidget {
final String message;
final VoidCallback onRetry;

const AsyncErrorWidget({
required this.text,
const ErrorMessage({
required this.message,
required this.onRetry,
super.key,
});
Expand All @@ -24,7 +24,7 @@ class AsyncErrorWidget extends HookConsumerWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Header(title: Loc.of(context).errorFound, subtitle: text),
Header(title: Loc.of(context).errorFound, subtitle: message),
Expanded(child: Container()),
NextButton(onPressed: onRetry, title: Loc.of(context).tapToRetry),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import 'package:didpay/shared/theme/grid.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

class AsyncLoadingWidget extends HookWidget {
final String text;
class LoadingMessage extends HookWidget {
final String message;

const AsyncLoadingWidget({required this.text, super.key});
const LoadingMessage({required this.message, super.key});

@override
Widget build(BuildContext context) => Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
text,
message,
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.center,
),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'package:didpay/shared/async/async_data_widget.dart';
import 'package:didpay/shared/confirmation_message.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../helpers/widget_helpers.dart';
import '../helpers/widget_helpers.dart';

void main() {
group('AsyncDataWidget', () {
group('ConfirmationMessage', () {
testWidgets('should show request was submitted', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(
child: const AsyncDataWidget(text: 'Your request was submitted!'),
child:
const ConfirmationMessage(message: 'Your request was submitted!'),
),
);

Expand All @@ -20,8 +21,8 @@ void main() {
testWidgets('should show done button', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testableWidget(
child: const AsyncDataWidget(
text: '',
child: const ConfirmationMessage(
message: '',
),
),
);
Expand Down
Loading

0 comments on commit 3e200c8

Please sign in to comment.