Components/Currency Converter

Currency Converter

FX conversion field built on MoneyInput: edit the source amount, read the converted one, swap directions. The rate is a prop - plug in your FX feed and re-render as it ticks.


BRL

1 BRL = US$ 0,19

USDUS$ 92,50

Installation

npx @ajax-ui/cli add currency-converter

Props

  • rate (required) - price of 1 unit of fromCurrency in toCurrency. The component never fetches; rates are your data layer's job.
  • fromCurrency / toCurrency - ISO 4217 (default BRL → USD).
  • defaultAmountCents - initial source amount in minor units.
  • allowSwap (default true) - flips direction using 1/rate and resets the amount.
  • onAmountChange(fromCents, toCents) - both sides in integer minor units.

Precision

Amounts travel as integer minor units end to end; the conversion crosses major units once and rounds once, so zero-decimal currencies (JPY) scale correctly. The converted side is a read-only <output> - a quote, not an editable field, because two editable sides bound by a rounding rate can never stay mutually consistent.