@@ -22,8 +22,8 @@ import {
2222} from "@web3auth/no-modal" ;
2323import 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" ;
2727import {
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
4449export 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 ;
0 commit comments