2021-08-01 05:48:15 -07:00
|
|
|
import { useCallback, useEffect, useState } from 'react'
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
import {
|
|
|
|
CurrencyDollarIcon,
|
2021-07-23 07:07:05 -07:00
|
|
|
DuplicateIcon,
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
ExternalLinkIcon,
|
|
|
|
LinkIcon,
|
2021-07-23 07:07:05 -07:00
|
|
|
PencilIcon,
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
} from '@heroicons/react/outline'
|
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
2021-07-23 07:07:05 -07:00
|
|
|
import { abbreviateAddress, copyToClipboard } from '../utils'
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
import PageBodyContainer from '../components/PageBodyContainer'
|
|
|
|
import TopBar from '../components/TopBar'
|
|
|
|
import AccountAssets from '../components/account-page/AccountAssets'
|
|
|
|
import AccountBorrows from '../components/account-page/AccountBorrows'
|
|
|
|
import AccountOrders from '../components/account-page/AccountOrders'
|
|
|
|
import AccountHistory from '../components/account-page/AccountHistory'
|
|
|
|
import AccountsModal from '../components/AccountsModal'
|
2021-07-25 06:54:25 -07:00
|
|
|
import AccountOverview from '../components/account-page/AccountOverview'
|
2021-07-23 07:07:05 -07:00
|
|
|
import AccountNameModal from '../components/AccountNameModal'
|
|
|
|
import Button from '../components/Button'
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
import EmptyState from '../components/EmptyState'
|
2021-08-20 06:17:02 -07:00
|
|
|
import Loading from '../components/Loading'
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
|
|
|
|
const TABS = [
|
2021-08-01 05:48:15 -07:00
|
|
|
'Portfolio',
|
|
|
|
// 'Assets',
|
|
|
|
// 'Borrows',
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
// 'Stats',
|
|
|
|
// 'Positions',
|
|
|
|
'Orders',
|
2021-08-13 13:02:12 -07:00
|
|
|
'History',
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
]
|
|
|
|
|
|
|
|
export default function Account() {
|
|
|
|
const [activeTab, setActiveTab] = useState(TABS[0])
|
|
|
|
const [showAccountsModal, setShowAccountsModal] = useState(false)
|
2021-07-23 07:07:05 -07:00
|
|
|
const [showNameModal, setShowNameModal] = useState(false)
|
|
|
|
const [isCopied, setIsCopied] = useState(false)
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
const connected = useMangoStore((s) => s.wallet.connected)
|
2021-07-06 17:13:17 -07:00
|
|
|
const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current)
|
2021-07-22 04:34:03 -07:00
|
|
|
const wallet = useMangoStore((s) => s.wallet.current)
|
2021-08-20 06:17:02 -07:00
|
|
|
const isLoading = useMangoStore((s) => s.selectedMangoAccount.initialLoad)
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
|
|
|
|
const handleTabChange = (tabName) => {
|
|
|
|
setActiveTab(tabName)
|
|
|
|
}
|
|
|
|
const handleCloseAccounts = useCallback(() => {
|
|
|
|
setShowAccountsModal(false)
|
|
|
|
}, [])
|
|
|
|
|
2021-07-23 07:07:05 -07:00
|
|
|
const handleCopyPublicKey = (code) => {
|
|
|
|
setIsCopied(true)
|
|
|
|
copyToClipboard(code)
|
|
|
|
}
|
|
|
|
const handleCloseNameModal = useCallback(() => {
|
|
|
|
setShowNameModal(false)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isCopied) {
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
setIsCopied(false)
|
|
|
|
}, 1500)
|
|
|
|
return () => clearTimeout(timer)
|
|
|
|
}
|
|
|
|
}, [isCopied])
|
2021-07-25 06:54:25 -07:00
|
|
|
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
return (
|
|
|
|
<div className={`bg-th-bkg-1 text-th-fgd-1 transition-all`}>
|
|
|
|
<TopBar />
|
|
|
|
<PageBodyContainer>
|
|
|
|
<div className="flex flex-col sm:flex-row items-center justify-between pt-8 pb-3 sm:pb-6 md:pt-10">
|
2021-07-06 17:13:17 -07:00
|
|
|
{mangoAccount ? (
|
2021-07-23 07:07:05 -07:00
|
|
|
<>
|
|
|
|
<div className="flex flex-col sm:flex-row sm:items-end pb-4 md:pb-0">
|
|
|
|
<h1 className={`font-semibold mr-3 text-th-fgd-1 text-2xl`}>
|
2021-07-30 13:37:00 -07:00
|
|
|
{mangoAccount?.name || 'Account'}
|
2021-07-23 07:07:05 -07:00
|
|
|
</h1>
|
|
|
|
<div className="flex items-center pb-0.5 text-th-fgd-3 ">
|
|
|
|
{abbreviateAddress(mangoAccount.publicKey)}
|
|
|
|
<DuplicateIcon
|
|
|
|
className="cursor-pointer default-transition h-4 w-4 ml-1.5 hover:text-th-fgd-1"
|
|
|
|
onClick={() => handleCopyPublicKey(mangoAccount.publicKey)}
|
|
|
|
/>
|
|
|
|
{isCopied ? (
|
|
|
|
<div className="ml-2 text-th-fgd-2 text-xs">Copied!</div>
|
|
|
|
) : null}
|
2021-06-07 10:03:51 -07:00
|
|
|
</div>
|
2021-07-23 07:07:05 -07:00
|
|
|
</div>
|
|
|
|
<div className="flex items-center">
|
2021-07-29 12:05:16 -07:00
|
|
|
<Button
|
2021-07-23 07:07:05 -07:00
|
|
|
className="text-xs flex flex-grow items-center justify-center mr-2 pt-0 pb-0 h-8 pl-3 pr-3"
|
|
|
|
onClick={() => setShowNameModal(true)}
|
|
|
|
>
|
|
|
|
<div className="flex items-center">
|
|
|
|
<PencilIcon className="h-4 w-4 mr-1.5" />
|
2021-07-30 13:37:00 -07:00
|
|
|
{mangoAccount?.name ? 'Edit Name' : 'Add Name'}
|
2021-07-23 07:07:05 -07:00
|
|
|
</div>
|
2021-07-29 12:05:16 -07:00
|
|
|
</Button>
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
<a
|
2021-08-01 05:48:15 -07:00
|
|
|
className="bg-th-bkg-4 default-transition flex flex-grow font-bold h-8 items-center justify-center pl-3 pr-3 rounded-full text-th-fgd-1 text-xs hover:text-th-fgd-1 hover:brightness-[1.15] focus:outline-none"
|
2021-07-06 17:13:17 -07:00
|
|
|
href={`https://explorer.solana.com/address/${mangoAccount?.publicKey}`}
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
2021-07-23 07:07:05 -07:00
|
|
|
<span>Explorer</span>
|
|
|
|
<ExternalLinkIcon className={`h-4 w-4 ml-1.5`} />
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
</a>
|
2021-07-23 07:07:05 -07:00
|
|
|
<Button
|
|
|
|
className="text-xs flex flex-grow items-center justify-center ml-2 pt-0 pb-0 h-8 pl-3 pr-3"
|
|
|
|
onClick={() => setShowAccountsModal(true)}
|
|
|
|
>
|
2021-08-01 05:48:15 -07:00
|
|
|
Accounts
|
2021-07-23 07:07:05 -07:00
|
|
|
</Button>
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
</div>
|
2021-07-23 07:07:05 -07:00
|
|
|
</>
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
) : null}
|
|
|
|
</div>
|
2021-06-07 10:03:51 -07:00
|
|
|
<div className="bg-th-bkg-2 overflow-none p-6 rounded-lg">
|
2021-07-06 17:13:17 -07:00
|
|
|
{mangoAccount ? (
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
<>
|
2021-07-25 06:54:25 -07:00
|
|
|
<div className="border-b border-th-fgd-4 mb-8">
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
<nav className={`-mb-px flex space-x-6`} aria-label="Tabs">
|
|
|
|
{TABS.map((tabName) => (
|
|
|
|
<a
|
|
|
|
key={tabName}
|
|
|
|
onClick={() => handleTabChange(tabName)}
|
|
|
|
className={`whitespace-nowrap pb-4 px-1 border-b-2 font-semibold cursor-pointer default-transition hover:opacity-100
|
2021-07-25 06:54:25 -07:00
|
|
|
${
|
|
|
|
activeTab === tabName
|
|
|
|
? `border-th-primary text-th-primary`
|
|
|
|
: `border-transparent text-th-fgd-4 hover:text-th-primary`
|
|
|
|
}
|
|
|
|
`}
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
>
|
|
|
|
{tabName}
|
|
|
|
</a>
|
|
|
|
))}
|
|
|
|
</nav>
|
|
|
|
</div>
|
2021-07-25 06:54:25 -07:00
|
|
|
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
<TabContent activeTab={activeTab} />
|
|
|
|
</>
|
|
|
|
) : connected ? (
|
2021-08-20 06:17:02 -07:00
|
|
|
isLoading ? (
|
|
|
|
<div className="flex justify-center py-10">
|
|
|
|
<Loading />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<EmptyState
|
|
|
|
buttonText="Create Account"
|
|
|
|
icon={<CurrencyDollarIcon />}
|
|
|
|
onClickButton={() => setShowAccountsModal(true)}
|
|
|
|
title="No Account Found"
|
|
|
|
/>
|
|
|
|
)
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
) : (
|
|
|
|
<EmptyState
|
2021-07-22 04:34:03 -07:00
|
|
|
buttonText="Connect"
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
desc="Connect a wallet to view your account"
|
|
|
|
icon={<LinkIcon />}
|
2021-07-22 04:34:03 -07:00
|
|
|
onClickButton={() => wallet.connect()}
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
title="Connect Wallet"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</PageBodyContainer>
|
|
|
|
{showAccountsModal ? (
|
|
|
|
<AccountsModal
|
|
|
|
onClose={handleCloseAccounts}
|
|
|
|
isOpen={showAccountsModal}
|
|
|
|
/>
|
|
|
|
) : null}
|
2021-07-23 07:07:05 -07:00
|
|
|
{showNameModal ? (
|
|
|
|
<AccountNameModal
|
2021-07-30 13:37:00 -07:00
|
|
|
accountName={mangoAccount?.name}
|
2021-07-23 07:07:05 -07:00
|
|
|
isOpen={showNameModal}
|
|
|
|
onClose={handleCloseNameModal}
|
|
|
|
/>
|
|
|
|
) : null}
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const TabContent = ({ activeTab }) => {
|
|
|
|
switch (activeTab) {
|
2021-08-01 05:48:15 -07:00
|
|
|
case 'Portfolio':
|
2021-07-25 06:54:25 -07:00
|
|
|
return <AccountOverview />
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
case 'Assets':
|
|
|
|
return <AccountAssets />
|
|
|
|
case 'Borrows':
|
|
|
|
return <AccountBorrows />
|
|
|
|
case 'Stats':
|
|
|
|
return <div>Stats</div>
|
|
|
|
case 'Positions':
|
|
|
|
return <div>Positions</div>
|
|
|
|
case 'Orders':
|
|
|
|
return <AccountOrders />
|
|
|
|
case 'History':
|
|
|
|
return <AccountHistory />
|
|
|
|
default:
|
2021-07-25 06:54:25 -07:00
|
|
|
return <AccountOverview />
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
}
|
|
|
|
}
|