Skip to content

Commit

Permalink
chore: hide diff state for account available balance when its negative (
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka authored Aug 13, 2024
1 parent 8e446a9 commit 5ecd0f7
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/views/AccountInfo/AccountInfoConnectedState.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useCallback } from 'react';

import { shallowEqual } from 'react-redux';
import styled, { css } from 'styled-components';

Expand Down Expand Up @@ -63,19 +61,16 @@ export const AccountInfoConnectedState = () => {
const { freeCollateral: availableBalance, marginUsage } = subAccount ?? {};
const portfolioValue = subAccount?.equity;

const hasDiff =
!!availableBalance?.postOrder && getTradeStateWithDoubleValuesHasDiff(availableBalance);
const isPostOrderBalanceNegative =
isNumber(availableBalance?.postOrder) && MustBigNumber(availableBalance?.postOrder).lt(0);

const showHeader = !hasDiff && !isTablet;
// Do not show diff state if there is no postOrder balance or if it is negative
const showDiff =
!!availableBalance?.postOrder &&
getTradeStateWithDoubleValuesHasDiff(availableBalance) &&
!isPostOrderBalanceNegative;

const isPostOrderTradeStateNegative = useCallback(
(tradeStateValue: Nullable<TradeState<number>>) => {
return (
isNumber(tradeStateValue?.postOrder) && MustBigNumber(tradeStateValue?.postOrder).lt(0)
);
},
[]
);
const showHeader = !showDiff && !isTablet;

return (
<$ConnectedAccountInfoContainer $showHeader={showHeader}>
Expand Down Expand Up @@ -143,7 +138,8 @@ export const AccountInfoConnectedState = () => {
},
{
key: AccountInfoItem.AvailableBalance,
hasError: isPostOrderTradeStateNegative(availableBalance),
hasError: isPostOrderBalanceNegative,
hideDiff: isPostOrderBalanceNegative,
isPositive: MustBigNumber(availableBalance?.postOrder).gt(
MustBigNumber(availableBalance?.current)
),
Expand Down

0 comments on commit 5ecd0f7

Please sign in to comment.