diff --git a/app/api/privacy-policy/route.js b/app/api/privacy-policy/route.js index cacc09d..2ba4c84 100644 --- a/app/api/privacy-policy/route.js +++ b/app/api/privacy-policy/route.js @@ -43,7 +43,7 @@ export function GET() {
We may occasionally update this Privacy Policy, and we encourage you to periodically review it to stay informed about how we are protecting your information. We will post any changes on this page, and if the changes are significant, we will provide a more prominent notice.
If you have any questions or comments about this Privacy Policy, or if you would like us to update information we have about you or your preferences, please contact us by email at contact@nepalirudraksha.com.
+If you have any questions or comments about this Privacy Policy, or if you would like us to update information we have about you or your preferences, please contact us by email at nepali.rudrakshabeads@gmail.com.
Your privacy is of utmost importance to us. We commit to safeguarding your personal information in accordance with legal obligations. By using our app, you are accepting the practices outlined in this Privacy Policy. If you do not agree to the terms of this Privacy Policy, please refrain from using our app.
diff --git a/app/contexts/currencyContext.js b/app/contexts/currencyContext.js index 71c03e8..72b48db 100644 --- a/app/contexts/currencyContext.js +++ b/app/contexts/currencyContext.js @@ -1,5 +1,7 @@ "use client"; import React, { createContext, useContext, useState, useEffect } from "react"; +import axios from 'axios'; + const CurrencyContext = createContext(); @@ -15,6 +17,7 @@ export const CurrencyProvider = ({ children }) => { const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); + const fetchExchangeRates = async () => { try { setIsLoading(true); @@ -23,60 +26,74 @@ export const CurrencyProvider = ({ children }) => { const cachedData = localStorage.getItem("exchangeRates"); const cached = cachedData ? JSON.parse(cachedData) : null; - if ( - cached && - new Date().getTime() - cached.timestamp < 24 * 60 * 60 * 1000 - ) { + if (cached && new Date().getTime() - cached.timestamp < 24 * 60 * 60 * 1000) { setExchangeRates(cached.rates); setIsLoading(false); return; } - const currencies = Object.keys(SUPPORTED_CURRENCIES) - .filter((key) => key !== "INR") - .join(","); + try { + const currencies = Object.keys(SUPPORTED_CURRENCIES) + .filter((key) => key !== "INR") + .join(","); - const response = await fetch( - `https://apilayer.net/api/live?access_key=9bcb30907dee1cda9866f7b49f0f8def¤cies=${currencies}&source=INR&format=1` - ); + const response = await axios.get("https://apilayer.net/api/live", { + params: { + access_key: "9bcb30907dee1cda9866f7b49f0f8def", + currencies: currencies, + source: "INR", + format: 1, + }, + }); - if (!response.ok) { - throw new Error("Failed to fetch exchange rates"); + const data = response.data; + + if (!data.success) { + throw new Error(data.error?.info || "API request failed"); + } + + const rates = Object.keys(SUPPORTED_CURRENCIES).reduce( + (acc, currency) => { + if (currency === "INR") { + acc[currency] = 1; + } else { + const rate = data.quotes?.[`INR${currency}`]; + if (!rate) { + throw new Error(`Rate not found for ${currency}`); + } + acc[currency] = rate; + } + return acc; + }, + {} + ); + + localStorage.setItem( + "exchangeRates", + JSON.stringify({ rates, timestamp: new Date().getTime() }) + ); + + setExchangeRates(rates); + } catch (error) { + console.error("Error fetching exchange rates:", error); + + setError("Failed to load currency conversion rates. Please try again later."); + + if (cached) { + console.log("Using older cached rates as fallback"); + setExchangeRates(cached.rates); + } else { + setExchangeRates(null); + } } - const data = await response.json(); - if (!data.success) { - throw new Error(data.error?.info || "API request failed"); - } - - const rates = Object.keys(SUPPORTED_CURRENCIES).reduce( - (acc, currency) => { - if (currency === "INR") { - acc[currency] = 1; - } else { - const rate = data.quotes?.[`INR${currency}`]; - acc[currency] = rate || null; - } - return acc; - }, - {} - ); - - const ratesData = { - rates, - timestamp: data.timestamp * 1000, - }; - - localStorage.setItem("exchangeRates", JSON.stringify(ratesData)); - setExchangeRates(rates); - } catch (err) { - setError("Error fetching exchange rates"); - console.error("Exchange rate fetch error:", err); - } finally { + setIsLoading(false); + } catch (error) { + console.error("Error in exchange rate handling:", error); + setError("Failed to load currency conversion rates"); setIsLoading(false); } }; - const convertPrice = (price) => { if (!price || typeof price !== "number") return price; if (!exchangeRates || !exchangeRates[selectedCurrency]) return price; diff --git a/components/common/CurrencyTooltip.jsx b/components/common/CurrencyTooltip.jsx new file mode 100644 index 0000000..49acf83 --- /dev/null +++ b/components/common/CurrencyTooltip.jsx @@ -0,0 +1,25 @@ +// Create a new component for currency conversion explanation +import React from 'react'; +import { Info } from 'lucide-react'; +import { useCurrency } from '@/app/contexts/currencyContext'; + +const CurrencyTooltip = () => { + const { selectedCurrency, SUPPORTED_CURRENCIES } = useCurrency(); + + // Only show for non-INR currencies + if (selectedCurrency === 'INR') return null; + + return ( ++
{message}
)} @@ -123,7 +230,6 @@ const PremiumBanner = ({ data }) => {