Skip to content

SlippageControl

Tolerance setting with an explicit worst case.
Implemented
Status
Implemented
Family
4 of 13
Registry
@lopifi/slippage-control
npx shadcn@latest add @lopifi/theme @lopifi/slippage-control

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

The four-layer spec

Tolerance setting that always states the worst case in absolute money: "You'll receive at least 910.15 EUR". A percentage alone is not a decision-grade number.

Lifted verbatim from Swaps & FX. The doc and this page are the same paragraphs, so they cannot disagree.

What lands in your repository

One component is never one file. Everything below is copied into your project, where you own it.

Files

components/ledger/slippage-control.tsx

Lopifi dependencies · 5
cnformat-moneymoneymoney.typestooltip
npm packages
@base-ui-components/reactclass-variance-authorityclsxtailwind-merge
Registry entry
/r/slippage-control.json

The whole component

No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.

components/ledger/slippage-control.tsx
"use client";

import { cn } from "@/lib/ledger/cn";
import type { MoneyValue } from "@/lib/ledger/money.types";
import { Money } from "@/components/ledger/money";

export interface SlippageControlProps {
  className?: string;
  onValueChange: (percent: number) => void;
  value: number;
  /** The worst case, in absolute money. A percentage alone is not decision-grade. */
  worstCase: MoneyValue;
}

const PRESETS = [0.1, 0.5, 1];

export function SlippageControl({ value, onValueChange, worstCase, className }: SlippageControlProps) {
  return (
    <div className={cn("space-y-2", className)}>
      <span className="block text-label font-medium text-text-secondary">Slippage tolerance</span>
      <div className="flex flex-wrap items-center gap-2">
        {PRESETS.map((p) => (
          <button
            aria-pressed={value === p}
            className={cn(
              "numeric h-8 rounded-sm border px-3 text-label font-medium",
              "transition-colors duration-1 ease-standard",
              value === p
                ? "border-accent bg-accent-subtle text-accent"
                : "border-border hover:bg-surface-hover",
            )}
            key={p}
            onClick={() => onValueChange(p)}
            type="button"
          >
            {p}%
          </button>
        ))}
        <label className="flex items-center gap-2">
          <span className="sr-only">Custom slippage tolerance, percent</span>
          <input
            className="numeric h-8 w-16 rounded-sm border border-border bg-surface px-2 text-label outline-none focus-visible:border-accent"
            inputMode="decimal"
            onChange={(e) => onValueChange(Number(e.target.value.replace(/[^\d.]/g, "")) || 0)}
            type="text"
            value={value}
          />
          <span aria-hidden="true" className="text-label text-text-secondary">
            %
          </span>
        </label>
      </div>
      <p className="text-caption text-text-secondary">
        You’ll receive at least <Money showCode size="xs" tone="inherit" value={worstCase} />.
      </p>
    </div>
  );
}

Also in Swaps & FX

See also

A component is specified in one place, defined in another, and running in a third. All three, from here.

Elsewhere in the system

Where SlippageControl sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.

Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.

Told when Swaps & FX changes

Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.