diff --git a/src/components/data-management.tsx b/src/components/data-management.tsx index 7efe5b4..cee3a23 100644 --- a/src/components/data-management.tsx +++ b/src/components/data-management.tsx @@ -115,7 +115,7 @@ const App = ({ } catch (e: any) { toast({ description: e.message || e, - variant: "destructive" + variant: "destructive", }); } finally { if (force) { @@ -157,7 +157,7 @@ const App = ({ .catch((err) => { toast({ description: err.message || err, - variant: "destructive" + variant: "destructive", }); }); } @@ -172,7 +172,7 @@ const App = ({ if (!email || !verificationCode) { toast({ description: "email or verification code is empty", - variant: "destructive" + variant: "destructive", }); return; } @@ -184,13 +184,13 @@ const App = ({ if (msg.includes("400")) { toast({ description: "invalid verification code", - variant: "destructive" + variant: "destructive", }); return; } toast({ description: e.message || e, - variant: "destructive" + variant: "destructive", }); } finally { setSignLoading(false); @@ -201,7 +201,7 @@ const App = ({ if (!email) { toast({ description: "email is empty", - variant: "destructive" + variant: "destructive", }); return; } @@ -214,7 +214,7 @@ const App = ({ if (!emailRegex.test(email)) { toast({ description: "invalid email", - variant: "destructive" + variant: "destructive", }); return; } @@ -238,7 +238,7 @@ const App = ({ } catch (e: any) { toast({ description: e.message || e, - variant: "destructive" + variant: "destructive", }); } finally { setSendEmailLoading(false); @@ -293,12 +293,8 @@ const App = ({ className="ml-1 wd-40" disabled={sendVerifyCodeDisabledSeconds > 0} > - {sendEmailLoading ? ( + {sendEmailLoading && ( - ) : ( - sendVerifyCodeDisabledSeconds > 0 && ( - - ) )} Send Code {sendVerifyCodeDisabledSeconds > 0 && diff --git a/src/components/index/index.tsx b/src/components/index/index.tsx index 96d7c5d..8f7bd5b 100644 --- a/src/components/index/index.tsx +++ b/src/components/index/index.tsx @@ -17,6 +17,7 @@ import ChartDataLabels from "chartjs-plugin-datalabels"; import HistoricalData from "../historical-data"; import Overview from "../overview"; import Comparison from "../comparison"; +import PageWrapper from "../page-wrapper"; import WalletAnalyzer from "../wallet-analyzer"; import "./index.css"; import { @@ -38,7 +39,7 @@ import { TopCoinsRankData, TotalValueData, } from "@/middlelayers/types"; -import { useContext, useEffect, useState } from "react"; +import { useContext, useEffect, useMemo, useState } from "react"; import { queryAssetChange, queryLastRefreshAt, @@ -53,6 +54,7 @@ import { useWindowSize } from "@/utils/hook"; import { Chart } from "chart.js"; import { LoadingContext } from "@/App"; import { + getConfiguration, getCurrentPreferCurrency, getQuerySize, } from "@/middlelayers/configuration"; @@ -64,7 +66,6 @@ import Configuration from "@/components/configuration"; import DataManagement from "@/components/data-management"; import SystemInfo from "@/components/system-info"; import React from "react"; -import { queryCoinPrices } from "@/middlelayers/data"; ChartJS.register( ...registerables, @@ -97,6 +98,8 @@ const App = () => { getDefaultCurrencyRate() ); + const [hasData, setHasData] = useState(true); + const [activeMenu, setActiveMenu] = useState("overview"); const [latestAssetsPercentageData, setLatestAssetsPercentageData] = @@ -143,6 +146,18 @@ const App = () => { }, [windowSize]); useEffect(() => { + resizeAllChartsInPage() + }, [lastSize]); + + useEffect(() => { + if (hasData) { + setTimeout(()=>{ + resizeAllChartsInPage() + }, resizeDelay / 2); + } + }, [hasData]); + + function resizeAllChartsInPage() { if ( lastSize.width === windowSize.width && lastSize.height === windowSize.height && @@ -150,7 +165,7 @@ const App = () => { ) { resizeAllCharts(); } - }, [lastSize]); + } function resizeAllCharts() { const overviewsCharts = [ @@ -215,14 +230,18 @@ const App = () => { const lra = await queryLastRefreshAt(); setLastRefreshAt(lra); + + if (lap.length > 0) { + setHasData(true); + } else { + setHasData(false); + } } function loadAllData(size = 10) { setLoading(true); // set a loading delay to show the loading animation - setTimeout(() => { - loadAllDataAsync(size).finally(() => setLoading(false)); - }, 100); + loadAllDataAsync(size).finally(() => setLoading(false)); } useEffect(() => { @@ -304,34 +323,46 @@ const App = () => { + + + } /> } + element={ + + + + } /> } + element={ + + + + } /> loadAllData(querySize)} - /> + + loadAllData(querySize)} + /> + } /> }> diff --git a/src/components/latest-assets-percentage.tsx b/src/components/latest-assets-percentage.tsx index 87e943a..20afee1 100644 --- a/src/components/latest-assets-percentage.tsx +++ b/src/components/latest-assets-percentage.tsx @@ -215,7 +215,7 @@ const App = ({
-
+
{renderDoughnut()}
{renderTokenHoldingList()} diff --git a/src/components/page-wrapper.tsx b/src/components/page-wrapper.tsx new file mode 100644 index 0000000..f0d1270 --- /dev/null +++ b/src/components/page-wrapper.tsx @@ -0,0 +1,41 @@ +import { Button } from "./ui/button"; +import { useNavigate } from "react-router-dom"; +import { + ArrowTopRightIcon +} from "@radix-ui/react-icons"; + +// if there is no data, show a message and a button to go to settings page +const App = ({ + hasData, + children, +}: { + hasData: boolean; + children: React.ReactNode; +}) => { + const navigate = useNavigate(); + return ( + <> + {hasData ? ( + children + ) : ( +
+
+
There is no enough data
+
+ Please add configurations in "settings" and click "Refresh" Button +
+ +
+
+ )} + + ); +}; + +export default App;