diff --git a/components/BorrowForm.tsx b/components/BorrowForm.tsx
index e3a9e9c3..f8bf2372 100644
--- a/components/BorrowForm.tsx
+++ b/components/BorrowForm.tsx
@@ -35,7 +35,6 @@ import useMangoAccount from 'hooks/useMangoAccount'
import useMangoGroup from 'hooks/useMangoGroup'
import TokenVaultWarnings from '@components/shared/TokenVaultWarnings'
import { useWallet } from '@solana/wallet-adapter-react'
-import { useEnhancedWallet } from './wallet/EnhancedWalletProvider'
import FormatNumericValue from './shared/FormatNumericValue'
import { floorToDecimal } from 'utils/numbers'
import BankAmountWithValue from './shared/BankAmountWithValue'
@@ -63,8 +62,7 @@ function BorrowForm({ onSuccess, token }: BorrowFormProps) {
const [showTokenList, setShowTokenList] = useState(false)
const [sizePercentage, setSizePercentage] = useState('')
const { mangoAccount } = useMangoAccount()
- const { connected, publicKey } = useWallet()
- const { handleConnect } = useEnhancedWallet()
+ const { connected, publicKey, connect } = useWallet()
const banks = useBanksWithBalances('maxBorrow')
const bank = useMemo(() => {
@@ -329,7 +327,7 @@ function BorrowForm({ onSuccess, token }: BorrowFormProps) {
) : null}
- {wallets?.map((w) => (
+ {walletsDisplayed?.map((w) => (
{
select(w.adapter.name)
}}
key={w.adapter.name}
>
-
-
- {w.adapter.name}
+
+
+
+
{w.adapter.name}
+
+ {w.adapter.readyState === WalletReadyState.Installed ? (
+
Detected
+ ) : null}
))}
-
- {connected && mangoAccountLoading ? (
-
- ) : (
-
-
-
- {t('onboarding:connect-wallet')}
+ {walletsToDisplay !== 'all' ? (
+
setWalletstoDisplay('all')}
+ >
+ More
+
+
- )}
-
+
+ ) : null}
) : null}
diff --git a/components/shared/ConnectEmptyState.tsx b/components/shared/ConnectEmptyState.tsx
index 672dc4ae..3ec74750 100644
--- a/components/shared/ConnectEmptyState.tsx
+++ b/components/shared/ConnectEmptyState.tsx
@@ -1,19 +1,17 @@
import WalletIcon from '@components/icons/WalletIcon'
-import { useEnhancedWallet } from '@components/wallet/EnhancedWalletProvider'
import { LinkIcon } from '@heroicons/react/20/solid'
-import mangoStore from '@store/mangoStore'
import { useTranslation } from 'next-i18next'
import Button from './Button'
+import { useWallet } from '@solana/wallet-adapter-react'
const ConnectEmptyState = ({ text }: { text: string }) => {
const { t } = useTranslation('common')
- const { handleConnect } = useEnhancedWallet()
- const groupLoaded = mangoStore((s) => s.groupLoaded)
+ const { connect } = useWallet()
return (
{text}
-
+
{t('connect')}
diff --git a/components/swap/SwapForm.tsx b/components/swap/SwapForm.tsx
index 27aff671..ea92dedd 100644
--- a/components/swap/SwapForm.tsx
+++ b/components/swap/SwapForm.tsx
@@ -42,7 +42,6 @@ import TokenVaultWarnings from '@components/shared/TokenVaultWarnings'
import MaxSwapAmount from './MaxSwapAmount'
import PercentageSelectButtons from './PercentageSelectButtons'
import useIpAddress from 'hooks/useIpAddress'
-import { useEnhancedWallet } from '@components/wallet/EnhancedWalletProvider'
import SwapSettings from './SwapSettings'
import InlineNotification from '@components/shared/InlineNotification'
import useUnownedAccount from 'hooks/useUnownedAccount'
@@ -601,9 +600,8 @@ const SwapFormSubmitButton = ({
useMargin: boolean
}) => {
const { t } = useTranslation('common')
- const { connected } = useWallet()
+ const { connected, connect } = useWallet()
const { amount: tokenMax, amountWithBorrow } = useTokenMax(useMargin)
- const { handleConnect } = useEnhancedWallet()
const showInsufficientBalance = useMargin
? amountWithBorrow.lt(amountIn)
@@ -616,7 +614,7 @@ const SwapFormSubmitButton = ({
!amountOut ||
!selectedRoute)
- const onClick = connected ? () => setShowConfirm(true) : handleConnect
+ const onClick = connected ? () => setShowConfirm(true) : connect
return (
<>
diff --git a/components/trade/AdvancedTradeForm.tsx b/components/trade/AdvancedTradeForm.tsx
index a918d766..7353f7a6 100644
--- a/components/trade/AdvancedTradeForm.tsx
+++ b/components/trade/AdvancedTradeForm.tsx
@@ -55,7 +55,6 @@ import MaxSizeButton from './MaxSizeButton'
import { INITIAL_SOUND_SETTINGS } from '@components/settings/SoundSettings'
import { Howl } from 'howler'
import { useWallet } from '@solana/wallet-adapter-react'
-import { useEnhancedWallet } from '@components/wallet/EnhancedWalletProvider'
import { isMangoError } from 'types'
import InlineNotification from '@components/shared/InlineNotification'
import SpotMarketOrderSwapForm from './SpotMarketOrderSwapForm'
@@ -92,8 +91,7 @@ const AdvancedTradeForm = () => {
SOUND_SETTINGS_KEY,
INITIAL_SOUND_SETTINGS
)
- const { connected } = useWallet()
- const { handleConnect } = useEnhancedWallet()
+ const { connected, connect } = useWallet()
const {
selectedMarket,
price: oraclePrice,
@@ -478,7 +476,7 @@ const AdvancedTradeForm = () => {
const handleSubmit = (e: FormEvent
) => {
e.preventDefault()
- connected ? handlePlaceOrder() : handleConnect()
+ connected ? handlePlaceOrder() : connect()
}
const disabled =
diff --git a/components/trade/SpotMarketOrderSwapForm.tsx b/components/trade/SpotMarketOrderSwapForm.tsx
index 5604ef82..be488a85 100644
--- a/components/trade/SpotMarketOrderSwapForm.tsx
+++ b/components/trade/SpotMarketOrderSwapForm.tsx
@@ -24,7 +24,6 @@ import {
fetchJupiterTransaction,
} from '@blockworks-foundation/mango-v4'
import Decimal from 'decimal.js'
-import { useEnhancedWallet } from '@components/wallet/EnhancedWalletProvider'
import { notify } from 'utils/notifications'
import * as sentry from '@sentry/nextjs'
import { isMangoError } from 'types'
@@ -54,8 +53,7 @@ export default function SpotMarketOrderSwapForm() {
const { isUnownedAccount } = useUnownedAccount()
const [placingOrder, setPlacingOrder] = useState(false)
const { ipAllowed, ipCountry } = useIpAddress()
- const { connected, publicKey } = useWallet()
- const { handleConnect } = useEnhancedWallet()
+ const { connected, publicKey, connect } = useWallet()
const [swapFormSizeUi] = useLocalStorageState(SIZE_INPUT_UI_KEY, 'slider')
const {
selectedMarket,
@@ -240,7 +238,7 @@ export default function SpotMarketOrderSwapForm() {
const handleSubmit = (e: FormEvent) => {
e.preventDefault()
- connected ? handlePlaceOrder() : handleConnect()
+ connected ? handlePlaceOrder() : connect()
}
const maintProjectedHealth = useMemo(() => {
diff --git a/components/wallet/ConnectWalletButton.tsx b/components/wallet/ConnectWalletButton.tsx
index 2ef68e8f..4c8f4a8e 100644
--- a/components/wallet/ConnectWalletButton.tsx
+++ b/components/wallet/ConnectWalletButton.tsx
@@ -1,64 +1,99 @@
-import React, { useMemo } from 'react'
+import React, { Fragment } from 'react'
import { useWallet } from '@solana/wallet-adapter-react'
import { useTranslation } from 'next-i18next'
-import WalletSelect from './WalletSelect'
+import WalletIcon from '@components/icons/WalletIcon'
+import useLocalStorageState from 'hooks/useLocalStorageState'
+import { IS_ONBOARDED_KEY } from 'utils/constants'
+import { ChevronDownIcon } from '@heroicons/react/20/solid'
+import { Popover, Transition } from '@headlessui/react'
+import Loading from '@components/shared/Loading'
import mangoStore from '@store/mangoStore'
-import Loading from '../shared/Loading'
-import { useEnhancedWallet } from './EnhancedWalletProvider'
-export const ConnectWalletButton: React.FC = () => {
- const { connecting, wallet } = useWallet()
- const { displayedWallets, handleConnect, preselectedWalletName } =
- useEnhancedWallet()
- const groupLoaded = mangoStore((s) => s.groupLoaded)
+export default function ConnectWalletButton({
+ handleShowSetup,
+}: {
+ handleShowSetup: () => void
+}) {
const { t } = useTranslation('common')
-
- const selectedWallet = useMemo(() => {
- if (!displayedWallets.length || !preselectedWalletName) return undefined
- return displayedWallets.find(
- (w) => w.adapter.name === preselectedWalletName
- )
- }, [displayedWallets, preselectedWalletName])
+ const { wallet, wallets, select } = useWallet()
+ const [isOnboarded] = useLocalStorageState(IS_ONBOARDED_KEY)
+ const mangoAccountLoading = mangoStore((s) => s.mangoAccount.initialLoad)
return (
-
-
-
- {connecting ? (
-
- ) : (
-
-
-
+ <>
+ {isOnboarded ? (
+
+ {({ open }) => (
+ <>
+
+
+
+
+
+
+ {wallet?.adapter.name && mangoAccountLoading ? (
+
+ ) : (
+
+ )}
+ {t('connect')}
+
+
+
+
+
+
+
+
+
+ {wallets.map((wallet, index) => (
+ {
+ select(wallet.adapter.name)
+ }}
+ key={wallet.adapter.name + index}
+ >
+
+
+ {wallet.adapter.name}
+
+
+ ))}
+
+
+ >
)}
-
-
- {t('connect')}
-
-
-
- {preselectedWalletName}
-
+
+ ) : (
+
+
+
+ {t('connect')}
-
-
-
-
+
+ )}
+ >
)
}
diff --git a/components/wallet/ConnectedMenu.tsx b/components/wallet/ConnectedMenu.tsx
index 0352d716..f8f90768 100644
--- a/components/wallet/ConnectedMenu.tsx
+++ b/components/wallet/ConnectedMenu.tsx
@@ -4,7 +4,7 @@ import {
CurrencyDollarIcon,
UserCircleIcon,
} from '@heroicons/react/20/solid'
-import { useWallet, Wallet } from '@solana/wallet-adapter-react'
+import { useWallet } from '@solana/wallet-adapter-react'
import { useTranslation } from 'next-i18next'
import { Fragment, useCallback, useEffect, useState } from 'react'
import mangoStore from '@store/mangoStore'
@@ -15,29 +15,25 @@ import { useViewport } from 'hooks/useViewport'
import { breakpoints } from '../../utils/theme'
import EditProfileModal from '@components/modals/EditProfileModal'
import MangoAccountsListModal from '@components/modals/MangoAccountsListModal'
+import { TV_USER_ID_KEY } from 'utils/constants'
+import useLocalStorageState from 'hooks/useLocalStorageState'
+
+const set = mangoStore.getState().set
+const actions = mangoStore.getState().actions
const ConnectedMenu = () => {
const { t } = useTranslation('common')
const { publicKey, disconnect, wallet } = useWallet()
const { width } = useViewport()
-
+ const [tvUserId, setTvUserId] = useLocalStorageState(TV_USER_ID_KEY, '')
const [showEditProfileModal, setShowEditProfileModal] = useState(false)
const [showMangoAccountsModal, setShowMangoAccountsModal] = useState(false)
- const set = mangoStore((s) => s.set)
- const actions = mangoStore.getState().actions
// const profileDetails = mangoStore((s) => s.profile.details)
const loadProfileDetails = mangoStore((s) => s.profile.loadDetails)
-
+ const groupLoaded = mangoStore((s) => s.groupLoaded)
const isMobile = width ? width < breakpoints.md : false
- const onConnectFetchAccountData = async (wallet: Wallet) => {
- if (!wallet.adapter.publicKey) return
- await actions.fetchMangoAccounts(wallet.adapter.publicKey)
- // actions.fetchTourSettings(wallet.adapter.publicKey?.toString() as string)
- actions.fetchWalletTokens(wallet.adapter.publicKey)
- }
-
const handleDisconnect = useCallback(() => {
set((state) => {
state.activityFeed.feed = []
@@ -52,20 +48,20 @@ const ConnectedMenu = () => {
type: 'info',
title: t('wallet-disconnected'),
})
- }, [set, t, disconnect])
+ }, [t, disconnect])
useEffect(() => {
- const handleGetWalletMangoData = async (wallet: Wallet) => {
- const actions = mangoStore.getState().actions
- await actions.connectMangoClientWithWallet(wallet)
- await onConnectFetchAccountData(wallet)
- }
-
- if (publicKey && wallet) {
+ if (publicKey && wallet && groupLoaded) {
+ actions.connectMangoClientWithWallet(wallet)
+ actions.fetchMangoAccounts(publicKey)
+ // actions.fetchTourSettings(publicKey?.toString() as string)
actions.fetchProfileDetails(publicKey.toString())
- handleGetWalletMangoData(wallet)
+ actions.fetchWalletTokens(publicKey)
+ if (!tvUserId) {
+ setTvUserId(publicKey.toString())
+ }
}
- }, [publicKey, actions, wallet])
+ }, [publicKey, wallet, groupLoaded, tvUserId, setTvUserId])
return (
<>
diff --git a/components/wallet/EnhancedWalletProvider.tsx b/components/wallet/EnhancedWalletProvider.tsx
deleted file mode 100644
index c72a8aab..00000000
--- a/components/wallet/EnhancedWalletProvider.tsx
+++ /dev/null
@@ -1,162 +0,0 @@
-import { SolanaMobileWalletAdapter } from '@solana-mobile/wallet-adapter-mobile'
-import { WalletName, WalletReadyState } from '@solana/wallet-adapter-base'
-import { useWallet, Wallet } from '@solana/wallet-adapter-react'
-import { StandardWalletAdapter } from '@solana/wallet-standard-wallet-adapter-base'
-import React, {
- createContext,
- ReactNode,
- useCallback,
- useContext,
- useEffect,
- useMemo,
-} from 'react'
-import { notify } from 'utils/notifications'
-import useLocalStorageState from 'hooks/useLocalStorageState'
-import { TV_USER_ID_KEY } from 'utils/constants'
-
-interface EnhancedWalletContextState {
- displayedWallets: Wallet[]
- preselectedWalletName: string
- handleSelect: (name: WalletName | null) => void
- handleConnect: () => Promise
-}
-
-const EnhancedWalletContext = createContext(
- {} as EnhancedWalletContextState
-)
-
-export function useEnhancedWallet(): EnhancedWalletContextState {
- return useContext(EnhancedWalletContext)
-}
-
-export default function EnhancedWalletProvider({
- children,
-}: {
- children: ReactNode
-}) {
- const { wallets, select, wallet, connect } = useWallet()
-
- const displayedWallets = useMemo(
- () =>
- wallets.slice().sort(({ adapter: a }, { adapter: b }) => {
- if (a instanceof SolanaMobileWalletAdapter) {
- if (b instanceof SolanaMobileWalletAdapter) return 0
- return -1
- } else if (b instanceof SolanaMobileWalletAdapter) {
- return 1
- }
-
- if (a instanceof StandardWalletAdapter) {
- if (b instanceof StandardWalletAdapter) return 0
- return -1
- } else if (b instanceof StandardWalletAdapter) {
- return 1
- }
-
- if (a.readyState === b.readyState) return 0
- if (a.readyState === WalletReadyState.Installed) return -1
- if (b.readyState === WalletReadyState.Installed) return 1
- return 0
- }),
- [wallets]
- )
-
- const [preselectedWalletName, setPreselectedWalletName] =
- useLocalStorageState('preselectedWalletName', '')
-
- const [tvUserId, setTvUserId] = useLocalStorageState(TV_USER_ID_KEY, '')
-
- useEffect(() => {
- if (wallet) {
- setPreselectedWalletName(wallet.adapter.name)
- } else {
- const hasInstalledWallet = displayedWallets.find(
- (w) => w.readyState === 'Installed'
- )
- if (hasInstalledWallet) {
- setPreselectedWalletName(hasInstalledWallet.adapter.name)
- } else {
- setPreselectedWalletName('Phantom')
- }
- }
- }, [displayedWallets, wallet, setPreselectedWalletName])
-
- useEffect(() => {
- if (!wallet && preselectedWalletName) {
- const wallet = wallets.find(
- (w) => w.adapter.name === preselectedWalletName
- )
- if (wallet) {
- select(wallet.adapter.name)
- }
- }
- }, [wallet, preselectedWalletName, wallets, select])
-
- const handleSelect = useCallback(
- (name: WalletName | null) => {
- setPreselectedWalletName(name)
- select(name)
- },
- [setPreselectedWalletName, select]
- )
-
- const handleConnect = useCallback(async () => {
- if (wallet) {
- try {
- console.log('connecting')
- await connect()
- if (!tvUserId && wallet.adapter.publicKey) {
- setTvUserId(wallet.adapter.publicKey.toString())
- }
- } catch (e) {
- // Error will be handled by WalletProvider#onError
- select(null)
- }
- } else if (preselectedWalletName) {
- const adapter = wallets.find(
- ({ adapter }) => adapter.name === preselectedWalletName
- )?.adapter
-
- if (!adapter) {
- setPreselectedWalletName(null)
- return
- }
-
- if (
- adapter.readyState === WalletReadyState.Installed ||
- adapter.readyState === WalletReadyState.Loadable
- ) {
- await select(adapter.name)
- } else {
- 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')
- }
- }
- }
- }, [
- wallets,
- select,
- wallet,
- connect,
- preselectedWalletName,
- setPreselectedWalletName,
- ])
-
- return (
-
- {children}
-
- )
-}
diff --git a/components/wallet/WalletSelect.tsx b/components/wallet/WalletSelect.tsx
deleted file mode 100644
index 0ec71a9f..00000000
--- a/components/wallet/WalletSelect.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-import React, { Fragment } from 'react'
-import { ChevronDownIcon } from '@heroicons/react/20/solid'
-import { Popover, Transition } from '@headlessui/react'
-import { useEnhancedWallet } from './EnhancedWalletProvider'
-import useMangoGroup from 'hooks/useMangoGroup'
-
-const WalletSelect = () => {
- const { displayedWallets, handleSelect } = useEnhancedWallet()
- const { group } = useMangoGroup()
-
- return (
-
- {({ open }) => (
- <>
-
-
-
-
-
- {displayedWallets?.map((wallet, index) => (
- {
- handleSelect(wallet.adapter.name)
- }}
- key={wallet.adapter.name + index}
- >
-
-
- {wallet.adapter.name}
-
-
- ))}
-
-
- >
- )}
-
- )
-}
-
-export default WalletSelect
diff --git a/pages/_app.tsx b/pages/_app.tsx
index 200eb216..81a488b1 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -17,6 +17,14 @@ import {
PhantomWalletAdapter,
SolflareWalletAdapter,
GlowWalletAdapter,
+ BackpackWalletAdapter,
+ BraveWalletAdapter,
+ CoinbaseWalletAdapter,
+ MathWalletAdapter,
+ Coin98WalletAdapter,
+ CloverWalletAdapter,
+ LedgerWalletAdapter,
+ ExodusWalletAdapter,
} from '@solana/wallet-adapter-wallets'
import { clusterApiUrl } from '@solana/web3.js'
import TransactionNotification from '@components/notifications/TransactionNotification'
@@ -26,7 +34,6 @@ import Layout from '../components/Layout'
import { ViewportProvider } from '../hooks/useViewport'
import MangoProvider from '@components/MangoProvider'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
-import EnhancedWalletProvider from '@components/wallet/EnhancedWalletProvider'
import { notify } from 'utils/notifications'
import { useRouter } from 'next/router'
import useSelectedMarket from 'hooks/useSelectedMarket'
@@ -36,16 +43,15 @@ import { PerpMarket } from '@blockworks-foundation/mango-v4'
import { getDecimalCount } from 'utils/numbers'
import { THEME_KEY } from 'utils/constants'
-// Do not add hooks to this component that will cause unnecessary rerenders
-// Top level state hydrating/updating should go in MangoProvider
-
-// Create a client
+// init react-query
export const queryClient = new QueryClient()
const metaTitle = 'Mango Markets – Safer. Smarter. Faster.'
const metaDescription =
'A magical new way to interact with DeFi. Groundbreaking safety features designed to keep your funds secure. The easiest way to margin trade any token pair. All powered by flashloans.'
+// Do not add hooks to this component, that will cause unnecessary rerenders
+// Top level state hydrating/updating should go in MangoProvider
function MyApp({ Component, pageProps }: AppProps) {
const network = WalletAdapterNetwork.Mainnet
const endpoint = useMemo(() => clusterApiUrl(network), [network])
@@ -53,7 +59,15 @@ function MyApp({ Component, pageProps }: AppProps) {
() => [
new PhantomWalletAdapter(),
new SolflareWalletAdapter(),
+ new BackpackWalletAdapter(),
new GlowWalletAdapter(),
+ new BraveWalletAdapter(),
+ new CoinbaseWalletAdapter(),
+ new MathWalletAdapter(),
+ new Coin98WalletAdapter(),
+ new CloverWalletAdapter(),
+ new LedgerWalletAdapter(),
+ new ExodusWalletAdapter(),
],
[]
)
@@ -100,21 +114,16 @@ function MyApp({ Component, pageProps }: AppProps) {
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/store/mangoStore.ts b/store/mangoStore.ts
index 087fabab..209f573d 100644
--- a/store/mangoStore.ts
+++ b/store/mangoStore.ts
@@ -42,11 +42,9 @@ import {
RPC_PROVIDER_KEY,
} from '../utils/constants'
import {
- AccountPerformanceData,
ActivityFeed,
EmptyObject,
OrderbookL2,
- PerformanceDataItem,
PerpStatsItem,
PerpTradeHistory,
SerumEvent,
diff --git a/utils/index.ts b/utils/index.ts
index de0b7e5a..92a54322 100644
--- a/utils/index.ts
+++ b/utils/index.ts
@@ -44,3 +44,14 @@ export const copyToClipboard = (copyThis: string) => {
document.execCommand('copy')
document.body.removeChild(el)
}
+
+export function getNetworkInfo() {
+ const connection =
+ (navigator as any).connection ||
+ (navigator as any).mozConnection ||
+ (navigator as any).webkitConnection
+ if (connection) {
+ return connection.effectiveType
+ }
+ return 'unknown'
+}