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

Fixes after review #31

Merged
merged 1 commit into from
Sep 3, 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
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@formatjs/intl-locale": "^3.0.0",
"@formatjs/intl-pluralrules": "^5.0.0",
"@formatjs/intl-relativetimeformat": "^11.1.8",
"@ledgerhq/coin-elrond": "workspace:^",
"@ledgerhq/coin-evm": "workspace:^",
"@ledgerhq/coin-framework": "workspace:^",
"@ledgerhq/devices": "workspace:*",
Expand Down
15 changes: 10 additions & 5 deletions apps/ledger-live-mobile/src/families/elrond/accountActions.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +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 { hasMinimumDelegableBalance } from "@ledgerhq/live-common/families/elrond/helpers";
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 { useElrondRandomizedValidators } from "@ledgerhq/live-common/families/elrond/react";
import { NavigatorName, ScreenName } from "~/const";

/*
* Declare the types for the properties and return payload.
Expand All @@ -36,7 +39,9 @@ const getMainActions = ({
/*
* Get a list of all the providers, randomize, and also the screen, conditionally, based on existing amount of delegations.
*/
const validators = useElrondRandomizedValidators();
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
Expand Up @@ -58,7 +58,7 @@ const PickAmount = (props: PickAmountPropsType) => {
};

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

