From c14b980e7929a86ae282ab981e567901c27f020a Mon Sep 17 00:00:00 2001 From: kaf-lamed-beyt Date: Sun, 3 Aug 2025 22:43:46 +0100 Subject: [PATCH 1/2] fix: fixed mismatched imports due to the recent PR i've also updated the ThemeProvider to expose a isDark value so it is not computed everytime in components needing it. --- app/context/theme-provider.tsx | 27 ++++++++++++++++--- app/dapp/components/claim-burn/index.tsx | 3 +-- app/dapp/components/claim-burn/success.tsx | 3 +-- app/dapp/components/claim-burn/tab.tsx | 3 +-- .../components/ui/ConnectWalletButton.tsx | 3 +-- app/dapp/components/ui/ThemeSwitcher.tsx | 9 +++---- app/dapp/swap/components/SwapSuccessModal.tsx | 7 +++-- .../swap/components/TokenDropDownMenu.tsx | 7 +++-- app/dapp/swap/page.tsx | 2 +- app/hooks/context/theme.ts | 3 +-- 10 files changed, 39 insertions(+), 28 deletions(-) diff --git a/app/context/theme-provider.tsx b/app/context/theme-provider.tsx index acc166b..f1c80be 100644 --- a/app/context/theme-provider.tsx +++ b/app/context/theme-provider.tsx @@ -1,15 +1,24 @@ "use client"; -import React, { createContext, useContext, useEffect, useState } from "react"; +import React, { + createContext, + useContext, + useEffect, + useMemo, + useState, +} from "react"; export type Theme = "light" | "dark"; export interface ThemeContextValues { theme: Theme; + isDark: boolean; toggleTheme: () => void; } -export const ThemeContext = createContext(undefined); +export const ThemeContext = createContext( + undefined, +); export const ThemeProvider = ({ children }: { children: React.ReactNode }) => { const [theme, setTheme] = useState("light"); @@ -17,7 +26,9 @@ export const ThemeProvider = ({ children }: { children: React.ReactNode }) => { useEffect(() => { const storedTheme = localStorage.getItem("theme") as Theme | null; - const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches; + const prefersDark = window.matchMedia( + "(prefers-color-scheme: dark)", + ).matches; const activeTheme = storedTheme || (prefersDark ? "dark" : "light"); setTheme(activeTheme); @@ -29,6 +40,8 @@ export const ThemeProvider = ({ children }: { children: React.ReactNode }) => { document.documentElement.classList.add(newTheme); }; + const isDark = useMemo(() => theme === "dark", [theme]); + const toggleTheme = () => { const newTheme = theme === "dark" ? "light" : "dark"; setTheme(newTheme); @@ -36,8 +49,14 @@ export const ThemeProvider = ({ children }: { children: React.ReactNode }) => { localStorage.setItem("theme", newTheme); }; + const contextValues: ThemeContextValues = { + theme, + isDark, + toggleTheme, + }; + return ( - + {children} ); diff --git a/app/dapp/components/claim-burn/index.tsx b/app/dapp/components/claim-burn/index.tsx index 64671dc..1aeaf95 100644 --- a/app/dapp/components/claim-burn/index.tsx +++ b/app/dapp/components/claim-burn/index.tsx @@ -28,13 +28,12 @@ type BurnClaimData = { }; const ClaimBurn = () => { - const { theme } = useThemeContext(); + const { isDark } = useThemeContext(); const { isConnected } = useWallet(); const [activeTab, setActiveTab] = useState("claim"); const [amount, setAmount] = useState(""); const [showSuccessModal, setShowSuccessModal] = useState(false); - const isDark = useMemo(() => theme === "dark", [theme]); const CLAIM_BURN_DATA: Record = useMemo( () => ({ diff --git a/app/dapp/components/claim-burn/success.tsx b/app/dapp/components/claim-burn/success.tsx index a8ac05a..b1404a9 100644 --- a/app/dapp/components/claim-burn/success.tsx +++ b/app/dapp/components/claim-burn/success.tsx @@ -30,8 +30,7 @@ export const SuccessModal = ({ type, amount, }: SuccessModalProps) => { - const { theme } = useThemeContext(); - const isDark = useMemo(() => theme === "dark", [theme]); + const { isDark } = useThemeContext(); const date = new Date().toLocaleString("en-US", { dateStyle: "long", timeStyle: "medium", diff --git a/app/dapp/components/claim-burn/tab.tsx b/app/dapp/components/claim-burn/tab.tsx index 6f9366a..4775881 100644 --- a/app/dapp/components/claim-burn/tab.tsx +++ b/app/dapp/components/claim-burn/tab.tsx @@ -12,8 +12,7 @@ export const ClaimBurnTab = ({ activeTab, setActiveTab, }: ClaimBurnTabProps) => { - const { theme } = useThemeContext(); - const isDark = useMemo(() => theme === "dark", [theme]); + const { isDark } = useThemeContext(); return (
theme === "dark", [theme]); + const { isDark } = useThemeContext(); const handleClick = async () => { if (isConnected) { diff --git a/app/dapp/components/ui/ThemeSwitcher.tsx b/app/dapp/components/ui/ThemeSwitcher.tsx index 51e2154..4083bd1 100644 --- a/app/dapp/components/ui/ThemeSwitcher.tsx +++ b/app/dapp/components/ui/ThemeSwitcher.tsx @@ -5,8 +5,7 @@ import MoonIcon from "@/svg/MoonIcon"; import SunIcon from "@/svg/SunIcon"; function ThemeSwitcher() { - const { theme, toggleTheme } = useThemeContext(); - const isDarkMode = theme === "dark"; + const { isDark, toggleTheme } = useThemeContext(); return (