Memoize on numbers, not dates
This commit is contained in:
parent
5b5a919ed7
commit
de7cf62918
|
@ -55,14 +55,14 @@ export const BinaryContractChart = (props: {
|
|||
const betPoints = useMemo(() => getBetPoints(bets), [bets])
|
||||
const data = useMemo(() => {
|
||||
return [
|
||||
{ x: startDate, y: startP },
|
||||
{ x: new Date(startDate), y: startP },
|
||||
...betPoints,
|
||||
{ x: endDate ?? new Date(Date.now() + DAY_MS), y: endP },
|
||||
{ x: new Date(endDate ?? Date.now() + DAY_MS), y: endP },
|
||||
]
|
||||
}, [startDate, startP, endDate, endP, betPoints])
|
||||
|
||||
const rightmostDate = getRightmostVisibleDate(
|
||||
endDate,
|
||||
endDate ? new Date(endDate) : null,
|
||||
last(betPoints)?.x,
|
||||
new Date(Date.now())
|
||||
)
|
||||
|
|
|
@ -136,17 +136,17 @@ export const ChoiceContractChart = (props: {
|
|||
const betPoints = useMemo(() => getBetPoints(answers, bets), [answers, bets])
|
||||
const data = useMemo(
|
||||
() => [
|
||||
{ x: start, y: answers.map((_) => 0) },
|
||||
{ x: new Date(start), y: answers.map((_) => 0) },
|
||||
...betPoints,
|
||||
{
|
||||
x: end ?? new Date(Date.now() + DAY_MS),
|
||||
x: new Date(end ?? Date.now() + DAY_MS),
|
||||
y: answers.map((a) => getOutcomeProbability(contract, a.id)),
|
||||
},
|
||||
],
|
||||
[answers, contract, betPoints, start, end]
|
||||
)
|
||||
const rightmostDate = getRightmostVisibleDate(
|
||||
end,
|
||||
end ? new Date(end) : null,
|
||||
last(betPoints)?.x,
|
||||
new Date(Date.now())
|
||||
)
|
||||
|
|
|
@ -72,14 +72,14 @@ export const PseudoNumericContractChart = (props: {
|
|||
const betPoints = useMemo(() => getBetPoints(bets, scaleP), [bets, scaleP])
|
||||
const data = useMemo(
|
||||
() => [
|
||||
{ x: startDate, y: startP },
|
||||
{ x: new Date(startDate), y: startP },
|
||||
...betPoints,
|
||||
{ x: endDate ?? new Date(Date.now() + DAY_MS), y: endP },
|
||||
{ x: new Date(endDate ?? Date.now() + DAY_MS), y: endP },
|
||||
],
|
||||
[betPoints, startDate, startP, endDate, endP]
|
||||
)
|
||||
const rightmostDate = getRightmostVisibleDate(
|
||||
endDate,
|
||||
endDate ? new Date(endDate) : null,
|
||||
last(betPoints)?.x,
|
||||
new Date(Date.now())
|
||||
)
|
||||
|
|
|
@ -259,7 +259,7 @@ export const getDateRange = (contract: Contract) => {
|
|||
const { createdTime, closeTime, resolutionTime } = contract
|
||||
const isClosed = !!closeTime && Date.now() > closeTime
|
||||
const endDate = resolutionTime ?? (isClosed ? closeTime : null)
|
||||
return [new Date(createdTime), endDate ? new Date(endDate) : null] as const
|
||||
return [createdTime, endDate ?? null] as const
|
||||
}
|
||||
|
||||
export const getRightmostVisibleDate = (
|
||||
|
|
Loading…
Reference in New Issue
Block a user