From 746be06840dea5f9934b37e46f6929342e9b372d Mon Sep 17 00:00:00 2001 From: kennethcheng Date: Tue, 28 Apr 2026 01:18:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E4=BF=AE=E5=A4=8D=20portfolio=20?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E4=B8=AD=E6=BC=8F=E5=86=99=20new=20Big()=20?= =?UTF-8?q?=E5=8C=85=E8=A3=85=E5=AF=BC=E8=87=B4=E7=9A=84=20TypeError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/portfolio.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/actions/portfolio.ts b/src/actions/portfolio.ts index c17ec11..0279a82 100644 --- a/src/actions/portfolio.ts +++ b/src/actions/portfolio.ts @@ -54,7 +54,7 @@ function calculateCnyValueFromPrice( const directRate = getRate(rateMap, baseCurrency, 'CNY'); if (directRate) { - return quantity.times(price).times(directRate); + return quantity.times(price).times(new Big(directRate)); } const usdToCny = getRate(rateMap, 'USD', 'CNY'); @@ -64,7 +64,7 @@ function calculateCnyValueFromPrice( const usdRate = getRate(rateMap, baseCurrency, 'USD'); if (usdRate) { - return quantity.times(price).times(usdRate).times(usdToCny); + return quantity.times(price).times(new Big(usdRate)).times(new Big(usdToCny)); } return new Big('0'); @@ -116,16 +116,16 @@ export async function getPortfolioPositions(): Promise { const holding = holdings.get(tx.assetId)!; if (tx.txType === 'BUY') { - holding.quantity = holding.quantity.plus(tx.quantity); - const costPerUnit = tx.quantity.times(tx.price); - const costCny = costPerUnit.times(tx.exchangeRate || '1'); + holding.quantity = holding.quantity.plus(new Big(tx.quantity)); + const costPerUnit = new Big(tx.quantity).times(new Big(tx.price)); + const costCny = costPerUnit.times(new Big(tx.exchangeRate || '1')); holding.totalCostCny = holding.totalCostCny.plus(costCny); } else if (tx.txType === 'SELL') { - holding.quantity = holding.quantity.minus(tx.quantity); + holding.quantity = holding.quantity.minus(new Big(tx.quantity)); } else if (tx.txType === 'AIRDROP') { - holding.quantity = holding.quantity.plus(tx.quantity); + holding.quantity = holding.quantity.plus(new Big(tx.quantity)); } else if (tx.txType === 'DIVIDEND') { - holding.quantity = holding.quantity.plus(tx.quantity); + holding.quantity = holding.quantity.plus(new Big(tx.quantity)); } if (tx.assetLatestPrice) {