@web3auth/no-modal 11.1.0 → 11.2.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/account-linking/react.js +1 -0
- package/dist/lib.cjs/account-linking/vue.js +1 -0
- package/dist/lib.cjs/base/connector/baseConnector.js +42 -11
- package/dist/lib.cjs/base/errors/index.js +5 -1
- package/dist/lib.cjs/base/utils.js +1 -1
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +15 -6
- package/dist/lib.cjs/connectors/coinbase-connector/coinbaseConnector.js +5 -5
- package/dist/lib.cjs/connectors/injected-evm-connector/injectedEvmConnector.js +6 -5
- package/dist/lib.cjs/connectors/injected-solana-connector/walletStandardConnector.js +6 -5
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +82 -31
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +8 -6
- package/dist/lib.cjs/index.js +8 -7
- package/dist/lib.cjs/noModal.js +44 -21
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +9 -2
- package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +10 -0
- package/dist/lib.cjs/react/solana/provider.js +65 -32
- package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +2 -1
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +1 -0
- package/dist/lib.cjs/types/base/errors/index.d.ts +1 -0
- package/dist/lib.cjs/types/base/interfaces.d.ts +2 -1
- package/dist/lib.cjs/types/connectors/metamask-connector/metamaskConnector.d.ts +1 -0
- package/dist/lib.cjs/types/vue/solana/provider.d.ts +2 -2
- package/dist/lib.cjs/vue/solana/provider.js +55 -21
- package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +12 -2
- package/dist/lib.esm/base/connector/baseConnector.js +42 -11
- package/dist/lib.esm/base/errors/index.js +5 -1
- package/dist/lib.esm/base/utils.js +1 -1
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +13 -5
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +5 -5
- package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +6 -5
- package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +6 -5
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +86 -31
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +8 -7
- package/dist/lib.esm/index.js +1 -1
- package/dist/lib.esm/noModal.js +44 -21
- package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +9 -2
- package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +10 -0
- package/dist/lib.esm/react/solana/provider.js +64 -30
- package/dist/lib.esm/vue/solana/provider.js +55 -19
- package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +10 -0
- package/package.json +2 -2
package/dist/lib.cjs/noModal.js
CHANGED
|
@@ -7,6 +7,8 @@ var baseControllers = require('@toruslabs/base-controllers');
|
|
|
7
7
|
var ethereumControllers = require('@toruslabs/ethereum-controllers');
|
|
8
8
|
var auth = require('@web3auth/auth');
|
|
9
9
|
var deepmerge = require('deepmerge');
|
|
10
|
+
var errors = require('./account-linking/errors.js');
|
|
11
|
+
require('@toruslabs/http-helpers');
|
|
10
12
|
var analytics = require('./base/analytics.js');
|
|
11
13
|
var IChainInterface = require('./base/chain/IChainInterface.js');
|
|
12
14
|
require('@toruslabs/session-manager');
|
|
@@ -27,7 +29,6 @@ var plugin = require('./plugins/wallet-services-plugin/plugin.js');
|
|
|
27
29
|
require('./providers/base-provider/utils.js');
|
|
28
30
|
var CommonJRPCProvider = require('./providers/base-provider/CommonJRPCProvider.js');
|
|
29
31
|
require('./providers/base-provider/commonPrivateKeyProvider.js');
|
|
30
|
-
var errors = require('./account-linking/errors.js');
|
|
31
32
|
|
|
32
33
|
const _excluded = ["walletScope", "eipStandard"];
|
|
33
34
|
const PRIMARY_CONNECTED_WALLET_KEY = "__primary__";
|
|
@@ -56,7 +57,8 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
56
57
|
idToken: null,
|
|
57
58
|
accessToken: null,
|
|
58
59
|
refreshToken: null,
|
|
59
|
-
activeAccount: null
|
|
60
|
+
activeAccount: null,
|
|
61
|
+
cachedConnectorNamespace: null
|
|
60
62
|
});
|
|
61
63
|
if (!options.clientId) throw index.WalletInitializationError.invalidParams("Please provide a valid clientId in constructor");
|
|
62
64
|
if (options.enableLogging) loglevel.log.enableAll();else loglevel.log.setLevel("error");
|
|
@@ -248,6 +250,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
248
250
|
await this.setState({
|
|
249
251
|
primaryConnectorName: null,
|
|
250
252
|
cachedConnector: null,
|
|
253
|
+
cachedConnectorNamespace: null,
|
|
251
254
|
currentChainId: null,
|
|
252
255
|
idToken: null,
|
|
253
256
|
accessToken: null,
|
|
@@ -783,7 +786,9 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
783
786
|
chains: this.coreOptions.chains
|
|
784
787
|
});
|
|
785
788
|
// sync chainId
|
|
786
|
-
this.commonJRPCProvider.on("chainChanged", async chainId =>
|
|
789
|
+
this.commonJRPCProvider.on("chainChanged", async chainId => {
|
|
790
|
+
await this.setCurrentChain(chainId);
|
|
791
|
+
});
|
|
787
792
|
}
|
|
788
793
|
async setupConnector(connector) {
|
|
789
794
|
this.subscribeToConnectorEvents(connector);
|
|
@@ -847,12 +852,19 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
847
852
|
injectedEvmConnector
|
|
848
853
|
} = await Promise.resolve().then(function () { return require('./connectors/injected-evm-connector/index.js'); });
|
|
849
854
|
const evmMipd = createMipd();
|
|
855
|
+
// `@metamask/connect-evm` SDK announces its own EIP-6963 provider (`io.metamask.mmc`) so
|
|
856
|
+
// it can be discovered by generic wallet pickers. We already register MetaMask via
|
|
857
|
+
// `metaMaskConnector`, so we must exclude the SDK-announced provider here; otherwise
|
|
858
|
+
// it is misclassified as an injected wallet and the modal shows MetaMask as installed,
|
|
859
|
+
// even when the user does not have the extension installed.
|
|
860
|
+
const isNonSdkAnnouncedProvider = providerDetail => providerDetail.info.rdns !== metamaskConnector.METAMASK_ERC_6963_PROVIDER_RDNS;
|
|
850
861
|
// subscribe to new injected connectors
|
|
851
862
|
evmMipd.subscribe(providerDetails => {
|
|
852
|
-
const
|
|
863
|
+
const filteredProviderDetails = providerDetails.filter(isNonSdkAnnouncedProvider);
|
|
864
|
+
const newConnectors = filteredProviderDetails.map(providerDetail => injectedEvmConnector(providerDetail)(config));
|
|
853
865
|
this.setConnectors(newConnectors);
|
|
854
866
|
});
|
|
855
|
-
connectorFns.push(...evmMipd.getProviders().map(injectedEvmConnector));
|
|
867
|
+
connectorFns.push(...evmMipd.getProviders().filter(isNonSdkAnnouncedProvider).map(injectedEvmConnector));
|
|
856
868
|
}
|
|
857
869
|
}
|
|
858
870
|
// add WalletConnectV2 connector if external wallets are enabled
|
|
@@ -984,7 +996,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
984
996
|
await this.setState({
|
|
985
997
|
primaryConnectorName: data.connectorName
|
|
986
998
|
});
|
|
987
|
-
this.cacheWallet(data.connectorName);
|
|
999
|
+
this.cacheWallet(data.connectorName, data.connectorNamespace);
|
|
988
1000
|
const isConnectAndSign = this.coreOptions.initialAuthenticationMode === constants.CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN;
|
|
989
1001
|
const pendingUserConsent = this.consentRequired && !this.state.hasUserConsent;
|
|
990
1002
|
if (pendingUserConsent && !isConnectAndSign) {
|
|
@@ -999,7 +1011,6 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
999
1011
|
if (this.status !== constants.CONNECTOR_STATUS.CONSENT_REQUIRING && this.status !== constants.CONNECTOR_STATUS.AUTHORIZED) {
|
|
1000
1012
|
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
1001
1013
|
}
|
|
1002
|
-
loglevel.log.debug("connected", this.status, this.primaryConnectorName);
|
|
1003
1014
|
// Defer plugin connection until consent is accepted; otherwise plugins would start before the consent step completes.
|
|
1004
1015
|
// `completeConsentAcceptance` connects the plugins once the user accepts the consent.
|
|
1005
1016
|
if (!pendingUserConsent) {
|
|
@@ -1114,7 +1125,14 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1114
1125
|
// External wallets can resolve to a different active chain than the requested one,
|
|
1115
1126
|
// so let connector-reported chain updates reconcile Web3Auth state after connect.
|
|
1116
1127
|
if (typeof (data === null || data === void 0 ? void 0 : data.data) === "object" && (data === null || data === void 0 ? void 0 : data.data) !== null && "chainId" in data.data && typeof data.data.chainId === "string") {
|
|
1128
|
+
const previousChain = this.currentChain;
|
|
1117
1129
|
await this.setCurrentChain(data.data.chainId);
|
|
1130
|
+
const currentChain = this.currentChain;
|
|
1131
|
+
const connectorEthereumProvider = connector.provider;
|
|
1132
|
+
if ((previousChain === null || previousChain === void 0 ? void 0 : previousChain.chainNamespace) !== (currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) && (currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) === baseControllers.CHAIN_NAMESPACES.EIP155 && connectorEthereumProvider) {
|
|
1133
|
+
// from sol -> evm namespace switch, we need to re-create AccountAbstractionProvider
|
|
1134
|
+
await this.bindPrimaryEthereumSigningProxy(connectorEthereumProvider, connector.name);
|
|
1135
|
+
}
|
|
1118
1136
|
}
|
|
1119
1137
|
loglevel.log.debug("connector data updated", data);
|
|
1120
1138
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, data);
|
|
@@ -1168,7 +1186,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1168
1186
|
}
|
|
1169
1187
|
checkIfAutoConnect(connector) {
|
|
1170
1188
|
var _this$currentChain3;
|
|
1171
|
-
let autoConnect = this.cachedConnector === connector.name;
|
|
1189
|
+
let autoConnect = this.cachedConnector === connector.name && this.state.cachedConnectorNamespace === connector.connectorNamespace;
|
|
1172
1190
|
if (autoConnect && (_this$currentChain3 = this.currentChain) !== null && _this$currentChain3 !== void 0 && _this$currentChain3.chainNamespace) {
|
|
1173
1191
|
if (connector.connectorNamespace === IChainInterface.CONNECTOR_NAMESPACES.MULTICHAIN) autoConnect = true;else autoConnect = connector.connectorNamespace === this.currentChain.chainNamespace;
|
|
1174
1192
|
}
|
|
@@ -1181,10 +1199,15 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1181
1199
|
getInitialChainIdForConnector(connector) {
|
|
1182
1200
|
var _initialChain;
|
|
1183
1201
|
let initialChain = this.currentChain;
|
|
1184
|
-
|
|
1202
|
+
const defaultChainId = this.coreOptions.defaultChainId;
|
|
1203
|
+
const isMultiChainConnector = connector.connectorNamespace === IChainInterface.CONNECTOR_NAMESPACES.MULTICHAIN;
|
|
1204
|
+
// if the connector is a multi-chain connector and a default chain id is set, use the default chain id
|
|
1205
|
+
if (isMultiChainConnector && defaultChainId) {
|
|
1206
|
+
initialChain = this.coreOptions.chains.find(chain => chain.chainId === defaultChainId) || this.currentChain;
|
|
1207
|
+
} else if (((_initialChain = initialChain) === null || _initialChain === void 0 ? void 0 : _initialChain.chainNamespace) !== connector.connectorNamespace && connector.connectorNamespace !== IChainInterface.CONNECTOR_NAMESPACES.MULTICHAIN) {
|
|
1185
1208
|
initialChain = this.coreOptions.chains.find(x => x.chainNamespace === connector.connectorNamespace);
|
|
1186
|
-
if (!initialChain) throw index.WalletInitializationError.invalidParams(`No chain found for ${connector.connectorNamespace}`);
|
|
1187
1209
|
}
|
|
1210
|
+
if (!initialChain) throw index.WalletInitializationError.invalidParams(`No chain found for ${connector.connectorNamespace}`);
|
|
1188
1211
|
return initialChain;
|
|
1189
1212
|
}
|
|
1190
1213
|
async completeConsentAcceptance() {
|
|
@@ -1368,7 +1391,8 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1368
1391
|
return {
|
|
1369
1392
|
ethereumProvider: connectedWallet.signingProvider,
|
|
1370
1393
|
solanaWallet: (_connectedWallet$sola = connectedWallet.solanaWallet) !== null && _connectedWallet$sola !== void 0 ? _connectedWallet$sola : null,
|
|
1371
|
-
connectorName: connectedWallet.connector.name
|
|
1394
|
+
connectorName: connectedWallet.connector.name,
|
|
1395
|
+
connectorNamespace: connectedWallet.connector.connectorNamespace
|
|
1372
1396
|
};
|
|
1373
1397
|
}
|
|
1374
1398
|
buildImmediateConnectedWalletConnectorState(params) {
|
|
@@ -1505,11 +1529,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1505
1529
|
if (!connection) {
|
|
1506
1530
|
throw index.WalletLoginError.connectionError("Failed to resolve the active connection after switching accounts.");
|
|
1507
1531
|
}
|
|
1508
|
-
this.emit(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED,
|
|
1509
|
-
ethereumProvider: connection.ethereumProvider,
|
|
1510
|
-
solanaWallet: connection.solanaWallet,
|
|
1511
|
-
connectorName: connection.connectorName
|
|
1512
|
-
});
|
|
1532
|
+
this.emit(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connection);
|
|
1513
1533
|
}
|
|
1514
1534
|
isActiveConnectorEventSource(connector) {
|
|
1515
1535
|
if (!this.primaryConnectorName) return true;
|
|
@@ -1592,9 +1612,10 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1592
1612
|
loglevel.log.debug("Failed to cache connected linked wallet connector", error);
|
|
1593
1613
|
}
|
|
1594
1614
|
}
|
|
1595
|
-
async cacheWallet(walletName) {
|
|
1615
|
+
async cacheWallet(walletName, connectorNamespace) {
|
|
1596
1616
|
await this.setState({
|
|
1597
|
-
cachedConnector: walletName
|
|
1617
|
+
cachedConnector: walletName,
|
|
1618
|
+
cachedConnectorNamespace: connectorNamespace
|
|
1598
1619
|
});
|
|
1599
1620
|
}
|
|
1600
1621
|
async setCurrentChain(chainId) {
|
|
@@ -1630,9 +1651,11 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1630
1651
|
});
|
|
1631
1652
|
}
|
|
1632
1653
|
async bindPrimaryEthereumSigningProxy(ethereumProvider, connectorName) {
|
|
1633
|
-
var _this$currentChain5, _accountAbstractionCo;
|
|
1654
|
+
var _this$primaryConnecto2, _this$currentChain5, _accountAbstractionCo;
|
|
1634
1655
|
if (!this.commonJRPCProvider) throw index.WalletInitializationError.notFound(`CommonJrpcProvider not found`);
|
|
1635
|
-
|
|
1656
|
+
const primaryConnectorProvider = connectorName === this.primaryConnectorName ? (_this$primaryConnecto2 = this.primaryConnector) === null || _this$primaryConnecto2 === void 0 ? void 0 : _this$primaryConnecto2.provider : null;
|
|
1657
|
+
const baseEthereumProvider = ethereumProvider === this.commonJRPCProvider || ethereumProvider === this.aaProvider ? primaryConnectorProvider !== null && primaryConnectorProvider !== void 0 ? primaryConnectorProvider : ethereumProvider : ethereumProvider;
|
|
1658
|
+
let finalProvider = (baseEthereumProvider === null || baseEthereumProvider === void 0 ? void 0 : baseEthereumProvider.provider) || baseEthereumProvider;
|
|
1636
1659
|
const {
|
|
1637
1660
|
accountAbstractionConfig
|
|
1638
1661
|
} = this.coreOptions;
|
|
@@ -1648,7 +1671,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1648
1671
|
accountAbstractionProvider,
|
|
1649
1672
|
toEoaProvider
|
|
1650
1673
|
} = await Promise.resolve().then(function () { return require('./providers/account-abstraction-provider/index.js'); });
|
|
1651
|
-
const eoaProvider = connectorName === index$1.WALLET_CONNECTORS.AUTH ? await toEoaProvider(
|
|
1674
|
+
const eoaProvider = connectorName === index$1.WALLET_CONNECTORS.AUTH ? await toEoaProvider(baseEthereumProvider) : baseEthereumProvider;
|
|
1652
1675
|
const aaChainIds = new Set((accountAbstractionConfig === null || accountAbstractionConfig === void 0 || (_accountAbstractionCo2 = accountAbstractionConfig.chains) === null || _accountAbstractionCo2 === void 0 ? void 0 : _accountAbstractionCo2.map(chain => chain.chainId)) || []);
|
|
1653
1676
|
const aaProvider = await accountAbstractionProvider({
|
|
1654
1677
|
accountAbstractionConfig,
|
package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js
CHANGED
|
@@ -70,7 +70,7 @@ class AccountAbstractionProvider extends baseProvider.BaseProvider {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
async setupProvider(eoaProvider) {
|
|
73
|
-
var _bundlerConfig$transp;
|
|
73
|
+
var _await$eoaProvider$re, _bundlerConfig$transp;
|
|
74
74
|
const currentChain = this.currentChain;
|
|
75
75
|
if (!currentChain) {
|
|
76
76
|
throw index.WalletInitializationError.invalidProviderConfigError(`AA chain config not found for chain ${this.chainId}`);
|
|
@@ -113,7 +113,14 @@ class AccountAbstractionProvider extends baseProvider.BaseProvider {
|
|
|
113
113
|
chain,
|
|
114
114
|
transport: viem.http(currentChain.rpcTarget)
|
|
115
115
|
});
|
|
116
|
-
|
|
116
|
+
// Firstly, try to get the accounts from the existing connected provider with `eth_accounts` method.
|
|
117
|
+
// We don't wanna do `eth_requestAccounts` method here, coz if the wallet is already connected, it will trigger chainChanged event and unintentionally update the AaProvider re-bind and
|
|
118
|
+
// re-bind run this again, so we will end up in infinite loop.
|
|
119
|
+
const existingAccounts = (_await$eoaProvider$re = await eoaProvider.request({
|
|
120
|
+
method: ethereumControllers.METHOD_TYPES.GET_ACCOUNTS
|
|
121
|
+
})) !== null && _await$eoaProvider$re !== void 0 ? _await$eoaProvider$re : [];
|
|
122
|
+
// only if the existing accounts are not found (that means wallet isn't connected), then we will trigger `eth_requestAccounts` method to get the accounts.
|
|
123
|
+
const [eoaAddress] = existingAccounts.length > 0 ? existingAccounts : await eoaProvider.request({
|
|
117
124
|
method: ethereumControllers.METHOD_TYPES.ETH_REQUEST_ACCOUNTS
|
|
118
125
|
});
|
|
119
126
|
const walletClient = viem.createWalletClient({
|
|
@@ -175,6 +175,14 @@ function useWeb3AuthInnerContextValue({
|
|
|
175
175
|
setChainId(web3Auth.currentChainId);
|
|
176
176
|
setChainNamespace((_web3Auth$currentChai1 = (_web3Auth$currentChai10 = web3Auth.currentChain) === null || _web3Auth$currentChai10 === void 0 ? void 0 : _web3Auth$currentChai10.chainNamespace) !== null && _web3Auth$currentChai1 !== void 0 ? _web3Auth$currentChai1 : null);
|
|
177
177
|
};
|
|
178
|
+
const connectorDataUpdatedListener = data => {
|
|
179
|
+
const updatedData = data.data;
|
|
180
|
+
if (updatedData.chainId) {
|
|
181
|
+
var _web3Auth$currentChai11;
|
|
182
|
+
setChainId(updatedData.chainId);
|
|
183
|
+
setChainNamespace((_web3Auth$currentChai11 = web3Auth.currentChain) === null || _web3Auth$currentChai11 === void 0 ? void 0 : _web3Auth$currentChai11.chainNamespace);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
178
186
|
if (web3Auth) {
|
|
179
187
|
web3Auth.on(constants.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
|
|
180
188
|
web3Auth.on(constants.CONNECTOR_EVENTS.READY, readyListener);
|
|
@@ -186,6 +194,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
186
194
|
web3Auth.on(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
|
|
187
195
|
web3Auth.on(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
188
196
|
web3Auth.on(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
197
|
+
web3Auth.on(constants.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, connectorDataUpdatedListener);
|
|
189
198
|
if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
190
199
|
web3Auth.on(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
191
200
|
}
|
|
@@ -202,6 +211,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
202
211
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
203
212
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.AUTHORIZED, authorizedListener);
|
|
204
213
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
214
|
+
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, connectorDataUpdatedListener);
|
|
205
215
|
if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
206
216
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
207
217
|
}
|
|
@@ -12,13 +12,12 @@ var baseControllers = require('@toruslabs/base-controllers');
|
|
|
12
12
|
require('@toruslabs/session-manager');
|
|
13
13
|
require('@web3auth/auth');
|
|
14
14
|
require('../../base/errors/index.js');
|
|
15
|
-
require('
|
|
16
|
-
require('@toruslabs/http-helpers');
|
|
17
|
-
require('../../base/constants.js');
|
|
15
|
+
var utils = require('../../base/utils.js');
|
|
18
16
|
require('../../base/wallet/index.js');
|
|
19
17
|
require('../../base/connector/connectorStatus.js');
|
|
20
18
|
require('../../base/connector/constants.js');
|
|
21
19
|
require('jwt-decode');
|
|
20
|
+
require('../../base/constants.js');
|
|
22
21
|
require('../../base/plugin/errors.js');
|
|
23
22
|
require('../../base/plugin/IPlugin.js');
|
|
24
23
|
require('../context/Web3AuthInnerContext.js');
|
|
@@ -54,12 +53,28 @@ function makePlaceholder(rpc) {
|
|
|
54
53
|
});
|
|
55
54
|
}
|
|
56
55
|
function dispose(client) {
|
|
57
|
-
void client.actions.disconnectWallet().catch(() => {});
|
|
58
56
|
client.destroy();
|
|
59
57
|
}
|
|
58
|
+
function resolveSolanaChain(web3Auth, connection) {
|
|
59
|
+
var _web3Auth$coreOptions3;
|
|
60
|
+
const currentChain = web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.currentChain;
|
|
61
|
+
if ((currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
62
|
+
return currentChain;
|
|
63
|
+
}
|
|
64
|
+
const connectedScope = connection !== null && connection !== void 0 && connection.solanaWallet && "scope" in connection.solanaWallet && typeof connection.solanaWallet.scope === "string" ? connection.solanaWallet.scope : null;
|
|
65
|
+
if (connectedScope) {
|
|
66
|
+
var _web3Auth$coreOptions2;
|
|
67
|
+
const connectedChain = web3Auth === null || web3Auth === void 0 || (_web3Auth$coreOptions2 = web3Auth.coreOptions.chains) === null || _web3Auth$coreOptions2 === void 0 ? void 0 : _web3Auth$coreOptions2.find(chain => {
|
|
68
|
+
return chain.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA && utils.getCaipChainId(chain) === connectedScope;
|
|
69
|
+
});
|
|
70
|
+
if (connectedChain) return connectedChain;
|
|
71
|
+
}
|
|
72
|
+
return (web3Auth === null || web3Auth === void 0 || (_web3Auth$coreOptions3 = web3Auth.coreOptions.chains) === null || _web3Auth$coreOptions3 === void 0 ? void 0 : _web3Auth$coreOptions3.find(chain => chain.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA)) || null;
|
|
73
|
+
}
|
|
60
74
|
/**
|
|
61
|
-
* Builds the SolanaClient for Framework Kit React hooks
|
|
62
|
-
*
|
|
75
|
+
* Builds the SolanaClient for Framework Kit React hooks.
|
|
76
|
+
* For multichain wallets, keep the Solana client warm across namespace switches so
|
|
77
|
+
* switching back to Solana can reuse the existing wallet session.
|
|
63
78
|
*/
|
|
64
79
|
function useFrameworkKitSolanaClient() {
|
|
65
80
|
const {
|
|
@@ -72,12 +87,13 @@ function useFrameworkKitSolanaClient() {
|
|
|
72
87
|
chainId,
|
|
73
88
|
chainNamespace
|
|
74
89
|
} = useChain.useChain();
|
|
75
|
-
const
|
|
90
|
+
const solClientRef = react.useRef(null);
|
|
91
|
+
const connectedClientRef = react.useRef(null);
|
|
76
92
|
const [client$1, setClient] = react.useState(() => {
|
|
77
93
|
const c = makePlaceholder({
|
|
78
94
|
rpcTarget: DEVNET_ENDPOINT
|
|
79
95
|
});
|
|
80
|
-
|
|
96
|
+
solClientRef.current = c;
|
|
81
97
|
return c;
|
|
82
98
|
});
|
|
83
99
|
react.useEffect(() => {
|
|
@@ -86,53 +102,61 @@ function useFrameworkKitSolanaClient() {
|
|
|
86
102
|
});
|
|
87
103
|
}, [isInitialized, web3Auth]);
|
|
88
104
|
react.useEffect(() => () => {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
const connectedClient = connectedClientRef.current;
|
|
106
|
+
const currentClient = solClientRef.current;
|
|
107
|
+
if (currentClient) {
|
|
108
|
+
dispose(currentClient);
|
|
109
|
+
solClientRef.current = null;
|
|
110
|
+
}
|
|
111
|
+
if (connectedClient && connectedClient !== currentClient) {
|
|
112
|
+
dispose(connectedClient);
|
|
93
113
|
}
|
|
114
|
+
connectedClientRef.current = null;
|
|
94
115
|
}, []);
|
|
95
116
|
react.useEffect(() => {
|
|
96
117
|
let stale = false;
|
|
97
|
-
const adopt =
|
|
118
|
+
const adopt = nextClient => {
|
|
98
119
|
if (stale) {
|
|
99
|
-
dispose(
|
|
120
|
+
dispose(nextClient);
|
|
100
121
|
return;
|
|
101
122
|
}
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
setClient(
|
|
123
|
+
const prevClient = solClientRef.current;
|
|
124
|
+
if (prevClient === nextClient) return;
|
|
125
|
+
if (prevClient) dispose(prevClient);
|
|
126
|
+
solClientRef.current = nextClient;
|
|
127
|
+
setClient(nextClient);
|
|
107
128
|
};
|
|
108
|
-
(async
|
|
129
|
+
(async () => {
|
|
109
130
|
const rpc = placeholderRpc(isInitialized, web3Auth);
|
|
110
|
-
const solanaWallet = connection === null || connection === void 0 ? void 0 : connection.solanaWallet;
|
|
111
|
-
const onSolana = isConnected && Boolean(solanaWallet) && chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA && (web3Auth === null || web3Auth === void 0 || (_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainNamespace) === baseControllers.CHAIN_NAMESPACES.SOLANA;
|
|
112
|
-
if (!onSolana) {
|
|
113
|
-
adopt(makePlaceholder(rpc));
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
131
|
const conn = connection;
|
|
117
|
-
|
|
132
|
+
const currentChain = web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.currentChain;
|
|
133
|
+
if ((currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) !== baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
118
134
|
adopt(makePlaceholder(rpc));
|
|
119
135
|
return;
|
|
120
136
|
}
|
|
121
|
-
|
|
122
|
-
|
|
137
|
+
const preferredSolanaChain = resolveSolanaChain(web3Auth, conn);
|
|
138
|
+
const shouldKeepSolanaClient = isConnected && Boolean(conn === null || conn === void 0 ? void 0 : conn.solanaWallet) && Boolean(preferredSolanaChain) &&
|
|
139
|
+
// only manage the client for the primary connector
|
|
140
|
+
(conn === null || conn === void 0 ? void 0 : conn.connectorName) === (web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.primaryConnectorName);
|
|
141
|
+
if (!shouldKeepSolanaClient) {
|
|
142
|
+
const connectedClient = connectedClientRef.current;
|
|
143
|
+
connectedClientRef.current = null;
|
|
144
|
+
if (connectedClient) {
|
|
145
|
+
dispose(connectedClient);
|
|
146
|
+
}
|
|
123
147
|
adopt(makePlaceholder(rpc));
|
|
124
148
|
return;
|
|
125
149
|
}
|
|
126
150
|
try {
|
|
127
151
|
const solanaWalletId = "wallet-standard:" + conn.connectorName;
|
|
128
|
-
const connector = client.createWalletStandardConnector(solanaWallet, {
|
|
152
|
+
const connector = client.createWalletStandardConnector(conn.solanaWallet, {
|
|
129
153
|
id: solanaWalletId,
|
|
130
154
|
name: conn.connectorName
|
|
131
155
|
});
|
|
132
156
|
const {
|
|
133
157
|
rpcTarget,
|
|
134
158
|
wsTarget
|
|
135
|
-
} =
|
|
159
|
+
} = preferredSolanaChain;
|
|
136
160
|
const wired = client.createClient({
|
|
137
161
|
endpoint: rpcTarget,
|
|
138
162
|
websocketEndpoint: wsTarget,
|
|
@@ -145,7 +169,16 @@ function useFrameworkKitSolanaClient() {
|
|
|
145
169
|
dispose(wired);
|
|
146
170
|
return;
|
|
147
171
|
}
|
|
148
|
-
|
|
172
|
+
const prevConnectedClient = connectedClientRef.current;
|
|
173
|
+
connectedClientRef.current = wired;
|
|
174
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA && (currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
175
|
+
adopt(wired);
|
|
176
|
+
} else {
|
|
177
|
+
adopt(makePlaceholder(rpc));
|
|
178
|
+
}
|
|
179
|
+
if (prevConnectedClient && prevConnectedClient !== wired) {
|
|
180
|
+
dispose(prevConnectedClient);
|
|
181
|
+
}
|
|
149
182
|
} catch (e) {
|
|
150
183
|
loglevel.log.error("Failed to create or connect Solana client", e);
|
|
151
184
|
adopt(makePlaceholder(rpc));
|
|
@@ -40,6 +40,7 @@ export declare abstract class BaseConnector<T> extends SafeEventEmitter<Connecto
|
|
|
40
40
|
challenge: string;
|
|
41
41
|
authServer: string;
|
|
42
42
|
}): Promise<AuthTokenInfo>;
|
|
43
|
+
protected authorizeOrDisconnect(getAuthTokenInfo?: boolean, chainId?: string): Promise<void>;
|
|
43
44
|
protected clearWalletSession(): Promise<void>;
|
|
44
45
|
abstract init(options?: ConnectorInitOptions): Promise<void>;
|
|
45
46
|
abstract connect(params: T & BaseConnectorLoginParams): Promise<Connection | null>;
|
|
@@ -47,7 +48,7 @@ export declare abstract class BaseConnector<T> extends SafeEventEmitter<Connecto
|
|
|
47
48
|
abstract getUserInfo(): Promise<Partial<UserInfo>>;
|
|
48
49
|
abstract enableMFA(params?: T): Promise<void>;
|
|
49
50
|
abstract manageMFA(params?: T): Promise<void>;
|
|
50
|
-
abstract getAuthTokenInfo(): Promise<AuthTokenInfo>;
|
|
51
|
+
abstract getAuthTokenInfo(chainId?: string): Promise<AuthTokenInfo>;
|
|
51
52
|
abstract generateChallengeAndSign(authServerUrl?: string, accounts?: string[]): Promise<{
|
|
52
53
|
challenge: string;
|
|
53
54
|
signature: string;
|
|
@@ -79,6 +79,7 @@ export interface Connection {
|
|
|
79
79
|
readonly ethereumProvider: IProvider | null;
|
|
80
80
|
readonly solanaWallet: Wallet | null;
|
|
81
81
|
readonly connectorName: WALLET_CONNECTOR_TYPE | string;
|
|
82
|
+
readonly connectorNamespace: ConnectorNamespaceType;
|
|
82
83
|
}
|
|
83
84
|
export interface IConnector<T> extends SafeEventEmitter {
|
|
84
85
|
connectorNamespace: ConnectorNamespaceType;
|
|
@@ -48,6 +48,7 @@ export declare class WalletLoginError extends Web3AuthError {
|
|
|
48
48
|
static unsupportedOperation(extraMessage?: string, cause?: unknown): IWeb3AuthError;
|
|
49
49
|
static sfaKeyNotFound(extraMessage?: string, cause?: unknown): IWeb3AuthError;
|
|
50
50
|
static userNotLoggedIn(extraMessage?: string, cause?: unknown): IWeb3AuthError;
|
|
51
|
+
static userBlocked(extraMessage?: string, cause?: unknown): IWeb3AuthError;
|
|
51
52
|
}
|
|
52
53
|
export declare class WalletOperationsError extends Web3AuthError {
|
|
53
54
|
protected static messages: ErrorCodes;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type BUTTON_POSITION_TYPE } from "@toruslabs/base-controllers";
|
|
2
2
|
import type { SmartAccountEipStandardType, SmartAccountType } from "@toruslabs/ethereum-controllers";
|
|
3
3
|
import { AuthConnectionConfigItem, type WhiteLabelData } from "@web3auth/auth";
|
|
4
|
-
import { type ChainNamespaceType, type CustomChainConfig } from "./chain/IChainInterface";
|
|
4
|
+
import { type ChainNamespaceType, ConnectorNamespaceType, type CustomChainConfig } from "./chain/IChainInterface";
|
|
5
5
|
import { LinkedAccountInfo } from "./connector";
|
|
6
6
|
import { LOGIN_MODE, MODAL_SIGN_IN_METHODS, SMART_ACCOUNT_WALLET_SCOPE, WIDGET_TYPE } from "./constants";
|
|
7
7
|
import { WALLET_CONNECTOR_TYPE } from "./wallet";
|
|
@@ -11,6 +11,7 @@ export interface WhitelistResponse {
|
|
|
11
11
|
}
|
|
12
12
|
export interface IWeb3AuthState {
|
|
13
13
|
cachedConnector: string | null;
|
|
14
|
+
cachedConnectorNamespace: ConnectorNamespaceType | null;
|
|
14
15
|
primaryConnectorName: WALLET_CONNECTOR_TYPE | null;
|
|
15
16
|
currentChainId: string;
|
|
16
17
|
idToken: string | null;
|
|
@@ -21,6 +21,7 @@ export interface MetaMaskConnectorSettings {
|
|
|
21
21
|
export interface MetaMaskConnectorOptions extends BaseConnectorSettings {
|
|
22
22
|
connectorSettings?: MetaMaskConnectorSettings;
|
|
23
23
|
}
|
|
24
|
+
export declare const METAMASK_ERC_6963_PROVIDER_RDNS = "io.metamask.mmc";
|
|
24
25
|
/**
|
|
25
26
|
* Factory function to create a MetaMask connector
|
|
26
27
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Syncs Web3Auth Solana connection with Framework Kit client.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* For multichain wallets, keep the Solana client warm across namespace switches so
|
|
4
|
+
* switching back to Solana can reuse the existing wallet session.
|
|
5
5
|
*/
|
|
6
6
|
export declare const SolanaProvider: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
7
7
|
[key: string]: any;
|
|
@@ -10,13 +10,12 @@ var baseControllers = require('@toruslabs/base-controllers');
|
|
|
10
10
|
require('@toruslabs/session-manager');
|
|
11
11
|
require('@web3auth/auth');
|
|
12
12
|
require('../../base/errors/index.js');
|
|
13
|
-
require('
|
|
14
|
-
require('@toruslabs/http-helpers');
|
|
15
|
-
require('../../base/constants.js');
|
|
13
|
+
var utils = require('../../base/utils.js');
|
|
16
14
|
require('../../base/wallet/index.js');
|
|
17
15
|
require('../../base/connector/connectorStatus.js');
|
|
18
16
|
require('../../base/connector/constants.js');
|
|
19
17
|
require('jwt-decode');
|
|
18
|
+
require('../../base/constants.js');
|
|
20
19
|
require('../../base/plugin/errors.js');
|
|
21
20
|
require('../../base/plugin/IPlugin.js');
|
|
22
21
|
var useChain = require('../composables/useChain.js');
|
|
@@ -24,17 +23,28 @@ var useWeb3Auth = require('../composables/useWeb3Auth.js');
|
|
|
24
23
|
var constants = require('./constants.js');
|
|
25
24
|
|
|
26
25
|
const disposeClient = async client => {
|
|
27
|
-
try {
|
|
28
|
-
await client.actions.disconnectWallet();
|
|
29
|
-
} catch (e) {
|
|
30
|
-
loglevel.log.warn("Solana client disconnect", e);
|
|
31
|
-
}
|
|
32
26
|
client.destroy();
|
|
33
27
|
};
|
|
28
|
+
const resolveSolanaChain = (web3Auth, connection) => {
|
|
29
|
+
var _web3Auth$coreOptions2;
|
|
30
|
+
const currentChain = web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.currentChain;
|
|
31
|
+
if ((currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
32
|
+
return currentChain;
|
|
33
|
+
}
|
|
34
|
+
const connectedScope = connection !== null && connection !== void 0 && connection.solanaWallet && "scope" in connection.solanaWallet && typeof connection.solanaWallet.scope === "string" ? connection.solanaWallet.scope : null;
|
|
35
|
+
if (connectedScope) {
|
|
36
|
+
var _web3Auth$coreOptions;
|
|
37
|
+
const connectedChain = web3Auth === null || web3Auth === void 0 || (_web3Auth$coreOptions = web3Auth.coreOptions.chains) === null || _web3Auth$coreOptions === void 0 ? void 0 : _web3Auth$coreOptions.find(chain => {
|
|
38
|
+
return chain.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA && utils.getCaipChainId(chain) === connectedScope;
|
|
39
|
+
});
|
|
40
|
+
if (connectedChain) return connectedChain;
|
|
41
|
+
}
|
|
42
|
+
return (web3Auth === null || web3Auth === void 0 || (_web3Auth$coreOptions2 = web3Auth.coreOptions.chains) === null || _web3Auth$coreOptions2 === void 0 ? void 0 : _web3Auth$coreOptions2.find(chain => chain.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA)) || null;
|
|
43
|
+
};
|
|
34
44
|
/**
|
|
35
45
|
* Syncs Web3Auth Solana connection with Framework Kit client.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
46
|
+
* For multichain wallets, keep the Solana client warm across namespace switches so
|
|
47
|
+
* switching back to Solana can reuse the existing wallet session.
|
|
38
48
|
*/
|
|
39
49
|
const SolanaProvider = vue.defineComponent({
|
|
40
50
|
name: "SolanaProvider",
|
|
@@ -50,6 +60,8 @@ const SolanaProvider = vue.defineComponent({
|
|
|
50
60
|
chainId
|
|
51
61
|
} = useChain.useChain();
|
|
52
62
|
const clientRef = vue.ref(null);
|
|
63
|
+
let connectedClient = null;
|
|
64
|
+
// let connectedClientKey: string | null = null;
|
|
53
65
|
// Holds the token for the newest requested sync run. Older async runs compare against it
|
|
54
66
|
// before publishing results so a slower reconnect cannot overwrite a newer chain/account update.
|
|
55
67
|
let activeSyncToken = null;
|
|
@@ -64,21 +76,26 @@ const SolanaProvider = vue.defineComponent({
|
|
|
64
76
|
const newIsConnected = isConnected.value;
|
|
65
77
|
const newConnection = connection.value;
|
|
66
78
|
const currentChain = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.currentChain;
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
if ((currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) !== baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
80
|
+
// Mirror the React provider behavior: hide the live Solana client from injected
|
|
81
|
+
// consumers whenever Web3Auth is currently scoped to a non-Solana namespace.
|
|
82
|
+
clientRef.value = null;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const preferredSolanaChain = resolveSolanaChain(web3Auth.value, newConnection);
|
|
86
|
+
const shouldKeepSolanaClient = newIsConnected && Boolean(newConnection === null || newConnection === void 0 ? void 0 : newConnection.solanaWallet) && Boolean(preferredSolanaChain) &&
|
|
87
|
+
// only manage the client for the primary connector
|
|
88
|
+
(newConnection === null || newConnection === void 0 ? void 0 : newConnection.connectorName) === ((_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 ? void 0 : _web3Auth$value2.primaryConnectorName);
|
|
89
|
+
if (!shouldKeepSolanaClient) {
|
|
71
90
|
clientRef.value = null;
|
|
91
|
+
const prevClient = connectedClient;
|
|
92
|
+
connectedClient = null;
|
|
93
|
+
// connectedClientKey = null;
|
|
72
94
|
if (prevClient) {
|
|
73
95
|
await disposeClient(prevClient);
|
|
74
96
|
}
|
|
75
97
|
return;
|
|
76
98
|
}
|
|
77
|
-
const prevClient = clientRef.value;
|
|
78
|
-
clientRef.value = null;
|
|
79
|
-
if (prevClient) {
|
|
80
|
-
await disposeClient(prevClient);
|
|
81
|
-
}
|
|
82
99
|
let client$1 = null;
|
|
83
100
|
try {
|
|
84
101
|
// create a wallet standard connector from connected wallet
|
|
@@ -91,7 +108,7 @@ const SolanaProvider = vue.defineComponent({
|
|
|
91
108
|
const {
|
|
92
109
|
rpcTarget,
|
|
93
110
|
wsTarget
|
|
94
|
-
} =
|
|
111
|
+
} = preferredSolanaChain;
|
|
95
112
|
client$1 = client.createClient({
|
|
96
113
|
endpoint: rpcTarget,
|
|
97
114
|
websocketEndpoint: wsTarget,
|
|
@@ -106,7 +123,13 @@ const SolanaProvider = vue.defineComponent({
|
|
|
106
123
|
await disposeClient(client$1);
|
|
107
124
|
return;
|
|
108
125
|
}
|
|
109
|
-
|
|
126
|
+
const prevClient = connectedClient;
|
|
127
|
+
connectedClient = client$1;
|
|
128
|
+
// connectedClientKey = nextClientKey;
|
|
129
|
+
clientRef.value = (currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) === baseControllers.CHAIN_NAMESPACES.SOLANA ? client$1 : null;
|
|
130
|
+
if (prevClient) {
|
|
131
|
+
await disposeClient(prevClient);
|
|
132
|
+
}
|
|
110
133
|
} catch (err) {
|
|
111
134
|
if (client$1) {
|
|
112
135
|
await disposeClient(client$1);
|
|
@@ -124,6 +147,17 @@ const SolanaProvider = vue.defineComponent({
|
|
|
124
147
|
}, {
|
|
125
148
|
immediate: true
|
|
126
149
|
});
|
|
150
|
+
vue.onBeforeUnmount(() => {
|
|
151
|
+
const publishedClient = clientRef.value;
|
|
152
|
+
clientRef.value = null;
|
|
153
|
+
const prevClient = connectedClient;
|
|
154
|
+
connectedClient = null;
|
|
155
|
+
if (prevClient) {
|
|
156
|
+
void disposeClient(prevClient);
|
|
157
|
+
} else if (publishedClient) {
|
|
158
|
+
void disposeClient(publishedClient);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
127
161
|
return () => {
|
|
128
162
|
var _slots$default, _slots$default2;
|
|
129
163
|
return vue.h(vue.Fragment, null, (_slots$default = (_slots$default2 = slots.default) === null || _slots$default2 === void 0 ? void 0 : _slots$default2.call(slots)) !== null && _slots$default !== void 0 ? _slots$default : []);
|