Skip to content

Commit

Permalink
split value by thousand (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
domechn authored Oct 8, 2023
1 parent 8492f64 commit 4b64d96
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
7 changes: 2 additions & 5 deletions src/components/comparison/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import _ from "lodash";
import Select from "../common/select";
import viewIcon from "../../assets/icons/view-icon.png";
import hideIcon from "../../assets/icons/hide-icon.png";
import { currencyWrapper } from "../../utils/currency";
import { currencyWrapper, prettyNumberToLocaleString } from "../../utils/currency";
import { useWindowSize } from "../../utils/hook";
import { parseDateToTS } from "../../utils/date";

Expand Down Expand Up @@ -314,10 +314,7 @@ const App = ({ currency }: { currency: CurrencyRateDetail }) => {
}
let res = "" + convertedNumber;
if (!keepDecimal) {
res = convertedNumber.toLocaleString("en-US", {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
res = prettyNumberToLocaleString(convertedNumber)
}
if (convertCurrency) {
return `${currency.symbol} ${res}`;
Expand Down
23 changes: 16 additions & 7 deletions src/components/historical-data/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import "./index.css";
import { toast } from "react-hot-toast";
import { LoadingContext } from "../../App";
import { timestampToDate } from "../../utils/date";
import { currencyWrapper } from "../../utils/currency";
import {
currencyWrapper,
prettyNumberToLocaleString,
} from "../../utils/currency";
import Modal from "../common/modal";

type RankData = {
Expand Down Expand Up @@ -66,7 +69,9 @@ const App = ({
<>
{curData
? currency.symbol +
currencyWrapper(currency)(curData.value).toFixed(2)
prettyNumberToLocaleString(
currencyWrapper(currency)(curData.value)
)
: "-"}
</>
);
Expand Down Expand Up @@ -169,7 +174,9 @@ const App = ({
</div>
<div className="historical-data-card-total">
{currency.symbol +
currencyWrapper(currency)(d.total).toFixed(2)}
prettyNumberToLocaleString(
currencyWrapper(currency)(d.total)
)}
</div>
</div>

Expand All @@ -196,9 +203,11 @@ const App = ({
{idx < data.length - 1
? getUpOrDown(d.total - data[idx + 1].total) +
currency.symbol +
currencyWrapper(currency)(
Math.abs(d.total - data[idx + 1].total)
).toFixed(2)
prettyNumberToLocaleString(
currencyWrapper(currency)(
Math.abs(d.total - data[idx + 1].total)
)
)
: ""}
</div>
</div>
Expand All @@ -220,7 +229,7 @@ const App = ({
key={"his-page-" + curPageNum}
onClick={() => setPageNum(curPageNum)}
style={{
color: curPageNum === pageNum ? "rgb(37, 37, 244)" : "gray",
color: curPageNum === pageNum ? "black" : "gray",
marginRight: 10,
}}
>
Expand Down
19 changes: 12 additions & 7 deletions src/components/total-value/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useEffect, useState } from "react";
import { CurrencyRateDetail } from "../../middlelayers/types";
import { currencyWrapper } from "../../utils/currency";
import {
currencyWrapper,
prettyNumberToLocaleString,
} from "../../utils/currency";
import { useWindowSize } from "../../utils/hook";
import "./index.css";

Expand Down Expand Up @@ -32,7 +35,8 @@ const App = ({

function formatTotalValue() {
return (
currency.symbol + currencyWrapper(currency)(data.totalValue).toFixed(2)
currency.symbol +
prettyNumberToLocaleString(currencyWrapper(currency)(data.totalValue))
);
}

Expand All @@ -47,7 +51,7 @@ const App = ({
if (val < 0) {
val = -val;
}
return `${p}${val.toFixed(2)}%`;
return `${p}${prettyNumberToLocaleString(val)}%`;
}

function formatChangeValue() {
Expand All @@ -59,7 +63,7 @@ const App = ({
if (val < 0) {
val = -val;
}
return p + symbol + val.toFixed(2);
return p + symbol + prettyNumberToLocaleString(val);
}

function fontCount() {
Expand Down Expand Up @@ -117,8 +121,10 @@ const App = ({
style={{
minHeight: totalValueFontSize(),
}}
onMouseEnter={() => setChangedValueOrPercentage(formatChangeValue())}
onMouseLeave={() => setChangedValueOrPercentage(formatChangePercentage()) }
onMouseEnter={() => setChangedValueOrPercentage(formatChangeValue())}
onMouseLeave={() =>
setChangedValueOrPercentage(formatChangePercentage())
}
>
<span
className="totalValue"
Expand All @@ -138,7 +144,6 @@ const App = ({
fontSize: changePercentageFontSize(),
}}
>
{/* {formatChangePercentage()} */}
{changedValueOrPercentage}
</span>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/components/wallet-assets-change/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
CurrencyRateDetail,
WalletAssetsChangeData,
} from "../../middlelayers/types";
import { currencyWrapper } from "../../utils/currency";
import { currencyWrapper, prettyNumberToLocaleString } from "../../utils/currency";
import { useWindowSize } from "../../utils/hook";
import { insertEllipsis } from "../../utils/string";
import "./index.css";
Expand Down Expand Up @@ -125,7 +125,7 @@ const App = ({
>
<span className={getChangeClassName(d.changePercentage)}>
{getArrow(d.changePercentage)}
{getPositiveValue(d.changePercentage).toFixed(2)}%
{prettyNumberToLocaleString(getPositiveValue(d.changePercentage))}%
</span>
</td>
<td
Expand All @@ -137,9 +137,9 @@ const App = ({
<span className={getChangeClassName(d.changeValue)}>
{getArrow(d.changeValue)}
{currency.symbol}
{currencyWrapper(currency)(
getPositiveValue(d.changeValue)
).toFixed(2)}
{prettyNumberToLocaleString(
currencyWrapper(currency)(getPositiveValue(d.changeValue))
)}
</span>
</td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions src/components/wallet-assets-percentage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CurrencyRateDetail,
WalletAssetsPercentageData,
} from "../../middlelayers/types";
import { currencyWrapper } from "../../utils/currency";
import { currencyWrapper, prettyNumberToLocaleString } from "../../utils/currency";
import _ from "lodash";
import { useEffect, useState } from "react";
import { insertEllipsis } from '../../utils/string'
Expand Down Expand Up @@ -42,7 +42,7 @@ const App = ({
align: "top",
offset: Math.max(0, 15 - _(data).size()),
formatter: (value: number) => {
return `${((value / totalValue) * 100).toFixed(2)}%`;
return `${prettyNumberToLocaleString((value / totalValue) * 100)}%`;
},
},
},
Expand Down
7 changes: 7 additions & 0 deletions src/utils/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ export function currencyWrapper(currencyInfo: CurrencyRateDetail) {
return valueInUsd * currencyInfo.rate
}
}

export function prettyNumberToLocaleString(value: number) {
return value.toLocaleString("en-US", {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})
}

0 comments on commit 4b64d96

Please sign in to comment.