Skip to content

Commit 9690d30

Browse files
type initial auth mode to const
1 parent f8e0f2b commit 9690d30

File tree

11 files changed

+41
-20
lines changed

11 files changed

+41
-20
lines changed

demo/vue-app-new/src/components/AppDashboard.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
useWeb3AuthUser,
1515
useSwitchChain as useWeb3AuthSwitchChain,
1616
} from "@web3auth/modal/vue";
17-
import { type CustomChainConfig, type NFTCheckoutPluginType } from "@web3auth/no-modal";
17+
import { CONNECTOR_INITIAL_AUTHENTICATION_MODE, type CustomChainConfig, type NFTCheckoutPluginType } from "@web3auth/no-modal";
1818
import { useI18n } from "petite-vue-i18n";
1919
2020
import { useSignAndSendTransaction, useSignMessage as useSolanaSignMessage, useSignTransaction, useSolanaWallet } from "@web3auth/modal/vue/solana";
@@ -92,7 +92,7 @@ const isDisplay = (name: "dashboard" | "ethServices" | "solServices" | "walletSe
9292
const chainNamespace = currentChainNamespace.value;
9393
switch (name) {
9494
case "dashboard":
95-
return formData.initialAuthenticationMode === "connect-and-sign" ? isAuthorized.value : isConnected.value;
95+
return formData.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN ? isAuthorized.value : isConnected.value;
9696
9797
case "ethServices":
9898
return chainNamespace === CHAIN_NAMESPACES.EIP155;

demo/vue-app-new/src/components/AppHeader.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useWeb3Auth, useWeb3AuthDisconnect } from "@web3auth/modal/vue";
44
import { useI18n } from "petite-vue-i18n";
55
import { watch } from "vue";
66
import { formDataStore } from "../store/form";
7+
import { CONNECTOR_INITIAL_AUTHENTICATION_MODE } from "@web3auth/no-modal";
78
89
const { log } = console;
910
const { t } = useI18n({ useScope: "global" });
@@ -15,10 +16,10 @@ const formData = formDataStore;
1516
const isDisplay = (name: string): boolean => {
1617
switch (name) {
1718
case "btnLogout":
18-
return formData.initialAuthenticationMode === "connect-and-sign" ? isAuthorized.value : isConnected.value;
19+
return formData.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN ? isAuthorized.value : isConnected.value;
1920
2021
case "appHeading":
21-
return formData.initialAuthenticationMode === "connect-and-sign" ? isAuthorized.value : isConnected.value;
22+
return formData.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN ? isAuthorized.value : isConnected.value;
2223
2324
default: {
2425
return false;

demo/vue-app-new/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
ChainNamespaceType,
55
CONFIRMATION_STRATEGY,
66
type CONFIRMATION_STRATEGY_TYPE,
7-
InitialAuthenticationModeType,
7+
type ConnectorInitialAuthenticationModeType,
88
LoginMethodConfig,
99
ModalConfig,
1010
SignTypedDataMessageV4,
@@ -110,7 +110,7 @@ export type FormData = {
110110
config: WhiteLabelData;
111111
};
112112
connectors: string[];
113-
initialAuthenticationMode: InitialAuthenticationModeType;
113+
initialAuthenticationMode: ConnectorInitialAuthenticationModeType;
114114
loginProviders: AUTH_CONNECTION_TYPE[];
115115
showWalletDiscovery: boolean;
116116
multiInjectedProviderDiscovery: boolean;

demo/vue-app-new/src/store/form.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { WEB3AUTH_NETWORK } from "@web3auth/auth";
2-
import { CHAIN_NAMESPACES, WIDGET_TYPE } from "@web3auth/modal";
2+
import { CHAIN_NAMESPACES, CONNECTOR_INITIAL_AUTHENTICATION_MODE, WIDGET_TYPE } from "@web3auth/modal";
33
import { reactive } from "vue";
44

55
import { chainConfigs, defaultLoginMethod, FormData, initWhiteLabel } from "../config";
66

77
export const formDataStore = reactive<FormData>({
88
// authMode: "",
99
connectors: [],
10-
initialAuthenticationMode: "connect-only",
10+
initialAuthenticationMode: CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_ONLY,
1111
network: process.env.NODE_ENV === "production" ? WEB3AUTH_NETWORK.SAPPHIRE_MAINNET : WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
1212
chainNamespaces: [CHAIN_NAMESPACES.EIP155, CHAIN_NAMESPACES.SOLANA],
1313
chains: [chainConfigs[CHAIN_NAMESPACES.EIP155][0], chainConfigs[CHAIN_NAMESPACES.SOLANA][0]],

packages/modal/src/ui/components/Widget/Widget.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { AUTH_CONNECTION, AUTH_CONNECTION_TYPE, BUILD_ENV, WEB3AUTH_NETWORK } from "@web3auth/auth";
2-
import { cloneDeep, CONNECTOR_NAMES, log, WALLET_CONNECTOR_TYPE, WALLET_CONNECTORS, WIDGET_TYPE } from "@web3auth/no-modal";
2+
import {
3+
cloneDeep,
4+
CONNECTOR_INITIAL_AUTHENTICATION_MODE,
5+
CONNECTOR_NAMES,
6+
log,
7+
WALLET_CONNECTOR_TYPE,
8+
WALLET_CONNECTORS,
9+
WIDGET_TYPE,
10+
} from "@web3auth/no-modal";
311
import deepmerge from "deepmerge";
412
import { useEffect, useMemo, useState } from "react";
513

@@ -57,7 +65,10 @@ function Widget(props: WidgetProps) {
5765
authBuildEnv: BUILD_ENV.PRODUCTION,
5866
});
5967

60-
const isConnectAndSignAuthenticationMode = useMemo(() => initialAuthenticationMode === "connect-and-sign", [initialAuthenticationMode]);
68+
const isConnectAndSignAuthenticationMode = useMemo(
69+
() => initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN,
70+
[initialAuthenticationMode]
71+
);
6172

6273
useEffect(() => {
6374
setModalState((prev) => ({ ...prev, modalVisibility: visible }));

packages/modal/src/ui/components/Widget/Widget.type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SafeEventEmitter } from "@web3auth/auth";
2-
import { ChainNamespaceType, InitialAuthenticationModeType, WALLET_CONNECTOR_TYPE, WalletRegistry } from "@web3auth/no-modal";
2+
import { ChainNamespaceType, ConnectorInitialAuthenticationModeType, WALLET_CONNECTOR_TYPE, WalletRegistry } from "@web3auth/no-modal";
33

44
import { browser, ExternalWalletEventType, os, platform, SocialLoginEventType, StateEmitterEvents, UIConfig } from "../../interfaces";
55

@@ -10,7 +10,7 @@ export interface WidgetProps {
1010
chainNamespaces: ChainNamespaceType[];
1111
walletRegistry?: WalletRegistry;
1212
uiConfig: UIConfig;
13-
initialAuthenticationMode: InitialAuthenticationModeType;
13+
initialAuthenticationMode: ConnectorInitialAuthenticationModeType;
1414
deviceDetails: { platform: platform; browser: browser; os: os };
1515
handleSocialLoginClick: (params: SocialLoginEventType) => void;
1616
handleExternalWalletClick: (params: ExternalWalletEventType) => void;

packages/modal/src/ui/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
type AuthLoginParams,
1414
type BaseConnectorConfig,
1515
type ChainNamespaceType,
16-
InitialAuthenticationModeType,
16+
type ConnectorInitialAuthenticationModeType,
1717
type LoginMethodConfig,
1818
type LoginModalConfig,
1919
type UIConfig as CoreUIConfig,
@@ -77,7 +77,7 @@ export type ModalLoginParams = Pick<
7777
};
7878

7979
export interface LoginModalProps extends UIConfig {
80-
initialAuthenticationMode: InitialAuthenticationModeType;
80+
initialAuthenticationMode: ConnectorInitialAuthenticationModeType;
8181
chainNamespaces: ChainNamespaceType[];
8282
walletRegistry: WalletRegistry;
8383
web3authClientId: string;

packages/modal/src/ui/loginModal.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import "./css/index.css";
44

5-
import { applyWhiteLabelTheme, LANGUAGES, SafeEventEmitter } from "@web3auth/auth";
5+
import { applyWhiteLabelTheme, LANGUAGES, SafeEventEmitter, THEME_MODES } from "@web3auth/auth";
66
import {
77
type Analytics,
88
ANALYTICS_EVENTS,
99
type BaseConnectorConfig,
1010
type ChainNamespaceType,
1111
CONNECTOR_EVENTS,
12+
CONNECTOR_INITIAL_AUTHENTICATION_MODE,
1213
getWhitelabelAnalyticsProperties,
1314
type IConnectorDataEvent,
1415
log,
@@ -90,15 +91,15 @@ export class LoginModal {
9091

9192
if (!uiConfig.logoDark) this.uiConfig.logoDark = DEFAULT_LOGO_DARK;
9293
if (!uiConfig.logoLight) this.uiConfig.logoLight = DEFAULT_LOGO_LIGHT;
93-
if (!uiConfig.mode) this.uiConfig.mode = "light";
94+
if (!uiConfig.mode) this.uiConfig.mode = THEME_MODES.light;
9495
if (!uiConfig.modalZIndex) this.uiConfig.modalZIndex = "99998";
9596
if (typeof uiConfig.displayErrorsOnModal === "undefined") this.uiConfig.displayErrorsOnModal = true;
9697
if (!uiConfig.appName) this.uiConfig.appName = "Web3Auth";
9798
if (!uiConfig.loginGridCol) this.uiConfig.loginGridCol = 3;
9899
if (!uiConfig.primaryButton) this.uiConfig.primaryButton = "socialLogin";
99100
if (!uiConfig.defaultLanguage) this.uiConfig.defaultLanguage = getUserLanguage(uiConfig.defaultLanguage);
100101
if (!uiConfig.widgetType) this.uiConfig.widgetType = WIDGET_TYPE.MODAL;
101-
if (!uiConfig.initialAuthenticationMode) this.uiConfig.initialAuthenticationMode = "connect-only";
102+
if (!uiConfig.initialAuthenticationMode) this.uiConfig.initialAuthenticationMode = CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_ONLY;
102103

103104
if (uiConfig.widgetType === WIDGET_TYPE.EMBED && !uiConfig.targetId) {
104105
log.error("targetId is required for embed widget");

packages/no-modal/src/base/connector/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ export const CONNECTOR_CATEGORY = {
2323
EXTERNAL: "external",
2424
IN_APP: "in_app",
2525
} as const;
26+
27+
export const CONNECTOR_INITIAL_AUTHENTICATION_MODE = {
28+
CONNECT_ONLY: "connect-only",
29+
CONNECT_AND_SIGN: "connect-and-sign",
30+
} as const;

packages/no-modal/src/base/core/IWeb3Auth.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { type ChainNamespaceType, type CustomChainConfig } from "../chain/IChain
1414
import {
1515
CONNECTED_EVENT_DATA,
1616
CONNECTOR_EVENTS,
17+
CONNECTOR_INITIAL_AUTHENTICATION_MODE,
1718
type CONNECTOR_STATUS_TYPE,
1819
ConnectorEvents,
1920
type ConnectorFn,
@@ -62,7 +63,8 @@ export interface UIConfig extends WhiteLabelData {
6263
uxMode?: UX_MODE_TYPE;
6364
}
6465

65-
export type InitialAuthenticationModeType = "connect-only" | "connect-and-sign";
66+
export type ConnectorInitialAuthenticationModeType =
67+
(typeof CONNECTOR_INITIAL_AUTHENTICATION_MODE)[keyof typeof CONNECTOR_INITIAL_AUTHENTICATION_MODE];
6668

6769
export interface IWeb3AuthCoreOptions {
6870
/**
@@ -185,7 +187,7 @@ export interface IWeb3AuthCoreOptions {
185187
* Initial authentication mode for the auth connector.
186188
* @defaultValue "connect-only"
187189
*/
188-
initialAuthenticationMode?: InitialAuthenticationModeType;
190+
initialAuthenticationMode?: ConnectorInitialAuthenticationModeType;
189191
}
190192

191193
export type LoginParamMap = {

0 commit comments

Comments
 (0)