From 3973189b74b5d7698e705e4fda96d4e3c0fb8208 Mon Sep 17 00:00:00 2001 From: Leonardo Arcari Date: Sat, 7 Oct 2023 14:10:19 +0200 Subject: [PATCH] FE: Do not weigh unallocated cash if portfolio does not have liquidity position --- .../allocationFlow/endStep/allocateCard.js | 56 ++++++++++--------- .../allocationFlow/endStep/index.js | 15 +++-- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/dcapal-frontend/src/components/allocationFlow/endStep/allocateCard.js b/dcapal-frontend/src/components/allocationFlow/endStep/allocateCard.js index 32b48360..b1a2fa25 100644 --- a/dcapal-frontend/src/components/allocationFlow/endStep/allocateCard.js +++ b/dcapal-frontend/src/components/allocationFlow/endStep/allocateCard.js @@ -148,34 +148,38 @@ export const AllocateCard = ({ {qty >= 0 && ( -
-
- {actionIcon} - {qty > oldQty && ( - - {t("endStep.buy")} {roundDecimals(qty - oldQty, 6)}{" "} - {symbol} @ {price}{" "} - {quoteCcy} - - )} - {qty < oldQty && ( - - {t("endStep.sell")} {roundDecimals(oldQty - qty, 6)}{" "} - {symbol} @ {price}{" "} - {quoteCcy} - - )} - {qty === oldQty && ( - - {aclass === ACLASS.CRYPTO - ? t("endStep.nothingToTradeHodl") - : t("endStep.nothingToTradeHold")} - - )} -
-

+

+ {actionIcon} + {qty > oldQty && ( + + {t("endStep.buy")} {roundDecimals(qty - oldQty, 6)}{" "} + {symbol} @ {price}{" "} + {quoteCcy} + + )} + {qty < oldQty && ( + + {t("endStep.sell")} {roundDecimals(oldQty - qty, 6)}{" "} + {symbol} @ {price}{" "} + {quoteCcy} + + )} + {qty === oldQty && ( + + {aclass === ACLASS.CRYPTO + ? t("endStep.nothingToTradeHodl") + : t("endStep.nothingToTradeHold")} + + )} +
+ )} + {qty < 0 && symbol === quoteCcy && ( +
+ 💰 + {t("endStep.leftBudget")}
)} +

{isMobile && (
diff --git a/dcapal-frontend/src/components/allocationFlow/endStep/index.js b/dcapal-frontend/src/components/allocationFlow/endStep/index.js index 68e61dec..fa9f6b73 100644 --- a/dcapal-frontend/src/components/allocationFlow/endStep/index.js +++ b/dcapal-frontend/src/components/allocationFlow/endStep/index.js @@ -6,7 +6,6 @@ import { replacer, roundAmount, roundDecimals, timeout } from "../../../utils"; import { Spinner } from "../../spinner/spinner"; import { ACLASS, - FeeType, clearBudget, feeTypeToString, isWholeShares, @@ -35,18 +34,24 @@ const buildCards = (assets, solution, pfolioCcy, pfolioFees) => { if (!solution?.amounts) return cards; - let totalAmount = solution.budget_left || 0; + const budgetLeft = solution.budget_left || 0; + const hasCashPosition = pfolioCcy in assets; + + let totalAmount = hasCashPosition ? budgetLeft : 0; for (const a of solution.amounts.values()) { totalAmount += a; } for (const card of cards) { + const isCashAsset = hasCashPosition && card.symbol === pfolioCcy; + if (solution.amounts.has(card.symbol)) { card.amount = solution.amounts.get(card.symbol); + card.amount += isCashAsset ? budgetLeft : 0; card.weight = (100 * card.amount) / totalAmount; } - if (solution?.shares?.has(card.symbol)) { + if (solution?.shares?.has(card.symbol) && !isCashAsset) { card.qty = solution.shares.get(card.symbol); } @@ -55,7 +60,7 @@ const buildCards = (assets, solution, pfolioCcy, pfolioFees) => { } } - if (solution.budget_left) { + if (budgetLeft && !hasCashPosition) { cards.push({ symbol: pfolioCcy, name: UNALLOCATED_CASH, @@ -63,7 +68,7 @@ const buildCards = (assets, solution, pfolioCcy, pfolioFees) => { qty: -1, oldQty: 0, price: 0, - amount: solution.budget_left, + amount: budgetLeft, oldAmount: 0, weight: 0, oldWeight: 0,