Skip to content

Commit

Permalink
fix: more misc fixes (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tbd authored Jul 19, 2024
1 parent e5f0ddc commit d7662f5
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 31 deletions.
11 changes: 6 additions & 5 deletions lib/features/account/account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class AccountPage extends HookConsumerWidget {
) =>
ListTile(
title: Text(
'KCC - ${_getIssuanceDate(credential)}',
_getCredentialTitle(credential),
style: Theme.of(context).textTheme.titleSmall,
),
leading: Container(
Expand All @@ -230,7 +230,7 @@ class AccountPage extends HookConsumerWidget {
),
onTap: () => ModalRemoveItem.show(
context,
credential,
_getCredentialTitle(credential),
Loc.of(context).removeCredential,
() async => ref.read(vcsProvider.notifier).remove(credential),
),
Expand Down Expand Up @@ -307,13 +307,14 @@ class AccountPage extends HookConsumerWidget {
),
);

String _getIssuanceDate(String credentialJwt) {
String _getCredentialTitle(String credentialJwt) {
final decodedJwt = Jwt.decode(credentialJwt);
final payload = decodedJwt.claims.misc?['vc'] as Map<String, dynamic>?;
final issuedAt = payload?['issuanceDate'] as String?;

return issuedAt != null
final issuanceDate = issuedAt != null
? DateFormat('MMM dd yyyy').format(DateTime.parse(issuedAt).toLocal())
: 'no issuance date';

return 'KCC - $issuanceDate';
}
}
5 changes: 4 additions & 1 deletion lib/features/countries/countries_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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_details_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 @@ -36,9 +37,11 @@ class CountriesPage extends HookConsumerWidget {
? null
: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const PaymentAmountPage(
builder: (context) => PaymentAmountPage(
paymentState: PaymentState(
transactionType: TransactionType.send,
paymentDetailsState:
PaymentDetailsState(paymentCurrency: 'MXN'),
),
),
),
Expand Down
19 changes: 7 additions & 12 deletions lib/features/payment/payment_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,14 @@ class PaymentDetailsPage extends HookConsumerWidget {

useEffect(
() {
if (state.value.moneyAddresses != null) {
state.value =
state.value.copyWith(formData: paymentState.payoutDetails);
} else {
final selectedMethod = (availableMethods?.length ?? 0) <= 1
? availableMethods?.firstOrNull
: null;
final selectedMethod = (availableMethods?.length ?? 0) <= 1
? availableMethods?.firstOrNull
: null;

state.value = state.value.copyWith(
selectedPaymentMethod: selectedMethod,
paymentName: selectedMethod?.title,
);
}
state.value = state.value.copyWith(
selectedPaymentMethod: selectedMethod,
paymentName: selectedMethod?.title,
);

return;
},
Expand Down
12 changes: 3 additions & 9 deletions lib/features/payment/payment_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class PaymentState {
case TransactionType.deposit:
return 'USDC';
case TransactionType.send:
return paymentDetailsState?.moneyAddresses?.firstOrNull?.currency
.toUpperCase();
return paymentDetailsState?.paymentCurrency ??
paymentDetailsState?.moneyAddresses?.firstOrNull?.currency
.toUpperCase();
case TransactionType.withdraw:
return null;
}
Expand Down Expand Up @@ -82,13 +83,6 @@ class PaymentState {
case TransactionType.deposit:
return null;
case TransactionType.send:
// TODO(ethan-tbd): remove hardcoded map
return {
'lnAddress': paymentDetailsState?.moneyAddresses?.firstOrNull?.css
.split(':')
.last ??
'',
};
case TransactionType.withdraw:
return paymentDetailsState?.formData;
}
Expand Down
23 changes: 22 additions & 1 deletion lib/features/transaction/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ class Transaction {
status == TransactionStatus.payoutSuccess ||
status == TransactionStatus.payoutCanceled;

static Color getStatusColor(BuildContext context, TransactionStatus? status) {
static Color getStatusBackgroundColor(
BuildContext context,
TransactionStatus? status,
) {
switch (status) {
case TransactionStatus.payoutSuccess:
return Theme.of(context).colorScheme.tertiary;
Expand All @@ -135,6 +138,24 @@ class Transaction {
}
}

static Color getStatusTextColor(
BuildContext context,
TransactionStatus? status,
) {
switch (status) {
case TransactionStatus.payoutSuccess:
return Theme.of(context).colorScheme.tertiary;
case TransactionStatus.payoutCanceled:
return Theme.of(context).colorScheme.error;
case TransactionStatus.payoutPending:
case TransactionStatus.payoutInitiated:
case TransactionStatus.payoutComplete:
case TransactionStatus.orderSubmitted:
case null:
return Theme.of(context).colorScheme.outline;
}
}

static TransactionStatus _getStatus(String status) {
switch (status) {
case 'PAYOUT_PENDING':
Expand Down
2 changes: 1 addition & 1 deletion lib/features/transaction/transaction_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class TransactionDetailsPage extends HookConsumerWidget {
child: Text(
status.toString(),
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Transaction.getStatusColor(context, status),
color: Transaction.getStatusTextColor(context, status),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/features/transaction/transaction_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TransactionTile extends HookConsumerWidget {
),
behavior: SnackBarBehavior.floating,
duration: const Duration(seconds: 1),
backgroundColor: Transaction.getStatusColor(
backgroundColor: Transaction.getStatusBackgroundColor(
context,
transaction.value?.status,
),
Expand Down
3 changes: 2 additions & 1 deletion lib/shared/json_schema_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class JsonSchemaForm extends HookWidget {

formFields.add(
TextFormField(
initialValue: state.formData?[key],
initialValue:
state.moneyAddresses?.firstOrNull?.css.split(':').last,
focusNode: focusNode,
onTapOutside: (_) => focusNode.unfocus(),
enableSuggestions: false,
Expand Down

0 comments on commit d7662f5

Please sign in to comment.