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

Update @planet-sdk/common and fix typos in currency functions #475

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

mohitb35
Copy link
Contributor

@mohitb35 mohitb35 commented Dec 3, 2024

  • Upgrade the @planet-sdk/common package to version 0.1.47
  • correct typos in the getFormattedCurrency and getFormattedCurrencySymbol functions.

Summary by CodeRabbit

  • New Features

    • Updated the currency formatting function to ensure accuracy in displaying donation amounts across various components.
  • Bug Fixes

    • Corrected the naming of the currency formatting function from getFormatedCurrency to getFormattedCurrency in multiple components, ensuring consistent functionality.
  • Chores

    • Updated the version of the @planet-sdk/common package to enhance overall application performance and stability.

Copy link

vercel bot commented Dec 3, 2024

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

Name Status Preview Comments Updated (UTC)
donate-with-planet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 3, 2024 11:30am

Copy link

coderabbitai bot commented Dec 3, 2024

Walkthrough

The changes in this pull request primarily involve updating the version of the @planet-sdk/common package in package.json from ^0.1.42 to ^0.1.47. Additionally, there are multiple modifications across various components related to correcting the spelling of the currency formatting function from getFormatedCurrency to getFormattedCurrency. This correction is consistent throughout several files, ensuring that the correct function is utilized without altering existing functionality or logic.

Changes

File Path Change Summary
package.json Updated dependency version: "@planet-sdk/common": "^0.1.42""@planet-sdk/common": "^0.1.47"
src/Utils/getFormattedCurrency.ts Renamed functions: getFormatedCurrencygetFormattedCurrency, getFormatedCurrencySymbolgetFormattedCurrencySymbol
src/Donations/Components/ContactsForm.tsx Updated import and usage of getFormatedCurrency to getFormattedCurrency
src/Donations/Components/DonationsForm.tsx Updated all instances of getFormatedCurrency to getFormattedCurrency
src/Donations/Components/PaymentsForm.tsx Corrected import and usage of getFormatedCurrency to getFormattedCurrency
src/Donations/LeftPanel/TransactionSummary.tsx Updated import and usage of getFormatedCurrency to getFormattedCurrency
src/Donations/Micros/DonationAmount.tsx Corrected import and usage of getFormatedCurrency to getFormattedCurrency
src/Donations/Micros/DonationTypes/BouquetDonations.tsx Updated all instances of getFormatedCurrency and getFormatedCurrencySymbol to their corrected forms
src/Donations/Micros/DonationTypes/FundingDonations.tsx Updated all instances of getFormatedCurrency and getFormatedCurrencySymbol to their corrected forms
src/Donations/Micros/DonationTypes/TreeDonation.tsx Corrected import and usage of getFormatedCurrency to getFormattedCurrency
src/Donations/Micros/PaymentStatus/ImageComponent.tsx Updated import and usage of getFormatedCurrency to getFormattedCurrency
src/Donations/Micros/PaymentStatus/ThankyouMessage.tsx Updated import and usage of getFormatedCurrency to getFormattedCurrency
src/Donations/Micros/PaymentStatus/TransferDetails.tsx Updated import and usage of getFormatedCurrency to getFormattedCurrency
src/Donations/Micros/PlanetCashSelector.tsx Updated import and usage of getFormatedCurrency to getFormattedCurrency
src/Donations/PaymentMethods/PaymentMethodTabs.tsx Updated import and usage of getFormatedCurrency to getFormattedCurrency

Possibly related PRs

  • Giftable donations #470: The changes in the main PR regarding the update of the @planet-sdk/common package version from ^0.1.42 to ^0.1.47 are related to PR Giftable donations #470, which also updates the same package version from ^0.1.34 to ^0.1.42.

Suggested labels

PR: reviewed-approved

Suggested reviewers

  • sunilsabatp
  • mariahosfeld

Poem

