diff --git a/apps/sample-react-app/src/Components/SwitchWalletButton.tsx b/apps/sample-react-app/src/Components/SwitchWalletButton.tsx index 4f7753a7..ff993976 100644 --- a/apps/sample-react-app/src/Components/SwitchWalletButton.tsx +++ b/apps/sample-react-app/src/Components/SwitchWalletButton.tsx @@ -1,11 +1,7 @@ import type { HTMLChakraProps } from '@chakra-ui/react'; import { Button, Icon, useDisclosure } from '@chakra-ui/react'; import React from 'react'; -import { - ConnectWalletModal, - useWallet, - useWalletModal, -} from '@vechainfoundation/dapp-kit-react'; +import { useWallet, useWalletModal } from '@vechainfoundation/dapp-kit-react'; import { WalletIcon } from '@heroicons/react/24/solid'; import { AccountDetailModal } from './AccountDetailModal'; import { AddressButton } from './AddressButton'; @@ -42,16 +38,12 @@ export const SwitchWalletButton: React.FC = ({ ); return ( - <> - - - - + ); }; diff --git a/apps/sample-react-app/src/Components/layout/NavBar.tsx b/apps/sample-react-app/src/Components/layout/NavBar.tsx index 37af2c9b..029efad9 100644 --- a/apps/sample-react-app/src/Components/layout/NavBar.tsx +++ b/apps/sample-react-app/src/Components/layout/NavBar.tsx @@ -17,9 +17,11 @@ import { import type { JSX } from 'react'; import React from 'react'; import { Bars3Icon } from '@heroicons/react/24/solid'; -import { useWallet } from '@vechainfoundation/dapp-kit-react'; +import { + ConnectWalletButtonWithModal, + useWallet, +} from '@vechainfoundation/dapp-kit-react'; import { AccountDetailBody } from '../AccountDetailBody'; -import { SwitchWalletButton } from '../SwitchWalletButton'; export const NavBar = (): JSX.Element => { const bg = useColorModeValue('gray.50', 'gray.900'); @@ -96,7 +98,7 @@ const MobileNavBarDrawer = ({ source={source} /> ) : ( - + )} @@ -109,7 +111,7 @@ const MobileNavBarDrawer = ({ const NavBarWalletConnect = (): JSX.Element => { return ( - + ); }; diff --git a/packages/dapp-kit-react/src/Components/ConnectWalletButtonWithModal/Components/ConnectButtonWithModal.tsx b/packages/dapp-kit-react/src/Components/ConnectWalletButtonWithModal/Components/ConnectButtonWithModal.tsx index 7311fea7..78a7ae43 100644 --- a/packages/dapp-kit-react/src/Components/ConnectWalletButtonWithModal/Components/ConnectButtonWithModal.tsx +++ b/packages/dapp-kit-react/src/Components/ConnectWalletButtonWithModal/Components/ConnectButtonWithModal.tsx @@ -1,66 +1,33 @@ -import { useCallback, useContext, useState } from 'react'; +import { useCallback, useContext } from 'react'; import type { WalletSource } from '@vechainfoundation/dapp-kit'; import type { SourceInfo } from '@vechainfoundation/dapp-kit-ui'; import { ThemeContext } from '../../../provider/ThemeProvider'; import { useWallet } from '../../../ConnexProvider'; import { ConnectModalWithButtonWrapped } from './Wrapped/ConnectModalWithButtonWrapped'; -interface ConnectButtonWithModalProps { - onClose?: () => void; -} - -export const ConnectButtonWithModal = ({ - onClose, -}: ConnectButtonWithModalProps) => { +export const ConnectButtonWithModal = () => { const { theme } = useContext(ThemeContext); - const handleSourceClick = (e: SourceInfo | undefined): void => { - if (!e) return; - - _connect(e.id); - }; - - const { setAccount, connect, setSource } = useWallet(); - - const [connectionLoading, setConnectionLoading] = useState(false); - const [connectionError, setConnectionError] = useState(''); + const { setSource, connect, setAccount } = useWallet(); const connectHandler = useCallback( async (source: WalletSource) => { - try { - setSource(source); - setConnectionError(''); - setConnectionLoading(true); + setSource(source); - const { account } = await connect(); - setAccount(account); + const { account } = await connect(); - onClose?.(); - } catch (e) { - if (e instanceof Error) { - setConnectionError(e.message); - } else { - setConnectionError('Failed to connect to wallet'); - } - } finally { - setConnectionLoading(false); - } + setAccount(account); }, - [ - connect, - onClose, - setAccount, - setConnectionError, - setConnectionLoading, - setSource, - ], + [connect, setAccount, setSource], ); const _connect = useCallback( - (source: WalletSource) => { - connectHandler(source).catch(() => { - // do nothing - }); + (source?: SourceInfo) => { + if (source) { + connectHandler(source.id).catch(() => { + // do nothing + }); + } }, [connectHandler], ); @@ -69,10 +36,8 @@ export const ConnectButtonWithModal = ({ <> - {connectionError} - {connectionLoading} ); }; diff --git a/packages/dapp-kit-react/src/Components/ConnectWalletButtonWithModal/ConnectWalletButton.tsx b/packages/dapp-kit-react/src/Components/ConnectWalletButtonWithModal/ConnectWalletButton.tsx index ee8f3220..e2a106eb 100644 --- a/packages/dapp-kit-react/src/Components/ConnectWalletButtonWithModal/ConnectWalletButton.tsx +++ b/packages/dapp-kit-react/src/Components/ConnectWalletButtonWithModal/ConnectWalletButton.tsx @@ -15,8 +15,8 @@ export const ConnectWalletButtonWithModal: React.FC< return ( - + ); }; diff --git a/packages/dapp-kit-react/src/Components/ConnectWalletModal/ConnectWalletModal.tsx b/packages/dapp-kit-react/src/Components/ConnectWalletModal/ConnectWalletModal.tsx deleted file mode 100644 index f65e2380..00000000 --- a/packages/dapp-kit-react/src/Components/ConnectWalletModal/ConnectWalletModal.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import React, { useCallback } from 'react'; -import type { WalletSource } from '@vechainfoundation/dapp-kit'; -import type { SourceInfo } from '@vechainfoundation/dapp-kit-ui'; -import { ConnectModal } from '@vechainfoundation/dapp-kit-ui'; -import { createComponent } from '@lit/react'; -import GlobalFonts from '../../../assets/fonts/fonts'; -import { ThemeProvider } from '../../provider/ThemeProvider'; -import { ThemeSelector } from '../ThemeSelector'; -import { useWallet } from '../../ConnexProvider'; - -export const ConnectModalWrapped = createComponent({ - tagName: 'vwk-connect-modal', - elementClass: ConnectModal, - react: React, -}); - -export const ConnectWalletModal: React.FC = (): React.ReactElement => { - const { setSource, connect, setAccount } = useWallet(); - - const connectHandler = useCallback( - async (source: WalletSource) => { - setSource(source); - - const { account } = await connect(); - - setAccount(account); - }, - [connect, setAccount, setSource], - ); - - const _connect = useCallback( - (source?: SourceInfo) => { - if (source) { - connectHandler(source.id).catch(() => { - // do nothing - }); - } - }, - [connectHandler], - ); - - return ( - - - - - - ); -}; diff --git a/packages/dapp-kit-react/src/Components/ConnectWalletModal/index.ts b/packages/dapp-kit-react/src/Components/ConnectWalletModal/index.ts deleted file mode 100644 index 423a5eae..00000000 --- a/packages/dapp-kit-react/src/Components/ConnectWalletModal/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './ConnectWalletModal'; diff --git a/packages/dapp-kit-react/src/Components/index.ts b/packages/dapp-kit-react/src/Components/index.ts index 925ebed8..590adc22 100644 --- a/packages/dapp-kit-react/src/Components/index.ts +++ b/packages/dapp-kit-react/src/Components/index.ts @@ -1,2 +1 @@ -export * from './ConnectWalletModal'; export * from './ConnectWalletButtonWithModal';