FxExposure
- Status
- Implemented
- Family
- 4 of 13
- Registry
- @lopifi/fx-exposure
npx shadcn@latest add @lopifi/theme @lopifi/fx-exposureThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
Position by currency with unrealized gain/loss. Uses polarity="standard" per position, and clearly separates realized from unrealized — they're different facts and conflating them misstates the position.
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/fx-exposure.tsx
- Lopifi dependencies · 13
- as-ofcncurrency-badgedeltafiscal-periodformat-moneymoneymoney.typespercentruletooltipuse-scroll-edgesuse-shared-now
- npm packages
- @base-ui-components/reactclass-variance-authorityclsxtailwind-merge
- Registry entry
- /r/fx-exposure.json
The whole component
No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.
import * as React from "react";
import { useScrollEdges } from "@/hooks/ledger/use-scroll-edges";
import { cn } from "@/lib/ledger/cn";
import type { MoneyValue } from "@/lib/ledger/money.types";
import { AsOf } from "@/components/ledger/as-of";
import { CurrencyBadge } from "@/components/ledger/currency-badge";
import { Delta } from "@/components/ledger/delta";
import { Money } from "@/components/ledger/money";
import { Rule } from "@/components/ledger/rule";
export type Position = {
currency: string;
position: MoneyValue;
/** In the presentation currency, at the stated rate. */
presentationValue: MoneyValue;
rate: number;
/** Realized and unrealized are different facts. Never combined. */
unrealized: MoneyValue;
realized: MoneyValue;
};
export interface FxExposureProps extends React.ComponentPropsWithoutRef<"div"> {
asOf: Date;
/** Caps the scroller so the header and the currency column can freeze. */
maxHeight?: number;
positions: Position[];
presentationCurrency: string;
totalRealized: MoneyValue;
totalUnrealized: MoneyValue;
}
export const FxExposure = React.forwardRef<HTMLDivElement, FxExposureProps>(
(
{
className,
positions,
presentationCurrency,
totalUnrealized,
totalRealized,
asOf,
maxHeight = 520,
...props
},
ref,
) => {
const scroller = useScrollEdges<HTMLDivElement>();
return (
<div className={cn("rounded-xl border border-border bg-surface", className)} ref={ref} {...props}>
<div className="px-6 pb-4 pt-6">
<p className="text-title-sm font-medium">FX exposure</p>
<p className="text-caption text-text-secondary">
Presented in {presentationCurrency} · <AsOf date={asOf} />
</p>
</div>
<div className="ledger-frozen scrollbar-thin" ref={scroller} style={{ maxHeight }}>
<table className="w-full min-w-[640px]">
<caption className="sr-only">FX exposure, presented in {presentationCurrency}</caption>
<thead>
<tr className="border-b border-border-subtle">
<th className="px-6 py-3 text-left text-label text-text-secondary" scope="col">
Currency
</th>
<th className="px-3 py-3 text-right text-label text-text-secondary" scope="col">
Position
</th>
<th className="px-3 py-3 text-right text-label text-text-secondary" scope="col">
Rate
</th>
<th className="px-3 py-3 text-right text-label text-text-secondary" scope="col">
Value ({presentationCurrency})
</th>
<th className="px-3 py-3 text-right text-label text-text-secondary" scope="col">
Unrealized
</th>
<th className="px-6 py-3 text-right text-label text-text-secondary" scope="col">
Realized
</th>
</tr>
</thead>
<tbody>
{positions.map((p) => (
<tr className="border-b border-border-subtle" key={p.currency}>
<th className="px-6 py-3 text-left" scope="row">
<CurrencyBadge currency={p.currency} />
</th>
<td className="px-3 py-3 text-right">
<Money accounting showCode value={p.position} />
</td>
<td className="numeric px-3 py-3 text-right text-figure-sm text-text-secondary">
{p.rate.toFixed(5)}
</td>
<td className="px-3 py-3 text-right">
<Money accounting value={p.presentationValue} />
</td>
<td className="px-3 py-3 text-right">
<Delta polarity="standard" showArrow={false} value={p.unrealized} />
</td>
<td className="px-6 py-3 text-right">
<Delta polarity="standard" showArrow={false} value={p.realized} />
</td>
</tr>
))}
</tbody>
<tfoot>
<tr>
<td colSpan={4} />
<td className="px-3">
<Rule variant="subtotal" />
</td>
<td className="px-6">
<Rule variant="subtotal" />
</td>
</tr>
<tr>
<th className="px-6 py-3 text-left text-label font-medium" scope="row">
Total
</th>
<td colSpan={3} />
<td className="px-3 py-3 text-right">
<Money accounting size="md" value={totalUnrealized} />
</td>
<td className="px-6 py-3 text-right">
<Money accounting size="md" value={totalRealized} />
</td>
</tr>
</tfoot>
</table>
</div>
</div>
);
},
);
FxExposure.displayName = "FxExposure";
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.
- RateTickerLive multi-pair ticker with value flash.
- SlippageControlTolerance setting with an explicit worst case.
- SwapRouteMulti-hop path visualization.
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 FxExposure 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.
- FxExposure, 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.