Skip to content

Commit

Permalink
feat: add DapForm (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tbd authored Jun 25, 2024
1 parent c1906a6 commit ba1b412
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib/features/account/account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AccountPage extends HookConsumerWidget {
final pfis = ref.watch(pfisProvider);
final credentials = ref.watch(vcsProvider);
final featureFlags = ref.watch(featureFlagsProvider);
const dap = 'username@didpay.me';
const dap = '@username/didpay.me';

return Scaffold(
body: SafeArea(
Expand Down
6 changes: 3 additions & 3 deletions lib/features/currency/currency_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class CurrencyDropdown extends HookConsumerWidget {
);

Widget _buildCurrencyLabel(BuildContext context) => Text(
paymentState.transactionType == TransactionType.deposit
? paymentState.selectedOffering?.data.payin.currencyCode ?? ''
: paymentState.selectedOffering?.data.payout.currencyCode ?? '',
paymentState.transactionType == TransactionType.withdraw
? paymentState.selectedOffering?.data.payout.currencyCode ?? ''
: paymentState.selectedOffering?.data.payin.currencyCode ?? '',
style: Theme.of(context).textTheme.headlineMedium,
);
}
105 changes: 105 additions & 0 deletions lib/features/dap/dap_form.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'package:dap/dap.dart';
import 'package:didpay/features/did/did_qr_tile.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/next_button.dart';
import 'package:didpay/shared/theme/grid.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class DapForm extends HookConsumerWidget {
final String buttonTitle;
final void Function(String) onSubmit;

DapForm({required this.buttonTitle, required this.onSubmit, super.key});

final _formKey = GlobalKey<FormState>();

@override
Widget build(BuildContext context, WidgetRef ref) {
final dap = useState<Dap?>(null);
final errorText = useState<String?>(null);
final focusNode = useFocusNode();

final textController = useTextEditingController();
final errorMessage = Loc.of(context).invalidDap;

return Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.symmetric(horizontal: Grid.side),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextFormField(
focusNode: focusNode,
controller: textController,
onTap: () => errorText.value = null,
onTapOutside: (_) async => _updateErrorText(
textController.text,
errorMessage,
dap,
errorText,
).then((_) => focusNode.unfocus()),
onFieldSubmitted: (_) async => _updateErrorText(
textController.text,
errorMessage,
dap,
errorText,
),
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
labelText: Loc.of(context).dapHint,
errorText: errorText.value,
),
validator: (value) => value == null || value.isEmpty
? Loc.of(context).thisFieldCannotBeEmpty
: null,
),
],
),
),
),
DidQrTile(
title: Loc.of(context).dontKnowTheirDap,
didTextController: textController,
errorText: errorText,
),
NextButton(
onPressed: () async => _updateErrorText(
textController.text,
errorMessage,
dap,
errorText,
).then(
(_) => errorText.value == null
? onSubmit(textController.text)
: null,
),
title: buttonTitle,
),
],
),
);
}

