CodingNic

Next.js Project Foundation

Prepare the Currency Data Layer

Next.js Project Foundation 20 min read

Prepare the Currency Data Layer

Prepare the Currency Data Layer

Open lib/currencies.js.

The project keeps currency display data and fallback rates in one module so the UI can reuse the same source.

javascript
export function getRate(rates, from, to) {
  return from === to
    ? 1
    : (rates[to] ?? fallbackRates[to]) / (rates[from] ?? fallbackRates[from]);
}

This helper will become the bridge between API responses and the converter UI.

Test it

Temporarily check that switching the from and to arguments produces the expected ratio.

Checkpoint

You have one shared place for currency metadata, fallback data, and rate calculation.