2022-03-22 02:18:58 -07:00
|
|
|
import React, { FunctionComponent, useCallback } from 'react'
|
2022-06-30 03:54:01 -07:00
|
|
|
import { LinkIcon } from '@heroicons/react/solid'
|
2021-04-15 06:22:39 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
|
|
|
import { MoveIcon } from './icons'
|
2021-07-22 04:34:03 -07:00
|
|
|
import EmptyState from './EmptyState'
|
2021-10-20 05:42:40 -07:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2022-03-22 02:18:58 -07:00
|
|
|
import { handleWalletConnect } from 'components/ConnectWalletButton'
|
2022-03-22 04:27:13 -07:00
|
|
|
import { useWallet } from '@solana/wallet-adapter-react'
|
2022-04-09 17:13:12 -07:00
|
|
|
import { useRouter } from 'next/router'
|
2022-06-16 20:17:30 -07:00
|
|
|
import { useViewport } from '../hooks/useViewport'
|
|
|
|
import { breakpoints } from './TradePageGrid'
|
2021-04-14 23:16:36 -07:00
|
|
|
|
2021-04-15 09:13:16 -07:00
|
|
|
interface FloatingElementProps {
|
|
|
|
className?: string
|
2021-07-22 04:34:03 -07:00
|
|
|
showConnect?: boolean
|
2021-04-15 09:13:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const FloatingElement: FunctionComponent<FloatingElementProps> = ({
|
|
|
|
className,
|
|
|
|
children,
|
2021-07-22 04:34:03 -07:00
|
|
|
showConnect,
|
2021-04-15 09:13:16 -07:00
|
|
|
}) => {
|
2021-10-20 05:42:40 -07:00
|
|
|
const { t } = useTranslation('common')
|
2022-03-23 03:42:04 -07:00
|
|
|
const { wallet, connected } = useWallet()
|
2021-04-15 06:22:39 -07:00
|
|
|
const { uiLocked } = useMangoStore((s) => s.settings)
|
2022-03-22 02:18:58 -07:00
|
|
|
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
|
2022-04-09 17:13:12 -07:00
|
|
|
const router = useRouter()
|
|
|
|
const { pubkey } = router.query
|
2022-06-16 20:17:30 -07:00
|
|
|
const { width } = useViewport()
|
|
|
|
const isMobile = width ? width < breakpoints.sm : false
|
2022-03-22 02:18:58 -07:00
|
|
|
|
|
|
|
const handleConnect = useCallback(() => {
|
2022-03-30 04:08:05 -07:00
|
|
|
if (wallet) {
|
|
|
|
handleWalletConnect(wallet)
|
|
|
|
}
|
2022-03-22 02:18:58 -07:00
|
|
|
}, [wallet])
|
|
|
|
|
2021-03-30 15:47:08 -07:00
|
|
|
return (
|
2021-09-19 17:36:02 -07:00
|
|
|
<div
|
2022-06-16 20:17:30 -07:00
|
|
|
className={`thin-scroll relative overflow-auto overflow-x-hidden rounded-md ${
|
2022-06-17 23:14:01 -07:00
|
|
|
!isMobile ? 'border border-th-bkg-3' : ''
|
2022-06-16 20:17:30 -07:00
|
|
|
} bg-th-bkg-1 p-2.5 md:p-4 ${className}`}
|
2021-09-19 17:36:02 -07:00
|
|
|
>
|
2022-04-09 17:13:12 -07:00
|
|
|
{!connected && showConnect && !pubkey ? (
|
2022-03-09 12:53:11 -08:00
|
|
|
<div className="absolute top-0 left-0 z-10 h-full w-full">
|
|
|
|
<div className="relative z-10 flex h-full flex-col items-center justify-center">
|
2021-09-19 17:36:02 -07:00
|
|
|
<EmptyState
|
2022-03-22 02:18:58 -07:00
|
|
|
disabled={!wallet || !mangoGroup}
|
2021-10-20 05:42:40 -07:00
|
|
|
buttonText={t('connect')}
|
2021-09-19 17:36:02 -07:00
|
|
|
icon={<LinkIcon />}
|
2022-03-22 02:18:58 -07:00
|
|
|
onClickButton={handleConnect}
|
2021-10-20 05:42:40 -07:00
|
|
|
title={t('connect-wallet')}
|
2021-09-19 17:36:02 -07:00
|
|
|
/>
|
2021-07-22 04:34:03 -07:00
|
|
|
</div>
|
2022-06-13 17:13:25 -07:00
|
|
|
<div className="absolute top-0 left-0 h-full w-full rounded-lg bg-th-bkg-1 opacity-50" />
|
2021-09-19 17:36:02 -07:00
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
{!uiLocked ? (
|
2022-03-09 12:53:11 -08:00
|
|
|
<div className="absolute top-0 left-0 z-50 h-full w-full cursor-move opacity-80">
|
|
|
|
<div className="relative z-50 flex h-full flex-col items-center justify-center text-th-fgd-1">
|
|
|
|
<MoveIcon className="h-8 w-8" />
|
2021-10-20 05:42:40 -07:00
|
|
|
<div className="mt-2">{t('reposition')}</div>
|
2021-10-26 11:58:49 -07:00
|
|
|
</div>
|
2022-03-09 12:53:11 -08:00
|
|
|
<div className="absolute top-0 left-0 h-full w-full rounded-lg bg-th-bkg-3" />
|
2021-10-26 11:58:49 -07:00
|
|
|
</div>
|
2021-09-19 17:36:02 -07:00
|
|
|
) : null}
|
|
|
|
{children}
|
2021-04-11 14:25:01 -07:00
|
|
|
</div>
|
2021-03-30 15:47:08 -07:00
|
|
|
)
|
|
|
|
}
|
2021-04-15 09:13:16 -07:00
|
|
|
|
|
|
|
export default FloatingElement
|