Skip to content

Commit

Permalink
fix trade history value
Browse files Browse the repository at this point in the history
  • Loading branch information
saml33 committed Oct 11, 2024
1 parent d6b25e0 commit ba435c7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
13 changes: 10 additions & 3 deletions components/account/ActivityFeedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ export const getValue = (activity: any, mangoAccountAddress: string) => {
value = isTaker ? notional + fee : notional - fee
}
if (activity_type === 'openbook_trade') {
const { price, size } = activity.activity_details
value = price * size
const { price, side, size } = activity.activity_details
const flip = side === 'sell' ? -1 : 1
value = price * size * flip
}
if (activity_type === 'loan_origination_fee') {
const { price, fee } = activity.activity_details
Expand Down Expand Up @@ -534,7 +535,13 @@ const SharedTableBody = ({
{value > 0 && activity_type !== 'swap' && !isOpenbook && !isExpandable
? '+'
: ''}
<FormatNumericValue value={value} isUsd />
<FormatNumericValue
value={value}
isUsd={fee.symbol === 'USDC' || !isOpenbook}
/>
{isOpenbook && fee.symbol !== 'USDC' ? (
<span className="font-body text-th-fgd-3"> {fee.symbol}</span>
) : null}
</Td>
</>
)
Expand Down
8 changes: 7 additions & 1 deletion components/account/SpotTradeActivityDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ const SpotTradeActivityDetails = ({
<div className="col-span-1">
<p className="mb-0.5 font-body text-sm text-th-fgd-3">{t('value')}</p>
<p className="font-mono text-th-fgd-1">
<FormatNumericValue value={notional} isUsd />
<FormatNumericValue
value={notional}
isUsd={quote_symbol === 'USDC'}
/>
{quote_symbol !== 'USDC' ? (
<span className="font-body text-th-fgd-3"> {quote_symbol}</span>
) : null}
</p>
</div>
<div className="col-span-1">
Expand Down
32 changes: 29 additions & 3 deletions components/trade/TradeHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
} from '@heroicons/react/20/solid'
import { useWallet } from '@solana/wallet-adapter-react'
import { PublicKey } from '@solana/web3.js'
import mangoStore from '@store/mangoStore'
import dayjs from 'dayjs'
import useMangoAccount from 'hooks/useMangoAccount'
import useSelectedMarket from 'hooks/useSelectedMarket'
Expand All @@ -37,10 +36,11 @@ import TableMarketName from './TableMarketName'
import { useSortableData } from 'hooks/useSortableData'
import { useCallback } from 'react'
import { useHiddenMangoAccounts } from 'hooks/useHiddenMangoAccounts'
import useMangoGroup from 'hooks/useMangoGroup'

const TradeHistory = ({ filterForMarket }: { filterForMarket?: boolean }) => {
const { t } = useTranslation(['common', 'trade'])
const group = mangoStore.getState().group
const { group } = useMangoGroup()
const { selectedMarket } = useSelectedMarket()
const { mangoAccountAddress } = useMangoAccount()
const {
Expand All @@ -58,12 +58,23 @@ const TradeHistory = ({ filterForMarket }: { filterForMarket?: boolean }) => {
for (const trade of combinedTradeHistory) {
const marketName = trade.market.name
const value = trade.price * trade.size
// if (
// trade.market instanceof Serum3Market &&
// trade.market.quoteTokenIndex
// ) {
// const quotePrice = group?.getFirstBankByTokenIndex(
// trade.market.quoteTokenIndex,
// )?.uiPrice
// value = quotePrice ? value * quotePrice : 0
// }
const sortTime = trade?.time
? trade.time
: dayjs().format('YYYY-MM-DDTHH:mm:ss')

const data = { ...trade, marketName, value, sortTime }
formatted.push(data)
}

if (!filterForMarket) {
return formatted
} else {
Expand Down Expand Up @@ -154,6 +165,11 @@ const TradeHistory = ({ filterForMarket }: { filterForMarket?: boolean }) => {
const { side, price, market, size, feeCost, liquidity, value } =
trade

let quoteSymbol
if ('quote_symbol' in trade) {
quoteSymbol = trade.quote_symbol
}

let counterpartyAddress = ''
if ('taker' in trade) {
counterpartyAddress =
Expand Down Expand Up @@ -183,7 +199,17 @@ const TradeHistory = ({ filterForMarket }: { filterForMarket?: boolean }) => {
<p>{price}</p>
</Td>
<Td className="text-right font-mono">
<FormatNumericValue value={value} decimals={2} isUsd />
<FormatNumericValue
value={value}
decimals={2}
isUsd={!quoteSymbol || quoteSymbol === 'USDC'}
/>
{quoteSymbol && quoteSymbol !== 'USDC' ? (
<span className="font-body text-th-fgd-3">
{' '}
{quoteSymbol}
</span>
) : null}
</Td>
<Td className="text-right">
<span className="font-mono">
Expand Down

0 comments on commit ba435c7

Please sign in to comment.