vega-frontend-monorepo/libs/deposits/src/lib/deposits-table.tsx
botond df8a22a19e
chore: migrate withdrawals lib (#2009)
* chore: cleanup lib types

* chore: migrate withdrawals

* fix: withdrawals query and types

* fix: types

* fix: orders build

* fix: withdraws build

* fix: format

* fix: more build stuff in withdrawal lib

* fix: format

* fix: more withdrawal builds

* fix: format

* fix: orders build again

* fix: remaining build errors

* fix: format

* fix: withdrawal tests

* fix: trick git to pick up file rename?

* fix: rename back to orders

* fix: rename generated file
2022-11-10 14:13:58 +00:00

88 lines
2.5 KiB
TypeScript

import { AgGridColumn } from 'ag-grid-react';
import {
t,
addDecimalsFormatNumber,
getDateTimeFormat,
truncateByChars,
isNumeric,
} from '@vegaprotocol/react-helpers';
import type {
VegaICellRendererParams,
VegaValueFormatterParams,
} from '@vegaprotocol/ui-toolkit';
import { AgGridDynamic as AgGrid, Link } from '@vegaprotocol/ui-toolkit';
import type { DepositFieldsFragment } from './__generated__/Deposit';
import { useEnvironment } from '@vegaprotocol/environment';
import { DepositStatusMapping } from '@vegaprotocol/types';
export interface DepositsTableProps {
deposits: DepositFieldsFragment[];
}
export const DepositsTable = ({ deposits }: DepositsTableProps) => {
const { ETHERSCAN_URL } = useEnvironment();
return (
<AgGrid
rowData={deposits}
overlayNoRowsTemplate={t('No deposits')}
defaultColDef={{ flex: 1, resizable: true }}
style={{ width: '100%', height: '100%' }}
suppressCellFocus={true}
>
<AgGridColumn headerName="Asset" field="asset.symbol" />
<AgGridColumn
headerName="Amount"
field="amount"
valueFormatter={({
value,
data,
}: VegaValueFormatterParams<DepositFieldsFragment, 'amount'>) => {
return isNumeric(value) && data
? addDecimalsFormatNumber(value, data.asset.decimals)
: null;
}}
/>
<AgGridColumn
headerName="Created at"
field="createdTimestamp"
valueFormatter={({
value,
}: VegaValueFormatterParams<
DepositFieldsFragment,
'createdTimestamp'
>) => {
return value ? getDateTimeFormat().format(new Date(value)) : '';
}}
/>
<AgGridColumn
headerName="Status"
field="status"
valueFormatter={({
value,
}: VegaValueFormatterParams<DepositFieldsFragment, 'status'>) => {
return value ? DepositStatusMapping[value] : '';
}}
/>
<AgGridColumn
headerName="Tx hash"
field="txHash"
cellRenderer={({
value,
}: VegaICellRendererParams<DepositFieldsFragment, 'txHash'>) => {
if (!value) return '-';
return (
<Link
title={t('View transaction on Etherscan')}
href={`${ETHERSCAN_URL}/tx/${value}`}
data-testid="etherscan-link"
target="_blank"
>
{truncateByChars(value)}
</Link>
);
}}
/>
</AgGrid>
);
};