@gearbox-protocol/ui-kit 4.0.0-next.14 → 4.0.0-next.16
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.
- package/dist/cjs/components/base/stat-badge/constants.cjs +1 -1
- package/dist/cjs/components/base/stat-badge/stat-badge.cjs +1 -1
- package/dist/cjs/components/base/strategy-apy-breakdown-card/strategy-apy-breakdown-card.cjs +1 -1
- package/dist/cjs/components/base/tabber/tabber.cjs +1 -1
- package/dist/cjs/components/checkbox/checkbox-labeled.cjs +1 -1
- package/dist/cjs/components/client-adapters/styled-rounded-image/styled-rounded-image.cjs +1 -1
- package/dist/cjs/components/index.cjs +1 -1
- package/dist/cjs/components/sdk-status-pill/constants.cjs +1 -0
- package/dist/cjs/components/sdk-status-pill/index.cjs +1 -0
- package/dist/cjs/components/sdk-status-pill/sdk-status-pill.cjs +1 -0
- package/dist/cjs/components/sdk-status-pill/sdk-status.cjs +1 -0
- package/dist/cjs/components/with-copy/with-copy.cjs +1 -1
- package/dist/cjs/components/yield-breakdown-tooltip/yield-breakdown-tooltip.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/locale/en.json.cjs +1 -1
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/cjs/utils/strategy-apy.cjs +1 -0
- package/dist/esm/components/base/stat-badge/constants.js +1 -0
- package/dist/esm/components/base/stat-badge/stat-badge.js +87 -52
- package/dist/esm/components/base/strategy-apy-breakdown-card/strategy-apy-breakdown-card.js +130 -110
- package/dist/esm/components/base/tabber/tabber.js +67 -64
- package/dist/esm/components/checkbox/checkbox-labeled.js +1 -1
- package/dist/esm/components/client-adapters/styled-rounded-image/styled-rounded-image.js +1 -1
- package/dist/esm/components/index.js +234 -235
- package/dist/esm/components/sdk-status-pill/constants.js +8 -0
- package/dist/esm/components/sdk-status-pill/index.js +8 -0
- package/dist/esm/components/sdk-status-pill/sdk-status-pill.js +59 -0
- package/dist/esm/components/sdk-status-pill/sdk-status.js +6 -0
- package/dist/esm/components/with-copy/with-copy.js +1 -1
- package/dist/esm/components/yield-breakdown-tooltip/yield-breakdown-tooltip.js +20 -19
- package/dist/esm/index.js +567 -564
- package/dist/esm/locale/en.json.js +5 -9
- package/dist/esm/utils/index.js +64 -60
- package/dist/esm/utils/strategy-apy.js +41 -0
- package/dist/types/components/base/stat-badge/constants.d.ts +1 -0
- package/dist/types/components/base/stat-badge/stat-badge.d.ts +11 -1
- package/dist/types/components/base/strategy-apy-breakdown-card/strategy-apy-breakdown-card.d.ts +12 -0
- package/dist/types/components/base/tabber/tabber.d.ts +2 -2
- package/dist/types/components/index.d.ts +1 -1
- package/dist/types/components/sdk-status-pill/constants.d.ts +5 -0
- package/dist/types/components/sdk-status-pill/index.d.ts +3 -0
- package/dist/types/components/sdk-status-pill/sdk-status-pill.d.ts +27 -0
- package/dist/types/components/sdk-status-pill/sdk-status.d.ts +11 -0
- package/dist/types/index.d.ts +1 -2
- package/dist/types/locale/en.json.d.ts +5 -9
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/strategy-apy.d.ts +37 -0
- package/package.json +1 -1
- package/dist/cjs/components/sync-status-pill/constants.cjs +0 -1
- package/dist/cjs/components/sync-status-pill/get-sync-status.cjs +0 -1
- package/dist/cjs/components/sync-status-pill/index.cjs +0 -1
- package/dist/cjs/components/sync-status-pill/sync-status-pill.cjs +0 -1
- package/dist/cjs/types/footer.cjs +0 -1
- package/dist/esm/components/sync-status-pill/constants.js +0 -10
- package/dist/esm/components/sync-status-pill/get-sync-status.js +0 -78
- package/dist/esm/components/sync-status-pill/index.js +0 -9
- package/dist/esm/components/sync-status-pill/sync-status-pill.js +0 -137
- package/dist/esm/types/footer.js +0 -1
- package/dist/types/components/sync-status-pill/constants.d.ts +0 -7
- package/dist/types/components/sync-status-pill/get-sync-status.d.ts +0 -100
- package/dist/types/components/sync-status-pill/index.d.ts +0 -3
- package/dist/types/components/sync-status-pill/sync-status-pill.d.ts +0 -42
- package/dist/types/types/footer.d.ts +0 -7
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { jsx as a, jsxs as h } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo as S, useState as y, useEffect as g } from "react";
|
|
3
|
-
import { StatusDot as x } from "../status-dot/status-dot.js";
|
|
4
|
-
import { SimpleTooltip as I } from "../tooltip/simple-tooltip.js";
|
|
5
|
-
import "../tooltip/tooltip.js";
|
|
6
|
-
import { useIntlTyped as v } from "../typed-intl/index.js";
|
|
7
|
-
import "@gearbox-protocol/sdk/common-utils";
|
|
8
|
-
import { useMediaQuery as w } from "../../hooks/use-media-query.js";
|
|
9
|
-
import { SyncStatusPillTest as c } from "./constants.js";
|
|
10
|
-
import { getSyncStatus as $, syncStatusDotVariant as A } from "./get-sync-status.js";
|
|
11
|
-
const E = 6e4 * 2.5, M = 1e3, N = "(hover: none)";
|
|
12
|
-
function F({
|
|
13
|
-
onchain: e,
|
|
14
|
-
offchain: t,
|
|
15
|
-
attach: n,
|
|
16
|
-
isSyncing: i = !1,
|
|
17
|
-
networkById: u
|
|
18
|
-
}) {
|
|
19
|
-
const { formatMessage: s } = v(), d = D(), p = !w(N), o = S(
|
|
20
|
-
() => $({
|
|
21
|
-
onchain: e,
|
|
22
|
-
offchain: t,
|
|
23
|
-
attach: n,
|
|
24
|
-
now: d,
|
|
25
|
-
staleAfterMs: E
|
|
26
|
-
}),
|
|
27
|
-
[e, t, n, d]
|
|
28
|
-
), l = s({
|
|
29
|
-
messageId: T[o.health]
|
|
30
|
-
}), m = o.syncedAt ? `${l} · ${s(
|
|
31
|
-
{ messageId: "components.syncStatus.ago" },
|
|
32
|
-
{ age: R(d - o.syncedAt) }
|
|
33
|
-
)}` : l, f = (
|
|
34
|
-
// `<output>` rather than a span with role="status": same implicit live
|
|
35
|
-
// region, and the status is announced without the dot being focusable.
|
|
36
|
-
//
|
|
37
|
-
// The box is `size-6`, not the dot's 6px: a 6px hover/tap target is far
|
|
38
|
-
// under the 24px WCAG 2.5.8 minimum and genuinely hard to hit, while the
|
|
39
|
-
// dot itself has to stay small to keep the footer quiet. So the target is
|
|
40
|
-
// the padding around it.
|
|
41
|
-
//
|
|
42
|
-
// `-m-1.5` keeps that out of the layout in both axes: the box contributes
|
|
43
|
-
// 12px, less than the 16px line beside it, so the footer row keeps its
|
|
44
|
-
// height and the links do not shift.
|
|
45
|
-
/* @__PURE__ */ a(
|
|
46
|
-
"output",
|
|
47
|
-
{
|
|
48
|
-
className: "-m-1.5 flex size-6 cursor-pointer items-center justify-center",
|
|
49
|
-
"data-testid": c.root,
|
|
50
|
-
"aria-label": m,
|
|
51
|
-
children: /* @__PURE__ */ a(
|
|
52
|
-
x,
|
|
53
|
-
{
|
|
54
|
-
variant: A(o.health),
|
|
55
|
-
size: "xs",
|
|
56
|
-
pulse: o.health === "starting" || i,
|
|
57
|
-
"data-testid": c.dot
|
|
58
|
-
}
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
return /* @__PURE__ */ a(
|
|
64
|
-
I,
|
|
65
|
-
{
|
|
66
|
-
title: f,
|
|
67
|
-
trigger: p ? "hover" : "click",
|
|
68
|
-
placement: "top",
|
|
69
|
-
maxWidth: "280px",
|
|
70
|
-
children: /* @__PURE__ */ h(
|
|
71
|
-
"div",
|
|
72
|
-
{
|
|
73
|
-
className: "flex flex-col gap-1 text-left text-xs",
|
|
74
|
-
"data-testid": c.tooltip,
|
|
75
|
-
children: [
|
|
76
|
-
/* @__PURE__ */ a("span", { className: "font-medium", "data-testid": c.headline, children: m }),
|
|
77
|
-
o.chains.map((r) => /* @__PURE__ */ a(
|
|
78
|
-
"span",
|
|
79
|
-
{
|
|
80
|
-
className: "text-muted-foreground",
|
|
81
|
-
"data-testid": c.chainRow,
|
|
82
|
-
children: `${u[r.chainId] ?? String(r.chainId)} ${_(r, s)}`
|
|
83
|
-
},
|
|
84
|
-
r.chainId
|
|
85
|
-
))
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
)
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
const T = {
|
|
93
|
-
live: "components.syncStatus.live",
|
|
94
|
-
starting: "components.syncStatus.starting",
|
|
95
|
-
cached: "components.syncStatus.cached",
|
|
96
|
-
none: "components.syncStatus.none"
|
|
97
|
-
};
|
|
98
|
-
function _(e, t) {
|
|
99
|
-
if (e.health === "none")
|
|
100
|
-
return t({ messageId: "components.syncStatus.unavailable" });
|
|
101
|
-
const [n, i, u] = e.health === "live" ? [
|
|
102
|
-
t({ messageId: "components.syncStatus.live" }),
|
|
103
|
-
"offchain",
|
|
104
|
-
e.offchain
|
|
105
|
-
] : [
|
|
106
|
-
t({ messageId: "components.syncStatus.cached" }),
|
|
107
|
-
"onchain",
|
|
108
|
-
e.onchain
|
|
109
|
-
], s = b(i, u, t);
|
|
110
|
-
return s ? `${n} · ${s}` : n;
|
|
111
|
-
}
|
|
112
|
-
function b(e, t, n) {
|
|
113
|
-
if (t === "stale")
|
|
114
|
-
return n(
|
|
115
|
-
{ messageId: "components.syncStatus.sourceOutdated" },
|
|
116
|
-
{ source: e }
|
|
117
|
-
);
|
|
118
|
-
if (t === "failed" || t === "unknown")
|
|
119
|
-
return n(
|
|
120
|
-
{ messageId: "components.syncStatus.sourceMissing" },
|
|
121
|
-
{ source: e }
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
function R(e) {
|
|
125
|
-
const t = Math.max(0, Math.round(e / 1e3));
|
|
126
|
-
return t < 60 ? `${t}s` : t < 3600 ? `${Math.round(t / 60)}m` : `${Math.round(t / 3600)}h`;
|
|
127
|
-
}
|
|
128
|
-
function D() {
|
|
129
|
-
const [e, t] = y(() => Date.now());
|
|
130
|
-
return g(() => {
|
|
131
|
-
const n = window.setInterval(() => t(Date.now()), M);
|
|
132
|
-
return () => window.clearInterval(n);
|
|
133
|
-
}, []), e;
|
|
134
|
-
}
|
|
135
|
-
export {
|
|
136
|
-
F as SyncStatusPill
|
|
137
|
-
};
|
package/dist/esm/types/footer.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { ResponseMetadata } from '@gearbox-protocol/sdk/model';
|
|
2
|
-
/**
|
|
3
|
-
* Health of one source (onchain or offchain) as far as one chain is concerned.
|
|
4
|
-
*
|
|
5
|
-
* `unknown` is not an error: it means this source has not spoken about the
|
|
6
|
-
* chain yet, which is what the first frames of a two-source read look like.
|
|
7
|
-
*/
|
|
8
|
-
export type SourceHealth = "ok" | "stale" | "failed" | "unknown";
|
|
9
|
-
/**
|
|
10
|
-
* What the user sees and can do on one chain.
|
|
11
|
-
*
|
|
12
|
-
* Derived from `onchain` alone — see {@link deriveChainHealth}. `offchain`
|
|
13
|
-
* never moves a chain between these values, it only annotates the row.
|
|
14
|
-
*/
|
|
15
|
-
export type ChainHealth =
|
|
16
|
-
/** Onchain is fresh: what is on screen is current and actions go through. */
|
|
17
|
-
"live"
|
|
18
|
-
/** Onchain lagged or never answered: rows come from the backend. */
|
|
19
|
-
| "cached"
|
|
20
|
-
/** Nobody answered. */
|
|
21
|
-
| "none";
|
|
22
|
-
/** Rolled-up health of the whole app. */
|
|
23
|
-
export type AppSyncHealth = "starting" | "live" | "cached" | "none";
|
|
24
|
-
/** Where the app's single SDK is in its attach lifecycle. */
|
|
25
|
-
export type SdkAttachStatus = "loading" | "error" | "ready";
|
|
26
|
-
/**
|
|
27
|
-
* One source exactly as the SDK returned it, plus the local clock reading of
|
|
28
|
-
* its last success.
|
|
29
|
-
*
|
|
30
|
-
* `meta` is `DataResponse.meta` verbatim — no projection, no intermediate
|
|
31
|
-
* format. The previous footer indicator died because ui-kit owned its own
|
|
32
|
-
* shape (`BlockByChain`) and the app had to hand-translate SDK state into it;
|
|
33
|
-
* the translator outlived nothing and the format outlived its source.
|
|
34
|
-
*/
|
|
35
|
-
export interface SyncSourceInput {
|
|
36
|
-
/** `DataResponse.meta`, or `undefined` while the source has never answered. */
|
|
37
|
-
meta: ResponseMetadata | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* react-query `dataUpdatedAt` in ms. The one number that cannot come from
|
|
40
|
-
* the SDK: `ChainSucceeded.timestamp` is the *block's* time, which answers
|
|
41
|
-
* "how old is the chain state", not "is our polling loop still alive".
|
|
42
|
-
* `0` / `undefined` mean no success yet.
|
|
43
|
-
*/
|
|
44
|
-
updatedAt?: number;
|
|
45
|
-
}
|
|
46
|
-
/** Per-chain outcome, ready to render as one tooltip row. */
|
|
47
|
-
export interface ChainStatus {
|
|
48
|
-
chainId: number;
|
|
49
|
-
/** Decides {@link health}, and through it the dot colour. */
|
|
50
|
-
onchain: SourceHealth;
|
|
51
|
-
/** Never decides colour — only the row's suffix. */
|
|
52
|
-
offchain: SourceHealth;
|
|
53
|
-
health: ChainHealth;
|
|
54
|
-
}
|
|
55
|
-
export interface SyncStatus {
|
|
56
|
-
health: AppSyncHealth;
|
|
57
|
-
chains: ChainStatus[];
|
|
58
|
-
/**
|
|
59
|
-
* Local clock (ms) of the last success behind what is currently shown, or
|
|
60
|
-
* `undefined` when nothing has been shown yet. Feeds the "· 12s ago" in the
|
|
61
|
-
* tooltip header.
|
|
62
|
-
*/
|
|
63
|
-
syncedAt: number | undefined;
|
|
64
|
-
}
|
|
65
|
-
export interface GetSyncStatusProps {
|
|
66
|
-
onchain: SyncSourceInput;
|
|
67
|
-
offchain: SyncSourceInput;
|
|
68
|
-
attach?: SdkAttachStatus;
|
|
69
|
-
/** Reference "now" in ms. */
|
|
70
|
-
now: number;
|
|
71
|
-
/** Age after which a source counts as stale. */
|
|
72
|
-
staleAfterMs: number;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Pure derivation of the sync indicator's state.
|
|
76
|
-
*
|
|
77
|
-
* The whole model rests on one asymmetry: **onchain is the ability to act,
|
|
78
|
-
* offchain is the trimmings** (charts, APY, history). So the colour tracks
|
|
79
|
-
* `onchain` and nothing else — a dead backend under a healthy chain is still
|
|
80
|
-
* green, because the user sees current data and their transactions land. The
|
|
81
|
-
* reverse, a live polling loop over a lagging node, is *not* green: the screen
|
|
82
|
-
* looks current while a transaction would be built against stale state.
|
|
83
|
-
*
|
|
84
|
-
* The roll-up is deliberately optimistic: one dead chain annotates its own row
|
|
85
|
-
* and leaves the dot green. Statuspage-style pessimism ("any component down ⇒
|
|
86
|
-
* system degraded") assumes components of one service; our chains are
|
|
87
|
-
* independent, and greying the dot for a chain the user is not on is a false
|
|
88
|
-
* alarm.
|
|
89
|
-
*/
|
|
90
|
-
export declare function getSyncStatus({ onchain, offchain, attach, now, staleAfterMs, }: GetSyncStatusProps): SyncStatus;
|
|
91
|
-
/** Dot variants this indicator is allowed to use. */
|
|
92
|
-
export type SyncStatusDotVariant = "success" | "default";
|
|
93
|
-
/**
|
|
94
|
-
* The palette rule, as a function rather than a comment: green when the user
|
|
95
|
-
* can act, muted grey otherwise. Never `alert` or `warning` — an alarming dot
|
|
96
|
-
* in permanent view teaches people to ignore it, and the screens surface their
|
|
97
|
-
* own failures. Exported so the rule is pinned by a unit test instead of by
|
|
98
|
-
* inspecting rendered markup.
|
|
99
|
-
*/
|
|
100
|
-
export declare function syncStatusDotVariant(health: AppSyncHealth): SyncStatusDotVariant;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { NetworkById } from '../../types/footer';
|
|
2
|
-
import { SdkAttachStatus, SyncSourceInput } from './get-sync-status';
|
|
3
|
-
import type * as React from "react";
|
|
4
|
-
export interface SyncStatusPillProps {
|
|
5
|
-
onchain: SyncSourceInput;
|
|
6
|
-
offchain: SyncSourceInput;
|
|
7
|
-
attach?: SdkAttachStatus;
|
|
8
|
-
/** A read is in flight — the dot pulses. Orthogonal to health. */
|
|
9
|
-
isSyncing?: boolean;
|
|
10
|
-
/** Only for chain labels in the tooltip. */
|
|
11
|
-
networkById: NetworkById;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* SyncStatusPill — data-freshness indicator for an app footer: one dot, and
|
|
15
|
-
* every word in the tooltip.
|
|
16
|
-
*
|
|
17
|
-
* Takes the SDK's own `DataResponse.meta` for each source, untouched, and
|
|
18
|
-
* derives the status itself. The predecessor (`BlockSyncPill`) owned a bespoke
|
|
19
|
-
* `BlockByChain` shape that each client had to hand-translate SDK state into;
|
|
20
|
-
* the format outlived its source and the translators rotted.
|
|
21
|
-
*
|
|
22
|
-
* Two deliberate constraints:
|
|
23
|
-
*
|
|
24
|
-
* - **The palette is green and muted grey only** — never red or amber, at any
|
|
25
|
-
* input. See {@link syncStatusDotVariant}.
|
|
26
|
-
* - **No visible label.** Colour therefore separates only two of the four
|
|
27
|
-
* states, which makes the tooltip the status rather than a nicety — and it is
|
|
28
|
-
* mirrored into `aria-label`, because a screen reader cannot see colour.
|
|
29
|
-
*
|
|
30
|
-
* Colour tracks `onchain` alone; see {@link getSyncStatus} for why.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* <SyncStatusPill
|
|
35
|
-
* onchain={{ meta: onchainResponse?.meta, updatedAt: onchainUpdatedAt }}
|
|
36
|
-
* offchain={{ meta: offchainResponse?.meta, updatedAt: offchainUpdatedAt }}
|
|
37
|
-
* attach="ready"
|
|
38
|
-
* networkById={{ 1: "Ethereum" }}
|
|
39
|
-
* />
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function SyncStatusPill({ onchain, offchain, attach, isSyncing, networkById, }: SyncStatusPillProps): React.ReactElement;
|