Skip to content

Commit

Permalink
improve ui for total page
Browse files Browse the repository at this point in the history
  • Loading branch information
domechn committed Nov 8, 2023
1 parent 4a9bff5 commit c43191e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
50 changes: 31 additions & 19 deletions src/components/asset-change.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Line } from "react-chartjs-2";
import { useWindowSize } from "@/utils/hook";
import { timestampToDate } from "@/utils/date";
import { AssetChangeData, CurrencyRateDetail } from "@/middlelayers/types";
import _ from 'lodash'
import { currencyWrapper } from '@/utils/currency'
import _ from "lodash";
import { currencyWrapper } from "@/utils/currency";

const App = ({
data,
Expand All @@ -14,30 +13,47 @@ const App = ({
}) => {
const lineColor = "rgba(255, 99, 71, 1)";

const size = useWindowSize();

const options = {
maintainAspectRatio: false,
responsive: false,
plugins: {
title: {
display: true,
text: `Trend of Asset ${currency.currency} Value`,
display: false,
},
datalabels: {
display: false,
},
legend: {
display: false,
},
},
scales: {
x: {
title: {
display: true,
display: false,
text: "Date",
},
ticks: {
maxTicksLimit: 2,
autoSkip: false,
labelOffset: -5,
callback: function (val: number, index: number) {
console.log(index === 0 || index === _(data.timestamps).size() - 1);
const total = _(data.timestamps).size() - 1;

// Hide every 2nd tick label
return index === 0 || index === total - 1
? timestampToDate(data.timestamps[index])
: "";
},
},
grid: {
display: false,
},
},
y: {
title: {
display: true,
display: false,
text: currency.currency,
},
offset: true,
Expand All @@ -57,12 +73,14 @@ const App = ({
datasets: [
{
label: "Value",
data: _(data.data).map(d => currencyWrapper(currency)(d)).value(),
data: _(data.data)
.map((d) => currencyWrapper(currency)(d))
.value(),
borderColor: lineColor,
backgroundColor: lineColor,
borderWidth: 5,
borderWidth: data.data.length > 20 ? 2 : 4,
tension: 0.1,
pointRadius: 1,
pointRadius: data.data.length > 20 ? 0 : 0.3,
pointStyle: "rotRect",
},
],
Expand All @@ -71,13 +89,7 @@ const App = ({

return (
<div>
<div
style={{
height: Math.max((size.height || 100) / 2, 350),
}}
>
<Line options={options} data={lineData()} />
</div>
<Line options={options as any} data={lineData()} />
</div>
);
};
Expand Down
8 changes: 6 additions & 2 deletions src/components/overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
TopCoinsRankData,
} from "../../middlelayers/types";
import { Separator } from "../ui/separator";
import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";

const App = ({
currency,
Expand All @@ -38,11 +39,14 @@ const App = ({
}) => {
return (
<>
<TotalValue currency={currency} data={totalValueData} />
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-2">
<TotalValue currency={currency} data={totalValueData}>
<AssetChange currency={currency} data={assetChangeData} />
</TotalValue>
</div>
{/* <hr className="nice-hr" /> */}
<LatestAssetsPercentage data={latestAssetsPercentageData} />
<Separator className="my-6" />
<AssetChange currency={currency} data={assetChangeData} />
<Separator className="my-6" />
<CoinsAmountAndValueChange
currency={currency}
Expand Down
2 changes: 1 addition & 1 deletion src/components/refresh-data/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const App = ({
<ReloadIcon
className={`mr-2 h-4 w-4 ${refreshLoading && "animate-spin"}`}
/>
Refresh
<p className='hidden sm:inline-block'>Refresh</p>
</Button>
</div>
);
Expand Down
13 changes: 7 additions & 6 deletions src/components/total-value/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
const App = ({
data,
currency,
children,
}: {
currency: CurrencyRateDetail;
data: {
totalValue: number;
changePercentage: number;
};
children: React.ReactNode;
}) => {
const [changedValueOrPercentage, setChangedValueOrPercentage] = useState("");

Expand Down Expand Up @@ -62,13 +64,13 @@ const App = ({

function changePercentageColorClass() {
if (data.changePercentage === 0) {
return "";
return "text-gray-500";
}
return data.changePercentage > 0 ? "positive" : "negative";
return data.changePercentage > 0 ? "text-green-500" : "text-red-500";
}

return (
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-2">
<div>
<Card
onMouseEnter={() => setChangedValueOrPercentage(formatChangeValue())}
onMouseLeave={() =>
Expand All @@ -93,13 +95,12 @@ const App = ({
<CardContent>
<div className="text-2xl font-bold">{formatTotalValue()}</div>
<p className="text-xs text-muted-foreground">
<span
className={`changePercentage ${changePercentageColorClass()}`}
>
<span className={changePercentageColorClass()}>
{changedValueOrPercentage}
</span>{" "}
from last time
</p>
{children}
</CardContent>
</Card>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/middlelayers/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ async function queryCoinsData(): Promise<(WalletCoin & {
throw new Error("no configuration found,\n please add configuration first")
}
const assets = await loadPortfolios(config)
const priceMap = await queryCoinPrices(_(assets).map("symbol").push("USDT").uniq().value())
// always query btc and usdt price
const priceMap = await queryCoinPrices(_(assets).map("symbol").push("USDT").push("BTC").uniq().value())

let lastAssets = _.clone(assets)
const groupUSD: boolean = _(config).get(['configs', 'groupUSD']) || false
Expand Down

0 comments on commit c43191e

Please sign in to comment.