Skip to content

Commit

Permalink
Merge pull request #1736 from Web3Auth/feat/fetch-configs-from-dashboard
Browse files Browse the repository at this point in the history
Update description of primaryButton option in web3auth sdk + refactor to use language constants
  • Loading branch information
BboyStatix authored Feb 22, 2024
2 parents 0428ae5 + 6ed9dc1 commit 342b183
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
5 changes: 3 additions & 2 deletions packages/ui/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export interface UIConfig extends WhiteLabelData {
loginGridCol?: 2 | 3;

/**
* decides which button will be displayed as primary button in modal
* only one button will be primary and other buttons in modal will be secondary
* Decides which button will be the focus of the modal
* For `socialLogin` the social icon will be colored
* For other options like `emailLogin` and `externalLogin` the respective buttons will be coverted into a primary button
*
* @defaultValue `socialLogin`
*/
Expand Down
24 changes: 12 additions & 12 deletions packages/ui/src/loginModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "../css/web3auth.css";

import { SafeEventEmitter } from "@toruslabs/openlogin-jrpc";
import { applyWhiteLabelTheme } from "@toruslabs/openlogin-utils";
import { applyWhiteLabelTheme, LANGUAGES } from "@toruslabs/openlogin-utils";
import {
ADAPTER_EVENTS,
BaseAdapterConfig,
Expand Down Expand Up @@ -62,7 +62,7 @@ class LoginModal extends SafeEventEmitter {
if (!uiConfig.mode) this.uiConfig.mode = "auto";
if (!uiConfig.modalZIndex) this.uiConfig.modalZIndex = "99998";
if (typeof uiConfig.displayErrorsOnModal === "undefined") this.uiConfig.displayErrorsOnModal = true;
if (!uiConfig.defaultLanguage) this.uiConfig.defaultLanguage = "en";
if (!uiConfig.defaultLanguage) this.uiConfig.defaultLanguage = LANGUAGES.en;
if (!uiConfig.appName) this.uiConfig.appName = "Web3Auth";
if (!uiConfig.loginGridCol) this.uiConfig.loginGridCol = 3;
if (!uiConfig.primaryButton) this.uiConfig.primaryButton = "socialLogin";
Expand All @@ -79,10 +79,10 @@ class LoginModal extends SafeEventEmitter {
initModal = async (): Promise<void> => {
const darkState = { isDark: this.isDark };

const useLang = this.uiConfig.defaultLanguage || "en";
const useLang = this.uiConfig.defaultLanguage || LANGUAGES.en;
// Load new language resource

if (useLang === "de") {
if (useLang === LANGUAGES.de) {
import("./i18n/german.json")
.then((messages) => {
i18n.addResourceBundle(useLang as string, "translation", messages.default);
Expand All @@ -91,7 +91,7 @@ class LoginModal extends SafeEventEmitter {
.catch((error) => {
log.error(error);
});
} else if (useLang === "ja") {
} else if (useLang === LANGUAGES.ja) {
import(`./i18n/japanese.json`)
.then((messages) => {
i18n.addResourceBundle(useLang as string, "translation", messages.default);
Expand All @@ -100,7 +100,7 @@ class LoginModal extends SafeEventEmitter {
.catch((error) => {
log.error(error);
});
} else if (useLang === "ko") {
} else if (useLang === LANGUAGES.ko) {
import(`./i18n/korean.json`)
.then((messages) => {
i18n.addResourceBundle(useLang as string, "translation", messages.default);
Expand All @@ -109,7 +109,7 @@ class LoginModal extends SafeEventEmitter {
.catch((error) => {
log.error(error);
});
} else if (useLang === "zh") {
} else if (useLang === LANGUAGES.zh) {
import(`./i18n/mandarin.json`)
.then((messages) => {
i18n.addResourceBundle(useLang as string, "translation", messages.default);
Expand All @@ -118,7 +118,7 @@ class LoginModal extends SafeEventEmitter {
.catch((error) => {
log.error(error);
});
} else if (useLang === "es") {
} else if (useLang === LANGUAGES.es) {
import(`./i18n/spanish.json`)
.then((messages) => {
i18n.addResourceBundle(useLang as string, "translation", messages.default);
Expand All @@ -127,7 +127,7 @@ class LoginModal extends SafeEventEmitter {
.catch((error) => {
log.error(error);
});
} else if (useLang === "fr") {
} else if (useLang === LANGUAGES.fr) {
import(`./i18n/french.json`)
.then((messages) => {
i18n.addResourceBundle(useLang as string, "translation", messages.default);
Expand All @@ -136,7 +136,7 @@ class LoginModal extends SafeEventEmitter {
.catch((error) => {
log.error(error);
});
} else if (useLang === "pt") {
} else if (useLang === LANGUAGES.pt) {
import(`./i18n/portuguese.json`)
.then((messages) => {
i18n.addResourceBundle(useLang as string, "translation", messages.default);
Expand All @@ -145,7 +145,7 @@ class LoginModal extends SafeEventEmitter {
.catch((error) => {
log.error(error);
});
} else if (useLang === "nl") {
} else if (useLang === LANGUAGES.nl) {
import(`./i18n/dutch.json`)
.then((messages) => {
i18n.addResourceBundle(useLang as string, "translation", messages.default);
Expand All @@ -154,7 +154,7 @@ class LoginModal extends SafeEventEmitter {
.catch((error) => {
log.error(error);
});
} else if (useLang === "tr") {
} else if (useLang === LANGUAGES.tr) {
import(`./i18n/turkish.json`)
.then((messages) => {
i18n.addResourceBundle(useLang as string, "translation", messages.default);
Expand Down
17 changes: 2 additions & 15 deletions packages/ui/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get, post } from "@toruslabs/http-helpers";
import { LANGUAGE_TYPE } from "@toruslabs/openlogin-utils";
import { LANGUAGE_MAP, LANGUAGE_TYPE, LANGUAGES } from "@toruslabs/openlogin-utils";
import { log, LoginMethodConfig, WALLET_ADAPTERS } from "@web3auth/base";

import { OPENLOGIN_PROVIDERS, OPENLOGIN_PROVIDERS_NAMES } from "./config";
Expand Down Expand Up @@ -86,19 +86,6 @@ export const validatePhoneNumber = async (phoneNumber: string): Promise<string |
}
};

export const languageMap: Record<LANGUAGE_TYPE, string> = {
en: "english",
de: "german",
ja: "japanese",
ko: "korean",
zh: "mandarin",
es: "spanish",
fr: "french",
pt: "portuguese",
nl: "dutch",
tr: "turkish",
};

interface NavigatorLanguage {
userLanguage?: string;
}
Expand All @@ -110,5 +97,5 @@ export const getUserLanguage = (defaultLanguage: string | undefined): LANGUAGE_T
typeof window !== "undefined" ? (window.navigator as NavigatorLanguage).userLanguage || window.navigator.language || "en-US" : "en-US";
userLanguage = browserLanguage.split("-")[0];
}
return Object.prototype.hasOwnProperty.call(languageMap, userLanguage) ? (userLanguage as LANGUAGE_TYPE) : "en";
return Object.prototype.hasOwnProperty.call(LANGUAGE_MAP, userLanguage) ? (userLanguage as LANGUAGE_TYPE) : LANGUAGES.en;
};

0 comments on commit 342b183

Please sign in to comment.