Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve performance by gpt4o #438

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-hover-card": "^1.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
Expand Down
72 changes: 42 additions & 30 deletions src/components/ath-value.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import {
TotalValueData,
} from "@/middlelayers/types";
import _ from "lodash";
import { useEffect, useMemo, useState } from "react";
import { useEffect, useMemo, useState, useCallback } from "react";
import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";
import { loadingWrapper } from "@/lib/loading";
import { queryMaxTotalValue, queryTotalValue } from "@/middlelayers/charts";
import { currencyWrapper, prettyNumberToLocaleString } from "@/utils/currency";
import { timeToDateStr } from "@/utils/date";
import { positiveNegativeColor } from "@/utils/color";
import { cn } from "@/lib/utils";
import React from "react";

const App = ({
dateRange,
Expand All @@ -38,33 +37,37 @@ const App = ({
totalValue: 0,
});

function updateLoading(val: boolean) {
if (initialLoaded) {
return;
}
setLoading(val);
}
const updateLoading = useCallback(
(val: boolean) => {
if (!initialLoaded) {
setLoading(val);
}
},
[initialLoaded]
);

const loadData = useCallback(
async (dt: TDateRange) => {
updateLoading(true);
try {
const [mtv, tv] = await Promise.all([
queryMaxTotalValue(dt),
queryTotalValue(),
]);
setMaxTotalValueData(mtv);
setTotalValueData(tv);
} finally {
updateLoading(false);
}
},
[updateLoading]
);

useEffect(() => {
loadData(dateRange).then(() => {
setInitialLoaded(true);
});
}, [dateRange]);

async function loadData(dt: TDateRange) {
updateLoading(true);

try {
const [mtv, tv] = await Promise.all([
queryMaxTotalValue(dt),
queryTotalValue(),
]);
setMaxTotalValueData(mtv);
setTotalValueData(tv);
} finally {
updateLoading(false);
}
}
}, [dateRange, loadData]);

const percentageFromATH = useMemo(() => {
if (maxTotalValueData.totalValue === 0) {
Expand All @@ -75,17 +78,17 @@ const App = ({
maxTotalValueData.totalValue) *
100
);
}, [totalValueData, maxTotalValueData]);
}, [totalValueData.totalValue, maxTotalValueData.totalValue]);

const needBreakTotalValueLine = useMemo(
() =>
currencyWrapper(currency)(totalValueData.totalValue) >= 10 ** 8 ||
currencyWrapper(currency)(maxTotalValueData.totalValue) >= 10 ** 8,
[currency, totalValueData, maxTotalValueData]
[currency, totalValueData.totalValue, maxTotalValueData.totalValue]
);

const MaxTotalValueView = React.memo(() => {
return (
const MaxTotalValueView = useCallback(
() => (
<div
className={cn(
"grid gap-2 grid-cols-2",
Expand Down Expand Up @@ -133,8 +136,17 @@ const App = ({
</div>
</div>
</div>
);
});
),
[
needBreakTotalValueLine,
currency,
totalValueData.totalValue,
maxTotalValueData.totalValue,
maxTotalValueData.date,
percentageFromATH,
quoteColor,
]
);

return (
<Card>
Expand Down
Loading
Loading