diff --git a/components/AccountsButton.tsx b/components/AccountsButton.tsx new file mode 100644 index 00000000..096bbac6 --- /dev/null +++ b/components/AccountsButton.tsx @@ -0,0 +1,72 @@ +import { UsersIcon } from '@heroicons/react/20/solid' +import useMangoAccount from 'hooks/useMangoAccount' +import { useTranslation } from 'next-i18next' +import { useCallback, useState } from 'react' +import { abbreviateAddress } from 'utils/formatting' +import CreateAccountModal from './modals/CreateAccountModal' +import { DEFAULT_DELEGATE } from './modals/DelegateModal' +import MangoAccountsListModal from './modals/MangoAccountsListModal' +import Tooltip from './shared/Tooltip' + +const AccountsButton = () => { + const { t } = useTranslation('common') + const { mangoAccount, initialLoad } = useMangoAccount() + const [showCreateAccountModal, setShowCreateAccountModal] = useState(false) + const [showMangoAccountsModal, setShowMangoAccountsModal] = useState(false) + + const handleShowAccounts = useCallback(() => { + if (mangoAccount) { + setShowMangoAccountsModal(true) + } else { + setShowCreateAccountModal(true) + } + }, [mangoAccount]) + return ( + <> + + {t('accounts')} + + {mangoAccount ? ( + + {mangoAccount.name} + {mangoAccount.delegate.toString() !== DEFAULT_DELEGATE ? ( + + + + ) : null} + + ) : initialLoad ? ( + {t('loading')}... + ) : ( + + 🥠+ {t('create-account')} + + )} + + + {showMangoAccountsModal ? ( + setShowMangoAccountsModal(false)} + /> + ) : null} + {showCreateAccountModal ? ( + setShowCreateAccountModal(false)} + /> + ) : null} + > + ) +} + +export default AccountsButton diff --git a/components/TopBar.tsx b/components/TopBar.tsx index ce8e33e0..1be20b6d 100644 --- a/components/TopBar.tsx +++ b/components/TopBar.tsx @@ -4,7 +4,6 @@ import { ArrowRightIcon, ExclamationTriangleIcon, EyeIcon, - UsersIcon, } from '@heroicons/react/20/solid' import { useWallet } from '@solana/wallet-adapter-react' import { useTranslation } from 'next-i18next' @@ -15,18 +14,16 @@ import { ConnectWalletButton } from './wallet/ConnectWalletButton' import { IS_ONBOARDED_KEY } from '../utils/constants' import useLocalStorageState from '../hooks/useLocalStorageState' import CreateAccountModal from './modals/CreateAccountModal' -import MangoAccountsListModal from './modals/MangoAccountsListModal' import { useRouter } from 'next/router' import UserSetupModal from './modals/UserSetupModal' import SolanaTps from './SolanaTps' import useMangoAccount from 'hooks/useMangoAccount' import useOnlineStatus from 'hooks/useOnlineStatus' -import { DEFAULT_DELEGATE } from './modals/DelegateModal' -import Tooltip from './shared/Tooltip' import { abbreviateAddress } from 'utils/formatting' import DepositWithdrawModal from './modals/DepositWithdrawModal' import { useViewport } from 'hooks/useViewport' import { breakpoints } from 'utils/theme' +import AccountsButton from './AccountsButton' // import ThemeSwitcher from './ThemeSwitcher' const TopBar = () => { @@ -35,11 +32,10 @@ const TopBar = () => { const { connected } = useWallet() const [isOnboarded, setIsOnboarded] = useLocalStorageState(IS_ONBOARDED_KEY) const [action, setAction] = useState<'deposit' | 'withdraw'>('deposit') - const [showCreateAccountModal, setShowCreateAccountModal] = useState(false) - const [showMangoAccountsModal, setShowMangoAccountsModal] = useState(false) const [showUserSetup, setShowUserSetup] = useState(false) const [showDepositWithdrawModal, setShowDepositWithdrawModal] = useState(false) + const [showCreateAccountModal, setShowCreateAccountModal] = useState(false) const isOnline = useOnlineStatus() const router = useRouter() const { query } = router @@ -55,14 +51,6 @@ const TopBar = () => { setShowUserSetup(true) }, []) - const handleShowAccounts = useCallback(() => { - if (mangoAccount) { - setShowMangoAccountsModal(true) - } else { - setShowCreateAccountModal(true) - } - }, [mangoAccount]) - const handleDepositWithdrawModal = (action: 'deposit' | 'withdraw') => { if (!connected || mangoAccount) { setAction(action) @@ -133,34 +121,7 @@ const TopBar = () => { )} {connected ? ( - - {t('accounts')} - - {mangoAccount ? ( - - {mangoAccount.name} - {mangoAccount.delegate.toString() !== DEFAULT_DELEGATE ? ( - - - - ) : null} - - ) : ( - - 🥠- {t('create-account')} - - )} - - + ) : isOnboarded ? ( @@ -185,12 +146,6 @@ const TopBar = () => { onClose={() => setShowDepositWithdrawModal(false)} /> ) : null} - {showMangoAccountsModal ? ( - setShowMangoAccountsModal(false)} - /> - ) : null} {showUserSetup ? ( ) : null} diff --git a/components/wallet/ConnectedMenu.tsx b/components/wallet/ConnectedMenu.tsx index 37bb7449..d63ca8fd 100644 --- a/components/wallet/ConnectedMenu.tsx +++ b/components/wallet/ConnectedMenu.tsx @@ -44,6 +44,7 @@ const ConnectedMenu = () => { state.activityFeed.feed = [] state.mangoAccount.current = undefined state.mangoAccounts = [] + state.mangoAccount.initialLoad = true state.mangoAccount.openOrders = {} state.mangoAccount.interestTotals = { data: [], loading: false } state.mangoAccount.performance = { diff --git a/public/locales/en/common.json b/public/locales/en/common.json index d7f04097..61b521ee 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -77,6 +77,7 @@ "leverage": "Leverage", "liability-weight": "Liability Weight", "liquidity": "Liquidity", + "loading": "Loading", "loan-origination-fee": "Loan Origination Fee", "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", "mango": "Mango", diff --git a/public/locales/es/common.json b/public/locales/es/common.json index d7f04097..61b521ee 100644 --- a/public/locales/es/common.json +++ b/public/locales/es/common.json @@ -77,6 +77,7 @@ "leverage": "Leverage", "liability-weight": "Liability Weight", "liquidity": "Liquidity", + "loading": "Loading", "loan-origination-fee": "Loan Origination Fee", "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", "mango": "Mango", diff --git a/public/locales/ru/common.json b/public/locales/ru/common.json index d7f04097..61b521ee 100644 --- a/public/locales/ru/common.json +++ b/public/locales/ru/common.json @@ -77,6 +77,7 @@ "leverage": "Leverage", "liability-weight": "Liability Weight", "liquidity": "Liquidity", + "loading": "Loading", "loan-origination-fee": "Loan Origination Fee", "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", "mango": "Mango", diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index d7f04097..61b521ee 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -77,6 +77,7 @@ "leverage": "Leverage", "liability-weight": "Liability Weight", "liquidity": "Liquidity", + "loading": "Loading", "loan-origination-fee": "Loan Origination Fee", "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", "mango": "Mango", diff --git a/public/locales/zh_tw/common.json b/public/locales/zh_tw/common.json index d7f04097..61b521ee 100644 --- a/public/locales/zh_tw/common.json +++ b/public/locales/zh_tw/common.json @@ -77,6 +77,7 @@ "leverage": "Leverage", "liability-weight": "Liability Weight", "liquidity": "Liquidity", + "loading": "Loading", "loan-origination-fee": "Loan Origination Fee", "loan-origination-fee-tooltip": "The fee for opening a borrow. This is paid to the Mango DAO Treasury", "mango": "Mango",
{t('accounts')}