Skip to content

Commit e9ab03e

Browse files
committed
Merge branch 'master' into feat/sdk-v10-dashboard-config-p1
2 parents 1fa2669 + 453fe57 commit e9ab03e

File tree

17 files changed

+403
-802
lines changed

17 files changed

+403
-802
lines changed

demo/vite-react-app-sfa/package-lock.json

Lines changed: 316 additions & 661 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/vite-react-app-sfa/src/services/web3auth.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
8787
setIsLoading(true);
8888
const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ";
8989
const authConnectorInstance = authConnector({
90-
connectorSettings: { buildEnv: "development" },
90+
connectorSettings: { buildEnv: "testing" },
9191
});
9292

9393
const web3AuthInstance = new Web3AuthNoModal({

demo/vue-app-new/src/MainView.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ const options = computed((): Web3AuthOptions => {
114114
plugins,
115115
multiInjectedProviderDiscovery: formData.multiInjectedProviderDiscovery,
116116
walletServicesConfig,
117+
modalConfig: {
118+
connectors: modalParams.value,
119+
hideWalletDiscovery: !formData.showWalletDiscovery,
120+
}
117121
};
118122
});
119123
@@ -193,8 +197,6 @@ watch(
193197
const configs = computed<Web3AuthContextConfig>(() => {
194198
return {
195199
web3AuthOptions: options.value,
196-
modalConfig: modalParams.value,
197-
hideWalletDiscovery: !formData.showWalletDiscovery,
198200
};
199201
});
200202
</script>

packages/modal/src/config.ts

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,9 @@
1-
import { CHAIN_NAMESPACES, EVM_CONNECTORS, SOLANA_CONNECTORS } from "@web3auth/no-modal";
1+
import { EVM_CONNECTORS } from "@web3auth/no-modal";
22

33
import { ConnectorsModalConfig } from "./interface";
44

5-
export const defaultSolanaDappModalConfig: ConnectorsModalConfig = {
6-
chainNamespace: CHAIN_NAMESPACES.SOLANA,
7-
connectors: {
8-
[SOLANA_CONNECTORS.AUTH]: {
9-
label: "Auth",
10-
showOnModal: true,
11-
showOnMobile: true,
12-
showOnDesktop: true,
13-
},
14-
},
15-
};
16-
17-
export const defaultEvmDappModalConfig: ConnectorsModalConfig = {
18-
chainNamespace: CHAIN_NAMESPACES.EIP155,
19-
connectors: {
20-
[EVM_CONNECTORS.AUTH]: {
21-
label: "Auth",
22-
showOnModal: true,
23-
showOnMobile: true,
24-
showOnDesktop: true,
25-
},
26-
[EVM_CONNECTORS.WALLET_CONNECT_V2]: {
27-
label: "Wallet Connect",
28-
showOnModal: true,
29-
showOnMobile: true,
30-
showOnDesktop: true,
31-
},
32-
},
33-
};
34-
35-
export const defaultSolanaWalletModalConfig: ConnectorsModalConfig = {
36-
chainNamespace: CHAIN_NAMESPACES.SOLANA,
37-
connectors: {
38-
[SOLANA_CONNECTORS.AUTH]: {
39-
label: "Auth",
40-
showOnModal: true,
41-
showOnMobile: true,
42-
showOnDesktop: true,
43-
},
44-
},
45-
};
46-
47-
export const defaultEvmWalletModalConfig: ConnectorsModalConfig = {
48-
chainNamespace: CHAIN_NAMESPACES.EIP155,
49-
connectors: {
50-
[EVM_CONNECTORS.AUTH]: {
51-
label: "Auth",
52-
showOnModal: true,
53-
showOnMobile: true,
54-
showOnDesktop: true,
55-
},
56-
},
57-
};
58-
59-
export const defaultOtherModalConfig: ConnectorsModalConfig = {
60-
chainNamespace: CHAIN_NAMESPACES.OTHER,
5+
export const defaultConnectorsModalConfig: ConnectorsModalConfig = {
6+
hideWalletDiscovery: false,
617
connectors: {
628
[EVM_CONNECTORS.AUTH]: {
639
label: "Auth",

packages/modal/src/interface.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
import type { BaseConnectorConfig, ChainNamespaceType, IProvider, IWeb3Auth, LoginMethodConfig, WALLET_CONNECTOR_TYPE } from "@web3auth/no-modal";
1+
import type { BaseConnectorConfig, IProvider, IWeb3Auth, LoginMethodConfig, WALLET_CONNECTOR_TYPE } from "@web3auth/no-modal";
22

33
export interface ModalConfig extends Omit<BaseConnectorConfig, "isInjected"> {
44
loginMethods?: LoginMethodConfig;
55
}
66

77
export interface ConnectorsModalConfig {
8-
chainNamespace: ChainNamespaceType;
98
connectors?: Record<WALLET_CONNECTOR_TYPE, ModalConfig>;
10-
}
11-
12-
export interface ModalConfigParams {
13-
modalConfig?: Record<WALLET_CONNECTOR_TYPE, ModalConfig>;
149
hideWalletDiscovery?: boolean;
1510
}
16-
1711
export interface IWeb3AuthModal extends IWeb3Auth {
18-
initModal(params?: ModalConfigParams): Promise<void>;
12+
initModal(): Promise<void>;
1913
connect(): Promise<IProvider | null>;
2014
}

packages/modal/src/modalManager.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
} from "@web3auth/no-modal";
2323
import deepmerge from "deepmerge";
2424

25-
import { defaultOtherModalConfig, walletRegistryUrl } from "./config";
26-
import { type ConnectorsModalConfig, type IWeb3AuthModal, type ModalConfig, type ModalConfigParams } from "./interface";
25+
import { defaultConnectorsModalConfig, walletRegistryUrl } from "./config";
26+
import { type ConnectorsModalConfig, type IWeb3AuthModal, type ModalConfig } from "./interface";
2727
import {
2828
AUTH_PROVIDERS,
2929
capitalizeFirstLetter,
@@ -39,31 +39,34 @@ export interface Web3AuthOptions extends IWeb3AuthCoreOptions {
3939
* Config for configuring modal ui display properties
4040
*/
4141
uiConfig?: Omit<UIConfig, "connectorListener">;
42+
43+
/**
44+
* Config for configuring modal ui display properties
45+
*/
46+
modalConfig?: ConnectorsModalConfig;
4247
}
4348

4449
export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
4550
public loginModal: LoginModal;
4651

4752
readonly options: Web3AuthOptions;
4853

49-
private modalConfig: ConnectorsModalConfig = cloneDeep(defaultOtherModalConfig);
54+
private modalConfig: ConnectorsModalConfig = cloneDeep(defaultConnectorsModalConfig);
5055

5156
constructor(options: Web3AuthOptions) {
5257
super(options);
5358
this.options = { ...options };
5459

5560
if (!this.options.uiConfig) this.options.uiConfig = {};
56-
}
61+
if (this.options.modalConfig) this.modalConfig = this.options.modalConfig;
5762

58-
public setModalConfig(modalConfig: ConnectorsModalConfig): void {
59-
super.checkInitRequirements();
60-
this.modalConfig = modalConfig;
63+
log.info("modalConfig", this.modalConfig);
6164
}
6265

63-
public async initModal(params?: ModalConfigParams): Promise<void> {
66+
public async initModal(): Promise<void> {
6467
super.checkInitRequirements();
6568
// get project config and wallet registry
66-
const { projectConfig, walletRegistry } = await this.getProjectAndWalletConfig(params);
69+
const { projectConfig, walletRegistry } = await this.getProjectAndWalletConfig();
6770
this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
6871
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
6972
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
@@ -89,7 +92,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
8992

9093
// initialize connectors
9194
this.on(CONNECTOR_EVENTS.CONNECTORS_UPDATED, ({ connectors: newConnectors }) =>
92-
this.initConnectors({ connectors: newConnectors, projectConfig, modalConfig: params, disabledExternalWallets })
95+
this.initConnectors({ connectors: newConnectors, projectConfig, disabledExternalWallets })
9396
);
9497
await this.loadConnectors({ projectConfig });
9598

@@ -142,7 +145,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
142145
return { disabledExternalWallets, filteredWalletRegistry };
143146
}
144147

145-
private async getProjectAndWalletConfig(params?: ModalConfigParams) {
148+
private async getProjectAndWalletConfig() {
146149
// get project config
147150
let projectConfig: ProjectConfig;
148151
try {
@@ -159,7 +162,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
159162
// get wallet registry
160163
let walletRegistry: WalletRegistry = { others: {}, default: {} };
161164
const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
162-
if (isExternalWalletEnabled && !params?.hideWalletDiscovery) {
165+
if (isExternalWalletEnabled && !this.modalConfig?.hideWalletDiscovery) {
163166
try {
164167
walletRegistry = await fetchWalletRegistry(walletRegistryUrl);
165168
} catch (e) {
@@ -172,16 +175,14 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
172175
private async initConnectors({
173176
connectors,
174177
projectConfig,
175-
modalConfig,
176178
disabledExternalWallets,
177179
}: {
178180
connectors: IConnector<unknown>[];
179181
projectConfig: ProjectConfig;
180-
modalConfig: ModalConfigParams;
181182
disabledExternalWallets: Set<string>;
182183
}) {
183184
// filter connectors based on config
184-
const filteredConnectorNames = await this.filterConnectors({ modalConfig, projectConfig, disabledExternalWallets });
185+
const filteredConnectorNames = await this.filterConnectors({ projectConfig, disabledExternalWallets });
185186

186187
// initialize connectors based on availability
187188
const { hasInAppConnectors, hasExternalConnectors } = await this.checkConnectorAvailability(filteredConnectorNames);
@@ -202,15 +203,13 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
202203
}
203204

204205
private async filterConnectors({
205-
modalConfig,
206206
projectConfig,
207207
disabledExternalWallets,
208208
}: {
209-
modalConfig: ModalConfigParams;
210209
projectConfig: ProjectConfig;
211210
disabledExternalWallets: Set<string>;
212211
}): Promise<string[]> {
213-
// modal config from project config
212+
// Auth connector config: merge code config with config from dashboard
214213
const loginMethods: LoginMethodConfig = {};
215214
for (const authConnectionConfig of projectConfig.embeddedWalletAuth || []) {
216215
const connectionType = authConnectionConfig.authConnection;
@@ -222,14 +221,13 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
222221
showOnMobile: true,
223222
};
224223
}
225-
const projectModalConfig: Record<WALLET_CONNECTOR_TYPE, ModalConfig> = {
224+
const dashboardConnectorConfig: Record<WALLET_CONNECTOR_TYPE, ModalConfig> = {
226225
[WALLET_CONNECTORS.AUTH]: { label: WALLET_CONNECTORS.AUTH, loginMethods },
227226
};
228-
// merge with user config
229-
if (modalConfig?.modalConfig?.[WALLET_CONNECTORS.AUTH]) {
230-
if (!modalConfig.modalConfig[WALLET_CONNECTORS.AUTH].loginMethods) modalConfig.modalConfig[WALLET_CONNECTORS.AUTH].loginMethods = {};
227+
if (this.modalConfig?.connectors?.[WALLET_CONNECTORS.AUTH]) {
228+
if (!this.modalConfig.connectors[WALLET_CONNECTORS.AUTH].loginMethods) this.modalConfig.connectors[WALLET_CONNECTORS.AUTH].loginMethods = {};
231229
}
232-
modalConfig.modalConfig = deepmerge(projectModalConfig, cloneDeep(modalConfig.modalConfig || {}));
230+
this.modalConfig.connectors = deepmerge(dashboardConnectorConfig, cloneDeep(this.modalConfig.connectors));
233231

234232
// external wallets config
235233
const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
@@ -239,29 +237,31 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
239237
const allConnectorNames = [
240238
...new Set([...Object.keys(this.modalConfig.connectors || {}), ...this.connectors.map((connector) => connector.name)]),
241239
];
242-
const connectorConfigurationPromises = allConnectorNames.map(async (connectorName) => {
240+
const connectorConfigurationPromises = allConnectorNames.map(async (connectorName: string) => {
243241
// start with the default config of connector.
244-
let connectorConfig = this.modalConfig.connectors?.[connectorName] || {
242+
const defaultConnectorConfig = {
245243
label: CONNECTOR_NAMES[connectorName] || connectorName.split("-").map(capitalizeFirstLetter).join(" "),
246244
showOnModal: true,
247245
showOnMobile: true,
248246
showOnDesktop: true,
249247
};
250-
// override the default config of connector if some config is being provided by the user.
251-
if (modalConfig?.modalConfig?.[connectorName]) {
252-
connectorConfig = { ...connectorConfig, ...modalConfig.modalConfig[connectorName] };
253-
}
248+
249+
this.modalConfig.connectors[connectorName] = {
250+
...defaultConnectorConfig,
251+
...(this.modalConfig?.connectors?.[connectorName] || {}),
252+
};
254253

255254
// check if connector is configured/added by user and exist in connectors map.
256255
const connector = this.getConnector(connectorName);
257-
log.debug("connector config", connectorName, connectorConfig.showOnModal, connector);
256+
log.debug("connector config", connectorName, this.modalConfig.connectors?.[connectorName]?.showOnModal, connector);
258257

259-
// if connector is not custom configured then check if it is available in default connectors.
260-
// and if connector is not hidden by user
258+
// check if connector is configured/added by user and exist in connectors map.
259+
const connectorConfig = this.modalConfig.connectors?.[connectorName];
261260
if (!connector) {
262261
if (connectorConfig.showOnModal) throw WalletInitializationError.invalidParams(`Connector ${connectorName} is not configured`);
263262
return;
264263
}
264+
265265
// skip connector if it is hidden by user
266266
if (!connectorConfig.showOnModal) return;
267267

@@ -275,7 +275,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
275275
// skip WC connector if external wallets are disabled or hideWalletDiscovery is true
276276
if (connectorName === WALLET_CONNECTORS.WALLET_CONNECT_V2) {
277277
if (!isExternalWalletEnabled) return;
278-
if (modalConfig?.hideWalletDiscovery) return;
278+
if (this.modalConfig?.hideWalletDiscovery) return;
279279
}
280280

281281
this.modalConfig.connectors[connectorName] = connectorConfig;

packages/modal/src/react/context/Web3AuthInnerContext.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,7 @@ export function Web3AuthInnerProvider(params: PropsWithChildren<Web3AuthProvider
117117
try {
118118
setInitError(null);
119119
setIsInitializing(true);
120-
const { modalConfig, hideWalletDiscovery } = config;
121-
if (modalConfig) {
122-
await web3Auth.initModal({ modalConfig, hideWalletDiscovery });
123-
} else {
124-
await web3Auth.initModal();
125-
}
120+
await web3Auth.initModal();
126121
} catch (error) {
127122
setInitError(error as Error);
128123
} finally {

packages/modal/src/react/interfaces.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import type { ConnectorFn, IBaseWeb3AuthHookContext, IProvider, PluginFn, WALLET_CONNECTOR_TYPE } from "@web3auth/no-modal";
1+
import type { IBaseWeb3AuthHookContext, IProvider } from "@web3auth/no-modal";
22

3-
import { type ModalConfig } from "../interface";
43
import type { Web3Auth, Web3AuthOptions } from "../modalManager";
54

65
export type Web3AuthContextConfig = {
76
web3AuthOptions: Web3AuthOptions;
8-
modalConfig?: Record<WALLET_CONNECTOR_TYPE, ModalConfig>;
9-
hideWalletDiscovery?: boolean;
10-
connectors?: ConnectorFn[];
11-
plugins?: PluginFn[];
127
};
138

149
export interface Web3AuthProviderProps {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export default function Modal(props: ModalProps) {
146146
<Button
147147
variant={isExternalPrimary ? "primary" : "tertiary"}
148148
type="button"
149-
className="w3a--w-full w3ajs-external-toggle__button"
149+
className="w3ajs-external-toggle__button w3a--w-full"
150150
style={{ width: "100%" }}
151151
onClick={() => {
152152
setModalState((prevState) => {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default function SocialLoginPasswordless(props: SocialLoginPasswordlessPr
3737
loginParams: {
3838
authConnection: AUTH_CONNECTION.EMAIL_PASSWORDLESS,
3939
authConnectionId: emailConfig.authConnectionId,
40-
groupedAuthConnectionId: "",
40+
groupedAuthConnectionId: emailConfig.groupedAuthConnectionId,
41+
extraLoginOptions: emailConfig.extraLoginOptions,
4142
login_hint: value,
4243
name: "Email",
4344
},
@@ -55,6 +56,7 @@ export default function SocialLoginPasswordless(props: SocialLoginPasswordlessPr
5556
authConnection: AUTH_CONNECTION.SMS_PASSWORDLESS,
5657
authConnectionId: smsConfig.authConnectionId,
5758
groupedAuthConnectionId: smsConfig.groupedAuthConnectionId,
59+
extraLoginOptions: smsConfig.extraLoginOptions,
5860
login_hint: typeof result === "string" ? result : number,
5961
name: "Mobile",
6062
},
@@ -104,12 +106,12 @@ export default function SocialLoginPasswordless(props: SocialLoginPasswordlessPr
104106
<div className="w3a-group__title">
105107
{t(title)}
106108
{isSmsVisible && (
107-
<div className="w3a--relative w3a--flex w3a--flex-col w3a--items-center w3a--cursor-pointer w3a--group">
109+
<div className="w3a--group w3a--relative w3a--flex w3a--cursor-pointer w3a--flex-col w3a--items-center">
108110
<Icon iconName="information-circle-light" darkIconName="information-circle" />
109-
<div className="w3a--absolute w3a--z-20 w3a--flex-col w3a--items-center w3a--hidden w3a--mb-5 w3a--top-4 group-hover:w3a--flex">
110-
<div className="w3a--w-3 w3a--h-3 w3a--ml-[3px] -w3a--mb-2 w3a--rotate-45 w3a--bg-app-gray-50 dark:w3a--bg-app-gray-600" />
111+
<div className="w3a--absolute w3a--top-4 w3a--z-20 w3a--mb-5 w3a--hidden w3a--flex-col w3a--items-center group-hover:w3a--flex">
112+
<div className="-w3a--mb-2 w3a--ml-[3px] w3a--size-3 w3a--rotate-45 w3a--bg-app-gray-50 dark:w3a--bg-app-gray-600" />
111113
<div
112-
className={`w3a--relative w3a--p-4 w3a--w-[300px] w3a--text-xs w3a--leading-none w3a--text-app-white w3a--rounded-md w3a--bg-app-gray-50 dark:w3a--bg-app-gray-600 w3a--shadow-lg ${
114+
className={`w3a--relative w3a--w-[300px] w3a--rounded-md w3a--bg-app-gray-50 w3a--p-4 w3a--text-xs w3a--leading-none w3a--text-app-white w3a--shadow-lg dark:w3a--bg-app-gray-600 ${
113115
isSmsVisible && !isEmailVisible ? "w3a--left-20" : "w3a--left-8"
114116
}`}
115117
>
@@ -124,7 +126,7 @@ export default function SocialLoginPasswordless(props: SocialLoginPasswordlessPr
124126
</div>
125127
<form className="w3ajs-passwordless-form" onSubmit={(e) => handleFormSubmit(e)}>
126128
<input
127-
className="w3a--w-full w3a--mb-4 w3a-text-field"
129+
className="w3a-text-field w3a--mb-4 w3a--w-full"
128130
name="passwordless-input"
129131
required
130132
placeholder={`${t("modal.social.sms-placeholder-text")} ${placeholder}`}

0 commit comments

Comments
 (0)