Skip to content

Commit

Permalink
fix bug where flag stakePrograms was not checked into account screen,…
Browse files Browse the repository at this point in the history
… add check on flag into bitcoin header actions
  • Loading branch information
adammino-ledger committed Oct 9, 2024
1 parent 34cf28f commit fafecd1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 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 @@ -44,16 +49,20 @@ const AccountHeaderActions = ({ account, parentAccount }: Props) => {
};

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

Expand Down
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 @@ -279,15 +285,17 @@ const AccountHeaderActions = ({ account, parentAccount, openModal }: Props) => {
}, [openModal, parentAccount, account, buttonSharedTrackingFields]);

const manageActions: RenderActionParams[] = [
...manageList.map(item => ({
...item,
contrastText,
currency,
eventProperties: {
...buttonSharedTrackingFields,
...item.eventProperties,
},
})),
...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")} />;
Expand Down

0 comments on commit fafecd1

Please sign in to comment.