From a45886b353cd3ff665981451e5d98e7ec337bd2d Mon Sep 17 00:00:00 2001 From: Petar Todorovic Date: Sat, 26 Oct 2024 23:59:30 +0200 Subject: [PATCH] feat(): enable ape and cape staking via stakekit --- .../evm/AccountHeaderManageActions.ts | 28 ++++++++++++--- .../src/families/evm/accountActions.tsx | 36 +++++++++++++++++-- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/apps/ledger-live-desktop/src/renderer/families/evm/AccountHeaderManageActions.ts b/apps/ledger-live-desktop/src/renderer/families/evm/AccountHeaderManageActions.ts index 9a33815c923b..77837b5e8bfa 100644 --- a/apps/ledger-live-desktop/src/renderer/families/evm/AccountHeaderManageActions.ts +++ b/apps/ledger-live-desktop/src/renderer/families/evm/AccountHeaderManageActions.ts @@ -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; @@ -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)) { @@ -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", @@ -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", }, ]; diff --git a/apps/ledger-live-mobile/src/families/evm/accountActions.tsx b/apps/ledger-live-mobile/src/families/evm/accountActions.tsx index e7ebf10f6dd7..c60638d0d38d 100644 --- a/apps/ledger-live-mobile/src/families/evm/accountActions.tsx +++ b/apps/ledger-live-mobile/src/families/evm/accountActions.tsx @@ -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"; @@ -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; }; @@ -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: , + Icon: IconsLegacy.CoinsMedium, + eventProperties: { + currency: "APE", + }, + }, + ]; + } + return []; };