Commit 202c2662 authored by aballerr's avatar aballerr Committed by GitHub

fix: Adding socks icon to users profile icon (#4545)

* Adding icon for socks owner for p0 redesign
Co-authored-by: default avatarAlex Ball <alexball@UNISWAP-MAC-038.local>
parent d2afd71c
<svg width="10" height="12" viewBox="0 0 10 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4.75 11C4.75 11 5.22377 11.1391 5.80923 10.5828L7.64433 8.65908C8.35405 7.91508 8.74998 6.92678 8.74989 5.89856C8.7498 4.72716 8.74971 3.31706 8.74991 2.50009C8.74996 2.22391 8.77618 2 8.5 2H8.25M6.74898 5.75L6.74979 2L6.74991 1.50009C6.74996 1.22391 6.52609 1 6.24991 1H4.25167C3.97553 1 3.75167 1.22386 3.75167 1.5V4.75039C3.75167 5.29859 3.52665 5.82276 3.12922 6.20034L1.6891 7.56856C1.10364 8.12478 1.10363 9.0266 1.68909 9.58283C2.12197 9.99409 2.75372 10.1013 3.29025 9.90438C3.47937 9.83497 3.65665 9.72779 3.80923 9.58283L5.80923 7.6827M6.74898 5.75L6.7487 6.36119C6.74861 6.63517 6.63611 6.89711 6.43748 7.08582L5.80923 7.6827M6.74898 5.75H6.4384C5.67845 5.75 5.19623 6.56419 5.56146 7.23061L5.80923 7.6827" stroke="white" stroke-linecap="round"/>
</svg>
import { useWeb3React } from '@web3-react/core'
import { ConnectionType } from 'connection' import { ConnectionType } from 'connection'
import { NavBarVariant, useNavBarFlag } from 'featureFlags/flags/navBar'
import useENSAvatar from 'hooks/useENSAvatar'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { colors } from 'theme/colors'
import CoinbaseWalletIcon from '../../assets/images/coinbaseWalletIcon.svg' import CoinbaseWalletIcon from '../../assets/images/coinbaseWalletIcon.svg'
import WalletConnectIcon from '../../assets/images/walletConnectIcon.svg' import WalletConnectIcon from '../../assets/images/walletConnectIcon.svg'
import sockImg from '../../assets/svg/socks.svg'
import { useHasSocks } from '../../hooks/useSocksBalance'
import Identicon from '../Identicon' import Identicon from '../Identicon'
const IconWrapper = styled.div<{ size?: number }>` const IconWrapper = styled.div<{ size?: number }>`
position: relative;
${({ theme }) => theme.flexColumnNoWrap}; ${({ theme }) => theme.flexColumnNoWrap};
align-items: center; align-items: center;
justify-content: center; justify-content: center;
...@@ -20,19 +27,57 @@ const IconWrapper = styled.div<{ size?: number }>` ...@@ -20,19 +27,57 @@ const IconWrapper = styled.div<{ size?: number }>`
`}; `};
` `
export default function StatusIcon({ connectionType, size }: { connectionType: ConnectionType; size?: number }) { const SockContainer = styled.div`
let image position: absolute;
switch (connectionType) { background-color: ${colors.pink400};
case ConnectionType.INJECTED: display: flex;
image = <Identicon /> justify-content: center;
break border-radius: 50%;
case ConnectionType.WALLET_CONNECT: width: 16px;
image = <img src={WalletConnectIcon} alt="WalletConnect" /> height: 16px;
break bottom: -5px;
case ConnectionType.COINBASE_WALLET: right: -5px;
image = <img src={CoinbaseWalletIcon} alt="Coinbase Wallet" /> `
break
const SockImg = styled.img`
width: 7.5px;
height: 10px;
margin-top: 3px;
`
const Socks = () => {
return (
<SockContainer>
<SockImg src={sockImg} />
</SockContainer>
)
}
const useIcon = (connectionType: ConnectionType) => {
const { account } = useWeb3React()
const { avatar } = useENSAvatar(account ?? undefined)
const isNavbarEnabled = useNavBarFlag() === NavBarVariant.Enabled
if ((isNavbarEnabled && avatar) || connectionType === ConnectionType.INJECTED) {
return <Identicon />
} else if (connectionType === ConnectionType.WALLET_CONNECT) {
return <img src={WalletConnectIcon} alt="WalletConnect" />
} else if (connectionType === ConnectionType.COINBASE_WALLET) {
return <img src={CoinbaseWalletIcon} alt="Coinbase Wallet" />
} }
return <IconWrapper size={size ?? 16}>{image}</IconWrapper> return undefined
}
export default function StatusIcon({ connectionType, size }: { connectionType: ConnectionType; size?: number }) {
const hasSocks = useHasSocks()
const isNavbarEnabled = useNavBarFlag() === NavBarVariant.Enabled
const icon = useIcon(connectionType)
return (
<IconWrapper size={size ?? 16}>
{isNavbarEnabled && hasSocks && <Socks />}
{icon}
</IconWrapper>
)
} }
import jazzicon from '@metamask/jazzicon' import jazzicon from '@metamask/jazzicon'
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { NavBarVariant, useNavBarFlag } from 'featureFlags/flags/navBar'
import useENSAvatar from 'hooks/useENSAvatar' import useENSAvatar from 'hooks/useENSAvatar'
import { useLayoutEffect, useMemo, useRef, useState } from 'react' import { useLayoutEffect, useMemo, useRef, useState } from 'react'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
const StyledIdenticon = styled.div` const StyledIdenticon = styled.div<{ isNavbarEnabled: boolean }>`
height: 1rem; height: ${({ isNavbarEnabled }) => (isNavbarEnabled ? '24px' : '1rem')};
width: 1rem; width: ${({ isNavbarEnabled }) => (isNavbarEnabled ? '24px' : '1rem')};
border-radius: 1.125rem; border-radius: 1.125rem;
background-color: ${({ theme }) => theme.deprecated_bg4}; background-color: ${({ theme }) => theme.deprecated_bg4};
font-size: initial; font-size: initial;
...@@ -22,8 +23,10 @@ export default function Identicon() { ...@@ -22,8 +23,10 @@ export default function Identicon() {
const { account } = useWeb3React() const { account } = useWeb3React()
const { avatar } = useENSAvatar(account ?? undefined) const { avatar } = useENSAvatar(account ?? undefined)
const [fetchable, setFetchable] = useState(true) const [fetchable, setFetchable] = useState(true)
const isNavbarEnabled = useNavBarFlag() === NavBarVariant.Enabled
const iconSize = isNavbarEnabled ? 24 : 16
const icon = useMemo(() => account && jazzicon(16, parseInt(account.slice(2, 10), 16)), [account]) const icon = useMemo(() => account && jazzicon(iconSize, parseInt(account.slice(2, 10), 16)), [account, iconSize])
const iconRef = useRef<HTMLDivElement>(null) const iconRef = useRef<HTMLDivElement>(null)
useLayoutEffect(() => { useLayoutEffect(() => {
const current = iconRef.current const current = iconRef.current
...@@ -41,7 +44,7 @@ export default function Identicon() { ...@@ -41,7 +44,7 @@ export default function Identicon() {
}, [icon, iconRef]) }, [icon, iconRef])
return ( return (
<StyledIdenticon> <StyledIdenticon isNavbarEnabled={isNavbarEnabled}>
{avatar && fetchable ? ( {avatar && fetchable ? (
<StyledAvatar alt="avatar" src={avatar} onError={() => setFetchable(false)}></StyledAvatar> <StyledAvatar alt="avatar" src={avatar} onError={() => setFetchable(false)}></StyledAvatar>
) : ( ) : (
......
...@@ -228,7 +228,7 @@ function Web3StatusInner() { ...@@ -228,7 +228,7 @@ function Web3StatusInner() {
</RowBetween> </RowBetween>
) : ( ) : (
<> <>
{hasSocks ? <Sock /> : null} {hasSocks && !navbarFlagEnabled ? <Sock /> : null}
<Text>{ENSName || shortenAddress(account)}</Text> <Text>{ENSName || shortenAddress(account)}</Text>
{navbarFlagEnabled ? ( {navbarFlagEnabled ? (
walletIsOpen ? ( walletIsOpen ? (
......
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