swap fixes
This commit is contained in:
parent
5a9024a74d
commit
0c6517477f
|
@ -50,11 +50,19 @@ const LeverageSlider = ({
|
||||||
[decimals, leverageMax],
|
[decimals, leverageMax],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// set percent when max changes (toggling margin)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const percent = ((value - leverageMax) / leverageMax) * 100 + 100
|
const percent = ((value - leverageMax) / leverageMax) * 100 + 100
|
||||||
setPercent(Math.round(percent))
|
setPercent(Math.round(percent))
|
||||||
}, [leverageMax])
|
}, [leverageMax])
|
||||||
|
|
||||||
|
// set percent to 100 on max button click
|
||||||
|
useEffect(() => {
|
||||||
|
if (amount === leverageMax) {
|
||||||
|
setPercent(100)
|
||||||
|
}
|
||||||
|
}, [amount, leverageMax])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (amount) {
|
if (amount) {
|
||||||
setValue(amount)
|
setValue(amount)
|
||||||
|
|
|
@ -51,6 +51,8 @@ import { isMangoError } from 'types'
|
||||||
import { useWallet } from '@solana/wallet-adapter-react'
|
import { useWallet } from '@solana/wallet-adapter-react'
|
||||||
import TokenLogo from '@components/shared/TokenLogo'
|
import TokenLogo from '@components/shared/TokenLogo'
|
||||||
|
|
||||||
|
const set = mangoStore.getState().set
|
||||||
|
|
||||||
type JupiterRouteInfoProps = {
|
type JupiterRouteInfoProps = {
|
||||||
amountIn: Decimal
|
amountIn: Decimal
|
||||||
isWalletSwap?: boolean
|
isWalletSwap?: boolean
|
||||||
|
@ -279,6 +281,10 @@ const SwapReviewRouteInfo = ({
|
||||||
)
|
)
|
||||||
|
|
||||||
const tx = await client.sendAndConfirmTransaction(ixs)
|
const tx = await client.sendAndConfirmTransaction(ixs)
|
||||||
|
set((s) => {
|
||||||
|
s.swap.amountIn = ''
|
||||||
|
s.swap.amountOut = ''
|
||||||
|
})
|
||||||
notify({
|
notify({
|
||||||
title: 'Transaction confirmed',
|
title: 'Transaction confirmed',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
|
@ -309,7 +315,6 @@ const SwapReviewRouteInfo = ({
|
||||||
const mangoAccount = mangoStore.getState().mangoAccount.current
|
const mangoAccount = mangoStore.getState().mangoAccount.current
|
||||||
const inputBank = mangoStore.getState().swap.inputBank
|
const inputBank = mangoStore.getState().swap.inputBank
|
||||||
const outputBank = mangoStore.getState().swap.outputBank
|
const outputBank = mangoStore.getState().swap.outputBank
|
||||||
const set = mangoStore.getState().set
|
|
||||||
const connection = mangoStore.getState().connection
|
const connection = mangoStore.getState().connection
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -352,6 +357,8 @@ const SwapReviewRouteInfo = ({
|
||||||
})
|
})
|
||||||
set((s) => {
|
set((s) => {
|
||||||
s.successAnimation.swap = true
|
s.successAnimation.swap = true
|
||||||
|
s.swap.amountIn = ''
|
||||||
|
s.swap.amountOut = ''
|
||||||
})
|
})
|
||||||
if (soundSettings['swap-success']) {
|
if (soundSettings['swap-success']) {
|
||||||
successSound.play()
|
successSound.play()
|
||||||
|
|
|
@ -169,13 +169,13 @@ const WalletSwapForm = ({ setShowTokenSelect }: WalletSwapFormProps) => {
|
||||||
if (typeof bestRoute !== 'undefined') {
|
if (typeof bestRoute !== 'undefined') {
|
||||||
setSelectedRoute(bestRoute)
|
setSelectedRoute(bestRoute)
|
||||||
|
|
||||||
if (inputBank && swapMode === 'ExactOut' && bestRoute) {
|
if (inputBank && swapMode === 'ExactOut' && bestRoute?.inAmount) {
|
||||||
const inAmount = new Decimal(bestRoute!.inAmount)
|
const inAmount = new Decimal(bestRoute.inAmount)
|
||||||
.div(10 ** inputBank.mintDecimals)
|
.div(10 ** inputBank.mintDecimals)
|
||||||
.toString()
|
.toString()
|
||||||
setAmountInFormValue(inAmount)
|
setAmountInFormValue(inAmount)
|
||||||
} else if (outputBank && swapMode === 'ExactIn' && bestRoute) {
|
} else if (outputBank && swapMode === 'ExactIn' && bestRoute?.outAmount) {
|
||||||
const outAmount = new Decimal(bestRoute!.outAmount)
|
const outAmount = new Decimal(bestRoute.outAmount)
|
||||||
.div(10 ** outputBank.mintDecimals)
|
.div(10 ** outputBank.mintDecimals)
|
||||||
.toString()
|
.toString()
|
||||||
setAmountOutFormValue(outAmount)
|
setAmountOutFormValue(outAmount)
|
||||||
|
@ -346,7 +346,8 @@ const SwapFormSubmitButton = ({
|
||||||
isLarge
|
isLarge
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{selectedRoute === null && amountIn.gt(0) ? (
|
{(selectedRoute === null && amountIn.gt(0)) ||
|
||||||
|
(selectedRoute && !!selectedRoute.error) ? (
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<InlineNotification type="error" desc={t('swap:no-swap-found')} />
|
<InlineNotification type="error" desc={t('swap:no-swap-found')} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import mangoStore from '@store/mangoStore'
|
||||||
import LeverageSlider from '../shared/LeverageSlider'
|
import LeverageSlider from '../shared/LeverageSlider'
|
||||||
|
|
||||||
const WalletSwapSlider = ({
|
const WalletSwapSlider = ({
|
||||||
|
@ -11,9 +12,11 @@ const WalletSwapSlider = ({
|
||||||
step: number
|
step: number
|
||||||
maxAmount: number
|
maxAmount: number
|
||||||
}) => {
|
}) => {
|
||||||
|
const { inputBank } = mangoStore((s) => s.swap)
|
||||||
return (
|
return (
|
||||||
<LeverageSlider
|
<LeverageSlider
|
||||||
amount={amount}
|
amount={amount}
|
||||||
|
decimals={inputBank?.mintDecimals}
|
||||||
leverageMax={maxAmount}
|
leverageMax={maxAmount}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
step={step}
|
step={step}
|
||||||
|
|
Loading…
Reference in New Issue