@ledgerhq/live-common 34.47.0-nightly.3 → 34.47.0-nightly.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bridge/crypto-assets/cal-store.d.ts.map +1 -1
- package/lib/bridge/crypto-assets/cal-store.js +21 -5
- package/lib/bridge/crypto-assets/cal-store.js.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/index.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/index.js +6 -1
- package/lib/bridge/generic-alpaca/alpaca/index.js.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/index.unit.test.d.ts +2 -0
- package/lib/bridge/generic-alpaca/alpaca/index.unit.test.d.ts.map +1 -0
- package/lib/bridge/generic-alpaca/alpaca/index.unit.test.js +89 -0
- package/lib/bridge/generic-alpaca/alpaca/index.unit.test.js.map +1 -0
- package/lib/bridge/generic-alpaca/utils.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/utils.js +5 -2
- package/lib/bridge/generic-alpaca/utils.js.map +1 -1
- package/lib/bridge/generic-alpaca/utils.test.d.ts.map +1 -0
- package/lib/bridge/generic-alpaca/utils.test.js +86 -0
- package/lib/bridge/generic-alpaca/utils.test.js.map +1 -0
- package/lib/e2e/speculos.js +3 -3
- package/lib/e2e/speculos.js.map +1 -1
- package/lib-es/bridge/crypto-assets/cal-store.d.ts.map +1 -1
- package/lib-es/bridge/crypto-assets/cal-store.js +21 -5
- package/lib-es/bridge/crypto-assets/cal-store.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.js +6 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.unit.test.d.ts +2 -0
- package/lib-es/bridge/generic-alpaca/alpaca/index.unit.test.d.ts.map +1 -0
- package/lib-es/bridge/generic-alpaca/alpaca/index.unit.test.js +64 -0
- package/lib-es/bridge/generic-alpaca/alpaca/index.unit.test.js.map +1 -0
- package/lib-es/bridge/generic-alpaca/utils.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/utils.js +5 -2
- package/lib-es/bridge/generic-alpaca/utils.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/utils.test.d.ts.map +1 -0
- package/lib-es/bridge/generic-alpaca/utils.test.js +81 -0
- package/lib-es/bridge/generic-alpaca/utils.test.js.map +1 -0
- package/lib-es/e2e/speculos.js +3 -3
- package/lib-es/e2e/speculos.js.map +1 -1
- package/package.json +15 -15
- package/src/bridge/crypto-assets/cal-store.ts +22 -5
- package/src/bridge/generic-alpaca/alpaca/index.ts +14 -1
- package/src/bridge/generic-alpaca/alpaca/index.unit.test.ts +78 -0
- package/src/bridge/generic-alpaca/utils.test.ts +93 -0
- package/src/bridge/generic-alpaca/utils.ts +5 -2
- package/src/e2e/speculos.ts +3 -3
- package/lib/bridge/generic-alpaca/tests/utils.test.d.ts.map +0 -1
- package/lib/bridge/generic-alpaca/tests/utils.test.js +0 -20
- package/lib/bridge/generic-alpaca/tests/utils.test.js.map +0 -1
- package/lib-es/bridge/generic-alpaca/tests/utils.test.d.ts.map +0 -1
- package/lib-es/bridge/generic-alpaca/tests/utils.test.js +0 -18
- package/lib-es/bridge/generic-alpaca/tests/utils.test.js.map +0 -1
- package/src/bridge/generic-alpaca/tests/utils.test.ts +0 -19
- /package/lib/bridge/generic-alpaca/{tests/utils.test.d.ts → utils.test.d.ts} +0 -0
- /package/lib-es/bridge/generic-alpaca/{tests/utils.test.d.ts → utils.test.d.ts} +0 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
import { adaptCoreOperationToLiveOperation, extractBalance } from "./utils";
|
2
|
+
import BigNumber from "bignumber.js";
|
3
|
+
import { Operation as CoreOperation } from "@ledgerhq/coin-framework/api/types";
|
4
|
+
|
5
|
+
describe("Alpaca utils", () => {
|
6
|
+
describe("extractBalance", () => {
|
7
|
+
it("extracts an existing balance", () => {
|
8
|
+
expect(extractBalance([{ value: 4n, asset: { type: "type1" } }], "type1")).toEqual({
|
9
|
+
value: 4n,
|
10
|
+
asset: { type: "type1" },
|
11
|
+
});
|
12
|
+
});
|
13
|
+
|
14
|
+
it("generates an empty balance for a missing type", () => {
|
15
|
+
expect(extractBalance([{ value: 4n, asset: { type: "type1" } }], "type2")).toEqual({
|
16
|
+
value: 0n,
|
17
|
+
asset: { type: "type2" },
|
18
|
+
});
|
19
|
+
});
|
20
|
+
});
|
21
|
+
|
22
|
+
jest.mock("@ledgerhq/coin-framework/operation", () => ({
|
23
|
+
encodeOperationId: jest.fn((accountId, txHash, opType) => `${accountId}-${txHash}-${opType}`),
|
24
|
+
}));
|
25
|
+
|
26
|
+
describe("adaptCoreOperationToLiveOperation", () => {
|
27
|
+
const accountId = "acc_123";
|
28
|
+
const baseOp: CoreOperation = {
|
29
|
+
id: "op_123",
|
30
|
+
asset: { type: "native" },
|
31
|
+
type: "OUT",
|
32
|
+
value: BigInt(100),
|
33
|
+
tx: {
|
34
|
+
hash: "txhash123",
|
35
|
+
fees: BigInt(10),
|
36
|
+
block: {
|
37
|
+
hash: "blockhash123",
|
38
|
+
height: 123456,
|
39
|
+
},
|
40
|
+
date: new Date("2025-08-29T12:00:00Z"),
|
41
|
+
},
|
42
|
+
senders: ["sender1"],
|
43
|
+
recipients: ["recipient1"],
|
44
|
+
};
|
45
|
+
|
46
|
+
it("adapts a basic OUT operation", () => {
|
47
|
+
const result = adaptCoreOperationToLiveOperation(accountId, baseOp);
|
48
|
+
|
49
|
+
expect(result).toEqual({
|
50
|
+
id: "acc_123-txhash123-OUT",
|
51
|
+
hash: "txhash123",
|
52
|
+
accountId,
|
53
|
+
type: "OUT",
|
54
|
+
value: new BigNumber(110), // value + fee
|
55
|
+
fee: new BigNumber(10),
|
56
|
+
blockHash: "blockhash123",
|
57
|
+
blockHeight: 123456,
|
58
|
+
senders: ["sender1"],
|
59
|
+
recipients: ["recipient1"],
|
60
|
+
date: new Date("2025-08-29T12:00:00Z"),
|
61
|
+
transactionSequenceNumber: undefined,
|
62
|
+
hasFailed: false,
|
63
|
+
extra: {},
|
64
|
+
});
|
65
|
+
});
|
66
|
+
|
67
|
+
it("handles FEES operation where value = value + fees", () => {
|
68
|
+
const op = {
|
69
|
+
...baseOp,
|
70
|
+
type: "FEES",
|
71
|
+
value: BigInt(5),
|
72
|
+
tx: { ...baseOp.tx, fees: BigInt(2) },
|
73
|
+
};
|
74
|
+
|
75
|
+
const result = adaptCoreOperationToLiveOperation(accountId, op);
|
76
|
+
|
77
|
+
expect(result.value.toString()).toEqual("7");
|
78
|
+
});
|
79
|
+
|
80
|
+
it("handles non-FEES/OUT operation where value = value only", () => {
|
81
|
+
const op = {
|
82
|
+
...baseOp,
|
83
|
+
type: "IN",
|
84
|
+
value: BigInt(50),
|
85
|
+
tx: { ...baseOp.tx, fees: BigInt(2) },
|
86
|
+
};
|
87
|
+
|
88
|
+
const result = adaptCoreOperationToLiveOperation(accountId, op);
|
89
|
+
|
90
|
+
expect(result.value.toString()).toEqual("50");
|
91
|
+
});
|
92
|
+
});
|
93
|
+
});
|
@@ -44,6 +44,7 @@ export function adaptCoreOperationToLiveOperation(accountId: string, op: CoreOpe
|
|
44
44
|
if (op.details?.memo) {
|
45
45
|
extra.memo = op.details.memo as string;
|
46
46
|
}
|
47
|
+
const bnFees = new BigNumber(op.tx.fees.toString());
|
47
48
|
const res = {
|
48
49
|
id: extra.ledgerOpType
|
49
50
|
? encodeOperationId(accountId, op.tx.hash, extra.ledgerOpType)
|
@@ -51,8 +52,10 @@ export function adaptCoreOperationToLiveOperation(accountId: string, op: CoreOpe
|
|
51
52
|
hash: op.tx.hash,
|
52
53
|
accountId,
|
53
54
|
type: opType,
|
54
|
-
value:
|
55
|
-
|
55
|
+
value: ["OUT", "FEES"].includes(opType)
|
56
|
+
? new BigNumber(op.value.toString()).plus(bnFees)
|
57
|
+
: new BigNumber(op.value.toString()),
|
58
|
+
fee: bnFees,
|
56
59
|
blockHash: op.tx.block.hash,
|
57
60
|
blockHeight: op.tx.block.height,
|
58
61
|
senders: op.senders,
|
package/src/e2e/speculos.ts
CHANGED
@@ -731,14 +731,14 @@ export async function signDelegationTransaction(delegatingAccount: Delegate) {
|
|
731
731
|
}
|
732
732
|
|
733
733
|
export async function verifyAmountsAndAcceptSwap(swap: Swap, amount: string) {
|
734
|
-
await waitFor(DeviceLabels.
|
735
|
-
const events = await pressUntilTextFound(DeviceLabels.
|
734
|
+
await waitFor(DeviceLabels.REVIEW_TRANSACTION);
|
735
|
+
const events = await pressUntilTextFound(DeviceLabels.SIGN_TRANSACTION);
|
736
736
|
await verifySwapData(swap, events, amount);
|
737
737
|
await pressBoth();
|
738
738
|
}
|
739
739
|
|
740
740
|
export async function verifyAmountsAndRejectSwap(swap: Swap, amount: string) {
|
741
|
-
await waitFor(DeviceLabels.
|
741
|
+
await waitFor(DeviceLabels.REVIEW_TRANSACTION);
|
742
742
|
const events = await pressUntilTextFound(DeviceLabels.REJECT);
|
743
743
|
await verifySwapData(swap, events, amount);
|
744
744
|
await pressBoth();
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../../../src/bridge/generic-alpaca/tests/utils.test.ts"],"names":[],"mappings":""}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const utils_1 = require("../utils");
|
4
|
-
describe("Alpaca utils", () => {
|
5
|
-
describe("extractBalance", () => {
|
6
|
-
it("extracts an existing balance", () => {
|
7
|
-
expect((0, utils_1.extractBalance)([{ value: 4n, asset: { type: "type1" } }], "type1")).toEqual({
|
8
|
-
value: 4n,
|
9
|
-
asset: { type: "type1" },
|
10
|
-
});
|
11
|
-
});
|
12
|
-
it("generates an empty balance for a missing type", () => {
|
13
|
-
expect((0, utils_1.extractBalance)([{ value: 4n, asset: { type: "type1" } }], "type2")).toEqual({
|
14
|
-
value: 0n,
|
15
|
-
asset: { type: "type2" },
|
16
|
-
});
|
17
|
-
});
|
18
|
-
});
|
19
|
-
});
|
20
|
-
//# sourceMappingURL=utils.test.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../../../src/bridge/generic-alpaca/tests/utils.test.ts"],"names":[],"mappings":";;AAAA,oCAA0C;AAE1C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,MAAM,CAAC,IAAA,sBAAc,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;gBACjF,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;aACzB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;YACvD,MAAM,CAAC,IAAA,sBAAc,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;gBACjF,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;aACzB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../../../src/bridge/generic-alpaca/tests/utils.test.ts"],"names":[],"mappings":""}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { extractBalance } from "../utils";
|
2
|
-
describe("Alpaca utils", () => {
|
3
|
-
describe("extractBalance", () => {
|
4
|
-
it("extracts an existing balance", () => {
|
5
|
-
expect(extractBalance([{ value: 4n, asset: { type: "type1" } }], "type1")).toEqual({
|
6
|
-
value: 4n,
|
7
|
-
asset: { type: "type1" },
|
8
|
-
});
|
9
|
-
});
|
10
|
-
it("generates an empty balance for a missing type", () => {
|
11
|
-
expect(extractBalance([{ value: 4n, asset: { type: "type1" } }], "type2")).toEqual({
|
12
|
-
value: 0n,
|
13
|
-
asset: { type: "type2" },
|
14
|
-
});
|
15
|
-
});
|
16
|
-
});
|
17
|
-
});
|
18
|
-
//# sourceMappingURL=utils.test.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../../../src/bridge/generic-alpaca/tests/utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;gBACjF,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;aACzB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;YACvD,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;gBACjF,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;aACzB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import { extractBalance } from "../utils";
|
2
|
-
|
3
|
-
describe("Alpaca utils", () => {
|
4
|
-
describe("extractBalance", () => {
|
5
|
-
it("extracts an existing balance", () => {
|
6
|
-
expect(extractBalance([{ value: 4n, asset: { type: "type1" } }], "type1")).toEqual({
|
7
|
-
value: 4n,
|
8
|
-
asset: { type: "type1" },
|
9
|
-
});
|
10
|
-
});
|
11
|
-
|
12
|
-
it("generates an empty balance for a missing type", () => {
|
13
|
-
expect(extractBalance([{ value: 4n, asset: { type: "type1" } }], "type2")).toEqual({
|
14
|
-
value: 0n,
|
15
|
-
asset: { type: "type2" },
|
16
|
-
});
|
17
|
-
});
|
18
|
-
});
|
19
|
-
});
|
File without changes
|
File without changes
|