Skip to content

Commit

Permalink
LIVE-8169: multiversx coin modularization (#7750)
Browse files Browse the repository at this point in the history
* create coin module package

* fix cosmos delegation flaky e2e test due to rounding error

* fix main.js file

---------

Co-authored-by: Alexandru Popenta <[email protected]>
  • Loading branch information
Wozacosta and popenta authored Sep 16, 2024
1 parent 51a32cc commit 8679584
Show file tree
Hide file tree
Showing 115 changed files with 2,032 additions and 825 deletions.
10 changes: 10 additions & 0 deletions .changeset/violet-planets-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@ledgerhq/hw-app-elrond": patch
"@ledgerhq/coin-elrond": patch
"@actions/turbo-affected": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
---

Move Multiversx/Elrond to its own module
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import { hasMinimumDelegableBalance } from "@ledgerhq/live-common/families/elrond/helpers/hasMinimumDelegableBalance";
import { hasMinimumDelegableBalance } from "@ledgerhq/live-common/families/elrond/helpers";
import { useElrondRandomizedValidators } from "@ledgerhq/live-common/families/elrond/react";
import { openModal } from "~/renderer/actions/modals";
import IconCoins from "~/renderer/icons/Coins";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Trans } from "react-i18next";
import styled from "styled-components";
import { BigNumber } from "bignumber.js";
import { useElrondRandomizedValidators } from "@ledgerhq/live-common/families/elrond/react";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { hasMinimumDelegableBalance } from "@ledgerhq/live-common/families/elrond/helpers/hasMinimumDelegableBalance";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { hasMinimumDelegableBalance } from "@ledgerhq/live-common/families/elrond/helpers";
import Text from "~/renderer/components/Text";
import Button from "~/renderer/components/Button";
import Box from "~/renderer/components/Box";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useMemo, Fragment, useCallback, ReactNode } from "react";
import { BigNumber } from "bignumber.js";
import { Trans } from "react-i18next";
import { useDispatch } from "react-redux";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import Box from "~/renderer/components/Box/Box";
import CheckCircle from "~/renderer/icons/CheckCircle";
import ToolTip from "~/renderer/components/Tooltip";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useCallback, useState, useEffect } from "react";
import { BigNumber } from "bignumber.js";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import Box from "~/renderer/components/Box";
import FirstLetterIcon from "~/renderer/components/FirstLetterIcon";
import Label from "~/renderer/components/Label";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Fragment, useCallback } from "react";
import { Trans } from "react-i18next";
import { BigNumber } from "bignumber.js";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import invariant from "invariant";
import TrackPage from "~/renderer/analytics/TrackPage";
import Box from "~/renderer/components/Box";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { Trans } from "react-i18next";
import styled from "styled-components";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { SyncOneAccountOnMount } from "@ledgerhq/live-common/bridge/react/index";
import TrackPage from "~/renderer/analytics/TrackPage";
import Box from "~/renderer/components/Box";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useState, useCallback } from "react";
import { useTranslation } from "react-i18next";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import FirstLetterIcon from "~/renderer/components/FirstLetterIcon";
import Box from "~/renderer/components/Box";
import Label from "~/renderer/components/Label";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback } from "react";
import { useTranslation, Trans } from "react-i18next";
import styled from "styled-components";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { SyncOneAccountOnMount } from "@ledgerhq/live-common/bridge/react/index";
import TrackPage from "~/renderer/analytics/TrackPage";
import Box from "~/renderer/components/Box";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useCallback, useState, useEffect } from "react";
import { BigNumber } from "bignumber.js";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import Box from "~/renderer/components/Box";
import FirstLetterIcon from "~/renderer/components/FirstLetterIcon";
import Label from "~/renderer/components/Label";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { Trans } from "react-i18next";
import styled from "styled-components";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { SyncOneAccountOnMount } from "@ledgerhq/live-common/bridge/react/index";
import TrackPage from "~/renderer/analytics/TrackPage";
import Box from "~/renderer/components/Box";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment, useCallback } from "react";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { Trans } from "react-i18next";
import { BigNumber } from "bignumber.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useCallback, useMemo, useEffect } from "react";
import { Trans } from "react-i18next";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { useDispatch } from "react-redux";
import Box from "~/renderer/components/Box/Box";
import ExclamationCircleThin from "~/renderer/icons/ExclamationCircleThin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ELROND_EXPLORER_URL,
ELROND_LEDGER_VALIDATOR_ADDRESS,
} from "@ledgerhq/live-common/families/elrond/constants";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { useElrondPreloadData } from "@ledgerhq/live-common/families/elrond/react";
import { ElrondProvider, ElrondOperation } from "@ledgerhq/live-common/families/elrond/types";
import { Account, Operation } from "@ledgerhq/types-live";
Expand Down
8 changes: 7 additions & 1 deletion apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "../../models/currencies";
import { Application } from "../../page";
import DeviceAction from "../../models/DeviceAction";
import BigNumber from "bignumber.js";

