Skip to content

Commit

Permalink
swaps: fix max native check
Browse files Browse the repository at this point in the history
  • Loading branch information
skylarbarrera committed Feb 9, 2024
1 parent d1555c4 commit 79d1e76
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/hooks/useSwapInputHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Alert } from '../components/alerts';
import { isNativeAsset } from '@/handlers/assets';
import {
greaterThan,
multiply,
subtract,
toFixedDecimals,
} from '@/helpers/utilities';
import { greaterThan, toFixedDecimals } from '@/helpers/utilities';
import { useGas } from '@/hooks';
import { AppState } from '@/redux/store';
import {
Expand All @@ -20,7 +15,6 @@ import { ethereumUtils } from '@/utils';

export default function useSwapInputHandlers() {
const dispatch = useDispatch();
const type = useSelector((state: AppState) => state.swap.type);

const { selectedGasFee, l1GasFeeOptimism } = useGas();

Expand All @@ -40,6 +34,7 @@ export default function useSwapInputHandlers() {
isNativeAsset(inputCurrencyAddress, inputCurrencyNetwork) &&
accountAsset
) {
// this subtracts gas from the balance of the asset
newAmount = toFixedDecimals(
ethereumUtils.getBalanceAmount(
selectedGasFee,
Expand All @@ -48,14 +43,9 @@ export default function useSwapInputHandlers() {
),
6
);
const transactionFee = subtract(oldAmount, newAmount);
const newAmountMinusFee = toFixedDecimals(
subtract(newAmount, multiply(transactionFee, 1.5)),
6
);

if (greaterThan(newAmountMinusFee, 0)) {
dispatch(updateSwapInputAmount(newAmountMinusFee));
if (greaterThan(newAmount, 0)) {
dispatch(updateSwapInputAmount(newAmount));
} else {
Alert({
message: lang.t(
Expand Down

0 comments on commit 79d1e76

Please sign in to comment.