In the garden where donations bloom,
A rabbit hops, dispelling gloom.
With currency formatted just so right,
Every donation shines so bright!
From getFormated to getFormatted,
Our code now dances, all well-mended! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 71554b5 and f2574c1.

📒 Files selected for processing (2)
  • src/Donations/Components/ContactsForm.tsx (3 hunks)
  • src/Donations/Micros/DonationTypes/TreeDonation.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Donations/Components/ContactsForm.tsx
  • src/Donations/Micros/DonationTypes/TreeDonation.tsx

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 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: 1

🧹 Outside diff range and nitpick comments (6)
src/Donations/LeftPanel/TransactionSummary.tsx (1)

3-3: Consider using relative imports for consistency

The import path uses an absolute path with src/ prefix, while other files like DonationAmount.tsx use relative paths. Consider using relative imports for consistency across the codebase.

-import getFormattedCurrency from "src/Utils/getFormattedCurrency";
+import getFormattedCurrency from "../../Utils/getFormattedCurrency";
src/Donations/Micros/DonationTypes/TreeDonation.tsx (1)

Line range hint 168-172: Fix empty currency parameter in getFormattedCurrency

The getFormattedCurrency function is called with an empty string as the currency parameter. This could lead to incorrect currency formatting.

-getFormattedCurrency(
-  i18n.language,
-  "",
-  Number(paymentSetup.unitCost)
-)
+getFormattedCurrency(
+  i18n.language,
+  currency,
+  Number(paymentSetup.unitCost)
+)

The currency variable from the context should be used instead of an empty string to ensure proper currency formatting.

src/Donations/PaymentMethods/PaymentMethodTabs.tsx (1)

Line range hint 107-129: Consider refactoring repetitive currency formatting logic

The switch statement contains duplicate currency formatting logic across multiple cases. Consider extracting this common logic to reduce code duplication.

