Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 7x 911x 911x 7x 21x 21x 7x 36x 33x 7x 62x 7x 72x 70x | import { formatNumberToShort, parseAmount } from "@utils/index";
/**
* Formats an integer-cents amount as a full grouped number string (no currency
* symbol — the cards label the currency as "(USD)" instead), e.g. `4022929` →
* `40,229.29`. Uses `parseAmount` with `noFormat` so large figures are NOT
* compacted (a reconciliation report needs exact values, not `1.2M`).
*/
export const formatHubAmount = (cents?: number | null): string => {
const dollars = (cents ?? 0) / 100;
return parseAmount(dollars, 2, false, true) as string;
};
/**
* Compact variant of {@link formatHubAmount} for space-constrained cards on
* small screens: full grouped number below 1M, then compact `M`/`B`/`T`
* notation (e.g. `-7143485456.89` → `-7.14B`). Confirmed with design — used
* only where full figures would otherwise ellipsize.
*/
export const formatHubAmountCompact = (cents?: number | null): string => {
const dollars = (cents ?? 0) / 100;
return formatNumberToShort(dollars, { maxFractionDigits: 2 });
};
/**
* Formats a ratio as a one-decimal percentage, e.g. `177009 / 4022929` →
* `4.4%`. Returns `0%` when the denominator is zero/absent.
*/
export const formatHubPercent = (
numerator?: number | null,
denominator?: number | null,
): string => {
if (!denominator) return "0%";
return `${(((numerator ?? 0) / denominator) * 100).toFixed(1)}%`;
};
/**
* Formats a basis-point integer as a one-decimal percentage, e.g. `263` →
* `2.63%`. Used for the cost-rate / chargeback-rate gauges.
*/
export const formatBpsAsPercent = (bps?: number | null): string => {
return `${((bps ?? 0) / 100).toFixed(2)}%`;
};
/**
* Computes a fee's basis points relative to processed volume:
* `fee ÷ volume × 10000`. Returns 0 when volume is zero.
*/
export const computeBps = (fee?: number | null, volume?: number | null): number => {
if (!volume) return 0;
return Math.round(((fee ?? 0) / volume) * 10000);
};
|