Skip to content

Commit a578266

Browse files
feat: aleo operation details extra
1 parent 1a90cfc commit a578266

File tree

7 files changed

+99
-3
lines changed

7 files changed

+99
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ledgerhq/coin-aleo": minor
3+
"ledger-live-desktop": minor
4+
---
5+
6+
aleo operation details extra
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react";
2+
import { render, screen } from "tests/testSetup";
3+
import type { AleoOperation } from "@ledgerhq/live-common/families/aleo/types";
4+
import { ALEO_ACCOUNT_1 } from "../__mocks__/account.mock";
5+
import operationDetails from "../operationDetails";
6+
7+
const { OperationDetailsExtra } = operationDetails;
8+
9+
describe("OperationDetailsExtra", () => {
10+
it("should only render functionId and not expose transactionType or patched", () => {
11+
const mockOperation: AleoOperation = {
12+
...ALEO_ACCOUNT_1.operations[0],
13+
extra: {
14+
functionId: "transfer_public",
15+
transactionType: "public",
16+
patched: true,
17+
},
18+
};
19+
20+
render(<OperationDetailsExtra account={ALEO_ACCOUNT_1} operation={mockOperation} type="OUT" />);
21+
22+
expect(screen.getByText("transfer_public")).toBeInTheDocument();
23+
expect(screen.queryByText("transactionType")).not.toBeInTheDocument();
24+
expect(screen.queryByText("public")).not.toBeInTheDocument();
25+
expect(screen.queryByText("patched")).not.toBeInTheDocument();
26+
});
27+
});

apps/ledger-live-desktop/src/renderer/families/aleo/operationDetails.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import React from "react";
22
import { Trans } from "react-i18next";
33
import { Box, Text } from "@ledgerhq/react-ui/index";
4-
import type { AleoTransactionType } from "@ledgerhq/live-common/families/aleo/types";
4+
import { getOperationDetailsExtraFields } from "@ledgerhq/live-common/families/aleo/utils";
5+
import type {
6+
AleoAccount,
7+
AleoOperation,
8+
AleoTransactionType,
9+
} from "@ledgerhq/live-common/families/aleo/types";
10+
import Ellipsis from "~/renderer/components/Ellipsis";
11+
import {
12+
OpDetailsData,
13+
OpDetailsSection,
14+
OpDetailsTitle,
15+
} from "~/renderer/drawers/OperationDetails/styledComponents";
16+
import type { OperationDetailsExtraProps } from "~/renderer/families/types";
517
import type { AleoFamily } from "./types";
618

719
type OperationDetails = NonNullable<AleoFamily["operationDetails"]>;
@@ -28,6 +40,28 @@ const CustomMetadataCell: OperationDetails["customMetadataCell"] = props => {
2840
);
2941
};
3042

43+
const OperationDetailsExtra = ({
44+
operation,
45+
}: OperationDetailsExtraProps<AleoAccount, AleoOperation>) => {
46+
const extraFields = getOperationDetailsExtraFields(operation.extra);
47+
48+
return (
49+
<>
50+
{extraFields.map(item => (
51+
<OpDetailsSection key={item.key}>
52+
<OpDetailsTitle>
53+
<Trans i18nKey={`operationDetails.extra.${item.key}`} defaults={item.key} />
54+
</OpDetailsTitle>
55+
<OpDetailsData>
56+
<Ellipsis>{item.value}</Ellipsis>
57+
</OpDetailsData>
58+
</OpDetailsSection>
59+
))}
60+
</>
61+
);
62+
};
63+
3164
export default {
3265
customMetadataCell: CustomMetadataCell,
66+
OperationDetailsExtra,
3367
};

apps/ledger-live-desktop/static/i18n/en/app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,8 @@
17521752
"previousStakingNodeId": "Previous node ID",
17531753
"gasConsumed": "Gas consumed",
17541754
"gasUsed": "Gas used",
1755-
"gasLimit": "Gas limit"
1755+
"gasLimit": "Gas limit",
1756+
"functionId": "Function ID"
17561757
}
17571758
},
17581759
"operationList": {

libs/coin-modules/coin-aleo/src/logic/utils.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { getMockedOperation } from "../__tests__/fixtures/operation.fixture";
1515
import { getMockedPreparedRequestResponse } from "../__tests__/fixtures/sdk.fixture";
1616
import { getMockedTransaction } from "../__tests__/fixtures/transaction.fixture";
17-
import type { ProvableApi, AleoTransactionIntentData } from "../types";
17+
import type { AleoOperationExtra, ProvableApi, AleoTransactionIntentData } from "../types";
1818
import {
1919
getNetworkConfig,
2020
parseMicrocredits,
@@ -35,6 +35,7 @@ import {
3535
deserializeTransaction,
3636
mapTransactionIntentToSdkIntent,
3737
hasSpecificIntentData,
38+
getOperationDetailsExtraFields,
3839
} from "./utils";
3940

4041
jest.mock("@ledgerhq/cryptoassets/currencies");
@@ -974,3 +975,17 @@ describe("deserializeTransaction", () => {
974975
expect(() => deserializeTransaction(invalidJsonHex)).toThrow();
975976
});
976977
});
978+
979+
describe("getOperationDetailsExtraFields", () => {
980+
it("should return only the functionId field", () => {
981+
const extra = {
982+
functionId: "transfer_private_to_public",
983+
transactionType: "private",
984+
patched: true,
985+
} satisfies AleoOperationExtra;
986+
987+
const result = getOperationDetailsExtraFields(extra);
988+
989+
expect(result).toEqual([{ key: "functionId", value: "transfer_private_to_public" }]);
990+
});
991+
});

libs/coin-modules/coin-aleo/src/logic/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
AleoOperation,
1818
AleoTransactionType,
1919
EnrichedPrivateRecord,
20+
OperationDetailsExtraField,
2021
Transaction,
2122
TransactionType,
2223
ProvableApi,
@@ -26,6 +27,7 @@ import type {
2627
PreparedRequestResponse,
2728
AleoTransactionIntentData,
2829
AleoPublicTransaction,
30+
AleoOperationExtra,
2931
} from "../types";
3032

3133
export function parseMicrocredits(microcreditsU64: string): string {
@@ -356,3 +358,9 @@ export function serializeTransaction(tx: PreparedRequestResponse): string {
356358
export function deserializeTransaction(txHex: string): PreparedRequestResponse {
357359
return JSON.parse(Buffer.from(txHex, "hex").toString());
358360
}
361+
// this function is used to extract the fields that should be displayed in the operation details
362+
export const getOperationDetailsExtraFields = (
363+
extra: AleoOperationExtra,
364+
): OperationDetailsExtraField[] => {
365+
return [{ key: "functionId", value: extra.functionId }];
366+
};

libs/coin-modules/coin-aleo/src/types/bridge.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export type AleoOperationExtra = {
8484
patched?: boolean;
8585
};
8686

87+
export type OperationDetailsExtraField = {
88+
key: keyof AleoOperationExtra;
89+
value: string | number;
90+
};
91+
8792
export type AleoOperation = Operation<AleoOperationExtra>;
8893

8994
export type TransactionTransfer = Extract<

0 commit comments

Comments
 (0)