Skip to content

Commit

Permalink
Merge pull request #8600 from LedgerHQ/feat/add-dot-entrypoints
Browse files Browse the repository at this point in the history
CN-721: Add dot entrypoints
  • Loading branch information
adammino-ledger authored Dec 9, 2024
2 parents e7bd973 + fa184cc commit e4c35c8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 66 deletions.
6 changes: 6 additions & 0 deletions .changeset/great-baboons-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"ledger-live-desktop": minor
"live-mobile": minor
---

Change entrypoints for DOT so they open the Stakekit live app directly without modal
Original file line number Diff line number Diff line change
@@ -1,55 +1,45 @@
import { useCallback } from "react";
import { useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
import { SubAccount } from "@ledgerhq/types-live";
import {
hasExternalController,
hasExternalStash,
hasPendingOperationType,
} from "@ledgerhq/live-common/families/polkadot/logic";
import { isAccountEmpty, getMainAccount } from "@ledgerhq/live-common/account/index";
import { openModal } from "~/renderer/actions/modals";
import { getMainAccount } from "@ledgerhq/live-common/account/index";
import IconCoins from "~/renderer/icons/Coins";
import { PolkadotAccount } from "@ledgerhq/live-common/families/polkadot/types";
import { useGetStakeLabelLocaleBased } from "~/renderer/hooks/useGetStakeLabelLocaleBased";
import { useHistory } from "react-router";

type Props = {
account: PolkadotAccount | SubAccount;
parentAccount: PolkadotAccount | undefined | null;
source?: string;
};

const AccountHeaderManageActions = ({ account, parentAccount, source = "Account Page" }: Props) => {
const AccountHeaderManageActions = ({ account, parentAccount }: Props) => {
const { t } = useTranslation();
const label = useGetStakeLabelLocaleBased();
const dispatch = useDispatch();
const mainAccount = getMainAccount(account, parentAccount);
const { polkadotResources } = mainAccount;
const hasBondedBalance = polkadotResources.lockedBalance && polkadotResources.lockedBalance.gt(0);
const hasPendingBondOperation = hasPendingOperationType(mainAccount, "BOND");
const history = useHistory();
if (!polkadotResources || parentAccount) return null;

const onClick = useCallback(() => {
if (isAccountEmpty(mainAccount)) {
dispatch(
openModal("MODAL_NO_FUNDS_STAKE", {
account: mainAccount,
}),
);
} else if (hasBondedBalance || hasPendingBondOperation) {
dispatch(
openModal("MODAL_POLKADOT_MANAGE", {
account: mainAccount,
source,
}),
);
} else {
dispatch(
openModal("MODAL_POLKADOT_REWARDS_INFO", {
account: mainAccount,
}),
);
}
}, [mainAccount, hasBondedBalance, hasPendingBondOperation, dispatch, source]);
const onClick = () => {
history.push({
pathname: "/platform/stakekit",
state: {
yieldId: "polkadot-dot-validator-staking",
accountId: account.id,
returnTo:
account.type === "TokenAccount"
? `/account/${account.parentId}/${account.id}`
: `/account/${account.id}`,
},
});
};

const _hasExternalController = hasExternalController(mainAccount);
const _hasExternalStash = hasExternalStash(mainAccount);
Expand All @@ -72,7 +62,7 @@ const AccountHeaderManageActions = ({ account, parentAccount, source = "Account
return [
{
key: "Stake",
onClick: onClick,
onClick,
icon: IconCoins,
disabled: !manageEnabled,
label,
Expand Down
59 changes: 22 additions & 37 deletions apps/ledger-live-mobile/src/families/polkadot/accountActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
hasExternalStash,
hasPendingOperationType,
isElectionOpen,
isStash,
} from "@ledgerhq/live-common/families/polkadot/logic";
import { IconsLegacy } from "@ledgerhq/native-ui";
import { PolkadotAccount } from "@ledgerhq/live-common/families/polkadot/types";
Expand All @@ -29,7 +28,7 @@ const getMainActions = (args: {
parentAccount?: Account;
parentRoute?: RouteProp<ParamListBase, ScreenName>;
}): ActionButtonEvent[] | null => {
const { account, parentAccount, parentRoute } = args;
const { account, parentAccount } = args;
invariant(account.polkadotResources, "polkadot resources required");
const accountId = account.id;
const { lockedBalance } = account.polkadotResources || {};
Expand All @@ -45,43 +44,29 @@ const getMainActions = (args: {
return null;
}

const getNavigationParams = (): NavigationParamsType => {
if (!earnRewardsEnabled && !nominationEnabled) {
return [
NavigatorName.NoFundsFlow,
{
screen: ScreenName.NoFunds,
params: {
account,
parentAccount,
const navigationParams: NavigationParamsType =
!earnRewardsEnabled && !nominationEnabled
? [
NavigatorName.NoFundsFlow,
{
screen: ScreenName.NoFunds,
params: {
account,
parentAccount,
},
},
},
];
}
if (isStash(account)) {
return [
NavigatorName.PolkadotNominateFlow,
{
screen: ScreenName.PolkadotNominateSelectValidators,
params: {
accountId,
source: parentRoute,
]
: [
ScreenName.PlatformApp,
{
params: {
platform: "stakekit",
name: "StakeKit",
accountId,
yieldId: "polkadot-dot-validator-staking",
},
},
},
];
}
return [
NavigatorName.PolkadotBondFlow,
{
screen: ScreenName.PolkadotBondStarted,
params: {
accountId,
},
},
];
};

const navigationParams = getNavigationParams();
];

return [
{
Expand Down

0 comments on commit e4c35c8

Please sign in to comment.