fix: show ens in wallet dropdown too if available (#5564)

* done

* handle no ENS case
This commit is contained in:
lynn 2022-12-07 14:38:40 -05:00 committed by GitHub
parent d4cb32c4c3
commit a4c54ff953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,8 @@ import { Text } from 'rebass'
import { useCurrencyBalanceString } from 'state/connection/hooks'
import { useAppDispatch } from 'state/hooks'
import { updateSelectedWallet } from 'state/user/reducer'
import styled from 'styled-components/macro'
import styled, { css } from 'styled-components/macro'
import { ThemedText } from 'theme'
import { shortenAddress } from '../../nft/utils/address'
import { useCloseModal, useToggleModal } from '../../state/application/hooks'
@ -82,6 +83,30 @@ const FlexContainer = styled.div`
const StatusWrapper = styled.div`
display: inline-block;
margin-top: 4px;
width: 70%;
`
const TruncatedTextStyle = css`
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
`
const AccountNamesWrapper = styled.div`
${TruncatedTextStyle}
margin-right: 8px;
`
const ENSNameContainer = styled(ThemedText.SubHeader)`
${TruncatedTextStyle}
color: ${({ theme }) => theme.textPrimary};
margin-top: 2.5px;
`
const AccountContainer = styled(ThemedText.BodySmall)`
${TruncatedTextStyle}
color: ${({ theme }) => theme.textSecondary};
margin-top: 2.5px;
`
const BalanceWrapper = styled.div`
@ -99,7 +124,7 @@ const AuthenticatedHeaderWrapper = styled.div`
`
const AuthenticatedHeader = () => {
const { account, chainId, connector } = useWeb3React()
const { account, chainId, connector, ENSName } = useWeb3React()
const [isCopied, setCopied] = useCopyClipboard()
const copy = useCallback(() => {
setCopied(account || '')
@ -153,9 +178,14 @@ const AuthenticatedHeader = () => {
<StatusWrapper>
<FlexContainer>
<StatusIcon connectionType={connectionType} size={24} />
<Text fontSize={16} fontWeight={600} marginTop="2.5px">
{account && shortenAddress(account, 2, 4)}
</Text>
{ENSName ? (
<AccountNamesWrapper>
<ENSNameContainer>{ENSName}</ENSNameContainer>
<AccountContainer>{account && shortenAddress(account, 2, 4)}</AccountContainer>
</AccountNamesWrapper>
) : (
<ThemedText.SubHeader marginTop="2.5px">{account && shortenAddress(account, 2, 4)}</ThemedText.SubHeader>
)}
</FlexContainer>
</StatusWrapper>
<IconContainer>