2023-06-27 00:10:22 +00:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
import type { ReactNode } from 'react';
|
|
|
|
import { LayoutPriority } from 'allotment';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { titlefy } from '@vegaprotocol/utils';
|
|
|
|
import { t } from '@vegaprotocol/i18n';
|
2023-06-27 00:10:22 +00:00
|
|
|
import { useIncompleteWithdrawals } from '@vegaprotocol/withdraws';
|
2023-05-03 08:44:45 +00:00
|
|
|
import { usePaneLayout } from '@vegaprotocol/react-helpers';
|
2023-06-27 00:10:22 +00:00
|
|
|
import { Tab, LocalStoragePersistTabs as Tabs } from '@vegaprotocol/ui-toolkit';
|
2022-10-14 15:42:53 +00:00
|
|
|
import { usePageTitleStore } from '../../stores';
|
2023-06-27 00:10:22 +00:00
|
|
|
import { useMarketClickHandler } from '../../lib/hooks/use-market-click-handler';
|
2022-11-08 07:23:38 +00:00
|
|
|
import { AccountsContainer } from '../../components/accounts-container';
|
2023-06-27 00:10:22 +00:00
|
|
|
import { DepositsContainer } from './deposits-container';
|
|
|
|
import { FillsContainer } from '../../components/fills-container';
|
|
|
|
import { PositionsContainer } from '../../components/positions-container';
|
|
|
|
import { WithdrawalsContainer } from './withdrawals-container';
|
|
|
|
import { OrdersContainer } from '../../components/orders-container';
|
|
|
|
import { VegaWalletContainer } from '../../components/vega-wallet-container';
|
|
|
|
import { LedgerContainer } from '../../components/ledger-container';
|
2022-12-20 11:22:35 +00:00
|
|
|
import { AccountHistoryContainer } from './account-history-container';
|
2023-04-21 15:16:04 +00:00
|
|
|
import {
|
|
|
|
ResizableGrid,
|
|
|
|
ResizableGridPanel,
|
|
|
|
} from '../../components/resizable-grid';
|
2023-06-26 14:28:14 +00:00
|
|
|
|
|
|
|
const WithdrawalsIndicator = () => {
|
|
|
|
const { ready } = useIncompleteWithdrawals();
|
|
|
|
if (!ready || ready.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<span className="bg-vega-blue-450 text-white text-[10px] rounded p-[3px] pb-[2px] leading-none">
|
|
|
|
{ready.length}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
2022-06-07 09:26:45 +00:00
|
|
|
|
2022-11-08 07:23:38 +00:00
|
|
|
export const Portfolio = () => {
|
2022-10-14 15:42:53 +00:00
|
|
|
const { updateTitle } = usePageTitleStore((store) => ({
|
|
|
|
updateTitle: store.updateTitle,
|
2022-09-23 14:29:35 +00:00
|
|
|
}));
|
2022-11-08 07:23:38 +00:00
|
|
|
|
2022-09-23 14:29:35 +00:00
|
|
|
useEffect(() => {
|
2022-10-14 15:42:53 +00:00
|
|
|
updateTitle(titlefy([t('Portfolio')]));
|
|
|
|
}, [updateTitle]);
|
2022-11-08 07:23:38 +00:00
|
|
|
|
2023-03-31 13:23:44 +00:00
|
|
|
const onMarketClick = useMarketClickHandler(true);
|
2023-05-03 08:44:45 +00:00
|
|
|
const [sizes, handleOnLayoutChange] = usePaneLayout({ id: 'portfolio' });
|
2022-08-31 04:35:46 +00:00
|
|
|
const wrapperClasses = 'h-full max-h-full flex flex-col';
|
2022-02-17 05:03:46 +00:00
|
|
|
return (
|
2022-06-30 07:52:25 +00:00
|
|
|
<div className={wrapperClasses}>
|
2023-05-03 08:44:45 +00:00
|
|
|
<ResizableGrid vertical onChange={handleOnLayoutChange}>
|
2022-08-31 04:35:46 +00:00
|
|
|
<ResizableGridPanel minSize={75}>
|
|
|
|
<PortfolioGridChild>
|
2023-03-22 23:34:58 +00:00
|
|
|
<Tabs storageKey="console-portfolio-top">
|
2022-12-20 11:22:35 +00:00
|
|
|
<Tab id="account-history" name={t('Account history')}>
|
|
|
|
<VegaWalletContainer>
|
|
|
|
<AccountHistoryContainer />
|
|
|
|
</VegaWalletContainer>
|
|
|
|
</Tab>
|
2022-08-05 13:24:46 +00:00
|
|
|
<Tab id="positions" name={t('Positions')}>
|
|
|
|
<VegaWalletContainer>
|
2023-06-27 00:10:22 +00:00
|
|
|
<PositionsContainer onMarketClick={onMarketClick} allKeys />
|
2022-08-05 13:24:46 +00:00
|
|
|
</VegaWalletContainer>
|
|
|
|
</Tab>
|
|
|
|
<Tab id="orders" name={t('Orders')}>
|
|
|
|
<VegaWalletContainer>
|
2023-06-27 00:10:22 +00:00
|
|
|
<OrdersContainer />
|
2022-08-05 13:24:46 +00:00
|
|
|
</VegaWalletContainer>
|
|
|
|
</Tab>
|
|
|
|
<Tab id="fills" name={t('Fills')}>
|
|
|
|
<VegaWalletContainer>
|
2023-06-27 00:10:22 +00:00
|
|
|
<FillsContainer onMarketClick={onMarketClick} />
|
2022-08-05 13:24:46 +00:00
|
|
|
</VegaWalletContainer>
|
|
|
|
</Tab>
|
2022-11-04 10:47:39 +00:00
|
|
|
<Tab id="ledger-entries" name={t('Ledger entries')}>
|
|
|
|
<VegaWalletContainer>
|
|
|
|
<LedgerContainer />
|
|
|
|
</VegaWalletContainer>
|
|
|
|
</Tab>
|
2022-08-05 13:24:46 +00:00
|
|
|
</Tabs>
|
|
|
|
</PortfolioGridChild>
|
2022-08-31 04:35:46 +00:00
|
|
|
</ResizableGridPanel>
|
|
|
|
<ResizableGridPanel
|
2022-08-05 13:24:46 +00:00
|
|
|
priority={LayoutPriority.Low}
|
2023-05-03 08:44:45 +00:00
|
|
|
preferredSize={sizes[1] || 300}
|
2022-08-05 13:24:46 +00:00
|
|
|
minSize={50}
|
|
|
|
>
|
2022-08-31 04:35:46 +00:00
|
|
|
<PortfolioGridChild>
|
2023-03-22 23:34:58 +00:00
|
|
|
<Tabs storageKey="console-portfolio-bottom">
|
2022-08-05 13:24:46 +00:00
|
|
|
<Tab id="collateral" name={t('Collateral')}>
|
|
|
|
<VegaWalletContainer>
|
2023-06-27 00:10:22 +00:00
|
|
|
<AccountsContainer />
|
2022-08-05 13:24:46 +00:00
|
|
|
</VegaWalletContainer>
|
|
|
|
</Tab>
|
|
|
|
<Tab id="deposits" name={t('Deposits')}>
|
2022-09-06 01:30:13 +00:00
|
|
|
<VegaWalletContainer>
|
|
|
|
<DepositsContainer />
|
|
|
|
</VegaWalletContainer>
|
2022-08-05 13:24:46 +00:00
|
|
|
</Tab>
|
2023-06-26 14:28:14 +00:00
|
|
|
<Tab
|
|
|
|
id="withdrawals"
|
|
|
|
name={t('Withdrawals')}
|
|
|
|
indicator={<WithdrawalsIndicator />}
|
|
|
|
>
|
2022-09-06 01:30:13 +00:00
|
|
|
<WithdrawalsContainer />
|
2022-08-05 13:24:46 +00:00
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
</PortfolioGridChild>
|
2022-08-31 04:35:46 +00:00
|
|
|
</ResizableGridPanel>
|
|
|
|
</ResizableGrid>
|
2022-06-30 07:52:25 +00:00
|
|
|
</div>
|
2022-02-17 05:03:46 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-06-30 07:52:25 +00:00
|
|
|
interface PortfolioGridChildProps {
|
|
|
|
children: ReactNode;
|
|
|
|
}
|
|
|
|
|
2022-08-31 04:35:46 +00:00
|
|
|
const PortfolioGridChild = ({ children }: PortfolioGridChildProps) => {
|
|
|
|
return (
|
|
|
|
<section className="bg-white dark:bg-black w-full h-full">
|
|
|
|
{children}
|
|
|
|
</section>
|
|
|
|
);
|
2022-06-30 07:52:25 +00:00
|
|
|
};
|