Skip to content

Commit

Permalink
fix issue with login config being overriden
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Apr 15, 2024
1 parent 4714848 commit ae1d9d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/adapters/openlogin-adapter/src/openloginAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ export class OpenloginAdapter extends BaseAdapter<OpenloginLoginParams> {
super.setAdapterSettings(adapterSettings);
const defaultOptions = getOpenloginDefaultOptions();
log.info("setting adapter settings", adapterSettings);
this.openloginOptions = {
...defaultOptions.adapterSettings,
...this.openloginOptions,
...adapterSettings,
};
this.openloginOptions = merge(
defaultOptions.adapterSettings,
this.openloginOptions,
adapterSettings
) as OpenloginAdapterOptions["adapterSettings"];
if (adapterSettings.web3AuthNetwork) {
this.openloginOptions.network = adapterSettings.web3AuthNetwork;
}
Expand Down
30 changes: 26 additions & 4 deletions packages/modal/src/modalManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from "@web3auth/base";
import { CommonJRPCProvider } from "@web3auth/base-provider";
import { Web3AuthNoModal } from "@web3auth/no-modal";
import { getOpenloginDefaultOptions, OpenloginAdapter } from "@web3auth/openlogin-adapter";
import { getOpenloginDefaultOptions, LOGIN_PROVIDER, LoginConfig, OpenloginAdapter, OpenLoginOptions } from "@web3auth/openlogin-adapter";
import { getAdapterSocialLogins, getUserLanguage, LOGIN_MODAL_EVENTS, LoginModal, OPENLOGIN_PROVIDERS, UIConfig } from "@web3auth/ui";
import { WalletConnectV2Adapter } from "@web3auth/wallet-connect-v2-adapter";
import clonedeep from "lodash.clonedeep";
Expand Down Expand Up @@ -86,8 +86,8 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
[WALLET_ADAPTERS.OPENLOGIN]: {
label: WALLET_ADAPTERS.OPENLOGIN,
loginMethods: {
sms_passwordless: {
name: "sms_passwordless",
[LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
name: LOGIN_PROVIDER.SMS_PASSWORDLESS,
showOnModal: smsOtpEnabled,
showOnDesktop: smsOtpEnabled,
showOnMobile: smsOtpEnabled,
Expand Down Expand Up @@ -137,12 +137,22 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
if (!privateKeyProvider) {
throw WalletInitializationError.invalidParams("privateKeyProvider is required");
}
const finalOpenloginAdapterSettings = {
const finalOpenloginAdapterSettings: Partial<OpenLoginOptions> = {
...defaultOptions.adapterSettings,
clientId,
network: web3AuthNetwork,
whiteLabel: this.options.uiConfig,
};
if (smsOtpEnabled !== undefined) {
finalOpenloginAdapterSettings.loginConfig = {
[LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
showOnModal: smsOtpEnabled,
showOnDesktop: smsOtpEnabled,
showOnMobile: smsOtpEnabled,
showOnSocialBackupFactor: smsOtpEnabled,
} as LoginConfig[keyof LoginConfig],
};
}
if (this.options.uiConfig.uxMode) {
finalOpenloginAdapterSettings.uxMode = this.options.uiConfig.uxMode;
}
Expand Down Expand Up @@ -191,6 +201,18 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
}
openloginAdapter.setAdapterSettings({ privateKeyProvider: this.coreOptions.privateKeyProvider });
}
if (smsOtpEnabled !== undefined) {
openloginAdapter.setAdapterSettings({
loginConfig: {
[LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
showOnModal: smsOtpEnabled,
showOnDesktop: smsOtpEnabled,
showOnMobile: smsOtpEnabled,
showOnSocialBackupFactor: smsOtpEnabled,
} as LoginConfig[keyof LoginConfig],
},
});
}
if (this.options.uiConfig?.uxMode) {
openloginAdapter.setAdapterSettings({ uxMode: this.options.uiConfig.uxMode });
}
Expand Down

0 comments on commit ae1d9d2

Please sign in to comment.