import Head from 'next/head' import { ThemeProvider } from 'next-themes' import '../node_modules/react-grid-layout/css/styles.css' import '../node_modules/react-resizable/css/styles.css' import 'intro.js/introjs.css' import '../styles/index.css' import 'react-nice-dates/build/style.css' import '../styles/datepicker.css' import useHydrateStore from '../hooks/useHydrateStore' import Notifications from '../components/Notification' import useMangoStore from '../stores/useMangoStore' import useOraclePrice from '../hooks/useOraclePrice' import { getDecimalCount } from '../utils' import { useRouter } from 'next/router' import { ViewportProvider } from '../hooks/useViewport' import BottomBar from '../components/mobile/BottomBar' import { appWithTranslation } from 'next-i18next' import ErrorBoundary from '../components/ErrorBoundary' import GlobalNotification from '../components/GlobalNotification' import { useOpenOrders } from '../hooks/useOpenOrders' import usePerpPositions from '../hooks/usePerpPositions' import { useEffect, useMemo } from 'react' import { PublicKey } from '@solana/web3.js' import { connectionSelector, mangoGroupSelector } from '../stores/selectors' import { ReferrerIdRecordLayout, ReferrerIdRecord, } from '@blockworks-foundation/mango-client' import useTradeHistory from '../hooks/useTradeHistory' import * as Sentry from '@sentry/react' import { BrowserTracing } from '@sentry/tracing' Sentry.init({ dsn: 'https://657354c743f24ac686c979e77d9759d9@o1177229.ingest.sentry.io/6276097', integrations: [new BrowserTracing()], }) import { WalletProvider, WalletListener } from 'components/WalletAdapter' import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom' import { SolflareWalletAdapter } from '@solana/wallet-adapter-solflare' import { SolletWalletAdapter } from '@solana/wallet-adapter-sollet' import { SlopeWalletAdapter } from '@solana/wallet-adapter-slope' import { BitpieWalletAdapter } from '@solana/wallet-adapter-bitpie' import { HuobiWalletAdapter } from '@solana/wallet-adapter-huobi' import { GlowWalletAdapter } from '@solana/wallet-adapter-glow' const MangoStoreUpdater = () => { useHydrateStore() return null } const OpenOrdersStoreUpdater = () => { useOpenOrders() return null } const PerpPositionsStoreUpdater = () => { usePerpPositions() return null } const TradeHistoryStoreUpdater = () => { useTradeHistory() return null } const FetchReferrer = () => { const setMangoStore = useMangoStore((s) => s.set) const router = useRouter() const mangoGroup = useMangoStore(mangoGroupSelector) const connection = useMangoStore(connectionSelector) const { query } = router useEffect(() => { const storeReferrer = async () => { if (query.ref && mangoGroup) { let referrerPk if (query.ref.length === 44) { referrerPk = new PublicKey(query.ref) } else { let decodedRefLink: string try { decodedRefLink = decodeURIComponent(query.ref as string) } catch (e) { console.log('Failed to decode referrer link', e) } const mangoClient = useMangoStore.getState().connection.client const { referrerPda } = await mangoClient.getReferrerPda( mangoGroup, decodedRefLink ) const info = await connection.getAccountInfo(referrerPda) if (info) { const decoded = ReferrerIdRecordLayout.decode(info.data) const referrerRecord = new ReferrerIdRecord(decoded) referrerPk = referrerRecord.referrerMangoAccount } } setMangoStore((state) => { state.referrerPk = referrerPk }) } } storeReferrer() }, [query, mangoGroup]) return null } const PageTitle = () => { const router = useRouter() const marketConfig = useMangoStore((s) => s.selectedMarket.config) const market = useMangoStore((s) => s.selectedMarket.current) const oraclePrice = useOraclePrice() const selectedMarketName = marketConfig.name const marketTitleString = marketConfig && router.pathname == '/' ? `${ oraclePrice ? oraclePrice.toFixed(getDecimalCount(market?.tickSize)) + ' | ' : '' }${selectedMarketName} - ` : '' return (