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) {