Skip to content

Commit

Permalink
Refactor: Trade size bug (#1154)
Browse files Browse the repository at this point in the history
* check for divide by zero

* fixed height on balance

* remove fixed height

* fix account bug
  • Loading branch information
Tburm authored Jul 21, 2022
1 parent fdc1a73 commit 7132127
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion constants/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ export const QUERY_KEYS = {
market,
walletAddress,
],
MarketsPositions: (markets: string[] | []) => ['futures', 'marketsPositions', markets],
MarketsPositions: (
networkId: NetworkId,
walletAddress: string | null,
markets: string[] | []
) => ['futures', 'marketsPositions', networkId, walletAddress, markets],
Positions: (networkId: NetworkId, markets: string[] | [], walletAddress: string) => [
'futures',
'positions',
Expand Down
2 changes: 1 addition & 1 deletion queries/futures/useGetFuturesPositionForMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useGetFuturesPositionForMarkets = (
const assets = futuresMarkets?.map(({ asset }) => asset) ?? [];

return useQuery<FuturesPosition[] | []>(
QUERY_KEYS.Futures.MarketsPositions(assets || []),
QUERY_KEYS.Futures.MarketsPositions(network.id, walletAddress, assets || []),
async () => {
if (!markets || (walletAddress && !isL2)) {
return [];
Expand Down
3 changes: 2 additions & 1 deletion sections/futures/PositionCard/PositionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ const PositionCard: React.FC<PositionCardProps> = ({ currencyKeyRate, mobile })
const existingValue = positionHistory.avgEntryPrice.mul(positionHistory.size);
const newValue = previewTradeData.price.mul(potentialTrade.size);
const totalValue = existingValue.add(newValue);
return totalValue.div(totalSize);

return totalSize.gt(0) ? totalValue.div(totalSize) : null;
}
return null;
}, [positionHistory, previewTradeData, potentialTrade]);
Expand Down

0 comments on commit 7132127

Please sign in to comment.