Skip to content

Commit 1f8be9e

Browse files
committed
Merge branch 'master' into feat/sdk-v10-chains
2 parents 33a8f9e + d22af09 commit 1f8be9e

File tree

8 files changed

+48
-32
lines changed

8 files changed

+48
-32
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "10.0.0-alpha.0",
2+
"version": "10.0.0-alpha.1",
33
"npmClient": "npm"
44
}

package-lock.json

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

packages/modal/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3auth/modal",
3-
"version": "10.0.0-alpha.0",
3+
"version": "10.0.0-alpha.1",
44
"description": "Multi chain wallet aggregator for web3Auth",
55
"keywords": [
66
"web3Auth/ui",
@@ -74,7 +74,7 @@
7474
"dependencies": {
7575
"@toruslabs/http-helpers": "^7.0.0",
7676
"@web3auth/auth": "^9.6.4",
77-
"@web3auth/no-modal": "^10.0.0-alpha.0",
77+
"@web3auth/no-modal": "^10.0.0-alpha.1",
7878
"bowser": "^2.11.0",
7979
"classnames": "^2.5.1",
8080
"copy-to-clipboard": "^3.3.3",

packages/no-modal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3auth/no-modal",
3-
"version": "10.0.0-alpha.0",
3+
"version": "10.0.0-alpha.1",
44
"description": "Multi chain wallet aggregator for web3Auth",
55
"keywords": [
66
"web3Auth/no-modal",

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

Lines changed: 2 additions & 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
@@ -75,6 +74,7 @@ export interface IWeb3AuthCoreOptions {
7574
*
7675
* @defaultValue "local"
7776
*/
77+
// TODO: rename this to match customauth, sfa
7878
storageType?: "session" | "local";
7979

8080
/**

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ class AuthConnector extends BaseConnector<AuthLoginParams> {
127127
});
128128
break;
129129
}
130+
case CHAIN_NAMESPACES.XRPL:
131+
throw WalletLoginError.connectionError("Private key provider is required for XRPL");
130132
default: {
131133
const { CommonPrivateKeyProvider } = await import("@/core/base-provider");
132134
this.privateKeyProvider = new CommonPrivateKeyProvider({
@@ -350,10 +352,10 @@ class AuthConnector extends BaseConnector<AuthLoginParams> {
350352
}
351353
}
352354

353-
export const authConnector = (params?: AuthConnectorOptions): ConnectorFn => {
355+
export const authConnector = (params?: Omit<AuthConnectorOptions, "coreOptions">): ConnectorFn => {
354356
return ({ projectConfig, coreOptions }: ConnectorParams) => {
355357
// Connector settings
356-
const connectorSettings: AuthConnectorOptions["connectorSettings"] = { uxMode: UX_MODE.POPUP };
358+
const connectorSettings: AuthConnectorOptions["connectorSettings"] = {};
357359
const { sms_otp_enabled: smsOtpEnabled, whitelist } = projectConfig;
358360
if (smsOtpEnabled !== undefined) {
359361
connectorSettings.loginConfig = {
@@ -370,7 +372,11 @@ export const authConnector = (params?: AuthConnectorOptions): ConnectorFn => {
370372
const uiConfig = deepmerge(cloneDeep(projectConfig?.whitelabel || {}), coreOptions.uiConfig || {});
371373
if (!uiConfig.mode) uiConfig.mode = "light";
372374
connectorSettings.whiteLabel = uiConfig;
373-
const finalConnectorSettings = deepmerge(params?.connectorSettings || {}, connectorSettings) as AuthConnectorOptions["connectorSettings"];
375+
const finalConnectorSettings = deepmerge.all([
376+
{ uxMode: UX_MODE.POPUP }, // default settings
377+
params?.connectorSettings || {},
378+
connectorSettings,
379+
]) as AuthConnectorOptions["connectorSettings"];
374380

375381
// WS settings
376382
const isKeyExportEnabled = typeof projectConfig.key_export_enabled === "boolean" ? projectConfig.key_export_enabled : true;

packages/no-modal/src/noModal.ts

Lines changed: 13 additions & 14 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() {
@@ -266,8 +266,8 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
266266

267267
// add injected connectors
268268
const isMipdEnabled = this.coreOptions.multiInjectedProviderDiscovery ?? true;
269+
const chainNamespaces = new Set(this.coreOptions.chains.map((chain) => chain.chainNamespace));
269270
if (isMipdEnabled) {
270-
const chainNamespaces = new Set(this.coreOptions.chains.map((chain) => chain.chainNamespace));
271271
// Solana chains
272272
if (chainNamespaces.has(CHAIN_NAMESPACES.SOLANA)) {
273273
const { createSolanaMipd, hasSolanaWalletStandardFeatures, walletStandardConnector } = await import("@/core/injected-solana-connector");
@@ -295,16 +295,16 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
295295
});
296296
connectorFns.push(...evmMipd.getProviders().map(injectedEvmConnector));
297297
}
298+
}
298299

299-
// add WalletConnectV2 connector if enabled
300-
if (
301-
projectConfig.wallet_connect_enabled &&
302-
projectConfig.wallet_connect_project_id &&
303-
(chainNamespaces.has(CHAIN_NAMESPACES.SOLANA) || chainNamespaces.has(CHAIN_NAMESPACES.EIP155))
304-
) {
305-
const { walletConnectV2Connector } = await import("@/core/wallet-connect-v2-connector");
306-
connectorFns.push(walletConnectV2Connector());
307-
}
300+
// add WalletConnectV2 connector if enabled
301+
if (
302+
projectConfig.wallet_connect_enabled &&
303+
projectConfig.wallet_connect_project_id &&
304+
(chainNamespaces.has(CHAIN_NAMESPACES.SOLANA) || chainNamespaces.has(CHAIN_NAMESPACES.EIP155))
305+
) {
306+
const { walletConnectV2Connector } = await import("@/core/wallet-connect-v2-connector");
307+
connectorFns.push(walletConnectV2Connector());
308308
}
309309

310310
const connectors = connectorFns.map((connectorFn) => connectorFn(config));
@@ -433,7 +433,6 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
433433
* @throws WalletInitializationError If no chain is found for the connector's namespace
434434
*/
435435
protected getInitialChainIdForConnector(connector: IConnector<unknown>): CustomChainConfig {
436-
// TODO: combine this logic with chainId input from web3auth options
437436
let initialChain = this.currentChain;
438437
if (initialChain.chainNamespace !== connector.connectorNamespace && connector.connectorNamespace !== CONNECTOR_NAMESPACES.MULTICHAIN) {
439438
initialChain = this.coreOptions.chains.find((x) => x.chainNamespace === connector.connectorNamespace);

packages/no-modal/src/providers/base-provider/baseProvider.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,17 @@ export abstract class BaseProvider<C extends BaseProviderConfig, S extends BaseP
118118
if (this._providerEngineProxy) {
119119
// eslint-disable-next-line @typescript-eslint/no-explicit-any
120120
(this._providerEngineProxy as any).setTarget(provider);
121+
// re-emit events from provider
122+
this._providerEngineProxy.eventNames().forEach((event) => {
123+
provider.on(event as keyof ProviderEvents, (...args) => {
124+
// eslint-disable-next-line
125+
this.emit(event as keyof BaseProviderEvents<S>, ...(args as any));
126+
});
127+
});
128+
this.handleChainChangedProvider();
121129
} else {
122-
// TODO: need to test if provider.on("chainChanged") & other events are re-emitted by commonjrpc provider
123130
this._providerEngineProxy = createEventEmitterProxy<SafeEventEmitterProvider>(provider);
124131
}
125-
126-
this.handleChainChangedProvider();
127132
}
128133

129134
public setKeyExportFlag(flag: boolean): void {
@@ -146,7 +151,6 @@ export abstract class BaseProvider<C extends BaseProviderConfig, S extends BaseP
146151
// This is only added because we don't have ethereum and solana private key providers anymore
147152
this.provider.on("chainChanged", (chainId: string) => {
148153
this.update({ chainId } as Partial<S>);
149-
this.emit("chainChanged", chainId);
150154
});
151155
}
152156

0 commit comments

Comments
 (0)