Skip to content

Commit

Permalink
Merge branch 'develop' into support/LIVE-7931-evm-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
hzheng-ledger committed Aug 16, 2023
2 parents 1536115 + 62310d6 commit c5130bf
Show file tree
Hide file tree
Showing 22 changed files with 312 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-llamas-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

fix cosmos amount string parser
17 changes: 16 additions & 1 deletion apps/ledger-live-desktop/cryptoassets.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
| lisk | LSK | NO | lisk |
| æternity | AE | NO | aeternity |

## Tokens (11431)
## Tokens (11446)
| parent currency | ticker | contract | name | status | ledger id |
|--|--|--|--|--|--|
| Algorand | ARCC | MESEJMPXKL7YUWEQGNRCKSLMQDKHOHWIZ3RBWP7BV4JDMUJXFUVQZWUBJM | Asia Reserve Currency Coin | countervalues disabled | algorand/asa/163650 |
Expand Down Expand Up @@ -8154,16 +8154,31 @@
| MultiversX | AERO | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | Aerovek | | elrond/esdt/4145524f2d343538626266 |
| MultiversX | ASH | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | AshSwap | | elrond/esdt/4153482d613634326431 |
| MultiversX | BHAT | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | BHNetwork | | elrond/esdt/424841542d633166646533 |
| MultiversX | INFRA | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | Bware | | elrond/esdt/494e4652412d343339383563 |
| MultiversX | CRU | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | CrustNetwork | | elrond/esdt/4352552d613566346161 |
| MultiversX | CYBER | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | CyberpunkCity | | elrond/esdt/43594245522d343839633163 |
| MultiversX | CHARGED | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | GoChargeTech | | elrond/esdt/434841524745442d373033353833 |
| MultiversX | HTM | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | Hatom | | elrond/esdt/48544d2d663531643535 |
| MultiversX | HSEGLD | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | HatomSEGLD | | elrond/esdt/485345474c442d633133613465 |
| MultiversX | ISET | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | IsengardToken | | elrond/esdt/495345542d383465353565 |
| MultiversX | ITHEUM | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | Itheum | | elrond/esdt/49544845554d2d646636663236 |
| MultiversX | KRO | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | Krogan | | elrond/esdt/4b524f2d646639376563 |
| MultiversX | LEGLD | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | LiquidEGLD | | elrond/esdt/4c45474c442d643734646139 |
| MultiversX | MEX | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | MEX | | elrond/esdt/4d45582d343535633537 |
| MultiversX | MOOVE | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | MOOVEProtocol | | elrond/esdt/4d4f4f56452d383735353339 |
| MultiversX | OFE | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | Ofero | | elrond/esdt/4f46452d323965623534 |
| MultiversX | ONE | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | OneDex | | elrond/esdt/4f4e452d663939353466 |
| MultiversX | PROTEO | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | Proteo | | elrond/esdt/50524f54454f2d306337333131 |
| MultiversX | QWT | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | QoWatt | | elrond/esdt/5157542d343661633031 |
| MultiversX | RARE | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | RARE | | elrond/esdt/524152452d393965386230 |
| MultiversX | SUPER | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | SUPER | | elrond/esdt/53555045522d353037616136 |
| MultiversX | SFIT | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | Sense4FIT | | elrond/esdt/534649542d616562633930 |
| MultiversX | SEGLD | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | StakedEGLD | | elrond/esdt/5345474c442d336164326430 |
| MultiversX | UTK | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | Utrust | | elrond/esdt/55544B2D326638306539 |
| MultiversX | WAM | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | WAM | | elrond/esdt/57414d2d353130653432 |
| MultiversX | WBTC | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | WrappedBTC | | elrond/esdt/574254432d353334396233 |
| MultiversX | BUSD | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | WrappedBUSD | | elrond/esdt/425553442d343062353765 |
| MultiversX | WETH | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | WrappedETH | | elrond/esdt/574554482d623463613239 |
| MultiversX | USDC | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | WrappedUSDC | | elrond/esdt/555344432d633736663166 |
| MultiversX | USDT | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | WrappedUSDT | | elrond/esdt/555344542d663863303863 |
| MultiversX | ZPAY | erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u | ZoidPay | | elrond/esdt/5a5041592d323437383735 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import React, { useState } from "react";
import React, { Fragment, useState } from "react";
import { ElrondAccount } from "@ledgerhq/live-common/families/elrond/types";
import { Trans, useTranslation } from "react-i18next";
import { SubAccount } from "@ledgerhq/types-live";
import styled from "styled-components";

