@web3auth/no-modal 10.7.0 → 10.8.1
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/utils.js +1 -1
- package/dist/lib.cjs/connectors/coinbase-connector/coinbaseConnector.js +31 -6
- package/dist/lib.cjs/react/context/Web3AuthInnerContext.js +21 -1
- package/dist/lib.cjs/react/hooks/useChain.js +16 -0
- package/dist/lib.cjs/react/index.js +2 -0
- package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +14 -7
- package/dist/lib.cjs/react/wagmi/provider.js +19 -4
- package/dist/lib.cjs/types/base/hooks/index.d.ts +3 -0
- package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
- package/dist/lib.cjs/types/react/hooks/useChain.d.ts +6 -0
- package/dist/lib.cjs/types/react/hooks/useWeb3Auth.d.ts +1 -1
- package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
- package/dist/lib.cjs/types/vue/composables/useChain.d.ts +7 -0
- package/dist/lib.cjs/vue/composables/useChain.js +24 -0
- package/dist/lib.cjs/vue/index.js +2 -0
- package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +24 -9
- package/dist/lib.cjs/vue/wagmi/provider.js +21 -8
- package/dist/lib.esm/base/utils.js +1 -1
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +31 -6
- package/dist/lib.esm/react/context/Web3AuthInnerContext.js +21 -1
- package/dist/lib.esm/react/hooks/useChain.js +14 -0
- package/dist/lib.esm/react/index.js +1 -0
- package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +12 -7
- package/dist/lib.esm/react/wagmi/provider.js +18 -3
- package/dist/lib.esm/vue/composables/useChain.js +22 -0
- package/dist/lib.esm/vue/index.js +1 -0
- package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +25 -10
- package/dist/lib.esm/vue/wagmi/provider.js +21 -8
- package/package.json +2 -2
|
@@ -145,7 +145,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
|
|
|
145
145
|
ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig1 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig1 === void 0 ? void 0 : _walletServicesConfig1.defaultPortfolio
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
|
-
const sdkVersion = "10.
|
|
148
|
+
const sdkVersion = "10.8.1";
|
|
149
149
|
const getErrorAnalyticsProperties = error => {
|
|
150
150
|
try {
|
|
151
151
|
const code = error instanceof index.Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
|
|
@@ -147,12 +147,37 @@ class CoinbaseConnector extends baseEvmConnector.BaseEvmConnector {
|
|
|
147
147
|
}
|
|
148
148
|
async switchChain(params, init = false) {
|
|
149
149
|
super.checkSwitchChainRequirements(params, init);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
try {
|
|
151
|
+
await this.coinbaseProvider.request({
|
|
152
|
+
method: "wallet_switchEthereumChain",
|
|
153
|
+
params: [{
|
|
154
|
+
chainId: params.chainId
|
|
155
|
+
}]
|
|
156
|
+
});
|
|
157
|
+
} catch (switchError) {
|
|
158
|
+
// 4902 indicates that the client does not recognize the Harmony One network
|
|
159
|
+
if (switchError.code === 4902) {
|
|
160
|
+
const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId);
|
|
161
|
+
if (!chainConfig) throw index$1.WalletLoginError.connectionError("Chain config is not available");
|
|
162
|
+
await this.coinbaseProvider.request({
|
|
163
|
+
method: "wallet_addEthereumChain",
|
|
164
|
+
params: [{
|
|
165
|
+
chainId: chainConfig.chainId,
|
|
166
|
+
rpcUrls: [chainConfig.rpcTarget],
|
|
167
|
+
chainName: chainConfig.displayName,
|
|
168
|
+
nativeCurrency: {
|
|
169
|
+
name: chainConfig.tickerName,
|
|
170
|
+
symbol: chainConfig.ticker,
|
|
171
|
+
decimals: chainConfig.decimals || 18
|
|
172
|
+
},
|
|
173
|
+
blockExplorerUrls: [chainConfig.blockExplorerUrl],
|
|
174
|
+
iconUrls: [chainConfig.logo]
|
|
175
|
+
}]
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
throw switchError;
|
|
180
|
+
}
|
|
156
181
|
}
|
|
157
182
|
async enableMFA() {
|
|
158
183
|
throw new Error("Method Not implemented");
|
|
@@ -30,6 +30,8 @@ function Web3AuthInnerProvider(params) {
|
|
|
30
30
|
setProvider(null);
|
|
31
31
|
return new noModal.Web3AuthNoModal(web3AuthOptions, initialState);
|
|
32
32
|
}, [web3AuthOptions, initialState]);
|
|
33
|
+
const [chainId, setChainId] = react.useState(null);
|
|
34
|
+
const [chainNamespace, setChainNamespace] = react.useState(null);
|
|
33
35
|
const [isInitializing, setIsInitializing] = react.useState(false);
|
|
34
36
|
const [initError, setInitError] = react.useState(null);
|
|
35
37
|
const [isConnected, setIsConnected] = react.useState(false);
|
|
@@ -45,6 +47,7 @@ function Web3AuthInnerProvider(params) {
|
|
|
45
47
|
const controller = new AbortController();
|
|
46
48
|
async function init() {
|
|
47
49
|
try {
|
|
50
|
+
var _web3Auth$currentChai;
|
|
48
51
|
setInitError(null);
|
|
49
52
|
setIsInitializing(true);
|
|
50
53
|
web3Auth.setAnalyticsProperties({
|
|
@@ -53,6 +56,8 @@ function Web3AuthInnerProvider(params) {
|
|
|
53
56
|
await web3Auth.init({
|
|
54
57
|
signal: controller.signal
|
|
55
58
|
});
|
|
59
|
+
setChainId(web3Auth.currentChainId);
|
|
60
|
+
setChainNamespace((_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainNamespace);
|
|
56
61
|
} catch (error) {
|
|
57
62
|
setInitError(error);
|
|
58
63
|
} finally {
|
|
@@ -64,6 +69,19 @@ function Web3AuthInnerProvider(params) {
|
|
|
64
69
|
controller.abort();
|
|
65
70
|
};
|
|
66
71
|
}, [web3Auth]);
|
|
72
|
+
react.useEffect(() => {
|
|
73
|
+
const handleChainChange = async chainId => {
|
|
74
|
+
var _web3Auth$currentChai2;
|
|
75
|
+
setChainId(chainId);
|
|
76
|
+
setChainNamespace(web3Auth === null || web3Auth === void 0 || (_web3Auth$currentChai2 = web3Auth.currentChain) === null || _web3Auth$currentChai2 === void 0 ? void 0 : _web3Auth$currentChai2.chainNamespace);
|
|
77
|
+
};
|
|
78
|
+
if (provider) {
|
|
79
|
+
provider.on("chainChanged", handleChainChange);
|
|
80
|
+
return () => {
|
|
81
|
+
provider.off("chainChanged", handleChainChange);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}, [web3Auth, provider]);
|
|
67
85
|
react.useEffect(() => {
|
|
68
86
|
const notReadyListener = () => setStatus(constants.CONNECTOR_STATUS.NOT_READY);
|
|
69
87
|
const readyListener = () => {
|
|
@@ -133,10 +151,12 @@ function Web3AuthInnerProvider(params) {
|
|
|
133
151
|
isInitializing,
|
|
134
152
|
initError,
|
|
135
153
|
isMFAEnabled,
|
|
154
|
+
chainId,
|
|
155
|
+
chainNamespace,
|
|
136
156
|
getPlugin,
|
|
137
157
|
setIsMFAEnabled
|
|
138
158
|
};
|
|
139
|
-
}, [web3Auth, isConnected, isInitialized, provider, status, getPlugin, isInitializing, initError, isMFAEnabled, setIsMFAEnabled]);
|
|
159
|
+
}, [web3Auth, isConnected, isInitialized, provider, status, getPlugin, isInitializing, initError, isMFAEnabled, setIsMFAEnabled, chainId, chainNamespace]);
|
|
140
160
|
return react.createElement(Web3AuthInnerContext.Provider, {
|
|
141
161
|
value
|
|
142
162
|
}, children);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
4
|
+
|
|
5
|
+
const useChain = () => {
|
|
6
|
+
const {
|
|
7
|
+
chainId,
|
|
8
|
+
chainNamespace
|
|
9
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
10
|
+
return {
|
|
11
|
+
chainId,
|
|
12
|
+
chainNamespace
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.useChain = useChain;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var useChain = require('./hooks/useChain.js');
|
|
3
4
|
var useCheckout = require('./hooks/useCheckout.js');
|
|
4
5
|
var useEnableMFA = require('./hooks/useEnableMFA.js');
|
|
5
6
|
var useFunding = require('./hooks/useFunding.js');
|
|
@@ -19,6 +20,7 @@ var Web3AuthProvider = require('./Web3AuthProvider.js');
|
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
|
|
23
|
+
exports.useChain = useChain.useChain;
|
|
22
24
|
exports.useCheckout = useCheckout.useCheckout;
|
|
23
25
|
exports.useEnableMFA = useEnableMFA.useEnableMFA;
|
|
24
26
|
exports.useFunding = useFunding.useFunding;
|
|
@@ -23,6 +23,9 @@ require('../../../providers/base-provider/CommonJRPCProvider.js');
|
|
|
23
23
|
require('../../../providers/base-provider/commonPrivateKeyProvider.js');
|
|
24
24
|
require('@web3auth/ws-embed');
|
|
25
25
|
var solanaWallet = require('../../../providers/solana-provider/solanaWallet.js');
|
|
26
|
+
var useChain = require('../../hooks/useChain.js');
|
|
27
|
+
require('../../context/WalletServicesInnerContext.js');
|
|
28
|
+
require('../../context/Web3AuthInnerContext.js');
|
|
26
29
|
var useWeb3Auth = require('../../hooks/useWeb3Auth.js');
|
|
27
30
|
|
|
28
31
|
const useSolanaWallet = () => {
|
|
@@ -30,29 +33,33 @@ const useSolanaWallet = () => {
|
|
|
30
33
|
provider,
|
|
31
34
|
web3Auth
|
|
32
35
|
} = useWeb3Auth.useWeb3Auth();
|
|
36
|
+
const {
|
|
37
|
+
chainNamespace
|
|
38
|
+
} = useChain.useChain();
|
|
33
39
|
const [accounts, setAccounts] = react.useState(null);
|
|
34
40
|
const solanaWallet$1 = react.useMemo(() => {
|
|
35
41
|
if (!provider) return null;
|
|
42
|
+
if (chainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) return null;
|
|
36
43
|
return new solanaWallet.SolanaWallet(provider);
|
|
37
|
-
}, [provider]);
|
|
44
|
+
}, [provider, chainNamespace]);
|
|
38
45
|
const connection = react.useMemo(() => {
|
|
39
|
-
if (!web3Auth || !provider) return null;
|
|
46
|
+
if (!web3Auth || !provider || chainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) return null;
|
|
40
47
|
return new web3_js.Connection(web3Auth.currentChain.rpcTarget);
|
|
41
|
-
}, [web3Auth, provider]);
|
|
48
|
+
}, [web3Auth, provider, chainNamespace]);
|
|
42
49
|
react.useEffect(() => {
|
|
43
50
|
const init = async () => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (!(web3Auth !== null && web3Auth !== void 0 && (_web3Auth$currentChai = web3Auth.currentChain) !== null && _web3Auth$currentChai !== void 0 && _web3Auth$currentChai.chainNamespace) || web3Auth.currentChain.chainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
51
|
+
if (chainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
52
|
+
setAccounts(null);
|
|
47
53
|
return;
|
|
48
54
|
}
|
|
55
|
+
if (!solanaWallet$1) return;
|
|
49
56
|
const accounts = await solanaWallet$1.getAccounts();
|
|
50
57
|
if ((accounts === null || accounts === void 0 ? void 0 : accounts.length) > 0) {
|
|
51
58
|
setAccounts(accounts);
|
|
52
59
|
}
|
|
53
60
|
};
|
|
54
61
|
if (solanaWallet$1) init();
|
|
55
|
-
}, [solanaWallet$1]);
|
|
62
|
+
}, [solanaWallet$1, chainNamespace]);
|
|
56
63
|
return {
|
|
57
64
|
solanaWallet: solanaWallet$1,
|
|
58
65
|
accounts,
|
|
@@ -19,18 +19,21 @@ require('../../base/plugin/errors.js');
|
|
|
19
19
|
require('../../base/plugin/IPlugin.js');
|
|
20
20
|
require('@toruslabs/constants');
|
|
21
21
|
require('@toruslabs/http-helpers');
|
|
22
|
-
require('../context/WalletServicesInnerContext.js');
|
|
23
22
|
require('../context/Web3AuthInnerContext.js');
|
|
23
|
+
require('../context/WalletServicesInnerContext.js');
|
|
24
24
|
var useWeb3Auth = require('../hooks/useWeb3Auth.js');
|
|
25
25
|
var useWeb3AuthDisconnect = require('../hooks/useWeb3AuthDisconnect.js');
|
|
26
26
|
var constants = require('./constants.js');
|
|
27
27
|
|
|
28
28
|
const _excluded = ["children"];
|
|
29
29
|
const WEB3AUTH_CONNECTOR_ID = "web3auth";
|
|
30
|
+
function getWeb3authConnector(config) {
|
|
31
|
+
return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
|
|
32
|
+
}
|
|
30
33
|
// Helper to initialize connectors for the given wallets
|
|
31
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
35
|
async function setupConnector(provider, config) {
|
|
33
|
-
let connector = config
|
|
36
|
+
let connector = getWeb3authConnector(config);
|
|
34
37
|
if (connector) return connector;
|
|
35
38
|
// Create new connector if not already existing
|
|
36
39
|
connector = connectors.injected({
|
|
@@ -65,8 +68,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
|
|
|
65
68
|
status: "connected"
|
|
66
69
|
}));
|
|
67
70
|
}
|
|
68
|
-
|
|
71
|
+
function resetConnectorState(config) {
|
|
69
72
|
config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
|
|
73
|
+
config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
|
|
74
|
+
}
|
|
75
|
+
async function disconnectWeb3AuthFromWagmi(config) {
|
|
76
|
+
var _config$storage3, _config$storage4;
|
|
77
|
+
const connector = getWeb3authConnector(config);
|
|
78
|
+
await Promise.all([(_config$storage3 = config.storage) === null || _config$storage3 === void 0 ? void 0 : _config$storage3.setItem(`${connector === null || connector === void 0 ? void 0 : connector.id}.disconnected`, true), (_config$storage4 = config.storage) === null || _config$storage4 === void 0 ? void 0 : _config$storage4.removeItem("injected.connected")]);
|
|
79
|
+
resetConnectorState(config);
|
|
70
80
|
config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
|
|
71
81
|
chainId: state.chainId,
|
|
72
82
|
connections: new Map(),
|
|
@@ -92,6 +102,12 @@ function Web3AuthWagmiProvider({
|
|
|
92
102
|
onDisconnect: async () => {
|
|
93
103
|
loglevel.log.info("Disconnected from wagmi");
|
|
94
104
|
if (isConnected) await disconnect();
|
|
105
|
+
const connector = getWeb3authConnector(wagmiConfig);
|
|
106
|
+
// reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
|
|
107
|
+
// from the connected provider
|
|
108
|
+
if (connector) {
|
|
109
|
+
resetConnectorState(wagmiConfig);
|
|
110
|
+
}
|
|
95
111
|
}
|
|
96
112
|
});
|
|
97
113
|
react.useEffect(() => {
|
|
@@ -192,7 +208,6 @@ function WagmiProvider(_ref) {
|
|
|
192
208
|
});
|
|
193
209
|
finalConfig.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
|
|
194
210
|
}
|
|
195
|
-
if (!finalConfig.chains) return;
|
|
196
211
|
return wagmi.createConfig(finalConfig);
|
|
197
212
|
}, [config, web3Auth, isInitialized]);
|
|
198
213
|
return react.createElement(wagmi.WagmiProvider, // typecast to WagmiProviderPropsBase to avoid type error
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type { ChainNamespaceType } from "../chain/IChainInterface";
|
|
1
2
|
import { CONNECTOR_STATUS_TYPE, IProvider } from "../connector";
|
|
2
3
|
import { IPlugin } from "../plugin";
|
|
3
4
|
export interface IBaseWeb3AuthHookContext {
|
|
5
|
+
chainId: string | null;
|
|
6
|
+
chainNamespace: ChainNamespaceType | null;
|
|
4
7
|
isInitialized: boolean;
|
|
5
8
|
isInitializing: boolean;
|
|
6
9
|
initError: unknown;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IWeb3AuthInnerContext } from "../interfaces";
|
|
2
|
-
export type IUseWeb3Auth = Omit<IWeb3AuthInnerContext, "isMFAEnabled" | "setIsMFAEnabled">;
|
|
2
|
+
export type IUseWeb3Auth = Omit<IWeb3AuthInnerContext, "isMFAEnabled" | "setIsMFAEnabled" | "chainId" | "chainNamespace">;
|
|
3
3
|
export declare const useWeb3Auth: () => IUseWeb3Auth;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vue = require('vue');
|
|
4
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
5
|
+
|
|
6
|
+
const useChain = () => {
|
|
7
|
+
const context = useWeb3AuthInner.useWeb3AuthInner();
|
|
8
|
+
const chainId = vue.computed(() => {
|
|
9
|
+
var _context$web3Auth$val;
|
|
10
|
+
if (!((_context$web3Auth$val = context.web3Auth.value) !== null && _context$web3Auth$val !== void 0 && _context$web3Auth$val.currentChain)) return null;
|
|
11
|
+
return context.web3Auth.value.currentChain.chainId;
|
|
12
|
+
});
|
|
13
|
+
const chainNamespace = vue.computed(() => {
|
|
14
|
+
var _context$web3Auth$val2;
|
|
15
|
+
if (!((_context$web3Auth$val2 = context.web3Auth.value) !== null && _context$web3Auth$val2 !== void 0 && _context$web3Auth$val2.currentChain)) return null;
|
|
16
|
+
return context.web3Auth.value.currentChain.chainNamespace;
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
chainId,
|
|
20
|
+
chainNamespace
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.useChain = useChain;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var useChain = require('./composables/useChain.js');
|
|
3
4
|
var useCheckout = require('./composables/useCheckout.js');
|
|
4
5
|
var useEnableMFA = require('./composables/useEnableMFA.js');
|
|
5
6
|
var useFunding = require('./composables/useFunding.js');
|
|
@@ -20,6 +21,7 @@ var Web3AuthProvider = require('./Web3AuthProvider.js');
|
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
|
|
24
|
+
exports.useChain = useChain.useChain;
|
|
23
25
|
exports.useCheckout = useCheckout.useCheckout;
|
|
24
26
|
exports.useEnableMFA = useEnableMFA.useEnableMFA;
|
|
25
27
|
exports.useFunding = useFunding.useFunding;
|
|
@@ -4,6 +4,7 @@ var web3_js = require('@solana/web3.js');
|
|
|
4
4
|
var vue = require('vue');
|
|
5
5
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
6
6
|
var solanaWallet = require('../../../providers/solana-provider/solanaWallet.js');
|
|
7
|
+
var useChain = require('../../composables/useChain.js');
|
|
7
8
|
require('@babel/runtime/helpers/objectSpread2');
|
|
8
9
|
require('@babel/runtime/helpers/defineProperty');
|
|
9
10
|
require('@segment/analytics-next');
|
|
@@ -24,12 +25,19 @@ const useSolanaWallet = () => {
|
|
|
24
25
|
provider,
|
|
25
26
|
web3Auth
|
|
26
27
|
} = useWeb3Auth.useWeb3Auth();
|
|
28
|
+
const {
|
|
29
|
+
chainNamespace
|
|
30
|
+
} = useChain.useChain();
|
|
27
31
|
const accounts = vue.ref([]);
|
|
28
32
|
const solanaWallet$1 = vue.shallowRef(null);
|
|
29
33
|
const connection = vue.shallowRef(null);
|
|
34
|
+
const isSolana = vue.computed(() => chainNamespace.value === baseControllers.CHAIN_NAMESPACES.SOLANA);
|
|
30
35
|
const setupWallet = async () => {
|
|
31
|
-
var _web3Auth$value
|
|
32
|
-
if (!
|
|
36
|
+
var _web3Auth$value;
|
|
37
|
+
if (!isSolana.value) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!provider.value) {
|
|
33
41
|
return;
|
|
34
42
|
}
|
|
35
43
|
solanaWallet$1.value = new solanaWallet.SolanaWallet(provider.value);
|
|
@@ -37,19 +45,26 @@ const useSolanaWallet = () => {
|
|
|
37
45
|
if ((result === null || result === void 0 ? void 0 : result.length) > 0) {
|
|
38
46
|
accounts.value = result;
|
|
39
47
|
}
|
|
40
|
-
|
|
48
|
+
if ((_web3Auth$value = web3Auth.value) !== null && _web3Auth$value !== void 0 && (_web3Auth$value = _web3Auth$value.currentChain) !== null && _web3Auth$value !== void 0 && _web3Auth$value.rpcTarget) {
|
|
49
|
+
connection.value = new web3_js.Connection(web3Auth.value.currentChain.rpcTarget);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const resetWallet = () => {
|
|
53
|
+
solanaWallet$1.value = null;
|
|
54
|
+
accounts.value = null;
|
|
55
|
+
connection.value = null;
|
|
41
56
|
};
|
|
42
57
|
if (provider.value && !solanaWallet$1.value) {
|
|
43
58
|
setupWallet();
|
|
44
59
|
}
|
|
45
|
-
vue.watch(provider, async
|
|
46
|
-
if (!
|
|
47
|
-
solanaWallet$1.value
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
vue.watch([provider, chainNamespace], async ([newProvider, newChainNamespace]) => {
|
|
61
|
+
if (!newProvider || newChainNamespace !== baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
62
|
+
if (solanaWallet$1.value) {
|
|
63
|
+
resetWallet();
|
|
64
|
+
}
|
|
50
65
|
return;
|
|
51
66
|
}
|
|
52
|
-
if (
|
|
67
|
+
if (newProvider && !solanaWallet$1.value) {
|
|
53
68
|
setupWallet();
|
|
54
69
|
}
|
|
55
70
|
}, {
|
|
@@ -24,10 +24,13 @@ var useWeb3AuthDisconnect = require('../composables/useWeb3AuthDisconnect.js');
|
|
|
24
24
|
var constants = require('./constants.js');
|
|
25
25
|
|
|
26
26
|
const WEB3AUTH_CONNECTOR_ID = "web3auth";
|
|
27
|
+
function getWeb3authConnector(config) {
|
|
28
|
+
return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
|
|
29
|
+
}
|
|
27
30
|
// Helper to initialize connectors for the given wallets
|
|
28
31
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
32
|
async function setupConnector(provider, config) {
|
|
30
|
-
let connector = config
|
|
33
|
+
let connector = getWeb3authConnector(config);
|
|
31
34
|
if (connector) return connector;
|
|
32
35
|
// Create new connector if not already existing
|
|
33
36
|
connector = connectors.injected({
|
|
@@ -62,8 +65,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
|
|
|
62
65
|
status: "connected"
|
|
63
66
|
}));
|
|
64
67
|
}
|
|
65
|
-
|
|
68
|
+
function resetConnectorState(config) {
|
|
66
69
|
config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
|
|
70
|
+
config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
|
|
71
|
+
}
|
|
72
|
+
async function disconnectWeb3AuthFromWagmi(config) {
|
|
73
|
+
var _config$storage3, _config$storage4;
|
|
74
|
+
const connector = getWeb3authConnector(config);
|
|
75
|
+
await Promise.all([(_config$storage3 = config.storage) === null || _config$storage3 === void 0 ? void 0 : _config$storage3.setItem(`${connector === null || connector === void 0 ? void 0 : connector.id}.disconnected`, true), (_config$storage4 = config.storage) === null || _config$storage4 === void 0 ? void 0 : _config$storage4.removeItem("injected.connected")]);
|
|
76
|
+
resetConnectorState(config);
|
|
67
77
|
config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
|
|
68
78
|
chainId: state.chainId,
|
|
69
79
|
connections: new Map(),
|
|
@@ -89,6 +99,12 @@ const Web3AuthWagmiProvider = vue.defineComponent({
|
|
|
89
99
|
onDisconnect: async () => {
|
|
90
100
|
loglevel.log.info("Disconnected from wagmi");
|
|
91
101
|
if (isConnected.value) await disconnect();
|
|
102
|
+
const connector = getWeb3authConnector(wagmiConfig);
|
|
103
|
+
// reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
|
|
104
|
+
// from the connected provider
|
|
105
|
+
if (connector) {
|
|
106
|
+
resetConnectorState(wagmiConfig);
|
|
107
|
+
}
|
|
92
108
|
}
|
|
93
109
|
});
|
|
94
110
|
vue.watch(isConnected, async newIsConnected => {
|
|
@@ -223,12 +239,12 @@ const WagmiProvider = vue.defineComponent({
|
|
|
223
239
|
}, props.config));
|
|
224
240
|
}
|
|
225
241
|
};
|
|
226
|
-
vue.watch(isInitialized, newIsInitialized => {
|
|
242
|
+
vue.watch(isInitialized, (newIsInitialized, prevIsInitialized) => {
|
|
227
243
|
var _web3Auth$value2;
|
|
228
244
|
(_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 || _web3Auth$value2.setAnalyticsProperties({
|
|
229
245
|
wagmi_enabled: true
|
|
230
246
|
});
|
|
231
|
-
if (newIsInitialized && !
|
|
247
|
+
if (newIsInitialized && !prevIsInitialized) {
|
|
232
248
|
finalConfig.value = defineWagmiConfig();
|
|
233
249
|
hydrateWagmiConfig();
|
|
234
250
|
configKey.value = auth.randomId();
|
|
@@ -245,10 +261,7 @@ const WagmiProvider = vue.defineComponent({
|
|
|
245
261
|
};
|
|
246
262
|
},
|
|
247
263
|
render() {
|
|
248
|
-
|
|
249
|
-
return vue.h(Web3AuthWagmiInnerProvider,
|
|
250
|
-
// This key is used to remount the provider when the config changes.
|
|
251
|
-
{
|
|
264
|
+
return vue.h(Web3AuthWagmiInnerProvider, {
|
|
252
265
|
config: this.finalConfig,
|
|
253
266
|
key: this.configKey
|
|
254
267
|
}, {
|
|
@@ -145,7 +145,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
|
|
|
145
145
|
ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig1 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig1 === void 0 ? void 0 : _walletServicesConfig1.defaultPortfolio
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
|
-
const sdkVersion = "10.
|
|
148
|
+
const sdkVersion = "10.8.1";
|
|
149
149
|
const getErrorAnalyticsProperties = error => {
|
|
150
150
|
try {
|
|
151
151
|
const code = error instanceof Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
|
|
@@ -137,12 +137,37 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
137
137
|
}
|
|
138
138
|
async switchChain(params, init = false) {
|
|
139
139
|
super.checkSwitchChainRequirements(params, init);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
try {
|
|
141
|
+
await this.coinbaseProvider.request({
|
|
142
|
+
method: "wallet_switchEthereumChain",
|
|
143
|
+
params: [{
|
|
144
|
+
chainId: params.chainId
|
|
145
|
+
}]
|
|
146
|
+
});
|
|
147
|
+
} catch (switchError) {
|
|
148
|
+
// 4902 indicates that the client does not recognize the Harmony One network
|
|
149
|
+
if (switchError.code === 4902) {
|
|
150
|
+
const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId);
|
|
151
|
+
if (!chainConfig) throw WalletLoginError.connectionError("Chain config is not available");
|
|
152
|
+
await this.coinbaseProvider.request({
|
|
153
|
+
method: "wallet_addEthereumChain",
|
|
154
|
+
params: [{
|
|
155
|
+
chainId: chainConfig.chainId,
|
|
156
|
+
rpcUrls: [chainConfig.rpcTarget],
|
|
157
|
+
chainName: chainConfig.displayName,
|
|
158
|
+
nativeCurrency: {
|
|
159
|
+
name: chainConfig.tickerName,
|
|
160
|
+
symbol: chainConfig.ticker,
|
|
161
|
+
decimals: chainConfig.decimals || 18
|
|
162
|
+
},
|
|
163
|
+
blockExplorerUrls: [chainConfig.blockExplorerUrl],
|
|
164
|
+
iconUrls: [chainConfig.logo]
|
|
165
|
+
}]
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
throw switchError;
|
|
170
|
+
}
|
|
146
171
|
}
|
|
147
172
|
async enableMFA() {
|
|
148
173
|
throw new Error("Method Not implemented");
|
|
@@ -18,6 +18,8 @@ function Web3AuthInnerProvider(params) {
|
|
|
18
18
|
setProvider(null);
|
|
19
19
|
return new Web3AuthNoModal(web3AuthOptions, initialState);
|
|
20
20
|
}, [web3AuthOptions, initialState]);
|
|
21
|
+
const [chainId, setChainId] = useState(null);
|
|
22
|
+
const [chainNamespace, setChainNamespace] = useState(null);
|
|
21
23
|
const [isInitializing, setIsInitializing] = useState(false);
|
|
22
24
|
const [initError, setInitError] = useState(null);
|
|
23
25
|
const [isConnected, setIsConnected] = useState(false);
|
|
@@ -33,6 +35,7 @@ function Web3AuthInnerProvider(params) {
|
|
|
33
35
|
const controller = new AbortController();
|
|
34
36
|
async function init() {
|
|
35
37
|
try {
|
|
38
|
+
var _web3Auth$currentChai;
|
|
36
39
|
setInitError(null);
|
|
37
40
|
setIsInitializing(true);
|
|
38
41
|
web3Auth.setAnalyticsProperties({
|
|
@@ -41,6 +44,8 @@ function Web3AuthInnerProvider(params) {
|
|
|
41
44
|
await web3Auth.init({
|
|
42
45
|
signal: controller.signal
|
|
43
46
|
});
|
|
47
|
+
setChainId(web3Auth.currentChainId);
|
|
48
|
+
setChainNamespace((_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainNamespace);
|
|
44
49
|
} catch (error) {
|
|
45
50
|
setInitError(error);
|
|
46
51
|
} finally {
|
|
@@ -52,6 +57,19 @@ function Web3AuthInnerProvider(params) {
|
|
|
52
57
|
controller.abort();
|
|
53
58
|
};
|
|
54
59
|
}, [web3Auth]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const handleChainChange = async chainId => {
|
|
62
|
+
var _web3Auth$currentChai2;
|
|
63
|
+
setChainId(chainId);
|
|
64
|
+
setChainNamespace(web3Auth === null || web3Auth === void 0 || (_web3Auth$currentChai2 = web3Auth.currentChain) === null || _web3Auth$currentChai2 === void 0 ? void 0 : _web3Auth$currentChai2.chainNamespace);
|
|
65
|
+
};
|
|
66
|
+
if (provider) {
|
|
67
|
+
provider.on("chainChanged", handleChainChange);
|
|
68
|
+
return () => {
|
|
69
|
+
provider.off("chainChanged", handleChainChange);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}, [web3Auth, provider]);
|
|
55
73
|
useEffect(() => {
|
|
56
74
|
const notReadyListener = () => setStatus(CONNECTOR_STATUS.NOT_READY);
|
|
57
75
|
const readyListener = () => {
|
|
@@ -121,10 +139,12 @@ function Web3AuthInnerProvider(params) {
|
|
|
121
139
|
isInitializing,
|
|
122
140
|
initError,
|
|
123
141
|
isMFAEnabled,
|
|
142
|
+
chainId,
|
|
143
|
+
chainNamespace,
|
|
124
144
|
getPlugin,
|
|
125
145
|
setIsMFAEnabled
|
|
126
146
|
};
|
|
127
|
-
}, [web3Auth, isConnected, isInitialized, provider, status, getPlugin, isInitializing, initError, isMFAEnabled, setIsMFAEnabled]);
|
|
147
|
+
}, [web3Auth, isConnected, isInitialized, provider, status, getPlugin, isInitializing, initError, isMFAEnabled, setIsMFAEnabled, chainId, chainNamespace]);
|
|
128
148
|
return createElement(Web3AuthInnerContext.Provider, {
|
|
129
149
|
value
|
|
130
150
|
}, children);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Web3AuthProvider } from './Web3AuthProvider.js';
|
|
2
|
+
export { useChain } from './hooks/useChain.js';
|
|
2
3
|
export { useCheckout } from './hooks/useCheckout.js';
|
|
3
4
|
export { useEnableMFA } from './hooks/useEnableMFA.js';
|
|
4
5
|
export { useFunding } from './hooks/useFunding.js';
|
|
@@ -2,6 +2,7 @@ import { Connection } from '@solana/web3.js';
|
|
|
2
2
|
import { useState, useMemo, useEffect } from 'react';
|
|
3
3
|
import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
4
4
|
import { useWeb3Auth } from '../../hooks/useWeb3Auth.js';
|
|
5
|
+
import { useChain } from '../../hooks/useChain.js';
|
|
5
6
|
import { SolanaWallet } from '../../../providers/solana-provider/solanaWallet.js';
|
|
6
7
|
|
|
7
8
|
const useSolanaWallet = () => {
|
|
@@ -9,29 +10,33 @@ const useSolanaWallet = () => {
|
|
|
9
10
|
provider,
|
|
10
11
|
web3Auth
|
|
11
12
|
} = useWeb3Auth();
|
|
13
|
+
const {
|
|
14
|
+
chainNamespace
|
|
15
|
+
} = useChain();
|
|
12
16
|
const [accounts, setAccounts] = useState(null);
|
|
13
17
|
const solanaWallet = useMemo(() => {
|
|
14
18
|
if (!provider) return null;
|
|
19
|
+
if (chainNamespace !== CHAIN_NAMESPACES.SOLANA) return null;
|
|
15
20
|
return new SolanaWallet(provider);
|
|
16
|
-
}, [provider]);
|
|
21
|
+
}, [provider, chainNamespace]);
|
|
17
22
|
const connection = useMemo(() => {
|
|
18
|
-
if (!web3Auth || !provider) return null;
|
|
23
|
+
if (!web3Auth || !provider || chainNamespace !== CHAIN_NAMESPACES.SOLANA) return null;
|
|
19
24
|
return new Connection(web3Auth.currentChain.rpcTarget);
|
|
20
|
-
}, [web3Auth, provider]);
|
|
25
|
+
}, [web3Auth, provider, chainNamespace]);
|
|
21
26
|
useEffect(() => {
|
|
22
27
|
const init = async () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!(web3Auth !== null && web3Auth !== void 0 && (_web3Auth$currentChai = web3Auth.currentChain) !== null && _web3Auth$currentChai !== void 0 && _web3Auth$currentChai.chainNamespace) || web3Auth.currentChain.chainNamespace !== CHAIN_NAMESPACES.SOLANA) {
|
|
28
|
+
if (chainNamespace !== CHAIN_NAMESPACES.SOLANA) {
|
|
29
|
+
setAccounts(null);
|
|
26
30
|
return;
|
|
27
31
|
}
|
|
32
|
+
if (!solanaWallet) return;
|
|
28
33
|
const accounts = await solanaWallet.getAccounts();
|
|
29
34
|
if ((accounts === null || accounts === void 0 ? void 0 : accounts.length) > 0) {
|
|
30
35
|
setAccounts(accounts);
|
|
31
36
|
}
|
|
32
37
|
};
|
|
33
38
|
if (solanaWallet) init();
|
|
34
|
-
}, [solanaWallet]);
|
|
39
|
+
}, [solanaWallet, chainNamespace]);
|
|
35
40
|
return {
|
|
36
41
|
solanaWallet,
|
|
37
42
|
accounts,
|
|
@@ -13,11 +13,14 @@ import { log } from '../../base/loglevel.js';
|
|
|
13
13
|
|
|
14
14
|
const _excluded = ["children"];
|
|
15
15
|
const WEB3AUTH_CONNECTOR_ID = "web3auth";
|
|
16
|
+
function getWeb3authConnector(config) {
|
|
17
|
+
return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
|
|
18
|
+
}
|
|
16
19
|
|
|
17
20
|
// Helper to initialize connectors for the given wallets
|
|
18
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
22
|
async function setupConnector(provider, config) {
|
|
20
|
-
let connector = config
|
|
23
|
+
let connector = getWeb3authConnector(config);
|
|
21
24
|
if (connector) return connector;
|
|
22
25
|
|
|
23
26
|
// Create new connector if not already existing
|
|
@@ -54,8 +57,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
|
|
|
54
57
|
status: "connected"
|
|
55
58
|
}));
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
function resetConnectorState(config) {
|
|
58
61
|
config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
|
|
62
|
+
config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
|
|
63
|
+
}
|
|
64
|
+
async function disconnectWeb3AuthFromWagmi(config) {
|
|
65
|
+
var _config$storage3, _config$storage4;
|
|
66
|
+
const connector = getWeb3authConnector(config);
|
|
67
|
+
await Promise.all([(_config$storage3 = config.storage) === null || _config$storage3 === void 0 ? void 0 : _config$storage3.setItem(`${connector === null || connector === void 0 ? void 0 : connector.id}.disconnected`, true), (_config$storage4 = config.storage) === null || _config$storage4 === void 0 ? void 0 : _config$storage4.removeItem("injected.connected")]);
|
|
68
|
+
resetConnectorState(config);
|
|
59
69
|
config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
|
|
60
70
|
chainId: state.chainId,
|
|
61
71
|
connections: new Map(),
|
|
@@ -81,6 +91,12 @@ function Web3AuthWagmiProvider({
|
|
|
81
91
|
onDisconnect: async () => {
|
|
82
92
|
log.info("Disconnected from wagmi");
|
|
83
93
|
if (isConnected) await disconnect();
|
|
94
|
+
const connector = getWeb3authConnector(wagmiConfig);
|
|
95
|
+
// reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
|
|
96
|
+
// from the connected provider
|
|
97
|
+
if (connector) {
|
|
98
|
+
resetConnectorState(wagmiConfig);
|
|
99
|
+
}
|
|
84
100
|
}
|
|
85
101
|
});
|
|
86
102
|
useEffect(() => {
|
|
@@ -181,7 +197,6 @@ function WagmiProvider(_ref) {
|
|
|
181
197
|
});
|
|
182
198
|
finalConfig.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
|
|
183
199
|
}
|
|
184
|
-
if (!finalConfig.chains) return;
|
|
185
200
|
return createConfig(finalConfig);
|
|
186
201
|
}, [config, web3Auth, isInitialized]);
|
|
187
202
|
return createElement(WagmiProvider$1, // typecast to WagmiProviderPropsBase to avoid type error
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
import { useWeb3AuthInner } from './useWeb3AuthInner.js';
|
|
3
|
+
|
|
4
|
+
const useChain = () => {
|
|
5
|
+
const context = useWeb3AuthInner();
|
|
6
|
+
const chainId = computed(() => {
|
|
7
|
+
var _context$web3Auth$val;
|
|
8
|
+
if (!((_context$web3Auth$val = context.web3Auth.value) !== null && _context$web3Auth$val !== void 0 && _context$web3Auth$val.currentChain)) return null;
|
|
9
|
+
return context.web3Auth.value.currentChain.chainId;
|
|
10
|
+
});
|
|
11
|
+
const chainNamespace = computed(() => {
|
|
12
|
+
var _context$web3Auth$val2;
|
|
13
|
+
if (!((_context$web3Auth$val2 = context.web3Auth.value) !== null && _context$web3Auth$val2 !== void 0 && _context$web3Auth$val2.currentChain)) return null;
|
|
14
|
+
return context.web3Auth.value.currentChain.chainNamespace;
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
chainId,
|
|
18
|
+
chainNamespace
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { useChain };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Web3AuthProvider } from './Web3AuthProvider.js';
|
|
2
|
+
export { useChain } from './composables/useChain.js';
|
|
2
3
|
export { useCheckout } from './composables/useCheckout.js';
|
|
3
4
|
export { useEnableMFA } from './composables/useEnableMFA.js';
|
|
4
5
|
export { useFunding } from './composables/useFunding.js';
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { Connection } from '@solana/web3.js';
|
|
2
|
-
import { ref, shallowRef, watch } from 'vue';
|
|
2
|
+
import { ref, shallowRef, computed, watch } from 'vue';
|
|
3
3
|
import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
4
4
|
import { SolanaWallet } from '../../../providers/solana-provider/solanaWallet.js';
|
|
5
5
|
import { useWeb3Auth } from '../../composables/useWeb3Auth.js';
|
|
6
|
+
import { useChain } from '../../composables/useChain.js';
|
|
6
7
|
|
|
7
8
|
const useSolanaWallet = () => {
|
|
8
9
|
const {
|
|
9
10
|
provider,
|
|
10
11
|
web3Auth
|
|
11
12
|
} = useWeb3Auth();
|
|
13
|
+
const {
|
|
14
|
+
chainNamespace
|
|
15
|
+
} = useChain();
|
|
12
16
|
const accounts = ref([]);
|
|
13
17
|
const solanaWallet = shallowRef(null);
|
|
14
18
|
const connection = shallowRef(null);
|
|
19
|
+
const isSolana = computed(() => chainNamespace.value === CHAIN_NAMESPACES.SOLANA);
|
|
15
20
|
const setupWallet = async () => {
|
|
16
|
-
var _web3Auth$value
|
|
17
|
-
if (!
|
|
21
|
+
var _web3Auth$value;
|
|
22
|
+
if (!isSolana.value) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!provider.value) {
|
|
18
26
|
return;
|
|
19
27
|
}
|
|
20
28
|
solanaWallet.value = new SolanaWallet(provider.value);
|
|
@@ -22,19 +30,26 @@ const useSolanaWallet = () => {
|
|
|
22
30
|
if ((result === null || result === void 0 ? void 0 : result.length) > 0) {
|
|
23
31
|
accounts.value = result;
|
|
24
32
|
}
|
|
25
|
-
|
|
33
|
+
if ((_web3Auth$value = web3Auth.value) !== null && _web3Auth$value !== void 0 && (_web3Auth$value = _web3Auth$value.currentChain) !== null && _web3Auth$value !== void 0 && _web3Auth$value.rpcTarget) {
|
|
34
|
+
connection.value = new Connection(web3Auth.value.currentChain.rpcTarget);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const resetWallet = () => {
|
|
38
|
+
solanaWallet.value = null;
|
|
39
|
+
accounts.value = null;
|
|
40
|
+
connection.value = null;
|
|
26
41
|
};
|
|
27
42
|
if (provider.value && !solanaWallet.value) {
|
|
28
43
|
setupWallet();
|
|
29
44
|
}
|
|
30
|
-
watch(provider, async
|
|
31
|
-
if (!
|
|
32
|
-
solanaWallet.value
|
|
33
|
-
|
|
34
|
-
|
|
45
|
+
watch([provider, chainNamespace], async ([newProvider, newChainNamespace]) => {
|
|
46
|
+
if (!newProvider || newChainNamespace !== CHAIN_NAMESPACES.SOLANA) {
|
|
47
|
+
if (solanaWallet.value) {
|
|
48
|
+
resetWallet();
|
|
49
|
+
}
|
|
35
50
|
return;
|
|
36
51
|
}
|
|
37
|
-
if (
|
|
52
|
+
if (newProvider && !solanaWallet.value) {
|
|
38
53
|
setupWallet();
|
|
39
54
|
}
|
|
40
55
|
}, {
|
|
@@ -13,11 +13,14 @@ import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
|
13
13
|
import { WalletInitializationError } from '../../base/errors/index.js';
|
|
14
14
|
|
|
15
15
|
const WEB3AUTH_CONNECTOR_ID = "web3auth";
|
|
16
|
+
function getWeb3authConnector(config) {
|
|
17
|
+
return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
|
|
18
|
+
}
|
|
16
19
|
|
|
17
20
|
// Helper to initialize connectors for the given wallets
|
|
18
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
22
|
async function setupConnector(provider, config) {
|
|
20
|
-
let connector = config
|
|
23
|
+
let connector = getWeb3authConnector(config);
|
|
21
24
|
if (connector) return connector;
|
|
22
25
|
|
|
23
26
|
// Create new connector if not already existing
|
|
@@ -54,8 +57,15 @@ async function connectWeb3AuthWithWagmi(connector, config) {
|
|
|
54
57
|
status: "connected"
|
|
55
58
|
}));
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
function resetConnectorState(config) {
|
|
58
61
|
config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
|
|
62
|
+
config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
|
|
63
|
+
}
|
|
64
|
+
async function disconnectWeb3AuthFromWagmi(config) {
|
|
65
|
+
var _config$storage3, _config$storage4;
|
|
66
|
+
const connector = getWeb3authConnector(config);
|
|
67
|
+
await Promise.all([(_config$storage3 = config.storage) === null || _config$storage3 === void 0 ? void 0 : _config$storage3.setItem(`${connector === null || connector === void 0 ? void 0 : connector.id}.disconnected`, true), (_config$storage4 = config.storage) === null || _config$storage4 === void 0 ? void 0 : _config$storage4.removeItem("injected.connected")]);
|
|
68
|
+
resetConnectorState(config);
|
|
59
69
|
config.setState(state => _objectSpread(_objectSpread({}, state), {}, {
|
|
60
70
|
chainId: state.chainId,
|
|
61
71
|
connections: new Map(),
|
|
@@ -81,6 +91,12 @@ const Web3AuthWagmiProvider = defineComponent({
|
|
|
81
91
|
onDisconnect: async () => {
|
|
82
92
|
log.info("Disconnected from wagmi");
|
|
83
93
|
if (isConnected.value) await disconnect();
|
|
94
|
+
const connector = getWeb3authConnector(wagmiConfig);
|
|
95
|
+
// reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
|
|
96
|
+
// from the connected provider
|
|
97
|
+
if (connector) {
|
|
98
|
+
resetConnectorState(wagmiConfig);
|
|
99
|
+
}
|
|
84
100
|
}
|
|
85
101
|
});
|
|
86
102
|
watch(isConnected, async newIsConnected => {
|
|
@@ -215,12 +231,12 @@ const WagmiProvider = defineComponent({
|
|
|
215
231
|
}, props.config));
|
|
216
232
|
}
|
|
217
233
|
};
|
|
218
|
-
watch(isInitialized, newIsInitialized => {
|
|
234
|
+
watch(isInitialized, (newIsInitialized, prevIsInitialized) => {
|
|
219
235
|
var _web3Auth$value2;
|
|
220
236
|
(_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 || _web3Auth$value2.setAnalyticsProperties({
|
|
221
237
|
wagmi_enabled: true
|
|
222
238
|
});
|
|
223
|
-
if (newIsInitialized && !
|
|
239
|
+
if (newIsInitialized && !prevIsInitialized) {
|
|
224
240
|
finalConfig.value = defineWagmiConfig();
|
|
225
241
|
hydrateWagmiConfig();
|
|
226
242
|
configKey.value = randomId();
|
|
@@ -237,10 +253,7 @@ const WagmiProvider = defineComponent({
|
|
|
237
253
|
};
|
|
238
254
|
},
|
|
239
255
|
render() {
|
|
240
|
-
|
|
241
|
-
return h(Web3AuthWagmiInnerProvider,
|
|
242
|
-
// This key is used to remount the provider when the config changes.
|
|
243
|
-
{
|
|
256
|
+
return h(Web3AuthWagmiInnerProvider, {
|
|
244
257
|
config: this.finalConfig,
|
|
245
258
|
key: this.configKey
|
|
246
259
|
}, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web3auth/no-modal",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.8.1",
|
|
4
4
|
"description": "Multi chain wallet aggregator for web3Auth",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web3Auth/no-modal",
|
|
@@ -203,5 +203,5 @@
|
|
|
203
203
|
"node": ">=20.x",
|
|
204
204
|
"npm": ">=9.x"
|
|
205
205
|
},
|
|
206
|
-
"gitHead": "
|
|
206
|
+
"gitHead": "d93410531e87a465eba46ae0e9b645a6646ee0b4"
|
|
207
207
|
}
|