Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(recipients-app): Fix grey empty payments #628

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions recipients_app/lib/data/repositories/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class UserRepository {
return null;
}

final userSnapshot = matchingUsers.docs.first;
final userSnapshot = matchingUsers.docs.firstOrNull;

// This doesnt work because user id from firebaseAuth is not related to user id from firestore
// Needs to be discussed if changes should be made or not
// final userSnapshot =
// await firestore.collection("/recipients").doc(firebaseUser.uid).get();

if (userSnapshot.exists) {
if (userSnapshot != null && userSnapshot.exists) {
// TODO: decide if we should keep it in user object in the app at all
final payments = await PaymentRepository(firestore: firestore)
.fetchPayments(recipientId: userSnapshot.id);
Expand Down
1 change: 1 addition & 0 deletions recipients_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"pastPayments" : "Past Payments",
"futurePayments" : "Future Payments",
"paymentsSuspended" : "Suspended",
"paymentsEmptyList": "No payments.",
"survey" : "Survey",
"createAccountInfo":"By creating an account, you agree with our ",
"privacyPolicy":"Privacy Policy",
Expand Down
1 change: 1 addition & 0 deletions recipients_app/lib/l10n/app_kri.arb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"pastPayments": "Pemɛnt dɛm we dɛn dɔn mek",
"futurePayments": "Pemɛnt dɛm we yu nɔ gɛt yet",
"paymentsSuspended": "Dɛn ɔl am fɔs",
"paymentsEmptyList": "Nɔ pemɛnt.",
"survey": "Sɔve",
"createAccountInfo": "We yu mek di akawnt, yu dɔn gri wit wi ",
"privacyPolicy": "Wi de kip sikrit",
Expand Down
35 changes: 24 additions & 11 deletions recipients_app/lib/view/pages/payments_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,29 @@ class PaymentsPage extends StatelessWidget {
),
),
const SizedBox(height: 16),
Expanded(
child: ListView.builder(
itemCount: paymentsUiState.payments.length,
itemBuilder: (context, index) {
return PaymentTile(
mappedPayment: paymentsUiState.payments[index],
);
},
if (paymentsUiState.payments.isEmpty)
Expanded(
child: Padding(
padding: AppSpacings.a8,
child: Center(
child: Text(
localizations.paymentsEmptyList,
textAlign: TextAlign.center,
),
),
),
)
else
Expanded(
child: ListView.builder(
itemCount: paymentsUiState.payments.length,
itemBuilder: (context, index) {
return PaymentTile(
mappedPayment: paymentsUiState.payments[index],
);
},
),
),
),
],
),
),
Expand All @@ -141,7 +154,7 @@ class PaymentsPage extends StatelessWidget {
total += (mappedPayment.payment.amount ?? 0) ~/ factor;
}

return "${mappedPayments.first.payment.currency} $total";
return "${mappedPayments.firstOrNull?.payment.currency ?? "SLE"} $total";
}

String _calculateFuturePayments(List<MappedPayment> mappedPayments) {
Expand All @@ -150,6 +163,6 @@ class PaymentsPage extends StatelessWidget {
final futurePayments = (kProgramDurationMonths - mappedPayments.length) *
kCurrentPaymentAmount;

return "${mappedPayments.first.payment.currency} ${futurePayments}";
return "${mappedPayments.firstOrNull?.payment.currency ?? "SLE"} ${futurePayments}";
}
}
Loading