Skip to content

Commit 1cfd33d

Browse files
committed
ThemeContext added
1 parent 5e12bc2 commit 1cfd33d

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

packages/modal-ui/src/components/Image/Image.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// import { useContext } from "react";
1+
import { useContext } from "solid-js";
22

33
import { mergeProps } from "solid-js";
4+
import { ThemedContext } from "../../context/ThemeContext";
45

56
export interface ImageProps {
67
hoverImageId?: string;
@@ -22,7 +23,7 @@ export default function Image(props: ImageProps) {
2223
extension: "svg"
2324
}, props)
2425

25-
const isDark = false;
26+
const { isDark } = useContext(ThemedContext);
2627

2728
const imgName = isDark && mergedProps.darkImageId ? mergedProps.darkImageId : mergedProps.imageId;
2829
const hoverImgName = isDark && mergedProps.darkHoverImageId ? mergedProps.darkHoverImageId : mergedProps.hoverImageId;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createContext } from "solid-js";
2+
3+
export const ThemedContext = createContext({
4+
isDark: true, // default value
5+
});
6+
7+
8+

packages/modal-ui/src/loginModal.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Web3AuthNoModalEvents,
1818
} from "@web3auth/base";
1919
import { render } from "solid-js/web";
20+
import { ThemedContext } from "./context/ThemeContext";
2021

2122
import { LoginModal as Modal } from "./components/LoginModal";
2223
// import { ThemedContext } from "./context/ThemeContext";
@@ -34,7 +35,6 @@ import {
3435
} from "./interfaces";
3536
import i18n from "./localeImport";
3637
import { getUserLanguage } from "./utils/modal";
37-
import { Body } from "./components/Body";
3838

3939
function createWrapper(parentZIndex: string): HTMLElement {
4040
const existingWrapper = document.getElementById("w3a-parent-container");
@@ -208,17 +208,19 @@ export class LoginModal extends SafeEventEmitter {
208208

209209
render(
210210
() =>
211-
<Modal
212-
closeModal={this.closeModal}
213-
stateListener={this.stateEmitter}
214-
handleShowExternalWallets={this.handleShowExternalWallets}
215-
handleExternalWalletClick={this.handleExternalWalletClick}
216-
handleSocialLoginClick={this.handleSocialLoginClick}
217-
appLogo={darkState.isDark ? this.uiConfig.logoDark : this.uiConfig.logoLight}
218-
appName={this.uiConfig.appName}
219-
chainNamespace={this.chainNamespace}
220-
walletRegistry={this.walletRegistry}
221-
/>,
211+
<ThemedContext.Provider value={darkState}>
212+
<Modal
213+
closeModal={this.closeModal}
214+
stateListener={this.stateEmitter}
215+
handleShowExternalWallets={this.handleShowExternalWallets}
216+
handleExternalWalletClick={this.handleExternalWalletClick}
217+
handleSocialLoginClick={this.handleSocialLoginClick}
218+
appLogo={darkState.isDark ? this.uiConfig.logoDark : this.uiConfig.logoLight}
219+
appName={this.uiConfig.appName}
220+
chainNamespace={this.chainNamespace}
221+
walletRegistry={this.walletRegistry}
222+
/>
223+
</ThemedContext.Provider>,
222224
root!);
223225

224226

@@ -316,7 +318,7 @@ export class LoginModal extends SafeEventEmitter {
316318
};
317319

318320
private subscribeCoreEvents = (listener: SafeEventEmitter<Web3AuthNoModalEvents>) => {
319-
listener.on(ADAPTER_EVENTS.CONNECTING, (data) => {
321+
listener.on(ADAPTER_EVENTS.CONNECTING, (data: any) => {
320322
log.info("connecting with adapter", data);
321323
// don't show loader in case of wallet connect, because currently it listens for incoming for incoming
322324
// connections without any user interaction.

0 commit comments

Comments
 (0)