rename positions table; fix rounding issues

This commit is contained in:
Tyler Shipe 2021-08-15 13:06:52 -04:00
parent b9fee21da7
commit 9c1f8edf20
6 changed files with 39 additions and 23 deletions

View File

@ -5,7 +5,7 @@ import { notify } from '../utils/notifications'
import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table' import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table'
import { InformationCircleIcon } from '@heroicons/react/outline' import { InformationCircleIcon } from '@heroicons/react/outline'
import Tooltip from './Tooltip' import Tooltip from './Tooltip'
import { sleep } from '../utils' import { floorToDecimal, sleep } from '../utils'
import { Market } from '@project-serum/serum' import { Market } from '@project-serum/serum'
import { import {
getTokenBySymbol, getTokenBySymbol,
@ -159,7 +159,8 @@ const BalancesTable = () => {
className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`} className={`px-6 py-3 whitespace-nowrap text-sm text-th-fgd-1`}
> >
{+balance.marginDeposits > 0 {+balance.marginDeposits > 0
? balance.marginDeposits.toFixed( ? floorToDecimal(
balance.marginDeposits.toNumber(),
tokenConfig.decimals tokenConfig.decimals
) )
: 0} : 0}

View File

@ -2,7 +2,12 @@ import { useCallback, useMemo, useState } from 'react'
import FloatingElement from './FloatingElement' import FloatingElement from './FloatingElement'
import { ElementTitle } from './styles' import { ElementTitle } from './styles'
import useMangoStore, { mangoClient } from '../stores/useMangoStore' import useMangoStore, { mangoClient } from '../stores/useMangoStore'
import { i80f48ToPercent, tokenPrecision, formatUsdValue } from '../utils/index' import {
ceilToDecimal,
floorToDecimal,
i80f48ToPercent,
formatUsdValue,
} from '../utils/index'
import DepositModal from './DepositModal' import DepositModal from './DepositModal'
import WithdrawModal from './WithdrawModal' import WithdrawModal from './WithdrawModal'
import Button from './Button' import Button from './Button'
@ -17,7 +22,7 @@ import {
ZERO_BN, ZERO_BN,
} from '@blockworks-foundation/mango-client' } from '@blockworks-foundation/mango-client'
import useTradeHistory from '../hooks/useTradeHistory' import useTradeHistory from '../hooks/useTradeHistory'
import { getAvgEntryPrice, getBreakEvenPrice } from './PositionsTable' import { getAvgEntryPrice, getBreakEvenPrice } from './PerpPositionsTable'
import { notify } from '../utils/notifications' import { notify } from '../utils/notifications'
const handleSettlePnl = async ( const handleSettlePnl = async (
@ -225,14 +230,19 @@ export default function MarketPosition() {
</div> </div>
<div className={`text-th-fgd-1`}> <div className={`text-th-fgd-1`}>
{mangoAccount {mangoAccount
? mangoAccount ? floorToDecimal(
.getUiDeposit( mangoAccount
mangoGroupCache.rootBankCache[tokenIndex], .getUiDeposit(
mangoGroup, mangoGroupCache.rootBankCache[tokenIndex],
tokenIndex mangoGroup,
) tokenIndex
.toFixed(tokenPrecision[symbol]) )
: (0).toFixed(tokenPrecision[symbol])} .toNumber(),
mangoGroup.tokens[tokenIndex].decimals
)
: (0).toFixed(
mangoGroup.tokens[tokenIndex].decimals
)}
</div> </div>
</div> </div>
<div className="pb-3"> <div className="pb-3">
@ -241,14 +251,19 @@ export default function MarketPosition() {
</div> </div>
<div className={`text-th-fgd-1`}> <div className={`text-th-fgd-1`}>
{mangoAccount {mangoAccount
? mangoAccount ? ceilToDecimal(
.getUiBorrow( mangoAccount
mangoGroupCache.rootBankCache[tokenIndex], .getUiBorrow(
mangoGroup, mangoGroupCache.rootBankCache[tokenIndex],
tokenIndex mangoGroup,
) tokenIndex
.toFixed(tokenPrecision[symbol]) )
: (0).toFixed(tokenPrecision[symbol])} .toNumber(),
mangoGroup.tokens[tokenIndex].decimals
)
: (0).toFixed(
mangoGroup.tokens[tokenIndex].decimals
)}
</div> </div>
</div> </div>
<div> <div>

View File

@ -239,7 +239,7 @@ const TradeHistoryTable = () => {
</div> </div>
) : ( ) : (
<div className="w-full text-center py-6 bg-th-bkg-1 text-th-fgd-3 rounded-md"> <div className="w-full text-center py-6 bg-th-bkg-1 text-th-fgd-3 rounded-md">
No {marketConfig.name} trade history No trade history
{asPath === '/account' ? ( {asPath === '/account' ? (
<Link href={'/'}> <Link href={'/'}>
<a className="inline-flex ml-2 py-0">Make a trade</a> <a className="inline-flex ml-2 py-0">Make a trade</a>

View File

@ -2,7 +2,7 @@ import { useState } from 'react'
import FloatingElement from './FloatingElement' import FloatingElement from './FloatingElement'
import OpenOrdersTable from './OpenOrdersTable' import OpenOrdersTable from './OpenOrdersTable'
import BalancesTable from './BalancesTable' import BalancesTable from './BalancesTable'
import PositionsTable from './PositionsTable' import PositionsTable from './PerpPositionsTable'
import TradeHistoryTable from './TradeHistoryTable' import TradeHistoryTable from './TradeHistoryTable'
// import { Position } from '../public/charting_library/charting_library' // import { Position } from '../public/charting_library/charting_library'
// import FeeDiscountsTable from './FeeDiscountsTable' // import FeeDiscountsTable from './FeeDiscountsTable'

View File

@ -32,7 +32,7 @@ import { Market } from '@project-serum/serum'
import SideBadge from '../SideBadge' import SideBadge from '../SideBadge'
import Button, { LinkButton } from '../Button' import Button, { LinkButton } from '../Button'
import Switch from '../Switch' import Switch from '../Switch'
import PositionsTable from '../PositionsTable' import PositionsTable from '../PerpPositionsTable'
import DepositModal from '../DepositModal' import DepositModal from '../DepositModal'
import WithdrawModal from '../WithdrawModal' import WithdrawModal from '../WithdrawModal'