2022-09-27 11:47:15 -07:00
|
|
|
import '../styles/globals.css'
|
2022-09-29 20:22:55 -07:00
|
|
|
import 'react-nice-dates/build/style.css'
|
|
|
|
import '../styles/datepicker.css'
|
2022-04-12 13:48:22 -07:00
|
|
|
import type { AppProps } from 'next/app'
|
2022-11-15 20:12:51 -08:00
|
|
|
import { useCallback, useMemo } from 'react'
|
|
|
|
import {
|
|
|
|
Adapter,
|
|
|
|
WalletAdapterNetwork,
|
|
|
|
WalletError,
|
|
|
|
WalletNotReadyError,
|
|
|
|
} from '@solana/wallet-adapter-base'
|
|
|
|
import {
|
|
|
|
ConnectionProvider,
|
|
|
|
WalletProvider,
|
|
|
|
} from '@solana/wallet-adapter-react'
|
2022-06-10 06:05:45 -07:00
|
|
|
import {
|
|
|
|
PhantomWalletAdapter,
|
|
|
|
SolflareWalletAdapter,
|
|
|
|
} from '@solana/wallet-adapter-wallets'
|
|
|
|
import { clusterApiUrl } from '@solana/web3.js'
|
2022-07-05 20:37:49 -07:00
|
|
|
import Notifications from '../components/shared/Notification'
|
|
|
|
import { ThemeProvider } from 'next-themes'
|
2022-07-14 16:36:31 -07:00
|
|
|
import { appWithTranslation } from 'next-i18next'
|
2022-07-26 19:45:27 -07:00
|
|
|
import Layout from '../components/Layout'
|
2022-07-18 04:17:56 -07:00
|
|
|
import { ViewportProvider } from '../hooks/useViewport'
|
2022-09-27 11:47:15 -07:00
|
|
|
import MangoProvider from '@components/MangoProvider'
|
2022-10-07 16:39:06 -07:00
|
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
2022-11-15 20:12:51 -08:00
|
|
|
import EnhancedWalletProvider from '@components/wallet/EnhancedWalletProvider'
|
|
|
|
import { notify } from 'utils/notifications'
|
2022-06-10 06:05:45 -07:00
|
|
|
|
2022-09-27 11:47:15 -07:00
|
|
|
// Do not add hooks to this component that will cause unnecessary rerenders
|
|
|
|
// Top level state hydrating/updating should go in MangoProvider
|
2022-06-29 20:37:25 -07:00
|
|
|
|
2022-10-07 16:39:06 -07:00
|
|
|
// Create a client
|
|
|
|
const queryClient = new QueryClient()
|
|
|
|
|
2022-06-29 20:37:25 -07:00
|
|
|
function MyApp({ Component, pageProps }: AppProps) {
|
2022-06-10 06:05:45 -07:00
|
|
|
const network = WalletAdapterNetwork.Devnet
|
|
|
|
const endpoint = useMemo(() => clusterApiUrl(network), [network])
|
|
|
|
const wallets = useMemo(
|
2022-11-15 20:12:51 -08:00
|
|
|
() => [new PhantomWalletAdapter(), new SolflareWalletAdapter({ network })],
|
|
|
|
[]
|
2022-06-10 06:05:45 -07:00
|
|
|
)
|
|
|
|
|
2022-11-15 20:12:51 -08:00
|
|
|
const onError = useCallback((error: WalletError, adapter?: Adapter) => {
|
|
|
|
console.error(error, adapter)
|
|
|
|
if (error instanceof WalletNotReadyError && adapter) {
|
|
|
|
notify({
|
|
|
|
title: `${adapter.name} Error`,
|
|
|
|
type: 'error',
|
|
|
|
description: `Please install ${adapter.name} and then reload this page.`,
|
|
|
|
})
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
window.open(adapter.url, '_blank')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [])
|
|
|
|
|
2022-06-10 06:05:45 -07:00
|
|
|
return (
|
2022-06-29 20:37:25 -07:00
|
|
|
<>
|
2022-09-27 11:47:15 -07:00
|
|
|
<MangoProvider />
|
2022-10-07 16:39:06 -07:00
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<ConnectionProvider endpoint={endpoint}>
|
2022-11-15 20:12:51 -08:00
|
|
|
<WalletProvider wallets={wallets} onError={onError}>
|
|
|
|
<EnhancedWalletProvider>
|
2022-12-07 17:04:48 -08:00
|
|
|
<ThemeProvider defaultTheme="Mango Classic">
|
2022-11-15 20:12:51 -08:00
|
|
|
<ViewportProvider>
|
|
|
|
<Layout>
|
|
|
|
<Component {...pageProps} />
|
|
|
|
</Layout>
|
|
|
|
</ViewportProvider>
|
|
|
|
<Notifications />
|
|
|
|
</ThemeProvider>
|
|
|
|
</EnhancedWalletProvider>
|
2022-10-07 16:39:06 -07:00
|
|
|
</WalletProvider>
|
|
|
|
</ConnectionProvider>
|
|
|
|
</QueryClientProvider>
|
2022-06-29 20:37:25 -07:00
|
|
|
</>
|
2022-06-10 06:05:45 -07:00
|
|
|
)
|
2022-04-12 13:48:22 -07:00
|
|
|
}
|
|
|
|
|
2022-07-14 16:36:31 -07:00
|
|
|
export default appWithTranslation(MyApp)
|