diff --git a/src/components/common/ConnectWallet/AccountCenter.tsx b/src/components/common/ConnectWallet/AccountCenter.tsx index f4a86686e9..d77363d4d2 100644 --- a/src/components/common/ConnectWallet/AccountCenter.tsx +++ b/src/components/common/ConnectWallet/AccountCenter.tsx @@ -56,7 +56,7 @@ const AccountCenter = ({ wallet }: { wallet: ConnectedWallet }) => { <> - + {open ? : } @@ -109,7 +109,7 @@ const AccountCenter = ({ wallet }: { wallet: ConnectedWallet }) => { Balance - + diff --git a/src/components/common/WalletBalance/index.tsx b/src/components/common/WalletBalance/index.tsx index aa87361a2d..d486ec2e55 100644 --- a/src/components/common/WalletBalance/index.tsx +++ b/src/components/common/WalletBalance/index.tsx @@ -1,16 +1,19 @@ -import { type ChainInfo } from '@safe-global/safe-gateway-typescript-sdk' import { formatVisualAmount } from '@/utils/formatters' import { Skeleton } from '@mui/material' +import { type BigNumber } from 'ethers' +import { useCurrentChain } from '@/hooks/useChains' + +const WalletBalance = ({ balance }: { balance: BigNumber | undefined }) => { + const currentChain = useCurrentChain() -const WalletBalance = ({ chainInfo, balance }: { chainInfo: ChainInfo | undefined; balance: BigInt | undefined }) => { if (!balance) { return } return ( <> - {formatVisualAmount(balance.toString(10), chainInfo?.nativeCurrency.decimals ?? 18)}{' '} - {chainInfo?.nativeCurrency.symbol ?? 'ETH'} + {formatVisualAmount(balance, currentChain?.nativeCurrency.decimals ?? 18)}{' '} + {currentChain?.nativeCurrency.symbol ?? 'ETH'} ) } diff --git a/src/components/common/WalletInfo/index.tsx b/src/components/common/WalletInfo/index.tsx index ecea88cfdd..6d0400df22 100644 --- a/src/components/common/WalletInfo/index.tsx +++ b/src/components/common/WalletInfo/index.tsx @@ -12,10 +12,19 @@ import css from './styles.module.css' import Identicon from '@/components/common/Identicon' import classnames from 'classnames' import WalletBalance from '@/components/common/WalletBalance' +import { type BigNumber } from 'ethers' export const UNKNOWN_CHAIN_NAME = 'Unknown' -const WalletInfo = ({ wallet, balance }: { wallet: ConnectedWallet; balance: BigInt | undefined }): ReactElement => { +const WalletInfo = ({ + wallet, + balance, + showBalance = false, +}: { + wallet: ConnectedWallet + balance?: BigNumber | undefined + showBalance?: boolean +}): ReactElement => { const walletChain = useAppSelector((state) => selectChainById(state, wallet.chainId)) const prefix = walletChain?.shortName @@ -47,11 +56,13 @@ const WalletInfo = ({ wallet, balance }: { wallet: ConnectedWallet; balance: Big )} - - - - - + {showBalance && ( + + + + + + )} ) diff --git a/src/components/tx/BalanceInfo/index.tsx b/src/components/tx/BalanceInfo/index.tsx new file mode 100644 index 0000000000..0a5b020e24 --- /dev/null +++ b/src/components/tx/BalanceInfo/index.tsx @@ -0,0 +1,28 @@ +import { Box, Stack, SvgIcon, Typography } from '@mui/material' +import GasStationIcon from '@/public/images/common/gas-station.svg' +import css from './styles.module.css' +import useWalletBalance from '@/hooks/wallets/useWalletBalance' +import WalletBalance from '@/components/common/WalletBalance' + +const BalanceInfo = () => { + const [balance] = useWalletBalance() + + return ( + + +
+ + + Wallet balance + + + + + + +
+
+ ) +} + +export default BalanceInfo diff --git a/src/components/tx/BalanceInfo/styles.module.css b/src/components/tx/BalanceInfo/styles.module.css new file mode 100644 index 0000000000..2df83cc5b5 --- /dev/null +++ b/src/components/tx/BalanceInfo/styles.module.css @@ -0,0 +1,20 @@ +.sponsoredBy { + padding: 8px 12px; + background-color: var(--color-background-main); + border-bottom-left-radius: 6px; + border-bottom-right-radius: 6px; + border-top: 1px solid var(--color-border-light); + display: flex; +} + +.icon { + margin-right: 8px; + margin-top: -1px; + color: var(--color-text-secondary); + width: 24px; +} + +.logo { + width: 16px; + height: 16px; +} diff --git a/src/components/tx/ExecutionMethodSelector/index.tsx b/src/components/tx/ExecutionMethodSelector/index.tsx index 95e56b9d4a..c314c210c7 100644 --- a/src/components/tx/ExecutionMethodSelector/index.tsx +++ b/src/components/tx/ExecutionMethodSelector/index.tsx @@ -8,6 +8,7 @@ import SponsoredBy from '../SponsoredBy' import type { RelayResponse } from '@/services/tx/relaying' import css from './styles.module.css' +import BalanceInfo from '@/components/tx/BalanceInfo' export const enum ExecutionMethod { RELAY = 'RELAY', @@ -71,7 +72,7 @@ export const ExecutionMethodSelector = ({ - {shouldRelay && relays ? : null} + {shouldRelay && relays ? : wallet ? : null} ) } diff --git a/src/hooks/wallets/useWalletBalance.ts b/src/hooks/wallets/useWalletBalance.ts index e2117a0985..b2754005a0 100644 --- a/src/hooks/wallets/useWalletBalance.ts +++ b/src/hooks/wallets/useWalletBalance.ts @@ -1,19 +1,19 @@ import useAsync from '../useAsync' import useWallet from './useWallet' +import { useWeb3ReadOnly } from '@/hooks/wallets/web3' +import { type BigNumber } from 'ethers' const useWalletBalance = () => { + const web3ReadOnly = useWeb3ReadOnly() const wallet = useWallet() - return useAsync(async () => { - if (!wallet) { + return useAsync(() => { + if (!wallet || !web3ReadOnly) { return undefined } - const balanceString = await wallet.provider.request({ - method: 'eth_getBalance', - params: [wallet.address, 'latest'], - }) - return BigInt(balanceString) - }, [wallet]) + + return web3ReadOnly.getBalance(wallet.address, 'latest') + }, [wallet, web3ReadOnly]) } export default useWalletBalance