@web3auth/no-modal 11.0.0-beta.0 → 11.0.0-beta.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/account-linking/index.js +8 -0
- package/dist/lib.cjs/account-linking/react.js +95 -0
- package/dist/lib.cjs/account-linking/rest.js +54 -0
- package/dist/lib.cjs/account-linking/vue.js +98 -0
- package/dist/lib.cjs/base/analytics.js +17 -2
- package/dist/lib.cjs/base/connector/constants.js +2 -0
- package/dist/lib.cjs/base/errors/index.js +48 -0
- package/dist/lib.cjs/base/utils.js +15 -3
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +427 -50
- package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +42 -23
- package/dist/lib.cjs/connectors/base-solana-connector/baseSolanaConnector.js +41 -24
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +76 -45
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +41 -13
- package/dist/lib.cjs/index.js +20 -13
- package/dist/lib.cjs/noModal.js +811 -110
- package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +1 -1
- package/dist/lib.cjs/providers/base-provider/baseProvider.js +65 -33
- package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +34 -20
- package/dist/lib.cjs/react/hooks/useWallets.js +51 -0
- package/dist/lib.cjs/react/hooks/useWeb3AuthConnect.js +2 -2
- package/dist/lib.cjs/react/index.js +2 -0
- package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +2 -2
- package/dist/lib.cjs/react/solana/provider.js +2 -0
- package/dist/lib.cjs/types/account-linking/index.d.ts +2 -0
- package/dist/lib.cjs/types/account-linking/interfaces.d.ts +90 -0
- package/dist/lib.cjs/types/account-linking/react.d.ts +19 -0
- package/dist/lib.cjs/types/account-linking/rest.d.ts +9 -0
- package/dist/lib.cjs/types/account-linking/vue.d.ts +20 -0
- package/dist/lib.cjs/types/base/analytics.d.ts +9 -0
- package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +5 -0
- package/dist/lib.cjs/types/base/connector/constants.d.ts +2 -0
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +51 -6
- package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +39 -2
- package/dist/lib.cjs/types/base/errors/index.d.ts +13 -0
- package/dist/lib.cjs/types/base/interfaces.d.ts +3 -1
- package/dist/lib.cjs/types/base/utils.d.ts +7 -1
- package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +27 -3
- package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +77 -2
- package/dist/lib.cjs/types/connectors/base-evm-connector/baseEvmConnector.d.ts +6 -0
- package/dist/lib.cjs/types/connectors/base-solana-connector/baseSolanaConnector.d.ts +6 -0
- package/dist/lib.cjs/types/index.d.ts +1 -0
- package/dist/lib.cjs/types/noModal.d.ts +104 -5
- package/dist/lib.cjs/types/providers/base-provider/baseProvider.d.ts +7 -0
- package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
- package/dist/lib.cjs/types/react/hooks/useWallets.d.ts +8 -0
- package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
- package/dist/lib.cjs/types/vue/composables/useWallets.d.ts +9 -0
- package/dist/lib.cjs/vue/composables/useWallets.js +52 -0
- package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +2 -2
- package/dist/lib.cjs/vue/index.js +2 -0
- package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +2 -2
- package/dist/lib.cjs/vue/solana/provider.js +3 -0
- package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -4
- package/dist/lib.cjs/vue/wagmi/provider.js +19 -7
- package/dist/lib.esm/account-linking/index.js +1 -0
- package/dist/lib.esm/account-linking/react.js +74 -0
- package/dist/lib.esm/account-linking/rest.js +51 -0
- package/dist/lib.esm/account-linking/vue.js +78 -0
- package/dist/lib.esm/base/analytics.js +17 -2
- package/dist/lib.esm/base/connector/constants.js +2 -0
- package/dist/lib.esm/base/errors/index.js +48 -1
- package/dist/lib.esm/base/utils.js +16 -4
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +386 -9
- package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +43 -24
- package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +43 -26
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +2 -2
- package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +2 -2
- package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +3 -3
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +80 -49
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +2 -2
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +43 -15
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/wcSolanaWallet.js +1 -1
- package/dist/lib.esm/index.js +4 -3
- package/dist/lib.esm/noModal.js +828 -119
- package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +3 -3
- package/dist/lib.esm/providers/base-provider/baseProvider.js +68 -38
- package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +36 -21
- package/dist/lib.esm/react/hooks/useWallets.js +33 -0
- package/dist/lib.esm/react/hooks/useWeb3AuthConnect.js +2 -2
- package/dist/lib.esm/react/index.js +1 -0
- package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +2 -2
- package/dist/lib.esm/react/solana/provider.js +4 -1
- package/dist/lib.esm/react/wagmi/provider.js +1 -1
- package/dist/lib.esm/vue/composables/useCheckout.js +1 -1
- package/dist/lib.esm/vue/composables/useFunding.js +1 -1
- package/dist/lib.esm/vue/composables/useReceive.js +1 -1
- package/dist/lib.esm/vue/composables/useSwap.js +1 -1
- package/dist/lib.esm/vue/composables/useWalletConnectScanner.js +1 -1
- package/dist/lib.esm/vue/composables/useWalletUI.js +1 -1
- package/dist/lib.esm/vue/composables/useWallets.js +35 -0
- package/dist/lib.esm/vue/composables/useWeb3AuthConnect.js +2 -2
- package/dist/lib.esm/vue/index.js +1 -0
- package/dist/lib.esm/vue/solana/composables/useSignAndSendTransaction.js +1 -1
- package/dist/lib.esm/vue/solana/composables/useSignMessage.js +1 -1
- package/dist/lib.esm/vue/solana/composables/useSignTransaction.js +1 -1
- package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +2 -2
- package/dist/lib.esm/vue/solana/provider.js +4 -0
- package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +12 -3
- package/dist/lib.esm/vue/wagmi/provider.js +20 -8
- package/package.json +43 -19
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Ref } from "vue";
|
|
2
|
+
import { type ConnectedAccountsWithProviders, Web3AuthError } from "../../base";
|
|
3
|
+
export interface IUseWallets {
|
|
4
|
+
loading: Ref<boolean>;
|
|
5
|
+
error: Ref<Web3AuthError | null>;
|
|
6
|
+
wallets: Ref<ConnectedAccountsWithProviders[]>;
|
|
7
|
+
syncWallets(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare const useWallets: () => IUseWallets;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vue = require('vue');
|
|
4
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
5
|
+
require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
require('@segment/analytics-next');
|
|
7
|
+
var loglevel = require('../../base/loglevel.js');
|
|
8
|
+
require('@toruslabs/base-controllers');
|
|
9
|
+
require('@toruslabs/session-manager');
|
|
10
|
+
require('@web3auth/auth');
|
|
11
|
+
var index = require('../../base/errors/index.js');
|
|
12
|
+
require('@toruslabs/constants');
|
|
13
|
+
require('@toruslabs/http-helpers');
|
|
14
|
+
require('../../base/constants.js');
|
|
15
|
+
require('../../base/wallet/index.js');
|
|
16
|
+
require('../../base/connector/connectorStatus.js');
|
|
17
|
+
require('../../base/connector/constants.js');
|
|
18
|
+
require('jwt-decode');
|
|
19
|
+
require('../../base/plugin/errors.js');
|
|
20
|
+
require('../../base/plugin/IPlugin.js');
|
|
21
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
22
|
+
|
|
23
|
+
const useWallets = () => {
|
|
24
|
+
const {
|
|
25
|
+
web3Auth
|
|
26
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
27
|
+
const loading = vue.ref(false);
|
|
28
|
+
const error = vue.ref(null);
|
|
29
|
+
const wallets = vue.ref([]);
|
|
30
|
+
const syncWallets = async () => {
|
|
31
|
+
if (!web3Auth.value) throw index.WalletInitializationError.notReady();
|
|
32
|
+
error.value = null;
|
|
33
|
+
loading.value = true;
|
|
34
|
+
try {
|
|
35
|
+
const result = await web3Auth.value.getConnectedAccountsWithProviders();
|
|
36
|
+
wallets.value = result;
|
|
37
|
+
} catch (err) {
|
|
38
|
+
loglevel.log.error("Error getting wallets", err);
|
|
39
|
+
error.value = err;
|
|
40
|
+
} finally {
|
|
41
|
+
loading.value = false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
loading,
|
|
46
|
+
error,
|
|
47
|
+
wallets,
|
|
48
|
+
syncWallets
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.useWallets = useWallets;
|
|
@@ -34,7 +34,7 @@ const useWeb3AuthConnect = () => {
|
|
|
34
34
|
}
|
|
35
35
|
if (newVal && !connectorName.value) {
|
|
36
36
|
var _web3Auth$value;
|
|
37
|
-
connectorName.value = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.
|
|
37
|
+
connectorName.value = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.primaryConnectorName;
|
|
38
38
|
}
|
|
39
39
|
}, {
|
|
40
40
|
immediate: true
|
|
@@ -45,7 +45,7 @@ const useWeb3AuthConnect = () => {
|
|
|
45
45
|
error.value = null;
|
|
46
46
|
loading.value = true;
|
|
47
47
|
const localProvider = await web3Auth.value.connectTo(connectorType, loginParams);
|
|
48
|
-
connectorName.value = web3Auth.value.
|
|
48
|
+
connectorName.value = web3Auth.value.primaryConnectorName;
|
|
49
49
|
return localProvider;
|
|
50
50
|
} catch (err) {
|
|
51
51
|
loglevel.log.error("Error connecting", err);
|
|
@@ -11,6 +11,7 @@ var useReceive = require('./composables/useReceive.js');
|
|
|
11
11
|
var useSwap = require('./composables/useSwap.js');
|
|
12
12
|
var useSwitchChain = require('./composables/useSwitchChain.js');
|
|
13
13
|
var useWalletConnectScanner = require('./composables/useWalletConnectScanner.js');
|
|
14
|
+
var useWallets = require('./composables/useWallets.js');
|
|
14
15
|
var useWalletServicesPlugin = require('./composables/useWalletServicesPlugin.js');
|
|
15
16
|
var useWalletUI = require('./composables/useWalletUI.js');
|
|
16
17
|
var useWeb3Auth = require('./composables/useWeb3Auth.js');
|
|
@@ -35,6 +36,7 @@ exports.useReceive = useReceive.useReceive;
|
|
|
35
36
|
exports.useSwap = useSwap.useSwap;
|
|
36
37
|
exports.useSwitchChain = useSwitchChain.useSwitchChain;
|
|
37
38
|
exports.useWalletConnectScanner = useWalletConnectScanner.useWalletConnectScanner;
|
|
39
|
+
exports.useWallets = useWallets.useWallets;
|
|
38
40
|
exports.useWalletServicesPlugin = useWalletServicesPlugin.useWalletServicesPlugin;
|
|
39
41
|
exports.useWalletUI = useWalletUI.useWalletUI;
|
|
40
42
|
exports.useWeb3Auth = useWeb3Auth.useWeb3Auth;
|
|
@@ -66,12 +66,12 @@ const useSolanaWallet = () => {
|
|
|
66
66
|
};
|
|
67
67
|
vue.onScopeDispose(teardownWalletListeners);
|
|
68
68
|
const getPrivateKey = async () => {
|
|
69
|
-
var _connection$value2, _web3Auth$value$
|
|
69
|
+
var _connection$value2, _web3Auth$value$prima;
|
|
70
70
|
if (!web3Auth.value) throw new Error("Web3Auth not initialized");
|
|
71
71
|
if (((_connection$value2 = connection.value) === null || _connection$value2 === void 0 ? void 0 : _connection$value2.connectorName) !== index.WALLET_CONNECTORS.AUTH) {
|
|
72
72
|
throw new Error("getPrivateKey is only supported with the Auth connector");
|
|
73
73
|
}
|
|
74
|
-
const provider = (_web3Auth$value$
|
|
74
|
+
const provider = (_web3Auth$value$prima = web3Auth.value.primaryConnector) === null || _web3Auth$value$prima === void 0 ? void 0 : _web3Auth$value$prima.provider;
|
|
75
75
|
if (!provider) throw new Error("Provider not available");
|
|
76
76
|
const privateKey = await provider.request({
|
|
77
77
|
method: wsEmbed.SOLANA_METHOD_TYPES.SOLANA_PRIVATE_KEY
|
|
@@ -50,6 +50,7 @@ const SolanaProvider = vue.defineComponent({
|
|
|
50
50
|
vue.provide(constants.SOLANA_CLIENT_KEY, clientRef);
|
|
51
51
|
// watch for changes in the connection and chain namespace
|
|
52
52
|
vue.watch([isConnected, connection], async ([newIsConnected, newConnection]) => {
|
|
53
|
+
var _web3Auth$value;
|
|
53
54
|
if (!newIsConnected || !(newConnection !== null && newConnection !== void 0 && newConnection.solanaWallet)) {
|
|
54
55
|
if (clientRef.value) {
|
|
55
56
|
await disposeClient(clientRef.value);
|
|
@@ -66,6 +67,8 @@ const SolanaProvider = vue.defineComponent({
|
|
|
66
67
|
chainConfig = web3Auth.value.coreOptions.chains.find(c => c.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA);
|
|
67
68
|
if (!chainConfig) return;
|
|
68
69
|
}
|
|
70
|
+
// only reconnect for the primary connector
|
|
71
|
+
if (newConnection.connectorName !== ((_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.primaryConnectorName)) return;
|
|
69
72
|
const prevClient = clientRef.value;
|
|
70
73
|
try {
|
|
71
74
|
// create a wallet standard connector from connected wallet
|
|
@@ -105,7 +105,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
105
105
|
var _web3Auth$value$curre, _web3Auth$value$curre2;
|
|
106
106
|
if (!isInitialized.value) isInitialized.value = true;
|
|
107
107
|
isConnected.value = true;
|
|
108
|
-
connection.value =
|
|
108
|
+
connection.value = web3Auth.value.connection;
|
|
109
109
|
chainId.value = web3Auth.value.currentChainId;
|
|
110
110
|
chainNamespace.value = (_web3Auth$value$curre = (_web3Auth$value$curre2 = web3Auth.value.currentChain) === null || _web3Auth$value$curre2 === void 0 ? void 0 : _web3Auth$value$curre2.chainNamespace) !== null && _web3Auth$value$curre !== void 0 ? _web3Auth$value$curre : null;
|
|
111
111
|
}
|
|
@@ -123,7 +123,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
123
123
|
var _web3Auth$value$curre3, _web3Auth$value$curre4;
|
|
124
124
|
if (!isInitialized.value) isInitialized.value = true;
|
|
125
125
|
isConnected.value = true;
|
|
126
|
-
connection.value =
|
|
126
|
+
connection.value = web3Auth.value.connection;
|
|
127
127
|
chainId.value = web3Auth.value.currentChainId;
|
|
128
128
|
chainNamespace.value = (_web3Auth$value$curre3 = (_web3Auth$value$curre4 = web3Auth.value.currentChain) === null || _web3Auth$value$curre4 === void 0 ? void 0 : _web3Auth$value$curre4.chainNamespace) !== null && _web3Auth$value$curre3 !== void 0 ? _web3Auth$value$curre3 : null;
|
|
129
129
|
if (web3Auth.value.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
|
|
@@ -147,6 +147,13 @@ function useWeb3AuthInnerContextValue({
|
|
|
147
147
|
const mfaEnabledListener = () => {
|
|
148
148
|
isMFAEnabled.value = true;
|
|
149
149
|
};
|
|
150
|
+
const connectionUpdatedListener = () => {
|
|
151
|
+
var _web3Auth$value$curre5, _web3Auth$value$curre6;
|
|
152
|
+
status.value = web3Auth.value.status;
|
|
153
|
+
connection.value = web3Auth.value.connection;
|
|
154
|
+
chainId.value = web3Auth.value.currentChainId;
|
|
155
|
+
chainNamespace.value = (_web3Auth$value$curre5 = (_web3Auth$value$curre6 = web3Auth.value.currentChain) === null || _web3Auth$value$curre6 === void 0 ? void 0 : _web3Auth$value$curre6.chainNamespace) !== null && _web3Auth$value$curre5 !== void 0 ? _web3Auth$value$curre5 : null;
|
|
156
|
+
};
|
|
150
157
|
if (prevWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
|
|
151
158
|
prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
|
|
152
159
|
prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.READY, readyListener);
|
|
@@ -157,6 +164,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
157
164
|
prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
158
165
|
prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, errorListener);
|
|
159
166
|
prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
167
|
+
prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
160
168
|
if (prevWeb3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
161
169
|
prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
162
170
|
}
|
|
@@ -172,6 +180,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
172
180
|
newWeb3Auth.on(constants.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
173
181
|
newWeb3Auth.on(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, errorListener);
|
|
174
182
|
newWeb3Auth.on(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
183
|
+
newWeb3Auth.on(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
175
184
|
if (newWeb3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
176
185
|
newWeb3Auth.on(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
177
186
|
}
|
|
@@ -182,9 +191,9 @@ function useWeb3AuthInnerContextValue({
|
|
|
182
191
|
vue.watch(connection, (newConnection, prevConnection) => {
|
|
183
192
|
var _prevConnection$ether, _newConnection$ethere;
|
|
184
193
|
const handleChainChange = newChainId => {
|
|
185
|
-
var _web3Auth$value$
|
|
194
|
+
var _web3Auth$value$curre7, _web3Auth$value;
|
|
186
195
|
chainId.value = newChainId;
|
|
187
|
-
chainNamespace.value = (_web3Auth$value$
|
|
196
|
+
chainNamespace.value = (_web3Auth$value$curre7 = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 || (_web3Auth$value = _web3Auth$value.currentChain) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.chainNamespace) !== null && _web3Auth$value$curre7 !== void 0 ? _web3Auth$value$curre7 : null;
|
|
188
197
|
};
|
|
189
198
|
const prevProvider = (_prevConnection$ether = prevConnection === null || prevConnection === void 0 ? void 0 : prevConnection.ethereumProvider) !== null && _prevConnection$ether !== void 0 ? _prevConnection$ether : null;
|
|
190
199
|
const newProvider = (_newConnection$ethere = newConnection === null || newConnection === void 0 ? void 0 : newConnection.ethereumProvider) !== null && _newConnection$ethere !== void 0 ? _newConnection$ethere : null;
|
|
@@ -98,6 +98,7 @@ const Web3AuthWagmiProvider = vue.defineComponent({
|
|
|
98
98
|
const {
|
|
99
99
|
mutate: reconnect
|
|
100
100
|
} = vue$1.useReconnect();
|
|
101
|
+
const lastSyncedWeb3AuthConnection = vue.shallowRef(null);
|
|
101
102
|
vue$1.useConnectionEffect({
|
|
102
103
|
onDisconnect: async () => {
|
|
103
104
|
loglevel.log.info("Disconnected from wagmi");
|
|
@@ -111,16 +112,27 @@ const Web3AuthWagmiProvider = vue.defineComponent({
|
|
|
111
112
|
}
|
|
112
113
|
});
|
|
113
114
|
vue.watch([isConnected, connection], async () => {
|
|
114
|
-
var
|
|
115
|
+
var _newConnection$ethere;
|
|
115
116
|
const newIsConnected = isConnected.value;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
const newConnection = connection.value;
|
|
118
|
+
const newEth = (_newConnection$ethere = newConnection === null || newConnection === void 0 ? void 0 : newConnection.ethereumProvider) !== null && _newConnection$ethere !== void 0 ? _newConnection$ethere : null;
|
|
119
|
+
if (newIsConnected && newConnection && newEth) {
|
|
120
|
+
// Linked-account switches can reuse or replace the underlying wallet provider,
|
|
121
|
+
// so key wagmi resyncs off the Web3Auth connection object instead of provider identity.
|
|
122
|
+
if (lastSyncedWeb3AuthConnection.value !== newConnection) {
|
|
123
|
+
if (getWeb3authConnector(wagmiConfig)) {
|
|
124
|
+
resetConnectorState(wagmiConfig);
|
|
125
|
+
}
|
|
126
|
+
lastSyncedWeb3AuthConnection.value = newConnection;
|
|
127
|
+
const connector = await setupConnector(newEth, wagmiConfig);
|
|
128
|
+
if (!connector) {
|
|
129
|
+
throw new Error("Failed to setup connector");
|
|
130
|
+
}
|
|
131
|
+
await connectWeb3AuthWithWagmi(connector, wagmiConfig);
|
|
132
|
+
reconnect();
|
|
120
133
|
}
|
|
121
|
-
await connectWeb3AuthWithWagmi(connector, wagmiConfig);
|
|
122
|
-
reconnect();
|
|
123
134
|
} else if (!newIsConnected) {
|
|
135
|
+
lastSyncedWeb3AuthConnection.value = null;
|
|
124
136
|
if (wagmiConfig.state.status === "connected") {
|
|
125
137
|
await disconnectWeb3AuthFromWagmi(wagmiConfig);
|
|
126
138
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from './rest.js';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useWeb3AuthInner } from '../react/hooks/useWeb3AuthInner.js';
|
|
3
|
+
import { WalletInitializationError } from '../base/errors/index.js';
|
|
4
|
+
export { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from './rest.js';
|
|
5
|
+
|
|
6
|
+
const useLinkAccount = () => {
|
|
7
|
+
const {
|
|
8
|
+
web3Auth
|
|
9
|
+
} = useWeb3AuthInner();
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const [linkedAccounts, setLinkedAccounts] = useState([]);
|
|
13
|
+
const linkAccount = useCallback(async params => {
|
|
14
|
+
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
15
|
+
setLoading(true);
|
|
16
|
+
setError(null);
|
|
17
|
+
try {
|
|
18
|
+
const result = await web3Auth.linkAccount(params);
|
|
19
|
+
setLinkedAccounts(result.linkedAccounts);
|
|
20
|
+
return result;
|
|
21
|
+
} catch (err) {
|
|
22
|
+
setError(err);
|
|
23
|
+
} finally {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
}
|
|
26
|
+
}, [web3Auth]);
|
|
27
|
+
const unlinkAccount = useCallback(async address => {
|
|
28
|
+
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
29
|
+
setLoading(true);
|
|
30
|
+
setError(null);
|
|
31
|
+
try {
|
|
32
|
+
const result = await web3Auth.unlinkAccount(address);
|
|
33
|
+
setLinkedAccounts(result.linkedAccounts);
|
|
34
|
+
return result;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
setError(err);
|
|
37
|
+
} finally {
|
|
38
|
+
setLoading(false);
|
|
39
|
+
}
|
|
40
|
+
}, [web3Auth]);
|
|
41
|
+
return {
|
|
42
|
+
loading,
|
|
43
|
+
error,
|
|
44
|
+
linkAccount,
|
|
45
|
+
unlinkAccount,
|
|
46
|
+
linkedAccounts
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const useSwitchAccount = () => {
|
|
50
|
+
const {
|
|
51
|
+
web3Auth
|
|
52
|
+
} = useWeb3AuthInner();
|
|
53
|
+
const [loading, setLoading] = useState(false);
|
|
54
|
+
const [error, setError] = useState(null);
|
|
55
|
+
const switchAccount = useCallback(async account => {
|
|
56
|
+
if (!web3Auth) throw WalletInitializationError.notReady();
|
|
57
|
+
setLoading(true);
|
|
58
|
+
setError(null);
|
|
59
|
+
try {
|
|
60
|
+
await web3Auth.switchAccount(account);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
setError(err);
|
|
63
|
+
} finally {
|
|
64
|
+
setLoading(false);
|
|
65
|
+
}
|
|
66
|
+
}, [web3Auth]);
|
|
67
|
+
return {
|
|
68
|
+
loading,
|
|
69
|
+
error,
|
|
70
|
+
switchAccount
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export { useLinkAccount, useSwitchAccount };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { post } from '@toruslabs/http-helpers';
|
|
2
|
+
import { AccountLinkingError } from '../base/errors/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Send both identity proofs to the Citadel account-linking endpoint and
|
|
6
|
+
* return a normalized result.
|
|
7
|
+
*
|
|
8
|
+
* Throws AccountLinkingError when the server returns an error or the request itself fails.
|
|
9
|
+
*/
|
|
10
|
+
async function makeAccountLinkingRequest(authServerUrl, accessToken, payload) {
|
|
11
|
+
const url = `${authServerUrl}/v1/link/wallet`;
|
|
12
|
+
let result;
|
|
13
|
+
try {
|
|
14
|
+
result = await post(url, payload, {
|
|
15
|
+
headers: {
|
|
16
|
+
Authorization: `Bearer ${accessToken}`
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
} catch (cause) {
|
|
20
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
21
|
+
throw AccountLinkingError.requestFailed(message, cause);
|
|
22
|
+
}
|
|
23
|
+
if (!result.success) {
|
|
24
|
+
var _result$message;
|
|
25
|
+
const errMessage = (_result$message = result.message) !== null && _result$message !== void 0 ? _result$message : "Failed to link account";
|
|
26
|
+
throw AccountLinkingError.requestFailed(errMessage);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
async function makeAccountUnlinkingRequest(authServerUrl, accessToken, payload) {
|
|
31
|
+
const url = `${authServerUrl}/v1/unlink`;
|
|
32
|
+
let result;
|
|
33
|
+
try {
|
|
34
|
+
result = await post(url, payload, {
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: `Bearer ${accessToken}`
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
} catch (cause) {
|
|
40
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
41
|
+
throw AccountLinkingError.requestFailed(message, cause);
|
|
42
|
+
}
|
|
43
|
+
if (!result.success) {
|
|
44
|
+
var _result$message2;
|
|
45
|
+
const errMessage = (_result$message2 = result.message) !== null && _result$message2 !== void 0 ? _result$message2 : "Failed to unlink account";
|
|
46
|
+
throw AccountLinkingError.requestFailed(errMessage);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { makeAccountLinkingRequest, makeAccountUnlinkingRequest };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { useWeb3AuthInner } from '../vue/composables/useWeb3AuthInner.js';
|
|
3
|
+
import { WalletInitializationError } from '../base/errors/index.js';
|
|
4
|
+
import { log } from '../base/loglevel.js';
|
|
5
|
+
export { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from './rest.js';
|
|
6
|
+
|
|
7
|
+
const useLinkAccount = () => {
|
|
8
|
+
const {
|
|
9
|
+
web3Auth
|
|
10
|
+
} = useWeb3AuthInner();
|
|
11
|
+
const loading = ref(false);
|
|
12
|
+
const error = ref(null);
|
|
13
|
+
const linkedAccounts = ref([]);
|
|
14
|
+
const linkAccount = async params => {
|
|
15
|
+
if (!web3Auth.value) throw WalletInitializationError.notReady();
|
|
16
|
+
try {
|
|
17
|
+
error.value = null;
|
|
18
|
+
loading.value = true;
|
|
19
|
+
const result = await web3Auth.value.linkAccount(params);
|
|
20
|
+
linkedAccounts.value = result.linkedAccounts;
|
|
21
|
+
return result;
|
|
22
|
+
} catch (err) {
|
|
23
|
+
log.error("Error linking account", err);
|
|
24
|
+
error.value = err;
|
|
25
|
+
} finally {
|
|
26
|
+
loading.value = false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const unlinkAccount = async address => {
|
|
30
|
+
if (!web3Auth.value) throw WalletInitializationError.notReady();
|
|
31
|
+
try {
|
|
32
|
+
error.value = null;
|
|
33
|
+
loading.value = true;
|
|
34
|
+
const result = await web3Auth.value.unlinkAccount(address);
|
|
35
|
+
linkedAccounts.value = result.linkedAccounts;
|
|
36
|
+
return result;
|
|
37
|
+
} catch (err) {
|
|
38
|
+
log.error("Error unlinking account", err);
|
|
39
|
+
error.value = err;
|
|
40
|
+
} finally {
|
|
41
|
+
loading.value = false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
loading,
|
|
46
|
+
error,
|
|
47
|
+
linkAccount,
|
|
48
|
+
unlinkAccount,
|
|
49
|
+
linkedAccounts
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const useSwitchAccount = () => {
|
|
53
|
+
const {
|
|
54
|
+
web3Auth
|
|
55
|
+
} = useWeb3AuthInner();
|
|
56
|
+
const loading = ref(false);
|
|
57
|
+
const error = ref(null);
|
|
58
|
+
const switchAccount = async account => {
|
|
59
|
+
if (!web3Auth.value) throw WalletInitializationError.notReady();
|
|
60
|
+
error.value = null;
|
|
61
|
+
loading.value = true;
|
|
62
|
+
try {
|
|
63
|
+
await web3Auth.value.switchAccount(account);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
log.error("Error switching account", err);
|
|
66
|
+
error.value = err;
|
|
67
|
+
} finally {
|
|
68
|
+
loading.value = false;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
loading,
|
|
73
|
+
error,
|
|
74
|
+
switchAccount
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { useLinkAccount, useSwitchAccount };
|
|
@@ -11,6 +11,9 @@ class Analytics {
|
|
|
11
11
|
_defineProperty(this, "enabled", true);
|
|
12
12
|
}
|
|
13
13
|
init() {
|
|
14
|
+
if (!this.enabled) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
14
17
|
if (this.isSkipped()) {
|
|
15
18
|
return;
|
|
16
19
|
}
|
|
@@ -74,7 +77,7 @@ class Analytics {
|
|
|
74
77
|
isSkipped() {
|
|
75
78
|
const dappOrigin = window.location.origin;
|
|
76
79
|
|
|
77
|
-
// skip if the protocol is
|
|
80
|
+
// skip if the protocol is http
|
|
78
81
|
if (dappOrigin.startsWith("http://")) {
|
|
79
82
|
return true;
|
|
80
83
|
}
|
|
@@ -115,7 +118,19 @@ const ANALYTICS_EVENTS = {
|
|
|
115
118
|
WALLET_FUNDING_CLICKED: "Wallet Funding Clicked",
|
|
116
119
|
WALLET_CHECKOUT_CLICKED: "Wallet Checkout Clicked",
|
|
117
120
|
WALLET_RECEIVE_CLICKED: "Wallet Receive Clicked",
|
|
118
|
-
WALLET_SWAP_CLICKED: "Wallet Swap Clicked"
|
|
121
|
+
WALLET_SWAP_CLICKED: "Wallet Swap Clicked",
|
|
122
|
+
// Account Linking
|
|
123
|
+
ACCOUNT_LINKING_STARTED: "Account Linking Started",
|
|
124
|
+
ACCOUNT_LINKING_COMPLETED: "Account Linking Completed",
|
|
125
|
+
ACCOUNT_LINKING_FAILED: "Account Linking Failed",
|
|
126
|
+
// Account Unlinking
|
|
127
|
+
ACCOUNT_UNLINKING_STARTED: "Account Unlinking Started",
|
|
128
|
+
ACCOUNT_UNLINKING_COMPLETED: "Account Unlinking Completed",
|
|
129
|
+
ACCOUNT_UNLINKING_FAILED: "Account Unlinking Failed",
|
|
130
|
+
// Account switch (active connected wallet)
|
|
131
|
+
ACCOUNT_SWITCH_STARTED: "Account Switch Started",
|
|
132
|
+
ACCOUNT_SWITCH_COMPLETED: "Account Switch Completed",
|
|
133
|
+
ACCOUNT_SWITCH_FAILED: "Account Switch Failed"
|
|
119
134
|
};
|
|
120
135
|
const ANALYTICS_INTEGRATION_TYPE = {
|
|
121
136
|
REACT_HOOKS: "React Hooks",
|
|
@@ -18,6 +18,8 @@ const CONNECTOR_EVENTS = _objectSpread(_objectSpread({}, CONNECTOR_STATUS), {},
|
|
|
18
18
|
CONNECTORS_UPDATED: "connectors_updated",
|
|
19
19
|
MFA_ENABLED: "mfa_enabled",
|
|
20
20
|
REHYDRATION_ERROR: "rehydration_error",
|
|
21
|
+
/** Emitted when the active public `connection` changes without a full reconnect (e.g. account switch). */
|
|
22
|
+
CONNECTION_UPDATED: "connection_updated",
|
|
21
23
|
CONSENT_ACCEPTED: "consent_accepted"
|
|
22
24
|
});
|
|
23
25
|
const CONNECTOR_CATEGORY = {
|
|
@@ -207,6 +207,53 @@ _defineProperty(WalletOperationsError, "messages", {
|
|
|
207
207
|
5201: "Provided chainId is not allowed",
|
|
208
208
|
5202: "This operation is not allowed"
|
|
209
209
|
});
|
|
210
|
+
class AccountLinkingError extends Web3AuthError {
|
|
211
|
+
constructor(code, message, cause) {
|
|
212
|
+
super(code, message, cause);
|
|
213
|
+
Object.defineProperty(this, "name", {
|
|
214
|
+
value: "AccountLinkingError",
|
|
215
|
+
configurable: true
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
static fromCode(code, extraMessage = "", cause) {
|
|
219
|
+
return new AccountLinkingError(code, `${AccountLinkingError.messages[code]}. ${extraMessage}`, cause);
|
|
220
|
+
}
|
|
221
|
+
static requestFailed(extraMessage = "", cause) {
|
|
222
|
+
return AccountLinkingError.fromCode(5401, extraMessage, cause);
|
|
223
|
+
}
|
|
224
|
+
static serverNotConfigured(extraMessage = "", cause) {
|
|
225
|
+
return AccountLinkingError.fromCode(5402, extraMessage, cause);
|
|
226
|
+
}
|
|
227
|
+
static primaryTokenNotAvailable(extraMessage = "", cause) {
|
|
228
|
+
return AccountLinkingError.fromCode(5403, extraMessage, cause);
|
|
229
|
+
}
|
|
230
|
+
static walletProofFailed(extraMessage = "", cause) {
|
|
231
|
+
return AccountLinkingError.fromCode(5404, extraMessage, cause);
|
|
232
|
+
}
|
|
233
|
+
static unsupportedConnector(extraMessage = "", cause) {
|
|
234
|
+
return AccountLinkingError.fromCode(5405, extraMessage, cause);
|
|
235
|
+
}
|
|
236
|
+
static cannotUnlinkActiveAccount() {
|
|
237
|
+
return AccountLinkingError.fromCode(5406);
|
|
238
|
+
}
|
|
239
|
+
static accountNotLinked(message = "", cause) {
|
|
240
|
+
return AccountLinkingError.fromCode(5407, message, cause);
|
|
241
|
+
}
|
|
242
|
+
static cannotUnlinkPrimaryAccount() {
|
|
243
|
+
return AccountLinkingError.fromCode(5408);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
_defineProperty(AccountLinkingError, "messages", {
|
|
247
|
+
5000: "Custom",
|
|
248
|
+
5401: "Account linking request failed",
|
|
249
|
+
5402: "Citadel server URL is not configured",
|
|
250
|
+
5403: "Primary identity token is not available",
|
|
251
|
+
5404: "Failed to obtain wallet proof token",
|
|
252
|
+
5405: "Connector is not supported for wallet linking",
|
|
253
|
+
5406: "Cannot unlink active account",
|
|
254
|
+
5407: "Account not linked",
|
|
255
|
+
5408: "Cannot unlink primary account"
|
|
256
|
+
});
|
|
210
257
|
class WalletProviderError extends Web3AuthError {
|
|
211
258
|
constructor(code, message, cause) {
|
|
212
259
|
// takes care of stack and proto
|
|
@@ -240,4 +287,4 @@ _defineProperty(WalletProviderError, "messages", {
|
|
|
240
287
|
5303: "'args.params' must be an object or array if provided."
|
|
241
288
|
});
|
|
242
289
|
|
|
243
|
-
export { WalletInitializationError, WalletLoginError, WalletOperationsError, WalletProviderError, Web3AuthError };
|
|
290
|
+
export { AccountLinkingError, WalletInitializationError, WalletLoginError, WalletOperationsError, WalletProviderError, Web3AuthError };
|
|
@@ -12,8 +12,8 @@ const isHexStrict = hex => {
|
|
|
12
12
|
const dashboardPublicApiUrl = buildEnv => {
|
|
13
13
|
return DASHBOARD_PUBLIC_API_MAP[buildEnv];
|
|
14
14
|
};
|
|
15
|
-
const citadelServerUrl = buildEnv => {
|
|
16
|
-
return CITADEL_SERVER_MAP[buildEnv
|
|
15
|
+
const citadelServerUrl = (buildEnv = BUILD_ENV.PRODUCTION) => {
|
|
16
|
+
return CITADEL_SERVER_MAP[buildEnv];
|
|
17
17
|
};
|
|
18
18
|
const fetchProjectConfig = async ({
|
|
19
19
|
clientId,
|
|
@@ -149,7 +149,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
|
|
|
149
149
|
ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig10 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig10 === void 0 ? void 0 : _walletServicesConfig10.defaultPortfolio
|
|
150
150
|
};
|
|
151
151
|
};
|
|
152
|
-
const sdkVersion = "11.0.0-beta.
|
|
152
|
+
const sdkVersion = "11.0.0-beta.1";
|
|
153
153
|
const getErrorAnalyticsProperties = error => {
|
|
154
154
|
try {
|
|
155
155
|
const code = error instanceof Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
|
|
@@ -184,4 +184,16 @@ const getCaipChainId = chain => {
|
|
|
184
184
|
return `${chain.chainNamespace}:${chain.chainId}`;
|
|
185
185
|
};
|
|
186
186
|
|
|
187
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Parse the chain namespace from the citadel response
|
|
189
|
+
* @param chainNamespace - The chain namespace from the citadel response
|
|
190
|
+
* @returns The parsed chain namespace
|
|
191
|
+
*/
|
|
192
|
+
const parseChainNamespaceFromCitadelResponse = chainNamespace => {
|
|
193
|
+
if (chainNamespace === "evm") {
|
|
194
|
+
return CHAIN_NAMESPACES.EIP155;
|
|
195
|
+
}
|
|
196
|
+
return chainNamespace;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export { citadelServerUrl, dashboardPublicApiUrl, fetchProjectConfig, fetchWalletRegistry, fromViemChain, fromWagmiChain, getAaAnalyticsProperties, getCaipChainId, getErrorAnalyticsProperties, getHostname, getWalletServicesAnalyticsProperties, getWhitelabelAnalyticsProperties, isBrowser, isHexStrict, normalizeWalletName, parseChainNamespaceFromCitadelResponse, sdkVersion, withAbort };
|