Skip to content

Commit

Permalink
update wallet kit theme related logic (#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeesunikim authored Oct 10, 2024
1 parent 6015fa2 commit 5b9a8fb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 35 deletions.
71 changes: 51 additions & 20 deletions src/components/WalletKitContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,66 @@ export const WalletKitContextProvider = ({
useEffect(() => {
const savedTheme = localStorageSavedTheme.get();

setTheme(savedTheme);
if (savedTheme) {
setTheme(savedTheme);
}
}, []);

const walletKitInstance = useMemo(() => {
const isDarkTheme = theme === "sds-theme-dark";

const commonDarkTheme = {
bgColor: "#161616",
textColor: "#fcfcfc",
solidTextColor: "#fcfcfc",
dividerColor: "#fcfcfc",
};

const commonLightTheme = {
bgColor: "#fcfcfc",
textColor: "#161616",
solidTextColor: "#161616",
dividerColor: "#161616",
};

const modalDarkTheme = {
...commonDarkTheme,
dividerColor: "#161616",
headerButtonColor: "#161616",
helpBgColor: "#161616",
notAvailableTextColor: "#fcfcfc",
notAvailableBgColor: "#161616",
notAvailableBorderColor: "#fcfcfc",
};

const modalLightTheme = {
...commonLightTheme,
dividerColor: "#fcfcfc",
headerButtonColor: "#fcfcfc",
helpBgColor: "#fcfcfc",
notAvailableTextColor: "#161616",
notAvailableBgColor: "#fcfcfc",
notAvailableBorderColor: "#161616",
};

return new StellarWalletsKit({
network: networkType,
selectedWalletId: XBULL_ID,
modules: allowAllModules(),
buttonTheme: {
bgColor: isDarkTheme ? "#161616" : "#fcfcfc",
textColor: isDarkTheme ? "#fcfcfc" : "#161616",
solidTextColor: isDarkTheme ? "#fcfcfc" : "#161616",
dividerColor: isDarkTheme ? "#fcfcfc" : "#161616",
buttonPadding: "0.5rem 1.25rem",
buttonBorderRadius: "0.5rem",
},
modalTheme: {
bgColor: isDarkTheme ? "#161616" : "#fcfcfc",
textColor: isDarkTheme ? "#fcfcfc" : "#161616",
solidTextColor: isDarkTheme ? "#fcfcfc" : "#161616",
dividerColor: isDarkTheme ? "#161616" : "#fcfcfc",
headerButtonColor: isDarkTheme ? "#161616" : "#fcfcfc",
helpBgColor: isDarkTheme ? "#161616" : "#fcfcfc",
notAvailableTextColor: isDarkTheme ? "#fcfcfc" : "#161616",
notAvailableBgColor: isDarkTheme ? "#161616" : "#fcfcfc",
notAvailableBorderColor: isDarkTheme ? "#fcfcfc" : "#161616",
},
...(theme && {
buttonTheme: isDarkTheme
? {
...commonDarkTheme,
buttonPadding: "0.5rem 1.25rem",
buttonBorderRadius: "0.5rem",
}
: {
...commonLightTheme,
buttonPadding: "0.5rem 1.25rem",
buttonBorderRadius: "0.5rem",
},
modalTheme: isDarkTheme ? modalDarkTheme : modalLightTheme,
}),
});
}, [networkType, theme]);

Expand Down
21 changes: 8 additions & 13 deletions src/components/layout/LayoutHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ export const LayoutHeader = () => {
);
};

const renderTheme = (isDarkMode: boolean) => {
const theme = isDarkMode ? "sds-theme-dark" : "sds-theme-light";
setTheme(theme);
};

if (layoutMode === "desktop") {
return (
<div className="LabLayout__header">
Expand All @@ -167,21 +172,16 @@ export const LayoutHeader = () => {
/>

<MainNav />
<ConnectWallet />

<div className="LabLayout__header__settings">
<Hydration>
<ThemeSwitch
storageKeyId={LOCAL_STORAGE_SAVED_THEME}
onActionEnd={(isDarkMode) => {
const theme = isDarkMode
? "sds-theme-dark"
: "sds-theme-light";
setTheme(theme);
}}
onActionEnd={renderTheme}
/>
</Hydration>
<NetworkSelector />
<ConnectWallet />
</div>
</header>
</div>
Expand Down Expand Up @@ -219,12 +219,7 @@ export const LayoutHeader = () => {
<Hydration>
<ThemeSwitch
storageKeyId={LOCAL_STORAGE_SAVED_THEME}
onActionEnd={(isDarkMode) => {
const theme = isDarkMode
? "sds-theme-dark"
: "sds-theme-light";
setTheme(theme);
}}
onActionEnd={renderTheme}
/>
</Hydration>
</DropdownItem>
Expand Down
4 changes: 2 additions & 2 deletions src/store/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface Store {
// Shared
network: Network | EmptyObj;
// Theme Color
theme: ThemeColorType | undefined;
theme: ThemeColorType | null;
// isDynamicNetworkSelect flag to indicate network update outside of the dropdown
isDynamicNetworkSelect: boolean;
selectNetwork: (network: Network) => void;
Expand Down Expand Up @@ -267,7 +267,7 @@ export const createStore = (options: CreateStoreOptions) =>
immer((set) => ({
// Shared
network: {},
theme: undefined,
theme: null,
isDynamicNetworkSelect: false,
selectNetwork: (network: Network) =>
set((state) => {
Expand Down

0 comments on commit 5b9a8fb

Please sign in to comment.