Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(): enable ape and cape staking via stakekit #8214

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next";
import IconCoins from "~/renderer/icons/Coins";
import { openModal } from "~/renderer/actions/modals";
import { isAccountEmpty } from "@ledgerhq/live-common/account/index";
import { useHistory } from "react-router";

type Props = {
account: AccountLike;
Expand All @@ -14,8 +15,16 @@ type Props = {
const AccountHeaderActions = ({ account, parentAccount }: Props) => {
const { t } = useTranslation();
const dispatch = useDispatch();
const history = useHistory();

const isEthereumAccount = account.type === "Account" && account.currency.id === "ethereum";
const isApeTokenAccount =
account.type === "TokenAccount" && account.token.id === "ethereum/erc20/apecoin";
const isCApeTokenAccount =
account.type === "TokenAccount" &&
account.token.contractAddress === "0xC5c9fB6223A989208Df27dCEE33fC59ff5c26fFF";

const canStake = isEthereumAccount || isApeTokenAccount || isCApeTokenAccount;

const onClickStake = useCallback(() => {
if (isAccountEmpty(account)) {
Expand All @@ -31,10 +40,21 @@ const AccountHeaderActions = ({ account, parentAccount }: Props) => {
account,
}),
);
} else {
history.push({
pathname: "/platform/stakekit",
state: {
yieldId: isCApeTokenAccount
? "ethereum-ape-parax-staking"
: "ethereum-ape-native-staking",
accountId: account.id,
returnTo: `/account/${account.parentId}/${account.id}`,
},
});
}
}, [account, dispatch, parentAccount]);
}, [account, dispatch, history, isCApeTokenAccount, parentAccount]);

if (isEthereumAccount) {
if (canStake) {
return [
{
key: "Stake",
Expand All @@ -44,9 +64,7 @@ const AccountHeaderActions = ({ account, parentAccount }: Props) => {
button: "stake",
},
icon: IconCoins,
label: t("account.stake", {
currency: account?.currency?.name,
}),
label: t("account.stake", isEthereumAccount ? { currency: account?.currency?.name } : {}),
accountActionsTestId: "stake-button",
},
];
Expand Down
36 changes: 34 additions & 2 deletions apps/ledger-live-mobile/src/families/evm/accountActions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import type { Account } from "@ledgerhq/types-live";
import type { Account, AccountLike } from "@ledgerhq/types-live";
import { IconsLegacy } from "@ledgerhq/native-ui";
import { Trans } from "react-i18next";
import { isAccountEmpty } from "@ledgerhq/live-common/account/index";
Expand All @@ -14,7 +14,7 @@ const ethMagnitude = getCryptoCurrencyById("ethereum").units[0].magnitude ?? 18;
const ETH_LIMIT = BigNumber(32).times(BigNumber(10).pow(ethMagnitude));

type Props = {
account: Account;
account: AccountLike;
parentAccount: Account;
parentRoute: RouteProp<ParamListBase, ScreenName>;
};
Expand Down Expand Up @@ -83,6 +83,38 @@ const getMainActions = ({ account, parentAccount, parentRoute }: Props): ActionB
];
}

const isApeTokenAccount =
account.type === "TokenAccount" && account.token.id === "ethereum/erc20/apecoin";
const isCApeTokenAccount =
account.type === "TokenAccount" &&
account.token.contractAddress === "0xC5c9fB6223A989208Df27dCEE33fC59ff5c26fFF";

if (isApeTokenAccount || isCApeTokenAccount) {
return [
{
id: "stake",
navigationParams: [
ScreenName.PlatformApp,
{
params: {
platform: "stakekit",
name: "StakeKit",
accountId: account.id,
yieldId: isCApeTokenAccount
? "ethereum-ape-parax-staking"
: "ethereum-ape-native-staking",
},
},
],
label: <Trans i18nKey="account.stake" />,
Icon: IconsLegacy.CoinsMedium,
eventProperties: {
currency: "APE",
},
},
];
}

return [];
};

Expand Down
Loading