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

CN-721: Add dot entrypoints #8600

Merged
merged 7 commits into from
Dec 9, 2024
Merged
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
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
Loading