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(swap): Form state #2819

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 8 additions & 8 deletions apps/wallet-mobile/src/features/Swap/common/SwapFormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ export const SwapFormProvider = ({
const sellTokenInfo = useTokenInfo({wallet, tokenId: sellTokenId})

const balances = useBalances(wallet)
const sellbalance = Amounts.getAmount(balances, sellTokenId).quantity
const sellBalance = Amounts.getAmount(balances, sellTokenId).quantity
const primaryTokenBalance = Amounts.getAmount(balances, wallet.primaryTokenInfo.id).quantity

const poolSupply = buyTokenId === pool?.tokenA.tokenId ? pool?.tokenA.quantity : pool?.tokenB.quantity
const hasBuyTokenSupply = !Quantities.isGreaterThan(buyQuantity, poolSupply ?? Quantities.zero)
const hasSellBalance = !Quantities.isGreaterThan(sellQuantity, sellbalance)
const hasSellBalance = !Quantities.isGreaterThan(sellQuantity, sellBalance)
const hasFeesBalance = !Quantities.isGreaterThan(
Quantities.sum([
sellTokenId === wallet.primaryTokenInfo.id ? sellQuantity : Quantities.zero,
Expand Down Expand Up @@ -80,7 +78,7 @@ export const SwapFormProvider = ({
const buyError =
noPoolError !== undefined
? noPoolError
: (!Quantities.isZero(buyQuantity) && !hasBuyTokenSupply) ||
: !orderData.selectedPoolCalculation?.hasSupply ||
(state.sellQuantity.isTouched && state.buyQuantity.isTouched && pool === undefined)
? strings.notEnoughSupply
: undefined
Expand Down Expand Up @@ -198,11 +196,11 @@ export const SwapFormProvider = ({
)

React.useEffect(() => {
if (buyError !== state.buyQuantity.error && buyError !== undefined) actions.buyAmountErrorChanged(buyError)
if (buyError !== state.buyQuantity.error) actions.buyAmountErrorChanged(buyError)
}, [actions, buyError, state.buyQuantity.error])

React.useEffect(() => {
if (sellError !== state.sellQuantity.error && sellError !== undefined) {
if (sellError !== state.sellQuantity.error) {
actions.sellAmountErrorChanged(sellError)
}
}, [actions, sellError, state.sellQuantity.error])
Expand Down Expand Up @@ -270,9 +268,11 @@ const swapFormReducer = (state: SwapFormState, action: SwapFormAction) => {
break

case SwapFormActionType.ResetSwapForm:
case SwapFormActionType.ClearSwapForm:
return defaultState

case SwapFormActionType.ClearSwapForm:
return state

case SwapFormActionType.CanSwapChanged:
draft.canSwap = action.canSwap

Expand Down