Skip to content

Commit

Permalink
Merge pull request #8059 from LedgerHQ/feat/CN-551-entrypoints-for-ac…
Browse files Browse the repository at this point in the history
…re-bitcoin-yield

Fix bug where flag stakePrograms was not checked into account screen,…
  • Loading branch information
KVNLS authored Oct 11, 2024
2 parents 69cf2e5 + b8f33c4 commit c6b4d63
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import { stakeDefaultTrack } from "~/renderer/screens/stake/constants";
import { BitcoinAccount } from "@ledgerhq/coin-bitcoin/lib/types";
import { TokenAccount } from "@ledgerhq/types-live";
import IconCoins from "~/renderer/icons/Coins";
import useFeature from "@ledgerhq/live-common/featureFlags/useFeature";

type Props = {
account: BitcoinAccount | TokenAccount;
parentAccount: BitcoinAccount | undefined | null;
};

const AccountHeaderActions = ({ account, parentAccount }: Props) => {
const stakeProgramsFeatureFlag = useFeature("stakePrograms");
const listFlag = stakeProgramsFeatureFlag?.params?.list ?? [];
const stakeProgramsEnabled = stakeProgramsFeatureFlag?.enabled ?? false;
const availableOnStake = stakeProgramsEnabled && listFlag.includes("bitcoin");
const history = useHistory();
const { t } = useTranslation();
const mainAccount = getMainAccount(account, parentAccount);
Expand Down Expand Up @@ -43,18 +48,20 @@ const AccountHeaderActions = ({ account, parentAccount }: Props) => {
});
};

return [
{
key: "Stake",
icon: IconCoins,
label: t("accounts.contextMenu.yield"),
event: "button_clicked2",
eventProperties: {
button: "stake",
},
onClick: stakeOnClick,
},
];
return availableOnStake
? [
{
key: "Stake",
icon: IconCoins,
label: t("accounts.contextMenu.yield"),
event: "button_clicked2",
eventProperties: {
button: "stake",
},
onClick: stakeOnClick,
},
]
: [];
};

export default AccountHeaderActions;
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { getAvailableProviders } from "@ledgerhq/live-common/exchange/swap/index
import { useFetchCurrencyAll } from "@ledgerhq/live-common/exchange/swap/hooks/index";
import { isWalletConnectSupported } from "@ledgerhq/live-common/walletConnect/index";
import { WC_ID } from "@ledgerhq/live-common/wallet-api/constants";
import useFeature from "@ledgerhq/live-common/featureFlags/useFeature";

type RenderActionParams = {
label: React.ReactNode;
Expand Down Expand Up @@ -189,6 +190,10 @@ const AccountHeaderActions = ({ account, parentAccount, openModal }: Props) => {
const swapDefaultTrack = useGetSwapTrackingProperties();
const specific = getLLDCoinFamily(mainAccount.currency.family);

const stakeProgramsFeatureFlag = useFeature("stakePrograms");
const listFlag = stakeProgramsFeatureFlag?.params?.list ?? [];
const stakeProgramsEnabled = stakeProgramsFeatureFlag?.enabled ?? false;

const manage = specific?.accountHeaderManageActions;
let manageList: ManageAction[] = [];
if (manage) {
Expand All @@ -204,6 +209,7 @@ const AccountHeaderActions = ({ account, parentAccount, openModal }: Props) => {

const availableOnBuy = !!currency && isCurrencyAvailable(currency.id, "onRamp");
const availableOnSell = !!currency && isCurrencyAvailable(currency.id, "offRamp");
const availableOnStake = stakeProgramsEnabled && listFlag.includes(currency.id || "");

// don't show buttons until we know whether or not we can show swap button, otherwise possible click jacking
const showButtons = !!getAvailableProviders();
Expand Down Expand Up @@ -278,17 +284,17 @@ const AccountHeaderActions = ({ account, parentAccount, openModal }: Props) => {
});
}, [openModal, parentAccount, account, buttonSharedTrackingFields]);

const manageActions: RenderActionParams[] = [
...manageList.map(item => ({
const manageActions: RenderActionParams[] = manageList
.filter(item => (availableOnStake && item.key === "Stake") || item.key !== "Stake")
.map(item => ({
...item,
contrastText,
currency,
eventProperties: {
...buttonSharedTrackingFields,
...item.eventProperties,
},
})),
];
}));

const buyHeader = <BuyActionDefault onClick={() => onBuySell("buy")} />;
const sellHeader = <SellActionDefault onClick={() => onBuySell("sell")} />;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion apps/ledger-live-desktop/tests/specs/services/swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ test.describe.parallel("Swap", () => {
});
});

test("Full Swap with Centralised Exchange @smoke", async ({
//Test part of legacy swap, flaky at the moment they need to be reviewed
test.skip("Full Swap with Centralised Exchange @smoke", async ({
page,
mockProviderSvgs,
mockFeesEndpoint,
Expand Down

0 comments on commit c6b4d63

Please sign in to comment.