@web3auth/modal 8.0.0-alpha.1 → 8.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modal.cjs.js +58 -31
- package/dist/modal.cjs.js.map +1 -1
- package/dist/modal.esm.js +55 -30
- package/dist/modal.esm.js.map +1 -1
- package/dist/modal.umd.min.js +1 -1
- package/dist/modal.umd.min.js.map +1 -1
- package/dist/types/modalManager.d.ts +7 -11
- package/package.json +10 -14
- package/src/modalManager.ts +50 -41
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import { IProvider, WALLET_ADAPTER_TYPE, Web3AuthNoModalOptions } from "@web3auth/base";
|
|
1
|
+
import { IBaseProvider, IProvider, WALLET_ADAPTER_TYPE, Web3AuthNoModalOptions } from "@web3auth/base";
|
|
2
2
|
import { Web3AuthNoModal } from "@web3auth/no-modal";
|
|
3
3
|
import { LoginModal, UIConfig } from "@web3auth/ui";
|
|
4
|
-
import { IWeb3AuthModal, ModalConfig } from "./interface";
|
|
4
|
+
import { AdaptersModalConfig, IWeb3AuthModal, ModalConfig } from "./interface";
|
|
5
5
|
export interface Web3AuthOptions extends Web3AuthNoModalOptions {
|
|
6
|
-
/**
|
|
7
|
-
* web3auth instance provides different adapters for different type of usages. If you are dapp and want to
|
|
8
|
-
* use external wallets like metamask, then you can use the `DAPP` authMode.
|
|
9
|
-
* If you are a wallet and only want to use you own wallet implementations along with openlogin,
|
|
10
|
-
* then you should use `WALLET` authMode.
|
|
11
|
-
*
|
|
12
|
-
* @defaultValue `DAPP`
|
|
13
|
-
*/
|
|
14
|
-
authMode?: "DAPP" | "WALLET";
|
|
15
6
|
/**
|
|
16
7
|
* Config for configuring modal ui display properties
|
|
17
8
|
*/
|
|
18
9
|
uiConfig?: Omit<UIConfig, "adapterListener">;
|
|
10
|
+
/**
|
|
11
|
+
* Private key provider for your chain namespace
|
|
12
|
+
*/
|
|
13
|
+
privateKeyProvider: IBaseProvider<string>;
|
|
19
14
|
}
|
|
20
15
|
export declare class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
|
|
21
16
|
loginModal: LoginModal;
|
|
22
17
|
readonly options: Web3AuthOptions;
|
|
23
18
|
private modalConfig;
|
|
24
19
|
constructor(options: Web3AuthOptions);
|
|
20
|
+
setModalConfig(modalConfig: AdaptersModalConfig): void;
|
|
25
21
|
initModal(params?: {
|
|
26
22
|
modalConfig?: Record<WALLET_ADAPTER_TYPE, ModalConfig>;
|
|
27
23
|
}): Promise<void>;
|
package/package.json
CHANGED
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
"url": "https://github.com/Web3Auth/Web3Auth/issues"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@web3auth/base": "^8.0.0-alpha.
|
|
8
|
-
"@web3auth/base-provider": "^8.0.0-alpha.
|
|
9
|
-
"@web3auth/no-modal": "^8.0.0-alpha.
|
|
10
|
-
"@web3auth/
|
|
7
|
+
"@web3auth/base": "^8.0.0-alpha.11",
|
|
8
|
+
"@web3auth/base-provider": "^8.0.0-alpha.11",
|
|
9
|
+
"@web3auth/no-modal": "^8.0.0-alpha.11",
|
|
10
|
+
"@web3auth/openlogin-adapter": "^8.0.0-alpha.11",
|
|
11
|
+
"@web3auth/ui": "^8.0.0-alpha.11"
|
|
11
12
|
},
|
|
12
13
|
"devDependencies": {
|
|
13
14
|
"@svgr/webpack": "^8.1.0",
|
|
14
15
|
"@toruslabs/isomorphic-style-loader": "^5.3.3",
|
|
15
|
-
"@toruslabs/openlogin-utils": "^6.2.
|
|
16
|
-
"@web3auth/
|
|
17
|
-
"
|
|
18
|
-
"css-loader": "^6.9.1",
|
|
16
|
+
"@toruslabs/openlogin-utils": "^6.2.9",
|
|
17
|
+
"@web3auth/wallet-connect-v2-adapter": "^8.0.0-alpha.11",
|
|
18
|
+
"css-loader": "^6.10.0",
|
|
19
19
|
"postcss-prefix-selector": "^1.16.0",
|
|
20
20
|
"style-loader": "^3.3.4",
|
|
21
21
|
"tailwindcss": "^3.4.1",
|
|
@@ -44,13 +44,9 @@
|
|
|
44
44
|
"name": "@web3auth/modal",
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@babel/runtime": "^7.x",
|
|
47
|
-
"@web3auth/openlogin-adapter": "^8.x",
|
|
48
47
|
"@web3auth/wallet-connect-v2-adapter": "^8.x"
|
|
49
48
|
},
|
|
50
49
|
"peerDependenciesMeta": {
|
|
51
|
-
"@web3auth/openlogin-adapter": {
|
|
52
|
-
"optional": true
|
|
53
|
-
},
|
|
54
50
|
"@web3auth/wallet-connect-v2-adapter": {
|
|
55
51
|
"optional": true
|
|
56
52
|
}
|
|
@@ -73,6 +69,6 @@
|
|
|
73
69
|
},
|
|
74
70
|
"types": "dist/types/index.d.ts",
|
|
75
71
|
"unpkg": "dist/modal.umd.min.js",
|
|
76
|
-
"version": "8.0.0-alpha.
|
|
77
|
-
"gitHead": "
|
|
72
|
+
"version": "8.0.0-alpha.11",
|
|
73
|
+
"gitHead": "00efb0e38a6d52de3bb8bc234edc7fca06d10d87"
|
|
78
74
|
}
|
package/src/modalManager.ts
CHANGED
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
ADAPTER_EVENTS,
|
|
4
4
|
ADAPTER_STATUS,
|
|
5
5
|
BaseAdapterConfig,
|
|
6
|
-
CHAIN_NAMESPACES,
|
|
7
6
|
CustomChainConfig,
|
|
8
7
|
getChainConfig,
|
|
8
|
+
IBaseProvider,
|
|
9
9
|
IProvider,
|
|
10
10
|
log,
|
|
11
11
|
LoginMethodConfig,
|
|
@@ -16,33 +16,23 @@ import {
|
|
|
16
16
|
} from "@web3auth/base";
|
|
17
17
|
import { CommonJRPCProvider } from "@web3auth/base-provider";
|
|
18
18
|
import { Web3AuthNoModal } from "@web3auth/no-modal";
|
|
19
|
-
import
|
|
19
|
+
import { getOpenloginDefaultOptions, OpenloginAdapter } from "@web3auth/openlogin-adapter";
|
|
20
20
|
import { getAdapterSocialLogins, getUserLanguage, LOGIN_MODAL_EVENTS, LoginModal, OPENLOGIN_PROVIDERS, UIConfig } from "@web3auth/ui";
|
|
21
21
|
import type { WalletConnectV2Adapter } from "@web3auth/wallet-connect-v2-adapter";
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
defaultEvmDappModalConfig,
|
|
25
|
-
defaultEvmWalletModalConfig,
|
|
26
|
-
defaultOtherModalConfig,
|
|
27
|
-
defaultSolanaDappModalConfig,
|
|
28
|
-
defaultSolanaWalletModalConfig,
|
|
29
|
-
} from "./config";
|
|
23
|
+
import { defaultOtherModalConfig } from "./config";
|
|
30
24
|
import { AdaptersModalConfig, IWeb3AuthModal, ModalConfig } from "./interface";
|
|
31
25
|
|
|
32
26
|
export interface Web3AuthOptions extends Web3AuthNoModalOptions {
|
|
33
|
-
/**
|
|
34
|
-
* web3auth instance provides different adapters for different type of usages. If you are dapp and want to
|
|
35
|
-
* use external wallets like metamask, then you can use the `DAPP` authMode.
|
|
36
|
-
* If you are a wallet and only want to use you own wallet implementations along with openlogin,
|
|
37
|
-
* then you should use `WALLET` authMode.
|
|
38
|
-
*
|
|
39
|
-
* @defaultValue `DAPP`
|
|
40
|
-
*/
|
|
41
|
-
authMode?: "DAPP" | "WALLET";
|
|
42
27
|
/**
|
|
43
28
|
* Config for configuring modal ui display properties
|
|
44
29
|
*/
|
|
45
30
|
uiConfig?: Omit<UIConfig, "adapterListener">;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Private key provider for your chain namespace
|
|
34
|
+
*/
|
|
35
|
+
privateKeyProvider: IBaseProvider<string>;
|
|
46
36
|
}
|
|
47
37
|
|
|
48
38
|
export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
|
|
@@ -50,37 +40,16 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
|
|
|
50
40
|
|
|
51
41
|
readonly options: Web3AuthOptions;
|
|
52
42
|
|
|
53
|
-
private modalConfig: AdaptersModalConfig =
|
|
43
|
+
private modalConfig: AdaptersModalConfig = defaultOtherModalConfig;
|
|
54
44
|
|
|
55
45
|
constructor(options: Web3AuthOptions) {
|
|
56
46
|
super(options);
|
|
57
47
|
this.options = { ...options };
|
|
58
|
-
const providedChainConfig = this.options.chainConfig;
|
|
59
|
-
if (providedChainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA) {
|
|
60
|
-
if (options.authMode === "WALLET") {
|
|
61
|
-
// default config for solana wallet modal
|
|
62
|
-
this.modalConfig = defaultSolanaWalletModalConfig;
|
|
63
|
-
} else {
|
|
64
|
-
// default config for solana dapp modal
|
|
65
|
-
this.modalConfig = defaultSolanaDappModalConfig;
|
|
66
|
-
}
|
|
67
|
-
} else if (providedChainConfig.chainNamespace === CHAIN_NAMESPACES.EIP155) {
|
|
68
|
-
if (options.authMode === "WALLET") {
|
|
69
|
-
// default config for evm wallet modal
|
|
70
|
-
this.modalConfig = defaultEvmWalletModalConfig;
|
|
71
|
-
} else {
|
|
72
|
-
// default config for evm dapp modal
|
|
73
|
-
this.modalConfig = defaultEvmDappModalConfig;
|
|
74
|
-
}
|
|
75
|
-
} else if (providedChainConfig.chainNamespace === CHAIN_NAMESPACES.OTHER) {
|
|
76
|
-
this.modalConfig = defaultOtherModalConfig;
|
|
77
|
-
} else {
|
|
78
|
-
throw new Error(`Invalid chainNamespace provided: ${providedChainConfig.chainNamespace}`);
|
|
79
|
-
}
|
|
80
48
|
|
|
81
49
|
if (!this.options.uiConfig) this.options.uiConfig = {};
|
|
82
50
|
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
|
|
83
51
|
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "auto";
|
|
52
|
+
if (!this.coreOptions.privateKeyProvider) throw WalletInitializationError.invalidParams("privateKeyProvider is required");
|
|
84
53
|
|
|
85
54
|
this.loginModal = new LoginModal({
|
|
86
55
|
...this.options.uiConfig,
|
|
@@ -89,6 +58,11 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
|
|
|
89
58
|
this.subscribeToLoginModalEvents();
|
|
90
59
|
}
|
|
91
60
|
|
|
61
|
+
public setModalConfig(modalConfig: AdaptersModalConfig): void {
|
|
62
|
+
super.checkInitRequirements();
|
|
63
|
+
this.modalConfig = modalConfig;
|
|
64
|
+
}
|
|
65
|
+
|
|
92
66
|
public async initModal(params?: { modalConfig?: Record<WALLET_ADAPTER_TYPE, ModalConfig> }): Promise<void> {
|
|
93
67
|
super.checkInitRequirements();
|
|
94
68
|
await this.loginModal.initModal();
|
|
@@ -120,6 +94,38 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
|
|
|
120
94
|
// and if adapter is not hidden by user
|
|
121
95
|
if (!adapter && this.modalConfig.adapters?.[adapterName].showOnModal) {
|
|
122
96
|
// Adapters to be shown on modal should be pre-configured.
|
|
97
|
+
if (adapterName === WALLET_ADAPTERS.OPENLOGIN) {
|
|
98
|
+
const defaultOptions = getOpenloginDefaultOptions();
|
|
99
|
+
const { clientId, useCoreKitKey, chainConfig, web3AuthNetwork, sessionTime, privateKeyProvider } = this.coreOptions;
|
|
100
|
+
const finalChainConfig = {
|
|
101
|
+
...getChainConfig(providedChainConfig.chainNamespace, this.coreOptions.chainConfig?.chainId),
|
|
102
|
+
...chainConfig,
|
|
103
|
+
} as CustomChainConfig;
|
|
104
|
+
if (!privateKeyProvider) {
|
|
105
|
+
throw WalletInitializationError.invalidParams("privateKeyProvider is required");
|
|
106
|
+
}
|
|
107
|
+
const finalOpenloginAdapterSettings = {
|
|
108
|
+
...defaultOptions.adapterSettings,
|
|
109
|
+
clientId,
|
|
110
|
+
network: web3AuthNetwork,
|
|
111
|
+
whiteLabel: this.options.uiConfig,
|
|
112
|
+
};
|
|
113
|
+
if (this.options.uiConfig.uxMode) {
|
|
114
|
+
finalOpenloginAdapterSettings.uxMode = this.options.uiConfig.uxMode;
|
|
115
|
+
}
|
|
116
|
+
const openloginAdapter = new OpenloginAdapter({
|
|
117
|
+
...defaultOptions,
|
|
118
|
+
clientId,
|
|
119
|
+
useCoreKitKey,
|
|
120
|
+
chainConfig: { ...finalChainConfig },
|
|
121
|
+
adapterSettings: finalOpenloginAdapterSettings,
|
|
122
|
+
sessionTime,
|
|
123
|
+
web3AuthNetwork,
|
|
124
|
+
privateKeyProvider,
|
|
125
|
+
});
|
|
126
|
+
this.walletAdapters[adapterName] = openloginAdapter;
|
|
127
|
+
return adapterName;
|
|
128
|
+
}
|
|
123
129
|
throw WalletInitializationError.invalidParams(`Adapter ${adapterName} is not configured`);
|
|
124
130
|
} else if (adapter?.type === ADAPTER_CATEGORY.IN_APP || adapter?.type === ADAPTER_CATEGORY.EXTERNAL || adapterName === this.cachedAdapter) {
|
|
125
131
|
if (!this.modalConfig.adapters?.[adapterName].showOnModal) return;
|
|
@@ -152,6 +158,9 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
|
|
|
152
158
|
}
|
|
153
159
|
openloginAdapter.setAdapterSettings({ privateKeyProvider: this.coreOptions.privateKeyProvider });
|
|
154
160
|
}
|
|
161
|
+
if (this.options.uiConfig?.uxMode) {
|
|
162
|
+
openloginAdapter.setAdapterSettings({ uxMode: this.options.uiConfig.uxMode });
|
|
163
|
+
}
|
|
155
164
|
openloginAdapter.setAdapterSettings({ whiteLabel: this.options.uiConfig });
|
|
156
165
|
if (!openloginAdapter.privateKeyProvider) {
|
|
157
166
|
throw WalletInitializationError.invalidParams("privateKeyProvider is required for openlogin adapter");
|