Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set correct max amount from query params #1850

Merged
merged 7 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ export function SourceNetworkBox({
useEffect(() => {
if (isMaxAmount && typeof maxAmount !== 'undefined') {
setAmount(maxAmount)
} else {
setAmount(amount)
}
}, [amount, maxAmount, isMaxAmount, setAmount])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function useMaxAmount({
: selectedTokenBalances.childBalance

if (!tokenBalance) {
return
return undefined
}

// For token deposits and withdrawals, we can set the max amount, as gas fees are paid in ETH / custom fee token
Expand Down Expand Up @@ -68,16 +68,23 @@ export function useMaxAmount({
: ethChildBalance

if (!nativeCurrencyBalance) {
return
return undefined
}

const nativeCurrencyBalanceFormatted = utils.formatUnits(
nativeCurrencyBalance,
nativeCurrency.decimals
)

if (
typeof estimatedParentChainGasFees === 'undefined' ||
typeof estimatedChildChainGasFees === 'undefined'
) {
return undefined
}

const estimatedTotalGasFees =
(estimatedParentChainGasFees ?? 0) + (estimatedChildChainGasFees ?? 0)
estimatedParentChainGasFees + estimatedChildChainGasFees

const maxAmount =
parseFloat(nativeCurrencyBalanceFormatted) - estimatedTotalGasFees * 1.4
Expand Down
Loading