RateTicker
- Status
- Implemented
- Family
- 4 of 13
- Registry
- @lopifi/rate-ticker
npx shadcn@latest add @lopifi/theme @lopifi/rate-tickerThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
Live multi-pair ticker. The value flash is the whole point. Pauses off-screen and on tab hide. Never a marquee — a scrolling ticker is continuous large-surface motion that can't be read and can't be paused.
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/rate-ticker.tsx
- Lopifi dependencies · 4
- cnformat-moneymoney.typesuse-live-value
- npm packages
- clsxtailwind-merge
- Registry entry
- /r/rate-ticker.json
The whole component
No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.
"use client";
import * as React from "react";
import { useLiveTicker, useValueFlash } from "@/hooks/ledger/use-live-value";
import { cn } from "@/lib/ledger/cn";
import { formatRate } from "@/lib/ledger/format-money";
export type Pair = { from: string; to: string; rate: number };
export interface RateTickerProps {
className?: string;
pairs: Pair[];
}
/**
* The value flash is the whole point. Never a marquee — a scrolling ticker
* is continuous large-surface motion that can't be read and can't be paused.
* Pauses off-screen and on tab hide.
*/
export function RateTicker({ pairs: initial, className }: RateTickerProps) {
const [pairs, setPairs] = React.useState(initial);
const ref = useLiveTicker(() => {
setPairs((prev) =>
prev.map((p) => ({
...p,
rate: p.rate * (1 + (Math.random() - 0.5) * 0.0018),
})),
);
}, 2400);
return (
<section
aria-label="Live exchange rates"
className={cn(
"flex flex-wrap gap-x-6 gap-y-2 rounded-md border border-border bg-surface px-4 py-3",
className,
)}
ref={ref}
>
{pairs.map((p) => (
<TickerCell key={`${p.from}/${p.to}`} pair={p} />
))}
</section>
);
}
function TickerCell({ pair }: { pair: Pair }) {
// Throttled to one flash per 400ms by the tick interval itself.
const { flash, key } = useValueFlash(pair.rate);
return (
<span className="flex items-baseline gap-2">
<span className="text-caption text-text-secondary">
{pair.from}/{pair.to}
</span>
<span
className={cn(
"numeric rounded-xs px-1 text-figure-sm",
flash === "positive" && "ledger-flash-positive",
flash === "negative" && "ledger-flash-negative",
)}
key={key}
>
{formatRate(pair.rate)}
</span>
</span>
);
}
Also in Swaps & FX
- SwapWidgetFrom/to with the flip. The signature component.
- RateLineA rate with its timestamp. Never one without the other.
- RateLockLocked rate with a countdown and expiry behavior.
- ConversionBreakdownAmount → fee → rate → recipient gets. Every line.
- CurrencyPairChartRate history with a period selector.
- SlippageControlTolerance setting with an explicit worst case.
- SwapRouteMulti-hop path visualization.
- FxExposurePosition by currency with unrealized gain/loss.
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 RateTicker 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.
- RateTicker, runningThe swaps showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Swaps & FXThe governing rule for this entire family: A rate is a perishable fact. It never appears without a timestamp, and it is never transacted on without a lock. Specs for 9 React components: SwapWidget, RateLine, RateLock, ConversionBreakdown and 5 more.Doc
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.