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 5 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,27 +68,32 @@ 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

// make sure it's always a positive number
// if it's negative, set it to user's balance to show insufficient for gas error
if (maxAmount > 0) {
return String(maxAmount)
if (maxAmount <= 0) {
return undefined
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the input should still be set to the max amount available to show insufficient for gas error

otherwise clicking the max button would do nothing even though user has balance


return nativeCurrencyBalanceFormatted
return String(maxAmount)
}, [
nativeCurrency,
ethParentBalance,
Expand Down
Loading