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

View File

@ -105,12 +105,13 @@ const SwapForm = () => {
setSwapOrLimit(orderType) setSwapOrLimit(orderType)
if (orderType !== 'swap' && outputBank?.name === OUTPUT_TOKEN_DEFAULT) { if (orderType !== 'swap' && outputBank?.name === OUTPUT_TOKEN_DEFAULT) {
const { group } = mangoStore.getState() const { group } = mangoStore.getState()
const outputBankName = inputBank?.name === 'USDC' ? 'SOL' : 'USDC'
set((state) => { 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 = () => { const handleSetMargin = () => {