Skip to content

Commit

Permalink
feat(): enable ape and cape staking via stakekit
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-omni committed Oct 26, 2024
1 parent 77f01ea commit a45886b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
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

0 comments on commit a45886b

Please sign in to comment.