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

DRAFT: refactor currency converter - discussion #1331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gr4viton
Copy link

It is just a draft to discuss the approach

I will not polish this if this is not a "approved" direction - with enough simplicity in mind.

tldr

refactor currency converter

  • to allow multiple exchange rate getters
  • defaulting to user defined csv file
  • or if not defined hard coded exchange rates

based on discussion in - #1232

to allow multiple exchange rate getters
defaulting to user defined csv file
or hard coded exchange rates
"ZWL",
]
def get_currencies(self, with_no_currency: bool=True) -> list:
currencies = list(self.get_rates.keys())
Copy link
Author

@gr4viton gr4viton Oct 28, 2024

Choose a reason for hiding this comment

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

Or was the list of currencies hard-coded to have faster loading or something else?

I mean I removed it as I believe the currency exchange rates should be loaded close to "start-up", and then the list generated only based on the truly available ones...

Copy link
Member

Choose a reason for hiding this comment

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

I believe we could have a set of predefined rates here, but it's really not a requirement. If we want to have some of them, we could just put the most used ones here (like USD, EUR, and a few others). We don't need the full list here though :-)

@almet
Copy link
Member

almet commented Oct 28, 2024

Hey, thanks for opening this discussion with some code attached :-)

If I remember the discussion on this matter properly, I believe the way forward would be to have the ability for the users to define themselves a rate for the currency of their choosing. We could have a set of already defined currencies with set rates as a default, but the users would be able to overwrite them in the project settings page.

On the approach you're proposing here, I think we wouldn't need to have a .csv file. When I meant "in the project settings", I meant in the interface, when you go to settings for the project you're connected for.

raise NotImplementedError


class ApiExchangeRate(ExchangeRateGetter):
Copy link
Member

Choose a reason for hiding this comment

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

I believe we should ditch this way of retrieving the rates using an external API all together.

Copy link
Author

Choose a reason for hiding this comment

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

Understandable. I saw the comment mentioning other apps are also favoring the user-defined rates - and I get the simplicty is the key and not worth maintaining part of the app which would be used just by small partition of its users (providing API keys) .

Will remove.



class UserExchangeRate(ExchangeRateGetter):
user_csv_file = "path/to/file.csv"
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe using a CSV file would be useful here, instead, we could propose the user to define the rates themselves for the project, in the settings.

Copy link
Author

Choose a reason for hiding this comment

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

Understandable. Makes sense. Will try to incorporate the settings :)

class HardCodedExchangeRate(ExchangeRateGetter):

def _get_rates(self) -> Optional[dict]:
return {"USD": 1.0} # TODO fill in more
Copy link
Member

Choose a reason for hiding this comment

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

We could have the default values defined here, for sure.

@almet
Copy link
Member

almet commented Nov 30, 2024

@gr4viton hey let me know if you need any help on this :-)

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