31 lines
751 B
TypeScript
31 lines
751 B
TypeScript
"use client";
|
|
|
|
import { useCurrency } from "@/lib/hooks/useCurrency";
|
|
import { formatCurrency as baseFormatCurrency } from "@customer-portal/domain/toolkit";
|
|
|
|
export function useFormatCurrency() {
|
|
const { currencyCode, currencySymbol, loading, error } = useCurrency();
|
|
|
|
const formatCurrency = (amount: number) => {
|
|
if (loading) {
|
|
// Show loading state or fallback
|
|
return "¥" + amount.toLocaleString();
|
|
}
|
|
|
|
if (error) {
|
|
// Fallback to JPY if there's an error
|
|
return baseFormatCurrency(amount, "JPY", "¥");
|
|
}
|
|
|
|
// Use the currency from WHMCS API
|
|
return baseFormatCurrency(amount, currencyCode, currencySymbol);
|
|
};
|
|
|
|
return {
|
|
formatCurrency,
|
|
currencyCode,
|
|
loading,
|
|
error,
|
|
};
|
|
}
|