* frontend-monorepo-1263 validator status of pending now named 'candidate' in the ui * feat(1263): validator table updates, calculating penalties * feat(1263): bit of cleanup * feat(1263): tables built and values derived * feat(1263): tweaks * feat(1263): upping site max width to 1500px * feat(1263): tweak to normalised voting power column width * feat(1263): ensure validator rows when hovered have cursor:pointer * feat(1263): consensus validators now have a ranking field by voting power shown in the table * feat(1263): fixed linting errors * feat(1263): a couple of extra tests and correct import of schema to use enums * Update apps/token/src/routes/staking/home/validator-tables/standby-pending-validators-table.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * Update apps/token/src/routes/staking/home/validator-tables/validator-tables.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * Update apps/token/src/routes/staking/home/validator-tables/validator-tables.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * Update apps/token/src/routes/staking/home/validator-tables/validator-tables.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * feat(1263): tweaks from PR comments, initial push of util to remove 'node' from arrs * feat(1263): updated new util to remove 'node' from 'edges'. Implemented across the monorepo * feat(1263): cleaned up splitting validators into consensus, pending and ersatz to put into tables * feat(1263): used decimals from app state in validator-tables.tsx * feat(1263): removed redundant compact import Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { BigNumber } from 'bignumber.js';
|
|
import { useMarketPositionsQuery } from './__generated__/MarketPositions';
|
|
import { removePaginationWrapper } from '@vegaprotocol/react-helpers';
|
|
interface Props {
|
|
marketId: string;
|
|
partyId: string;
|
|
}
|
|
|
|
export type PositionMargin = {
|
|
openVolume: BigNumber;
|
|
balance: BigNumber;
|
|
balanceDecimals?: number;
|
|
} | null;
|
|
|
|
export const useMarketPositions = ({
|
|
marketId,
|
|
partyId,
|
|
}: Props): PositionMargin => {
|
|
const { data } = useMarketPositionsQuery({
|
|
pollInterval: 5000,
|
|
variables: { partyId },
|
|
fetchPolicy: 'no-cache',
|
|
});
|
|
|
|
const accounts = removePaginationWrapper(
|
|
data?.party?.accountsConnection?.edges
|
|
);
|
|
const account = accounts.find((nodes) => nodes.market?.id === marketId);
|
|
|
|
if (account) {
|
|
const positionConnectionNode =
|
|
data?.party?.positionsConnection?.edges?.find(
|
|
(nodes) => nodes.node.market.id === marketId
|
|
);
|
|
const balance = new BigNumber(account.balance || 0);
|
|
const openVolume = new BigNumber(
|
|
positionConnectionNode?.node.openVolume || 0
|
|
);
|
|
if (!balance.isZero() && !openVolume.isZero()) {
|
|
return {
|
|
balance,
|
|
balanceDecimals: account?.asset.decimals,
|
|
openVolume,
|
|
};
|
|
}
|
|
}
|
|
return null;
|
|
};
|