From 1c99e32997f2e53c90b10914f944028e52abbaf0 Mon Sep 17 00:00:00 2001 From: Naveed Elahi Date: Fri, 20 Oct 2023 19:31:50 +0800 Subject: [PATCH] fix whitelabel not applying due to out of sync uiconfig --- packages/modal/src/modalManager.ts | 18 +++++++++++------- packages/ui/src/components/Modal.tsx | 18 +++++++++--------- packages/ui/src/loginModal.tsx | 10 ---------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/packages/modal/src/modalManager.ts b/packages/modal/src/modalManager.ts index d5abe58e5..e70d5c846 100644 --- a/packages/modal/src/modalManager.ts +++ b/packages/modal/src/modalManager.ts @@ -96,20 +96,24 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal { if (!this.options.uiConfig) this.options.uiConfig = {}; if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage); if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "auto"; + } + + public async initModal(params?: { modalConfig?: Record }): Promise { + super.checkInitRequirements(); + const whitelabel = await getWhiteLabel(this.options.clientId); + this.options.uiConfig = { + // TODO: should whitelabel override? + // TODO: will we remove specifying via code in future? + ...this.options.uiConfig, + ...whitelabel, + }; this.loginModal = new LoginModal({ ...this.options.uiConfig, adapterListener: this, }); this.subscribeToLoginModalEvents(); - } - public async initModal(params?: { modalConfig?: Record }): Promise { - super.checkInitRequirements(); - - // TODO: handle get whitelabel error - const whitelabel = await getWhiteLabel(this.options.clientId); - this.loginModal.updateUIConfigFromWhitelabel(whitelabel); await this.loginModal.initModal(); const providedChainConfig = this.options.chainConfig; diff --git a/packages/ui/src/components/Modal.tsx b/packages/ui/src/components/Modal.tsx index bebc887d0..1818ad42e 100644 --- a/packages/ui/src/components/Modal.tsx +++ b/packages/ui/src/components/Modal.tsx @@ -1,5 +1,5 @@ import type { SafeEventEmitter } from "@toruslabs/openlogin-jrpc"; -import { LOGIN_PROVIDER, WhiteLabelData } from "@toruslabs/openlogin-utils"; +import { LOGIN_PROVIDER } from "@toruslabs/openlogin-utils"; import { ADAPTER_NAMES, log } from "@web3auth/base"; import cloneDeep from "lodash.clonedeep"; import deepmerge from "lodash.merge"; @@ -20,12 +20,10 @@ import SocialLogins from "./SocialLogins"; interface ModalProps { stateListener: SafeEventEmitter; appLogo?: string; - appName?: string; handleSocialLoginClick: (params: SocialLoginEventType) => void; handleExternalWalletClick: (params: ExternalWalletEventType) => void; handleShowExternalWallets: (externalWalletsInitialized: boolean) => void; closeModal: () => void; - whiteLabel?: WhiteLabelData; } log.enableAll(); @@ -59,8 +57,7 @@ export default function Modal(props: ModalProps) { const { isDark } = useContext(ThemedContext); const [t] = useTranslation(undefined, { i18n }); - const { stateListener, appLogo, appName, handleSocialLoginClick, handleExternalWalletClick, handleShowExternalWallets, closeModal, whiteLabel } = - props; + const { stateListener, appLogo, handleSocialLoginClick, handleExternalWalletClick, handleShowExternalWallets, closeModal } = props; useEffect(() => { stateListener.emit("MOUNTED"); @@ -132,7 +129,11 @@ export default function Modal(props: ModalProps) { const isEmailPrimary = modalState.socialLoginsConfig?.uiConfig?.primaryButton === "emailLogin"; const isExternalPrimary = modalState.socialLoginsConfig?.uiConfig?.primaryButton === "externalLogin"; - const primaryColor = whiteLabel?.theme?.primary || ""; + const primaryColor = modalState.socialLoginsConfig?.uiConfig?.theme?.primary || ""; + const privacyPolicy = modalState.socialLoginsConfig?.uiConfig?.privacyPolicy; + const tncLink = modalState.socialLoginsConfig?.uiConfig?.tncLink; + const defaultLanguage = modalState.socialLoginsConfig?.uiConfig?.defaultLanguage; + const appName = modalState.socialLoginsConfig?.uiConfig?.appName; const externalWalletButton = (
@@ -177,8 +178,7 @@ export default function Modal(props: ModalProps) { return modalState.socialLoginsConfig?.loginMethods[LOGIN_PROVIDER.SMS_PASSWORDLESS]?.showOnModal; }, [modalState.socialLoginsConfig?.loginMethods]); - // const modalClassName = `w3a-modal ${isDark ? "" : " w3a-modal--light"}`; - const modalClassName = `w3a-modal ${isDark ? "" : ""}`; + const modalClassName = `w3a-modal`; return ( modalState.modalVisibilityDelayed && ( @@ -244,7 +244,7 @@ export default function Modal(props: ModalProps) {
)} -