+ const formatAmount = () => getFormattedCurrency(
+   i18n.language,
+   currency,
+   paymentSetup.unitCost * quantity
+ );

  switch (projectDetails && projectDetails.purpose) {
    case "trees":
      paymentLabel = t("treesInCountry", {
        treeCount: quantity,
      });
      break;
    case "funds":
      paymentLabel = t("fundingPaymentLabel", {
-       amount: getFormattedCurrency(
-         i18n.language,
-         currency,
-         paymentSetup.unitCost * quantity
-       ),
+       amount: formatAmount(),
      });
      break;
    // Apply similar changes to other cases
src/Donations/Micros/DonationTypes/FundingDonations.tsx (1)

Line range hint 198-219: Consider enhancing input validation for custom amounts

The current input validation only handles numeric input and length constraints. Consider adding:

  1. Maximum amount validation
  2. Decimal point support for precise amounts
  3. Feedback to users when validation fails
  onInput={(e: ChangeEvent<HTMLInputElement>) => {
-   // replaces any character other than number to blank
-   e.target.value = e.target.value.replace(/[^0-9]/g, "");
+   // Allow numbers and one decimal point
+   e.target.value = e.target.value.replace(/[^0-9.]/g, "")
+     .replace(/(\..*)\./g, "$1"); // Allow only one decimal point
+   
+   // Validate maximum amount
+   const amount = parseFloat(e.target.value);
+   if (amount > 999999) {
+     e.target.value = "999999";
+   }
    
    if (e.target.value.toString().length >= 12) {
      e.target.value = e.target.value.toString().slice(0, 12);
    }
  }}
src/Donations/Micros/DonationTypes/BouquetDonations.tsx (1)

Line range hint 128-134: Track the rounded costs requirement

The TODO comment indicates a future requirement for showing rounded costs. This should be tracked to ensure it's not forgotten.

Would you like me to create a GitHub issue to track this requirement? I can help outline the necessary structural changes and implementation details.

src/Donations/Components/PaymentsForm.tsx (1)

Line range hint 133-133: Remove console.log and improve error handling.

The TODO comment indicates that better error handling is needed. Consider implementing proper error handling instead of using console.log.

-      console.log("Missing payment options"); //TODOO - better error handling
+      setPaymentError(t("errors.missingPaymentOptions"));
+      return;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 90d2774 and 9e8b60b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (15)
  • package.json (1 hunks)
  • src/Donations/Components/ContactsForm.tsx (2 hunks)
  • src/Donations/Components/DonationsForm.tsx (5 hunks)
  • src/Donations/Components/PaymentsForm.tsx (2 hunks)
  • src/Donations/LeftPanel/TransactionSummary.tsx (2 hunks)
  • src/Donations/Micros/DonationAmount.tsx (2 hunks)
  • src/Donations/Micros/DonationTypes/BouquetDonations.tsx (4 hunks)
  • src/Donations/Micros/DonationTypes/FundingDonations.tsx (3 hunks)
  • src/Donations/Micros/DonationTypes/TreeDonation.tsx (2 hunks)
  • src/Donations/Micros/PaymentStatus/ImageComponent.tsx (2 hunks)
  • src/Donations/Micros/PaymentStatus/ThankyouMessage.tsx (2 hunks)
  • src/Donations/Micros/PaymentStatus/TransferDetails.tsx (2 hunks)
  • src/Donations/Micros/PlanetCashSelector.tsx (4 hunks)
  • src/Donations/PaymentMethods/PaymentMethodTabs.tsx (4 hunks)
  • src/Utils/getFormattedCurrency.ts (2 hunks)
✅ Files skipped from review due to trivial changes (4)
  • src/Utils/getFormattedCurrency.ts
  • src/Donations/Components/ContactsForm.tsx
  • src/Donations/Micros/PlanetCashSelector.tsx
  • src/Donations/Micros/PaymentStatus/ThankyouMessage.tsx
🔇 Additional comments (14)
src/Donations/Micros/DonationAmount.tsx (1)

3-3: LGTM: Consistent function renaming

The renaming from getFormatedCurrency to getFormattedCurrency is applied consistently in both the import statement and function call, maintaining the same functionality.

Also applies to: 18-21

src/Donations/LeftPanel/TransactionSummary.tsx (1)

3-3: LGTM: Consistent function renaming

The renaming from getFormatedCurrency to getFormattedCurrency is applied consistently in both the import statement and function call.

Also applies to: 71-75

package.json (1)

29-29: Verify @planet-sdk/common version update implications

The package version update from ^0.1.42 to ^0.1.47 should be verified for:

  1. Breaking changes in the changelog
  2. Impact on the currency formatting functions being modified
✅ Verification successful

Based on the analysis of the codebase, I can now generate the final response:

@planet-sdk/common version update appears safe

The version update from ^0.1.42 to ^0.1.47 appears safe as:

  1. The package is primarily used for type definitions and error handling utilities
  2. No breaking changes in dependencies (only requires @types/geojson)
  3. The codebase uses well-defined imports and interfaces from the package
  4. Currency formatting functions being modified are local to this codebase (src/Utils/getFormattedCurrency.ts) and don't depend on @planet-sdk/common
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for breaking changes in @planet-sdk/common between versions

# Fetch package info and changelog
echo "Fetching package information..."
curl -s "https://registry.npmjs.org/@planet-sdk/common" | jq '.versions["0.1.47"].dependencies'

# Check git commits between versions using GitHub API
echo "Checking commits between versions..."
gh api graphql -f query='
{
  repository(owner: "Plant-for-the-Planet-org", name: "planet-sdk") {
    refs(refPrefix: "refs/tags/", first: 10, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
      nodes {
        name
        target {
          ... on Tag {
            message
            tagger { date }
          }
        }
      }
    }
  }
}'

Length of output: 953


Script:

#!/bin/bash
# Let's check the actual usage of @planet-sdk/common in the codebase
echo "Searching for @planet-sdk/common usage..."
rg "@planet-sdk/common" -A 3

# Check if there are any currency-related imports or usage
echo "Checking currency-related imports..."
rg "currency" --type js --type ts -A 3

# Look for any package-lock.json to see the exact versions
echo "Checking package-lock.json..."
fd "package-lock.json" --exec cat {} | jq '.dependencies["@planet-sdk/common"]'

Length of output: 65436

src/Donations/Micros/PaymentStatus/ImageComponent.tsx (1)

27-27: LGTM: Currency formatting function usage is correct

The renamed getFormattedCurrency function is correctly used with proper parameters.

src/Donations/Micros/PaymentStatus/TransferDetails.tsx (1)

Line range hint 54-58: LGTM: Currency formatting implementation is correct

The renamed getFormattedCurrency function is properly imported and used with correct parameters for formatting the recurrent transfer amount.

src/Donations/Micros/DonationTypes/TreeDonation.tsx (1)

10-10: Verify consistent renaming across the codebase

Let's ensure the function renaming is consistent across all files.

✅ Verification successful

Function renaming is consistent across the codebase

The verification shows that:

  • No instances of the old function name "getFormatedCurrency" were found
  • The new function name "getFormattedCurrency" is consistently used across 13 files
  • No typos or inconsistencies were found in the function naming
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of the old function name
# and verify the new function name is used consistently

echo "Checking for old function name (getFormatedCurrency)..."
rg -l "getFormatedCurrency"

echo -e "\nVerifying usage of new function name (getFormattedCurrency)..."
rg -l "getFormattedCurrency"

echo -e "\nChecking for potential typos in the function name..."
rg -i "get.*formatted.*currency"

Length of output: 5627

src/Donations/PaymentMethods/PaymentMethodTabs.tsx (1)

12-12: LGTM!

The import statement correctly uses the renamed currency formatting function.

src/Donations/Micros/DonationTypes/FundingDonations.tsx (1)

10-12: LGTM!

The import statements correctly use the renamed currency formatting functions.

src/Donations/Micros/DonationTypes/BouquetDonations.tsx (2)

11-13: LGTM!

The import statements correctly use the renamed currency formatting functions.


Line range hint 163-171: Consider handling edge cases in currency formatting

The currency formatting logic should handle edge cases such as:

  1. Zero or negative amounts
  2. Very large numbers
  3. Different currency precision requirements
src/Donations/Components/DonationsForm.tsx (2)

260-263: LGTM! Currency formatting is consistent across all payment labels.

The currency formatting implementation is consistent across funds, planet-cash, and bouquet payment labels.

Also applies to: 269-272, 279-282


469-469: LGTM! Minimum amount currency formatting is consistent.

The currency formatting for minimum amount display matches the pattern used in payment labels.

src/Donations/Components/PaymentsForm.tsx (2)

10-10: LGTM! Import statement is correctly updated.

The import statement for getFormattedCurrency is properly updated.


422-425: LGTM! Currency formatting in CardPayments is consistent.

The currency formatting implementation in CardPayments matches the pattern used throughout the application.

src/Donations/Micros/PaymentStatus/ImageComponent.tsx Outdated Show resolved Hide resolved
- removes unnecessary `true &&...` expression
- refactors onClick handler for currency selector in TreeDonations
@sunilsabatp
Copy link
Contributor

Could you address the code factor issue ?

@mohitb35
Copy link
Contributor Author

mohitb35 commented Dec 3, 2024

Could you address the code factor issue ?

I have addressed the ones that could be addressed. The pending issue relates to complex code in the PlanetCashSelector.tsx file, but that requires a substantial refactor that is not related to this PR.

@mohitb35 mohitb35 merged commit 0f124bf into develop Dec 3, 2024
4 of 5 checks passed
@mohitb35 mohitb35 deleted the hotfix/typos-and-planet-sdk-update branch December 3, 2024 11:52
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