/*
* Handle the ration selection callback.
Expand Down
17 changes: 15 additions & 2 deletions libs/coin-modules/coin-elrond/.unimportedrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
{
"entry": [],
"ignoreUnimported": []
"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", "lodash", "expect", "invariant"]
}
2 changes: 1 addition & 1 deletion libs/coin-modules/coin-elrond/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
coverageDirectory: "coverage",
collectCoverageFrom: ["src/**/*.ts"],
testEnvironment: "node",
testPathIgnorePatterns: ["lib/", "lib-es/", ".*\\.integ\\.test\\.[tj]s"],
testPathIgnorePatterns: ["lib/", "lib-es/", ".integration.test.ts"],
};
23 changes: 11 additions & 12 deletions libs/coin-modules/coin-elrond/src/bridge/js.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
import {
defaultUpdateTransaction,
makeAccountBridgeReceive,
makeScanAccounts,
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
import type { ElrondAccount, Transaction, TransactionStatus } from "../types";
import { getPreloadStrategy, preload, hydrate } from "../preload";
import { getTransactionStatus } from "../getTransactionStatus";
import { SignerContext } from "@ledgerhq/coin-framework/lib/signer";
import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
import { broadcast } from "../broadcast";
import { createTransaction } from "../createTransaction";
import { estimateMaxSpendable } from "../estimateMaxSpendable";
import { getTransactionStatus } from "../getTransactionStatus";
import resolver from "../hw-getAddress";
import { getPreloadStrategy, hydrate, preload } from "../preload";
import { prepareTransaction } from "../prepareTransaction";
import { sync } from "../synchronisation";
import { createTransaction } from "../createTransaction";
import { buildSignOperation } from "../signOperation";
import { broadcast } from "../broadcast";
import { getAccountShape } from "../synchronisation";
import {
assignFromAccountRaw,
assignToAccountRaw,
fromOperationExtraRaw,
toOperationExtraRaw,
} from "../serialization";
import { ElrondSigner } from "../signer";
import { SignerContext } from "@ledgerhq/coin-framework/lib/signer";
import resolver from "../hw-getAddress";
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
import { buildSignOperation } from "../signOperation";
import { getAccountShape, sync } from "../synchronisation";
import type { ElrondAccount, Transaction, TransactionStatus } from "../types";

export function buildCurrencyBridge(signerContext: SignerContext<ElrondSigner>): CurrencyBridge {
const getAddress = resolver(signerContext);
Expand Down
8 changes: 2 additions & 6 deletions libs/ledger-live-common/.unimportedrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,8 @@
"src/families/crypto_org/types.ts",
"src/families/elrond/banner.ts",
"src/families/elrond/constants.ts",
"src/families/elrond/helpers/denominate.ts",
"src/families/elrond/helpers/handleTransactionStatus.ts",
"src/families/elrond/helpers/hasMinimumDelegableBalance.ts",
"src/families/elrond/helpers/randomizeProviders.ts",
"src/families/elrond/js-estimateMaxSpendable.ts",
"src/families/elrond/preload.ts",
"src/families/elrond/helpers.ts",
"src/families/elrond/errors.ts",
"src/families/elrond/react.ts",
"src/families/elrond/types.ts",
"src/families/evm/banner.ts",
Expand Down
2 changes: 1 addition & 1 deletion libs/ledger-live-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"@ledgerhq/coin-algorand": "workspace:^",
"@ledgerhq/coin-bitcoin": "workspace:^",
"@ledgerhq/coin-cardano": "workspace:^",
"@ledgerhq/coin-elrond": "workspace:^",
"@ledgerhq/coin-evm": "workspace:^",
"@ledgerhq/coin-framework": "workspace:^",
"@ledgerhq/coin-near": "workspace:^",
Expand All @@ -149,7 +150,6 @@
"@ledgerhq/coin-tezos": "workspace:^",
"@ledgerhq/coin-tron": "workspace:^",
"@ledgerhq/coin-xrp": "workspace:^",
"@ledgerhq/coin-elrond": "workspace:^",
"@ledgerhq/crypto-icons-ui": "workspace:^",
"@ledgerhq/cryptoassets": "workspace:^",
"@ledgerhq/device-core": "workspace:^",
Expand Down
105 changes: 105 additions & 0 deletions libs/ledgerjs/packages/hw-app-elrond/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<img src="https://user-images.githubusercontent.com/4631227/191834116-59cf590e-25cc-4956-ae5c-812ea464f324.png" height="100" />

[GitHub](https://github.com/LedgerHQ/ledger-live/),
[Ledger Devs Discord](https://developers.ledger.com/discord-pro),
[Developer Portal](https://developers.ledger.com/)

## @ledgerhq/hw-app-elrond

Ledger Hardware Wallet Elrond JavaScript bindings.

***

## Are you adding Ledger support to your software wallet?

You may be using this package to communicate with the Elrond Nano App.

For a smooth and quick integration:

* See the developers’ documentation on the [Developer Portal](https://developers.ledger.com/docs/transport/overview/) and
* Go on [Discord](https://developers.ledger.com/discord-pro/) to chat with developer support and the developer community.

***

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

* [Elrond](#elrond)
* [Parameters](#parameters)
* [Examples](#examples)
* [getAppConfiguration](#getappconfiguration)
* [Examples](#examples-1)
* [getAddress](#getaddress)
* [Parameters](#parameters-1)
* [Examples](#examples-2)
* [setAddress](#setaddress)
* [Parameters](#parameters-2)
* [Examples](#examples-3)

### Elrond

Elrond API

#### Parameters

* `transport` **Transport**&#x20;
* `scrambleKey` (optional, default `"eGLD"`)

#### Examples

```javascript
import Elrond from "@ledgerhq/hw-app-elrond";
const elrond = new Elrond(transport)
```

#### getAppConfiguration

Get Elrond app configuration.

##### Examples

```javascript
const result = await elrond.getAppConfiguration();
const { contractData, accountIndex, addressIndex, version } = result;
```

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<any>** an object with a contractData, accountIndex, addressIndex, version

#### getAddress

Get Elrond address for a given BIP 32 path.

##### Parameters

* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
* `boolDisplay` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** optionally enable or not the display

##### Examples

```javascript
const result = await elrond.getAddress("44'/508'/0'/0'/0'");
const { publicKey, address } = result;
```

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{publicKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), address: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>** an object with a address

#### setAddress

Set Elrond address for a given BIP 32 path.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be changed in the rebranding PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, it wil.


##### Parameters

* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
* `display` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** optionally enable or not the display

##### Examples

```javascript
const result = await elrond.setAddress("44'/508'/0'/0/0");
result : Buffer;
```

Returns **any** an object with a address
9 changes: 8 additions & 1 deletion libs/ledgerjs/packages/hw-app-elrond/src/Elrond.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Transport from "@ledgerhq/hw-transport";
import BIPPath from "bip32-path";
import { Address } from "@multiversx/sdk-core";
import BIPPath from "bip32-path";

const CHUNK_SIZE = 150;
const CURVE_MASK = 0x80;
Expand All @@ -15,6 +15,13 @@ const SIGN_HASH_TX_INS = 0x07;
const SW_OK = 0x9000;
const SW_CANCEL = 0x6986;

/**
* Elrond API
*
* @example
* import Elrond from "@ledgerhq/hw-app-elrond";
* const elrond = new Elrond(transport)
*/
export default class Elrond {
transport: Transport;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"coin:algorand": "pnpm --filter coin-algorand",
"coin:bitcoin": "pnpm --filter coin-bitcoin",
"coin:cardano": "pnpm --filter coin-cardano",
"coin:elrond": "pnpm --filter coin-elrond",
"coin:evm": "pnpm --filter coin-evm",
"coin:framework": "pnpm --filter coin-framework",
"coin:tester": "pnpm --filter coin-tester",
Expand All @@ -76,7 +77,6 @@
"coin:tezos": "pnpm --filter coin-tezos",
"coin:tron": "pnpm --filter coin-tron",
"coin:xrp": "pnpm --filter coin-xrp",
"coin:elrond": "pnpm --filter coin-elrond",
"evm-tools": "pnpm --filter evm-tools",
"domain": "pnpm --filter domain-service",
"doc": "pnpm --filter docs",
Expand Down
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading