Skip to content

Commit c5c1e27

Browse files
committed
make defaultChainId optional
1 parent c463c72 commit c5c1e27

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ export interface IWeb3AuthCoreOptions {
5959
chains?: CustomChainConfig[];
6060

6161
/**
62-
* TODO: should we make this mandatory? Is it possible to configure it from Dashboard?
6362
* default chain Id to use
6463
*/
65-
defaultChainId: string;
64+
defaultChainId?: string;
6665

6766
/**
6867
* setting to true will enable logs

packages/no-modal/src/noModal.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
8383
})),
8484
};
8585

86-
this.currentChainId = options.defaultChainId;
86+
this.currentChainId = options.defaultChainId || chains[0].chainId;
8787
}
8888

8989
get currentChain(): CustomChainConfig {
@@ -230,10 +230,10 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
230230

231231
protected initCachedConnectorAndChainId() {
232232
this.cachedConnector = storageAvailable(this.storage) ? window[this.storage].getItem(CONNECTOR_CACHE_KEY) : null;
233-
// init chainId using cached chainId if it exists and is valid, otherwise use the first chain
233+
// init chainId using cached chainId if it exists and is valid, otherwise use the defaultChainId or the first chain
234234
const cachedChainId = storageAvailable(this.storage) ? window[this.storage].getItem(CURRENT_CHAIN_CACHE_KEY) : null;
235235
const isCachedChainIdValid = cachedChainId && this.coreOptions.chains.some((chain) => chain.chainId === cachedChainId);
236-
this.currentChainId = isCachedChainIdValid ? cachedChainId : this.coreOptions.defaultChainId;
236+
this.currentChainId = isCachedChainIdValid ? cachedChainId : this.coreOptions.defaultChainId || this.coreOptions.chains[0].chainId;
237237
}
238238

239239
protected async setupCommonJRPCProvider() {

0 commit comments

Comments
 (0)