diff --git a/components/PositionsTable.tsx b/components/PositionsTable.tsx index 9c040916..dc371781 100644 --- a/components/PositionsTable.tsx +++ b/components/PositionsTable.tsx @@ -35,10 +35,21 @@ const PositionsTable = () => { [mangoGroup] ) const perpAccounts = mangoAccount - ? groupConfig.perpMarkets.map( - (m) => mangoAccount.perpAccounts[m.marketIndex] - ) + ? groupConfig.perpMarkets.map((m) => { + return { + perpAccount: mangoAccount.perpAccounts[m.marketIndex], + marketIndex: m.marketIndex, + } + }) : [] + const filteredPerpAccounts = perpAccounts.filter( + ({ perpAccount }) => + !( + perpAccount.quotePosition.eq(ZERO_I80F48) && + perpAccount.basePosition.eq(new BN(0)) + ) + ) + console.log('perp acc length', filteredPerpAccounts.length) const handleSettlePnl = async ( perpMarket: PerpMarket, @@ -81,7 +92,7 @@ const PositionsTable = () => {
- {perpAccounts.length ? ( + {filteredPerpAccounts.length ? (
@@ -110,94 +121,90 @@ const PositionsTable = () => { - {perpAccounts.map((perpAcc, index) => { - const perpMarketInfo = perpMarkets[index] - const marketConfig = getMarketByPublicKey( - groupConfig, - perpMarketInfo.perpMarket - ) + {filteredPerpAccounts.map( + ({ perpAccount, marketIndex }, index) => { + const perpMarketInfo = perpMarkets[marketIndex] + const marketConfig = getMarketByPublicKey( + groupConfig, + perpMarketInfo.perpMarket + ) - const marketCache = - mangoCache.perpMarketCache[marketConfig.marketIndex] - const price = - mangoCache.priceCache[marketConfig.marketIndex].price - const perpMarket = allMarkets[ - marketConfig.publicKey.toString() - ] as PerpMarket + const marketCache = + mangoCache.perpMarketCache[marketIndex] + const price = mangoCache.priceCache[marketIndex].price + const perpMarket = allMarkets[ + marketConfig.publicKey.toString() + ] as PerpMarket - if ( - perpAcc.quotePosition.eq(ZERO_I80F48) && - perpAcc.basePosition.eq(new BN(0)) - ) { - return null - } - - return ( - - - - - - - - + - - ) - })} + /> + + + + + + + + ) + } + )}
- {marketConfig.name} - - - - {perpMarket.baseLotsToNumber(perpAcc.basePosition)} - - {nativeI80F48ToUi( - perpAcc.quotePosition, - marketConfig.quoteDecimals - ).toFixed()} - - $ - {nativeI80F48ToUi( - perpAcc.getPnl(perpMarketInfo, price), - marketConfig.quoteDecimals - ).toFixed()} - - {perpAcc - .getHealth( - perpMarketInfo, - price, - perpMarketInfo.maintAssetWeight, - perpMarketInfo.maintLiabWeight, - marketCache.longFunding, - marketCache.shortFunding - ) - .toFixed(3)} - -
-
+ {marketConfig.name} + + - {settlingPerpAcc == perpAcc ? ( - - ) : ( - Settle PNL - )} - - -
+ {perpMarket.baseLotsToNumber( + perpAccount.basePosition + )} + + {nativeI80F48ToUi( + perpAccount.quotePosition, + marketConfig.quoteDecimals + ).toFixed()} + + $ + {nativeI80F48ToUi( + perpAccount.getPnl(perpMarketInfo, price), + marketConfig.quoteDecimals + ).toFixed()} + + {perpAccount + .getHealth( + perpMarketInfo, + price, + perpMarketInfo.maintAssetWeight, + perpMarketInfo.maintLiabWeight, + marketCache.longFunding, + marketCache.shortFunding + ) + .toFixed(3)} + +
+ +
+
diff --git a/components/TradeHistoryTable.tsx b/components/TradeHistoryTable.tsx index 54b4e7c4..dec43b9f 100644 --- a/components/TradeHistoryTable.tsx +++ b/components/TradeHistoryTable.tsx @@ -7,15 +7,11 @@ import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table' import SideBadge from './SideBadge' import { LinkButton } from './Button' import { useSortableData } from '../hooks/useSortableData' -import useMangoStore from '../stores/useMangoStore' const TradeHistoryTable = () => { const { asPath } = useRouter() const tradeHistory = useTradeHistory() const { items, requestSort, sortConfig } = useSortableData(tradeHistory) - console.log('trade history items: ', items) - - const marketConfig = useMangoStore((s) => s.selectedMarket.config) const renderTradeDateTime = (timestamp: BN | string) => { let date @@ -276,7 +272,7 @@ const TradeHistoryTable = () => {
- No {marketConfig.name} trade history. + No trade history. {asPath === '/account' ? ( { }, [selectedMarket]) // fetch filled trades for selected market - useInterval(() => { - async function fetchFills() { - const market = useMangoStore.getState().selectedMarket.current - - if (!market) { - return null - } - try { - const loadedFills = await selectedMarket.loadFills( - DEFAULT_CONNECTION, - 10000 - ) - setMangoStore((state) => { - state.selectedMarket.fills = loadedFills - }) - } catch (err) { - console.log('Error fetching fills:', err) - } + const fetchFills = useCallback(async () => { + if (!selectedMarket) { + return null } + try { + const loadedFills = await selectedMarket.loadFills( + DEFAULT_CONNECTION, + 10000 + ) + setMangoStore((state) => { + state.selectedMarket.fills = loadedFills + }) + } catch (err) { + console.log('Error fetching fills:', err) + } + }, [selectedMarket, setMangoStore]) + useInterval(() => { fetchFills() }, _SLOW_REFRESH_INTERVAL) + + useEffect(() => { + fetchFills() + }, [fetchFills]) } export default useHydrateStore