@gearbox-protocol/permissionless-ui 1.22.0-next.37 → 1.22.0-next.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,48 +1,76 @@
1
- import { BigIntMath as f, formatBN as a, WAD_DECIMALS_POW as s } from "@gearbox-protocol/sdk";
2
- const N = 10000000000000000n;
3
- function b(t) {
1
+ import { BigIntMath as M, formatBN as A, WAD_DECIMALS_POW as $, PERCENTAGE_FACTOR as g } from "@gearbox-protocol/sdk";
2
+ import "react";
3
+ import { bnToInputView as h } from "./bn-to-input-view.js";
4
+ import "clsx";
5
+ import "tailwind-merge";
6
+ import "sonner";
7
+ import "react/jsx-runtime";
8
+ const _ = 10000000000000000n;
9
+ function F(t) {
4
10
  return BigInt(t.toFixed(18).replace(".", ""));
5
11
  }
6
- function p(t, e) {
7
- const r = typeof t == "number" && t < 0 || typeof t == "bigint" && t < 0n ? "-" : "", o = typeof t == "number" ? b(Math.abs(t)) : f.abs(t), u = o < N && o > 0n, i = u ? "0.01" : a(o, s, e), c = `${r}$${i}`;
8
- return u ? `< ${c}` : c;
12
+ function R(t, r) {
13
+ const n = typeof t == "number" && t < 0 || typeof t == "bigint" && t < 0n ? "-" : "", s = typeof t == "number" ? F(Math.abs(t)) : M.abs(t), u = s < _ && s > 0n, f = u ? "0.01" : A(s, $, r), o = `${n}$${f}`;
14
+ return u ? `< ${o}` : o;
9
15
  }
10
- const y = 1e4;
11
- function m(t, e, n = !0) {
12
- const r = typeof t == "number" ? t : Number(t);
13
- return Number.isNaN(r) || r === void 0 || r === null ? "0" : r === 0 ? 0 : n && r > y ? r.toExponential(e) : r.toFixed(e);
16
+ const O = 1e4;
17
+ function p(t, r, i = !0) {
18
+ const n = typeof t == "number" ? t : Number(t);
19
+ return Number.isNaN(n) || n === void 0 || n === null ? "0" : n === 0 ? 0 : i && n > O ? n.toExponential(r) : n.toFixed(r);
14
20
  }
15
- function g(t, e = 2) {
16
- return `${m(t, e)}%`;
21
+ function y(t, r = 2) {
22
+ return `${p(t, r)}%`;
17
23
  }
18
- const E = 1e4;
19
- function T(t, e = 2) {
20
- const n = Number(t) / Number(E);
21
- return `${m(n, e)}%`;
22
- }
23
- const A = 1000n;
24
- function S(t, e) {
25
- let n;
26
- return typeof t == "string" ? n = Number.parseFloat(t) || 0 : typeof t == "bigint" ? n = Number(t) : n = t, typeof e == "number" ? new Intl.NumberFormat("en-US", {
27
- style: "currency",
28
- currency: "USD",
29
- minimumFractionDigits: e,
30
- maximumFractionDigits: e
31
- }).format(n) : e && typeof e == "object" ? new Intl.NumberFormat("en-US", {
32
- style: "currency",
33
- currency: "USD",
34
- ...e
35
- }).format(n) : new Intl.NumberFormat("en-US", {
36
- style: "currency",
37
- currency: "USD"
38
- }).format(n);
24
+ function H(t, r = 2) {
25
+ const i = Number(t) / Number(g);
26
+ return `${p(i, r)}%`;
39
27
  }
28
+ const c = {
29
+ minimumFractionDigits: 2,
30
+ maximumFractionDigits: 2,
31
+ decimalPrecision: 4,
32
+ minDecimalThreshold: 1,
33
+ minExponentialThreshold: 1e-4,
34
+ maxExponentialThreshold: 1e6,
35
+ locale: "en-US"
36
+ }, U = ({
37
+ amount: t,
38
+ format: r = "full",
39
+ maximumFractionDigits: i = c.maximumFractionDigits,
40
+ minimumFractionDigits: n = c.minimumFractionDigits,
41
+ decimalPrecision: s = c.decimalPrecision,
42
+ minDecimalThreshold: u = c.minDecimalThreshold,
43
+ minExponentialThreshold: f = c.minExponentialThreshold,
44
+ maxExponentialThreshold: o = c.maxExponentialThreshold,
45
+ locale: N = c.locale
46
+ }) => {
47
+ const m = typeof t == "bigint" ? Number(h(t, 8)) : t, e = Math.abs(m);
48
+ if (r === "short") {
49
+ const T = m < 0 ? "-" : "", a = (l, d) => {
50
+ const b = l >= 100 ? 0 : i, E = l.toFixed(b).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
51
+ return `${T}${E}${d}`;
52
+ };
53
+ if (e >= 1e9 && e <= o)
54
+ return a(e / 1e9, "B");
55
+ if (e >= 1e6 && e <= o)
56
+ return a(e / 1e6, "M");
57
+ if (e >= 1e3 && e <= o)
58
+ return a(e / 1e3, "K");
59
+ if (e > o)
60
+ return a(e / o, "M+");
61
+ }
62
+ return e > o && r === "full" ? (m / c.maxExponentialThreshold).toFixed(
63
+ n
64
+ ) + "M" : e < f && e > 0 ? m.toFixed(Math.max(10, i)) : e < u && e > 0 ? m.toPrecision(s) : m.toLocaleString(N, {
65
+ minimumFractionDigits: n,
66
+ maximumFractionDigits: i
67
+ });
68
+ };
40
69
  export {
41
- E as PERCENTAGE_FACTOR,
42
- A as SLIPPAGE_DECIMALS,
43
- p as formatMoney,
44
- S as formatMoneyAmount,
45
- m as formatPercentAmount,
46
- g as percentTemplate,
47
- T as percentageTemplate
70
+ c as DEFAULT_FORMAT_MONEY_CONSTANTS,
71
+ R as formatMoney,
72
+ U as formatMoneyAmount,
73
+ p as formatPercentAmount,
74
+ y as percentTemplate,
75
+ H as percentageTemplate
48
76
  };
@@ -4,87 +4,85 @@ import { bnToPrettyView as i } from "./bn-to-pretty-view.js";
4
4
  import { cn as f, cn as l } from "./cn.js";
5
5
  import { generateColorsFromBase as T, getCSSVariable as x, hexToRgba as c, resolveCSSColor as g } from "./colors.js";
6
6
  import { copyToClipboard as u } from "./copy.js";
7
- import { convertPercent as A, formatBytecodeSize as N, formatBytecodeVersion as P, formatTimestamp as b, shortenHash as h, significantTrunc as I } from "./format.js";
8
- import { formatAssetAmount as L } from "./format-asset-amount.js";
9
- import { PERCENTAGE_FACTOR as F, SLIPPAGE_DECIMALS as k, formatMoney as v, formatMoney as w, formatPercentAmount as E, percentTemplate as V, percentageTemplate as B } from "./format-money.js";
10
- import { FORMAT_CONSTANTS as M, formatNumberWithSuffix as R, formatPrice as _, getAdaptiveDecimals as O, isBelowDisplayThreshold as z, isEffectivelyZero as Z, toSignificantDigits as G } from "./format-number.js";
11
- import { slippageTemplate as W } from "./format-slippage.js";
12
- import { allLoaded as X, loadingProgress as j, round5 as J } from "./loading.js";
13
- import { getNetworkIcon as Q } from "./network-icons.js";
14
- import { bnToLiquidationPriceView as Y, isPositiveFloat as $, parseInputToBN as ee, parseSmallNumber as oe } from "./parse-input-to-bn.js";
15
- import { pluralize as te, selectPluralString as ae } from "./plural.js";
16
- import { getAvailableRanges as ne } from "./ranges.js";
17
- import { extractTextFromLabel as pe, serializeValue as fe } from "./react.js";
18
- import { searchInString as se } from "./search.js";
19
- import { createTokenSearchFilter as xe, searchInToken as ce } from "./search-in-token.js";
20
- import { shortSHA as Se } from "./short-sha.js";
21
- import { isLongString as de, shortenString as Ae } from "./shorten-string.js";
22
- import { negativeTokenTemplate as Pe, tokenTemplate as be, tokenTemplateNumber as he, tokenTemplateString as Ie } from "./templates.js";
23
- import { TTL_CONSTANTS as Le, getTTLZone as ye, ttlFromTimestamp as Fe, ttlLeft as ke, ttlLeftParsed as ve } from "./ttl.js";
24
- import { openInNewWindow as Ee } from "./window.js";
25
- import { Z_INDEX as Be } from "./z-index.js";
7
+ import { convertPercent as b, formatBytecodeSize as h, formatBytecodeVersion as N, formatTimestamp as A, shortenHash as I, significantTrunc as P } from "./format.js";
8
+ import { formatAssetAmount as F } from "./format-asset-amount.js";
9
+ import { formatMoney as k, formatMoneyAmount as v, formatPercentAmount as w, percentTemplate as C, percentageTemplate as V } from "./format-money.js";
10
+ import { FORMAT_CONSTANTS as D, formatNumberWithSuffix as z, formatPrice as M, getAdaptiveDecimals as O, isBelowDisplayThreshold as R, isEffectivelyZero as Z, toSignificantDigits as _ } from "./format-number.js";
11
+ import { slippageTemplate as H } from "./format-slippage.js";
12
+ import { allLoaded as q, loadingProgress as X, round5 as j } from "./loading.js";
13
+ import { getNetworkIcon as J } from "./network-icons.js";
14
+ import { bnToLiquidationPriceView as Q, isPositiveFloat as U, parseInputToBN as Y, parseSmallNumber as $ } from "./parse-input-to-bn.js";
15
+ import { pluralize as oe, selectPluralString as re } from "./plural.js";
16
+ import { getAvailableRanges as ae } from "./ranges.js";
17
+ import { extractTextFromLabel as ne, serializeValue as ie } from "./react.js";
18
+ import { searchInString as fe } from "./search.js";
19
+ import { createTokenSearchFilter as se, searchInToken as Te } from "./search-in-token.js";
20
+ import { shortSHA as ce } from "./short-sha.js";
21
+ import { isLongString as Se, shortenString as ue } from "./shorten-string.js";
22
+ import { negativeTokenTemplate as be, tokenTemplate as he, tokenTemplateNumber as Ne, tokenTemplateString as Ae } from "./templates.js";
23
+ import { TTL_CONSTANTS as Pe, getTTLZone as ye, ttlFromTimestamp as Fe, ttlLeft as Le, ttlLeftParsed as ke } from "./ttl.js";
24
+ import { openInNewWindow as we } from "./window.js";
25
+ import { Z_INDEX as Ve } from "./z-index.js";
26
26
  export {
27
- M as FORMAT_CONSTANTS,
28
- F as PERCENTAGE_FACTOR,
29
- k as SLIPPAGE_DECIMALS,
30
- Le as TTL_CONSTANTS,
31
- Be as Z_INDEX,
32
- X as allLoaded,
27
+ D as FORMAT_CONSTANTS,
28
+ Pe as TTL_CONSTANTS,
29
+ Ve as Z_INDEX,
30
+ q as allLoaded,
33
31
  m as bnToInputView,
34
- Y as bnToLiquidationPriceView,
32
+ Q as bnToLiquidationPriceView,
35
33
  i as bnToPrettyView,
36
34
  f as cn,
37
- A as convertPercent,
35
+ b as convertPercent,
38
36
  u as copyToClipboard,
39
- xe as createTokenSearchFilter,
37
+ se as createTokenSearchFilter,
40
38
  l as default,
41
- pe as extractTextFromLabel,
42
- L as formatAssetAmount,
43
- N as formatBytecodeSize,
44
- P as formatBytecodeVersion,
45
- v as formatMoney,
46
- w as formatMoneyAmount,
47
- R as formatNumberWithSuffix,
48
- E as formatPercentAmount,
49
- _ as formatPrice,
50
- b as formatTimestamp,
39
+ ne as extractTextFromLabel,
40
+ F as formatAssetAmount,
41
+ h as formatBytecodeSize,
42
+ N as formatBytecodeVersion,
43
+ k as formatMoney,
44
+ v as formatMoneyAmount,
45
+ z as formatNumberWithSuffix,
46
+ w as formatPercentAmount,
47
+ M as formatPrice,
48
+ A as formatTimestamp,
51
49
  T as generateColorsFromBase,
52
50
  r as generateId,
53
51
  O as getAdaptiveDecimals,
54
- ne as getAvailableRanges,
52
+ ae as getAvailableRanges,
55
53
  x as getCSSVariable,
56
- Q as getNetworkIcon,
54
+ J as getNetworkIcon,
57
55
  ye as getTTLZone,
58
56
  c as hexToRgba,
59
- z as isBelowDisplayThreshold,
57
+ R as isBelowDisplayThreshold,
60
58
  Z as isEffectivelyZero,
61
- de as isLongString,
62
- $ as isPositiveFloat,
63
- j as loadingProgress,
64
- Pe as negativeTokenTemplate,
65
- Ee as openInNewWindow,
66
- ee as parseInputToBN,
67
- oe as parseSmallNumber,
68
- V as percentTemplate,
69
- B as percentageTemplate,
70
- te as pluralize,
59
+ Se as isLongString,
60
+ U as isPositiveFloat,
61
+ X as loadingProgress,
62
+ be as negativeTokenTemplate,
63
+ we as openInNewWindow,
64
+ Y as parseInputToBN,
65
+ $ as parseSmallNumber,
66
+ C as percentTemplate,
67
+ V as percentageTemplate,
68
+ oe as pluralize,
71
69
  g as resolveCSSColor,
72
- J as round5,
73
- se as searchInString,
74
- ce as searchInToken,
75
- ae as selectPluralString,
76
- fe as serializeValue,
77
- Se as shortSHA,
78
- h as shortenHash,
79
- Ae as shortenString,
80
- I as significantTrunc,
81
- W as slippageTemplate,
82
- G as toSignificantDigits,
83
- be as tokenTemplate,
84
- he as tokenTemplateNumber,
85
- Ie as tokenTemplateString,
70
+ j as round5,
71
+ fe as searchInString,
72
+ Te as searchInToken,
73
+ re as selectPluralString,
74
+ ie as serializeValue,
75
+ ce as shortSHA,
76
+ I as shortenHash,
77
+ ue as shortenString,
78
+ P as significantTrunc,
79
+ H as slippageTemplate,
80
+ _ as toSignificantDigits,
81
+ he as tokenTemplate,
82
+ Ne as tokenTemplateNumber,
83
+ Ae as tokenTemplateString,
86
84
  Fe as ttlFromTimestamp,
87
- ke as ttlLeft,
88
- ve as ttlLeftParsed,
85
+ Le as ttlLeft,
86
+ ke as ttlLeftParsed,
89
87
  t as useFormFieldIds
90
88
  };
@@ -133,5 +133,5 @@ export * from './utils/a11y';
133
133
  export { cn } from './utils/cn';
134
134
  export * from './utils/copy';
135
135
  export * from './utils/format';
136
- export { formatMoney, formatPercentAmount, PERCENTAGE_FACTOR, percentageTemplate, percentTemplate, } from './utils/format-money';
136
+ export { formatMoney, formatPercentAmount, percentageTemplate, percentTemplate, } from './utils/format-money';
137
137
  export * from './utils/templates';
@@ -44,10 +44,6 @@ export declare function formatPercentAmount(value: number, decimals: number, all
44
44
  * ```
45
45
  */
46
46
  export declare function percentTemplate(value: number, decimals?: number): string;
47
- /**
48
- * The factor used for percentage values in basis points (10000 = 100%)
49
- */
50
- export declare const PERCENTAGE_FACTOR = 10000;
51
47
  /**
52
48
  * Formats a percentage value from basis points
53
49
  * Use this when your value is in basis points (10000 = 100%)
@@ -64,23 +60,24 @@ export declare const PERCENTAGE_FACTOR = 10000;
64
60
  * ```
65
61
  */
66
62
  export declare function percentageTemplate(value: number | bigint, decimals?: number): string;
67
- /**
68
- * The factor used for slippage values (1000 = 1%)
69
- */
70
- export declare const SLIPPAGE_DECIMALS = 1000n;
71
- /**
72
- * Formats a number or bigint as a money amount with currency formatting
73
- * Compatible with legacy API that accepts options object
74
- *
75
- * @param value - The number or bigint to format
76
- * @param options - Number of decimal places or Intl.NumberFormatOptions
77
- * @returns Formatted string like "$1,234.56"
78
- *
79
- * @example
80
- * ```ts
81
- * formatMoneyAmount(1234.56) // "$1,234.56"
82
- * formatMoneyAmount(1234.56, 0) // "$1,235"
83
- * formatMoneyAmount(1234.56, { minimumFractionDigits: 2, maximumFractionDigits: 2 }) // "$1,234.56"
84
- * ```
85
- */
86
- export declare function formatMoneyAmount(value: number | bigint | string, options?: number | Intl.NumberFormatOptions): string;
63
+ export declare const DEFAULT_FORMAT_MONEY_CONSTANTS: {
64
+ minimumFractionDigits: number;
65
+ maximumFractionDigits: number;
66
+ decimalPrecision: number;
67
+ minDecimalThreshold: number;
68
+ minExponentialThreshold: number;
69
+ maxExponentialThreshold: number;
70
+ locale: string;
71
+ };
72
+ export interface FormatMoneyAmountProps {
73
+ amount: number | bigint;
74
+ format?: "short" | "full";
75
+ maximumFractionDigits?: number;
76
+ minimumFractionDigits?: number;
77
+ decimalPrecision?: number;
78
+ minDecimalThreshold?: number;
79
+ minExponentialThreshold?: number;
80
+ maxExponentialThreshold?: number;
81
+ locale?: string;
82
+ }
83
+ export declare const formatMoneyAmount: ({ amount, format, maximumFractionDigits, minimumFractionDigits, decimalPrecision, minDecimalThreshold, minExponentialThreshold, maxExponentialThreshold, locale, }: FormatMoneyAmountProps) => string;
@@ -7,7 +7,7 @@ export * from './colors';
7
7
  export * from './copy';
8
8
  export * from './format';
9
9
  export * from './format-asset-amount';
10
- export { formatMoney, formatMoney as formatMoneyAmount, formatPercentAmount, PERCENTAGE_FACTOR, percentageTemplate, percentTemplate, SLIPPAGE_DECIMALS, } from './format-money';
10
+ export { formatMoney, formatMoneyAmount, formatPercentAmount, percentageTemplate, percentTemplate, } from './format-money';
11
11
  export { FORMAT_CONSTANTS, type FormatNumberOptions, formatNumberWithSuffix, formatPrice, getAdaptiveDecimals, isBelowDisplayThreshold, isEffectivelyZero, toSignificantDigits, } from './format-number';
12
12
  export * from './format-slippage';
13
13
  export * from './interface';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/permissionless-ui",
3
- "version": "1.22.0-next.37",
3
+ "version": "1.22.0-next.39",
4
4
  "description": "Internal UI components",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/index.js",