Future<void> _updateErrorText(
String inputText,
String errorMessage,
ValueNotifier<Dap?> dap,
ValueNotifier<String?> errorText,
) async {
try {
dap.value = Dap.parse(inputText);
errorText.value = null;
} on Exception {
errorText.value = errorMessage;
}
}
}
4 changes: 2 additions & 2 deletions lib/features/did/did_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DidForm extends HookConsumerWidget {
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
labelText: Loc.of(context).didPrefix,
labelText: Loc.of(context).didHint,
errorText: errorText.value,
),
validator: (value) => value == null || value.isEmpty
Expand All @@ -64,7 +64,7 @@ class DidForm extends HookConsumerWidget {
),
),
DidQrTile(
title: Loc.of(context).dontKnowTheirDap,
title: Loc.of(context).dontKnowTheirDid,
didTextController: textController,
errorText: errorText,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/features/did/did_qr_tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DidQrTabs extends HookWidget {
Theme.of(context).colorScheme.onBackground,
tabs: [
Tab(text: Loc.of(context).scan),
Tab(text: Loc.of(context).myDid),
Tab(text: Loc.of(context).myDap),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/features/payin/payin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class Payin extends HookWidget {
Widget _buildPayinCurrency(BuildContext context) {
switch (paymentState.transactionType) {
case TransactionType.deposit:
case TransactionType.send:
return CurrencyDropdown(
paymentState: paymentState,
onCurrencySelect: onCurrencySelect,
);
case TransactionType.withdraw:
case TransactionType.send:
return Padding(
padding: const EdgeInsets.symmetric(horizontal: Grid.xxs),
child: Text(
Expand Down
8 changes: 4 additions & 4 deletions lib/features/send/send_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:didpay/features/countries/countries_page.dart';
import 'package:didpay/features/did/did_form.dart';
import 'package:didpay/features/dap/dap_form.dart';
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';
Expand All @@ -26,11 +26,11 @@ class SendPage extends HookConsumerWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Header(
title: Loc.of(context).enterRecipientDap,
subtitle: Loc.of(context).makeSureInfoIsCorrect,
title: Loc.of(context).whoDoYouWantToPay,
subtitle: Loc.of(context).enterADap,
),
Expanded(
child: DidForm(
child: DapForm(
buttonTitle: Loc.of(context).next,
onSubmit: (did) => Navigator.of(context).push(
MaterialPageRoute(
Expand Down
12 changes: 8 additions & 4 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@
"search": "Search",
"serviceFeesMayApply": "Service fees may apply",
"selectPaymentMethod": "Select a payment method",
"didPrefix": "did:...",
"didHint": "did:...",
"dapHint": "@local-handle/domain",
"thisFieldCannotBeEmpty": "This field cannot be empty",
"invalidDid": "Invalid DID",
"invalidDap": "Invalid DAP",
"noDidQrCodeFound": "No DID QR Code found",
"myDid": "My DID",
"myDap": "My DAP",
"myVc": "My VC",
"vcNotFound": "VC not found",
"copiedDid": "Copied DID!",
Expand Down Expand Up @@ -131,7 +133,7 @@
"cancel": "Cancel",
"linkedPfis": "Linked PFIs",
"noTransactionsFound": "No transactions found",
"enterRecipientDap": "Enter the recipient's DAP",
"whoDoYouWantToPay": "Who do you want to pay?",
"fetchingOfferings": "Fetching offerings...",
"startingIdv": "Starting identity verification...",
"verifyingYourIdentity": "Verifying your identity...",
Expand All @@ -144,6 +146,7 @@
"fetchingTransactions": "Fetching transactions...",
"scan": "Scan",
"cameraUnavailable": "Camera unavailable",
"dontKnowTheirDid": "Don't know their DID? Scan their QR code instead",
"dontKnowTheirDap": "Don't know their DAP? Scan their QR code instead",
"featureFlags": "Feature flags",
"lucidMode": "Lucid mode",
Expand All @@ -158,5 +161,6 @@
}
}
},
"ifYouExitNow": "If you exit now, you'll lose all your progress"
"ifYouExitNow": "If you exit now, you'll lose all your progress",
"enterADap": "Enter a Decentralized Agnostic Paytag (DAP)"
}
40 changes: 32 additions & 8 deletions lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,17 @@ abstract class Loc {
/// **'Select a payment method'**
String get selectPaymentMethod;

/// No description provided for @didPrefix.
/// No description provided for @didHint.
///
/// In en, this message translates to:
/// **'did:...'**
String get didPrefix;
String get didHint;

/// No description provided for @dapHint.
///
/// In en, this message translates to:
/// **'@local-handle/domain'**
String get dapHint;

/// No description provided for @thisFieldCannotBeEmpty.
///
Expand All @@ -337,17 +343,23 @@ abstract class Loc {
/// **'Invalid DID'**
String get invalidDid;

/// No description provided for @invalidDap.
///
/// In en, this message translates to:
/// **'Invalid DAP'**
String get invalidDap;

/// No description provided for @noDidQrCodeFound.
///
/// In en, this message translates to:
/// **'No DID QR Code found'**
String get noDidQrCodeFound;

/// No description provided for @myDid.
/// No description provided for @myDap.
///
/// In en, this message translates to:
/// **'My DID'**
String get myDid;
/// **'My DAP'**
String get myDap;

/// No description provided for @myVc.
///
Expand Down Expand Up @@ -697,11 +709,11 @@ abstract class Loc {
/// **'No transactions found'**
String get noTransactionsFound;

/// No description provided for @enterRecipientDap.
/// No description provided for @whoDoYouWantToPay.
///
/// In en, this message translates to:
/// **'Enter the recipient\'s DAP'**
String get enterRecipientDap;
/// **'Who do you want to pay?'**
String get whoDoYouWantToPay;

/// No description provided for @fetchingOfferings.
///
Expand Down Expand Up @@ -769,6 +781,12 @@ abstract class Loc {
/// **'Camera unavailable'**
String get cameraUnavailable;

/// No description provided for @dontKnowTheirDid.
///
/// In en, this message translates to:
/// **'Don\'t know their DID? Scan their QR code instead'**
String get dontKnowTheirDid;

/// No description provided for @dontKnowTheirDap.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -816,6 +834,12 @@ abstract class Loc {
/// In en, this message translates to:
/// **'If you exit now, you\'ll lose all your progress'**
String get ifYouExitNow;

/// No description provided for @enterADap.
///
/// In en, this message translates to:
/// **'Enter a Decentralized Agnostic Paytag (DAP)'**
String get enterADap;
}

class _LocDelegate extends LocalizationsDelegate<Loc> {
Expand Down
18 changes: 15 additions & 3 deletions lib/l10n/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,25 @@ class LocEn extends Loc {
String get selectPaymentMethod => 'Select a payment method';

@override
String get didPrefix => 'did:...';
String get didHint => 'did:...';

@override
String get dapHint => '@local-handle/domain';

@override
String get thisFieldCannotBeEmpty => 'This field cannot be empty';

@override
String get invalidDid => 'Invalid DID';

@override
String get invalidDap => 'Invalid DAP';

@override
String get noDidQrCodeFound => 'No DID QR Code found';

@override
String get myDid => 'My DID';
String get myDap => 'My DAP';

@override
String get myVc => 'My VC';
Expand Down Expand Up @@ -316,7 +322,7 @@ class LocEn extends Loc {
String get noTransactionsFound => 'No transactions found';

@override
String get enterRecipientDap => 'Enter the recipient\'s DAP';
String get whoDoYouWantToPay => 'Who do you want to pay?';

@override
String get fetchingOfferings => 'Fetching offerings...';
Expand Down Expand Up @@ -351,6 +357,9 @@ class LocEn extends Loc {
@override
String get cameraUnavailable => 'Camera unavailable';

@override
String get dontKnowTheirDid => 'Don\'t know their DID? Scan their QR code instead';

@override
String get dontKnowTheirDap => 'Don\'t know their DAP? Scan their QR code instead';

Expand All @@ -376,4 +385,7 @@ class LocEn extends Loc {

@override
String get ifYouExitNow => 'If you exit now, you\'ll lose all your progress';

@override
String get enterADap => 'Enter a Decentralized Agnostic Paytag (DAP)';
}
Loading

0 comments on commit ba1b412

Please sign in to comment.