2022-11-16 14:10:17 +00:00
|
|
|
import { useCallback } from 'react';
|
2022-10-12 10:49:13 +00:00
|
|
|
import { Button } from '@vegaprotocol/ui-toolkit';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
2022-11-16 14:10:17 +00:00
|
|
|
import { useWithdrawalDialog } from '@vegaprotocol/withdraws';
|
2022-09-30 00:40:44 +00:00
|
|
|
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
|
|
|
|
import { Splash } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import { useVegaWallet } from '@vegaprotocol/wallet';
|
2023-02-17 13:32:20 +00:00
|
|
|
import type { PinnedAsset } from '@vegaprotocol/accounts';
|
2023-02-06 19:35:40 +00:00
|
|
|
import { AccountManager, useTransferDialog } from '@vegaprotocol/accounts';
|
2022-11-16 14:10:17 +00:00
|
|
|
import { useDepositDialog } from '@vegaprotocol/deposits';
|
2022-09-30 00:40:44 +00:00
|
|
|
|
2023-02-17 13:32:20 +00:00
|
|
|
export const AccountsContainer = ({
|
|
|
|
pinnedAsset,
|
2023-03-09 23:52:38 +00:00
|
|
|
hideButtons,
|
2023-05-09 06:09:53 +00:00
|
|
|
storeKey,
|
2023-06-16 10:28:59 +00:00
|
|
|
onMarketClick,
|
2023-02-17 13:32:20 +00:00
|
|
|
}: {
|
|
|
|
pinnedAsset?: PinnedAsset;
|
2023-03-09 23:52:38 +00:00
|
|
|
hideButtons?: boolean;
|
2023-05-09 06:09:53 +00:00
|
|
|
storeKey?: string;
|
2023-06-16 10:28:59 +00:00
|
|
|
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
2023-02-17 13:32:20 +00:00
|
|
|
}) => {
|
2023-01-31 16:04:52 +00:00
|
|
|
const { pubKey, isReadOnly } = useVegaWallet();
|
2022-10-17 18:57:13 +00:00
|
|
|
const { open: openAssetDetailsDialog } = useAssetDetailsDialogStore();
|
2022-11-16 14:10:17 +00:00
|
|
|
const openWithdrawalDialog = useWithdrawalDialog((store) => store.open);
|
|
|
|
const openDepositDialog = useDepositDialog((store) => store.open);
|
2023-02-06 19:35:40 +00:00
|
|
|
const openTransferDialog = useTransferDialog((store) => store.open);
|
2022-09-30 00:40:44 +00:00
|
|
|
|
2022-11-07 12:14:21 +00:00
|
|
|
const onClickAsset = useCallback(
|
2022-11-23 23:42:22 +00:00
|
|
|
(assetId?: string) => {
|
|
|
|
assetId && openAssetDetailsDialog(assetId);
|
2022-11-07 12:14:21 +00:00
|
|
|
},
|
|
|
|
[openAssetDetailsDialog]
|
|
|
|
);
|
|
|
|
|
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 (
|
2023-03-08 14:58:40 +00:00
|
|
|
<div className="h-full relative">
|
|
|
|
<AccountManager
|
|
|
|
partyId={pubKey}
|
|
|
|
onClickAsset={onClickAsset}
|
|
|
|
onClickWithdraw={openWithdrawalDialog}
|
|
|
|
onClickDeposit={openDepositDialog}
|
2023-06-16 10:28:59 +00:00
|
|
|
onMarketClick={onMarketClick}
|
2023-03-08 14:58:40 +00:00
|
|
|
isReadOnly={isReadOnly}
|
|
|
|
pinnedAsset={pinnedAsset}
|
2023-05-09 06:09:53 +00:00
|
|
|
storeKey={storeKey}
|
2023-03-08 14:58:40 +00:00
|
|
|
/>
|
|
|
|
{!isReadOnly && !hideButtons && (
|
2023-03-09 23:52:38 +00:00
|
|
|
<div className="flex gap-2 justify-end p-2 px-[11px] absolute lg:fixed bottom-0 right-3 dark:bg-black/75 bg-white/75 rounded">
|
2023-02-08 17:31:41 +00:00
|
|
|
<Button
|
2023-03-08 14:58:40 +00:00
|
|
|
variant="primary"
|
2023-02-08 17:31:41 +00:00
|
|
|
size="sm"
|
|
|
|
data-testid="open-transfer-dialog"
|
|
|
|
onClick={() => openTransferDialog()}
|
|
|
|
>
|
2023-02-06 19:35:40 +00:00
|
|
|
{t('Transfer')}
|
|
|
|
</Button>
|
2023-03-08 14:58:40 +00:00
|
|
|
<Button
|
|
|
|
variant="primary"
|
|
|
|
size="sm"
|
|
|
|
onClick={() => openDepositDialog()}
|
|
|
|
>
|
2023-01-31 16:04:52 +00:00
|
|
|
{t('Deposit')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-11-16 14:10:17 +00:00
|
|
|
</div>
|
2022-09-30 00:40:44 +00:00
|
|
|
);
|
|
|
|
};
|