@web3auth/modal 10.0.0-alpha.1 → 10.0.0-beta.0
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/lib.cjs/packages/modal/src/config.js +3 -57
- package/dist/lib.cjs/packages/modal/src/index.js +1 -5
- package/dist/lib.cjs/packages/modal/src/modalManager.js +142 -106
- package/dist/lib.cjs/packages/modal/src/react/context/Web3AuthInnerContext.js +1 -12
- package/dist/lib.cjs/packages/modal/src/ui/components/AdapterLoader.js +24 -24
- package/dist/lib.cjs/packages/modal/src/ui/components/Button/Button.js +3 -4
- package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletButton.js +6 -6
- package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletChainNamespace.js +91 -0
- package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletConnect.js +12 -12
- package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletDetails.js +14 -5
- package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletHeader.js +9 -9
- package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletInstall.js +16 -16
- package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallets.js +48 -42
- package/dist/lib.cjs/packages/modal/src/ui/components/Footer.js +6 -6
- package/dist/lib.cjs/packages/modal/src/ui/components/Header.js +17 -17
- package/dist/lib.cjs/packages/modal/src/ui/components/Icon.js +4 -4
- package/dist/lib.cjs/packages/modal/src/ui/components/Image.js +4 -4
- package/dist/lib.cjs/packages/modal/src/ui/components/Loader.js +11 -11
- package/dist/lib.cjs/packages/modal/src/ui/components/Modal.js +62 -28
- package/dist/lib.cjs/packages/modal/src/ui/components/SelfCustodyViaWeb3Auth.js +5 -5
- package/dist/lib.cjs/packages/modal/src/ui/components/SocialLoginPasswordless.js +31 -22
- package/dist/lib.cjs/packages/modal/src/ui/components/SocialLogins.js +31 -26
- package/dist/lib.cjs/packages/modal/src/ui/components/WalletConnect.js +9 -9
- package/dist/lib.cjs/packages/modal/src/ui/config.js +3 -4
- package/dist/lib.cjs/packages/modal/src/ui/css/web3auth.css.js +1 -1
- package/dist/lib.cjs/packages/modal/src/ui/i18n/dutch.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/english.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/french.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/german.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/japanese.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/korean.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/mandarin.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/portuguese.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/spanish.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/i18n/turkish.json.js +3 -0
- package/dist/lib.cjs/packages/modal/src/ui/interfaces.js +2 -4
- package/dist/lib.cjs/packages/modal/src/ui/loginModal.js +18 -15
- package/dist/lib.cjs/packages/modal/src/ui/utils.js +0 -21
- package/dist/lib.cjs/packages/modal/src/vue/Web3AuthProvider.js +1 -13
- package/dist/lib.cjs/types/config.d.ts +3 -0
- package/dist/{types → lib.cjs/types}/interface.d.ts +2 -6
- package/dist/{types → lib.cjs/types}/modalManager.d.ts +7 -3
- package/dist/{types → lib.cjs/types}/react/interfaces.d.ts +1 -6
- package/dist/lib.cjs/types/ui/components/ExternalWallet/ExternalWalletChainNamespace.d.ts +9 -0
- package/dist/{types → lib.cjs/types}/ui/components/ExternalWallet/ExternalWalletDetails.d.ts +2 -1
- package/dist/{types → lib.cjs/types}/ui/components/ExternalWallets.d.ts +4 -6
- package/dist/{types → lib.cjs/types}/ui/components/Modal.d.ts +1 -1
- package/dist/{types → lib.cjs/types}/ui/components/SocialLoginPasswordless.d.ts +3 -5
- package/dist/{types → lib.cjs/types}/ui/components/SocialLogins.d.ts +2 -6
- package/dist/lib.cjs/types/ui/config.d.ts +4 -0
- package/dist/{types → lib.cjs/types}/ui/interfaces.d.ts +10 -8
- package/dist/{types → lib.cjs/types}/ui/loginModal.d.ts +1 -1
- package/dist/{types → lib.cjs/types}/ui/utils.d.ts +1 -3
- package/dist/{types → lib.cjs/types}/vue/interfaces.d.ts +1 -6
- package/dist/lib.esm/packages/modal/src/config.js +4 -54
- package/dist/lib.esm/packages/modal/src/index.js +1 -1
- package/dist/lib.esm/packages/modal/src/modalManager.js +154 -95
- package/dist/lib.esm/packages/modal/src/react/context/Web3AuthInnerContext.js +1 -12
- package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletChainNamespace.js +90 -0
- package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletDetails.js +13 -1
- package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallets.js +29 -19
- package/dist/lib.esm/packages/modal/src/ui/components/Modal.js +47 -12
- package/dist/lib.esm/packages/modal/src/ui/components/SocialLoginPasswordless.js +18 -9
- package/dist/lib.esm/packages/modal/src/ui/components/SocialLogins.js +18 -12
- package/dist/lib.esm/packages/modal/src/ui/config.js +5 -5
- package/dist/lib.esm/packages/modal/src/ui/css/web3auth.css.js +1 -1
- package/dist/lib.esm/packages/modal/src/ui/i18n/dutch.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/english.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/french.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/german.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/japanese.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/korean.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/mandarin.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/portuguese.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/spanish.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/i18n/turkish.json.js +3 -0
- package/dist/lib.esm/packages/modal/src/ui/interfaces.js +2 -1
- package/dist/lib.esm/packages/modal/src/ui/loginModal.js +15 -9
- package/dist/lib.esm/packages/modal/src/ui/utils.js +2 -22
- package/dist/lib.esm/packages/modal/src/vue/Web3AuthProvider.js +1 -12
- package/dist/modal.umd.min.js +1 -1
- package/package.json +18 -18
- package/dist/modal.cjs.js +0 -5884
- package/dist/types/config.d.ts +0 -7
- package/dist/types/ui/config.d.ts +0 -4
- /package/dist/{types → lib.cjs/types}/index.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/react/Web3AuthProvider.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/react/context/Web3AuthInnerContext.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/react/context/index.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/react/hooks/index.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/react/hooks/useWeb3Auth.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/react/index.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/AdapterLoader.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/Button/Button.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/Button/index.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/ExternalWallet/ExternalWalletButton.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/ExternalWallet/ExternalWalletConnect.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/ExternalWallet/ExternalWalletHeader.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/ExternalWallet/ExternalWalletInstall.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/Footer.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/Header.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/Icon.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/Image.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/Loader.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/SelfCustodyViaWeb3Auth.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/components/WalletConnect.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/context/ThemeContext.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/helper/countryData.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/i18n/index.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/index.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/ui/localeImport.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/vue/Web3AuthProvider.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/vue/composables/index.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/vue/composables/useWeb3Auth.d.ts +0 -0
- /package/dist/{types → lib.cjs/types}/vue/index.d.ts +0 -0
|
@@ -1,43 +1,50 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import { Web3AuthNoModal, cloneDeep, CONNECTOR_EVENTS, WalletInitializationError, CONNECTOR_STATUS, fetchProjectConfig,
|
|
3
|
+
import { Web3AuthNoModal, cloneDeep, log, CONNECTOR_EVENTS, WalletInitializationError, CONNECTOR_STATUS, fetchProjectConfig, fetchWalletRegistry, WALLET_CONNECTORS, CONNECTOR_NAMES, CONNECTOR_CATEGORY } from '@web3auth/no-modal';
|
|
4
4
|
import deepmerge from 'deepmerge';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { defaultConnectorsModalConfig, walletRegistryUrl } from './config.js';
|
|
6
|
+
import { AUTH_PROVIDERS, capitalizeFirstLetter } from './ui/config.js';
|
|
7
7
|
import { LOGIN_MODAL_EVENTS } from './ui/interfaces.js';
|
|
8
8
|
import { LoginModal } from './ui/loginModal.js';
|
|
9
|
-
import { getUserLanguage
|
|
9
|
+
import { getUserLanguage } from './ui/utils.js';
|
|
10
10
|
|
|
11
11
|
class Web3Auth extends Web3AuthNoModal {
|
|
12
12
|
constructor(options) {
|
|
13
13
|
super(options);
|
|
14
14
|
_defineProperty(this, "loginModal", void 0);
|
|
15
15
|
_defineProperty(this, "options", void 0);
|
|
16
|
-
_defineProperty(this, "modalConfig", cloneDeep(
|
|
16
|
+
_defineProperty(this, "modalConfig", cloneDeep(defaultConnectorsModalConfig));
|
|
17
17
|
this.options = _objectSpread({}, options);
|
|
18
18
|
if (!this.options.uiConfig) this.options.uiConfig = {};
|
|
19
|
+
if (this.options.modalConfig) this.modalConfig = this.options.modalConfig;
|
|
20
|
+
log.info("modalConfig", this.modalConfig);
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
async initModal() {
|
|
23
|
+
var _this$coreOptions$cha;
|
|
21
24
|
super.checkInitRequirements();
|
|
22
|
-
this.modalConfig = modalConfig;
|
|
23
|
-
}
|
|
24
|
-
async initModal(params) {
|
|
25
|
-
super.checkInitRequirements();
|
|
26
|
-
super.initCachedConnectorAndChainId();
|
|
27
25
|
// get project config and wallet registry
|
|
28
26
|
const {
|
|
29
27
|
projectConfig,
|
|
30
28
|
walletRegistry
|
|
31
|
-
} = await this.getProjectAndWalletConfig(
|
|
29
|
+
} = await this.getProjectAndWalletConfig();
|
|
32
30
|
this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
|
|
33
31
|
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
|
|
34
32
|
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
|
|
35
33
|
|
|
34
|
+
// init config
|
|
35
|
+
super.initAccountAbstractionConfig(projectConfig);
|
|
36
|
+
super.initChainsConfig(projectConfig);
|
|
37
|
+
super.initCachedConnectorAndChainId();
|
|
38
|
+
|
|
36
39
|
// init login modal
|
|
40
|
+
const {
|
|
41
|
+
filteredWalletRegistry,
|
|
42
|
+
disabledExternalWallets
|
|
43
|
+
} = this.filterWalletRegistry(walletRegistry, projectConfig);
|
|
37
44
|
this.loginModal = new LoginModal(_objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
|
|
38
45
|
connectorListener: this,
|
|
39
|
-
|
|
40
|
-
walletRegistry
|
|
46
|
+
chainNamespaces: [...new Set(((_this$coreOptions$cha = this.coreOptions.chains) === null || _this$coreOptions$cha === void 0 ? void 0 : _this$coreOptions$cha.map(x => x.chainNamespace)) || [])],
|
|
47
|
+
walletRegistry: filteredWalletRegistry
|
|
41
48
|
}));
|
|
42
49
|
this.subscribeToLoginModalEvents();
|
|
43
50
|
await this.loginModal.initModal();
|
|
@@ -51,7 +58,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
51
58
|
}) => this.initConnectors({
|
|
52
59
|
connectors: newConnectors,
|
|
53
60
|
projectConfig,
|
|
54
|
-
|
|
61
|
+
disabledExternalWallets
|
|
55
62
|
}));
|
|
56
63
|
await this.loadConnectors({
|
|
57
64
|
projectConfig
|
|
@@ -80,7 +87,35 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
80
87
|
});
|
|
81
88
|
});
|
|
82
89
|
}
|
|
83
|
-
|
|
90
|
+
filterWalletRegistry(walletRegistry, projectConfig) {
|
|
91
|
+
const {
|
|
92
|
+
disableAllRecommendedWallets,
|
|
93
|
+
disableAllOtherWallets,
|
|
94
|
+
disabledWallets
|
|
95
|
+
} = projectConfig.externalWalletAuth || {};
|
|
96
|
+
|
|
97
|
+
// add disabled wallets to set
|
|
98
|
+
const disabledExternalWallets = new Set(disabledWallets || []);
|
|
99
|
+
if (disableAllRecommendedWallets) {
|
|
100
|
+
Object.keys(walletRegistry.default).forEach(wallet => disabledExternalWallets.add(wallet));
|
|
101
|
+
}
|
|
102
|
+
if (disableAllOtherWallets) {
|
|
103
|
+
Object.keys(walletRegistry.others).forEach(wallet => disabledExternalWallets.add(wallet));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// remove wallets that are disabled in project config from wallet registry
|
|
107
|
+
const filteredWalletRegistry = cloneDeep(walletRegistry);
|
|
108
|
+
disabledExternalWallets.forEach(wallet => {
|
|
109
|
+
delete filteredWalletRegistry.default[wallet];
|
|
110
|
+
delete filteredWalletRegistry.others[wallet];
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
disabledExternalWallets,
|
|
114
|
+
filteredWalletRegistry
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async getProjectAndWalletConfig() {
|
|
118
|
+
var _this$modalConfig;
|
|
84
119
|
// get project config
|
|
85
120
|
let projectConfig;
|
|
86
121
|
try {
|
|
@@ -96,7 +131,8 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
96
131
|
others: {},
|
|
97
132
|
default: {}
|
|
98
133
|
};
|
|
99
|
-
|
|
134
|
+
const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
|
|
135
|
+
if (isExternalWalletEnabled && !((_this$modalConfig = this.modalConfig) !== null && _this$modalConfig !== void 0 && _this$modalConfig.hideWalletDiscovery)) {
|
|
100
136
|
try {
|
|
101
137
|
walletRegistry = await fetchWalletRegistry(walletRegistryUrl);
|
|
102
138
|
} catch (e) {
|
|
@@ -111,16 +147,19 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
111
147
|
async initConnectors({
|
|
112
148
|
connectors,
|
|
113
149
|
projectConfig,
|
|
114
|
-
|
|
150
|
+
disabledExternalWallets
|
|
115
151
|
}) {
|
|
116
152
|
// filter connectors based on config
|
|
117
|
-
const filteredConnectorNames = await this.filterConnectors(
|
|
153
|
+
const filteredConnectorNames = await this.filterConnectors({
|
|
154
|
+
projectConfig,
|
|
155
|
+
disabledExternalWallets
|
|
156
|
+
});
|
|
118
157
|
|
|
119
158
|
// initialize connectors based on availability
|
|
120
159
|
const {
|
|
121
160
|
hasInAppConnectors,
|
|
122
161
|
hasExternalConnectors
|
|
123
|
-
} = await this.checkConnectorAvailability(filteredConnectorNames
|
|
162
|
+
} = await this.checkConnectorAvailability(filteredConnectorNames);
|
|
124
163
|
if (hasInAppConnectors) {
|
|
125
164
|
await this.initInAppAndCachedConnectors(connectors, filteredConnectorNames);
|
|
126
165
|
// show connect button if external wallets are available
|
|
@@ -138,106 +177,119 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
138
177
|
this.emit(CONNECTOR_EVENTS.READY);
|
|
139
178
|
}
|
|
140
179
|
}
|
|
141
|
-
async filterConnectors(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
180
|
+
async filterConnectors({
|
|
181
|
+
projectConfig,
|
|
182
|
+
disabledExternalWallets
|
|
183
|
+
}) {
|
|
184
|
+
var _this$modalConfig2, _this$modalConfig3, _projectConfig$loginM, _projectConfig$loginM2;
|
|
185
|
+
// Auth connector config: merge code config with config from dashboard
|
|
186
|
+
const loginMethods = {};
|
|
187
|
+
for (const authConnectionConfig of projectConfig.embeddedWalletAuth || []) {
|
|
188
|
+
const {
|
|
189
|
+
isDefault,
|
|
190
|
+
authConnectionId,
|
|
191
|
+
groupedAuthConnectionId,
|
|
192
|
+
authConnection
|
|
193
|
+
} = authConnectionConfig;
|
|
194
|
+
// for custom auth connections, authConnectionId or groupedAuthConnectionId are required.
|
|
195
|
+
if (!isDefault && (!authConnectionId || !groupedAuthConnectionId)) return;
|
|
196
|
+
loginMethods[authConnection] = _objectSpread(_objectSpread({
|
|
197
|
+
name: authConnection
|
|
198
|
+
}, authConnectionConfig), {}, {
|
|
199
|
+
showOnModal: true,
|
|
200
|
+
showOnDesktop: true,
|
|
201
|
+
showOnMobile: true
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
const dashboardConnectorConfig = {
|
|
205
|
+
[WALLET_CONNECTORS.AUTH]: {
|
|
206
|
+
label: WALLET_CONNECTORS.AUTH,
|
|
207
|
+
loginMethods
|
|
168
208
|
}
|
|
169
|
-
|
|
209
|
+
};
|
|
210
|
+
if ((_this$modalConfig2 = this.modalConfig) !== null && _this$modalConfig2 !== void 0 && (_this$modalConfig2 = _this$modalConfig2.connectors) !== null && _this$modalConfig2 !== void 0 && _this$modalConfig2[WALLET_CONNECTORS.AUTH]) {
|
|
211
|
+
if (!this.modalConfig.connectors[WALLET_CONNECTORS.AUTH].loginMethods) this.modalConfig.connectors[WALLET_CONNECTORS.AUTH].loginMethods = {};
|
|
212
|
+
}
|
|
213
|
+
this.modalConfig.connectors = deepmerge(dashboardConnectorConfig, cloneDeep(this.modalConfig.connectors || {}));
|
|
214
|
+
// TODO: validate modal connector config here.!!
|
|
215
|
+
|
|
216
|
+
if ((_this$modalConfig3 = this.modalConfig) !== null && _this$modalConfig3 !== void 0 && (_this$modalConfig3 = _this$modalConfig3.connectors) !== null && _this$modalConfig3 !== void 0 && (_this$modalConfig3 = _this$modalConfig3[WALLET_CONNECTORS.AUTH]) !== null && _this$modalConfig3 !== void 0 && _this$modalConfig3.loginMethods) {
|
|
217
|
+
const authProviders = new Set(AUTH_PROVIDERS);
|
|
218
|
+
Object.keys(this.modalConfig.connectors[WALLET_CONNECTORS.AUTH].loginMethods).forEach(key => {
|
|
219
|
+
if (!authProviders.has(key)) {
|
|
220
|
+
throw WalletInitializationError.invalidParams(`Invalid auth connection: ${key}`);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
170
223
|
}
|
|
171
224
|
|
|
225
|
+
// external wallets config
|
|
226
|
+
const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
|
|
227
|
+
const isInstalledWalletWalletDisplayed = Boolean((_projectConfig$loginM = (_projectConfig$loginM2 = projectConfig.loginModal) === null || _projectConfig$loginM2 === void 0 ? void 0 : _projectConfig$loginM2.displayInstalledExternalWallets) !== null && _projectConfig$loginM !== void 0 ? _projectConfig$loginM : true);
|
|
228
|
+
|
|
172
229
|
// merge default connectors with the custom configured connectors.
|
|
173
230
|
const allConnectorNames = [...new Set([...Object.keys(this.modalConfig.connectors || {}), ...this.connectors.map(connector => connector.name)])];
|
|
174
|
-
const
|
|
175
|
-
var _this$
|
|
231
|
+
const connectorNames = allConnectorNames.map(connectorName => {
|
|
232
|
+
var _this$modalConfig4, _this$modalConfig$con, _this$modalConfig$con2;
|
|
176
233
|
// start with the default config of connector.
|
|
177
|
-
|
|
234
|
+
const defaultConnectorConfig = {
|
|
178
235
|
label: CONNECTOR_NAMES[connectorName] || connectorName.split("-").map(capitalizeFirstLetter).join(" "),
|
|
179
236
|
showOnModal: true,
|
|
180
237
|
showOnMobile: true,
|
|
181
238
|
showOnDesktop: true
|
|
182
239
|
};
|
|
183
|
-
|
|
184
|
-
if ((_params2 = params) !== null && _params2 !== void 0 && (_params2 = _params2.modalConfig) !== null && _params2 !== void 0 && _params2[connectorName]) {
|
|
185
|
-
connectorConfig = _objectSpread(_objectSpread({}, connectorConfig), params.modalConfig[connectorName]);
|
|
186
|
-
}
|
|
187
|
-
this.modalConfig.connectors[connectorName] = connectorConfig;
|
|
240
|
+
this.modalConfig.connectors[connectorName] = _objectSpread(_objectSpread({}, defaultConnectorConfig), ((_this$modalConfig4 = this.modalConfig) === null || _this$modalConfig4 === void 0 || (_this$modalConfig4 = _this$modalConfig4.connectors) === null || _this$modalConfig4 === void 0 ? void 0 : _this$modalConfig4[connectorName]) || {});
|
|
188
241
|
|
|
189
242
|
// check if connector is configured/added by user and exist in connectors map.
|
|
190
243
|
const connector = this.getConnector(connectorName);
|
|
191
|
-
log.debug("connector config", connectorName, (_this$modalConfig$
|
|
244
|
+
log.debug("connector config", connectorName, (_this$modalConfig$con = this.modalConfig.connectors) === null || _this$modalConfig$con === void 0 || (_this$modalConfig$con = _this$modalConfig$con[connectorName]) === null || _this$modalConfig$con === void 0 ? void 0 : _this$modalConfig$con.showOnModal, connector);
|
|
192
245
|
|
|
193
|
-
// if connector is
|
|
194
|
-
|
|
195
|
-
if (!connector
|
|
196
|
-
throw WalletInitializationError.invalidParams(`Connector ${connectorName} is not configured`);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return connectorName;
|
|
246
|
+
// check if connector is configured/added by user and exist in connectors map.
|
|
247
|
+
const connectorConfig = (_this$modalConfig$con2 = this.modalConfig.connectors) === null || _this$modalConfig$con2 === void 0 ? void 0 : _this$modalConfig$con2[connectorName];
|
|
248
|
+
if (!connector) {
|
|
249
|
+
if (connectorConfig.showOnModal) throw WalletInitializationError.invalidParams(`Connector ${connectorName} is not configured`);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// skip connector if it is hidden by user
|
|
254
|
+
if (!connectorConfig.showOnModal) return;
|
|
255
|
+
|
|
256
|
+
// skip external connector if external wallets are disabled or it is disabled or displayInstalledExternalWallets is false
|
|
257
|
+
if (connector.type === CONNECTOR_CATEGORY.EXTERNAL) {
|
|
258
|
+
if (!isExternalWalletEnabled) return;
|
|
259
|
+
if (disabledExternalWallets.has(connectorName)) return;
|
|
260
|
+
if (!isInstalledWalletWalletDisplayed) return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// skip WC connector if external wallets are disabled or hideWalletDiscovery is true
|
|
264
|
+
if (connectorName === WALLET_CONNECTORS.WALLET_CONNECT_V2) {
|
|
265
|
+
var _this$modalConfig5;
|
|
266
|
+
if (!isExternalWalletEnabled) return;
|
|
267
|
+
if ((_this$modalConfig5 = this.modalConfig) !== null && _this$modalConfig5 !== void 0 && _this$modalConfig5.hideWalletDiscovery) return;
|
|
216
268
|
}
|
|
269
|
+
this.modalConfig.connectors[connectorName] = connectorConfig;
|
|
270
|
+
return connectorName;
|
|
217
271
|
});
|
|
218
|
-
const connectorNames = await Promise.all(connectorConfigurationPromises);
|
|
272
|
+
// const connectorNames = await Promise.all(connectorConfigurationPromises);
|
|
219
273
|
return connectorNames.filter(name => name !== undefined);
|
|
220
274
|
}
|
|
221
|
-
async checkConnectorAvailability(connectorNames
|
|
275
|
+
async checkConnectorAvailability(connectorNames) {
|
|
222
276
|
// currently all default in app and external wallets can be hidden or shown based on config.
|
|
223
277
|
// check if in app connectors are available
|
|
224
278
|
const hasInAppConnectors = this.connectors.some(connector => {
|
|
225
|
-
var _this$modalConfig$
|
|
279
|
+
var _this$modalConfig$con3, _this$modalConfig$con4;
|
|
226
280
|
if (connector.type !== CONNECTOR_CATEGORY.IN_APP) return false;
|
|
227
|
-
if (((_this$modalConfig$
|
|
228
|
-
if (!((_this$modalConfig$
|
|
229
|
-
|
|
230
|
-
if (Object.values(mergedLoginMethods).some(method => method.showOnModal)) return true;
|
|
281
|
+
if (((_this$modalConfig$con3 = this.modalConfig.connectors) === null || _this$modalConfig$con3 === void 0 || (_this$modalConfig$con3 = _this$modalConfig$con3[connector.name]) === null || _this$modalConfig$con3 === void 0 ? void 0 : _this$modalConfig$con3.showOnModal) !== true) return false;
|
|
282
|
+
if (!((_this$modalConfig$con4 = this.modalConfig.connectors) !== null && _this$modalConfig$con4 !== void 0 && (_this$modalConfig$con4 = _this$modalConfig$con4[connector.name]) !== null && _this$modalConfig$con4 !== void 0 && _this$modalConfig$con4.loginMethods)) return true;
|
|
283
|
+
if (Object.values(this.modalConfig.connectors[connector.name].loginMethods).some(method => method.showOnModal)) return true;
|
|
231
284
|
return false;
|
|
232
285
|
});
|
|
233
286
|
log.debug(hasInAppConnectors, this.connectors, connectorNames, "hasInAppWallets");
|
|
234
287
|
|
|
235
288
|
// check if external connectors are available
|
|
236
289
|
const hasExternalConnectors = connectorNames.some(connectorName => {
|
|
237
|
-
var _this$getConnector, _this$modalConfig$
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return ((_this$getConnector = this.getConnector(connectorName)) === null || _this$getConnector === void 0 ? void 0 : _this$getConnector.type) === CONNECTOR_CATEGORY.EXTERNAL && ((_this$modalConfig$con10 = this.modalConfig.connectors) === null || _this$modalConfig$con10 === void 0 ? void 0 : _this$modalConfig$con10[connectorName].showOnModal);
|
|
290
|
+
var _this$getConnector, _this$modalConfig$con5;
|
|
291
|
+
if (connectorName === WALLET_CONNECTORS.WALLET_CONNECT_V2) return true;
|
|
292
|
+
return ((_this$getConnector = this.getConnector(connectorName)) === null || _this$getConnector === void 0 ? void 0 : _this$getConnector.type) === CONNECTOR_CATEGORY.EXTERNAL && ((_this$modalConfig$con5 = this.modalConfig.connectors) === null || _this$modalConfig$con5 === void 0 ? void 0 : _this$modalConfig$con5[connectorName].showOnModal);
|
|
241
293
|
});
|
|
242
294
|
return {
|
|
243
295
|
hasInAppConnectors,
|
|
@@ -253,7 +305,7 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
253
305
|
if (connector.status !== CONNECTOR_STATUS.NOT_READY) return;
|
|
254
306
|
|
|
255
307
|
// only initialize a external connectors here if it is a cached connector.
|
|
256
|
-
if (this.cachedConnector !== connectorName && connector.type === CONNECTOR_CATEGORY.EXTERNAL) return;
|
|
308
|
+
if (this.cachedConnector !== connectorName && connectorName !== WALLET_CONNECTORS.METAMASK && connector.type === CONNECTOR_CATEGORY.EXTERNAL) return;
|
|
257
309
|
|
|
258
310
|
// in-app wallets or cached wallet (being connected or already connected) are initialized first.
|
|
259
311
|
// if connector is configured then only initialize in app or cached connector.
|
|
@@ -268,9 +320,9 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
268
320
|
// note: not adding cachedWallet to modal if it is external wallet.
|
|
269
321
|
// adding it later if no in-app wallets are available.
|
|
270
322
|
if (connector.type === CONNECTOR_CATEGORY.IN_APP) {
|
|
271
|
-
var
|
|
323
|
+
var _this$modalConfig$con6, _this$options$uiConfi, _this$options$uiConfi2, _this$options$uiConfi3;
|
|
272
324
|
log.info("connectorInitResults", connectorName);
|
|
273
|
-
const loginMethods =
|
|
325
|
+
const loginMethods = ((_this$modalConfig$con6 = this.modalConfig.connectors[connectorName]) === null || _this$modalConfig$con6 === void 0 ? void 0 : _this$modalConfig$con6.loginMethods) || {};
|
|
274
326
|
this.loginModal.addSocialLogins(connectorName, loginMethods, ((_this$options$uiConfi = this.options.uiConfig) === null || _this$options$uiConfi === void 0 ? void 0 : _this$options$uiConfi.loginMethodsOrder) || AUTH_PROVIDERS, _objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
|
|
275
327
|
loginGridCol: ((_this$options$uiConfi2 = this.options.uiConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.loginGridCol) || 3,
|
|
276
328
|
primaryButton: ((_this$options$uiConfi3 = this.options.uiConfig) === null || _this$options$uiConfi3 === void 0 ? void 0 : _this$options$uiConfi3.primaryButton) || "socialLogin"
|
|
@@ -325,7 +377,14 @@ class Web3Auth extends Web3AuthNoModal {
|
|
|
325
377
|
});
|
|
326
378
|
}
|
|
327
379
|
subscribeToLoginModalEvents() {
|
|
328
|
-
this.loginModal.on(LOGIN_MODAL_EVENTS.
|
|
380
|
+
this.loginModal.on(LOGIN_MODAL_EVENTS.EXTERNAL_WALLET_LOGIN, async params => {
|
|
381
|
+
try {
|
|
382
|
+
await this.connectTo(params.connector);
|
|
383
|
+
} catch (error) {
|
|
384
|
+
log.error(`Error while connecting to connector: ${params.connector}`, error);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
this.loginModal.on(LOGIN_MODAL_EVENTS.SOCIAL_LOGIN, async params => {
|
|
329
388
|
try {
|
|
330
389
|
await this.connectTo(params.connector, params.loginParams);
|
|
331
390
|
} catch (error) {
|
|
@@ -85,18 +85,7 @@ function Web3AuthInnerProvider(params) {
|
|
|
85
85
|
try {
|
|
86
86
|
setInitError(null);
|
|
87
87
|
setIsInitializing(true);
|
|
88
|
-
|
|
89
|
-
modalConfig,
|
|
90
|
-
hideWalletDiscovery
|
|
91
|
-
} = config;
|
|
92
|
-
if (modalConfig) {
|
|
93
|
-
await web3Auth.initModal({
|
|
94
|
-
modalConfig,
|
|
95
|
-
hideWalletDiscovery
|
|
96
|
-
});
|
|
97
|
-
} else {
|
|
98
|
-
await web3Auth.initModal();
|
|
99
|
-
}
|
|
88
|
+
await web3Auth.initModal();
|
|
100
89
|
} catch (error) {
|
|
101
90
|
setInitError(error);
|
|
102
91
|
} finally {
|
package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletChainNamespace.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import i18nInstance from '../../localeImport.js';
|
|
3
|
+
import Button from '../Button/Button.js';
|
|
4
|
+
import Image from '../Image.js';
|
|
5
|
+
import ExternalWalletHeader from './ExternalWalletHeader.js';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
function ExternalWalletChainNamespace(props) {
|
|
9
|
+
const {
|
|
10
|
+
button,
|
|
11
|
+
goBack,
|
|
12
|
+
closeModal,
|
|
13
|
+
handleExternalWalletClick
|
|
14
|
+
} = props;
|
|
15
|
+
const [t] = useTranslation(undefined, {
|
|
16
|
+
i18n: i18nInstance
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// chainNames should be available when selecting a chain namespace
|
|
20
|
+
const chainNamespaces = button.chainNamespaces.map(chainNamespace => {
|
|
21
|
+
const imageId = chainNamespace === "eip155" ? "evm" : chainNamespace;
|
|
22
|
+
const displayName = chainNamespace === "eip155" ? "EVM" : chainNamespace;
|
|
23
|
+
return {
|
|
24
|
+
chainNamespace,
|
|
25
|
+
displayName,
|
|
26
|
+
imageId: `chain-${imageId}`
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
return /*#__PURE__*/jsxs("div", {
|
|
30
|
+
children: [/*#__PURE__*/jsx(ExternalWalletHeader, {
|
|
31
|
+
title: `${t("modal.external.select-chain")}`,
|
|
32
|
+
goBack: goBack,
|
|
33
|
+
closeModal: closeModal
|
|
34
|
+
}), /*#__PURE__*/jsx("div", {
|
|
35
|
+
className: "w3a--flex w3a--justify-center w3a--my-6",
|
|
36
|
+
children: /*#__PURE__*/jsx(Image, {
|
|
37
|
+
imageId: `login-${button.name}`,
|
|
38
|
+
hoverImageId: `login-${button.name}`,
|
|
39
|
+
fallbackImageId: "wallet",
|
|
40
|
+
height: "100",
|
|
41
|
+
width: "100",
|
|
42
|
+
isButton: true,
|
|
43
|
+
extension: button.imgExtension
|
|
44
|
+
})
|
|
45
|
+
}), /*#__PURE__*/jsx("p", {
|
|
46
|
+
className: "w3a--text-center w3a--text-sm w3a--text-app-gray-500 w3a--my-6",
|
|
47
|
+
children: t("modal.external.select-chain-description", {
|
|
48
|
+
wallet: button.displayName
|
|
49
|
+
})
|
|
50
|
+
}), /*#__PURE__*/jsx("ul", {
|
|
51
|
+
className: "w3a--flex w3a--flex-col w3a--gap-3",
|
|
52
|
+
children: chainNamespaces.map(({
|
|
53
|
+
chainNamespace,
|
|
54
|
+
displayName,
|
|
55
|
+
imageId
|
|
56
|
+
}) => /*#__PURE__*/jsx("li", {
|
|
57
|
+
children: /*#__PURE__*/jsxs(Button, {
|
|
58
|
+
variant: "tertiary",
|
|
59
|
+
type: "button",
|
|
60
|
+
onClick: () => handleExternalWalletClick({
|
|
61
|
+
connector: button.name,
|
|
62
|
+
chainNamespace
|
|
63
|
+
}),
|
|
64
|
+
className: "w3a--w-full w3a--size-xl !w3a--justify-between w3a--items-center wallet-btn",
|
|
65
|
+
title: displayName,
|
|
66
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
67
|
+
className: "w3a--flex w3a--items-center",
|
|
68
|
+
children: [/*#__PURE__*/jsx(Image, {
|
|
69
|
+
imageId: imageId,
|
|
70
|
+
hoverImageId: imageId,
|
|
71
|
+
fallbackImageId: "wallet",
|
|
72
|
+
height: "24",
|
|
73
|
+
width: "24",
|
|
74
|
+
isButton: true,
|
|
75
|
+
extension: "svg"
|
|
76
|
+
}), /*#__PURE__*/jsx("p", {
|
|
77
|
+
className: "w3a--ml-2 w3a--text-left w3a--text-sm first-letter:w3a--capitalize",
|
|
78
|
+
children: displayName
|
|
79
|
+
})]
|
|
80
|
+
}), /*#__PURE__*/jsx("span", {
|
|
81
|
+
className: "w3a--inline-flex w3a--items-center w3a--rounded-lg w3a--px-2 w3a--py-1 w3a--text-xs w3a--font-medium w3a--bg-app-primary-100 w3a--text-app-primary-800",
|
|
82
|
+
children: t("modal.external.installed")
|
|
83
|
+
})]
|
|
84
|
+
})
|
|
85
|
+
}, chainNamespace))
|
|
86
|
+
})]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { ExternalWalletChainNamespace as default };
|
package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletDetails.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ExternalWalletChainNamespace from './ExternalWalletChainNamespace.js';
|
|
1
2
|
import ExternalWalletConnect from './ExternalWalletConnect.js';
|
|
2
3
|
import ExternalWalletInstall from './ExternalWalletInstall.js';
|
|
3
4
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -7,8 +8,19 @@ function ExternalWalletDetail(props) {
|
|
|
7
8
|
connectButton,
|
|
8
9
|
walletConnectUri,
|
|
9
10
|
goBack,
|
|
10
|
-
closeModal
|
|
11
|
+
closeModal,
|
|
12
|
+
handleExternalWalletClick
|
|
11
13
|
} = props;
|
|
14
|
+
|
|
15
|
+
// Select chain namespace for injected wallets
|
|
16
|
+
if (connectButton.hasInjectedWallet) {
|
|
17
|
+
return /*#__PURE__*/jsx(ExternalWalletChainNamespace, {
|
|
18
|
+
handleExternalWalletClick: handleExternalWalletClick,
|
|
19
|
+
button: connectButton,
|
|
20
|
+
goBack: goBack,
|
|
21
|
+
closeModal: closeModal
|
|
22
|
+
});
|
|
23
|
+
}
|
|
12
24
|
return /*#__PURE__*/jsx("div", {
|
|
13
25
|
children: connectButton.hasWalletConnect ?
|
|
14
26
|
/*#__PURE__*/
|