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

[support] Minor code improvements on the Celo integration #3919

Merged
merged 3 commits into from
Jul 18, 2023
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getAddressExplorer, getDefaultExplorerView } from "@ledgerhq/live-common/explorers";
import React, { useCallback } from "react";
import { Trans } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";
import { useDispatch } from "react-redux";
import { urls } from "~/config/urls";
import { openModal } from "~/renderer/actions/modals";
import Alert from "~/renderer/components/Alert";
Expand All @@ -12,7 +12,6 @@ import TableContainer, { TableHeader } from "~/renderer/components/TableContaine
import Text from "~/renderer/components/Text";
import IconChartLine from "~/renderer/icons/ChartLine";
import { openURL } from "~/renderer/linking";
import { accountsSelector } from "~/renderer/reducers/accounts";
import { Header } from "./Header";
import { Row } from "./Row";
import {
Expand All @@ -28,11 +27,11 @@ type Props = {
account: CeloAccount;
};
const AccountBodyHeaderComponent = ({ account }: Props) => {
const { celoResources } = account;
const {
celoResources: { votes },
} = account;
const dispatch = useDispatch();
const accounts = useSelector(accountsSelector) as CeloAccount[]; // FIXME: how to not cast here ?
const isRegistrationPending = isAccountRegistrationPending(account?.id, accounts);
const { votes } = celoResources;
const isRegistrationPending = isAccountRegistrationPending(account);
const onEarnRewards = useCallback(() => {
dispatch(
openModal("MODAL_CELO_REWARDS_INFO", {
Expand Down Expand Up @@ -116,7 +115,7 @@ const AccountBodyHeaderComponent = ({ account }: Props) => {
{votes.map(vote => (
<Row
vote={vote}
key={vote.validatorGroup + vote.index}
key={`${vote.validatorGroup}${vote.index}`}
account={account}
onManageAction={onRedirect}
onExternalLink={onExternalLink}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,7 @@ export const Row = ({ account, vote, onManageAction, onExternalLink }: Props) =>
{actions.length > 0 && <ManageDropDown actions={actions} onSelect={onSelect} />}
{actions.length === 0 && (
<S.ManageInfoIconWrapper>
<Tooltip
content={
<Trans
i18nKey={"celo.delegation.manageMultipleVoteWarning"}
count={2}
values={{
count: 2,
}}
/>
}
>
<Tooltip content={<Trans i18nKey={"celo.delegation.manageMultipleVoteWarning"} />}>
<IconInfoCircle />
</Tooltip>
</S.ManageInfoIconWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { isAccountRegistrationPending } from "@ledgerhq/live-common/families/cel
import { CeloAccount } from "@ledgerhq/live-common/families/celo/types";
import React, { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";
import { useDispatch } from "react-redux";
import { openModal } from "~/renderer/actions/modals";
import { accountsSelector } from "~/renderer/reducers/accounts";
import { IconType } from "../../types";
import { CeloFamily } from "../types";
import Icon from "./Icon";
Expand All @@ -17,8 +16,7 @@ const AccountHeaderManageActions: CeloFamily["accountHeaderManageActions"] = ({
}) => {
const { t } = useTranslation();
const dispatch = useDispatch();
const accounts = useSelector(accountsSelector) as CeloAccount[]; // FIXME: Celo Account
const isRegistrationPending = isAccountRegistrationPending(account.id, accounts);
const isRegistrationPending = isAccountRegistrationPending(account as CeloAccount);
const onClick = useCallback(() => {
if (isAccountEmpty(account)) {
dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ const OperationDetailsExtra = ({
: null;
return (
<>
{type !== "ACTIVATE" && (
{type !== "ACTIVATE" && operation.extra && operation.extra.celoOperationValue && (
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey={`operation.type.${type}`} />
</OpDetailsTitle>
<OpDetailsData>
<Box>
<FormattedVal
val={operation.extra.celoOperationValue}
val={operation.extra.celoOperationValue.toFixed()}
unit={account.unit}
showCode
fontSize={4}
Expand Down Expand Up @@ -87,22 +87,24 @@ const OperationDetailsExtra = ({
case "UNLOCK":
return (
<>
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey={`operation.type.${type}`} />
</OpDetailsTitle>
<OpDetailsData>
<Box>
<FormattedVal
val={operation.extra.celoOperationValue}
unit={account.unit}
showCode
fontSize={4}
color="palette.text.shade60"
/>
</Box>
</OpDetailsData>
</OpDetailsSection>
{operation.extra && operation.extra.celoOperationValue && (
<OpDetailsSection>
<OpDetailsTitle>
<Trans i18nKey={`operation.type.${type}`} />
</OpDetailsTitle>
<OpDetailsData>
<Box>
<FormattedVal
val={operation.extra.celoOperationValue.toFixed()}
unit={account.unit}
showCode
fontSize={4}
color="palette.text.shade60"
/>
</Box>
</OpDetailsData>
</OpDetailsSection>
)}
</>
);
default:
Expand Down
20 changes: 20 additions & 0 deletions libs/ledger-live-common/src/families/celo/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { BigNumber } from "bignumber.js";

export function fromOperationExtraRaw(extra: Record<string, any> | null | undefined) {
if (extra && extra.celoOperationValue) {
return { ...extra, celoOperationValue: new BigNumber(extra.celoOperationValue) };
}
return extra;
}

export function toOperationExtraRaw(extra: Record<string, any> | null | undefined) {
if (extra && extra.celoOperationValue) {
return { ...extra, celoOperationValue: extra.celoOperationValue.toString() };
}
return extra;
}

export default {
fromOperationExtraRaw,
toOperationExtraRaw,
};
6 changes: 1 addition & 5 deletions libs/ledger-live-common/src/families/celo/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ export const fallbackValidatorGroup = (address: string): CeloValidatorGroup => (
votes: new BigNumber(0),
});

export const isAccountRegistrationPending = (
accountId: string,
accounts: CeloAccount[],
): boolean => {
export const isAccountRegistrationPending = (account: CeloAccount): boolean => {
// If there's a pending "REGISTER" operation and the
// account's registration status is false, then
// we know that the account is truly not registered yet.
const account = accounts.find(currentAccount => accountId === currentAccount.id);

const isAccountRegistrationPending =
!!account &&
Expand Down
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/generated/account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bitcoin from "../families/bitcoin/account";
import celo from "../families/celo/account";
import cosmos from "../families/cosmos/account";
import crypto_org from "../families/crypto_org/account";
import elrond from "../families/elrond/account";
Expand All @@ -11,6 +12,7 @@ import polkadot from "@ledgerhq/coin-polkadot/account";

export default {
bitcoin,
celo,
cosmos,
crypto_org,
elrond,
Expand Down
Loading