parent
ce62342d9a
commit
7c0bed2f14
@ -83,13 +83,7 @@ export const getMetrics = (
|
|||||||
const marginAccount = accounts?.find((account) => {
|
const marginAccount = accounts?.find((account) => {
|
||||||
return account.market?.id === market?.id;
|
return account.market?.id === market?.id;
|
||||||
});
|
});
|
||||||
if (
|
if (!marginAccount || !marginLevel || !market || !marketData) {
|
||||||
!marginAccount ||
|
|
||||||
!marginLevel ||
|
|
||||||
!market ||
|
|
||||||
!marketData ||
|
|
||||||
position.openVolume === '0'
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const generalAccount = accounts?.find(
|
const generalAccount = accounts?.find(
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
import { useRef, memo } from 'react';
|
|
||||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
|
||||||
import { t } from '@vegaprotocol/react-helpers';
|
|
||||||
import type { AgGridReact } from 'ag-grid-react';
|
|
||||||
import PositionsTable from './positions-table';
|
|
||||||
import type { Position } from './positions-data-providers';
|
|
||||||
import { AssetBalance } from '@vegaprotocol/accounts';
|
|
||||||
import { usePositionsData } from './use-positions-data';
|
|
||||||
|
|
||||||
interface PositionsProps {
|
|
||||||
partyId: string;
|
|
||||||
assetSymbol: string;
|
|
||||||
onClose: (position: Position) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Positions = memo(
|
|
||||||
({ partyId, assetSymbol, onClose }: PositionsProps) => {
|
|
||||||
const gridRef = useRef<AgGridReact | null>(null);
|
|
||||||
const { data, error, loading, getRows } = usePositionsData(
|
|
||||||
partyId,
|
|
||||||
gridRef,
|
|
||||||
assetSymbol
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AsyncRenderer loading={loading} error={error} data={data}>
|
|
||||||
<div className="flex justify-between items-center px-4 pt-3 pb-1">
|
|
||||||
<h4>
|
|
||||||
{assetSymbol} {t('markets')}
|
|
||||||
</h4>
|
|
||||||
<div className="text-sm text-neutral-500 dark:text-neutral-300">
|
|
||||||
{assetSymbol} {t('balance')}:
|
|
||||||
<span data-testid="balance" className="pl-1 font-mono">
|
|
||||||
<AssetBalance partyId={partyId} assetSymbol={assetSymbol} />
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<PositionsTable
|
|
||||||
domLayout="autoHeight"
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
ref={gridRef}
|
|
||||||
rowModelType={data?.length ? 'infinite' : 'clientSide'}
|
|
||||||
rowData={data?.length ? undefined : []}
|
|
||||||
datasource={{ getRows }}
|
|
||||||
onClose={onClose}
|
|
||||||
/>
|
|
||||||
</AsyncRenderer>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
@ -43,11 +43,16 @@ export const usePositionsData = (
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (update.length || add.length) {
|
if (update.length || add.length) {
|
||||||
gridRef.current.api.applyTransactionAsync({
|
const rowDataTransaction = {
|
||||||
update,
|
update,
|
||||||
add,
|
add,
|
||||||
addIndex: 0,
|
addIndex: 0,
|
||||||
});
|
};
|
||||||
|
if (add.length) {
|
||||||
|
gridRef.current.api.applyTransaction(rowDataTransaction);
|
||||||
|
} else {
|
||||||
|
gridRef.current.api.applyTransactionAsync(rowDataTransaction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
@ -646,7 +646,7 @@ function makeDerivedDataProviderInternal<
|
|||||||
const updatedPart = parts[updatedPartIndex];
|
const updatedPart = parts[updatedPartIndex];
|
||||||
if (updatedPart.isUpdate) {
|
if (updatedPart.isUpdate) {
|
||||||
isUpdate = true;
|
isUpdate = true;
|
||||||
if (updatedPart.delta && combineDelta && data) {
|
if (combineDelta && data) {
|
||||||
delta = combineDelta(data, parts, previousData, variables);
|
delta = combineDelta(data, parts, previousData, variables);
|
||||||
}
|
}
|
||||||
delete updatedPart.isUpdate;
|
delete updatedPart.isUpdate;
|
||||||
|
@ -4,17 +4,11 @@ export interface SummaryRow {
|
|||||||
__summaryRow?: boolean;
|
__summaryRow?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addSummaryRows<T>(
|
export function addSummaryRows<T extends SummaryRow>(
|
||||||
api: GridApi,
|
api: GridApi,
|
||||||
columnApi: ColumnApi,
|
columnApi: ColumnApi,
|
||||||
getGroupId: (
|
getGroupId: (data: T, columnApi: ColumnApi) => string | null | undefined,
|
||||||
data: T & SummaryRow,
|
getGroupSummaryRow: (data: T[], columnApi: ColumnApi) => Partial<T> | null
|
||||||
columnApi: ColumnApi
|
|
||||||
) => string | null | undefined,
|
|
||||||
getGroupSummaryRow: (
|
|
||||||
data: (T & SummaryRow)[],
|
|
||||||
columnApi: ColumnApi
|
|
||||||
) => Partial<T & SummaryRow> | null
|
|
||||||
) {
|
) {
|
||||||
let currentGroupId: string | null | undefined = undefined;
|
let currentGroupId: string | null | undefined = undefined;
|
||||||
let group: T[] = [];
|
let group: T[] = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user