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

Bill Currency Utils For Conversation Support #371

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mubarak23
Copy link
Contributor

πŸ“ Description

Please provide a brief summary of the changes in this pull request. What issue(s) does this PR address? What problem(s) does it solve?

Relates to #328


βœ… Checklist

Please ensure the following tasks are completed before requesting a review:

  • My code adheres to the coding guidelines of this project.
  • I have run cargo fmt.
  • I have run cargo clippy.
  • I have added or updated tests (if applicable).
  • All CI/CD steps were successful.
  • I have updated the documentation (if applicable).
  • I have checked that there are no console errors or warnings.
  • I have verified that the application builds without errors.
  • I've described the changes made to the API. (modification, addition, deletion).

πŸš€ Changes Made

  • Other Changes:
    • Add currency utils where we can convert from BTC to SATS
    • Convert a string to a Currency enum
    • Convert a Currency enum to a string

πŸ’‘ How to Test

Please provide clear instructions on how reviewers can test your changes:

  1. cargo run build

🀝 Related Issues

List any related issues, pull requests, or discussions:


πŸ”— Additional Context (optional)

Add any other context or information that might be useful for reviewers:

[Additional notes or links]


πŸ“„ Relevant Documentation (optional)

Provide links to relevant documentation that reviewers may need:

  • [Link to related documentation]

πŸ“‹ Review Guidelines

Please focus on the following while reviewing:

  • Does the code follow the repository's contribution guidelines?
  • Are there any potential bugs or performance issues?
  • Are there any typos or grammatical errors in the code or comments?

@mubarak23 mubarak23 marked this pull request as draft February 5, 2025 11:41
@mubarak23
Copy link
Contributor Author

@zupzup kindly review this Draft PR,

am a bit confuse on where to use it in the codebase

Copy link
Collaborator

@zupzup zupzup left a comment

Choose a reason for hiding this comment

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

Generally, this looks fine with some changes (I added a few comments).

The BTC to Sat conversion is optional for now, since we don't use it anywhere as of yet.

In terms of where to add it - the validation would need to be added to every place where a sum, or amount with a currency is sent to the Web API (e.g. issue bill).

}

// Convert a Currency enum to a string
pub fn as_str(&self, currency: &str) -> Option<&'static str> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should just take &self and can just return &'static str, it doesn't have to return an Option, since you can cover every case (currently only Currency::Sat).

pub fn as_str(&self) -> &'static str {
  match self {
    Currency::Sat => "sat",
  }
}

}

// From satoshis to BTC
pub fn sat_to_btc(sats: u64) -> f64 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using f64 for currency conversion is problematic, because floating point ops can introduce precision errors.

To to this correctly, we'd need something like rust-decimal (https://docs.rs/rust_decimal/latest/rust_decimal/) or something similar.

Since we currently send the sum as a string, it would also be OK to convert to a BTC string like "0.100".

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.

3 participants