refactor!: support RUB only (WealthLedger/main#55) (#168)
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 11s
Frontend verify / verify (push) Failing after 9m0s

This commit was merged in pull request #168.
This commit is contained in:
2026-11-11 09:36:29 +03:00
parent e2062ce837
commit 2b94a16ae5
55 changed files with 540 additions and 1153 deletions
+10 -24
View File
@@ -249,37 +249,23 @@ function toSection(
function toUnrealizedReturns(
positions: Portfolio["positions"],
): Money[] {
const totals = new Map<string, {
complete: boolean;
values: Decimal[];
}>();
): Money | null {
const values: Decimal[] = [];
for (const position of positions) {
const currencies = position.absoluteReturn
? [position.absoluteReturn.currency]
: [...new Set([
position.averagePurchasePrice?.currency,
position.currentValue?.currency,
].filter((currency): currency is string => !!currency))];
if (!position.absoluteReturn) {
// A position without any valuation has nothing to contribute.
for (const currency of currencies) {
const total = totals.get(currency) ?? { complete: true, values: [] };
if (!position.averagePurchasePrice && !position.currentValue)
continue;
if (position.absoluteReturn) {
total.values.push(decimalFromString(position.absoluteReturn.value));
}
else {
total.complete = false;
}
totals.set(currency, total);
return null;
}
values.push(decimalFromString(position.absoluteReturn.value));
}
return [...totals].flatMap(([currency, total]) => total.complete
? [{ currency, value: decimalToString(sumDecimals(total.values)) }]
: []);
return { currency: "RUB", value: decimalToString(sumDecimals(values)) };
}
export {