Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo committed Dec 17, 2024
1 parent 2d639fb commit 8e0459a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/wallet-mobile/src/features/Swap/common/SwapProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ export const SwapProvider = ({children}: {children: React.ReactNode}) => {
React.useEffect(() => {
if (state.reqres === 'response') return

if (state.tokenInInput.tokenId === undefined || state.tokenOutInput.tokenId === undefined) return
if (
state.tokenInInput.tokenId === undefined ||
state.tokenOutInput.tokenId === undefined ||
(state.tokenInInput.value === '' && state.tokenOutInput.value === '')
)
return

swapManager.api
.estimate({
Expand Down Expand Up @@ -200,11 +205,15 @@ const swapReducer = (state: SwapState, action: SwapAction) => {

break
case SwapAction.TokenInErrorChanged:
draft.lastInputTouched = state.lastInputTouched
draft.tokenInInput.error = action.value
draft.reqres = 'response'

break
case SwapAction.TokenOutErrorChanged:
draft.lastInputTouched = state.lastInputTouched
draft.tokenOutInput.error = action.value
draft.reqres = 'response'

break
case SwapAction.SlippageInputChanged:
Expand Down Expand Up @@ -245,10 +254,16 @@ const swapReducer = (state: SwapState, action: SwapAction) => {
draft = defaultState
break
case SwapAction.EstimateResponse:
draft.lastInputTouched = state.lastInputTouched
draft.reqres = 'response'
draft.estimate = action.value
draft.tokenOutInput.value = String(action.value.totalOutputWithoutSlippage ?? 0)
draft.tokenOutInput.error = null
draft.canSwap = true
if (state.lastInputTouched === 'in') {
draft.tokenOutInput.value = String(action.value.totalOutputWithoutSlippage ?? 0)
} else {
draft.tokenInInput.value = String(action.value.totalInput ?? 0)
}

break
case SwapAction.EstimateError:
Expand Down

0 comments on commit 8e0459a

Please sign in to comment.