Skip to content

Commit 25d8405

Browse files
committed
fix review comments
1 parent 6b6670e commit 25d8405

File tree

3 files changed

+15
-47
lines changed

3 files changed

+15
-47
lines changed

packages/modal/src/modalManager.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ import deepmerge from "deepmerge";
2424

2525
import { defaultConnectorsModalConfig, walletRegistryUrl } from "./config";
2626
import { type ConnectorsModalConfig, type IWeb3AuthModal, type ModalConfig } from "./interface";
27-
import {
28-
AUTH_PROVIDERS,
29-
capitalizeFirstLetter,
30-
getConnectorSocialLogins,
31-
getUserLanguage,
32-
LOGIN_MODAL_EVENTS,
33-
LoginModal,
34-
type UIConfig,
35-
} from "./ui";
27+
import { AUTH_PROVIDERS, capitalizeFirstLetter, getUserLanguage, LOGIN_MODAL_EVENTS, LoginModal, type UIConfig } from "./ui";
3628

3729
export interface Web3AuthOptions extends IWeb3AuthCoreOptions {
3830
/**
@@ -293,8 +285,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
293285
if (connector.type !== CONNECTOR_CATEGORY.IN_APP) return false;
294286
if (this.modalConfig.connectors?.[connector.name]?.showOnModal !== true) return false;
295287
if (!this.modalConfig.connectors?.[connector.name]?.loginMethods) return true;
296-
const mergedLoginMethods = getConnectorSocialLogins(connector.name, this.modalConfig.connectors[connector.name]?.loginMethods);
297-
if (Object.values(mergedLoginMethods).some((method: LoginMethodConfig[keyof LoginMethodConfig]) => method.showOnModal)) return true;
288+
if (Object.values(this.modalConfig.connectors[connector.name].loginMethods).some((method) => method.showOnModal)) return true;
298289
return false;
299290
});
300291
log.debug(hasInAppConnectors, this.connectors, connectorNames, "hasInAppWallets");
@@ -330,7 +321,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
330321
// adding it later if no in-app wallets are available.
331322
if (connector.type === CONNECTOR_CATEGORY.IN_APP) {
332323
log.info("connectorInitResults", connectorName);
333-
const loginMethods = getConnectorSocialLogins(connectorName, this.modalConfig.connectors[connectorName]?.loginMethods);
324+
const loginMethods = this.modalConfig.connectors[connectorName]?.loginMethods || {};
334325
this.loginModal.addSocialLogins(connectorName, loginMethods, this.options.uiConfig?.loginMethodsOrder || AUTH_PROVIDERS, {
335326
...this.options.uiConfig,
336327
loginGridCol: this.options.uiConfig?.loginGridCol || 3,

packages/modal/src/ui/utils.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
import { get, post } from "@toruslabs/http-helpers";
22
import { LANGUAGE_MAP, type LANGUAGE_TYPE, LANGUAGES } from "@web3auth/auth";
3-
import { log, type LoginMethodConfig, WALLET_CONNECTORS, WalletInitializationError } from "@web3auth/no-modal";
4-
5-
import { AUTH_PROVIDERS, AUTH_PROVIDERS_NAMES } from "./config";
6-
7-
export const getConnectorSocialLogins = (connectorName: string, loginMethodsConfig: LoginMethodConfig = {}): LoginMethodConfig => {
8-
const finalLoginMethodsConfig: LoginMethodConfig = {};
9-
if (connectorName === WALLET_CONNECTORS.AUTH) {
10-
AUTH_PROVIDERS.forEach((loginMethod) => {
11-
if (!loginMethodsConfig[loginMethod]) return;
12-
const currentLoginMethodConfig = { name: AUTH_PROVIDERS_NAMES[loginMethod], ...loginMethodsConfig[loginMethod] };
13-
finalLoginMethodsConfig[loginMethod] = { ...currentLoginMethodConfig };
14-
});
15-
log.debug("auth login method ui config", finalLoginMethodsConfig);
16-
} else {
17-
throw WalletInitializationError.invalidParams(`${connectorName} is not a valid connector`);
18-
}
19-
return finalLoginMethodsConfig;
20-
};
3+
import { log } from "@web3auth/no-modal";
214

225
export async function validateImageUrl(url: string): Promise<boolean> {
236
return new Promise((resolve, reject) => {

packages/no-modal/src/connectors/auth-connector/authConnector.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -504,23 +504,17 @@ class AuthConnector extends BaseConnector<AuthLoginParams> {
504504

505505
private getOAuthProviderConfig(params: Pick<AuthLoginParams, "authConnection" | "authConnectionId" | "groupedAuthConnectionId">) {
506506
const { authConnection, authConnectionId, groupedAuthConnectionId } = params;
507-
// if groupedAuthConnectionId or authConnectionId, then use the specific auth connection
508-
if (groupedAuthConnectionId || authConnectionId) {
509-
const authConnectionItem = this.authConnectionConfig.find((x) => {
510-
if (groupedAuthConnectionId) return x.authConnection === authConnection && x.groupedAuthConnectionId === groupedAuthConnectionId;
511-
if (authConnectionId) return x.authConnection === authConnection && x.authConnectionId === authConnectionId;
512-
return false;
513-
});
514-
// if no auth connection item found, then return undefined
515-
return authConnectionItem;
516-
} else {
517-
// if no groupedAuthConnectionId or authConnectionId, then use the default auth connection
518-
const defaultAuthConnectionItem = this.authConnectionConfig.find((x) => x.authConnection === authConnection && x.isDefault);
519-
if (defaultAuthConnectionItem) return defaultAuthConnectionItem;
520-
521-
// if no default auth connection, then use the first auth connection
522-
return this.authConnectionConfig.find((x) => x.authConnection === authConnection);
523-
}
507+
const providerConfig = this.authConnectionConfig.find((x) => {
508+
if (groupedAuthConnectionId) {
509+
return x.authConnection === authConnection && x.groupedAuthConnectionId === groupedAuthConnectionId;
510+
}
511+
if (authConnectionId) {
512+
return x.authConnection === authConnection && x.authConnectionId === authConnectionId;
513+
}
514+
// return the default auth connection, if not found, return undefined
515+
return x.authConnection === authConnection && x.isDefault;
516+
});
517+
return providerConfig;
524518
}
525519
}
526520

0 commit comments

Comments
 (0)