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

[Mobile App] Refactore past and future payment calculation in payment page #1044

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

KarinBerg
Copy link
Contributor

@KarinBerg KarinBerg commented Feb 12, 2025

  • Extracted duplicate logic into a new method and use it in "_calculateFuturePayments" and "_calculatePastPayments" within the payment page

Summary by CodeRabbit

  • Refactor
    • Optimized the logic on the Payments page to ensure more accurate calculation of past and future payments for enhanced reliability.

…calculateFuturePayments" and "_calculatePastPayments" within the payment page
Copy link

vercel bot commented Feb 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
public ⬜️ Ignored (Inspect) Feb 12, 2025 8:51pm

Copy link

coderabbitai bot commented Feb 12, 2025

📝 Walkthrough

Walkthrough

The changes refactor the payment calculation logic in the PaymentsPage. A new helper method, _getAllPaidOrConfirmedPayments, is introduced to filter payments with a status of paid or confirmed. Both _calculatePastPayments and _calculateFuturePayments now invoke this helper to work on the filtered list before computing sums and counts. The return statements have been adjusted accordingly to use the currency information from the filtered payments.

Changes

File Change Summary
recipients_app/.../payments_page.dart Refactored _calculatePastPayments and _calculateFuturePayments to use the new _getAllPaidOrConfirmedPayments helper method for filtering payments by status.

Sequence Diagram(s)

sequenceDiagram
    participant PP as _calculatePastPayments
    participant Helper as _getAllPaidOrConfirmedPayments
    participant Mapped as MappedPayments
    PP ->> Helper: Call with full mappedPayments
    Helper -->> PP: Return filteredPayments
    PP ->> PP: Sum amounts from filteredPayments
    PP -->> Caller: Return total amount with currency
Loading
sequenceDiagram
    participant FP as _calculateFuturePayments
    participant Helper as _getAllPaidOrConfirmedPayments
    participant Mapped as MappedPayments
    FP ->> Helper: Call with full mappedPayments
    Helper -->> FP: Return filteredPayments
    FP ->> FP: Count filteredPayments
    FP -->> Caller: Return payment count
Loading

Possibly related PRs

Suggested reviewers

  • novas1r1
  • ssandino
  • MDikkii

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
recipients_app/lib/view/pages/payments_page.dart (2)

150-151: Extract currency conversion factor to a constant.

The SLL to SLE conversion factor should be defined as a named constant for better maintainability.

+  static const _SLL_TO_SLE_CONVERSION_FACTOR = 1000;
+
   String _calculatePastPayments(List<MappedPayment> mappedPayments) {
     var total = 0;
     final List<MappedPayment> paidOrConfirmedPayments = _getAllPaidOrConfirmedPayments(mappedPayments);
     for (final payment in paidOrConfirmedPayments) {
-      final factor = (payment.payment.currency == "SLL") ? 1000 : 1;
+      final factor = (payment.payment.currency == "SLL") ? _SLL_TO_SLE_CONVERSION_FACTOR : 1;
       total += (payment.payment.amount ?? 0) ~/ factor;

166-174: Consider adding underscore prefix to private method.

The helper method effectively encapsulates the payment filtering logic. Since it's a private implementation detail, consider prefixing it with an underscore.

-  List<MappedPayment> _getAllPaidOrConfirmedPayments(List<MappedPayment> mappedPayments) {
+  List<MappedPayment> __getAllPaidOrConfirmedPayments(List<MappedPayment> mappedPayments) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47c133d and e363c83.

📒 Files selected for processing (1)
  • recipients_app/lib/view/pages/payments_page.dart (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test shared code
  • GitHub Check: Prettify
  • GitHub Check: Security checks (typescript)
🔇 Additional comments (2)
recipients_app/lib/view/pages/payments_page.dart (2)

157-164: LGTM! Clear and efficient implementation.

The refactored code effectively calculates future payments based on program duration and confirmed payment count.


146-174: Great refactoring that improves code maintainability!

The extraction of payment filtering logic into a helper method effectively reduces duplication while maintaining clear responsibilities.

@KarinBerg KarinBerg merged commit e960734 into main Feb 12, 2025
15 of 16 checks passed
@KarinBerg KarinBerg deleted the karin/refactor_payment_calculation branch February 12, 2025 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants