-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: insufficient balance message if too many
- Loading branch information
1 parent
ecb3dc7
commit 9e799a0
Showing
4 changed files
with
69 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
import { constants } from 'ethers' | ||
|
||
import { useAccount, useBalance } from 'wagmi' | ||
import { useQuery } from 'react-query' | ||
import { getJsonRpcProviders } from './getJsonRpcProviders' | ||
import { Address, useAccount, usePublicClient } from 'wagmi' | ||
import { l1, l2 } from '@/config/chain' | ||
import { useQuery } from 'react-query'; | ||
import { getJsonRpcProviders } from './getJsonRpcProviders'; | ||
|
||
const useBalances = () => { | ||
const {address} = useAccount(); | ||
const {address} = useAccount() | ||
const l1Provider = usePublicClient({chainId: l1.id}) | ||
const l2Provider = usePublicClient({chainId: l2.id}) | ||
const { data, isLoading } = useQuery({ | ||
queryKey: ['balances', address], | ||
queryFn: async ({ queryKey }) => { | ||
const [_, address] = queryKey as ['balances', string | undefined] | ||
const { l1Provider, l2Provider } = getJsonRpcProviders() | ||
|
||
const l1Signer = l1Provider.getSigner(address) | ||
const l2Signer = l2Provider.getSigner(address) | ||
if (!address) return {l1Balance: BigInt(0), l2Balance: BigInt(0)} | ||
|
||
const l1Balance = await l1Provider.getBalance({address: address as Address}) | ||
const l2Balance = await l2Provider.getBalance({address: address as Address}) | ||
|
||
const l1Balance = await l1Signer.getBalance() | ||
const l2Balance = await l2Signer.getBalance() | ||
return { l1Balance, l2Balance } | ||
}, | ||
}) | ||
|
||
return { | ||
l1Balance: data?.l1Balance || constants.Zero, | ||
l2Balance: data?.l2Balance || constants.Zero, | ||
l1Balance: data?.l1Balance || BigInt(0), | ||
l2Balance: data?.l2Balance || BigInt(0), | ||
isLoading, | ||
} | ||
} | ||
|
||
export default useBalances | ||
export default useBalances |
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,15 @@ | ||
import { useMintDialogContext } from "@/components/MintDialog/Context/useMintDialogContext" | ||
import { parseEther } from "viem" | ||
|
||
export const l2GasToMint = parseEther('0.0006') | ||
export const l1GasToBridge = parseEther('0.01') | ||
|
||
export function useMintThresholds() { | ||
const {price} = useMintDialogContext(); | ||
const priceWei = parseEther(price); | ||
|
||
return { | ||
minL1BalanceWei: l1GasToBridge + priceWei, | ||
minL2BalanceWei: l2GasToMint + priceWei | ||
} | ||
} |