2022-11-07 12:14:21 +00:00
|
|
|
import { useCallback, useState } from 'react';
|
2022-10-12 10:49:13 +00:00
|
|
|
import { Button } from '@vegaprotocol/ui-toolkit';
|
2022-09-30 00:40:44 +00:00
|
|
|
import { t } from '@vegaprotocol/react-helpers';
|
|
|
|
import { WithdrawalDialogs } from '@vegaprotocol/withdraws';
|
|
|
|
import { Web3Container } from '@vegaprotocol/web3';
|
2022-11-07 12:14:21 +00:00
|
|
|
import type { AssetFieldsFragment } from '@vegaprotocol/assets';
|
2022-09-30 00:40:44 +00:00
|
|
|
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
|
|
|
|
import { Splash } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import { useVegaWallet } from '@vegaprotocol/wallet';
|
|
|
|
import { AccountManager } from '@vegaprotocol/accounts';
|
2022-11-04 10:47:53 +00:00
|
|
|
import { DepositDialog } from '@vegaprotocol/deposits';
|
2022-09-30 00:40:44 +00:00
|
|
|
|
|
|
|
export const AccountsContainer = () => {
|
2022-10-03 18:12:34 +00:00
|
|
|
const { pubKey } = useVegaWallet();
|
2022-10-17 18:57:13 +00:00
|
|
|
const [withdrawDialog, setWithdrawDialog] = useState(false);
|
2022-09-30 00:40:44 +00:00
|
|
|
const [depositDialog, setDepositDialog] = useState(false);
|
2022-10-17 18:57:13 +00:00
|
|
|
const { open: openAssetDetailsDialog } = useAssetDetailsDialogStore();
|
|
|
|
const [assetId, setAssetId] = useState<string>();
|
2022-09-30 00:40:44 +00:00
|
|
|
|
2022-11-07 12:14:21 +00:00
|
|
|
const onClickAsset = useCallback(
|
|
|
|
(value?: string | AssetFieldsFragment) => {
|
|
|
|
value && openAssetDetailsDialog(value);
|
|
|
|
},
|
|
|
|
[openAssetDetailsDialog]
|
|
|
|
);
|
|
|
|
|
|
|
|
const onClickWithdraw = useCallback((assetId?: string) => {
|
|
|
|
setWithdrawDialog(true);
|
|
|
|
setAssetId(assetId);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const onClickDeposit = useCallback((assetId?: string) => {
|
|
|
|
setDepositDialog(true);
|
|
|
|
setAssetId(assetId);
|
|
|
|
}, []);
|
|
|
|
|
2022-10-03 18:12:34 +00:00
|
|
|
if (!pubKey) {
|
2022-09-30 00:40:44 +00:00
|
|
|
return (
|
|
|
|
<Splash>
|
|
|
|
<p>{t('Please connect Vega wallet')}</p>
|
|
|
|
</Splash>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Web3Container>
|
2022-10-12 10:49:13 +00:00
|
|
|
<div className="h-full relative grid grid-rows-[1fr,min-content]">
|
2022-10-17 18:57:13 +00:00
|
|
|
<div>
|
|
|
|
<AccountManager
|
|
|
|
partyId={pubKey}
|
2022-11-07 12:14:21 +00:00
|
|
|
onClickAsset={onClickAsset}
|
|
|
|
onClickWithdraw={onClickWithdraw}
|
|
|
|
onClickDeposit={onClickDeposit}
|
2022-10-17 18:57:13 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="flex justify-end p-2 px-[11px]">
|
|
|
|
<Button
|
|
|
|
size="sm"
|
|
|
|
onClick={() => {
|
|
|
|
setAssetId(undefined);
|
|
|
|
setDepositDialog(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('Deposit')}
|
2022-10-12 10:49:13 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
2022-09-30 00:40:44 +00:00
|
|
|
</div>
|
|
|
|
<WithdrawalDialogs
|
|
|
|
assetId={assetId}
|
|
|
|
withdrawDialog={withdrawDialog}
|
|
|
|
setWithdrawDialog={setWithdrawDialog}
|
|
|
|
/>
|
|
|
|
<DepositDialog
|
|
|
|
assetId={assetId}
|
|
|
|
depositDialog={depositDialog}
|
|
|
|
setDepositDialog={setDepositDialog}
|
|
|
|
/>
|
2022-10-17 18:57:13 +00:00
|
|
|
</Web3Container>
|
2022-09-30 00:40:44 +00:00
|
|
|
);
|
|
|
|
};
|