let app: Application;
let deviceAction: DeviceAction;
Expand Down Expand Up @@ -37,7 +38,12 @@ describe("Cosmos delegate flow", () => {
const unit = getAccountUnit(testAccount);

const usableAmount = testAccount.spendableBalance.minus(COSMOS_MIN_SAFE).minus(COSMOS_MIN_FEES);
const delegatedAmount = usableAmount.div(100 / delegatedPercent).integerValue();
// rounding to avoid floating point errors
// NOTE: we could allow for some precision error here to avoid rounding issues
const delegatedAmount = usableAmount
.multipliedBy(delegatedPercent)
.div(100)
.integerValue(BigNumber.ROUND_CEIL);
const remainingAmount = usableAmount.minus(delegatedAmount);

await app.stake.selectCurrency(testedCurrency);
Expand Down
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"@formatjs/intl-pluralrules": "^5.0.0",
"@formatjs/intl-relativetimeformat": "^11.1.8",
"@ledgerhq/coin-cosmos": "workspace:^",
"@ledgerhq/coin-elrond": "workspace:^",
"@ledgerhq/coin-evm": "workspace:^",
"@ledgerhq/coin-framework": "workspace:^",
"@ledgerhq/devices": "workspace:*",
Expand Down
13 changes: 8 additions & 5 deletions apps/ledger-live-mobile/src/families/elrond/accountActions.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from "react";
import {
hasMinimumDelegableBalance,
randomizeProviders,
} from "@ledgerhq/live-common/families/elrond/helpers";
import type { ElrondAccount } from "@ledgerhq/live-common/families/elrond/types";
import { getCurrentElrondPreloadData } from "@ledgerhq/live-common/families/elrond/preload";
import { randomizeProviders } from "@ledgerhq/live-common/families/elrond/helpers/randomizeProviders";
import { hasMinimumDelegableBalance } from "@ledgerhq/live-common/families/elrond/helpers/hasMinimumDelegableBalance";
import { IconsLegacy } from "@ledgerhq/native-ui";
import React from "react";
import { Trans } from "react-i18next";

import type { Account } from "@ledgerhq/types-live";
import type { ActionButtonEvent, NavigationParamsType } from "~/components/FabActions";

import { NavigatorName, ScreenName } from "~/const";
import { getCurrentElrondPreloadData } from "@ledgerhq/coin-elrond/preload";
import { ParamListBase, RouteProp } from "@react-navigation/native";
import { NavigatorName, ScreenName } from "~/const";

/*
* Declare the types for the properties and return payload.
Expand Down Expand Up @@ -39,6 +41,7 @@ const getMainActions = ({
*/
const preloaded = getCurrentElrondPreloadData();
const validators = randomizeProviders(preloaded.validators);

const isFirstTimeFlow =
account.elrondResources && account.elrondResources.delegations.length === 0;
const screen = isFirstTimeFlow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect, useMemo, useCallback, FC } from "react";
import { View } from "react-native";
import { BigNumber } from "bignumber.js";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { useElrondRandomizedValidators } from "@ledgerhq/live-common/families/elrond/react";

import type { ElrondProvider, ElrondAccount } from "@ledgerhq/live-common/families/elrond/types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { useCallback, useMemo } from "react";
import { useNavigation } from "@react-navigation/native";
import { useTranslation } from "react-i18next";
import { View } from "react-native";
import { hasMinimumDelegableBalance } from "@ledgerhq/live-common/families/elrond/helpers/hasMinimumDelegableBalance";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index";
import { hasMinimumDelegableBalance } from "@ledgerhq/live-common/families/elrond/helpers";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/coin-framework/account";
import BigNumber from "bignumber.js";
import type { StackNavigationProp } from "@react-navigation/stack";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTheme } from "@react-navigation/native";
import { useTranslation } from "react-i18next";
import { Text } from "@ledgerhq/native-ui";
import { BigNumber } from "bignumber.js";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { ELROND_LEDGER_VALIDATOR_ADDRESS } from "@ledgerhq/live-common/families/elrond/constants";

import CounterValue from "~/components/CounterValue";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { Linking } from "react-native";
import { getAddressExplorer, getDefaultExplorerView } from "@ledgerhq/live-common/explorers";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from "react";
import { useNavigation } from "@react-navigation/native";
import { View } from "react-native";
import { useTranslation } from "react-i18next";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/coin-framework/account";
import BigNumber from "bignumber.js";

import type { StackNavigationProp } from "@react-navigation/stack";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { View } from "react-native";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/coin-framework/account";

