Skip to content

Commit

Permalink
Merge pull request #8012 from LedgerHQ/fix/LIVE-9213
Browse files Browse the repository at this point in the history
[FIX/LIVE-9213]: add missing default parent account parameter for swap live app.
  • Loading branch information
kallen-ledger authored Oct 7, 2024
2 parents 961f567 + 82beaa0 commit 76947d8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-islands-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

add default parent account where missing
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -160,9 +167,10 @@ export default function BalanceInfos({
state: {
from: history.location.pathname,
defaultAccount,
defaultParentAccount: parentAccount,
},
});
}, [history, defaultAccount]);
}, [history, defaultAccount, parentAccount]);

const ref = useRef<HTMLDivElement>(null);
const { width } = useResize(ref);
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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();
Expand Down Expand Up @@ -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", {
Expand Down

0 comments on commit 76947d8

Please sign in to comment.