@web3auth/modal 10.0.0-beta.4 → 10.0.0-beta.6
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/packages/modal/src/config.js +1 -1
- package/dist/lib.cjs/packages/modal/src/modalManager.js +17 -19
- package/dist/lib.cjs/packages/modal/src/react/solana/hooks/useSignAndSendTransaction.js +35 -0
- package/dist/lib.cjs/packages/modal/src/react/solana/hooks/useSignMessage.js +36 -0
- package/dist/lib.cjs/packages/modal/src/react/solana/hooks/useSignTransaction.js +34 -0
- package/dist/lib.cjs/packages/modal/src/react/solana/hooks/useSolanaWallet.js +32 -0
- package/dist/lib.cjs/packages/modal/src/react/solana/index.js +13 -0
- package/dist/lib.cjs/packages/modal/src/ui/components/Login/Login.js +1 -1
- package/dist/lib.cjs/packages/modal/src/vue/WalletServicesInnerProvider.js +70 -0
- package/dist/lib.cjs/packages/modal/src/vue/Web3AuthProvider.js +16 -74
- package/dist/lib.cjs/packages/modal/src/vue/composables/useCheckout.js +34 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useEnableMFA.js +32 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useIdentityToken.js +44 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useManageMFA.js +32 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useSwap.js +34 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useSwitchChain.js +32 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useWalletConnectScanner.js +34 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useWalletServicesPlugin.js +12 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useWalletUI.js +34 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useWeb3Auth.js +2 -4
- package/dist/lib.cjs/packages/modal/src/vue/composables/useWeb3AuthConnect.js +46 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useWeb3AuthDisconnect.js +32 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useWeb3AuthInner.js +12 -0
- package/dist/lib.cjs/packages/modal/src/vue/composables/useWeb3AuthUser.js +53 -0
- package/dist/lib.cjs/packages/modal/src/vue/index.js +24 -0
- package/dist/lib.cjs/types/react/solana/hooks/index.d.ts +4 -0
- package/dist/lib.cjs/types/react/solana/hooks/useSignAndSendTransaction.d.ts +8 -0
- package/dist/lib.cjs/types/react/solana/hooks/useSignMessage.d.ts +8 -0
- package/dist/lib.cjs/types/react/solana/hooks/useSignTransaction.d.ts +13 -0
- package/dist/lib.cjs/types/react/solana/hooks/useSolanaWallet.d.ts +6 -0
- package/dist/lib.cjs/types/react/solana/index.d.ts +1 -0
- package/dist/lib.cjs/types/vue/WalletServicesInnerProvider.d.ts +1 -0
- package/dist/lib.cjs/types/vue/composables/index.d.ts +12 -0
- package/dist/lib.cjs/types/vue/composables/useCheckout.d.ts +9 -0
- package/dist/lib.cjs/types/vue/composables/useEnableMFA.d.ts +8 -0
- package/dist/lib.cjs/types/vue/composables/useIdentityToken.d.ts +9 -0
- package/dist/lib.cjs/types/vue/composables/useManageMFA.d.ts +8 -0
- package/dist/lib.cjs/types/vue/composables/useSwap.d.ts +9 -0
- package/dist/lib.cjs/types/vue/composables/useSwitchChain.d.ts +10 -0
- package/dist/lib.cjs/types/vue/composables/useWalletConnectScanner.d.ts +9 -0
- package/dist/lib.cjs/types/vue/composables/useWalletServicesPlugin.d.ts +2 -0
- package/dist/lib.cjs/types/vue/composables/useWalletUI.d.ts +9 -0
- package/dist/lib.cjs/types/vue/composables/useWeb3Auth.d.ts +3 -2
- package/dist/lib.cjs/types/vue/composables/useWeb3AuthConnect.d.ts +10 -0
- package/dist/lib.cjs/types/vue/composables/useWeb3AuthDisconnect.d.ts +10 -0
- package/dist/lib.cjs/types/vue/composables/useWeb3AuthInner.d.ts +2 -0
- package/dist/lib.cjs/types/vue/composables/useWeb3AuthUser.d.ts +10 -0
- package/dist/lib.cjs/types/vue/interfaces.d.ts +10 -18
- package/dist/lib.esm/packages/modal/src/config.js +1 -1
- package/dist/lib.esm/packages/modal/src/modalManager.js +19 -19
- package/dist/lib.esm/packages/modal/src/react/solana/hooks/useSignAndSendTransaction.js +33 -0
- package/dist/lib.esm/packages/modal/src/react/solana/hooks/useSignMessage.js +34 -0
- package/dist/lib.esm/packages/modal/src/react/solana/hooks/useSignTransaction.js +32 -0
- package/dist/lib.esm/packages/modal/src/react/solana/hooks/useSolanaWallet.js +30 -0
- package/dist/lib.esm/packages/modal/src/react/solana/index.js +4 -0
- package/dist/lib.esm/packages/modal/src/ui/components/Login/Login.js +1 -1
- package/dist/lib.esm/packages/modal/src/vue/WalletServicesInnerProvider.js +69 -0
- package/dist/lib.esm/packages/modal/src/vue/Web3AuthProvider.js +17 -75
- package/dist/lib.esm/packages/modal/src/vue/composables/useCheckout.js +32 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useEnableMFA.js +30 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useIdentityToken.js +42 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useManageMFA.js +30 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useSwap.js +32 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useSwitchChain.js +30 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useWalletConnectScanner.js +32 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useWalletServicesPlugin.js +10 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useWalletUI.js +32 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useWeb3Auth.js +2 -4
- package/dist/lib.esm/packages/modal/src/vue/composables/useWeb3AuthConnect.js +44 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useWeb3AuthDisconnect.js +30 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useWeb3AuthInner.js +10 -0
- package/dist/lib.esm/packages/modal/src/vue/composables/useWeb3AuthUser.js +51 -0
- package/dist/lib.esm/packages/modal/src/vue/index.js +12 -0
- package/dist/modal.umd.min.js +1 -1
- package/dist/modal.umd.min.js.LICENSE.txt +4 -10
- package/package.json +20 -9
|
@@ -190,32 +190,30 @@ class Web3Auth extends noModal.Web3AuthNoModal {
|
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
192
|
async getProjectAndWalletConfig() {
|
|
193
|
-
var _this$modalConfig;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
} catch (e) {
|
|
205
|
-
noModal.log.error("Failed to fetch project configurations", e);
|
|
206
|
-
throw noModal.WalletInitializationError.notReady("failed to fetch project configurations", e);
|
|
193
|
+
var _this$options$account, _this$modalConfig;
|
|
194
|
+
const [projectConfigResult, walletRegistryResult] = await Promise.allSettled([noModal.fetchProjectConfig({
|
|
195
|
+
clientId: this.options.clientId,
|
|
196
|
+
web3AuthNetwork: this.options.web3AuthNetwork,
|
|
197
|
+
aaProvider: (_this$options$account = this.options.accountAbstractionConfig) === null || _this$options$account === void 0 ? void 0 : _this$options$account.smartAccountType,
|
|
198
|
+
authBuildEnv: this.options.authBuildEnv
|
|
199
|
+
}), noModal.fetchWalletRegistry(config.walletRegistryUrl)]);
|
|
200
|
+
// handle project config result
|
|
201
|
+
if (projectConfigResult.status === "rejected") {
|
|
202
|
+
noModal.log.error("Failed to fetch project configurations", projectConfigResult.reason);
|
|
203
|
+
throw noModal.WalletInitializationError.notReady("failed to fetch project configurations", projectConfigResult.reason);
|
|
207
204
|
}
|
|
208
|
-
|
|
205
|
+
const projectConfig = projectConfigResult.value;
|
|
206
|
+
// handle wallet registry result
|
|
209
207
|
let walletRegistry = {
|
|
210
208
|
others: {},
|
|
211
209
|
default: {}
|
|
212
210
|
};
|
|
213
211
|
const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
|
|
214
212
|
if (isExternalWalletEnabled && !((_this$modalConfig = this.modalConfig) !== null && _this$modalConfig !== void 0 && _this$modalConfig.hideWalletDiscovery)) {
|
|
215
|
-
|
|
216
|
-
walletRegistry =
|
|
217
|
-
}
|
|
218
|
-
noModal.log.error("Failed to fetch wallet registry",
|
|
213
|
+
if (walletRegistryResult.status === "fulfilled") {
|
|
214
|
+
walletRegistry = walletRegistryResult.value;
|
|
215
|
+
} else {
|
|
216
|
+
noModal.log.error("Failed to fetch wallet registry", walletRegistryResult.reason);
|
|
219
217
|
}
|
|
220
218
|
}
|
|
221
219
|
return {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var useSolanaWallet = require('./useSolanaWallet.js');
|
|
5
|
+
|
|
6
|
+
const useSignAndSendTransaction = () => {
|
|
7
|
+
const {
|
|
8
|
+
solanaWallet
|
|
9
|
+
} = useSolanaWallet.useSolanaWallet();
|
|
10
|
+
const [loading, setLoading] = react.useState(false);
|
|
11
|
+
const [error, setError] = react.useState(null);
|
|
12
|
+
const [data, setData] = react.useState(null);
|
|
13
|
+
const signAndSendTransaction = react.useCallback(async transaction => {
|
|
14
|
+
setLoading(true);
|
|
15
|
+
setError(null);
|
|
16
|
+
try {
|
|
17
|
+
if (!solanaWallet) throw new Error("Solana wallet not found");
|
|
18
|
+
const signature = await solanaWallet.signAndSendTransaction(transaction);
|
|
19
|
+
setData(signature);
|
|
20
|
+
return signature;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
setError(error);
|
|
23
|
+
} finally {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
}
|
|
26
|
+
}, [solanaWallet]);
|
|
27
|
+
return {
|
|
28
|
+
loading,
|
|
29
|
+
error,
|
|
30
|
+
data,
|
|
31
|
+
signAndSendTransaction
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.useSignAndSendTransaction = useSignAndSendTransaction;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var useSolanaWallet = require('./useSolanaWallet.js');
|
|
5
|
+
|
|
6
|
+
const useSignMessage = () => {
|
|
7
|
+
const {
|
|
8
|
+
solanaWallet,
|
|
9
|
+
accounts
|
|
10
|
+
} = useSolanaWallet.useSolanaWallet();
|
|
11
|
+
const [loading, setLoading] = react.useState(false);
|
|
12
|
+
const [error, setError] = react.useState(null);
|
|
13
|
+
const [data, setData] = react.useState(null);
|
|
14
|
+
const signMessage = react.useCallback(async (message, from) => {
|
|
15
|
+
setLoading(true);
|
|
16
|
+
setError(null);
|
|
17
|
+
try {
|
|
18
|
+
if (!solanaWallet) throw new Error("Solana wallet not found");
|
|
19
|
+
const signature = await solanaWallet.signMessage(message, from !== null && from !== void 0 ? from : accounts === null || accounts === void 0 ? void 0 : accounts[0]);
|
|
20
|
+
setData(signature);
|
|
21
|
+
return signature;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
setError(error);
|
|
24
|
+
} finally {
|
|
25
|
+
setLoading(false);
|
|
26
|
+
}
|
|
27
|
+
}, [solanaWallet, accounts]);
|
|
28
|
+
return {
|
|
29
|
+
loading,
|
|
30
|
+
error,
|
|
31
|
+
data,
|
|
32
|
+
signMessage
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.useSignMessage = useSignMessage;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var useSolanaWallet = require('./useSolanaWallet.js');
|
|
5
|
+
|
|
6
|
+
const useSignTransaction = () => {
|
|
7
|
+
const {
|
|
8
|
+
solanaWallet
|
|
9
|
+
} = useSolanaWallet.useSolanaWallet();
|
|
10
|
+
const [loading, setLoading] = react.useState(false);
|
|
11
|
+
const [error, setError] = react.useState(null);
|
|
12
|
+
const [data, setData] = react.useState(null);
|
|
13
|
+
const signTransaction = react.useCallback(async transaction => {
|
|
14
|
+
setLoading(true);
|
|
15
|
+
setError(null);
|
|
16
|
+
try {
|
|
17
|
+
const signedTransaction = await solanaWallet.signTransaction(transaction);
|
|
18
|
+
setData(signedTransaction);
|
|
19
|
+
return signedTransaction;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
setError(error);
|
|
22
|
+
} finally {
|
|
23
|
+
setLoading(false);
|
|
24
|
+
}
|
|
25
|
+
}, [solanaWallet]);
|
|
26
|
+
return {
|
|
27
|
+
loading,
|
|
28
|
+
error,
|
|
29
|
+
data,
|
|
30
|
+
signTransaction
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.useSignTransaction = useSignTransaction;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var useWeb3Auth = require('../../hooks/useWeb3Auth.js');
|
|
6
|
+
|
|
7
|
+
const useSolanaWallet = () => {
|
|
8
|
+
const {
|
|
9
|
+
provider
|
|
10
|
+
} = useWeb3Auth.useWeb3Auth();
|
|
11
|
+
const [accounts, setAccounts] = react.useState(null);
|
|
12
|
+
const solanaWallet = react.useMemo(() => {
|
|
13
|
+
if (!provider) return null;
|
|
14
|
+
return new noModal.SolanaWallet(provider);
|
|
15
|
+
}, [provider]);
|
|
16
|
+
react.useEffect(() => {
|
|
17
|
+
const fetchAccounts = async () => {
|
|
18
|
+
if (!solanaWallet) return;
|
|
19
|
+
const accounts = await solanaWallet.requestAccounts();
|
|
20
|
+
if ((accounts === null || accounts === void 0 ? void 0 : accounts.length) > 0) {
|
|
21
|
+
setAccounts(accounts);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
if (solanaWallet) fetchAccounts();
|
|
25
|
+
}, [solanaWallet]);
|
|
26
|
+
return {
|
|
27
|
+
solanaWallet,
|
|
28
|
+
accounts
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.useSolanaWallet = useSolanaWallet;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var useSignAndSendTransaction = require('./hooks/useSignAndSendTransaction.js');
|
|
4
|
+
var useSignMessage = require('./hooks/useSignMessage.js');
|
|
5
|
+
var useSignTransaction = require('./hooks/useSignTransaction.js');
|
|
6
|
+
var useSolanaWallet = require('./hooks/useSolanaWallet.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.useSignAndSendTransaction = useSignAndSendTransaction.useSignAndSendTransaction;
|
|
11
|
+
exports.useSignMessage = useSignMessage.useSignMessage;
|
|
12
|
+
exports.useSignTransaction = useSignTransaction.useSignTransaction;
|
|
13
|
+
exports.useSolanaWallet = useSolanaWallet.useSolanaWallet;
|
|
@@ -479,7 +479,7 @@ function Login(props) {
|
|
|
479
479
|
children: [jsxRuntime.jsxs("div", {
|
|
480
480
|
className: utils.cn("w3a--flex w3a--flex-col w3a--items-center w3a--justify-center w3a--gap-y-2 w3a--pt-6", logoAlignment === "center" ? "" : "w3a--w-full"),
|
|
481
481
|
children: [jsxRuntime.jsx("figure", {
|
|
482
|
-
className: utils.cn("w3a--mx-auto w3a--h-12 w3a--w-[200px]", logoAlignment === "center" ? "w3a--flex w3a--justify-center w3a--items-center" : "w3a--ml-0"),
|
|
482
|
+
className: utils.cn("w3a--mx-auto w3a--h-12 w3a--w-[200px]", logoAlignment === "center" ? "w3a--flex w3a--justify-center w3a--items-center" : "w3a--ml-0 w3a--w-auto"),
|
|
483
483
|
children: jsxRuntime.jsx("img", {
|
|
484
484
|
src: headerLogo || utils.getIcons(isDark ? "logo-dark" : "logo-light"),
|
|
485
485
|
alt: "Logo",
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var vue$1 = require('@web3auth/no-modal/vue');
|
|
5
|
+
var vue = require('vue');
|
|
6
|
+
var useWeb3AuthInner = require('./composables/useWeb3AuthInner.js');
|
|
7
|
+
|
|
8
|
+
const WalletServicesInnerProvider = vue.defineComponent({
|
|
9
|
+
name: "WalletServicesInnerProvider",
|
|
10
|
+
setup() {
|
|
11
|
+
const web3AuthContext = useWeb3AuthInner.useWeb3AuthInner();
|
|
12
|
+
if (!web3AuthContext) throw noModal.WalletServicesPluginError.fromCode(1000, "`WalletServicesProvider` must be wrapped by `Web3AuthProvider`");
|
|
13
|
+
const {
|
|
14
|
+
getPlugin,
|
|
15
|
+
isInitialized,
|
|
16
|
+
isConnected
|
|
17
|
+
} = web3AuthContext;
|
|
18
|
+
const walletServicesPlugin = vue.shallowRef(null);
|
|
19
|
+
const ready = vue.ref(false);
|
|
20
|
+
const connecting = vue.ref(false);
|
|
21
|
+
vue.watch(isInitialized, newIsInitialized => {
|
|
22
|
+
if (newIsInitialized) {
|
|
23
|
+
const plugin = getPlugin(noModal.EVM_PLUGINS.WALLET_SERVICES);
|
|
24
|
+
walletServicesPlugin.value = plugin;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
vue.watch(isConnected, newIsConnected => {
|
|
28
|
+
if (newIsConnected) {
|
|
29
|
+
var _walletServicesPlugin;
|
|
30
|
+
const plugin = getPlugin(noModal.EVM_PLUGINS.WALLET_SERVICES);
|
|
31
|
+
if (!walletServicesPlugin.value) walletServicesPlugin.value = plugin;
|
|
32
|
+
// when rehydrating, the connectedListener may be registered after the connected event is emitted, we need to check the status here
|
|
33
|
+
if (((_walletServicesPlugin = walletServicesPlugin.value) === null || _walletServicesPlugin === void 0 ? void 0 : _walletServicesPlugin.status) === noModal.CONNECTOR_STATUS.CONNECTED) ready.value = true;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
vue.watch(walletServicesPlugin, (newWalletServicesPlugin, prevWalletServicesPlugin) => {
|
|
37
|
+
const connectedListener = () => {
|
|
38
|
+
ready.value = true;
|
|
39
|
+
};
|
|
40
|
+
const disconnectedListener = () => {
|
|
41
|
+
ready.value = false;
|
|
42
|
+
};
|
|
43
|
+
const connectingListener = () => {
|
|
44
|
+
connecting.value = true;
|
|
45
|
+
};
|
|
46
|
+
// unregister previous listeners
|
|
47
|
+
if (prevWalletServicesPlugin && newWalletServicesPlugin !== prevWalletServicesPlugin) {
|
|
48
|
+
prevWalletServicesPlugin.off(noModal.PLUGIN_EVENTS.CONNECTED, connectedListener);
|
|
49
|
+
prevWalletServicesPlugin.off(noModal.PLUGIN_EVENTS.DISCONNECTED, disconnectedListener);
|
|
50
|
+
prevWalletServicesPlugin.off(noModal.PLUGIN_EVENTS.CONNECTING, connectingListener);
|
|
51
|
+
}
|
|
52
|
+
if (newWalletServicesPlugin && newWalletServicesPlugin !== prevWalletServicesPlugin) {
|
|
53
|
+
newWalletServicesPlugin.on(noModal.PLUGIN_EVENTS.CONNECTED, connectedListener);
|
|
54
|
+
newWalletServicesPlugin.on(noModal.PLUGIN_EVENTS.DISCONNECTED, disconnectedListener);
|
|
55
|
+
newWalletServicesPlugin.on(noModal.PLUGIN_EVENTS.CONNECTING, connectingListener);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
vue.provide(vue$1.WalletServicesContextKey, {
|
|
59
|
+
plugin: walletServicesPlugin,
|
|
60
|
+
ready,
|
|
61
|
+
connecting
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
render() {
|
|
65
|
+
var _this$$slots$default;
|
|
66
|
+
return vue.h((_this$$slots$default = this.$slots.default) !== null && _this$$slots$default !== void 0 ? _this$$slots$default : "");
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
exports.WalletServicesInnerProvider = WalletServicesInnerProvider;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var noModal = require('@web3auth/no-modal');
|
|
4
4
|
var vue = require('vue');
|
|
5
5
|
var modalManager = require('../modalManager.js');
|
|
6
|
+
var WalletServicesInnerProvider = require('./WalletServicesInnerProvider.js');
|
|
6
7
|
|
|
7
8
|
const Web3AuthProvider = vue.defineComponent({
|
|
8
9
|
name: "Web3AuthProvider",
|
|
@@ -15,65 +16,22 @@ const Web3AuthProvider = vue.defineComponent({
|
|
|
15
16
|
setup(props) {
|
|
16
17
|
const web3Auth = vue.shallowRef(null);
|
|
17
18
|
const provider = vue.ref(null);
|
|
18
|
-
const userInfo = vue.ref(null);
|
|
19
19
|
const isMFAEnabled = vue.ref(false);
|
|
20
20
|
const status = vue.ref(null);
|
|
21
21
|
const isInitializing = vue.ref(false);
|
|
22
22
|
const initError = vue.ref(null);
|
|
23
23
|
const isInitialized = vue.ref(false);
|
|
24
|
-
const isConnecting = vue.ref(false);
|
|
25
|
-
const connectError = vue.ref(null);
|
|
26
24
|
const isConnected = vue.ref(false);
|
|
27
25
|
const getPlugin = name => {
|
|
28
26
|
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
29
27
|
return web3Auth.value.getPlugin(name);
|
|
30
28
|
};
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
if (!isConnected.value) throw noModal.WalletLoginError.notConnectedError();
|
|
34
|
-
await web3Auth.value.enableMFA(loginParams);
|
|
35
|
-
const localUserInfo = await web3Auth.value.getUserInfo();
|
|
36
|
-
userInfo.value = localUserInfo;
|
|
37
|
-
isMFAEnabled.value = localUserInfo.isMfaEnabled || false;
|
|
38
|
-
};
|
|
39
|
-
const manageMFA = async loginParams => {
|
|
40
|
-
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
41
|
-
if (!isConnected.value) throw noModal.WalletLoginError.notConnectedError();
|
|
42
|
-
await web3Auth.value.manageMFA(loginParams);
|
|
43
|
-
};
|
|
44
|
-
const logout = async (logoutParams = {
|
|
45
|
-
cleanup: false
|
|
46
|
-
}) => {
|
|
47
|
-
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
48
|
-
if (!isConnected.value) throw noModal.WalletLoginError.notConnectedError();
|
|
49
|
-
await web3Auth.value.logout(logoutParams);
|
|
50
|
-
};
|
|
51
|
-
const connect = async () => {
|
|
52
|
-
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
53
|
-
try {
|
|
54
|
-
connectError.value = null;
|
|
55
|
-
isConnecting.value = true;
|
|
56
|
-
const localProvider = await web3Auth.value.connect();
|
|
57
|
-
return localProvider;
|
|
58
|
-
} catch (error) {
|
|
59
|
-
connectError.value = error;
|
|
60
|
-
return null;
|
|
61
|
-
} finally {
|
|
62
|
-
isConnecting.value = false;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
const authenticateUser = async () => {
|
|
66
|
-
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
67
|
-
return web3Auth.value.authenticateUser();
|
|
68
|
-
};
|
|
69
|
-
const switchChain = chainParams => {
|
|
70
|
-
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
71
|
-
return web3Auth.value.switchChain(chainParams);
|
|
29
|
+
const setIsMFAEnabled = isMfaEnabled => {
|
|
30
|
+
isMFAEnabled.value = isMfaEnabled;
|
|
72
31
|
};
|
|
73
32
|
vue.watch(() => props.config, (newConfig, _, onInvalidate) => {
|
|
74
33
|
const resetHookState = () => {
|
|
75
34
|
provider.value = null;
|
|
76
|
-
userInfo.value = null;
|
|
77
35
|
isMFAEnabled.value = false;
|
|
78
36
|
isConnected.value = false;
|
|
79
37
|
status.value = null;
|
|
@@ -114,22 +72,6 @@ const Web3AuthProvider = vue.defineComponent({
|
|
|
114
72
|
}, {
|
|
115
73
|
immediate: true
|
|
116
74
|
});
|
|
117
|
-
vue.watch(isConnected, newIsConnected => {
|
|
118
|
-
if (web3Auth.value) {
|
|
119
|
-
const addState = async web3AuthInstance => {
|
|
120
|
-
provider.value = web3AuthInstance.provider;
|
|
121
|
-
const userState = await web3AuthInstance.getUserInfo();
|
|
122
|
-
userInfo.value = userState;
|
|
123
|
-
isMFAEnabled.value = (userState === null || userState === void 0 ? void 0 : userState.isMfaEnabled) || false;
|
|
124
|
-
};
|
|
125
|
-
const resetState = () => {
|
|
126
|
-
provider.value = null;
|
|
127
|
-
userInfo.value = null;
|
|
128
|
-
isMFAEnabled.value = false;
|
|
129
|
-
};
|
|
130
|
-
if (newIsConnected) addState(web3Auth.value);else resetState();
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
75
|
vue.watch(web3Auth, (newWeb3Auth, prevWeb3Auth) => {
|
|
134
76
|
const notReadyListener = () => {
|
|
135
77
|
status.value = web3Auth.value.status;
|
|
@@ -142,13 +84,16 @@ const Web3AuthProvider = vue.defineComponent({
|
|
|
142
84
|
status.value = web3Auth.value.status;
|
|
143
85
|
// we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
|
|
144
86
|
if (web3Auth.value.status === noModal.CONNECTOR_STATUS.CONNECTED) {
|
|
145
|
-
isInitialized.value = true;
|
|
87
|
+
if (!isInitialized.value) isInitialized.value = true;
|
|
146
88
|
isConnected.value = true;
|
|
89
|
+
provider.value = newWeb3Auth.provider;
|
|
147
90
|
}
|
|
148
91
|
};
|
|
149
92
|
const disconnectedListener = () => {
|
|
150
93
|
status.value = web3Auth.value.status;
|
|
151
94
|
isConnected.value = false;
|
|
95
|
+
provider.value = null;
|
|
96
|
+
isMFAEnabled.value = false;
|
|
152
97
|
};
|
|
153
98
|
const connectingListener = () => {
|
|
154
99
|
status.value = web3Auth.value.status;
|
|
@@ -156,6 +101,9 @@ const Web3AuthProvider = vue.defineComponent({
|
|
|
156
101
|
const errorListener = () => {
|
|
157
102
|
status.value = noModal.CONNECTOR_EVENTS.ERRORED;
|
|
158
103
|
};
|
|
104
|
+
const mfaEnabledListener = () => {
|
|
105
|
+
isMFAEnabled.value = true;
|
|
106
|
+
};
|
|
159
107
|
// unregister previous listeners
|
|
160
108
|
if (prevWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
|
|
161
109
|
prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
|
|
@@ -164,6 +112,7 @@ const Web3AuthProvider = vue.defineComponent({
|
|
|
164
112
|
prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
165
113
|
prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
166
114
|
prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
115
|
+
prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
167
116
|
}
|
|
168
117
|
if (newWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
|
|
169
118
|
status.value = newWeb3Auth.status;
|
|
@@ -174,6 +123,7 @@ const Web3AuthProvider = vue.defineComponent({
|
|
|
174
123
|
newWeb3Auth.on(noModal.CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
|
|
175
124
|
newWeb3Auth.on(noModal.CONNECTOR_EVENTS.CONNECTING, connectingListener);
|
|
176
125
|
newWeb3Auth.on(noModal.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
126
|
+
newWeb3Auth.on(noModal.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
177
127
|
}
|
|
178
128
|
}, {
|
|
179
129
|
immediate: true
|
|
@@ -183,25 +133,17 @@ const Web3AuthProvider = vue.defineComponent({
|
|
|
183
133
|
isConnected,
|
|
184
134
|
isInitialized,
|
|
185
135
|
provider,
|
|
186
|
-
userInfo,
|
|
187
|
-
isMFAEnabled,
|
|
188
136
|
status,
|
|
189
|
-
getPlugin,
|
|
190
|
-
connect,
|
|
191
|
-
enableMFA,
|
|
192
|
-
manageMFA,
|
|
193
|
-
logout,
|
|
194
|
-
authenticateUser,
|
|
195
|
-
switchChain,
|
|
196
137
|
isInitializing,
|
|
197
|
-
isConnecting,
|
|
198
138
|
initError,
|
|
199
|
-
|
|
139
|
+
isMFAEnabled,
|
|
140
|
+
getPlugin,
|
|
141
|
+
setIsMFAEnabled
|
|
200
142
|
});
|
|
201
143
|
},
|
|
202
144
|
render() {
|
|
203
145
|
var _this$$slots$default;
|
|
204
|
-
return vue.h((_this$$slots$default = this.$slots.default) !== null && _this$$slots$default !== void 0 ? _this$$slots$default : "");
|
|
146
|
+
return vue.h(WalletServicesInnerProvider.WalletServicesInnerProvider, {}, (_this$$slots$default = this.$slots.default) !== null && _this$$slots$default !== void 0 ? _this$$slots$default : "");
|
|
205
147
|
}
|
|
206
148
|
});
|
|
207
149
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var vue = require('vue');
|
|
5
|
+
var useWalletServicesPlugin = require('./useWalletServicesPlugin.js');
|
|
6
|
+
|
|
7
|
+
const useCheckout = () => {
|
|
8
|
+
const {
|
|
9
|
+
plugin,
|
|
10
|
+
ready
|
|
11
|
+
} = useWalletServicesPlugin.useWalletServicesPlugin();
|
|
12
|
+
const loading = vue.ref(false);
|
|
13
|
+
const error = vue.ref(null);
|
|
14
|
+
const showCheckout = async showCheckoutParams => {
|
|
15
|
+
loading.value = true;
|
|
16
|
+
error.value = null;
|
|
17
|
+
try {
|
|
18
|
+
if (!plugin) throw noModal.WalletServicesPluginError.notInitialized();
|
|
19
|
+
if (!ready) throw noModal.WalletServicesPluginError.walletPluginNotConnected();
|
|
20
|
+
await plugin.value.showCheckout(showCheckoutParams);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
error.value = err;
|
|
23
|
+
} finally {
|
|
24
|
+
loading.value = false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
loading,
|
|
29
|
+
error,
|
|
30
|
+
showCheckout
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.useCheckout = useCheckout;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var vue = require('vue');
|
|
5
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
6
|
+
|
|
7
|
+
const useEnableMFA = () => {
|
|
8
|
+
const {
|
|
9
|
+
web3Auth
|
|
10
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
11
|
+
const loading = vue.ref(false);
|
|
12
|
+
const error = vue.ref(null);
|
|
13
|
+
const enableMFA = async () => {
|
|
14
|
+
try {
|
|
15
|
+
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
16
|
+
error.value = null;
|
|
17
|
+
loading.value = true;
|
|
18
|
+
await web3Auth.value.enableMFA();
|
|
19
|
+
} catch (err) {
|
|
20
|
+
error.value = err;
|
|
21
|
+
} finally {
|
|
22
|
+
loading.value = false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
loading,
|
|
27
|
+
error,
|
|
28
|
+
enableMFA
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.useEnableMFA = useEnableMFA;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var vue = require('vue');
|
|
5
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
6
|
+
|
|
7
|
+
const useIdentityToken = () => {
|
|
8
|
+
const {
|
|
9
|
+
web3Auth,
|
|
10
|
+
isConnected
|
|
11
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
12
|
+
const loading = vue.ref(false);
|
|
13
|
+
const error = vue.ref(null);
|
|
14
|
+
const token = vue.ref(null);
|
|
15
|
+
const authenticateUser = async () => {
|
|
16
|
+
try {
|
|
17
|
+
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
18
|
+
error.value = null;
|
|
19
|
+
loading.value = true;
|
|
20
|
+
const result = await web3Auth.value.authenticateUser();
|
|
21
|
+
if (result !== null && result !== void 0 && result.idToken) {
|
|
22
|
+
token.value = result.idToken;
|
|
23
|
+
}
|
|
24
|
+
return result === null || result === void 0 ? void 0 : result.idToken;
|
|
25
|
+
} catch (err) {
|
|
26
|
+
error.value = err;
|
|
27
|
+
} finally {
|
|
28
|
+
loading.value = false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
vue.watch(isConnected, newIsConnected => {
|
|
32
|
+
if (!newIsConnected && token.value) {
|
|
33
|
+
token.value = null;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
loading,
|
|
38
|
+
error,
|
|
39
|
+
token,
|
|
40
|
+
authenticateUser
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.useIdentityToken = useIdentityToken;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var vue = require('vue');
|
|
5
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
6
|
+
|
|
7
|
+
const useManageMFA = () => {
|
|
8
|
+
const {
|
|
9
|
+
web3Auth
|
|
10
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
11
|
+
const loading = vue.ref(false);
|
|
12
|
+
const error = vue.ref(null);
|
|
13
|
+
const manageMFA = async () => {
|
|
14
|
+
try {
|
|
15
|
+
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
16
|
+
error.value = null;
|
|
17
|
+
loading.value = true;
|
|
18
|
+
await web3Auth.value.enableMFA();
|
|
19
|
+
} catch (err) {
|
|
20
|
+
error.value = err;
|
|
21
|
+
} finally {
|
|
22
|
+
loading.value = false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
loading,
|
|
27
|
+
error,
|
|
28
|
+
manageMFA
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.useManageMFA = useManageMFA;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var vue = require('vue');
|
|
5
|
+
var useWalletServicesPlugin = require('./useWalletServicesPlugin.js');
|
|
6
|
+
|
|
7
|
+
const useSwap = () => {
|
|
8
|
+
const {
|
|
9
|
+
plugin,
|
|
10
|
+
ready
|
|
11
|
+
} = useWalletServicesPlugin.useWalletServicesPlugin();
|
|
12
|
+
const loading = vue.ref(false);
|
|
13
|
+
const error = vue.ref(null);
|
|
14
|
+
const showSwap = async showSwapParams => {
|
|
15
|
+
loading.value = true;
|
|
16
|
+
error.value = null;
|
|
17
|
+
try {
|
|
18
|
+
if (!plugin) throw noModal.WalletServicesPluginError.notInitialized();
|
|
19
|
+
if (!ready) throw noModal.WalletServicesPluginError.walletPluginNotConnected();
|
|
20
|
+
await plugin.value.showSwap(showSwapParams);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
error.value = err;
|
|
23
|
+
} finally {
|
|
24
|
+
loading.value = false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
loading,
|
|
29
|
+
error,
|
|
30
|
+
showSwap
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.useSwap = useSwap;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var noModal = require('@web3auth/no-modal');
|
|
4
|
+
var vue = require('vue');
|
|
5
|
+
var useWeb3AuthInner = require('./useWeb3AuthInner.js');
|
|
6
|
+
|
|
7
|
+
const useSwitchChain = () => {
|
|
8
|
+
const {
|
|
9
|
+
web3Auth
|
|
10
|
+
} = useWeb3AuthInner.useWeb3AuthInner();
|
|
11
|
+
const loading = vue.ref(false);
|
|
12
|
+
const error = vue.ref(null);
|
|
13
|
+
const switchChain = async chainParams => {
|
|
14
|
+
try {
|
|
15
|
+
if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
|
|
16
|
+
error.value = null;
|
|
17
|
+
loading.value = true;
|
|
18
|
+
await web3Auth.value.switchChain(chainParams);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
error.value = err;
|
|
21
|
+
} finally {
|
|
22
|
+
loading.value = false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
loading,
|
|
27
|
+
error,
|
|
28
|
+
switchChain
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.useSwitchChain = useSwitchChain;
|