change default buy token to sol if sell token is usdc

This commit is contained in:
saml33 2023-08-24 10:21:06 +10:00
parent 094b6524e3
commit e10e54fcc7
2 changed files with 5 additions and 6 deletions

View File

@ -14,7 +14,6 @@ import MaxSwapAmount from './MaxSwapAmount'
import useUnownedAccount from 'hooks/useUnownedAccount'
import InlineNotification from '@components/shared/InlineNotification'
import useMangoAccount from 'hooks/useMangoAccount'
import { useWallet } from '@solana/wallet-adapter-react'
import { toUiDecimalsForQuote } from '@blockworks-foundation/mango-v4'
const SellTokenInput = ({
@ -34,7 +33,6 @@ const SellTokenInput = ({
}) => {
const { t } = useTranslation('common')
const { mangoAccountAddress } = useMangoAccount()
const { connected } = useWallet()
const { group } = useMangoGroup()
const { isUnownedAccount } = useUnownedAccount()
const {
@ -48,7 +46,7 @@ const SellTokenInput = ({
const mangoAccount = mangoStore.getState().mangoAccount.current
return group && mangoAccount
? toUiDecimalsForQuote(mangoAccount.getCollateralValue(group))
: 0
: 10
}, [mangoAccountAddress])
return (
@ -98,7 +96,7 @@ const SellTokenInput = ({
</span>
) : null}
</div>
{connected && freeCollateral <= 0 ? (
{mangoAccountAddress && freeCollateral <= 0 ? (
<div className="col-span-2 mt-1 flex justify-center">
<InlineNotification
type="warning"

View File

@ -105,12 +105,13 @@ const SwapForm = () => {
setSwapOrLimit(orderType)
if (orderType !== 'swap' && outputBank?.name === OUTPUT_TOKEN_DEFAULT) {
const { group } = mangoStore.getState()
const outputBankName = inputBank?.name === 'USDC' ? 'SOL' : 'USDC'
set((state) => {
state.swap.outputBank = group?.banksMapByName.get('USDC')?.[0]
state.swap.outputBank = group?.banksMapByName.get(outputBankName)?.[0]
})
}
},
[outputBank, set, setSwapOrLimit],
[inputBank, outputBank, set, setSwapOrLimit],
)
const handleSetMargin = () => {