-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2e06df
commit 6dfa491
Showing
7 changed files
with
84 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Box className={css.sponsoredBy}> | ||
<SvgIcon component={GasStationIcon} inheritViewBox className={css.icon} /> | ||
<div> | ||
<Stack direction="row" spacing={0.5} alignItems="center"> | ||
<Typography variant="body2" fontWeight={700} letterSpacing="0.1px"> | ||
Wallet balance | ||
</Typography> | ||
</Stack> | ||
|
||
<Typography variant="body2" color="primary.light"> | ||
<WalletBalance balance={balance} /> | ||
</Typography> | ||
</div> | ||
</Box> | ||
) | ||
} | ||
|
||
export default BalanceInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BigInt | undefined>(async () => { | ||
if (!wallet) { | ||
return useAsync<BigNumber | undefined>(() => { | ||
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 |