fix jup call on every type (#364)

This commit is contained in:
Adrian Brzeziński 2024-01-09 11:36:44 +01:00 committed by GitHub
parent fca4ca7f47
commit 71352cedf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 12 deletions

View File

@ -26,6 +26,7 @@ import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { SwapFormTokenListType } from './SwapFormTokenList'
import SwapFormSubmitButton from './SwapFormSubmitButton'
import { debounce } from 'lodash'
dayjs.extend(relativeTime)
@ -69,6 +70,7 @@ const MarketSwapForm = ({
const { mangoAccount } = useMangoAccount()
const quoteAmount =
swapMode === 'ExactIn' ? amountInFormValue : amountOutFormValue
const {
bestRoute,
isFetching: fetchingRoute,
@ -133,7 +135,7 @@ const MarketSwapForm = ({
)
const handleAmountInChange = useCallback(
(e: NumberFormatValues, info: SourceInfo) => {
debounce((e: NumberFormatValues, info: SourceInfo) => {
if (info.source !== 'event') return
setAmountInFormValue(e.value)
set((s) => {
@ -144,12 +146,12 @@ const MarketSwapForm = ({
s.swap.swapMode = 'ExactIn'
})
}
},
}, 500),
[outputBank, set, setAmountInFormValue, swapMode],
)
const handleAmountOutChange = useCallback(
(e: NumberFormatValues, info: SourceInfo) => {
debounce((e: NumberFormatValues, info: SourceInfo) => {
if (info.source !== 'event') return
setAmountOutFormValue(e.value)
set((s) => {
@ -160,7 +162,7 @@ const MarketSwapForm = ({
s.swap.swapMode = 'ExactOut'
})
}
},
}, 500),
[set, setAmountOutFormValue, swapMode],
)

View File

@ -27,6 +27,7 @@ import { walletBalanceForToken } from '@components/DepositForm'
import WalletSwapSlider from './WalletSwapSlider'
import ButtonGroup from '@components/forms/ButtonGroup'
import SwapFormSubmitButton from './SwapFormSubmitButton'
import { debounce } from 'lodash'
dayjs.extend(relativeTime)
@ -133,7 +134,7 @@ const WalletSwapForm = ({ setShowTokenSelect }: WalletSwapFormProps) => {
)
const handleAmountInChange = useCallback(
(e: NumberFormatValues, info: SourceInfo) => {
debounce((e: NumberFormatValues, info: SourceInfo) => {
if (info.source !== 'event') return
setAmountInFormValue(e.value)
set((s) => {
@ -144,12 +145,12 @@ const WalletSwapForm = ({ setShowTokenSelect }: WalletSwapFormProps) => {
s.swap.swapMode = 'ExactIn'
})
}
},
}, 500),
[outputBank, setAmountInFormValue, swapMode],
)
const handleAmountOutChange = useCallback(
(e: NumberFormatValues, info: SourceInfo) => {
debounce((e: NumberFormatValues, info: SourceInfo) => {
if (info.source !== 'event') return
setAmountOutFormValue(e.value)
set((s) => {
@ -160,7 +161,7 @@ const WalletSwapForm = ({ setShowTokenSelect }: WalletSwapFormProps) => {
s.swap.swapMode = 'ExactOut'
})
}
},
}, 500),
[swapMode, setAmountOutFormValue],
)

View File

@ -50,6 +50,7 @@ import { fetchJupiterTransaction } from '@components/swap/SwapReviewRouteInfo'
import MaxMarketTradeAmount from './MaxMarketTradeAmount'
import useMangoAccount from 'hooks/useMangoAccount'
import InlineNotification from '@components/shared/InlineNotification'
import { debounce } from 'lodash'
const set = mangoStore.getState().set
@ -113,7 +114,7 @@ export default function SpotMarketOrderSwapForm() {
}, [selectedMarket, side])
const handleBaseSizeChange = useCallback(
(e: NumberFormatValues, info: SourceInfo) => {
debounce((e: NumberFormatValues, info: SourceInfo) => {
if (info.source !== 'event') return
set((s) => {
s.tradeForm.baseSize = e.value
@ -125,12 +126,12 @@ export default function SpotMarketOrderSwapForm() {
s.tradeForm.quoteSize = ''
}
})
},
}, 500),
[oraclePrice],
)
const handleQuoteSizeChange = useCallback(
(e: NumberFormatValues, info: SourceInfo) => {
debounce((e: NumberFormatValues, info: SourceInfo) => {
if (info.source !== 'event') return
set((s) => {
s.tradeForm.quoteSize = e.value
@ -140,7 +141,7 @@ export default function SpotMarketOrderSwapForm() {
s.tradeForm.baseSize = ''
}
})
},
}, 500),
[oraclePrice],
)