Closed alxcar closed 8 months ago
Great find!
While looking at possible solutions for the issue, I found a more reliable solution, which should also be safe regarding newly introduced currencies.
For that, we can use the fact that CSFloat stores the currency in the localStorage
, which we can just retrieve:
export const userCurrency = localStorage.getItem('selected_currency') ?? 'USD';
I adjusted the code in the main-branch accordingly (commit 18d314f).
Fixed a bug where the user's currency could be invalid if their window's width was too small, breaking the extension.
If the width of the browser window is not wide enough, float might not be able to properly display the currency code (ex:
USD
,CAD
,AUD
) and would display a symbol instead (ex:$
,C$
,A$
. In that case, the following query would not be able to identify the currency,and because it would not be null, would not default to 'USD'.
In such cases, we now extract the symbol and match it with the proper currency code:
Not necessarily an ideal solution if float were to add more currencies, but we cannot use the current module "currency-symbol-map" to perform this operation.