Skip to content

Commit

Permalink
create coin module package
Browse files Browse the repository at this point in the history
move files from ledger-live-common to new package

wip: updating files

fix files

adapt files and move hw-app to separate package

fixes after review

fixes after review

fixes

update generated files

change string representation to ascii for address

rename to elrond for easier integration

move dependency from devDependencies

add missing dependency

regenerate files and small comment fix

update snapshot

fixes after testing

fix ledger live imports

Update auto-generated files.

Update libs/coin-modules/coin-elrond/src/bridge/js.ts

Co-authored-by: Samy Rabah <rabah.m.samy@gmail.com>

Fix regression - passing the data field (MultiversX transactions).

Bit of refactoring. Add unit tests.

mobile import fixes

Fix displayed amount upon performing a "delegate" operation.

Add unit tests.

Fix types within tests.

fixes after review

regenerate pnpm-lock

fix pnpmlock

update unimported

log out flaky test
  • Loading branch information
popenta authored and Wozacosta committed Sep 4, 2024
1 parent 1825bd3 commit 811b272
Show file tree
Hide file tree
Showing 113 changed files with 2,528 additions and 910 deletions.
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
6 changes: 6 additions & 0 deletions apps/ledger-live-mobile/e2e/specs/delegate/cosmos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ describe("Cosmos delegate flow", () => {
const usableAmount = testAccount.spendableBalance.minus(COSMOS_MIN_SAFE).minus(COSMOS_MIN_FEES);
const delegatedAmount = usableAmount.div(100 / delegatedPercent).integerValue();
const remainingAmount = usableAmount.minus(delegatedAmount);
console.log({ usableAmount, delegatedAmount, remainingAmount });
console.log({
usableAmount: usableAmount.toString(),
delegatedAmount: delegatedAmount.toString(),
remainingAmount: remainingAmount.toString(),
});

await app.stake.selectCurrency(testedCurrency);
await app.common.selectAccount(testAccount.id);
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",
},
},
],
};
29 changes: 29 additions & 0 deletions libs/coin-modules/coin-elrond/.unimportedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"entry": [
"src/index.ts",
"src/bridge/js.ts",
"src/network/index.ts",
"src/signer.ts"
],
"ignoreUnimported": [
"src/cli-transaction.ts",
"src/datasets/elrond1.ts",
"src/deviceTransactionConfig.ts",
"src/formatters.ts",
"src/helpers/denominate.ts",
"src/helpers/handleTransactionStatus.ts",
"src/helpers/hasMinimumDelegableBalance.ts",
"src/helpers/randomizeProviders.ts",
"src/specs.ts",
"src/speculos-deviceActions.ts",
"src/transaction.ts"
],
"ignoreUnused": [
"@ledgerhq/devices",
"@ledgerhq/live-promise",
"expect",
"invariant",
"lodash"
],
"ignoreUnresolved": []
}
8 changes: 8 additions & 0 deletions libs/coin-modules/coin-elrond/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
coverageDirectory: "coverage",
collectCoverageFrom: ["src/**/*.ts"],
testEnvironment: "node",
testPathIgnorePatterns: ["lib/", "lib-es/", ".integration.test.ts"],
};
Loading

0 comments on commit 811b272

Please sign in to comment.