@web3auth/no-modal 10.0.0-beta.8 → 10.0.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/base/analytics.js +121 -0
- package/dist/lib.cjs/base/connector/constants.js +2 -1
- package/dist/lib.cjs/base/constants.js +13 -0
- package/dist/lib.cjs/base/cookie.js +38 -0
- package/dist/lib.cjs/base/deserialize.js +13 -0
- package/dist/lib.cjs/base/errors/index.js +2 -2
- package/dist/lib.cjs/base/utils.js +112 -9
- package/dist/lib.cjs/base/wallet/index.js +3 -3
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +40 -63
- package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +5 -2
- package/dist/lib.cjs/connectors/base-solana-connector/baseSolanaConnector.js +5 -2
- package/dist/lib.cjs/connectors/coinbase-connector/coinbaseConnector.js +11 -4
- package/dist/lib.cjs/connectors/injected-evm-connector/injectedEvmConnector.js +10 -4
- package/dist/lib.cjs/connectors/injected-solana-connector/walletStandardConnector.js +10 -5
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +19 -8
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +2 -1
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/config.js +11 -9
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/index.js +0 -1
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +9 -4
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Utils.js +6 -5
- package/dist/lib.cjs/index.js +18 -1
- package/dist/lib.cjs/noModal.js +367 -101
- package/dist/lib.cjs/plugins/nft-checkout-plugin/plugin.js +3 -1
- package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +3 -1
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +10 -5
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +3 -2
- package/dist/lib.cjs/providers/base-provider/baseProvider.js +2 -1
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.js +2 -1
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.js +2 -1
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.js +2 -1
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.js +4 -2
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/walletStandardProvider.js +4 -2
- package/dist/lib.cjs/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.js +3 -1
- package/dist/lib.cjs/react/context/WalletServicesInnerContext.js +4 -2
- package/dist/lib.cjs/react/context/Web3AuthInnerContext.js +21 -16
- package/dist/lib.cjs/react/hooks/useCheckout.js +4 -2
- package/dist/lib.cjs/react/hooks/useIdentityToken.js +3 -3
- package/dist/lib.cjs/react/hooks/useSwap.js +4 -2
- package/dist/lib.cjs/react/hooks/useWalletConnectScanner.js +4 -2
- package/dist/lib.cjs/react/hooks/useWalletUI.js +4 -2
- package/dist/lib.cjs/react/hooks/useWeb3AuthInner.js +4 -2
- package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +8 -3
- package/dist/lib.cjs/react/wagmi/constants.js +16 -0
- package/dist/lib.cjs/react/wagmi/provider.js +16 -12
- package/dist/lib.cjs/types/base/analytics.d.ts +42 -0
- package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +2 -2
- package/dist/lib.cjs/types/base/connector/constants.d.ts +1 -0
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +3 -2
- package/dist/lib.cjs/types/base/constants.d.ts +6 -0
- package/dist/lib.cjs/types/base/cookie.d.ts +10 -0
- package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +31 -11
- package/dist/lib.cjs/types/base/deserialize.d.ts +3 -0
- package/dist/lib.cjs/types/base/errors/index.d.ts +1 -1
- package/dist/lib.cjs/types/base/index.d.ts +2 -0
- package/dist/lib.cjs/types/base/interfaces.d.ts +9 -1
- package/dist/lib.cjs/types/base/utils.d.ts +50 -3
- package/dist/lib.cjs/types/base/wallet/index.d.ts +4 -2
- package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +1 -1
- package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +1 -1
- package/dist/lib.cjs/types/connectors/base-evm-connector/baseEvmConnector.d.ts +2 -2
- package/dist/lib.cjs/types/connectors/base-solana-connector/baseSolanaConnector.d.ts +2 -2
- package/dist/lib.cjs/types/connectors/wallet-connect-v2-connector/config.d.ts +0 -1
- package/dist/lib.cjs/types/noModal.d.ts +18 -9
- package/dist/lib.cjs/types/providers/account-abstraction-provider/providers/AccountAbstractionProvider.d.ts +4 -1
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/converter.d.ts +0 -1
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.d.ts +0 -1
- package/dist/lib.cjs/types/react/hooks/useIdentityToken.d.ts +2 -2
- package/dist/lib.cjs/types/react/interfaces.d.ts +2 -1
- package/dist/lib.cjs/types/react/wagmi/constants.d.ts +43 -0
- package/dist/lib.cjs/types/react/wagmi/provider.d.ts +1 -2
- package/dist/lib.cjs/types/vue/composables/useIdentityToken.d.ts +1 -1
- package/dist/lib.cjs/types/vue/wagmi/constants.d.ts +43 -0
- package/dist/lib.cjs/types/vue/wagmi/provider.d.ts +1 -0
- package/dist/lib.cjs/vue/WalletServicesInnerProvider.js +4 -2
- package/dist/lib.cjs/vue/Web3AuthProvider.js +7 -1
- package/dist/lib.cjs/vue/composables/useCheckout.js +4 -2
- package/dist/lib.cjs/vue/composables/useEnableMFA.js +4 -2
- package/dist/lib.cjs/vue/composables/useIdentityToken.js +7 -5
- package/dist/lib.cjs/vue/composables/useManageMFA.js +5 -3
- package/dist/lib.cjs/vue/composables/useSwap.js +4 -2
- package/dist/lib.cjs/vue/composables/useSwitchChain.js +4 -2
- package/dist/lib.cjs/vue/composables/useWalletConnectScanner.js +4 -2
- package/dist/lib.cjs/vue/composables/useWalletUI.js +4 -2
- package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +4 -2
- package/dist/lib.cjs/vue/composables/useWeb3AuthDisconnect.js +4 -2
- package/dist/lib.cjs/vue/composables/useWeb3AuthInner.js +4 -2
- package/dist/lib.cjs/vue/composables/useWeb3AuthUser.js +4 -2
- package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +24 -15
- package/dist/lib.cjs/vue/wagmi/constants.js +16 -0
- package/dist/lib.cjs/vue/wagmi/provider.js +34 -16
- package/dist/lib.esm/base/analytics.js +117 -0
- package/dist/lib.esm/base/connector/constants.js +2 -1
- package/dist/lib.esm/base/constants.js +11 -1
- package/dist/lib.esm/base/cookie.js +34 -0
- package/dist/lib.esm/base/deserialize.js +11 -0
- package/dist/lib.esm/base/errors/index.js +2 -2
- package/dist/lib.esm/base/utils.js +104 -7
- package/dist/lib.esm/base/wallet/index.js +3 -3
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +41 -65
- package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +1 -1
- package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +1 -1
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +9 -3
- package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +7 -3
- package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +7 -4
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +17 -7
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/config.js +8 -7
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/index.js +1 -1
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +8 -4
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Utils.js +1 -1
- package/dist/lib.esm/index.js +5 -3
- package/dist/lib.esm/noModal.js +378 -107
- package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +8 -4
- package/dist/lib.esm/react/context/Web3AuthInnerContext.js +22 -17
- package/dist/lib.esm/react/hooks/useIdentityToken.js +3 -3
- package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +5 -0
- package/dist/lib.esm/react/wagmi/constants.js +14 -0
- package/dist/lib.esm/react/wagmi/provider.js +16 -12
- package/dist/lib.esm/vue/Web3AuthProvider.js +7 -1
- package/dist/lib.esm/vue/composables/useIdentityToken.js +3 -3
- package/dist/lib.esm/vue/composables/useManageMFA.js +1 -1
- package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +21 -13
- package/dist/lib.esm/vue/wagmi/constants.js +14 -0
- package/dist/lib.esm/vue/wagmi/provider.js +35 -15
- package/dist/noModal.umd.min.js +1 -1
- package/dist/noModal.umd.min.js.LICENSE.txt +4 -6
- package/package.json +24 -34
package/dist/lib.cjs/noModal.js
CHANGED
|
@@ -3,47 +3,58 @@
|
|
|
3
3
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
4
4
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
5
5
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
var baseControllers = require('@toruslabs/base-controllers');
|
|
6
7
|
var auth = require('@web3auth/auth');
|
|
7
8
|
var deepmerge = require('deepmerge');
|
|
9
|
+
var analytics = require('./base/analytics.js');
|
|
8
10
|
var IChainInterface = require('./base/chain/IChainInterface.js');
|
|
9
11
|
var index = require('./base/errors/index.js');
|
|
10
12
|
var index$1 = require('./base/wallet/index.js');
|
|
11
13
|
var constants = require('./base/connector/constants.js');
|
|
12
14
|
var utils$1 = require('./base/connector/utils.js');
|
|
13
15
|
var constants$1 = require('./base/constants.js');
|
|
16
|
+
var cookie = require('./base/cookie.js');
|
|
14
17
|
var loglevel = require('./base/loglevel.js');
|
|
15
18
|
require('./base/plugin/errors.js');
|
|
16
19
|
var IPlugin = require('./base/plugin/IPlugin.js');
|
|
17
20
|
var utils = require('./base/utils.js');
|
|
21
|
+
var deserialize = require('./base/deserialize.js');
|
|
18
22
|
var authConnector = require('./connectors/auth-connector/authConnector.js');
|
|
19
23
|
var metamaskConnector = require('./connectors/metamask-connector/metamaskConnector.js');
|
|
20
24
|
var plugin = require('./plugins/wallet-services-plugin/plugin.js');
|
|
21
|
-
var baseControllers = require('@toruslabs/base-controllers');
|
|
22
25
|
require('./providers/base-provider/utils.js');
|
|
23
26
|
var CommonJRPCProvider = require('./providers/base-provider/CommonJRPCProvider.js');
|
|
24
27
|
require('./providers/base-provider/commonPrivateKeyProvider.js');
|
|
25
28
|
|
|
26
29
|
const _excluded = ["walletScope"];
|
|
27
|
-
const CONNECTOR_CACHE_KEY = "Web3Auth-cachedConnector";
|
|
28
|
-
const CURRENT_CHAIN_CACHE_KEY = "Web3Auth-currentChain";
|
|
29
30
|
class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
30
|
-
constructor(options) {
|
|
31
|
+
constructor(options, initialState) {
|
|
31
32
|
super();
|
|
32
33
|
_defineProperty(this, "coreOptions", void 0);
|
|
33
|
-
_defineProperty(this, "connectedConnectorName", null);
|
|
34
34
|
_defineProperty(this, "status", constants.CONNECTOR_STATUS.NOT_READY);
|
|
35
|
-
_defineProperty(this, "cachedConnector", null);
|
|
36
35
|
_defineProperty(this, "aaProvider", null);
|
|
37
|
-
_defineProperty(this, "currentChainId", void 0);
|
|
38
36
|
_defineProperty(this, "connectors", []);
|
|
39
37
|
_defineProperty(this, "commonJRPCProvider", null);
|
|
38
|
+
_defineProperty(this, "analytics", void 0);
|
|
40
39
|
_defineProperty(this, "plugins", {});
|
|
41
|
-
_defineProperty(this, "storage",
|
|
40
|
+
_defineProperty(this, "storage", void 0);
|
|
41
|
+
_defineProperty(this, "state", {
|
|
42
|
+
connectedConnectorName: null,
|
|
43
|
+
cachedConnector: null,
|
|
44
|
+
currentChainId: null,
|
|
45
|
+
idToken: null
|
|
46
|
+
});
|
|
47
|
+
_defineProperty(this, "loginMode", constants$1.LOGIN_MODE.NO_MODAL);
|
|
42
48
|
if (!options.clientId) throw index.WalletInitializationError.invalidParams("Please provide a valid clientId in constructor");
|
|
43
49
|
if (options.enableLogging) loglevel.log.enableAll();else loglevel.log.setLevel("error");
|
|
44
|
-
if (options.storageType
|
|
50
|
+
if (!options.storageType) options.storageType = "local";
|
|
45
51
|
this.coreOptions = options;
|
|
46
|
-
this.
|
|
52
|
+
this.storage = this.getStorageMethod();
|
|
53
|
+
this.analytics = new analytics.Analytics();
|
|
54
|
+
this.loadState(initialState);
|
|
55
|
+
if (this.state.idToken && this.coreOptions.ssr) {
|
|
56
|
+
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
59
|
get currentChain() {
|
|
49
60
|
var _this$coreOptions$cha;
|
|
@@ -58,6 +69,15 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
58
69
|
}
|
|
59
70
|
return null;
|
|
60
71
|
}
|
|
72
|
+
get connectedConnectorName() {
|
|
73
|
+
return this.state.connectedConnectorName;
|
|
74
|
+
}
|
|
75
|
+
get cachedConnector() {
|
|
76
|
+
return this.state.cachedConnector;
|
|
77
|
+
}
|
|
78
|
+
get currentChainId() {
|
|
79
|
+
return this.state.currentChainId || this.coreOptions.defaultChainId || this.coreOptions.chains[0].chainId;
|
|
80
|
+
}
|
|
61
81
|
get connectedConnector() {
|
|
62
82
|
var _this$currentChain;
|
|
63
83
|
return this.getConnector(this.connectedConnectorName, (_this$currentChain = this.currentChain) === null || _this$currentChain === void 0 ? void 0 : _this$currentChain.chainNamespace);
|
|
@@ -69,51 +89,88 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
69
89
|
throw new Error("Not implemented");
|
|
70
90
|
}
|
|
71
91
|
async init(options) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
// init analytics
|
|
93
|
+
const startTime = Date.now();
|
|
94
|
+
this.analytics.init();
|
|
95
|
+
this.analytics.identify(this.coreOptions.clientId, {
|
|
96
|
+
web3auth_client_id: this.coreOptions.clientId,
|
|
97
|
+
web3auth_network: this.coreOptions.web3AuthNetwork
|
|
98
|
+
});
|
|
99
|
+
this.analytics.setGlobalProperties({
|
|
100
|
+
dapp_url: window.location.origin,
|
|
101
|
+
sdk_name: analytics.ANALYTICS_SDK_TYPE.WEB_NO_MODAL,
|
|
102
|
+
sdk_version: utils.sdkVersion
|
|
103
|
+
});
|
|
104
|
+
let trackData = {};
|
|
77
105
|
try {
|
|
78
|
-
var _this$coreOptions$
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
106
|
+
var _authConnector$authIn, _this$coreOptions$uiC;
|
|
107
|
+
const {
|
|
108
|
+
signal
|
|
109
|
+
} = options || {};
|
|
110
|
+
// get project config
|
|
111
|
+
let projectConfig;
|
|
112
|
+
try {
|
|
113
|
+
var _this$coreOptions$acc;
|
|
114
|
+
projectConfig = await utils.fetchProjectConfig({
|
|
115
|
+
clientId: this.coreOptions.clientId,
|
|
116
|
+
web3AuthNetwork: this.coreOptions.web3AuthNetwork,
|
|
117
|
+
aaProvider: (_this$coreOptions$acc = this.coreOptions.accountAbstractionConfig) === null || _this$coreOptions$acc === void 0 ? void 0 : _this$coreOptions$acc.smartAccountType,
|
|
118
|
+
authBuildEnv: this.coreOptions.authBuildEnv
|
|
119
|
+
});
|
|
120
|
+
} catch (e) {
|
|
121
|
+
const error = await auth.serializeError(e);
|
|
122
|
+
loglevel.log.error("Failed to fetch project configurations", error);
|
|
123
|
+
throw index.WalletInitializationError.notReady("failed to fetch project configurations", error);
|
|
124
|
+
}
|
|
125
|
+
// init config
|
|
126
|
+
this.initAccountAbstractionConfig(projectConfig);
|
|
127
|
+
this.initChainsConfig(projectConfig);
|
|
128
|
+
this.initCachedConnectorAndChainId();
|
|
129
|
+
this.initUIConfig(projectConfig);
|
|
130
|
+
this.initWalletServicesConfig(projectConfig);
|
|
131
|
+
trackData = this.getInitializationTrackData();
|
|
132
|
+
// setup common JRPC provider
|
|
133
|
+
await utils.withAbort(() => this.setupCommonJRPCProvider(), signal);
|
|
134
|
+
// initialize connectors
|
|
135
|
+
this.on(constants.CONNECTOR_EVENTS.CONNECTORS_UPDATED, async ({
|
|
136
|
+
connectors: newConnectors
|
|
137
|
+
}) => {
|
|
138
|
+
const onAbortHandler = () => {
|
|
139
|
+
var _this$connectors;
|
|
140
|
+
if (((_this$connectors = this.connectors) === null || _this$connectors === void 0 ? void 0 : _this$connectors.length) > 0) {
|
|
141
|
+
this.cleanup();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
await utils.withAbort(() => Promise.all(newConnectors.map(this.setupConnector.bind(this))), signal, onAbortHandler);
|
|
145
|
+
// emit connector ready event
|
|
146
|
+
if (this.status === constants.CONNECTOR_STATUS.NOT_READY) {
|
|
147
|
+
this.status = constants.CONNECTOR_STATUS.READY;
|
|
148
|
+
this.emit(constants.CONNECTOR_EVENTS.READY);
|
|
149
|
+
}
|
|
84
150
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
151
|
+
await utils.withAbort(() => this.loadConnectors({
|
|
152
|
+
projectConfig
|
|
153
|
+
}), signal);
|
|
154
|
+
await utils.withAbort(() => this.initPlugins(), signal);
|
|
155
|
+
// track completion event
|
|
156
|
+
const authConnector = this.getConnector(index$1.WALLET_CONNECTORS.AUTH);
|
|
157
|
+
trackData = _objectSpread(_objectSpread({}, trackData), {}, {
|
|
158
|
+
connectors: this.connectors.map(connector => connector.name),
|
|
159
|
+
plugins: Object.keys(this.plugins),
|
|
160
|
+
auth_ux_mode: (authConnector === null || authConnector === void 0 || (_authConnector$authIn = authConnector.authInstance) === null || _authConnector$authIn === void 0 || (_authConnector$authIn = _authConnector$authIn.options) === null || _authConnector$authIn === void 0 ? void 0 : _authConnector$authIn.uxMode) || ((_this$coreOptions$uiC = this.coreOptions.uiConfig) === null || _this$coreOptions$uiC === void 0 ? void 0 : _this$coreOptions$uiC.uxMode)
|
|
161
|
+
});
|
|
162
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.SDK_INITIALIZATION_COMPLETED, _objectSpread(_objectSpread({}, trackData), {}, {
|
|
163
|
+
duration: Date.now() - startTime
|
|
164
|
+
}));
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error instanceof DOMException && error.name === "AbortError") return;
|
|
167
|
+
// track failure event
|
|
168
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.SDK_INITIALIZATION_FAILED, _objectSpread(_objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)), {}, {
|
|
169
|
+
duration: Date.now() - startTime
|
|
170
|
+
}));
|
|
171
|
+
loglevel.log.error("Failed to initialize modal", error);
|
|
172
|
+
throw error;
|
|
89
173
|
}
|
|
90
|
-
// init config
|
|
91
|
-
this.initAccountAbstractionConfig(projectConfig);
|
|
92
|
-
this.initChainsConfig(projectConfig);
|
|
93
|
-
this.initCachedConnectorAndChainId();
|
|
94
|
-
// setup common JRPC provider
|
|
95
|
-
await utils.withAbort(() => this.setupCommonJRPCProvider(), signal);
|
|
96
|
-
// initialize connectors
|
|
97
|
-
this.on(constants.CONNECTOR_EVENTS.CONNECTORS_UPDATED, async ({
|
|
98
|
-
connectors: newConnectors
|
|
99
|
-
}) => {
|
|
100
|
-
const onAbortHandler = () => {
|
|
101
|
-
var _this$connectors;
|
|
102
|
-
if (((_this$connectors = this.connectors) === null || _this$connectors === void 0 ? void 0 : _this$connectors.length) > 0) {
|
|
103
|
-
this.cleanup();
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
await utils.withAbort(() => Promise.all(newConnectors.map(this.setupConnector.bind(this))), signal, onAbortHandler);
|
|
107
|
-
// emit connector ready event
|
|
108
|
-
if (this.status === constants.CONNECTOR_STATUS.NOT_READY) {
|
|
109
|
-
this.status = constants.CONNECTOR_STATUS.READY;
|
|
110
|
-
this.emit(constants.CONNECTOR_EVENTS.READY);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
await utils.withAbort(() => this.loadConnectors({
|
|
114
|
-
projectConfig
|
|
115
|
-
}), signal);
|
|
116
|
-
await utils.withAbort(() => this.initPlugins(), signal);
|
|
117
174
|
}
|
|
118
175
|
// we need to take into account the chainNamespace as for external connectors, same connector name can be used for multiple chain namespaces
|
|
119
176
|
getConnector(connectorName, chainNamespace) {
|
|
@@ -127,10 +184,12 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
127
184
|
}) || null;
|
|
128
185
|
}
|
|
129
186
|
clearCache() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
187
|
+
this.setState({
|
|
188
|
+
connectedConnectorName: null,
|
|
189
|
+
cachedConnector: null,
|
|
190
|
+
currentChainId: null,
|
|
191
|
+
idToken: null
|
|
192
|
+
});
|
|
134
193
|
}
|
|
135
194
|
async cleanup() {
|
|
136
195
|
for (const connector of this.connectors) {
|
|
@@ -158,20 +217,62 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
158
217
|
* Connect to a specific wallet connector
|
|
159
218
|
* @param connectorName - Key of the wallet connector to use.
|
|
160
219
|
*/
|
|
161
|
-
async connectTo(connectorName, loginParams) {
|
|
220
|
+
async connectTo(connectorName, loginParams, loginMode) {
|
|
221
|
+
this.loginMode = loginMode || "no-modal";
|
|
162
222
|
const connector = this.getConnector(connectorName, loginParams === null || loginParams === void 0 ? void 0 : loginParams.chainNamespace);
|
|
163
223
|
if (!connector || !this.commonJRPCProvider) throw index.WalletInitializationError.notFound(`Please add wallet connector for ${connectorName} wallet, before connecting`);
|
|
224
|
+
const initialChain = this.getInitialChainIdForConnector(connector);
|
|
225
|
+
const finalLoginParams = _objectSpread(_objectSpread({}, loginParams), {}, {
|
|
226
|
+
chainId: initialChain.chainId
|
|
227
|
+
});
|
|
228
|
+
// track connection started event
|
|
229
|
+
const startTime = Date.now();
|
|
230
|
+
let eventData;
|
|
231
|
+
if (connectorName === index$1.WALLET_CONNECTORS.AUTH) {
|
|
232
|
+
var _connector$authInstan;
|
|
233
|
+
const authLoginParams = loginParams;
|
|
234
|
+
eventData = {
|
|
235
|
+
connector: connectorName,
|
|
236
|
+
connector_type: connector.type,
|
|
237
|
+
chain_id: utils.getCaipChainId(initialChain),
|
|
238
|
+
chain_namespace: initialChain.chainNamespace,
|
|
239
|
+
auth_connection: authLoginParams.authConnection,
|
|
240
|
+
auth_connection_id: authLoginParams.authConnectionId,
|
|
241
|
+
group_auth_connection_id: authLoginParams.groupedAuthConnectionId,
|
|
242
|
+
mfa_level: authLoginParams.mfaLevel,
|
|
243
|
+
wallet_key_enabled: authLoginParams.getWalletKey,
|
|
244
|
+
extra_login_options_enabled: Boolean(authLoginParams.extraLoginOptions),
|
|
245
|
+
dapp_share_enabled: Boolean(authLoginParams.dappShare),
|
|
246
|
+
curve: authLoginParams.curve,
|
|
247
|
+
auth_dapp_url: authLoginParams.dappUrl,
|
|
248
|
+
is_sfa: Boolean(authLoginParams.idToken),
|
|
249
|
+
auth_ux_mode: (_connector$authInstan = connector.authInstance) === null || _connector$authInstan === void 0 || (_connector$authInstan = _connector$authInstan.options) === null || _connector$authInstan === void 0 ? void 0 : _connector$authInstan.uxMode
|
|
250
|
+
};
|
|
251
|
+
} else {
|
|
252
|
+
eventData = {
|
|
253
|
+
connector: connectorName,
|
|
254
|
+
connector_type: connector.type,
|
|
255
|
+
is_injected: connector.isInjected,
|
|
256
|
+
chain_id: utils.getCaipChainId(initialChain),
|
|
257
|
+
chain_namespace: initialChain.chainNamespace
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.CONNECTION_STARTED, eventData);
|
|
164
261
|
return new Promise((resolve, reject) => {
|
|
165
|
-
this.once(constants.CONNECTOR_EVENTS.CONNECTED, _ => {
|
|
262
|
+
this.once(constants.CONNECTOR_EVENTS.CONNECTED, async _ => {
|
|
263
|
+
// track connection completed event
|
|
264
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.CONNECTION_COMPLETED, _objectSpread(_objectSpread({}, eventData), {}, {
|
|
265
|
+
duration: Date.now() - startTime
|
|
266
|
+
}));
|
|
166
267
|
resolve(this.provider);
|
|
167
268
|
});
|
|
168
|
-
this.once(constants.CONNECTOR_EVENTS.ERRORED, err => {
|
|
269
|
+
this.once(constants.CONNECTOR_EVENTS.ERRORED, async err => {
|
|
270
|
+
// track connection failed event
|
|
271
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.CONNECTION_FAILED, _objectSpread(_objectSpread(_objectSpread({}, eventData), utils.getErrorAnalyticsProperties(err)), {}, {
|
|
272
|
+
duration: Date.now() - startTime
|
|
273
|
+
}));
|
|
169
274
|
reject(err);
|
|
170
275
|
});
|
|
171
|
-
const initialChain = this.getInitialChainIdForConnector(connector);
|
|
172
|
-
const finalLoginParams = _objectSpread(_objectSpread({}, loginParams), {}, {
|
|
173
|
-
chainId: initialChain.chainId
|
|
174
|
-
});
|
|
175
276
|
connector.connect(finalLoginParams);
|
|
176
277
|
this.setCurrentChain(initialChain.chainId);
|
|
177
278
|
});
|
|
@@ -189,22 +290,60 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
189
290
|
return this.connectedConnector.getUserInfo();
|
|
190
291
|
}
|
|
191
292
|
async enableMFA(loginParams) {
|
|
293
|
+
var _authConnector$authIn2;
|
|
192
294
|
if (this.status !== constants.CONNECTOR_STATUS.CONNECTED || !this.connectedConnector) throw index.WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
193
295
|
if (this.connectedConnector.name !== index$1.WALLET_CONNECTORS.AUTH) throw index.WalletLoginError.unsupportedOperation(`EnableMFA is not supported for this connector.`);
|
|
194
|
-
|
|
296
|
+
const authConnector = this.connectedConnector;
|
|
297
|
+
const trackData = {
|
|
298
|
+
connector: this.connectedConnector.name,
|
|
299
|
+
auth_ux_mode: (_authConnector$authIn2 = authConnector.authInstance) === null || _authConnector$authIn2 === void 0 || (_authConnector$authIn2 = _authConnector$authIn2.options) === null || _authConnector$authIn2 === void 0 ? void 0 : _authConnector$authIn2.uxMode
|
|
300
|
+
};
|
|
301
|
+
try {
|
|
302
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.MFA_ENABLEMENT_STARTED, trackData);
|
|
303
|
+
await this.connectedConnector.enableMFA(loginParams);
|
|
304
|
+
} catch (error) {
|
|
305
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.MFA_ENABLEMENT_FAILED, _objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)));
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
195
308
|
}
|
|
196
309
|
async manageMFA(loginParams) {
|
|
310
|
+
var _authConnector$authIn3;
|
|
197
311
|
if (this.status !== constants.CONNECTOR_STATUS.CONNECTED || !this.connectedConnector) throw index.WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
198
312
|
if (this.connectedConnector.name !== index$1.WALLET_CONNECTORS.AUTH) throw index.WalletLoginError.unsupportedOperation(`ManageMFA is not supported for this connector.`);
|
|
199
|
-
|
|
313
|
+
const authConnector = this.connectedConnector;
|
|
314
|
+
const trackData = {
|
|
315
|
+
connector: this.connectedConnector.name,
|
|
316
|
+
auth_ux_mode: (_authConnector$authIn3 = authConnector.authInstance) === null || _authConnector$authIn3 === void 0 || (_authConnector$authIn3 = _authConnector$authIn3.options) === null || _authConnector$authIn3 === void 0 ? void 0 : _authConnector$authIn3.uxMode
|
|
317
|
+
};
|
|
318
|
+
try {
|
|
319
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.MFA_MANAGEMENT_SELECTED, trackData);
|
|
320
|
+
await this.connectedConnector.manageMFA(loginParams);
|
|
321
|
+
} catch (error) {
|
|
322
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.MFA_MANAGEMENT_FAILED, _objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)));
|
|
323
|
+
throw error;
|
|
324
|
+
}
|
|
200
325
|
}
|
|
201
|
-
async
|
|
326
|
+
async getIdentityToken() {
|
|
202
327
|
if (this.status !== constants.CONNECTOR_STATUS.CONNECTED || !this.connectedConnector) throw index.WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
203
|
-
|
|
328
|
+
const trackData = {
|
|
329
|
+
connector: this.connectedConnector.name
|
|
330
|
+
};
|
|
331
|
+
try {
|
|
332
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.IDENTITY_TOKEN_STARTED, trackData);
|
|
333
|
+
const identityToken = await this.connectedConnector.getIdentityToken();
|
|
334
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.IDENTITY_TOKEN_COMPLETED, trackData);
|
|
335
|
+
return identityToken;
|
|
336
|
+
} catch (error) {
|
|
337
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.IDENTITY_TOKEN_FAILED, _objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)));
|
|
338
|
+
throw error;
|
|
339
|
+
}
|
|
204
340
|
}
|
|
205
341
|
getPlugin(name) {
|
|
206
342
|
return this.plugins[name] || null;
|
|
207
343
|
}
|
|
344
|
+
setAnalyticsProperties(properties) {
|
|
345
|
+
this.analytics.setGlobalProperties(properties);
|
|
346
|
+
}
|
|
208
347
|
initChainsConfig(projectConfig) {
|
|
209
348
|
// merge chains from project config with core options, core options chains will take precedence over project config chains
|
|
210
349
|
const chainMap = new Map();
|
|
@@ -301,13 +440,90 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
301
440
|
this.coreOptions.useAAWithExternalWallet = walletScope === constants$1.SMART_ACCOUNT_WALLET_SCOPE.ALL;
|
|
302
441
|
}
|
|
303
442
|
}
|
|
443
|
+
initUIConfig(projectConfig) {
|
|
444
|
+
this.coreOptions.uiConfig = deepmerge.all([{
|
|
445
|
+
mode: "light",
|
|
446
|
+
uxMode: auth.UX_MODE.POPUP
|
|
447
|
+
}, auth.cloneDeep(projectConfig.whitelabel || {}), this.coreOptions.uiConfig || {}]);
|
|
448
|
+
}
|
|
304
449
|
initCachedConnectorAndChainId() {
|
|
305
|
-
this.cachedConnector = utils$1.storageAvailable(this.storage) ? window[this.storage].getItem(CONNECTOR_CACHE_KEY) : null;
|
|
306
450
|
// init chainId using cached chainId if it exists and is valid, otherwise use the defaultChainId or the first chain
|
|
307
|
-
const cachedChainId =
|
|
451
|
+
const cachedChainId = this.state.currentChainId;
|
|
308
452
|
const isCachedChainIdValid = cachedChainId && this.coreOptions.chains.some(chain => chain.chainId === cachedChainId);
|
|
309
453
|
if (this.coreOptions.defaultChainId && !utils.isHexStrict(this.coreOptions.defaultChainId)) throw index.WalletInitializationError.invalidParams("Please provide a valid defaultChainId in constructor");
|
|
310
|
-
|
|
454
|
+
const currentChainId = isCachedChainIdValid ? cachedChainId : this.coreOptions.defaultChainId || this.coreOptions.chains[0].chainId;
|
|
455
|
+
this.setState({
|
|
456
|
+
currentChainId
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
initWalletServicesConfig(projectConfig) {
|
|
460
|
+
var _this$coreOptions$wal, _this$coreOptions$wal2, _this$coreOptions$wal3, _ref2, _this$coreOptions$wal4, _this$coreOptions$wal5;
|
|
461
|
+
const {
|
|
462
|
+
enableKeyExport,
|
|
463
|
+
walletUi
|
|
464
|
+
} = projectConfig;
|
|
465
|
+
const {
|
|
466
|
+
enablePortfolioWidget = false,
|
|
467
|
+
enableTokenDisplay = true,
|
|
468
|
+
enableNftDisplay = true,
|
|
469
|
+
enableWalletConnect = true,
|
|
470
|
+
enableBuyButton = true,
|
|
471
|
+
enableSendButton = true,
|
|
472
|
+
enableSwapButton = true,
|
|
473
|
+
enableReceiveButton = true,
|
|
474
|
+
enableShowAllTokensButton = true,
|
|
475
|
+
enableConfirmationModal = false,
|
|
476
|
+
portfolioWidgetPosition = baseControllers.BUTTON_POSITION.BOTTOM_LEFT,
|
|
477
|
+
defaultPortfolio = "token"
|
|
478
|
+
} = walletUi || {};
|
|
479
|
+
const projectConfigWhiteLabel = {
|
|
480
|
+
showWidgetButton: enablePortfolioWidget,
|
|
481
|
+
hideNftDisplay: !enableNftDisplay,
|
|
482
|
+
hideTokenDisplay: !enableTokenDisplay,
|
|
483
|
+
hideTransfers: !enableSendButton,
|
|
484
|
+
hideTopup: !enableBuyButton,
|
|
485
|
+
hideReceive: !enableReceiveButton,
|
|
486
|
+
hideSwap: !enableSwapButton,
|
|
487
|
+
hideShowAllTokens: !enableShowAllTokensButton,
|
|
488
|
+
hideWalletConnect: !enableWalletConnect,
|
|
489
|
+
buttonPosition: portfolioWidgetPosition,
|
|
490
|
+
defaultPortfolio
|
|
491
|
+
};
|
|
492
|
+
const whiteLabel = deepmerge.all([projectConfigWhiteLabel, ((_this$coreOptions$wal = this.coreOptions.walletServicesConfig) === null || _this$coreOptions$wal === void 0 ? void 0 : _this$coreOptions$wal.whiteLabel) || {}]);
|
|
493
|
+
const confirmationStrategy = (_this$coreOptions$wal2 = (_this$coreOptions$wal3 = this.coreOptions.walletServicesConfig) === null || _this$coreOptions$wal3 === void 0 ? void 0 : _this$coreOptions$wal3.confirmationStrategy) !== null && _this$coreOptions$wal2 !== void 0 ? _this$coreOptions$wal2 : enableConfirmationModal ? baseControllers.CONFIRMATION_STRATEGY.MODAL : baseControllers.CONFIRMATION_STRATEGY.AUTO_APPROVE;
|
|
494
|
+
const isKeyExportEnabled = (_ref2 = (_this$coreOptions$wal4 = (_this$coreOptions$wal5 = this.coreOptions.walletServicesConfig) === null || _this$coreOptions$wal5 === void 0 ? void 0 : _this$coreOptions$wal5.enableKeyExport) !== null && _this$coreOptions$wal4 !== void 0 ? _this$coreOptions$wal4 : enableKeyExport) !== null && _ref2 !== void 0 ? _ref2 : true;
|
|
495
|
+
this.coreOptions.walletServicesConfig = _objectSpread(_objectSpread({}, this.coreOptions.walletServicesConfig), {}, {
|
|
496
|
+
confirmationStrategy,
|
|
497
|
+
whiteLabel,
|
|
498
|
+
enableKeyExport: isKeyExportEnabled
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
getInitializationTrackData() {
|
|
502
|
+
try {
|
|
503
|
+
var _this$coreOptions$cha2, _this$coreOptions$cha3, _this$coreOptions$cha4, _this$coreOptions$uiC2;
|
|
504
|
+
const defaultChain = (_this$coreOptions$cha2 = this.coreOptions.chains) === null || _this$coreOptions$cha2 === void 0 ? void 0 : _this$coreOptions$cha2.find(chain => chain.chainId === this.coreOptions.defaultChainId);
|
|
505
|
+
const rpcHostnames = Array.from(new Set((_this$coreOptions$cha3 = this.coreOptions.chains) === null || _this$coreOptions$cha3 === void 0 ? void 0 : _this$coreOptions$cha3.map(chain => utils.getHostname(chain.rpcTarget)))).filter(Boolean);
|
|
506
|
+
return _objectSpread(_objectSpread(_objectSpread({
|
|
507
|
+
chain_ids: (_this$coreOptions$cha4 = this.coreOptions.chains) === null || _this$coreOptions$cha4 === void 0 ? void 0 : _this$coreOptions$cha4.map(chain => utils.getCaipChainId(chain)),
|
|
508
|
+
chain_rpc_targets: rpcHostnames,
|
|
509
|
+
default_chain_id: defaultChain ? utils.getCaipChainId(defaultChain) : undefined,
|
|
510
|
+
logging_enabled: this.coreOptions.enableLogging,
|
|
511
|
+
storage_type: this.coreOptions.storageType,
|
|
512
|
+
session_time: this.coreOptions.sessionTime,
|
|
513
|
+
sfa_key_enabled: this.coreOptions.useSFAKey,
|
|
514
|
+
mipd_enabled: this.coreOptions.multiInjectedProviderDiscovery,
|
|
515
|
+
private_key_provider_enabled: Boolean(this.coreOptions.privateKeyProvider),
|
|
516
|
+
ssr_enabled: this.coreOptions.ssr,
|
|
517
|
+
auth_build_env: this.coreOptions.authBuildEnv,
|
|
518
|
+
auth_ux_mode: (_this$coreOptions$uiC2 = this.coreOptions.uiConfig) === null || _this$coreOptions$uiC2 === void 0 ? void 0 : _this$coreOptions$uiC2.uxMode,
|
|
519
|
+
auth_mfa_level: this.coreOptions.mfaLevel,
|
|
520
|
+
auth_mfa_settings: Object.keys(this.coreOptions.mfaSettings || {}),
|
|
521
|
+
aa_enabled_for_external_wallets: this.coreOptions.accountAbstractionConfig ? this.coreOptions.useAAWithExternalWallet : undefined
|
|
522
|
+
}, utils.getWhitelabelAnalyticsProperties(this.coreOptions.uiConfig)), utils.getAaAnalyticsProperties(this.coreOptions.accountAbstractionConfig)), utils.getWalletServicesAnalyticsProperties(this.coreOptions.walletServicesConfig));
|
|
523
|
+
} catch (error) {
|
|
524
|
+
loglevel.log.error("Failed to get initialization track data", error);
|
|
525
|
+
return {};
|
|
526
|
+
}
|
|
311
527
|
}
|
|
312
528
|
async setupCommonJRPCProvider() {
|
|
313
529
|
this.commonJRPCProvider = await CommonJRPCProvider.CommonJRPCProvider.getProviderInstance({
|
|
@@ -344,7 +560,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
344
560
|
const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
|
|
345
561
|
const isMipdEnabled = isExternalWalletEnabled && ((_this$coreOptions$mul = this.coreOptions.multiInjectedProviderDiscovery) !== null && _this$coreOptions$mul !== void 0 ? _this$coreOptions$mul : true);
|
|
346
562
|
const chainNamespaces = new Set(this.coreOptions.chains.map(chain => chain.chainNamespace));
|
|
347
|
-
if (isMipdEnabled) {
|
|
563
|
+
if (isMipdEnabled && utils.isBrowser()) {
|
|
348
564
|
// Solana chains
|
|
349
565
|
if (chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.SOLANA)) {
|
|
350
566
|
const {
|
|
@@ -377,11 +593,13 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
377
593
|
}
|
|
378
594
|
// it's safe to add it here as if there is a MetaMask injected provider, this won't override it
|
|
379
595
|
// only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
596
|
+
if (utils.isBrowser() && (chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.EIP155) || chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.SOLANA))) {
|
|
597
|
+
connectorFns.push(metamaskConnector.metaMaskConnector(modalMode ? {
|
|
598
|
+
headless: true
|
|
599
|
+
} : undefined));
|
|
600
|
+
}
|
|
383
601
|
// add WalletConnectV2 connector if external wallets are enabled
|
|
384
|
-
if (isExternalWalletEnabled && (chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.SOLANA) || chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.EIP155))) {
|
|
602
|
+
if (utils.isBrowser() && isExternalWalletEnabled && (chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.SOLANA) || chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.EIP155))) {
|
|
385
603
|
const {
|
|
386
604
|
walletConnectV2Connector
|
|
387
605
|
} = await Promise.resolve().then(function () { return require('./connectors/wallet-connect-v2-connector/index.js'); });
|
|
@@ -429,6 +647,21 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
429
647
|
const {
|
|
430
648
|
provider
|
|
431
649
|
} = data;
|
|
650
|
+
// when ssr is enabled, we need to get the idToken from the connector.
|
|
651
|
+
if (this.coreOptions.ssr) {
|
|
652
|
+
try {
|
|
653
|
+
const data = await connector.getIdentityToken();
|
|
654
|
+
if (!data.idToken) throw index.WalletLoginError.connectionError("No idToken found");
|
|
655
|
+
this.setState({
|
|
656
|
+
idToken: data.idToken
|
|
657
|
+
});
|
|
658
|
+
} catch (error) {
|
|
659
|
+
loglevel.log.error(error);
|
|
660
|
+
this.status = constants.CONNECTOR_STATUS.ERRORED;
|
|
661
|
+
this.emit(constants.CONNECTOR_EVENTS.ERRORED, error, this.loginMode);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
432
665
|
let finalProvider = provider.provider || provider;
|
|
433
666
|
// setup AA provider if AA is enabled
|
|
434
667
|
const {
|
|
@@ -451,7 +684,8 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
451
684
|
accountAbstractionConfig,
|
|
452
685
|
provider: eoaProvider,
|
|
453
686
|
chain: this.currentChain,
|
|
454
|
-
chains: this.coreOptions.chains.filter(chain => aaChainIds.has(chain.chainId))
|
|
687
|
+
chains: this.coreOptions.chains.filter(chain => aaChainIds.has(chain.chainId)),
|
|
688
|
+
useProviderAsTransport: data.connector === index$1.WALLET_CONNECTORS.AUTH
|
|
455
689
|
});
|
|
456
690
|
this.aaProvider = aaProvider;
|
|
457
691
|
// if external wallet is used and AA is enabled for external wallets, use AA provider
|
|
@@ -461,12 +695,16 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
461
695
|
}
|
|
462
696
|
}
|
|
463
697
|
this.commonJRPCProvider.updateProviderEngineProxy(finalProvider);
|
|
464
|
-
this.
|
|
465
|
-
|
|
698
|
+
this.setState({
|
|
699
|
+
connectedConnectorName: data.connector
|
|
700
|
+
});
|
|
466
701
|
this.cacheWallet(data.connector);
|
|
702
|
+
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
467
703
|
loglevel.log.debug("connected", this.status, this.connectedConnectorName);
|
|
468
704
|
this.connectToPlugins(data);
|
|
469
|
-
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, _objectSpread({}, data)
|
|
705
|
+
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, _objectSpread(_objectSpread({}, data), {}, {
|
|
706
|
+
loginMode: this.loginMode
|
|
707
|
+
}));
|
|
470
708
|
});
|
|
471
709
|
connector.on(constants.CONNECTOR_EVENTS.DISCONNECTED, async () => {
|
|
472
710
|
// re-setup commonJRPCProvider
|
|
@@ -474,11 +712,9 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
474
712
|
this.setupCommonJRPCProvider();
|
|
475
713
|
// get back to ready state for rehydrating.
|
|
476
714
|
this.status = constants.CONNECTOR_STATUS.READY;
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
this.clearCache();
|
|
481
|
-
}
|
|
715
|
+
const cachedConnector = this.state.cachedConnector;
|
|
716
|
+
if (this.connectedConnectorName === cachedConnector) {
|
|
717
|
+
this.clearCache();
|
|
482
718
|
}
|
|
483
719
|
loglevel.log.debug("disconnected", this.status, this.connectedConnectorName);
|
|
484
720
|
await Promise.all(Object.values(this.plugins).map(async plugin => {
|
|
@@ -493,7 +729,9 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
493
729
|
loglevel.log.error(error);
|
|
494
730
|
});
|
|
495
731
|
}));
|
|
496
|
-
this.
|
|
732
|
+
this.setState({
|
|
733
|
+
connectedConnectorName: null
|
|
734
|
+
});
|
|
497
735
|
this.emit(constants.CONNECTOR_EVENTS.DISCONNECTED);
|
|
498
736
|
});
|
|
499
737
|
connector.on(constants.CONNECTOR_EVENTS.CONNECTING, data => {
|
|
@@ -504,27 +742,37 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
504
742
|
connector.on(constants.CONNECTOR_EVENTS.ERRORED, data => {
|
|
505
743
|
this.status = constants.CONNECTOR_STATUS.ERRORED;
|
|
506
744
|
this.clearCache();
|
|
507
|
-
this.emit(constants.CONNECTOR_EVENTS.ERRORED, data);
|
|
745
|
+
this.emit(constants.CONNECTOR_EVENTS.ERRORED, data, this.loginMode);
|
|
508
746
|
loglevel.log.debug("errored", this.status, this.connectedConnectorName);
|
|
509
747
|
});
|
|
748
|
+
connector.on(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, error => {
|
|
749
|
+
this.status = constants.CONNECTOR_STATUS.READY;
|
|
750
|
+
this.clearCache();
|
|
751
|
+
this.emit(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
752
|
+
});
|
|
510
753
|
connector.on(constants.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, data => {
|
|
511
754
|
loglevel.log.debug("connector data updated", data);
|
|
512
755
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, data);
|
|
513
756
|
});
|
|
514
757
|
connector.on(constants.CONNECTOR_EVENTS.CACHE_CLEAR, data => {
|
|
515
758
|
loglevel.log.debug("connector cache clear", data);
|
|
516
|
-
|
|
517
|
-
this.clearCache();
|
|
518
|
-
}
|
|
759
|
+
this.clearCache();
|
|
519
760
|
});
|
|
520
761
|
connector.on(constants.CONNECTOR_EVENTS.MFA_ENABLED, isMFAEnabled => {
|
|
762
|
+
var _authConnector$authIn4;
|
|
521
763
|
loglevel.log.debug("mfa enabled", isMFAEnabled);
|
|
764
|
+
const authConnector = this.connectedConnector;
|
|
765
|
+
// mfa_enabled event is only emitted when using "popup" ux_mode
|
|
766
|
+
// TODO: handle mfa_enabled event when using "redirect" ux_mode
|
|
767
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.MFA_ENABLEMENT_COMPLETED, {
|
|
768
|
+
connector: this.connectedConnector.name,
|
|
769
|
+
auth_ux_mode: (_authConnector$authIn4 = authConnector.authInstance) === null || _authConnector$authIn4 === void 0 || (_authConnector$authIn4 = _authConnector$authIn4.options) === null || _authConnector$authIn4 === void 0 ? void 0 : _authConnector$authIn4.uxMode,
|
|
770
|
+
is_mfa_enabled: isMFAEnabled
|
|
771
|
+
});
|
|
522
772
|
this.emit(constants.CONNECTOR_EVENTS.MFA_ENABLED, isMFAEnabled);
|
|
523
773
|
});
|
|
524
774
|
}
|
|
525
775
|
checkInitRequirements() {
|
|
526
|
-
if (this.status === constants.CONNECTOR_STATUS.CONNECTING) throw index.WalletInitializationError.notReady("Already pending connection");
|
|
527
|
-
if (this.status === constants.CONNECTOR_STATUS.CONNECTED) throw index.WalletInitializationError.notReady("Already connected");
|
|
528
776
|
if (this.status === constants.CONNECTOR_STATUS.READY) throw index.WalletInitializationError.notReady("Connector is already initialized");
|
|
529
777
|
}
|
|
530
778
|
/**
|
|
@@ -541,21 +789,17 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
541
789
|
return initialChain;
|
|
542
790
|
}
|
|
543
791
|
cacheWallet(walletName) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
this.cachedConnector = walletName;
|
|
792
|
+
this.setState({
|
|
793
|
+
cachedConnector: walletName
|
|
794
|
+
});
|
|
548
795
|
}
|
|
549
796
|
setCurrentChain(chainId) {
|
|
550
797
|
if (chainId === this.currentChainId) return;
|
|
551
798
|
const newChain = this.coreOptions.chains.find(chain => chain.chainId === chainId);
|
|
552
799
|
if (!newChain) throw index.WalletInitializationError.invalidParams(`Invalid chainId: ${chainId}`);
|
|
553
|
-
this.
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
cacheCurrentChain(chainId) {
|
|
557
|
-
if (!utils$1.storageAvailable(this.storage)) return;
|
|
558
|
-
window[this.storage].setItem(CURRENT_CHAIN_CACHE_KEY, chainId);
|
|
800
|
+
this.setState({
|
|
801
|
+
currentChainId: chainId
|
|
802
|
+
});
|
|
559
803
|
}
|
|
560
804
|
connectToPlugins(data) {
|
|
561
805
|
Object.values(this.plugins).map(async plugin => {
|
|
@@ -578,6 +822,28 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
578
822
|
}
|
|
579
823
|
});
|
|
580
824
|
}
|
|
825
|
+
setState(newState) {
|
|
826
|
+
this.state = _objectSpread(_objectSpread({}, this.state), newState);
|
|
827
|
+
this.storage.setItem(constants$1.WEB3AUTH_STATE_STORAGE_KEY, JSON.stringify(this.state));
|
|
828
|
+
}
|
|
829
|
+
loadState(initialState) {
|
|
830
|
+
if (initialState) {
|
|
831
|
+
this.state = initialState;
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
const state = this.storage.getItem(constants$1.WEB3AUTH_STATE_STORAGE_KEY);
|
|
835
|
+
if (!state) return;
|
|
836
|
+
this.state = deserialize.deserialize(state);
|
|
837
|
+
}
|
|
838
|
+
getStorageMethod() {
|
|
839
|
+
if (this.coreOptions.ssr || this.coreOptions.storageType === "cookies") return cookie.cookieStorage({
|
|
840
|
+
expiry: this.coreOptions.sessionTime
|
|
841
|
+
});
|
|
842
|
+
if (this.coreOptions.storageType === "session" && utils$1.storageAvailable("sessionStorage")) return window.sessionStorage;
|
|
843
|
+
if (this.coreOptions.storageType === "local" && utils$1.storageAvailable("localStorage")) return window.localStorage;
|
|
844
|
+
// If no storage is available, use a memory store.
|
|
845
|
+
return new auth.MemoryStore();
|
|
846
|
+
}
|
|
581
847
|
}
|
|
582
848
|
|
|
583
849
|
exports.Web3AuthNoModal = Web3AuthNoModal;
|