add active connect buttons

This commit is contained in:
saml33 2023-01-03 22:06:37 +11:00
parent e419752d49
commit b2257d2ca1
13 changed files with 87 additions and 50 deletions

View File

@ -39,6 +39,7 @@ import useJupiterMints from 'hooks/useJupiterMints'
import useMangoGroup from 'hooks/useMangoGroup' import useMangoGroup from 'hooks/useMangoGroup'
import TokenVaultWarnings from '@components/shared/TokenVaultWarnings' import TokenVaultWarnings from '@components/shared/TokenVaultWarnings'
import { useWallet } from '@solana/wallet-adapter-react' import { useWallet } from '@solana/wallet-adapter-react'
import { useEnhancedWallet } from './wallet/EnhancedWalletProvider'
interface BorrowFormProps { interface BorrowFormProps {
onSuccess: () => void onSuccess: () => void
@ -58,6 +59,7 @@ function BorrowForm({ onSuccess, token }: BorrowFormProps) {
const { mangoTokens } = useJupiterMints() const { mangoTokens } = useJupiterMints()
const { mangoAccount } = useMangoAccount() const { mangoAccount } = useMangoAccount()
const { connected } = useWallet() const { connected } = useWallet()
const { handleConnect } = useEnhancedWallet()
const bank = useMemo(() => { const bank = useMemo(() => {
const group = mangoStore.getState().group const group = mangoStore.getState().group
@ -113,7 +115,7 @@ function BorrowForm({ onSuccess, token }: BorrowFormProps) {
setShowTokenList(false) setShowTokenList(false)
} }
const handleWithdraw = async () => { const handleBorrow = async () => {
const client = mangoStore.getState().client const client = mangoStore.getState().client
const group = mangoStore.getState().group const group = mangoStore.getState().group
const mangoAccount = mangoStore.getState().mangoAccount.current const mangoAccount = mangoStore.getState().mangoAccount.current
@ -392,9 +394,9 @@ function BorrowForm({ onSuccess, token }: BorrowFormProps) {
) : null} ) : null}
</div> </div>
<Button <Button
onClick={handleWithdraw} onClick={connected ? handleBorrow : handleConnect}
className="flex w-full items-center justify-center" className="flex w-full items-center justify-center"
disabled={!inputAmount || showInsufficientBalance || !connected} disabled={connected && (!inputAmount || showInsufficientBalance)}
size="large" size="large"
> >
{!connected ? ( {!connected ? (

View File

@ -36,6 +36,7 @@ import HealthImpactTokenChange from '@components/HealthImpactTokenChange'
import SolBalanceWarnings from '@components/shared/SolBalanceWarnings' import SolBalanceWarnings from '@components/shared/SolBalanceWarnings'
import useJupiterMints from 'hooks/useJupiterMints' import useJupiterMints from 'hooks/useJupiterMints'
import useMangoGroup from 'hooks/useMangoGroup' import useMangoGroup from 'hooks/useMangoGroup'
import { useEnhancedWallet } from './wallet/EnhancedWalletProvider'
interface DepositFormProps { interface DepositFormProps {
onSuccess: () => void onSuccess: () => void
@ -95,6 +96,7 @@ function DepositForm({ onSuccess, token }: DepositFormProps) {
const [showTokenList, setShowTokenList] = useState(false) const [showTokenList, setShowTokenList] = useState(false)
const [sizePercentage, setSizePercentage] = useState('') const [sizePercentage, setSizePercentage] = useState('')
const { mangoTokens } = useJupiterMints() const { mangoTokens } = useJupiterMints()
const { handleConnect } = useEnhancedWallet()
const bank = useMemo(() => { const bank = useMemo(() => {
const group = mangoStore.getState().group const group = mangoStore.getState().group
@ -366,13 +368,11 @@ function DepositForm({ onSuccess, token }: DepositFormProps) {
</div> </div>
</div> </div>
<Button <Button
onClick={handleDeposit} onClick={connected ? handleDeposit : handleConnect}
className="flex w-full items-center justify-center" className="flex w-full items-center justify-center"
disabled={ disabled={
!inputAmount || connected &&
exceedsAlphaMax || (!inputAmount || exceedsAlphaMax || showInsufficientBalance)
showInsufficientBalance ||
!connected
} }
size="large" size="large"
> >

View File

@ -3,7 +3,6 @@ import {
ArrowLeftIcon, ArrowLeftIcon,
ChevronDownIcon, ChevronDownIcon,
ExclamationCircleIcon, ExclamationCircleIcon,
LinkIcon,
QuestionMarkCircleIcon, QuestionMarkCircleIcon,
} from '@heroicons/react/20/solid' } from '@heroicons/react/20/solid'
import { Wallet } from '@project-serum/anchor' import { Wallet } from '@project-serum/anchor'
@ -34,6 +33,7 @@ import {
ACCOUNT_ACTION_MODAL_INNER_HEIGHT, ACCOUNT_ACTION_MODAL_INNER_HEIGHT,
INPUT_TOKEN_DEFAULT, INPUT_TOKEN_DEFAULT,
} from 'utils/constants' } from 'utils/constants'
import ConnectEmptyState from './shared/ConnectEmptyState'
interface RepayFormProps { interface RepayFormProps {
onSuccess: () => void onSuccess: () => void
@ -358,8 +358,7 @@ function RepayForm({ onSuccess, token }: RepayFormProps) {
</> </>
) : !connected ? ( ) : !connected ? (
<div className="flex h-[356px] flex-col items-center justify-center"> <div className="flex h-[356px] flex-col items-center justify-center">
<LinkIcon className="mb-2 h-6 w-6 text-th-fgd-4" /> <ConnectEmptyState text="Connect to repay your borrows" />
<p>Connect to repay your borrows</p>
</div> </div>
) : ( ) : (
<div className="flex h-[356px] flex-col items-center justify-center"> <div className="flex h-[356px] flex-col items-center justify-center">

View File

@ -35,6 +35,7 @@ import useJupiterMints from 'hooks/useJupiterMints'
import useMangoGroup from 'hooks/useMangoGroup' import useMangoGroup from 'hooks/useMangoGroup'
import TokenVaultWarnings from '@components/shared/TokenVaultWarnings' import TokenVaultWarnings from '@components/shared/TokenVaultWarnings'
import { useWallet } from '@solana/wallet-adapter-react' import { useWallet } from '@solana/wallet-adapter-react'
import { useEnhancedWallet } from './wallet/EnhancedWalletProvider'
interface WithdrawFormProps { interface WithdrawFormProps {
onSuccess: () => void onSuccess: () => void
@ -54,6 +55,7 @@ function WithdrawForm({ onSuccess, token }: WithdrawFormProps) {
const { mangoTokens } = useJupiterMints() const { mangoTokens } = useJupiterMints()
const { mangoAccount } = useMangoAccount() const { mangoAccount } = useMangoAccount()
const { connected } = useWallet() const { connected } = useWallet()
const { handleConnect } = useEnhancedWallet()
const bank = useMemo(() => { const bank = useMemo(() => {
const group = mangoStore.getState().group const group = mangoStore.getState().group
@ -302,14 +304,12 @@ function WithdrawForm({ onSuccess, token }: WithdrawFormProps) {
</div> </div>
</div> </div>
<Button <Button
onClick={handleWithdraw} onClick={connected ? handleWithdraw : handleConnect}
className="flex w-full items-center justify-center" className="flex w-full items-center justify-center"
size="large" size="large"
disabled={ disabled={
!inputAmount || connected &&
showInsufficientBalance || (!inputAmount || showInsufficientBalance || initHealth <= 0)
initHealth <= 0 ||
!connected
} }
> >
{!connected ? ( {!connected ? (

View File

@ -1,5 +1,6 @@
import { EXPLORERS } from '@components/settings/PreferredExplorerSettings' import { EXPLORERS } from '@components/settings/PreferredExplorerSettings'
import { IconButton, LinkButton } from '@components/shared/Button' import { IconButton, LinkButton } from '@components/shared/Button'
import ConnectEmptyState from '@components/shared/ConnectEmptyState'
import SheenLoader from '@components/shared/SheenLoader' import SheenLoader from '@components/shared/SheenLoader'
import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements' import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
import Tooltip from '@components/shared/Tooltip' import Tooltip from '@components/shared/Tooltip'
@ -7,7 +8,6 @@ import { Transition } from '@headlessui/react'
import { import {
ChevronDownIcon, ChevronDownIcon,
ChevronRightIcon, ChevronRightIcon,
LinkIcon,
NoSymbolIcon, NoSymbolIcon,
} from '@heroicons/react/20/solid' } from '@heroicons/react/20/solid'
import mangoStore, { LiquidationFeedItem } from '@store/mangoStore' import mangoStore, { LiquidationFeedItem } from '@store/mangoStore'
@ -293,9 +293,8 @@ const ActivityFeedTable = ({
</div> </div>
) )
) : ( ) : (
<div className="flex flex-col items-center p-8"> <div className="p-8">
<LinkIcon className="mb-2 h-6 w-6 text-th-fgd-4" /> <ConnectEmptyState text={t('activity:connect-activity')} />
<p>{t('activity:connect-activity')}</p>
</div> </div>
) )
} }

View File

@ -0,0 +1,24 @@
import WalletIcon from '@components/icons/WalletIcon'
import { useEnhancedWallet } from '@components/wallet/EnhancedWalletProvider'
import { LinkIcon } from '@heroicons/react/20/solid'
import { useTranslation } from 'next-i18next'
import Button from './Button'
const ConnectEmptyState = ({ text }: { text: string }) => {
const { t } = useTranslation('common')
const { handleConnect } = useEnhancedWallet()
return (
<div className="flex flex-col items-center">
<WalletIcon className="mb-2 h-6 w-6 text-th-fgd-4" />
<p className="mb-4">{text}</p>
<Button onClick={handleConnect}>
<div className="flex items-center">
<LinkIcon className="mr-2 h-5 w-5" />
{t('connect')}
</div>
</Button>
</div>
)
}
export default ConnectEmptyState

View File

@ -46,6 +46,7 @@ import MaxSwapAmount from './MaxSwapAmount'
import PercentageSelectButtons from './PercentageSelectButtons' import PercentageSelectButtons from './PercentageSelectButtons'
import useIpAddress from 'hooks/useIpAddress' import useIpAddress from 'hooks/useIpAddress'
import Checkbox from '@components/forms/Checkbox' import Checkbox from '@components/forms/Checkbox'
import { useEnhancedWallet } from '@components/wallet/EnhancedWalletProvider'
const MAX_DIGITS = 11 const MAX_DIGITS = 11
export const withValueLimit = (values: NumberFormatValues): boolean => { export const withValueLimit = (values: NumberFormatValues): boolean => {
@ -498,17 +499,20 @@ const SwapFormSubmitButton = ({
const { t } = useTranslation('common') const { t } = useTranslation('common')
const { connected } = useWallet() const { connected } = useWallet()
const { amount: tokenMax, amountWithBorrow } = useTokenMax(useMargin) const { amount: tokenMax, amountWithBorrow } = useTokenMax(useMargin)
const { handleConnect } = useEnhancedWallet()
const showInsufficientBalance = useMargin const showInsufficientBalance = useMargin
? amountWithBorrow.lt(amountIn) ? amountWithBorrow.lt(amountIn)
: tokenMax.lt(amountIn) : tokenMax.lt(amountIn)
const disabled = const disabled =
!amountIn.toNumber() || !connected || showInsufficientBalance || !amountOut connected && (!amountIn.toNumber() || showInsufficientBalance || !amountOut)
const onClick = connected ? () => setShowConfirm(true) : handleConnect
return ( return (
<Button <Button
onClick={() => setShowConfirm(true)} onClick={onClick}
className="mt-6 mb-4 flex w-full items-center justify-center text-base" className="mt-6 mb-4 flex w-full items-center justify-center text-base"
disabled={disabled} disabled={disabled}
size="large" size="large"

View File

@ -2,7 +2,6 @@ import { Fragment, useEffect, useState } from 'react'
import { import {
ArrowRightIcon, ArrowRightIcon,
ChevronDownIcon, ChevronDownIcon,
LinkIcon,
NoSymbolIcon, NoSymbolIcon,
} from '@heroicons/react/20/solid' } from '@heroicons/react/20/solid'
import dayjs from 'dayjs' import dayjs from 'dayjs'
@ -28,6 +27,7 @@ import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
import { useWallet } from '@solana/wallet-adapter-react' import { useWallet } from '@solana/wallet-adapter-react'
import { EXPLORERS } from '@components/settings/PreferredExplorerSettings' import { EXPLORERS } from '@components/settings/PreferredExplorerSettings'
import useMangoAccount from 'hooks/useMangoAccount' import useMangoAccount from 'hooks/useMangoAccount'
import ConnectEmptyState from '@components/shared/ConnectEmptyState'
const SwapHistoryTable = ({ const SwapHistoryTable = ({
swapHistory, swapHistory,
@ -422,9 +422,8 @@ const SwapHistoryTable = ({
</div> </div>
) )
) : ( ) : (
<div className="flex flex-col items-center p-8"> <div className="p-8">
<LinkIcon className="mb-2 h-6 w-6 text-th-fgd-4" /> <ConnectEmptyState text={t('swap:connect-swap')} />
<p>{t('swap:connect-swap')}</p>
</div> </div>
) )
} }

View File

@ -22,7 +22,7 @@ import { notify } from 'utils/notifications'
import SpotSlider from './SpotSlider' import SpotSlider from './SpotSlider'
import { calculateLimitPriceForMarketOrder } from 'utils/tradeForm' import { calculateLimitPriceForMarketOrder } from 'utils/tradeForm'
import Image from 'next/legacy/image' import Image from 'next/legacy/image'
import { QuestionMarkCircleIcon } from '@heroicons/react/20/solid' import { LinkIcon, QuestionMarkCircleIcon } from '@heroicons/react/20/solid'
import Loading from '@components/shared/Loading' import Loading from '@components/shared/Loading'
import TabUnderline from '@components/shared/TabUnderline' import TabUnderline from '@components/shared/TabUnderline'
import PerpSlider from './PerpSlider' import PerpSlider from './PerpSlider'
@ -40,6 +40,8 @@ import ButtonGroup from '@components/forms/ButtonGroup'
import TradeSummary from './TradeSummary' import TradeSummary from './TradeSummary'
import useMangoAccount from 'hooks/useMangoAccount' import useMangoAccount from 'hooks/useMangoAccount'
import MaxSizeButton from './MaxSizeButton' import MaxSizeButton from './MaxSizeButton'
import { useWallet } from '@solana/wallet-adapter-react'
import { useEnhancedWallet } from '@components/wallet/EnhancedWalletProvider'
const set = mangoStore.getState().set const set = mangoStore.getState().set
@ -53,6 +55,8 @@ const AdvancedTradeForm = () => {
const [placingOrder, setPlacingOrder] = useState(false) const [placingOrder, setPlacingOrder] = useState(false)
const [tradeFormSizeUi] = useLocalStorageState(SIZE_INPUT_UI_KEY, 'Slider') const [tradeFormSizeUi] = useLocalStorageState(SIZE_INPUT_UI_KEY, 'Slider')
const { ipAllowed, ipCountry } = useIpAddress() const { ipAllowed, ipCountry } = useIpAddress()
const { connected } = useWallet()
const { handleConnect } = useEnhancedWallet()
const baseSymbol = useMemo(() => { const baseSymbol = useMemo(() => {
return selectedMarket?.name.split(/-|\//)[0] return selectedMarket?.name.split(/-|\//)[0]
@ -537,16 +541,23 @@ const AdvancedTradeForm = () => {
<div className="mt-6 mb-4 flex px-3 md:px-4"> <div className="mt-6 mb-4 flex px-3 md:px-4">
{ipAllowed ? ( {ipAllowed ? (
<Button <Button
onClick={handlePlaceOrder} onClick={connected ? handlePlaceOrder : handleConnect}
className={`flex w-full items-center justify-center text-white ${ className={`flex w-full items-center justify-center ${
tradeForm.side === 'buy' !connected
? 'bg-th-up-dark md:hover:bg-th-up' ? ''
: 'bg-th-down-dark md:hover:bg-th-down' : tradeForm.side === 'buy'
? 'bg-th-up-dark text-white md:hover:bg-th-up'
: 'bg-th-down-dark text-white md:hover:bg-th-down'
}`} }`}
disabled={!tradeForm.baseSize} disabled={connected && !tradeForm.baseSize}
size="large" size="large"
> >
{!placingOrder ? ( {!connected ? (
<div className="flex items-center">
<LinkIcon className="mr-2 h-5 w-5" />
{t('connect')}
</div>
) : !placingOrder ? (
<span className="capitalize"> <span className="capitalize">
{t('trade:place-order', { side: tradeForm.side })} {t('trade:place-order', { side: tradeForm.side })}
</span> </span>

View File

@ -9,13 +9,13 @@ import {
} from '@blockworks-foundation/mango-v4' } from '@blockworks-foundation/mango-v4'
import Input from '@components/forms/Input' import Input from '@components/forms/Input'
import { IconButton } from '@components/shared/Button' import { IconButton } from '@components/shared/Button'
import ConnectEmptyState from '@components/shared/ConnectEmptyState'
import Loading from '@components/shared/Loading' import Loading from '@components/shared/Loading'
import SideBadge from '@components/shared/SideBadge' import SideBadge from '@components/shared/SideBadge'
import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements' import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
import Tooltip from '@components/shared/Tooltip' import Tooltip from '@components/shared/Tooltip'
import { import {
CheckIcon, CheckIcon,
LinkIcon,
NoSymbolIcon, NoSymbolIcon,
PencilIcon, PencilIcon,
TrashIcon, TrashIcon,
@ -526,9 +526,8 @@ const OpenOrders = () => {
</div> </div>
) )
) : ( ) : (
<div className="flex flex-col items-center p-8"> <div className="p-8">
<LinkIcon className="mb-2 h-6 w-6 text-th-fgd-4" /> <ConnectEmptyState text={t('trade:connect-orders')} />
<p>{t('trade:connect-orders')}</p>
</div> </div>
) )
} }

View File

@ -1,7 +1,8 @@
import { PerpMarket } from '@blockworks-foundation/mango-v4' import { PerpMarket } from '@blockworks-foundation/mango-v4'
import { LinkButton } from '@components/shared/Button' import { LinkButton } from '@components/shared/Button'
import ConnectEmptyState from '@components/shared/ConnectEmptyState'
import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements' import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
import { LinkIcon, NoSymbolIcon } from '@heroicons/react/20/solid' import { NoSymbolIcon } from '@heroicons/react/20/solid'
import { useWallet } from '@solana/wallet-adapter-react' import { useWallet } from '@solana/wallet-adapter-react'
import mangoStore from '@store/mangoStore' import mangoStore from '@store/mangoStore'
import useMangoGroup from 'hooks/useMangoGroup' import useMangoGroup from 'hooks/useMangoGroup'
@ -156,9 +157,8 @@ const PerpPositions = () => {
</div> </div>
) )
) : ( ) : (
<div className="flex flex-col items-center p-8"> <div className="p-8">
<LinkIcon className="mb-2 h-6 w-6 text-th-fgd-4" /> <ConnectEmptyState text={t('trade:connect-positions')} />
<p>{t('trade:connect-positions')}</p>
</div> </div>
) )
} }

View File

@ -1,4 +1,5 @@
import { I80F48, PerpMarket } from '@blockworks-foundation/mango-v4' import { I80F48, PerpMarket } from '@blockworks-foundation/mango-v4'
import ConnectEmptyState from '@components/shared/ConnectEmptyState'
import InlineNotification from '@components/shared/InlineNotification' import InlineNotification from '@components/shared/InlineNotification'
import SideBadge from '@components/shared/SideBadge' import SideBadge from '@components/shared/SideBadge'
import { import {
@ -9,7 +10,7 @@ import {
TrBody, TrBody,
TrHead, TrHead,
} from '@components/shared/TableElements' } from '@components/shared/TableElements'
import { LinkIcon, NoSymbolIcon } from '@heroicons/react/20/solid' import { NoSymbolIcon } from '@heroicons/react/20/solid'
import { useWallet } from '@solana/wallet-adapter-react' import { useWallet } from '@solana/wallet-adapter-react'
import { PublicKey } from '@solana/web3.js' import { PublicKey } from '@solana/web3.js'
import mangoStore from '@store/mangoStore' import mangoStore from '@store/mangoStore'
@ -232,9 +233,8 @@ const TradeHistory = () => {
</div> </div>
) )
) : ( ) : (
<div className="flex flex-col items-center p-8"> <div className="p-8">
<LinkIcon className="mb-2 h-6 w-6 text-th-fgd-4" /> <ConnectEmptyState text="Connect to view your trade history" />
<p>Connect to view your trade history</p>
</div> </div>
) )
} }

View File

@ -4,7 +4,7 @@ import { useCallback, useState } from 'react'
import { PublicKey } from '@solana/web3.js' import { PublicKey } from '@solana/web3.js'
import { IconButton } from '@components/shared/Button' import { IconButton } from '@components/shared/Button'
import { notify } from 'utils/notifications' import { notify } from 'utils/notifications'
import { CheckIcon, LinkIcon, NoSymbolIcon } from '@heroicons/react/20/solid' import { CheckIcon, NoSymbolIcon } from '@heroicons/react/20/solid'
import Tooltip from '@components/shared/Tooltip' import Tooltip from '@components/shared/Tooltip'
import Loading from '@components/shared/Loading' import Loading from '@components/shared/Loading'
import { useViewport } from 'hooks/useViewport' import { useViewport } from 'hooks/useViewport'
@ -14,6 +14,7 @@ import useMangoGroup from 'hooks/useMangoGroup'
import { PerpMarket, PerpPosition } from '@blockworks-foundation/mango-v4' import { PerpMarket, PerpPosition } from '@blockworks-foundation/mango-v4'
import { useWallet } from '@solana/wallet-adapter-react' import { useWallet } from '@solana/wallet-adapter-react'
import TableMarketName from './TableMarketName' import TableMarketName from './TableMarketName'
import ConnectEmptyState from '@components/shared/ConnectEmptyState'
const UnsettledTrades = ({ const UnsettledTrades = ({
unsettledSpotBalances, unsettledSpotBalances,
@ -286,9 +287,8 @@ const UnsettledTrades = ({
</div> </div>
) )
) : ( ) : (
<div className="flex flex-col items-center p-8"> <div className="p-8">
<LinkIcon className="mb-2 h-6 w-6 text-th-fgd-4" /> <ConnectEmptyState text={t('trade:connect-unsettled')} />
<p>{t('trade:connect-unsettled')}</p>
</div> </div>
) )
} }