2023-02-13 14:48:44 +00:00
|
|
|
import { t, useDataProvider } from '@vegaprotocol/react-helpers';
|
2022-04-06 17:48:05 +00:00
|
|
|
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import type { AgGridReact } from 'ag-grid-react';
|
2023-02-13 14:48:44 +00:00
|
|
|
import { useRef, useMemo, memo } from 'react';
|
2022-09-30 00:40:44 +00:00
|
|
|
import type { AccountFields } from './accounts-data-provider';
|
|
|
|
import { aggregatedAccountsDataProvider } from './accounts-data-provider';
|
|
|
|
import { AccountTable } from './accounts-table';
|
2022-04-06 17:48:05 +00:00
|
|
|
|
2022-09-30 00:40:44 +00:00
|
|
|
interface AccountManagerProps {
|
2022-04-06 17:48:05 +00:00
|
|
|
partyId: string;
|
2022-11-23 23:42:22 +00:00
|
|
|
onClickAsset: (assetId: string) => void;
|
2022-09-30 00:40:44 +00:00
|
|
|
onClickWithdraw?: (assetId?: string) => void;
|
|
|
|
onClickDeposit?: (assetId?: string) => void;
|
2023-01-31 16:04:52 +00:00
|
|
|
isReadOnly: boolean;
|
2022-04-06 17:48:05 +00:00
|
|
|
}
|
|
|
|
|
2022-12-02 12:32:54 +00:00
|
|
|
export const AccountManager = ({
|
|
|
|
onClickAsset,
|
|
|
|
onClickWithdraw,
|
|
|
|
onClickDeposit,
|
|
|
|
partyId,
|
2023-01-31 16:04:52 +00:00
|
|
|
isReadOnly,
|
2022-12-02 12:32:54 +00:00
|
|
|
}: AccountManagerProps) => {
|
|
|
|
const gridRef = useRef<AgGridReact | null>(null);
|
|
|
|
const variables = useMemo(() => ({ partyId }), [partyId]);
|
2022-10-18 10:40:26 +00:00
|
|
|
|
2023-02-16 16:30:32 +00:00
|
|
|
const { data, loading, error, reload } = useDataProvider<
|
|
|
|
AccountFields[],
|
|
|
|
never
|
|
|
|
>({
|
2022-12-02 12:32:54 +00:00
|
|
|
dataProvider: aggregatedAccountsDataProvider,
|
|
|
|
variables,
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<div className="relative h-full">
|
|
|
|
<AccountTable
|
|
|
|
ref={gridRef}
|
2023-02-16 16:30:32 +00:00
|
|
|
rowData={error ? [] : data}
|
2022-12-02 12:32:54 +00:00
|
|
|
onClickAsset={onClickAsset}
|
|
|
|
onClickDeposit={onClickDeposit}
|
|
|
|
onClickWithdraw={onClickWithdraw}
|
2023-01-31 16:04:52 +00:00
|
|
|
isReadOnly={isReadOnly}
|
2023-02-13 14:48:44 +00:00
|
|
|
noRowsOverlayComponent={() => null}
|
2022-12-02 12:32:54 +00:00
|
|
|
/>
|
2023-01-11 14:43:52 +00:00
|
|
|
<div className="pointer-events-none absolute inset-0">
|
2022-12-02 12:32:54 +00:00
|
|
|
<AsyncRenderer
|
2023-01-11 14:43:52 +00:00
|
|
|
data={data}
|
|
|
|
noDataCondition={(data) => !(data && data.length)}
|
2022-12-02 12:32:54 +00:00
|
|
|
error={error}
|
|
|
|
loading={loading}
|
|
|
|
noDataMessage={t('No accounts')}
|
2023-02-16 16:30:32 +00:00
|
|
|
reload={reload}
|
2022-11-07 12:14:21 +00:00
|
|
|
/>
|
2022-12-02 12:32:54 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2022-09-30 00:40:44 +00:00
|
|
|
|
2022-11-07 12:14:21 +00:00
|
|
|
export default memo(AccountManager);
|