Skip to content

Commit

Permalink
Fix pnl for parallel network
Browse files Browse the repository at this point in the history
  • Loading branch information
samchuk-vlad committed Feb 12, 2024
1 parent f53602f commit efbcf02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/table/balancesTable/utils/ActionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const ActionPanel = ({
)

return !isEmptyArray(balances.filter(isDef))
}, [JSON.stringify(balancesFromStore || {})])
}, [ JSON.stringify(balancesFromStore || {}) ])

const totalBalance = loading ? (
<Tooltip
Expand Down Expand Up @@ -189,7 +189,7 @@ const MobileButtons = (props: CommonProps) => {
<Dropdown
overlay={<DrowdownOverlay {...props} />}
placement='bottomLeft'
trigger={['click']}
trigger={[ 'click' ]}
>
<Button shape='circle'>
<SwitchIcon />
Expand Down
14 changes: 8 additions & 6 deletions src/components/table/balancesTable/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { BIGNUMBER_ZERO } from 'src/config/app/consts'
import Image from 'next/image'
import styles from './Index.module.sass'
import clsx from 'clsx'
import {
LineChartOutlined,
MenuOutlined,
} from '@ant-design/icons'
import { LineChartOutlined, MenuOutlined } from '@ant-design/icons'
import TokenCentricIcon from '@/assets/icons/token-centric.svg'
import ChainCentricIcon from '@/assets/icons/chain-centric.svg'
import store from 'store'
Expand Down Expand Up @@ -246,6 +243,8 @@ export const calculatePnlInTokens = ({

const { current_price, price_change_percentage_24h } = priceData

if (!price_change_percentage_24h) return

const priceChange24h = new BN(price_change_percentage_24h)

const price24hAgo = new BN(current_price).dividedBy(
Expand All @@ -257,7 +256,7 @@ export const calculatePnlInTokens = ({

const pnl = currentBalance.minus(balance24hAgo)

if (pnl.isZero()) return null
if (pnl.isZero()) return

return { pnlBN: pnl, pnlString: pnl.abs().toFixed(4) }
}
Expand Down Expand Up @@ -318,9 +317,12 @@ export const PriceChangedOn = ({ symbol, className }: PriceChangesProps) => {
if (!priceData) return null

const { price_change_percentage_24h } = priceData

if (!price_change_percentage_24h) return null

const priceChange24h = new BN(price_change_percentage_24h)

const priceChange24hString = priceChange24h.abs().toFixed(4)
const priceChange24hString = priceChange24h.abs().toFixed(2)

const sign = priceChange24h.isPositive() ? '+' : '-'

Expand Down
8 changes: 4 additions & 4 deletions src/components/table/customTable/TableContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ export const TableContextWrapper: React.FC<TableContextProps> = ({
const showZeroBalancesFromStorage = store.get(storeShowZeroBalance)
const tableVariantFromStore = store.get(BALANCE_TABLE_VARIANT)

const [tableView, setTableView] = useState<TableView>(
const [ tableView, setTableView ] = useState<TableView>(
!tableViewFromStorage || tableViewFromStorage === 'cards'
? 'table'
: tableViewFromStorage
)
const [showZeroBalances, setShowZeroBalances] = useState<boolean>(
const [ showZeroBalances, setShowZeroBalances ] = useState<boolean>(
showZeroBalancesFromStorage !== undefined
? showZeroBalancesFromStorage
: true
)

const [balancesVariant, setBalancesVariant] = useState<BalanceVariant>(
const [ balancesVariant, setBalancesVariant ] = useState<BalanceVariant>(
tableVariantFromStore || 'chains'
)

useEffect(() => {
if (!tableViewFromStorage || tableViewFromStorage === 'cards') {
store.set(storeTableView, 'table')
}
}, [tableViewFromStorage])
}, [ tableViewFromStorage ])

const value = {
tableView,
Expand Down

0 comments on commit efbcf02

Please sign in to comment.