---
title: "Currency Swap"
description: "Swap or convert money, coins, metals, and points, or buy on a schedule. It shows a live price and the costs, then a review, each step, and the receipt."
url: https://gelatinui.com/components/currency-swap
markdown_url: https://gelatinui.com/components/currency-swap.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/currency-swap"
version: "2026-11-12"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Currency Swap

> Swap or convert money, coins, metals, and points, or buy on a schedule. It shows a live price and the costs, then a review, each step, and the receipt.

Page: https://gelatinui.com/components/currency-swap

## When to use it

Best for: A full swap panel: two amounts, a live price, costs, a confirm, and the run to the receipt.

- Use it for a swap, a money conversion, a limit order, or a recurring buy.
- Give `getQuote` and `onConfirm`; the machine owns the amounts, the quote, and the flow.
- Pick `confirm`: `review` (a dialog), `inline-slide`, or `inline-hold`.

## When not to use it

- For one amount with no second side, use a [Currency Input](https://gelatinui.com/components/currency-input.md).
- For a list of placed orders and plans, use [Currency Swap Orders](https://gelatinui.com/components/currency-swap-orders.md).

## Notes for agents

- Required: `assets` and `getQuote(request, signal)`. `getQuote` runs after a typing pause and every `holdMs` (default 15000); abort on `signal`.
- `onConfirm(order)` returns a stream of statuses (`wallet`, `pending` with steps, `done`, `refused`, `error`) or one promise of the receipt.
- Amounts are exact decimal strings: 18 decimals of ETH keep every digit. Type on either side; the other side follows the price.
- Modes: `swap`, `limit` (a price and an expiry), and `recurring` (every hour, day, week, or month).
- With no children it renders every part of the mode. Compose the parts (`CurrencySwapField`, `CurrencySwapAmount`, `CurrencySwapSwitch`, `CurrencySwapQuote`, `CurrencySwapSubmit`, and more) for a custom panel.
- `CurrencySwapRootProvider` takes a machine from `useCurrencySwapActor`, so the app can drive or read the flow.
- Settings (slippage, time limit, private send) live in `settings` or `defaultSettings`.

## Anatomy

```text
CurrencySwap
├─ CurrencySwapRootProvider (0..n)
├─ CurrencySwapHeader (0..n)
├─ CurrencySwapModes (0..n)
├─ CurrencySwapSettings (0..n)
├─ CurrencySwapField (0..n)
│  ├─ CurrencySwapLabel (0..n)
│  ├─ CurrencySwapBalance (0..n)
│  ├─ CurrencySwapAmount (0..n)
│  ├─ CurrencySwapAssetTrigger (0..n)
│  └─ CurrencySwapValue (0..n)
├─ CurrencySwapMax (0..n)
├─ CurrencySwapPercent (0..n)
├─ CurrencySwapSwitch (0..n)
├─ CurrencySwapQuote (0..n)
├─ CurrencySwapQuoteTimer (0..n)
├─ CurrencySwapDetails (0..n)
├─ CurrencySwapDetailsRow (0..n)
├─ CurrencySwapNote (0..n)
├─ CurrencySwapLimitPrice (0..n)
├─ CurrencySwapExpiry (0..n)
├─ CurrencySwapSchedule (0..n)
└─ CurrencySwapSubmit (0..n)
```

## API reference

### CurrencySwap

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `"default" \| "sm"` |  |  |
| `value` | `SwapValue` |  | The form value (controlled): the amount, its side, both asset ids, and the mode. |
| `defaultValue` | `Partial<SwapValue>` |  | The form value at first (uncontrolled); missing fields take the defaults. |
| `onValueChange` | `function` |  | People changed the form value: typed, picked, switched, or a new mode. `eventDetails.reason` says which; `eventDetails.cancel` keeps the value it had. |
| `assets` | `readonly Asset[]` |  | Every asset people can pick, on both sides. |
| `balances` | `Readonly<Record<string, string>>` |  | What the wallet holds, decimal strings by asset id. |
| `prices` | `Readonly<Record<string, number>>` |  | The price of 1 unit of each asset in `currency`, for value lines without a quote. |
| `currency` | `string` |  | The ISO 4217 code of the values. Default `"USD"`. |
| `getQuote` | `function` |  | The price source. Called after a typing pause and every `holdMs`; abort on `signal`. |
| `onConfirm` | `function` |  | Sends the swap, the order, or the plan: a stream of statuses, or one promise. |
| `settings` | `SwapSettings` |  |  |
| `defaultSettings` | `SwapSettings` |  |  |
| `onSettingsChange` | `function` |  |  |
| `confirm` | `SwapConfirmMode` |  | How people confirm. Default `review`. |
| `holdMs` | `number` |  | How long a price holds before it refreshes, in ms. Default 15 000. |
| `slowAfterMs` | `number` |  | A sent swap past this many ms shows "takes longer". Default 120 000. |
| `recent` | `readonly string[]` |  | Ids of the assets picked last, newest first, for the picker. |
| `assetsStatus` | `DataStatus` |  | The status of the asset list, for the picker. |
| `onAssetsRetry` | `function` |  |  |
| `onSearch` | `function` |  | Finds an unlisted token by a pasted address (Asset Picker `onSearch`). |
| `locale` | `string` |  |  |
| `labels` | `Partial<CurrencySwapLabels>` |  |  |
| `container` | `CurrencySwapPartsValue["container"]` |  | Where every popup portals to (the settings, the asset pickers, the date pickers, the Review): Base UI `Portal` `container`, so a scoped app or a playground keeps them in its frame. Default: the document body. |
| `children` | `ReactNode` |  | The parts. The root adds Status, Receipt, and Review when the parts leave them out. |

Also takes every prop of Base UI `UseRender`: https://base-ui.com/react/components/use-render

### CurrencySwapField

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `side` | `SwapSide` |  | The side this panel holds. |

Also takes every prop of Base UI `UseRender`: https://base-ui.com/react/components/use-render

### CurrencySwapAmount

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `maxFontSize` | `number` |  | The text size while the whole value fits, in px. Default `56`. |
| `minFontSize` | `number` |  | The smallest text size, in px. Past it the field scrolls to the caret. Default `24`. |
| `align` | `"center" \| "start"` |  | Where the value sits in the field: `center` (default) or `start`. |
| `rejectFeedback` | `boolean` |  | Nudge the value 2px when the mask rejects a key. Default `true`. |
| `onReject` | `function` |  | Runs when the mask rejects a key (a letter, a third decimal, a digit past max). |
| `rawName` | `string` |  | Also submit the raw value under this name (a hidden input), next to the shown one. |
| `className` | `string` |  | Classes of the root box (its width is the room the value fits in). |
| `ref` | `Ref<HTMLInputElement>` |  |  |

### CurrencySwapDetailsRow

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` |  | The name of the row ("Network cost"). |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| CurrencySwap | `currency-swap` |  |  |  |
| CurrencySwapRootProvider | `currency-swap` |  |  |  |
| CurrencySwapHeader | `currency-swap-header` |  |  |  |
| CurrencySwapModes | `currency-swap-modes` |  |  |  |
| CurrencySwapSettings | `currency-swap-settings` |  |  | `status-colors` |
| CurrencySwapField | `currency-swap-field` |  |  |  |
| CurrencySwapLabel | `currency-swap-label` |  |  |  |
| CurrencySwapBalance | `currency-swap-balance` | `data-over` |  | `status-colors` |
| CurrencySwapMax | `currency-swap-max` |  |  |  |
| CurrencySwapPercent | `currency-swap-percent` |  |  |  |
| CurrencySwapAmount | `currency-swap-amount` | `data-waiting` |  | `motion-timing` |
| CurrencySwapAssetTrigger | `currency-swap-asset-trigger` |  |  |  |
| CurrencySwapValue | `currency-swap-value` | `data-high` |  | `status-colors` |
| CurrencySwapSwitch | `currency-swap-switch` |  |  |  |
| CurrencySwapQuote | `currency-swap-quote-reveal` |  |  |  |
| CurrencySwapQuoteTimer | `currency-swap-quote-timer` |  |  |  |
| CurrencySwapDetails | `currency-swap-details-reveal` |  |  |  |
| CurrencySwapDetailsRow | `currency-swap-details-row` |  |  |  |
| CurrencySwapNote | `currency-swap-note` |  |  |  |
| CurrencySwapLimitPrice | `currency-swap-limit-price-reveal` |  |  |  |
| CurrencySwapExpiry | `currency-swap-expiry` |  |  |  |
| CurrencySwapSchedule | `currency-swap-schedule-reveal` |  |  |  |
| CurrencySwapSubmit | `currency-swap-submit` |  |  |  |

## Usage

Put the fields, the switch, the quote, and Submit in the swap, then the status, the receipt, and the review of the confirm flow.

```tsx title="swap-panel.tsx"
import {
  CurrencySwap,
  CurrencySwapDetails,
  CurrencySwapField,
  CurrencySwapHeader,
  CurrencySwapQuote,
  CurrencySwapSubmit,
  CurrencySwapSwitch,
} from "@/components/pro/finance/currency-swap";
import {
  CurrencySwapReceipt,
  CurrencySwapReview,
  CurrencySwapStatus,
} from "@/components/pro/finance/currency-swap-review";
import type { Asset } from "@/lib/asset-model";
import type { Quote, QuoteRequest, SwapOrder } from "@/lib/pro/currency-swap-model";

const ASSETS: Asset[] = [
  { id: "eth", kind: "crypto", code: "ETH", name: "Ether", decimals: 18 },
  { id: "usdc", kind: "crypto", code: "USDC", name: "USD Coin", decimals: 6 },
];

async function getQuote(request: QuoteRequest, signal: AbortSignal): Promise<Quote> {
  const response = await fetch(`/api/quote?amount=${request.amount}`, { signal });
  return (await response.json()) as Quote;
}

async function sendSwap(order: SwapOrder): Promise<void> {
  await fetch("/api/swaps", { method: "POST", body: JSON.stringify(order) });
}

export function SwapPanel() {
  return (
    <CurrencySwap
      assets={ASSETS}
      balances={{ eth: "1.25" }}
      defaultValue={{ payId: "eth", receiveId: "usdc" }}
      getQuote={getQuote}
      onConfirm={sendSwap}
    >
      <CurrencySwapHeader />
      <CurrencySwapField side="pay" />
      <CurrencySwapSwitch />
      <CurrencySwapField side="receive" />
      <CurrencySwapQuote />
      <CurrencySwapDetails />
      <CurrencySwapSubmit />
      <CurrencySwapStatus />
      <CurrencySwapReceipt />
      <CurrencySwapReview />
    </CurrencySwap>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/currency-swap
```

It adds 174 registry items: 168 files, 34286 lines, and the npm packages `@base-ui/react`, `@internationalized/date`, `@mantine/hooks`, `@maskito/core`, `@maskito/kit`, `@maskito/react`, `@phosphor-icons/react`, `@tanstack/react-virtual`, `@xstate/react`, `clsx`, `country-flag-icons`, `decimal.js`, `motion`, `react-aria-components`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## Built on

- [Asset Picker](https://gelatinui.com/components/asset-picker.md)
- [Auto Scale Input](https://gelatinui.com/components/auto-scale-input.md)
- [Currency Swap Review](https://gelatinui.com/components/currency-swap-review.md)
- [Swipe to Confirm](https://gelatinui.com/components/swipe-to-confirm.md)
- [Alert](https://gelatinui.com/components/alert.md)
- [Button](https://gelatinui.com/components/button.md)
- [Circular Progress](https://gelatinui.com/components/circular-progress.md)
- [Collapsible](https://gelatinui.com/components/collapsible.md)
- [Date Input](https://gelatinui.com/components/date-input.md)
- [Date Picker](https://gelatinui.com/components/date-picker.md)
- [Frame](https://gelatinui.com/components/frame.md)
- [Hold Button](https://gelatinui.com/components/hold-button.md)
- [Label](https://gelatinui.com/components/label.md)
- [Number Field](https://gelatinui.com/components/number-field.md)
- [Popover](https://gelatinui.com/components/popover.md)
- [Segmented Control](https://gelatinui.com/components/segmented-control.md)
- [Spinner](https://gelatinui.com/components/spinner.md)
- [Switch](https://gelatinui.com/components/switch.md)
- [Tabs](https://gelatinui.com/components/tabs.md)
- [Toggle Group](https://gelatinui.com/components/toggle-group.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Currency Swap Review](https://gelatinui.com/components/currency-swap-review.md)
- [Currency Swap Orders](https://gelatinui.com/components/currency-swap-orders.md)
- [Asset Picker](https://gelatinui.com/components/asset-picker.md)
- [Currency Input](https://gelatinui.com/components/currency-input.md)
- [Swipe to Confirm](https://gelatinui.com/components/swipe-to-confirm.md)
- [Button](https://gelatinui.com/components/button.md)

## Motion

| Part | Motion |
| --- | --- |
| Switch | panel · the arrows turn half a turn and the sides trade |
| Quote, details, and notes | panel · each row folds open and closed in place, on the shortest clock that keeps 15px a frame |
| Limit price and schedule | theme · the panel of the mode folds open |
| Waiting side | fade · the side that waits for a price fades to half |