import AccountSectionLabel from "~/components/AccountSectionLabel";
import Unbonding from "./components/Unbonding";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback } from "react";
import { View, TouchableOpacity } from "react-native";
import { useTheme } from "@react-navigation/native";
import { Text } from "@ledgerhq/native-ui";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { useTranslation } from "react-i18next";
import { BigNumber } from "bignumber.js";
import { ELROND_LEDGER_VALIDATOR_ADDRESS } from "@ledgerhq/live-common/families/elrond/constants";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useTheme } from "@react-navigation/native";
import { Trans } from "react-i18next";
import { BigNumber } from "bignumber.js";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { handleTransactionStatus } from "@ledgerhq/live-common/families/elrond/helpers/handleTransactionStatus";
import { getMainAccount, getAccountCurrency } from "@ledgerhq/live-common/account/index";
import { handleTransactionStatus } from "@ledgerhq/live-common/families/elrond/helpers";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/coin-framework/account";
import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction";
import { MIN_DELEGATION_AMOUNT } from "@ledgerhq/live-common/families/elrond/constants";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useMemo, useCallback } from "react";
import { View, FlatList } from "react-native";
import { useTheme } from "@react-navigation/native";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { getMainAccount } from "@ledgerhq/live-common/account/index";
import { getMainAccount } from "@ledgerhq/coin-framework/account";

import BigNumber from "bignumber.js";
import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { View, Keyboard, TouchableOpacity, TouchableWithoutFeedback, Platform }
import { Trans } from "react-i18next";
import { BigNumber } from "bignumber.js";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index";
import { useTheme } from "styled-components/native";
import { MIN_DELEGATION_AMOUNT } from "@ledgerhq/live-common/families/elrond/constants";
import estimateMaxSpendable from "@ledgerhq/live-common/families/elrond/estimateMaxSpendable";

import type { Transaction } from "@ledgerhq/live-common/families/elrond/types";
import type { PickAmountPropsType, RatioType } from "./types";
Expand Down Expand Up @@ -47,7 +46,7 @@ const PickAmount = (props: PickAmountPropsType) => {

const getMaxSpendable = useCallback(() => {
const fetchMaxSpendable = async () => {
const amount = await estimateMaxSpendable({
const amount = await bridge.estimateMaxSpendable({
account,
transaction,
parentAccount: undefined,
Expand All @@ -59,7 +58,7 @@ const PickAmount = (props: PickAmountPropsType) => {
};

fetchMaxSpendable();
}, [transaction, account]);
}, [bridge, account, transaction]);

/*
* Handle the ration selection callback.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Image, View, Animated } from "react-native";
import { useTheme } from "@react-navigation/native";
import { SafeAreaView } from "react-native-safe-area-context";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { handleTransactionStatus } from "@ledgerhq/live-common/families/elrond/helpers/handleTransactionStatus";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { handleTransactionStatus } from "@ledgerhq/live-common/families/elrond/helpers";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/live-common/account/index";
import { getAccountCurrency, getMainAccount } from "@ledgerhq/coin-framework/account";
import { Text } from "@ledgerhq/native-ui";
import { Trans } from "react-i18next";
import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { View } from "react-native";
import { useSelector } from "react-redux";
import { Trans } from "react-i18next";
import { useTheme } from "@react-navigation/native";
import { getAccountCurrency } from "@ledgerhq/live-common/account/index";
import { getAccountCurrency } from "@ledgerhq/coin-framework/account";

import { accountScreenSelector } from "~/reducers/accounts";
import { TrackScreen, track } from "~/analytics";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { View, Keyboard, TouchableOpacity, TouchableWithoutFeedback, Platform }
import { Trans } from "react-i18next";
import { BigNumber } from "bignumber.js";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers/denominate";
import { denominate } from "@ledgerhq/live-common/families/elrond/helpers";
import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index";
import { useTheme } from "styled-components/native";
import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React, { useCallback, useMemo } from "react";
import { View } from "react-native";
import { Trans } from "react-i18next";
import { useTheme } from "@react-navigation/native";
import { handleTransactionStatus } from "@ledgerhq/live-common/families/elrond/helpers/handleTransactionStatus";
import { handleTransactionStatus } from "@ledgerhq/live-common/families/elrond/helpers";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { getMainAccount, getAccountCurrency } from "@ledgerhq/live-common/account/index";
import { getMainAccount, getAccountCurrency } from "@ledgerhq/coin-framework/account/helpers";
import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction";

import Button from "~/components/Button";
Expand Down
23 changes: 23 additions & 0 deletions libs/coin-modules/coin-elrond/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
env: {
browser: true,
es6: true,
},
rules: {
"no-console": ["error", { allow: ["warn", "error"] }],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "warn",
},
overrides: [
{
files: ["src/test/**/*.{ts,tsx}"],
env: {
"jest/globals": true,
},
plugins: ["jest"],
rules: {
"no-console": "off",
},
},
],
};
Loading

0 comments on commit 8679584

Please sign in to comment.