From 0998181517df52a850a91aced8be366bd481a40e Mon Sep 17 00:00:00 2001 From: Kieran Allen Date: Fri, 4 Oct 2024 12:46:14 +0100 Subject: [PATCH 1/2] fix: add default parent account where missing --- .../src/renderer/components/BalanceInfos/index.tsx | 10 +++++++++- .../screens/asset/AssetBalanceSummaryHeader.tsx | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/ledger-live-desktop/src/renderer/components/BalanceInfos/index.tsx b/apps/ledger-live-desktop/src/renderer/components/BalanceInfos/index.tsx index 263b9c23b14e..fab152c2e45e 100644 --- a/apps/ledger-live-desktop/src/renderer/components/BalanceInfos/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/BalanceInfos/index.tsx @@ -142,6 +142,13 @@ export default function BalanceInfos({ [counterValueId, flattenedAccounts], ); + const parentAccount = useMemo(() => { + if (defaultAccount?.type === "TokenAccount") { + const parentId = defaultAccount.parentId; + return flattenedAccounts.find(a => a.id === parentId); + } + }, [defaultAccount, flattenedAccounts]); + // Remove "SWAP" and "BUY" redundant buttons when portafolio exchange banner is available const portfolioExchangeBanner = useFeature("portfolioExchangeBanner"); const onBuy = useCallback(() => { @@ -160,9 +167,10 @@ export default function BalanceInfos({ state: { from: history.location.pathname, defaultAccount, + defaultParentAccount: parentAccount, }, }); - }, [history, defaultAccount]); + }, [history, defaultAccount, parentAccount]); const ref = useRef(null); const { width } = useResize(ref); diff --git a/apps/ledger-live-desktop/src/renderer/screens/asset/AssetBalanceSummaryHeader.tsx b/apps/ledger-live-desktop/src/renderer/screens/asset/AssetBalanceSummaryHeader.tsx index a7c760c5239d..b400fe670dc0 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/asset/AssetBalanceSummaryHeader.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/asset/AssetBalanceSummaryHeader.tsx @@ -1,5 +1,5 @@ import React, { useCallback, useEffect, useMemo } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { Currency, CryptoCurrency, TokenCurrency, Unit } from "@ledgerhq/types-cryptoassets"; import { setCountervalueFirst } from "~/renderer/actions/settings"; @@ -22,6 +22,7 @@ import useStakeFlow from "~/renderer/screens/stake"; import { stakeDefaultTrack } from "~/renderer/screens/stake/constants"; import { AccountLike, BalanceHistoryWithCountervalue, ValueChange } from "@ledgerhq/types-live"; import { useFetchCurrencyAll } from "@ledgerhq/live-common/exchange/swap/hooks/index"; +import { flattenAccountsSelector } from "~/renderer/reducers/accounts"; type Props = { isAvailable: boolean; cryptoChange: ValueChange; @@ -49,6 +50,7 @@ export default function AssetBalanceSummaryHeader({ const dispatch = useDispatch(); const { t } = useTranslation(); const history = useHistory(); + const flattenAccounts = useSelector(flattenAccountsSelector); const cvUnit = counterValue.units[0]; const data = useMemo( @@ -71,6 +73,13 @@ export default function AssetBalanceSummaryHeader({ data.reverse(); } }, [countervalueFirst, data]); + + const parentAccount = useMemo(() => { + if (account.type === "TokenAccount") { + return flattenAccounts.find(a => a.id === account.parentId); + } + }, [account, flattenAccounts]); + const primaryKey = data[0].unit.code; const secondaryKey = data[1].unit.code; const { isCurrencyAvailable } = useRampCatalog(); @@ -109,11 +118,12 @@ export default function AssetBalanceSummaryHeader({ pathname: "/swap", state: { defaultAccount: account, + defaultParentAccount: parentAccount, defaultCurrency: currency, from: history.location.pathname, }, }); - }, [currency, history, swapDefaultTrack, account]); + }, [currency, swapDefaultTrack, history, account, parentAccount]); const onStake = useCallback(() => { track("button_clicked2", { From 82beaa0be485a48c4b28791e3bb65d59208741b0 Mon Sep 17 00:00:00 2001 From: Kieran Allen Date: Fri, 4 Oct 2024 12:46:37 +0100 Subject: [PATCH 2/2] chore: add changeset --- .changeset/three-islands-carry.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/three-islands-carry.md diff --git a/.changeset/three-islands-carry.md b/.changeset/three-islands-carry.md new file mode 100644 index 000000000000..36eaaef28c15 --- /dev/null +++ b/.changeset/three-islands-carry.md @@ -0,0 +1,5 @@ +--- +"ledger-live-desktop": patch +--- + +add default parent account where missing