@mojito-inc/connect-wallet
Version:
Connecting wallet via metamask, wallet connect, email
40 lines (37 loc) • 1.54 kB
JavaScript
import { useMemo } from 'react';
import { useConnect, useActiveAccount, useDisconnect, useActiveWallet, useActiveWalletChain, useActiveWalletConnectionStatus } from 'thirdweb/react';
import { inAppWallet } from 'thirdweb/wallets';
import { useWalletType } from '../provider/WalletTypeProvider.js';
/* eslint-disable react-hooks/rules-of-hooks */
const useEthWalletsMethod = () => {
const { walletType } = useWalletType();
const isEthereumWallet = useMemo(() => walletType === 'ethereum', [walletType]);
if (isEthereumWallet) {
const thirdWebWallet = inAppWallet();
const { connect } = useConnect();
const activeAccount = useActiveAccount();
const { disconnect: thirdWebDisconnect } = useDisconnect();
const connectedThirdWebWallet = useActiveWallet();
const thirdWebConnectedChain = useActiveWalletChain();
const connectionStatus = useActiveWalletConnectionStatus();
return {
thirdWebWallet,
connect,
activeAccount,
thirdWebDisconnect,
connectedThirdWebWallet,
thirdWebConnectedChain,
connectionStatus,
};
}
return {
thirdWebWallet: undefined,
connect: undefined,
activeAccount: undefined,
thirdWebDisconnect: undefined,
connectedThirdWebWallet: undefined,
thirdWebConnectedChain: undefined,
connectionStatus: undefined,
};
};
export { useEthWalletsMethod as default };