Skip to content

Commit dc61a3a

Browse files
authored
Merge pull request #3257 from pyth-network/bduran/pyth-feeds-demo-quick-fixes
fix(insights): fixed colors for system theme and changed API tokens wording to API keys
2 parents bf0c13e + 34df3a7 commit dc61a3a

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

apps/insights/src/components/PythProApiTokensMenu/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export function PythProApiTokensMenu() {
1818
const [open, setOpen] = useState(false);
1919

2020
/** local variables */
21-
const tooltip = "Configure your API tokens";
22-
const closeTooltip = "Close API tokens config";
21+
const tooltip = "Configure your API keys";
22+
const closeTooltip = "Close API keys config";
2323

2424
return (
2525
<>
@@ -61,7 +61,7 @@ export function PythProApiTokensMenu() {
6161
<div className={classes.fyi}>
6262
In order to provide a quality demo of Pyth Pro real-time
6363
performance relative to other sources, you will need to provide
64-
API tokens to interact with these APIs.
64+
API keys to interact with these APIs.
6565
</div>
6666
<div className={classes.fyi}>
6767
They will be saved securely to your browser for future use here.

apps/insights/src/components/PythProDemoPriceChart/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useAppTheme } from "@pythnetwork/react-hooks/use-app-theme";
12
import { capitalCase } from "change-case";
23
import type {
34
IChartApi,
@@ -6,7 +7,6 @@ import type {
67
UTCTimestamp,
78
} from "lightweight-charts";
89
import { createChart, LineSeries } from "lightweight-charts";
9-
import { useTheme } from "next-themes";
1010
import { useEffect, useLayoutEffect, useRef } from "react";
1111

1212
import type { AppStateContextVal } from "../../context/pyth-pro-demo";
@@ -31,7 +31,7 @@ export function PythProDemoPriceChartImpl({
3131
selectedSource,
3232
}: PythProDemoPriceChartImplProps) {
3333
/** hooks */
34-
const { theme } = useTheme();
34+
const { theme } = useAppTheme();
3535

3636
/** refs */
3737
const containerRef = useRef<HTMLDivElement | null>(null);

packages/react-hooks/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"dependencies": {
2727
"@pythnetwork/shared-lib": "workspace:",
28+
"next-themes": "catalog:",
2829
"nuqs": "catalog:",
2930
"react": "catalog:",
3031
"react-dom": "catalog:",
@@ -49,6 +50,10 @@
4950
"types": "./dist/nuqs.d.ts",
5051
"default": "./dist/nuqs.mjs"
5152
},
53+
"./use-app-theme": {
54+
"types": "./dist/use-app-theme.d.ts",
55+
"default": "./dist/use-app-theme.mjs"
56+
},
5257
"./use-websocket": {
5358
"types": "./dist/use-websocket.d.ts",
5459
"default": "./dist/use-websocket.mjs"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type { Nullish } from "@pythnetwork/shared-lib/types";
2+
import { useTheme } from "next-themes";
3+
import { useEffect, useState } from "react";
4+
5+
function getThemePreferenceMediaQuery() {
6+
return globalThis.window.matchMedia("(prefers-color-scheme: dark)");
7+
}
8+
9+
/**
10+
* wrapped version of the useTheme() hook from "next-themes,"
11+
* this one also detect if a user has selected the "system" theme
12+
* and, if so, returns their current color-scheme theme preference
13+
* (which comes directly from their OS or from their browser's settings)
14+
*/
15+
export function useAppTheme() {
16+
/** state */
17+
const [darkQuery, setDarkQuery] =
18+
useState<Nullish<ReturnType<typeof getThemePreferenceMediaQuery>>>(
19+
undefined,
20+
);
21+
const [browserThemePreference, setBrowserThemePreference] = useState<
22+
"dark" | "light" | "system"
23+
>("system");
24+
25+
/** hooks */
26+
const { theme, ...rest } = useTheme();
27+
28+
/** effects */
29+
useEffect(() => {
30+
setDarkQuery(getThemePreferenceMediaQuery());
31+
}, []);
32+
33+
useEffect(() => {
34+
if (!darkQuery) return;
35+
36+
// sync initial query
37+
setBrowserThemePreference(darkQuery.matches ? "dark" : "light");
38+
39+
const handleChange = (e: MediaQueryListEvent) => {
40+
setBrowserThemePreference(e.matches ? "dark" : "light");
41+
};
42+
43+
darkQuery.addEventListener("change", handleChange);
44+
45+
return () => {
46+
darkQuery.removeEventListener("change", handleChange);
47+
};
48+
}, [darkQuery]);
49+
50+
return {
51+
...rest,
52+
theme: (!theme || theme === "system"
53+
? browserThemePreference
54+
: theme) as typeof browserThemePreference,
55+
};
56+
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)