How to use convert back-and-forth with just one rates object? #762
Unanswered
victorcarvalhosp
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone! First of all, thanks for the great job everyone is doing on Dinero 2.0.
I'm confused about how can I use the convert function to convert back and forth between two different currencies. In the documentation, there's an example showing how to convert from USD to EUR - but how can I convert back from EUR to USD without creating a new rates object?
I'm my application I have an object like this(let's assume these values are update daily):
export const myRatesObject = {
EUR: { amount: 95, scale: 2 },
ETH: { amount: 64, scale: 5 },
BTC: { amount: 3719503474549434, scale: 20 },
BRL: { amount: 501, scale: 2 },
};
But this just works if I'm trying to convert these currencies to USD - but not the other way around. So for example, this works:
But I expect the other way around to work as well - without the need of creating a new rates object for each currency, something like:
If I need to create a new rates object for each currency, then these objects become unmanageable as I can have almost infinite combinations. I want to have just one single source of truth, that is the USD rates object and be able to convert everything back and forth just using it.
I'm missing something here? Can someone clear my mind or give some examples of how can I achieve this?
Beta Was this translation helpful? Give feedback.
All reactions