@dynamic-labs/sdk-react-core
Version:
A React SDK for implementing wallet web3 authentication and authorization to your website.
45 lines (42 loc) • 2.29 kB
JavaScript
'use client'
import { useMemo } from 'react';
import { usingV3Wallets } from '../../functions/usingV3Wallets/usingV3Wallets.js';
import { getProjectSettings } from '../../../store/state/projectSettings/projectSettings.js';
import { isTurnkeyEnabled } from '../../functions/isTurnkeyEnabled/isTurnkeyEnabled.js';
import { useAuthMode } from '../../../store/state/authMode/authMode.js';
import { useUser } from '../../../store/state/user/user.js';
import '@dynamic-labs/utils';
import '../../constants/values.js';
import '@dynamic-labs/sdk-api-core';
const useIsLoadingEmbeddedWallet = () => {
const { user } = useUser();
const authMode = useAuthMode();
const projectSettings = getProjectSettings();
// we only want to show the loading state if the user has no wallets at all, and is creating a waas wallet
// for example if they sign up with phantom wallet, we don't want to show the loading state
// always return false for connect-only mode, because verified credentials are not used in this mode
// except when user is logging in with email and will get an embedded wallet
const isLoadingEmbeddedWallet = useMemo(() => {
var _a, _b;
if (!usingV3Wallets(projectSettings) ||
!isTurnkeyEnabled(projectSettings)) {
return false;
}
const isEmailLogin = (_a = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.some((credential) => credential.format === 'email');
const hasWallet = (_b = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _b === void 0 ? void 0 : _b.some((credential) => credential.format === 'blockchain');
if (authMode === 'connect-only') {
if (isEmailLogin) {
if (hasWallet) {
return false;
}
return true;
}
// login with injected wallet will already have a primary wallet set so we dont need to show loading state
return false;
}
// If user has NO blockchain credential, then we show loading state
return !hasWallet;
}, [projectSettings, user, authMode]);
return { isLoadingEmbeddedWallet };
};
export { useIsLoadingEmbeddedWallet };