Skip to content

Commit 402fbc2

Browse files
committed
feat(entropy-explorer): bind to live apis
1 parent 435b8aa commit 402fbc2

30 files changed

+1296
-1176
lines changed

apps/entropy-explorer/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@
2323
"@phosphor-icons/react": "catalog:",
2424
"@pythnetwork/component-library": "workspace:*",
2525
"clsx": "catalog:",
26-
"connectkit": "catalog:",
2726
"next": "catalog:",
2827
"nuqs": "catalog:",
2928
"react": "catalog:",
3029
"react-aria": "catalog:",
3130
"react-dom": "catalog:",
3231
"react-timeago": "catalog:",
33-
"viem": "catalog:",
34-
"wagmi": "catalog:",
3532
"zod": "catalog:"
3633
},
3734
"devDependencies": {

apps/entropy-explorer/src/components/Address/index.module.scss

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,4 @@
55
flex-flow: row nowrap;
66
gap: theme.spacing(2);
77
font-size: theme.font-size("sm");
8-
9-
.full {
10-
display: none;
11-
}
12-
13-
&:not([data-always-truncate]) {
14-
@include theme.breakpoint("xl") {
15-
.truncated {
16-
display: none;
17-
}
18-
19-
.full {
20-
display: unset;
21-
}
22-
}
23-
}
248
}

apps/entropy-explorer/src/components/Address/index.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,32 @@ import { truncate } from "../../truncate";
99
type Props = {
1010
value: string;
1111
chain: keyof typeof EntropyDeployments;
12-
alwaysTruncate?: boolean | undefined;
12+
isAccount?: boolean | undefined;
1313
};
1414

