Skip to content

Commit 024ed2d

Browse files
authored
feat: improve sync indicator error message (#1892)
1 parent 17ac8f8 commit 024ed2d

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

apps/namadillo/src/App/Layout/SyncIndicator.tsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,43 @@ import {
77
import { useAtomValue } from "jotai";
88
import { twMerge } from "tailwind-merge";
99

10+
const formatError = (
11+
errors: (string | Error)[],
12+
label?: string
13+
): JSX.Element => {
14+
if (!errors.length) {
15+
return <></>;
16+
}
17+
18+
return (
19+
<div>
20+
{label && <div>{label}:</div>}
21+
{errors.map((e) => {
22+
const string = e instanceof Error ? e.message : String(e);
23+
return <div key={string}>{string}</div>;
24+
})}
25+
</div>
26+
);
27+
};
28+
1029
export const SyncIndicator = (): JSX.Element => {
1130
const syncStatus = useAtomValue(syncStatusAtom);
1231
const indexerServicesSyncStatus = useAtomValue(indexerServicesSyncStatusAtom);
1332
const chainStatus = useAtomValue(chainStatusAtom);
1433

15-
const isError = syncStatus.isError || indexerServicesSyncStatus.isError;
16-
const isSyncing = syncStatus.isSyncing || indexerServicesSyncStatus.isSyncing;
34+
const { errors } = syncStatus;
1735
const { services } = indexerServicesSyncStatus;
36+
const isChainStatusError = !chainStatus?.height || !chainStatus?.epoch;
37+
38+
const isError =
39+
syncStatus.isError ||
40+
indexerServicesSyncStatus.isError ||
41+
isChainStatusError;
42+
43+
const isSyncing = syncStatus.isSyncing || indexerServicesSyncStatus.isSyncing;
1844

1945
return (
20-
<div className="relative group/tooltip p-1">
46+
<div className="relative group/tooltip px-1 py-3">
2147
<div
2248
className={twMerge(
2349
"w-2 h-2 rounded-full",
@@ -26,12 +52,23 @@ export const SyncIndicator = (): JSX.Element => {
2652
isError && !isSyncing && "bg-red-500"
2753
)}
2854
/>
29-
<Tooltip className="whitespace-nowrap">
55+
<Tooltip
56+
position="bottom"
57+
className="z-10 w-max max-w-[200px] text-balance"
58+
>
3059
{isSyncing ?
3160
"Syncing"
3261
: isError ?
33-
`Error syncing ${services.length ? `. Lagging services: ${services.join(", ")}.` : ""}`
34-
: `Fully synced: height ${chainStatus?.height}, epoch ${chainStatus?.epoch}`
62+
<div>
63+
{formatError(errors, "Error")}
64+
{formatError(services, "Lagging services")}
65+
{isChainStatusError && "Chain status not loaded."}
66+
</div>
67+
: <div>
68+
<div>Fully synced:</div>
69+
<div>Height:{chainStatus?.height}</div>
70+
<div>Epoch:{chainStatus?.epoch}</div>
71+
</div>
3572
}
3673
</Tooltip>
3774
</div>

apps/namadillo/src/atoms/syncStatus/atoms.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ export const syncStatusAtom = atom((get) => {
3434

3535
const isSyncing = queries.some((q) => q.isFetching);
3636
const isError = queries.some((q) => q.isError);
37+
const errors = queries.filter((q) => q.isError).map((q) => q.error);
3738

3839
return {
3940
isSyncing,
4041
isError,
42+
errors,
4143
};
4244
});
4345

packages/utils/src/helpers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ export const truncateInMiddle = (
213213
* check a possible case e.g. when switching on the value of an enum.
214214
*/
215215
// eslint-disable-next-line
216-
export const assertNever = (_a: never): never => {
217-
throw new Error("this should never happen");
216+
export const assertNever = (error: never): never => {
217+
throw new Error(`This should never happen: ${error}`);
218218
};
219219

220220
export type Ok<T> = { ok: true; value: T };

0 commit comments

Comments
 (0)