mango-v4-ui/components/trade/TradeformSubmitButton.tsx

94 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-12-02 03:43:22 -08:00
import Button from '@components/shared/Button'
import Loading from '@components/shared/Loading'
import SecondaryConnectButton from '@components/shared/SecondaryConnectButton'
import { useWallet } from '@solana/wallet-adapter-react'
import useIpAddress from 'hooks/useIpAddress'
import useMangoAccount from 'hooks/useMangoAccount'
import mangoStore from '@store/mangoStore'
import { useTranslation } from 'react-i18next'
const TradeformSubmitButton = ({
disabled,
placingOrder,
setShowCreateAccountModal,
sideNames,
tooMuchSize,
2024-01-02 18:28:26 -08:00
isForceReduceOnly,
isSanctioned,
2023-12-02 03:43:22 -08:00
}: {
disabled: boolean
placingOrder: boolean
setShowCreateAccountModal: (show: boolean) => void
setShowDepositModal: (show: boolean) => void
sideNames: string[]
tooMuchSize: boolean
2023-12-02 03:43:22 -08:00
useMargin: boolean
2024-01-02 18:28:26 -08:00
isForceReduceOnly: boolean
isSanctioned: boolean
2023-12-02 03:43:22 -08:00
}) => {
const { t } = useTranslation(['common', 'swap', 'trade'])
2023-12-02 03:43:22 -08:00
const side = mangoStore((s) => s.tradeForm.side)
const themeData = mangoStore((s) => s.themeData)
const { connected } = useWallet()
2023-12-05 13:58:25 -08:00
const { initialLoad: mangoAccountLoading, mangoAccountAddress } =
useMangoAccount()
2024-01-04 15:37:00 -08:00
const { ipCountry } = useIpAddress()
2023-12-02 03:43:22 -08:00
2024-01-04 15:37:00 -08:00
return !isSanctioned || isForceReduceOnly ? (
2023-12-05 13:58:25 -08:00
(connected && mangoAccountLoading) || mangoAccountAddress ? (
<Button
className={`flex w-full items-center justify-center ${
side === 'buy'
? themeData.buttonStyle === 'raised'
? 'raised-buy-button'
: 'bg-th-up-dark text-white md:hover:bg-th-up-dark md:hover:brightness-90'
: themeData.buttonStyle === 'raised'
? 'raised-sell-button'
: 'bg-th-down-dark text-white md:hover:bg-th-down-dark md:hover:brightness-90'
}`}
2024-01-21 04:21:34 -08:00
disabled={disabled || tooMuchSize}
2023-12-05 13:58:25 -08:00
size="large"
type="submit"
>
{!placingOrder ? (
<span>
{tooMuchSize
? t('swap:insufficient-balance', { symbol: '' })
: t('trade:place-order', {
side: side === 'buy' ? sideNames[0] : sideNames[1],
})}
</span>
) : (
<div className="flex items-center space-x-2">
<Loading />
<span className="hidden sm:block">{t('trade:placing-order')}</span>
</div>
)}
</Button>
2023-12-28 03:14:08 -08:00
) : connected && !mangoAccountAddress ? (
2023-12-05 13:58:25 -08:00
<div className="w-full">
2023-12-02 03:43:22 -08:00
<Button
2023-12-05 13:58:25 -08:00
className="flex w-full items-center justify-center"
onClick={() => setShowCreateAccountModal(true)}
2023-12-02 03:43:22 -08:00
size="large"
>
2023-12-05 13:58:25 -08:00
{t('create-account')}
2023-12-02 03:43:22 -08:00
</Button>
2023-12-05 13:58:25 -08:00
</div>
2023-12-02 03:43:22 -08:00
) : (
<SecondaryConnectButton
className="flex w-full items-center justify-center"
isLarge
/>
)
) : (
<Button disabled className="w-full leading-tight" size="large">
{t('country-not-allowed', {
country: ipCountry ? `(${ipCountry})` : '',
})}
</Button>
)
}
export default TradeformSubmitButton