Commit 3009c972 authored by Max Alekseenko's avatar Max Alekseenko Committed by GitHub

Merge pull request #1838 from blockscout/manage-wallet-button

Add manage wallet button
parents c4686d4e 9ffeb72c
import { Box, Button, Text, Flex } from '@chakra-ui/react'; import { Box, Button, Text, Flex, IconButton } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import * as mixpanel from 'lib/mixpanel/index'; import * as mixpanel from 'lib/mixpanel/index';
...@@ -12,15 +12,24 @@ type Props = { ...@@ -12,15 +12,24 @@ type Props = {
address?: string; address?: string;
disconnect?: () => void; disconnect?: () => void;
isAutoConnectDisabled?: boolean; isAutoConnectDisabled?: boolean;
openWeb3Modal: () => void;
closeWalletMenu: () => void;
}; };
const WalletMenuContent = ({ address, disconnect, isAutoConnectDisabled }: Props) => { const WalletMenuContent = ({ address, disconnect, isAutoConnectDisabled, openWeb3Modal, closeWalletMenu }: Props) => {
const { themedBackgroundOrange } = useMenuButtonColors(); const { themedBackgroundOrange } = useMenuButtonColors();
const [ isModalOpening, setIsModalOpening ] = React.useState(false);
const onAddressClick = React.useCallback(() => { const onAddressClick = React.useCallback(() => {
mixpanel.logEvent(mixpanel.EventTypes.WALLET_ACTION, { Action: 'Address click' }); mixpanel.logEvent(mixpanel.EventTypes.WALLET_ACTION, { Action: 'Address click' });
}, []); }, []);
const handleOpenWeb3Modal = React.useCallback(async() => {
setIsModalOpening(true);
await openWeb3Modal();
setTimeout(closeWalletMenu, 300);
}, [ openWeb3Modal, closeWalletMenu ]);
return ( return (
<Box> <Box>
{ isAutoConnectDisabled && ( { isAutoConnectDisabled && (
...@@ -60,16 +69,28 @@ const WalletMenuContent = ({ address, disconnect, isAutoConnectDisabled }: Props ...@@ -60,16 +69,28 @@ const WalletMenuContent = ({ address, disconnect, isAutoConnectDisabled }: Props
> >
Your wallet is used to interact with apps and contracts in the explorer. Your wallet is used to interact with apps and contracts in the explorer.
</Text> </Text>
<AddressEntity <Flex alignItems="center" mb={ 6 }>
address={{ hash: address }} <AddressEntity
noTooltip address={{ hash: address }}
truncation="dynamic" noTooltip
fontSize="sm" truncation="dynamic"
fontWeight={ 700 } fontSize="sm"
color="text" fontWeight={ 700 }
mb={ 6 } color="text"
onClick={ onAddressClick } onClick={ onAddressClick }
/> flex={ 1 }
/>
<IconButton
aria-label="open wallet"
icon={ <IconSvg name="gear_slim" boxSize={ 5 }/> }
variant="simple"
h="20px"
w="20px"
ml={ 1 }
onClick={ handleOpenWeb3Modal }
isLoading={ isModalOpening }
/>
</Flex>
<Button size="sm" width="full" variant="outline" onClick={ disconnect }> <Button size="sm" width="full" variant="outline" onClick={ disconnect }>
Disconnect Disconnect
</Button> </Button>
......
...@@ -20,7 +20,7 @@ type Props = { ...@@ -20,7 +20,7 @@ type Props = {
}; };
const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => { const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => {
const { isWalletConnected, address, connect, disconnect, isModalOpening, isModalOpen } = useWallet({ source: 'Header' }); const { isWalletConnected, address, connect, disconnect, isModalOpening, isModalOpen, openModal } = useWallet({ source: 'Header' });
const { themedBackground, themedBackgroundOrange, themedBorderColor, themedColor } = useMenuButtonColors(); const { themedBackground, themedBackgroundOrange, themedBorderColor, themedColor } = useMenuButtonColors();
const [ isPopoverOpen, setIsPopoverOpen ] = useBoolean(false); const [ isPopoverOpen, setIsPopoverOpen ] = useBoolean(false);
const isMobile = useIsMobile(); const isMobile = useIsMobile();
...@@ -82,7 +82,7 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => { ...@@ -82,7 +82,7 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => {
variant={ variant } variant={ variant }
colorScheme="blue" colorScheme="blue"
flexShrink={ 0 } flexShrink={ 0 }
isLoading={ isModalOpening || isModalOpen } isLoading={ (isModalOpening || isModalOpen) && !isWalletConnected }
loadingText="Connect wallet" loadingText="Connect wallet"
onClick={ isWalletConnected ? openPopover : connect } onClick={ isWalletConnected ? openPopover : connect }
fontSize="sm" fontSize="sm"
...@@ -102,7 +102,13 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => { ...@@ -102,7 +102,13 @@ const WalletMenuDesktop = ({ isHomePage, className, size = 'md' }: Props) => {
{ isWalletConnected && ( { isWalletConnected && (
<PopoverContent w="235px"> <PopoverContent w="235px">
<PopoverBody padding="24px 16px 16px 16px"> <PopoverBody padding="24px 16px 16px 16px">
<WalletMenuContent address={ address } disconnect={ disconnect } isAutoConnectDisabled={ isAutoConnectDisabled }/> <WalletMenuContent
address={ address }
disconnect={ disconnect }
isAutoConnectDisabled={ isAutoConnectDisabled }
openWeb3Modal={ openModal }
closeWalletMenu={ setIsPopoverOpen.off }
/>
</PopoverBody> </PopoverBody>
</PopoverContent> </PopoverContent>
) } ) }
......
...@@ -14,7 +14,7 @@ import WalletTooltip from './WalletTooltip'; ...@@ -14,7 +14,7 @@ import WalletTooltip from './WalletTooltip';
const WalletMenuMobile = () => { const WalletMenuMobile = () => {
const { isOpen, onOpen, onClose } = useDisclosure(); const { isOpen, onOpen, onClose } = useDisclosure();
const { isWalletConnected, address, connect, disconnect, isModalOpening, isModalOpen } = useWallet({ source: 'Header' }); const { isWalletConnected, address, connect, disconnect, isModalOpening, isModalOpen, openModal } = useWallet({ source: 'Header' });
const { themedBackground, themedBackgroundOrange, themedBorderColor, themedColor } = useMenuButtonColors(); const { themedBackground, themedBackgroundOrange, themedBorderColor, themedColor } = useMenuButtonColors();
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const { isAutoConnectDisabled } = useMarketplaceContext(); const { isAutoConnectDisabled } = useMarketplaceContext();
...@@ -48,7 +48,7 @@ const WalletMenuMobile = () => { ...@@ -48,7 +48,7 @@ const WalletMenuMobile = () => {
color={ themedColor } color={ themedColor }
borderColor={ !isWalletConnected ? themedBorderColor : undefined } borderColor={ !isWalletConnected ? themedBorderColor : undefined }
onClick={ isWalletConnected ? openPopover : connect } onClick={ isWalletConnected ? openPopover : connect }
isLoading={ isModalOpening || isModalOpen } isLoading={ (isModalOpening || isModalOpen) && !isWalletConnected }
/> />
</WalletTooltip> </WalletTooltip>
{ isWalletConnected && ( { isWalletConnected && (
...@@ -61,7 +61,13 @@ const WalletMenuMobile = () => { ...@@ -61,7 +61,13 @@ const WalletMenuMobile = () => {
<DrawerOverlay/> <DrawerOverlay/>
<DrawerContent maxWidth="260px"> <DrawerContent maxWidth="260px">
<DrawerBody p={ 6 }> <DrawerBody p={ 6 }>
<WalletMenuContent address={ address } disconnect={ disconnect } isAutoConnectDisabled={ isAutoConnectDisabled }/> <WalletMenuContent
address={ address }
disconnect={ disconnect }
isAutoConnectDisabled={ isAutoConnectDisabled }
openWeb3Modal={ openModal }
closeWalletMenu={ onClose }
/>
</DrawerBody> </DrawerBody>
</DrawerContent> </DrawerContent>
</Drawer> </Drawer>
......
...@@ -45,6 +45,7 @@ export default function useWallet({ source }: Params) { ...@@ -45,6 +45,7 @@ export default function useWallet({ source }: Params) {
const isWalletConnected = isClientLoaded && !isDisconnected && address !== undefined; const isWalletConnected = isClientLoaded && !isDisconnected && address !== undefined;
return { return {
openModal: open,
isWalletConnected, isWalletConnected,
address: address || '', address: address || '',
connect: handleConnect, connect: handleConnect,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment