swap fixes

This commit is contained in:
saml33 2023-10-23 15:07:14 +11:00
parent 5a9024a74d
commit 0c6517477f
4 changed files with 25 additions and 6 deletions

View File

@ -50,11 +50,19 @@ const LeverageSlider = ({
[decimals, leverageMax],
)
// set percent when max changes (toggling margin)
useEffect(() => {
const percent = ((value - leverageMax) / leverageMax) * 100 + 100
setPercent(Math.round(percent))
}, [leverageMax])
// set percent to 100 on max button click
useEffect(() => {
if (amount === leverageMax) {
setPercent(100)
}
}, [amount, leverageMax])
useEffect(() => {
if (amount) {
setValue(amount)

View File

@ -51,6 +51,8 @@ import { isMangoError } from 'types'
import { useWallet } from '@solana/wallet-adapter-react'
import TokenLogo from '@components/shared/TokenLogo'
const set = mangoStore.getState().set
type JupiterRouteInfoProps = {
amountIn: Decimal
isWalletSwap?: boolean
@ -279,6 +281,10 @@ const SwapReviewRouteInfo = ({
)
const tx = await client.sendAndConfirmTransaction(ixs)
set((s) => {
s.swap.amountIn = ''
s.swap.amountOut = ''
})
notify({
title: 'Transaction confirmed',
type: 'success',
@ -309,7 +315,6 @@ const SwapReviewRouteInfo = ({
const mangoAccount = mangoStore.getState().mangoAccount.current
const inputBank = mangoStore.getState().swap.inputBank
const outputBank = mangoStore.getState().swap.outputBank
const set = mangoStore.getState().set
const connection = mangoStore.getState().connection
if (
@ -352,6 +357,8 @@ const SwapReviewRouteInfo = ({
})
set((s) => {
s.successAnimation.swap = true
s.swap.amountIn = ''
s.swap.amountOut = ''
})
if (soundSettings['swap-success']) {
successSound.play()

View File

@ -169,13 +169,13 @@ const WalletSwapForm = ({ setShowTokenSelect }: WalletSwapFormProps) => {
if (typeof bestRoute !== 'undefined') {
setSelectedRoute(bestRoute)
if (inputBank && swapMode === 'ExactOut' && bestRoute) {
const inAmount = new Decimal(bestRoute!.inAmount)
if (inputBank && swapMode === 'ExactOut' && bestRoute?.inAmount) {
const inAmount = new Decimal(bestRoute.inAmount)
.div(10 ** inputBank.mintDecimals)
.toString()
setAmountInFormValue(inAmount)
} else if (outputBank && swapMode === 'ExactIn' && bestRoute) {
const outAmount = new Decimal(bestRoute!.outAmount)
} else if (outputBank && swapMode === 'ExactIn' && bestRoute?.outAmount) {
const outAmount = new Decimal(bestRoute.outAmount)
.div(10 ** outputBank.mintDecimals)
.toString()
setAmountOutFormValue(outAmount)
@ -346,7 +346,8 @@ const SwapFormSubmitButton = ({
isLarge
/>
)}
{selectedRoute === null && amountIn.gt(0) ? (
{(selectedRoute === null && amountIn.gt(0)) ||
(selectedRoute && !!selectedRoute.error) ? (
<div className="mb-4">
<InlineNotification type="error" desc={t('swap:no-swap-found')} />
</div>

View File

@ -1,3 +1,4 @@
import mangoStore from '@store/mangoStore'
import LeverageSlider from '../shared/LeverageSlider'
const WalletSwapSlider = ({
@ -11,9 +12,11 @@ const WalletSwapSlider = ({
step: number
maxAmount: number
}) => {
const { inputBank } = mangoStore((s) => s.swap)
return (
<LeverageSlider
amount={amount}
decimals={inputBank?.mintDecimals}
leverageMax={maxAmount}
onChange={onChange}
step={step}