@web3auth/no-modal 10.0.0-beta.9 → 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 +10 -5
- 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 +3 -2
- package/dist/lib.cjs/react/wagmi/constants.js +16 -0
- package/dist/lib.cjs/react/wagmi/provider.js +14 -9
- 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/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 +21 -15
- package/dist/lib.cjs/vue/wagmi/constants.js +16 -0
- package/dist/lib.cjs/vue/wagmi/provider.js +33 -15
- 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 +8 -4
- 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/wagmi/constants.js +14 -0
- package/dist/lib.esm/react/wagmi/provider.js +13 -8
- 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 +18 -14
- package/dist/lib.esm/vue/wagmi/constants.js +14 -0
- package/dist/lib.esm/vue/wagmi/provider.js +33 -13
- package/dist/noModal.umd.min.js +1 -1
- package/dist/noModal.umd.min.js.LICENSE.txt +4 -6
- package/package.json +21 -19
package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js
CHANGED
|
@@ -26,6 +26,7 @@ class AccountAbstractionProvider extends BaseProvider {
|
|
|
26
26
|
_defineProperty(this, "_publicClient", void 0);
|
|
27
27
|
_defineProperty(this, "_bundlerClient", void 0);
|
|
28
28
|
_defineProperty(this, "_paymasterClient", void 0);
|
|
29
|
+
_defineProperty(this, "_useProviderAsTransport", void 0);
|
|
29
30
|
this.update({
|
|
30
31
|
chainId: config.chain.chainId
|
|
31
32
|
});
|
|
@@ -112,13 +113,13 @@ class AccountAbstractionProvider extends BaseProvider {
|
|
|
112
113
|
if (paymasterConfig) {
|
|
113
114
|
var _paymasterConfig$tran;
|
|
114
115
|
this._paymasterClient = createPaymasterClient(_objectSpread(_objectSpread({}, paymasterConfig), {}, {
|
|
115
|
-
transport: (_paymasterConfig$tran = paymasterConfig.transport) !== null && _paymasterConfig$tran !== void 0 ? _paymasterConfig$tran : http(paymasterConfig.url)
|
|
116
|
+
transport: this._useProviderAsTransport ? custom(eoaProvider) : (_paymasterConfig$tran = paymasterConfig.transport) !== null && _paymasterConfig$tran !== void 0 ? _paymasterConfig$tran : http(paymasterConfig.url)
|
|
116
117
|
}));
|
|
117
118
|
}
|
|
118
119
|
this._bundlerClient = createBundlerClient(_objectSpread(_objectSpread({}, bundlerConfig), {}, {
|
|
119
120
|
account: this.smartAccount,
|
|
120
121
|
client: this._publicClient,
|
|
121
|
-
transport: (_bundlerConfig$transp = bundlerConfig.transport) !== null && _bundlerConfig$transp !== void 0 ? _bundlerConfig$transp : http(bundlerConfig.url),
|
|
122
|
+
transport: this._useProviderAsTransport ? custom(eoaProvider) : (_bundlerConfig$transp = bundlerConfig.transport) !== null && _bundlerConfig$transp !== void 0 ? _bundlerConfig$transp : http(bundlerConfig.url),
|
|
122
123
|
paymaster: this._paymasterClient
|
|
123
124
|
}));
|
|
124
125
|
const providerHandlers = getProviderHandlers({
|
|
@@ -165,6 +166,7 @@ _defineProperty(AccountAbstractionProvider, "getProviderInstance", async params
|
|
|
165
166
|
const providerInstance = new _AccountAbstractionProvider({
|
|
166
167
|
config: params
|
|
167
168
|
});
|
|
169
|
+
providerInstance._useProviderAsTransport = params.useProviderAsTransport;
|
|
168
170
|
await providerInstance.setupProvider(params.eoaProvider);
|
|
169
171
|
providerInstance.update({
|
|
170
172
|
eoaProvider: params.eoaProvider
|
|
@@ -175,7 +177,8 @@ const accountAbstractionProvider = async ({
|
|
|
175
177
|
accountAbstractionConfig,
|
|
176
178
|
chain,
|
|
177
179
|
chains,
|
|
178
|
-
provider
|
|
180
|
+
provider,
|
|
181
|
+
useProviderAsTransport
|
|
179
182
|
}) => {
|
|
180
183
|
let smartAccountInit;
|
|
181
184
|
const {
|
|
@@ -242,7 +245,8 @@ const accountAbstractionProvider = async ({
|
|
|
242
245
|
smartAccountInit,
|
|
243
246
|
chain,
|
|
244
247
|
chains,
|
|
245
|
-
smartAccountChainsConfig
|
|
248
|
+
smartAccountChainsConfig,
|
|
249
|
+
useProviderAsTransport
|
|
246
250
|
});
|
|
247
251
|
};
|
|
248
252
|
const toEoaProvider = async aaProvider => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createContext, useState, useCallback, useEffect,
|
|
1
|
+
import { createContext, useMemo, useState, useCallback, useEffect, createElement } from 'react';
|
|
2
2
|
import { Web3AuthNoModal } from '../../noModal.js';
|
|
3
|
+
import { ANALYTICS_INTEGRATION_TYPE } from '../../base/analytics.js';
|
|
3
4
|
import { WalletInitializationError } from '../../base/errors/index.js';
|
|
4
5
|
import { CONNECTOR_EVENTS, CONNECTOR_STATUS } from '../../base/connector/constants.js';
|
|
5
6
|
|
|
@@ -7,9 +8,16 @@ const Web3AuthInnerContext = createContext(null);
|
|
|
7
8
|
function Web3AuthInnerProvider(params) {
|
|
8
9
|
const {
|
|
9
10
|
children,
|
|
10
|
-
config
|
|
11
|
+
config,
|
|
12
|
+
initialState
|
|
11
13
|
} = params;
|
|
12
|
-
const
|
|
14
|
+
const {
|
|
15
|
+
web3AuthOptions
|
|
16
|
+
} = config;
|
|
17
|
+
const web3Auth = useMemo(() => {
|
|
18
|
+
setProvider(null);
|
|
19
|
+
return new Web3AuthNoModal(web3AuthOptions, initialState);
|
|
20
|
+
}, [web3AuthOptions, initialState]);
|
|
13
21
|
const [isInitializing, setIsInitializing] = useState(false);
|
|
14
22
|
const [initError, setInitError] = useState(null);
|
|
15
23
|
const [isConnected, setIsConnected] = useState(false);
|
|
@@ -21,25 +29,15 @@ function Web3AuthInnerProvider(params) {
|
|
|
21
29
|
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
22
30
|
return web3Auth.getPlugin(name);
|
|
23
31
|
}, [web3Auth]);
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
const resetHookState = () => {
|
|
26
|
-
setProvider(null);
|
|
27
|
-
setIsConnected(false);
|
|
28
|
-
setStatus(null);
|
|
29
|
-
};
|
|
30
|
-
resetHookState();
|
|
31
|
-
const {
|
|
32
|
-
web3AuthOptions
|
|
33
|
-
} = config;
|
|
34
|
-
const web3Instance = new Web3AuthNoModal(web3AuthOptions);
|
|
35
|
-
setWeb3Auth(web3Instance);
|
|
36
|
-
}, [config]);
|
|
37
32
|
useEffect(() => {
|
|
38
33
|
const controller = new AbortController();
|
|
39
34
|
async function init() {
|
|
40
35
|
try {
|
|
41
36
|
setInitError(null);
|
|
42
37
|
setIsInitializing(true);
|
|
38
|
+
web3Auth.setAnalyticsProperties({
|
|
39
|
+
integration_type: ANALYTICS_INTEGRATION_TYPE.REACT_HOOKS
|
|
40
|
+
});
|
|
43
41
|
await web3Auth.init({
|
|
44
42
|
signal: controller.signal
|
|
45
43
|
});
|
|
@@ -78,7 +76,12 @@ function Web3AuthInnerProvider(params) {
|
|
|
78
76
|
setStatus(web3Auth.status);
|
|
79
77
|
};
|
|
80
78
|
const errorListener = () => {
|
|
81
|
-
setStatus(
|
|
79
|
+
setStatus(web3Auth.status);
|
|
80
|
+
};
|
|
81
|
+
const rehydrationErrorListener = () => {
|
|
82
|
+
setStatus(web3Auth.status);
|
|
83
|
+
setIsConnected(false);
|
|
84
|
+
setProvider(null);
|
|
82
85
|
};
|
|
83
86
|
const mfaEnabledListener = isMFAEnabled => {
|
|
84
87
|
if (typeof isMFAEnabled === "boolean") setIsMFAEnabled(isMFAEnabled);
|
|
@@ -92,6 +95,7 @@ function Web3AuthInnerProvider(params) {
|
|
|
92
95
|
web3Auth.on(CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
93
96
|
web3Auth.on(CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
94
97
|
web3Auth.on(CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
98
|
+
web3Auth.on(CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
|
|
95
99
|
web3Auth.on(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
96
100
|
}
|
|
97
101
|
return () => {
|
|
@@ -102,6 +106,7 @@ function Web3AuthInnerProvider(params) {
|
|
|
102
106
|
web3Auth.off(CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
103
107
|
web3Auth.off(CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
104
108
|
web3Auth.off(CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
109
|
+
web3Auth.off(CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
|
|
105
110
|
web3Auth.off(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
106
111
|
}
|
|
107
112
|
};
|
|
@@ -9,11 +9,11 @@ const useIdentityToken = () => {
|
|
|
9
9
|
const [loading, setLoading] = useState(false);
|
|
10
10
|
const [error, setError] = useState(null);
|
|
11
11
|
const [token, setToken] = useState(null);
|
|
12
|
-
const
|
|
12
|
+
const getIdentityToken = useCallback(async () => {
|
|
13
13
|
setLoading(true);
|
|
14
14
|
setError(null);
|
|
15
15
|
try {
|
|
16
|
-
const userAuthInfo = await web3Auth.
|
|
16
|
+
const userAuthInfo = await web3Auth.getIdentityToken();
|
|
17
17
|
if (userAuthInfo !== null && userAuthInfo !== void 0 && userAuthInfo.idToken) {
|
|
18
18
|
setToken(userAuthInfo.idToken);
|
|
19
19
|
}
|
|
@@ -33,7 +33,7 @@ const useIdentityToken = () => {
|
|
|
33
33
|
loading,
|
|
34
34
|
error,
|
|
35
35
|
token,
|
|
36
|
-
|
|
36
|
+
getIdentityToken
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
39
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createConfig, http } from 'wagmi';
|
|
2
|
+
import { mainnet } from 'wagmi/chains';
|
|
3
|
+
|
|
4
|
+
const defaultWagmiConfig = createConfig({
|
|
5
|
+
chains: [mainnet],
|
|
6
|
+
connectors: [],
|
|
7
|
+
// or your basic wallets
|
|
8
|
+
ssr: true,
|
|
9
|
+
transports: {
|
|
10
|
+
[mainnet.id]: http(mainnet.rpcUrls.default.http[0])
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export { defaultWagmiConfig };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
2
2
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
3
3
|
import { useMemo, createElement, useEffect, Fragment } from 'react';
|
|
4
|
-
import { defineChain
|
|
5
|
-
import { createConfig, WagmiProvider as WagmiProvider$1, useConfig, useAccountEffect } from 'wagmi';
|
|
4
|
+
import { defineChain } from 'viem';
|
|
5
|
+
import { webSocket, http, createConfig, WagmiProvider as WagmiProvider$1, useConfig, useReconnect, useAccountEffect } from 'wagmi';
|
|
6
6
|
import { injected } from 'wagmi/connectors';
|
|
7
|
+
import { defaultWagmiConfig } from './constants.js';
|
|
7
8
|
import { useWeb3Auth } from '../hooks/useWeb3Auth.js';
|
|
8
9
|
import { useWeb3AuthDisconnect } from '../hooks/useWeb3AuthDisconnect.js';
|
|
10
|
+
import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
11
|
+
import { WalletInitializationError } from '../../base/errors/index.js';
|
|
9
12
|
import { log } from '../../base/loglevel.js';
|
|
10
13
|
|
|
11
14
|
const _excluded = ["children"];
|
|
@@ -71,6 +74,9 @@ function Web3AuthWagmiProvider({
|
|
|
71
74
|
disconnect
|
|
72
75
|
} = useWeb3AuthDisconnect();
|
|
73
76
|
const wagmiConfig = useConfig();
|
|
77
|
+
const {
|
|
78
|
+
reconnect
|
|
79
|
+
} = useReconnect();
|
|
74
80
|
useAccountEffect({
|
|
75
81
|
onDisconnect: async () => {
|
|
76
82
|
log.info("Disconnected from wagmi");
|
|
@@ -85,13 +91,14 @@ function Web3AuthWagmiProvider({
|
|
|
85
91
|
throw new Error("Failed to setup connector");
|
|
86
92
|
}
|
|
87
93
|
await connectWeb3AuthWithWagmi(connector, wagmiConfig);
|
|
94
|
+
reconnect();
|
|
88
95
|
} else if (!isConnected) {
|
|
89
96
|
if (wagmiConfig.state.status === "connected") {
|
|
90
97
|
await disconnectWeb3AuthFromWagmi(wagmiConfig);
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
100
|
})();
|
|
94
|
-
}, [isConnected, wagmiConfig, provider]);
|
|
101
|
+
}, [isConnected, wagmiConfig, provider, reconnect]);
|
|
95
102
|
return createElement(Fragment, null, children);
|
|
96
103
|
}
|
|
97
104
|
function WagmiProvider(_ref) {
|
|
@@ -108,6 +115,7 @@ function WagmiProvider(_ref) {
|
|
|
108
115
|
} = useWeb3Auth();
|
|
109
116
|
const finalConfig = useMemo(() => {
|
|
110
117
|
var _web3Auth$coreOptions;
|
|
118
|
+
if (!isInitialized) return defaultWagmiConfig;
|
|
111
119
|
const finalConfig = _objectSpread(_objectSpread({
|
|
112
120
|
ssr: true
|
|
113
121
|
}, config), {}, {
|
|
@@ -121,7 +129,8 @@ function WagmiProvider(_ref) {
|
|
|
121
129
|
if (isInitialized && web3Auth !== null && web3Auth !== void 0 && (_web3Auth$coreOptions = web3Auth.coreOptions) !== null && _web3Auth$coreOptions !== void 0 && _web3Auth$coreOptions.chains) {
|
|
122
130
|
var _web3Auth$currentChai;
|
|
123
131
|
const defaultChainId = (_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainId;
|
|
124
|
-
const chains = web3Auth.coreOptions.chains;
|
|
132
|
+
const chains = web3Auth.coreOptions.chains.filter(chain => chain.chainNamespace === CHAIN_NAMESPACES.EIP155);
|
|
133
|
+
if (chains.length === 0) throw WalletInitializationError.invalidParams("No valid chains found in web3auth config for wagmi.");
|
|
125
134
|
chains.forEach(chain => {
|
|
126
135
|
const wagmiChain = defineChain({
|
|
127
136
|
id: Number.parseInt(chain.chainId, 16),
|
|
@@ -158,10 +167,6 @@ function WagmiProvider(_ref) {
|
|
|
158
167
|
if (!finalConfig.chains) return;
|
|
159
168
|
return createConfig(finalConfig);
|
|
160
169
|
}, [config, web3Auth, isInitialized]);
|
|
161
|
-
|
|
162
|
-
// WagmiProviderBase requires a config to initialize
|
|
163
|
-
// If no config is provided, it will throw an error.
|
|
164
|
-
if (!finalConfig) return null;
|
|
165
170
|
return createElement(WagmiProvider$1, // typecast to WagmiProviderPropsBase to avoid type error
|
|
166
171
|
// as we are omitting the config prop from WagmiProviderProps
|
|
167
172
|
// and creating a new config object with the finalConfig
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineComponent, h, shallowRef, ref, watch, provide } from 'vue';
|
|
2
2
|
import { Web3AuthNoModal } from '../noModal.js';
|
|
3
3
|
import { WalletServicesInnerProvider } from './WalletServicesInnerProvider.js';
|
|
4
|
+
import { ANALYTICS_INTEGRATION_TYPE } from '../base/analytics.js';
|
|
4
5
|
import { CONNECTOR_EVENTS, CONNECTOR_STATUS } from '../base/connector/constants.js';
|
|
5
6
|
import { Web3AuthContextKey } from '../base/composables/index.js';
|
|
6
7
|
import { WalletInitializationError } from '../base/errors/index.js';
|
|
@@ -46,6 +47,9 @@ const Web3AuthProvider = defineComponent({
|
|
|
46
47
|
web3AuthOptions
|
|
47
48
|
} = newConfig;
|
|
48
49
|
const web3AuthInstance = new Web3AuthNoModal(web3AuthOptions);
|
|
50
|
+
web3AuthInstance.setAnalyticsProperties({
|
|
51
|
+
integration_type: ANALYTICS_INTEGRATION_TYPE.VUE_COMPOSABLES
|
|
52
|
+
});
|
|
49
53
|
web3Auth.value = web3AuthInstance;
|
|
50
54
|
}, {
|
|
51
55
|
immediate: true
|
|
@@ -100,7 +104,7 @@ const Web3AuthProvider = defineComponent({
|
|
|
100
104
|
status.value = web3Auth.value.status;
|
|
101
105
|
};
|
|
102
106
|
const errorListener = () => {
|
|
103
|
-
status.value =
|
|
107
|
+
status.value = web3Auth.value.status;
|
|
104
108
|
};
|
|
105
109
|
const mfaEnabledListener = () => {
|
|
106
110
|
isMFAEnabled.value = true;
|
|
@@ -114,6 +118,7 @@ const Web3AuthProvider = defineComponent({
|
|
|
114
118
|
prevWeb3Auth.off(CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
115
119
|
prevWeb3Auth.off(CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
116
120
|
prevWeb3Auth.off(CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
121
|
+
prevWeb3Auth.off(CONNECTOR_EVENTS.REHYDRATION_ERROR, errorListener);
|
|
117
122
|
prevWeb3Auth.off(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
118
123
|
}
|
|
119
124
|
if (newWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
|
|
@@ -125,6 +130,7 @@ const Web3AuthProvider = defineComponent({
|
|
|
125
130
|
newWeb3Auth.on(CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
126
131
|
newWeb3Auth.on(CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
127
132
|
newWeb3Auth.on(CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
133
|
+
newWeb3Auth.on(CONNECTOR_EVENTS.REHYDRATION_ERROR, errorListener);
|
|
128
134
|
newWeb3Auth.on(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
129
135
|
}
|
|
130
136
|
}, {
|
|
@@ -10,12 +10,12 @@ const useIdentityToken = () => {
|
|
|
10
10
|
const loading = ref(false);
|
|
11
11
|
const error = ref(null);
|
|
12
12
|
const token = ref(null);
|
|
13
|
-
const
|
|
13
|
+
const getIdentityToken = async () => {
|
|
14
14
|
try {
|
|
15
15
|
if (!web3Auth.value) throw WalletInitializationError.notReady();
|
|
16
16
|
error.value = null;
|
|
17
17
|
loading.value = true;
|
|
18
|
-
const result = await web3Auth.value.
|
|
18
|
+
const result = await web3Auth.value.getIdentityToken();
|
|
19
19
|
if (result !== null && result !== void 0 && result.idToken) {
|
|
20
20
|
token.value = result.idToken;
|
|
21
21
|
}
|
|
@@ -35,7 +35,7 @@ const useIdentityToken = () => {
|
|
|
35
35
|
loading,
|
|
36
36
|
error,
|
|
37
37
|
token,
|
|
38
|
-
|
|
38
|
+
getIdentityToken
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
|
|
@@ -13,7 +13,7 @@ const useManageMFA = () => {
|
|
|
13
13
|
if (!web3Auth.value) throw WalletInitializationError.notReady();
|
|
14
14
|
error.value = null;
|
|
15
15
|
loading.value = true;
|
|
16
|
-
await web3Auth.value.
|
|
16
|
+
await web3Auth.value.manageMFA();
|
|
17
17
|
} catch (err) {
|
|
18
18
|
error.value = err;
|
|
19
19
|
} finally {
|
|
@@ -12,29 +12,33 @@ const useSolanaWallet = () => {
|
|
|
12
12
|
const accounts = ref([]);
|
|
13
13
|
const solanaWallet = shallowRef(null);
|
|
14
14
|
const connection = shallowRef(null);
|
|
15
|
-
|
|
16
|
-
var _web3Auth$value,
|
|
15
|
+
const setupWallet = async () => {
|
|
16
|
+
var _web3Auth$value, _web3Auth$value2;
|
|
17
17
|
if (!((_web3Auth$value = web3Auth.value) !== null && _web3Auth$value !== void 0 && (_web3Auth$value = _web3Auth$value.currentChain) !== null && _web3Auth$value !== void 0 && _web3Auth$value.chainNamespace) || web3Auth.value.currentChain.chainNamespace !== CHAIN_NAMESPACES.SOLANA) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
+
solanaWallet.value = new SolanaWallet(provider.value);
|
|
21
|
+
const result = await solanaWallet.value.requestAccounts();
|
|
22
|
+
if ((result === null || result === void 0 ? void 0 : result.length) > 0) {
|
|
23
|
+
accounts.value = result;
|
|
24
|
+
}
|
|
25
|
+
connection.value = new Connection((_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 || (_web3Auth$value2 = _web3Auth$value2.currentChain) === null || _web3Auth$value2 === void 0 ? void 0 : _web3Auth$value2.rpcTarget);
|
|
26
|
+
};
|
|
27
|
+
if (provider.value && !solanaWallet.value) {
|
|
28
|
+
setupWallet();
|
|
29
|
+
}
|
|
30
|
+
watch(provider, async newVal => {
|
|
20
31
|
if (!newVal && solanaWallet.value) {
|
|
21
32
|
solanaWallet.value = null;
|
|
22
33
|
accounts.value = null;
|
|
34
|
+
connection.value = null;
|
|
23
35
|
return;
|
|
24
36
|
}
|
|
25
|
-
if (!solanaWallet.value) {
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
if (((_accounts$value = accounts.value) === null || _accounts$value === void 0 ? void 0 : _accounts$value.length) === 0) {
|
|
29
|
-
const result = await solanaWallet.value.requestAccounts();
|
|
30
|
-
if ((result === null || result === void 0 ? void 0 : result.length) > 0) {
|
|
31
|
-
accounts.value = result;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (solanaWallet.value && !connection.value) {
|
|
35
|
-
var _web3Auth$value2;
|
|
36
|
-
connection.value = new Connection((_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 || (_web3Auth$value2 = _web3Auth$value2.currentChain) === null || _web3Auth$value2 === void 0 ? void 0 : _web3Auth$value2.rpcTarget);
|
|
37
|
+
if (newVal && !solanaWallet.value) {
|
|
38
|
+
setupWallet();
|
|
37
39
|
}
|
|
40
|
+
}, {
|
|
41
|
+
immediate: true
|
|
38
42
|
});
|
|
39
43
|
return {
|
|
40
44
|
solanaWallet,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createConfig, http } from '@wagmi/vue';
|
|
2
|
+
import { mainnet } from '@wagmi/vue/chains';
|
|
3
|
+
|
|
4
|
+
const defaultWagmiConfig = createConfig({
|
|
5
|
+
chains: [mainnet],
|
|
6
|
+
connectors: [],
|
|
7
|
+
// or your basic wallets
|
|
8
|
+
ssr: true,
|
|
9
|
+
transports: {
|
|
10
|
+
[mainnet.id]: http(mainnet.rpcUrls.default.http[0])
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export { defaultWagmiConfig };
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import { hydrate } from '@wagmi/core';
|
|
3
|
-
import { configKey, createConfig, useConfig, useAccountEffect } from '@wagmi/vue';
|
|
3
|
+
import { configKey, createConfig, useConfig, useReconnect, useAccountEffect } from '@wagmi/vue';
|
|
4
4
|
import { injected } from '@wagmi/vue/connectors';
|
|
5
|
+
import { randomId } from '@web3auth/auth';
|
|
5
6
|
import { defineChain, webSocket, http } from 'viem';
|
|
6
|
-
import { defineComponent, h, shallowRef, watch, provide } from 'vue';
|
|
7
|
+
import { defineComponent, h, shallowRef, ref, watch, provide } from 'vue';
|
|
7
8
|
import { log } from '../../base/loglevel.js';
|
|
9
|
+
import { defaultWagmiConfig } from './constants.js';
|
|
8
10
|
import { useWeb3AuthDisconnect } from '../composables/useWeb3AuthDisconnect.js';
|
|
9
11
|
import { useWeb3Auth } from '../composables/useWeb3Auth.js';
|
|
12
|
+
import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
13
|
+
import { WalletInitializationError } from '../../base/errors/index.js';
|
|
10
14
|
|
|
11
15
|
const WEB3AUTH_CONNECTOR_ID = "web3auth";
|
|
12
16
|
|
|
@@ -70,6 +74,9 @@ const Web3AuthWagmiProvider = defineComponent({
|
|
|
70
74
|
disconnect
|
|
71
75
|
} = useWeb3AuthDisconnect();
|
|
72
76
|
const wagmiConfig = useConfig();
|
|
77
|
+
const {
|
|
78
|
+
reconnect
|
|
79
|
+
} = useReconnect();
|
|
73
80
|
useAccountEffect({
|
|
74
81
|
onDisconnect: async () => {
|
|
75
82
|
log.info("Disconnected from wagmi");
|
|
@@ -83,6 +90,7 @@ const Web3AuthWagmiProvider = defineComponent({
|
|
|
83
90
|
throw new Error("Failed to setup connector");
|
|
84
91
|
}
|
|
85
92
|
await connectWeb3AuthWithWagmi(connector, wagmiConfig);
|
|
93
|
+
reconnect();
|
|
86
94
|
} else if (!newIsConnected) {
|
|
87
95
|
if (wagmiConfig.state.status === "connected") {
|
|
88
96
|
await disconnectWeb3AuthFromWagmi(wagmiConfig);
|
|
@@ -132,7 +140,8 @@ const WagmiProvider = defineComponent({
|
|
|
132
140
|
web3Auth,
|
|
133
141
|
isInitialized
|
|
134
142
|
} = useWeb3Auth();
|
|
135
|
-
const finalConfig = shallowRef(
|
|
143
|
+
const finalConfig = shallowRef(defaultWagmiConfig);
|
|
144
|
+
const configKey = ref(randomId());
|
|
136
145
|
const defineWagmiConfig = () => {
|
|
137
146
|
var _web3Auth$value;
|
|
138
147
|
const configParams = _objectSpread(_objectSpread({
|
|
@@ -148,7 +157,8 @@ const WagmiProvider = defineComponent({
|
|
|
148
157
|
if (isInitialized.value && web3Auth !== null && web3Auth !== void 0 && (_web3Auth$value = web3Auth.value) !== null && _web3Auth$value !== void 0 && (_web3Auth$value = _web3Auth$value.coreOptions) !== null && _web3Auth$value !== void 0 && _web3Auth$value.chains) {
|
|
149
158
|
var _web3Auth$value$curre;
|
|
150
159
|
const defaultChainId = (_web3Auth$value$curre = web3Auth.value.currentChain) === null || _web3Auth$value$curre === void 0 ? void 0 : _web3Auth$value$curre.chainId;
|
|
151
|
-
const chains = web3Auth.value.coreOptions.chains;
|
|
160
|
+
const chains = web3Auth.value.coreOptions.chains.filter(chain => chain.chainNamespace === CHAIN_NAMESPACES.EIP155);
|
|
161
|
+
if (chains.length === 0) throw WalletInitializationError.invalidParams("No valid chains found in web3auth config for wagmi.");
|
|
152
162
|
chains.forEach(chain => {
|
|
153
163
|
const wagmiChain = defineChain({
|
|
154
164
|
id: Number.parseInt(chain.chainId, 16),
|
|
@@ -182,29 +192,39 @@ const WagmiProvider = defineComponent({
|
|
|
182
192
|
});
|
|
183
193
|
configParams.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
|
|
184
194
|
}
|
|
185
|
-
if (!configParams.chains) return;
|
|
186
195
|
return createConfig(configParams);
|
|
187
196
|
};
|
|
197
|
+
const hydrateWagmiConfig = () => {
|
|
198
|
+
if (finalConfig.value) {
|
|
199
|
+
hydrate(finalConfig.value, _objectSpread({
|
|
200
|
+
reconnectOnMount: false
|
|
201
|
+
}, props.config));
|
|
202
|
+
}
|
|
203
|
+
};
|
|
188
204
|
watch(isInitialized, newIsInitialized => {
|
|
189
205
|
if (newIsInitialized && !finalConfig.value) {
|
|
190
206
|
finalConfig.value = defineWagmiConfig();
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
reconnectOnMount: false
|
|
194
|
-
}, props.config));
|
|
195
|
-
}
|
|
207
|
+
hydrateWagmiConfig();
|
|
208
|
+
configKey.value = randomId();
|
|
196
209
|
}
|
|
197
210
|
}, {
|
|
198
211
|
immediate: true
|
|
199
212
|
});
|
|
213
|
+
if (!isInitialized.value) {
|
|
214
|
+
hydrateWagmiConfig();
|
|
215
|
+
}
|
|
200
216
|
return {
|
|
201
|
-
finalConfig
|
|
217
|
+
finalConfig,
|
|
218
|
+
configKey
|
|
202
219
|
};
|
|
203
220
|
},
|
|
204
221
|
render() {
|
|
205
222
|
if (!this.finalConfig) return null;
|
|
206
|
-
return h(Web3AuthWagmiInnerProvider,
|
|
207
|
-
|
|
223
|
+
return h(Web3AuthWagmiInnerProvider,
|
|
224
|
+
// This key is used to remount the provider when the config changes.
|
|
225
|
+
{
|
|
226
|
+
config: this.finalConfig,
|
|
227
|
+
key: this.configKey
|
|
208
228
|
}, {
|
|
209
229
|
default: () => {
|
|
210
230
|
var _this$$slots$default3, _this$$slots;
|