Skip to content

Commit

Permalink
Add latest portfolio value to graph data
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Jul 1, 2024
1 parent ee6e2fe commit 02072f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion backend/shared/src/get-user-portfolio-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Answer } from 'common/answer'
import { computeInvestmentValue } from 'common/calculate-metrics'
import { getPortfolioHistory } from 'shared/supabase/portfolio-metrics'
import { DAY_MS } from 'common/util/time'
import { LivePortfolioMetrics } from 'common/portfolio-metrics'

export const getUserPortfolioInternal = async (userId: string) => {
const user = await getUser(userId)
Expand Down Expand Up @@ -124,5 +125,5 @@ export const getUserPortfolioInternal = async (userId: string) => {
dailyProfit:
investmentValue + balance + spiceBalance - totalDeposits - dayAgoProfit,
timestamp: Date.now(),
}
} as LivePortfolioMetrics
}
14 changes: 8 additions & 6 deletions web/components/portfolio/portfolio-value-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ export const PortfolioValueSection = memo(
Object.keys(newGraphValues).forEach((key) => {
const value = newGraphValues[key as keyof GraphValueType]
if (value === undefined) {
// Explicitly set to undefined or delete the key
updatedValues[key as keyof GraphValueType] = undefined // If you want to keep the key with value undefined
// delete updatedValues[key as keyof GraphValueType]; // If you want to remove the key entirely
updatedValues[key as keyof GraphValueType] = undefined
} else {
updatedValues[key as keyof GraphValueType] = value as NonNullable<
GraphValueType[keyof GraphValueType]
Expand Down Expand Up @@ -200,6 +198,11 @@ export const PortfolioValueSection = memo(
spice: spiceBalance,
}

// Add the latest portfolio data as the final point
const updatedPortfolioHistory = portfolio
? [...portfolioHistory, portfolio]
: portfolioHistory

return (
<PortfolioValueSkeleton
hideAddFundsButton={hideAddFundsButton}
Expand All @@ -214,7 +217,7 @@ export const PortfolioValueSection = memo(
<PortfolioGraph
mode={graphMode}
duration={currentTimePeriod}
portfolioHistory={portfolioHistory}
portfolioHistory={updatedPortfolioHistory}
width={width}
height={height}
zoomParams={zoomParams}
Expand All @@ -232,13 +235,12 @@ export const PortfolioValueSection = memo(
portfolioValues={portfolioValues}
graphValues={graphValues}
setGraphMode={setGraphMode}
portfolio={undefined}
portfolio={portfolio}
user={user}
/>
)
}
)

function PortfolioValueSkeleton(props: {
graphMode: GraphMode
currentTimePeriod: Period
Expand Down

0 comments on commit 02072f8

Please sign in to comment.