From cfe114756af83dbfca44bb69613c3d1a4f2532fe Mon Sep 17 00:00:00 2001 From: NFish Date: Thu, 9 Jan 2025 16:04:14 +0800 Subject: [PATCH] fix: sum costs return error value on overview page (#12534) --- web/app/components/app/overview/appChart.tsx | 7 +++---- web/package.json | 1 + web/yarn.lock | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/web/app/components/app/overview/appChart.tsx b/web/app/components/app/overview/appChart.tsx index e0788bcda3bed6..43b1cb6afe5b98 100644 --- a/web/app/components/app/overview/appChart.tsx +++ b/web/app/components/app/overview/appChart.tsx @@ -6,6 +6,7 @@ import type { EChartsOption } from 'echarts' import useSWR from 'swr' import dayjs from 'dayjs' import { get } from 'lodash-es' +import Decimal from 'decimal.js' import { useTranslation } from 'react-i18next' import { formatNumber } from '@/utils/format' import Basic from '@/app/components/app-sidebar/basic' @@ -60,10 +61,8 @@ const CHART_TYPE_CONFIG: Record = { }, } -const sum = (arr: number[]): number => { - return arr.reduce((acr, cur) => { - return acr + cur - }) +const sum = (arr: Decimal.Value[]): number => { + return Decimal.sum(...arr).toNumber() } const defaultPeriod = { diff --git a/web/package.json b/web/package.json index 304a42871bd14d..7afb766d87b21d 100644 --- a/web/package.json +++ b/web/package.json @@ -50,6 +50,7 @@ "copy-to-clipboard": "^3.3.3", "crypto-js": "^4.2.0", "dayjs": "^1.11.7", + "decimal.js": "^10.4.3", "echarts": "^5.5.1", "echarts-for-react": "^3.0.2", "elkjs": "^0.9.3", diff --git a/web/yarn.lock b/web/yarn.lock index 339f47c236e054..6eed53dd39fdcd 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -5568,6 +5568,11 @@ decimal.js@^10.4.2: resolved "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz" integrity sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA== +decimal.js@^10.4.3: + version "10.4.3" + resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.3.tgz#1044092884d245d1b7f65725fa4ad4c6f781cc23" + integrity sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA== + decode-named-character-reference@^1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.0.2.tgz"