Skip to content

Commit

Permalink
fix: Style component
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Oct 20, 2023
1 parent 59ad714 commit b2e06df
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 20 deletions.
13 changes: 11 additions & 2 deletions src/components/common/ConnectWallet/AccountCenter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MouseEvent } from 'react'
import { useState } from 'react'
import { Box, Button, ButtonBase, Paper, Popover, Skeleton, Typography } from '@mui/material'
import { Box, Button, ButtonBase, Paper, Popover, Typography } from '@mui/material'
import css from '@/components/common/ConnectWallet/styles.module.css'
import EthHashInfo from '@/components/common/EthHashInfo'
import ExpandLessIcon from '@mui/icons-material/ExpandLess'
Expand All @@ -13,12 +13,15 @@ import ChainSwitcher from '../ChainSwitcher'
import useAddressBook from '@/hooks/useAddressBook'
import { type ConnectedWallet } from '@/hooks/wallets/useOnboard'
import WalletInfo, { UNKNOWN_CHAIN_NAME } from '../WalletInfo'
import useWalletBalance from '@/hooks/wallets/useWalletBalance'
import WalletBalance from '@/components/common/WalletBalance'

const AccountCenter = ({ wallet }: { wallet: ConnectedWallet }) => {
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null)
const onboard = useOnboard()
const chainInfo = useAppSelector((state) => selectChainById(state, wallet.chainId))
const addressBook = useAddressBook()
const [balance] = useWalletBalance()
const prefix = chainInfo?.shortName

const handleSwitchWallet = () => {
Expand Down Expand Up @@ -53,7 +56,7 @@ const AccountCenter = ({ wallet }: { wallet: ConnectedWallet }) => {
<>
<ButtonBase onClick={handleClick} aria-describedby={id} disableRipple sx={{ alignSelf: 'stretch' }}>
<Box className={css.buttonContainer}>
<WalletInfo wallet={wallet} />
<WalletInfo wallet={wallet} balance={balance} />

<Box display="flex" alignItems="center" justifyContent="flex-end" marginLeft="auto">
{open ? <ExpandLessIcon color="border" /> : <ExpandMoreIcon color="border" />}
Expand Down Expand Up @@ -103,6 +106,12 @@ const AccountCenter = ({ wallet }: { wallet: ConnectedWallet }) => {
<Typography variant="caption">Connected network</Typography>
<Typography variant="body2">{chainInfo?.chainName || UNKNOWN_CHAIN_NAME}</Typography>
</Box>
<Box className={css.row}>
<Typography variant="caption">Balance</Typography>
<Typography variant="body2">
<WalletBalance chainInfo={chainInfo} balance={balance} />
</Typography>
</Box>
</Box>

<ChainSwitcher fullWidth />
Expand Down
18 changes: 18 additions & 0 deletions src/components/common/WalletBalance/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { type ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { formatVisualAmount } from '@/utils/formatters'
import { Skeleton } from '@mui/material'

const WalletBalance = ({ chainInfo, balance }: { chainInfo: ChainInfo | undefined; balance: BigInt | undefined }) => {
if (!balance) {
return <Skeleton width={30} />
}

return (
<>
{formatVisualAmount(balance.toString(10), chainInfo?.nativeCurrency.decimals ?? 18)}{' '}
{chainInfo?.nativeCurrency.symbol ?? 'ETH'}
</>
)
}

export default WalletBalance
33 changes: 15 additions & 18 deletions src/components/common/WalletInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Skeleton, Typography } from '@mui/material'
import { Box, Typography } from '@mui/material'
import { Suspense } from 'react'
import type { ReactElement } from 'react'

Expand All @@ -9,26 +9,31 @@ import { useAppSelector } from '@/store'
import { selectChainById } from '@/store/chainsSlice'

import css from './styles.module.css'
import useWalletBalance from '@/hooks/wallets/useWalletBalance'
import { formatVisualAmount } from '@/utils/formatters'
import Identicon from '@/components/common/Identicon'
import classnames from 'classnames'
import WalletBalance from '@/components/common/WalletBalance'

export const UNKNOWN_CHAIN_NAME = 'Unknown'

const WalletInfo = ({ wallet }: { wallet: ConnectedWallet }): ReactElement => {
const WalletInfo = ({ wallet, balance }: { wallet: ConnectedWallet; balance: BigInt | undefined }): ReactElement => {
const walletChain = useAppSelector((state) => selectChainById(state, wallet.chainId))
const prefix = walletChain?.shortName
const [balance, balanceError, balanceLoading] = useWalletBalance()

const isMetaMask = wallet.label === 'MetaMask'

return (
<Box className={css.container}>
<Box className={css.imageContainer}>
<Identicon address={wallet.address} size={34} />
<Suspense>
<WalletIcon provider={wallet.label} icon={wallet.icon} />
</Suspense>{' '}
<Box className={classnames(css.walletIcon, { [css.animate]: isMetaMask })}>
<WalletIcon provider={wallet.label} icon={wallet.icon} width={16} height={16} />
</Box>
</Suspense>
</Box>

<Box className={css.walletDetails}>
<Typography variant="caption" fontWeight="bold" component="div">
<Typography variant="body2" component="div">
{wallet.ens ? (
<div>{wallet.ens}</div>
) : (
Expand All @@ -43,16 +48,8 @@ const WalletInfo = ({ wallet }: { wallet: ConnectedWallet }): ReactElement => {
</Typography>

<Box display="flex" flexDirection="row" alignItems="center" gap={1}>
<Typography variant="caption" component="div" className={css.balance}>
{balance !== undefined ? (
<>
{' '}
{formatVisualAmount(balance.toString(10), walletChain?.nativeCurrency.decimals ?? 18)}{' '}
{walletChain?.nativeCurrency.symbol ?? 'ETH'}
</>
) : (
<Skeleton />
)}
<Typography variant="caption" component="div" fontWeight="bold" className={css.balance}>
<WalletBalance chainInfo={walletChain} balance={balance} />
</Typography>
</Box>
</Box>
Expand Down
31 changes: 31 additions & 0 deletions src/components/common/WalletInfo/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@
.imageContainer {
display: flex;
justify-content: center;
position: relative;
}

.walletIcon {
position: absolute;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
bottom: -4px;
right: -4px;
border-radius: 50%;
outline: rgb(255, 255, 255) solid 2px;
outline-offset: -0.1px;
background-color: rgb(255, 255, 255);
overflow: hidden;
}

.animate img {
animation: 30s scale-up;
}

@keyframes scale-up {
from {
transform: scale(1) rotateZ(0deg);
}

to {
transform: scale(2) rotateZ(10deg);
}
}

[data-theme='dark'] .imageContainer img[alt*='Ledger'] {
Expand Down

0 comments on commit b2e06df

Please sign in to comment.