15-
export const Address = ({ value, chain, alwaysTruncate }: Props) => {
16-
const { explorer } = EntropyDeployments[chain];
15+
export const Account = (props: Omit<Props, "isAccount">) => (
16+
<Address {...props} isAccount />
17+
);
18+
19+
export const Transaction = (props: Omit<Props, "isAccount">) => (
20+
<Address {...props} />
21+
);
22+
23+
const Address = ({ value, chain, isAccount }: Props) => {
24+
const { explorerTxTemplate, explorerAccountTemplate } =
25+
EntropyDeployments[chain];
26+
const explorerTemplate = isAccount
27+
? explorerAccountTemplate
28+
: explorerTxTemplate;
1729
const truncatedValue = useMemo(() => truncate(value), [value]);
1830
return (
19-
<div
20-
data-always-truncate={alwaysTruncate ? "" : undefined}
21-
className={styles.address}
22-
>
31+
<div className={styles.address}>
2332
<Link
24-
href={explorer.replace("$ADDRESS", value)}
33+
href={explorerTemplate.replace("$ADDRESS", value)}
2534
target="_blank"
2635
rel="noreferrer"
2736
>
28-
<code className={styles.truncated}>{truncatedValue}</code>
29-
<code className={styles.full}>{value}</code>
37+
<code>{truncatedValue}</code>
3038
</Link>
3139
<CopyButton text={value} iconOnly />
3240
</div>

apps/entropy-explorer/src/components/Home/chain-select.tsx

Lines changed: 0 additions & 126 deletions
This file was deleted.

apps/entropy-explorer/src/components/Home/index.module.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@
1919
.body {
2020
@include theme.max-width;
2121

22+
.statusSelect {
23+
width: theme.spacing(36);
24+
}
25+
2226
.searchBar {
2327
width: 100%;
2428

2529
@include theme.breakpoint("lg") {
2630
width: theme.spacing(100);
2731
}
2832
}
33+
34+
.cardBody {
35+
background: theme.color("background", "primary");
36+
border-radius: theme.border-radius("xl");
37+
}
2938
}
3039
}
Lines changed: 108 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import { ListDashes } from "@phosphor-icons/react/dist/ssr/ListDashes";
22
import { Card } from "@pythnetwork/component-library/Card";
3+
import { ErrorPage } from "@pythnetwork/component-library/ErrorPage";
4+
import { NoResults } from "@pythnetwork/component-library/NoResults";
5+
import { Suspense } from "react";
36

4-
import { ChainSelect } from "./chain-select";
57
import styles from "./index.module.scss";
6-
import { Results } from "./results";
7-
import { SearchBar } from "./search-bar";
8-
import { StatusSelect } from "./status-select";
8+
import { Results as ResultsImpl, ResultsLoading } from "./results";
9+
import {
10+
SearchBar,
11+
Paginator as PaginatorImpl,
12+
ChainSelect,
13+
StatusSelect,
14+
} from "./search-controls";
15+
import type { Args } from "../../requests";
16+
import { getRequests, ResultType } from "../../requests";
917

10-
export const Home = () => (
18+
type Props = {
19+
searchParams: Promise<Args>;
20+
};
21+
22+
export const Home = (props: Props) => (
1123
<div className={styles.home}>
1224
<h1 className={styles.header}>Requests</h1>
1325
<div className={styles.body}>
@@ -16,18 +28,106 @@ export const Home = () => (
1628
icon={<ListDashes />}
1729
toolbar={
1830
<>
19-
<ChainSelect variant="outline" size="sm" placement="bottom right" />
31+
<ChainSelect
32+
label="Chain"
33+
hideLabel
34+
defaultButtonLabel="Chain"
35+
variant="outline"
36+
size="sm"
37+
placement="bottom right"
38+
/>
2039
<StatusSelect
40+
label="Status"
41+
hideLabel
42+
defaultButtonLabel="Status"
43+
hideGroupLabel
2144
variant="outline"
2245
size="sm"
2346
placement="bottom right"
47+
className={styles.statusSelect ?? ""}
48+
/>
49+
<SearchBar
50+
size="sm"
51+
placeholder="Sequence number, provider, sender or tx hash"
52+
className={styles.searchBar ?? ""}
2453
/>
25-
<SearchBar className={styles.searchBar ?? ""} />
2654
</>
2755
}
56+
footer={
57+
<Suspense>
58+
<Paginator {...props} />
59+
</Suspense>
60+
}
2861
>
29-
<Results />
62+
<div className={styles.cardBody}>
63+
<Suspense fallback={<ResultsLoading />}>
64+
<Results {...props} />
65+
</Suspense>
66+
</div>
3067
</Card>
3168
</div>
3269
</div>
3370
);
71+
72+
const Results = async (props: Props) => {
73+
try {
74+
const searchParams = await props.searchParams;
75+
const results = await getRequests(searchParams);
76+
switch (results.type) {
77+
case ResultType.BadSearch: {
78+
return (
79+
<NoResults
80+
header="Invalid Search"
81+
body="Your search query is not a valid transaction hash, sequence number, or sender."
82+
query={results.search}
83+
/>
84+
);
85+
}
86+
case ResultType.ErrorResult: {
87+
return;
88+
}
89+
case ResultType.Success: {
90+
return (
91+
<ResultsImpl
92+
key={[
93+
searchParams.chain,
94+
searchParams.search,
95+
searchParams.status,
96+
].join(",")}
97+
search={searchParams.search}
98+
currentPage={results.currentPage}
99+
now={new Date()}
100+
/>
101+
);
102+
}
103+
}
104+
} catch (error) {
105+
if (error instanceof Error) {
106+
return <ErrorPage error={error} />;
107+
} else {
108+
const err = new Error("Unknown Error");
109+
err.cause = error;
110+
return <ErrorPage error={err} />;
111+
}
112+
}
113+
};
114+
115+
const Paginator = async (props: Props) => {
116+
try {
117+
const searchParams = await props.searchParams;
118+
const results = await getRequests(searchParams);
119+
switch (results.type) {
120+
case ResultType.Success: {
121+
return <PaginatorImpl numPages={results.numPages} />;
122+
}
123+
case ResultType.BadSearch: {
124+
return <PaginatorImpl numPages={0} />;
125+
}
126+
case ResultType.ErrorResult: {
127+
return <></>;
128+
}
129+
}
130+
} catch {
131+
return <></>;
132+
}
133+
};

apps/entropy-explorer/src/components/Home/request-drawer.module.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@
3636
margin-right: theme.spacing(4);
3737
position: relative;
3838

39+
.helpButton {
40+
position: absolute;
41+
top: theme.spacing(2);
42+
right: theme.spacing(2);
43+
}
44+
45+
.failureMessage {
46+
overflow: auto;
47+
width: 100%;
48+
display: flex;
49+
word-break: break-word;
50+
}
51+
3952
p {
4053
margin: 0;
4154

0 commit comments

Comments
 (0)