Skip to content

Commit

Permalink
implement nabla swap amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharqiewicz committed May 30, 2024
1 parent fdda833 commit edbe066
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/components/nabla/Swap/useSwapComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,25 @@ export const useSwapComponent = (props: UseSwapComponentProps) => {
to: prev?.to === f ? prev?.from : prev?.to,
};
updateStorage(updated);
setValue('from', updated.from);
//if (updated.to && prev?.to === f) setValue('to', updated.to);

if (prev.to === f) {
const prevToAmount = toAmountQuote.data?.amountOut.approximateStrings.atLeast4Decimals;
setValue('fromAmount', prevToAmount || '0');
} else {
setValue('from', updated.from);
}

if (onChange && event) onChange(updated.from, updated.to);
setTokenModal(undefined);
},
[getValues, onChange, setTokenModal, setValue, updateStorage],
[
getValues,
onChange,
setTokenModal,
setValue,
toAmountQuote.data?.amountOut.approximateStrings.atLeast4Decimals,
updateStorage,
],
);

const onToChange = useCallback(
Expand All @@ -174,12 +187,26 @@ export const useSwapComponent = (props: UseSwapComponentProps) => {
from: prev?.from === t ? prev?.to : prev?.from,
};
updateStorage(updated);

if (prev.from === t) {
const prevToAmount = toAmountQuote.data?.amountOut.approximateStrings.atLeast4Decimals;
setValue('fromAmount', prevToAmount || '0');
}

if (updated.from && prev?.from !== updated.from) setValue('from', updated.from);
setValue('to', updated.to);

if (onChange && event) onChange(updated.from, updated.to);
setTokenModal(undefined);
},
[getValues, onChange, setTokenModal, setValue, updateStorage],
[
getValues,
onChange,
setTokenModal,
setValue,
toAmountQuote.data?.amountOut.approximateStrings.atLeast4Decimals,
updateStorage,
],
);

// when props change (url updated)
Expand Down

0 comments on commit edbe066

Please sign in to comment.