const CURRENCY_PREFERENCE_KEY_BASE = "payment-currency-preference";
export const getUserStorageKey = (base, did) => {
  return did ? `${base}:${did}` : base;
};
export const saveCurrencyPreference = (currencyId, did) => {
  try {
    localStorage.setItem(getUserStorageKey(CURRENCY_PREFERENCE_KEY_BASE, did), currencyId);
  } catch (e) {
    console.warn("Failed to save currency preference", e);
  }
};
export const getCurrencyPreference = (did, availableCurrencyIds) => {
  try {
    const saved = localStorage.getItem(getUserStorageKey(CURRENCY_PREFERENCE_KEY_BASE, did));
    if (saved && (!availableCurrencyIds || availableCurrencyIds.includes(saved))) {
      return saved;
    }
  } catch (e) {
    console.warn("Failed to access localStorage", e);
  }
  return null;
};
