Skip to content

Commit

Permalink
[Tron] - tronResource not mandatory in accountActions component (#5958)
Browse files Browse the repository at this point in the history
* tronResource not mandatory in accountActions component

* no account actions for subAccounts

* changeset
  • Loading branch information
lvndry authored Jan 23, 2024
1 parent 040e591 commit a740084
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-mails-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

tronResource not mandatory in accountActions
109 changes: 55 additions & 54 deletions apps/ledger-live-mobile/src/families/tron/accountActions.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import { Trans } from "react-i18next";
import invariant from "invariant";
import type { Account } from "@ledgerhq/types-live";
import type { TronAccount } from "@ledgerhq/live-common/families/tron/types";
import { getLastVotedDate } from "@ledgerhq/live-common/families/tron/react";
import { IconsLegacy } from "@ledgerhq/native-ui";
import { NavigatorName, ScreenName } from "~/const";
import { ActionButtonEvent } from "~/components/FabActions";
import { isSubAccount } from "@ledgerhq/live-common/account/index";

const getSecondaryActions = ({
account,
Expand All @@ -15,71 +15,72 @@ const getSecondaryActions = ({
parentAccount: Account;
}): ActionButtonEvent[] => {
const { tronResources } = account;
invariant(tronResources, "tron resources required");
const { tronPower } = tronResources;
const tronPower = tronResources?.tronPower || 0;

const accountId = account.id;
const canVote = (tronPower || 0) > 0;
const canVote = tronPower > 0;
const lastVotedDate = getLastVotedDate(account as TronAccount);

return [
{
id: "freeze",
disabled: true,
navigationParams: [
NavigatorName.Freeze,
return isSubAccount(account)
? []
: [
{
screen: canVote ? ScreenName.FreezeAmount : ScreenName.FreezeInfo,
params: {
accountId,
},
id: "freeze",
disabled: true,
navigationParams: [
NavigatorName.Freeze,
{
screen: canVote ? ScreenName.FreezeAmount : ScreenName.FreezeInfo,
params: {
accountId,
},
},
],
label: <Trans i18nKey="tron.manage.freeze.title" />,
description: <Trans i18nKey="tron.manage.freeze.description" />,
Icon: IconsLegacy.FreezeMedium,
},
],
label: <Trans i18nKey="tron.manage.freeze.title" />,
description: <Trans i18nKey="tron.manage.freeze.description" />,
Icon: IconsLegacy.FreezeMedium,
},
{
id: "unfreeze",
disabled: true,
navigationParams: [
NavigatorName.Unfreeze,
{
screen: ScreenName.UnfreezeAmount,
params: {
accountId,
id: "unfreeze",
disabled: true,
navigationParams: [
NavigatorName.Unfreeze,
{
screen: ScreenName.UnfreezeAmount,
params: {
accountId,
},
},
],
label: <Trans i18nKey="tron.manage.unfreeze.title" />,
description: <Trans i18nKey="tron.manage.unfreeze.description" />,
Icon: IconsLegacy.UnfreezeMedium,
buttonProps: {
type: "main",
outline: false,
},
},
],
label: <Trans i18nKey="tron.manage.unfreeze.title" />,
description: <Trans i18nKey="tron.manage.unfreeze.description" />,
Icon: IconsLegacy.UnfreezeMedium,
buttonProps: {
type: "main",
outline: false,
},
},
{
id: "vote",
disabled: true,
navigationParams: [
NavigatorName.TronVoteFlow,
{
screen: lastVotedDate ? "VoteSelectValidator" : "VoteStarted",
params: {
accountId,
id: "vote",
disabled: true,
navigationParams: [
NavigatorName.TronVoteFlow,
{
screen: lastVotedDate ? "VoteSelectValidator" : "VoteStarted",
params: {
accountId,
},
},
],
label: <Trans i18nKey="tron.manage.vote.title" />,
description: <Trans i18nKey="tron.manage.vote.description" />,
Icon: IconsLegacy.VoteMedium,
buttonProps: {
type: "main",
outline: false,
},
},
],
label: <Trans i18nKey="tron.manage.vote.title" />,
description: <Trans i18nKey="tron.manage.vote.description" />,
Icon: IconsLegacy.VoteMedium,
buttonProps: {
type: "main",
outline: false,
},
},
];
];
};

export default {
Expand Down

0 comments on commit a740084

Please sign in to comment.