import Box, { Card } from "~/renderer/components/Box";
import Text from "~/renderer/components/Text";
import Button from "~/renderer/components/Button";
import ChevronRight from "~/renderer/icons/ChevronRight";
import InfoCircle from "~/renderer/icons/InfoCircle";
import AccountSubHeaderDrawer from "~/renderer/components/AccountSubHeader/AccountSubHeaderDrawer";
import Alert from "~/renderer/components/Alert";

export interface AccountSubHeaderPropsType {
account: ElrondAccount | SubAccount;
}

const CardContent = styled(Box)`
display: flex;
flex-direction: row;
Expand All @@ -29,42 +38,57 @@ const CustomButton = styled(Button)`
border: none;
padding-right: 14px;
`;
const AccountSubHeader = () => {
const AccountSubHeader = ({ account }: AccountSubHeaderPropsType) => {
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const { t } = useTranslation();

const isGuarded =
account.type === "Account" && account.elrondResources
? account.elrondResources.isGuarded
: false;

const openDrawer = () => {
setIsDrawerOpen(true);
};
const closeDrawer = () => {
setIsDrawerOpen(false);
};

return (
<Card px={2} py={1} mb={3}>
<CardContent>
<CardHeaderContainer>
<InfoCircle size={12} />
<Fragment>
<Card px={2} py={1} mb={3}>
<CardContent>
<CardHeaderContainer>
<InfoCircle size={12} />

<CardHeader>{t("elrond.account.subHeader.cardTitle")}</CardHeader>
</CardHeaderContainer>

<CardHeader>{t("elrond.account.subHeader.cardTitle")}</CardHeader>
</CardHeaderContainer>
<CustomButton outline={true} onClick={openDrawer}>
<Box horizontal={true} flow={1} alignItems="center">
<Box fontSize={3}>
<Trans i18nKey="elrond.account.subHeader.moreInfo" />
</Box>

<CustomButton outline={true} onClick={openDrawer}>
<Box horizontal={true} flow={1} alignItems="center">
<Box fontSize={3}>
<Trans i18nKey="elrond.account.subHeader.moreInfo" />
<ChevronRight size={12} />
</Box>
</CustomButton>
</CardContent>

<ChevronRight size={12} />
</Box>
</CustomButton>
</CardContent>
<AccountSubHeaderDrawer
isOpen={isDrawerOpen}
closeDrawer={closeDrawer}
team="MultiversX"
family="MultiversX"
/>
</Card>

<AccountSubHeaderDrawer
isOpen={isDrawerOpen}
closeDrawer={closeDrawer}
team="MultiversX"
family="MultiversX"
/>
</Card>
{isGuarded && (
<Alert type="warning" mb={3}>
<Trans i18nKey={`elrond.guardedAccountWarning`} />
</Alert>
)}
</Fragment>
);
};
export default AccountSubHeader;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ interface State {
const INITIAL_STATE: State = {
stepId: "withdraw",
};
class ClaimRewardsModal extends PureComponent<Data, State> {

class WithdrawModal extends PureComponent<Data, State> {
state: State = INITIAL_STATE;
handleReset = () => this.setState({ ...INITIAL_STATE });

Expand All @@ -23,7 +24,7 @@ class ClaimRewardsModal extends PureComponent<Data, State> {
const isModalLocked = ["connectDevice", "confirmation"].includes(stepId);
return (
<Modal
name="MODAL_ELROND_CLAIM_REWARDS"
name="MODAL_ELROND_WITHDRAW"
centered
onHide={this.handleReset}
preventBackdropClick={isModalLocked}
Expand All @@ -39,4 +40,4 @@ class ClaimRewardsModal extends PureComponent<Data, State> {
);
}
}
export default ClaimRewardsModal;
export default WithdrawModal;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TransactionStatus,
} from "@ledgerhq/live-common/families/elrond/types";
import { OpenModal } from "~/renderer/actions/modals";
export type StepId = "claimRewards" | "connectDevice" | "confirmation" | "withdraw";
export type StepId = "connectDevice" | "confirmation" | "withdraw";
export type StepProps = {
t: TFunction;
transitionTo: (param: string) => void;
Expand Down
1 change: 1 addition & 0 deletions apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,7 @@
"header": "Account allocation ({{count}})"
},
"elrond": {
"guardedAccountWarning": "If you have a guardian set on your account, you won't be able to successfully send transactions via Ledger Live.",
"summary": {
"availableBalanceTooltip": "This amount can be transferred.",
"availableBalance": "Available balance",
Expand Down
14 changes: 12 additions & 2 deletions apps/ledger-live-mobile/src/families/elrond/AccountSubHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import React from "react";
import React, { Fragment } from "react";
import { Trans } from "react-i18next";

import AccountSubHeader from "../../components/AccountSubHeader";
import Alert from "../../components/Alert";

/*
* Handle the component declaration.
*/

const ElrondAccountSubHeader = () => <AccountSubHeader family="MultiversX" team="MultiversX" />;
const ElrondAccountSubHeader = () => (
<Fragment>
<AccountSubHeader family="MultiversX" team="MultiversX" />

<Alert type="warning">
<Trans i18nKey={`elrond.guardedAccountWarning`} />
</Alert>
</Fragment>
);

export default ElrondAccountSubHeader;
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4893,6 +4893,7 @@
}
},
"elrond": {
"guardedAccountWarning": "If you have a guardian set on your account, you won't be able to successfully send transactions via Ledger Live.",
"info": {
"available": {
"title": "EGLD available",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7601,6 +7601,21 @@ Array [
"elrond/esdt/57414d2d353130653432",
"elrond/esdt/5a5041592d323437383735",
"elrond/esdt/49544845554d2d646636663236",
"elrond/esdt/434841524745442d373033353833",
"elrond/esdt/43594245522d343839633163",
"elrond/esdt/485345474c442d633133613465",
"elrond/esdt/48544d2d663531643535",
"elrond/esdt/494e4652412d343339383563",
"elrond/esdt/4b524f2d646639376563",
"elrond/esdt/4c45474c442d643734646139",
"elrond/esdt/4d4f4f56452d383735353339",
"elrond/esdt/4f46452d323965623534",
"elrond/esdt/4f4e452d663939353466",
"elrond/esdt/50524f54454f2d306337333131",
"elrond/esdt/524152452d393965386230",
"elrond/esdt/5345474c442d336164326430",
"elrond/esdt/574254432d353334396233",
"elrond/esdt/574554482d623463613239",
"cardano_testnet/native/47be64fcc8a7fe5321b976282ce4e43e4d29015f6613cfabcea28eab54657374",
"cardano/native/a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235484f534b59",
"cardano/native/af2e27f580f7f08e93190a81f72462f153026d06450924726645891b44524950",
Expand Down
15 changes: 15 additions & 0 deletions libs/ledger-live-common/src/families/cosmos/helpers.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getMainMessage } from "./helpers";
import { parseAmountStringToNumber } from "./logic";

describe("getMainMessage", () => {
it("should return delegate message with delegate and reward messages (claim rewards, compound)", () => {
Expand Down Expand Up @@ -61,3 +62,17 @@ describe("getMainMessage", () => {
).toEqual("redelegate");
});
});

describe("parseAmountStringToNumber", () => {
it("should remove suffix of amount string correctly", () => {
expect(parseAmountStringToNumber("1000000uatom", "uatom")).toEqual("1000000");
});
it("should remove prefix and suffix of amount string correctly", () => {
expect(
parseAmountStringToNumber(
"56ibc/0025F8A87464A471E66B234C4F93AEC5B4DA3D42D7986451A059273426290DD5,512ibc/6B8A3F5C2AD51CD6171FA41A7E8C35AD594AB69226438DB94450436EA57B3A89,10000uatom",
"uatom",
),
).toEqual("10000");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { encodeOperationId } from "../../operation";
import { CosmosDelegationInfo, CosmosMessage, CosmosTx } from "./types";
import type { Operation, OperationType } from "@ledgerhq/types-live";
import { getMainMessage } from "./helpers";
import { parseAmountStringToNumber } from "./logic";

const getBlankOperation = (tx, fees, id) => ({
id: "",
Expand Down Expand Up @@ -65,7 +66,7 @@ const txToOps = (info: AccountShapeInfo, accountId: string, txs: CosmosTx[]): Op
if (amount && sender && recipient && amount.endsWith(unitCode)) {
if (op.senders.indexOf(sender) === -1) op.senders.push(sender);
if (op.recipients.indexOf(recipient) === -1) op.recipients.push(recipient);
op.value = op.value.plus(amount.replace(unitCode, ""));
op.value = op.value.plus(parseAmountStringToNumber(amount, unitCode));
if (sender === address) {
op.type = "OUT";
} else if (recipient === address) {
Expand All @@ -86,11 +87,12 @@ const txToOps = (info: AccountShapeInfo, accountId: string, txs: CosmosTx[]): Op
const validator = message.attributes.find(attr => attr.key === "validator")?.value;
const amount = message.attributes.find(attr => attr.key === "amount")?.value;
if (validator && amount && amount.endsWith(unitCode)) {
const amountString = parseAmountStringToNumber(amount, unitCode);
rewardShards.push({
amount: new BigNumber(amount.replace(unitCode, "")),
amount: new BigNumber(amountString),
address: validator,
});
txRewardValue = txRewardValue.plus(amount.replace(unitCode, ""));
txRewardValue = txRewardValue.plus(amountString);
}
}
op.value = txRewardValue;
Expand All @@ -106,7 +108,7 @@ const txToOps = (info: AccountShapeInfo, accountId: string, txs: CosmosTx[]): Op
const validator = message.attributes.find(attr => attr.key === "validator")?.value;
if (amount && validator && amount.endsWith(unitCode)) {
delegateShards.push({
amount: new BigNumber(amount.replace(unitCode, "")),
amount: new BigNumber(parseAmountStringToNumber(amount, unitCode)),
address: validator,
});
}
Expand All @@ -129,7 +131,7 @@ const txToOps = (info: AccountShapeInfo, accountId: string, txs: CosmosTx[]): Op
if (amount && validatorDst && validatorSrc && amount.endsWith(unitCode)) {
op.extra.sourceValidator = validatorSrc;
redelegateShards.push({
amount: new BigNumber(amount.replace(unitCode, "")),
amount: new BigNumber(parseAmountStringToNumber(amount, unitCode)),
address: validatorDst,
});
}
Expand All @@ -146,7 +148,7 @@ const txToOps = (info: AccountShapeInfo, accountId: string, txs: CosmosTx[]): Op
const validator = message.attributes.find(attr => attr.key === "validator")?.value;
if (amount && validator && amount.endsWith(unitCode)) {
unbondShards.push({
amount: new BigNumber(amount.replace(unitCode, "")),
amount: new BigNumber(parseAmountStringToNumber(amount, unitCode)),
address: validator,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ describe("getAccountShape", () => {
},
],
},
{
type: "withdraw_rewards",
attributes: [
{
key: "amount",
value:
"56ibc/0025F8A87464A471E66B234C4F93AEC5B4DA3D42D7986451A059273426290DD5,512ibc/6B8A3F5C2AD51CD6171FA41A7E8C35AD594AB69226438DB94450436EA57B3A89,7uatom",
},
{
key: "validator",
value: "validatorAddressThree",
},
],
},
],
attributes: [],
},
Expand All @@ -314,7 +328,7 @@ describe("getAccountShape", () => {
});

const account = await getAccountShape(infoMock, syncConfig);
expect((account.operations as Operation[])[0].value).toEqual(new BigNumber(15));
expect((account.operations as Operation[])[0].value).toEqual(new BigNumber(22));
expect((account.operations as Operation[])[0].extra.validators).toEqual([
{
address: "validatorAddressHehe",
Expand All @@ -324,6 +338,10 @@ describe("getAccountShape", () => {
address: "validatorAddressTwo",
amount: new BigNumber(5),
},
{
address: "validatorAddressThree",
amount: new BigNumber(7),
},
]);
});

Expand Down
4 changes: 4 additions & 0 deletions libs/ledger-live-common/src/families/cosmos/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ export function getRedelegationCompletionDate(
const currentRedelegation = getRedelegation(account, delegation);
return currentRedelegation ? currentRedelegation.completionDate : null;
}

export function parseAmountStringToNumber(amountString: string, unitCode: string): string {
return amountString.slice(amountString.lastIndexOf(",") + 1).replace(unitCode, "");
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Array [
"derivationMode": "",
"elrondResources": Object {
"delegations": Array [],
"isGuarded": false,
"nonce": 3,
},
"freshAddress": "erd1vgfp3g7azqjx4wsmtt7067m0l62v3psmqzr24j6xvywj2tlz0gesvyzsq2",
Expand Down Expand Up @@ -39,6 +40,7 @@ Array [
"derivationMode": "",
"elrondResources": Object {
"delegations": Array [],
"isGuarded": false,
"nonce": 0,
},
"freshAddress": "erd1pm3gje2lmd5vyldcvuy6jpxgde4rapjpujvujkee6a7jw2zmh4tqre796z",
Expand Down
Loading

0 comments on commit c5130bf

Please sign in to comment.