@ledgerhq/live-common 34.41.0-nightly.3 → 34.41.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/DataModel.js +2 -2
- package/lib/DataModel.js.map +1 -1
- package/lib/DataModel.test.js +4 -4
- package/lib/DataModel.test.js.map +1 -1
- package/lib/e2e/enum/Account.d.ts +0 -2
- package/lib/e2e/enum/Account.d.ts.map +1 -1
- package/lib/e2e/enum/Account.js +72 -74
- package/lib/e2e/enum/Account.js.map +1 -1
- package/lib/e2e/enum/DeviceLabels.d.ts +2 -4
- package/lib/e2e/enum/DeviceLabels.d.ts.map +1 -1
- package/lib/e2e/enum/DeviceLabels.js +2 -4
- package/lib/e2e/enum/DeviceLabels.js.map +1 -1
- package/lib/e2e/families/aptos.d.ts +2 -0
- package/lib/e2e/families/aptos.d.ts.map +1 -1
- package/lib/e2e/families/aptos.js +13 -1
- package/lib/e2e/families/aptos.js.map +1 -1
- package/lib/e2e/families/cardano.d.ts.map +1 -1
- package/lib/e2e/families/cardano.js +29 -26
- package/lib/e2e/families/cardano.js.map +1 -1
- package/lib/e2e/families/celo.js +1 -1
- package/lib/e2e/families/celo.js.map +1 -1
- package/lib/e2e/families/evm.js +1 -1
- package/lib/e2e/families/evm.js.map +1 -1
- package/lib/e2e/index.d.ts +1 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/e2e/speculos.d.ts.map +1 -1
- package/lib/e2e/speculos.js +24 -21
- package/lib/e2e/speculos.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/families/aptos/config.d.ts +4 -0
- package/lib/families/aptos/config.d.ts.map +1 -0
- package/lib/families/aptos/config.js +13 -0
- package/lib/families/aptos/config.js.map +1 -0
- package/lib/families/aptos/constants.d.ts +2 -0
- package/lib/families/aptos/constants.d.ts.map +1 -0
- package/lib/families/aptos/constants.js +19 -0
- package/lib/families/aptos/constants.js.map +1 -0
- package/lib/families/aptos/logic.d.ts +2 -0
- package/lib/families/aptos/logic.d.ts.map +1 -0
- package/lib/families/aptos/logic.js +19 -0
- package/lib/families/aptos/logic.js.map +1 -0
- package/lib/families/aptos/react.d.ts +10 -0
- package/lib/families/aptos/react.d.ts.map +1 -0
- package/lib/families/aptos/react.js +56 -0
- package/lib/families/aptos/react.js.map +1 -0
- package/lib/families/aptos/setup.d.ts +1 -1
- package/lib/families/aptos/setup.d.ts.map +1 -1
- package/lib/families/aptos/setup.js +1 -1
- package/lib/families/aptos/setup.js.map +1 -1
- package/lib/families/aptos/staking.d.ts +2 -0
- package/lib/families/aptos/staking.d.ts.map +1 -0
- package/lib/families/aptos/staking.js +19 -0
- package/lib/families/aptos/staking.js.map +1 -0
- package/lib/families/aptos/types.d.ts +2 -0
- package/lib/families/aptos/types.d.ts.map +1 -0
- package/lib/families/aptos/types.js +19 -0
- package/lib/families/aptos/types.js.map +1 -0
- package/lib/families/aptos/utils.d.ts +2 -0
- package/lib/families/aptos/utils.d.ts.map +1 -0
- package/lib/families/aptos/utils.js +19 -0
- package/lib/families/aptos/utils.js.map +1 -0
- package/lib/generated/bridge/js.d.ts +1 -1
- package/lib/generated/cli-transaction.d.ts +2 -2
- package/lib/generated/deviceTransactionConfig.d.ts +1 -2
- package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/generated/specs.d.ts +1 -1
- package/lib/generated/transaction.d.ts +3 -3
- package/lib/modularDrawer/utils/index.d.ts +6 -0
- package/lib/modularDrawer/utils/index.d.ts.map +1 -0
- package/lib/modularDrawer/utils/index.js +21 -0
- package/lib/modularDrawer/utils/index.js.map +1 -0
- package/lib/modularDrawer/utils/index.test.d.ts +2 -0
- package/lib/modularDrawer/utils/index.test.d.ts.map +1 -0
- package/lib/modularDrawer/utils/index.test.js +64 -0
- package/lib/modularDrawer/utils/index.test.js.map +1 -0
- package/lib-es/DataModel.js +1 -1
- package/lib-es/DataModel.js.map +1 -1
- package/lib-es/DataModel.test.js +2 -2
- package/lib-es/DataModel.test.js.map +1 -1
- package/lib-es/e2e/enum/Account.d.ts +0 -2
- package/lib-es/e2e/enum/Account.d.ts.map +1 -1
- package/lib-es/e2e/enum/Account.js +72 -74
- package/lib-es/e2e/enum/Account.js.map +1 -1
- package/lib-es/e2e/enum/DeviceLabels.d.ts +2 -4
- package/lib-es/e2e/enum/DeviceLabels.d.ts.map +1 -1
- package/lib-es/e2e/enum/DeviceLabels.js +2 -4
- package/lib-es/e2e/enum/DeviceLabels.js.map +1 -1
- package/lib-es/e2e/families/aptos.d.ts +2 -0
- package/lib-es/e2e/families/aptos.d.ts.map +1 -1
- package/lib-es/e2e/families/aptos.js +9 -1
- package/lib-es/e2e/families/aptos.js.map +1 -1
- package/lib-es/e2e/families/cardano.d.ts.map +1 -1
- package/lib-es/e2e/families/cardano.js +29 -26
- package/lib-es/e2e/families/cardano.js.map +1 -1
- package/lib-es/e2e/families/celo.js +1 -1
- package/lib-es/e2e/families/celo.js.map +1 -1
- package/lib-es/e2e/families/evm.js +1 -1
- package/lib-es/e2e/families/evm.js.map +1 -1
- package/lib-es/e2e/index.d.ts +1 -0
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/e2e/speculos.d.ts.map +1 -1
- package/lib-es/e2e/speculos.js +24 -21
- package/lib-es/e2e/speculos.js.map +1 -1
- package/lib-es/env.react.d.ts +1 -1
- package/lib-es/env.react.d.ts.map +1 -1
- package/lib-es/families/aptos/config.d.ts +4 -0
- package/lib-es/families/aptos/config.d.ts.map +1 -0
- package/lib-es/families/aptos/config.js +10 -0
- package/lib-es/families/aptos/config.js.map +1 -0
- package/lib-es/families/aptos/constants.d.ts +2 -0
- package/lib-es/families/aptos/constants.d.ts.map +1 -0
- package/lib-es/families/aptos/constants.js +3 -0
- package/lib-es/families/aptos/constants.js.map +1 -0
- package/lib-es/families/aptos/logic.d.ts +2 -0
- package/lib-es/families/aptos/logic.d.ts.map +1 -0
- package/lib-es/families/aptos/logic.js +3 -0
- package/lib-es/families/aptos/logic.js.map +1 -0
- package/lib-es/families/aptos/react.d.ts +10 -0
- package/lib-es/families/aptos/react.d.ts.map +1 -0
- package/lib-es/families/aptos/react.js +49 -0
- package/lib-es/families/aptos/react.js.map +1 -0
- package/lib-es/families/aptos/setup.d.ts +1 -1
- package/lib-es/families/aptos/setup.d.ts.map +1 -1
- package/lib-es/families/aptos/setup.js +1 -1
- package/lib-es/families/aptos/setup.js.map +1 -1
- package/lib-es/families/aptos/staking.d.ts +2 -0
- package/lib-es/families/aptos/staking.d.ts.map +1 -0
- package/lib-es/families/aptos/staking.js +3 -0
- package/lib-es/families/aptos/staking.js.map +1 -0
- package/lib-es/families/aptos/types.d.ts +2 -0
- package/lib-es/families/aptos/types.d.ts.map +1 -0
- package/lib-es/families/aptos/types.js +3 -0
- package/lib-es/families/aptos/types.js.map +1 -0
- package/lib-es/families/aptos/utils.d.ts +2 -0
- package/lib-es/families/aptos/utils.d.ts.map +1 -0
- package/lib-es/families/aptos/utils.js +3 -0
- package/lib-es/families/aptos/utils.js.map +1 -0
- package/lib-es/generated/bridge/js.d.ts +1 -1
- package/lib-es/generated/cli-transaction.d.ts +2 -2
- package/lib-es/generated/deviceTransactionConfig.d.ts +1 -2
- package/lib-es/generated/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/generated/specs.d.ts +1 -1
- package/lib-es/generated/transaction.d.ts +3 -3
- package/lib-es/modularDrawer/utils/index.d.ts +6 -0
- package/lib-es/modularDrawer/utils/index.d.ts.map +1 -0
- package/lib-es/modularDrawer/utils/index.js +17 -0
- package/lib-es/modularDrawer/utils/index.js.map +1 -0
- package/lib-es/modularDrawer/utils/index.test.d.ts +2 -0
- package/lib-es/modularDrawer/utils/index.test.d.ts.map +1 -0
- package/lib-es/modularDrawer/utils/index.test.js +62 -0
- package/lib-es/modularDrawer/utils/index.test.js.map +1 -0
- package/package.json +62 -62
- package/src/DataModel.test.ts +5 -4
- package/src/DataModel.ts +1 -1
- package/src/e2e/enum/Account.ts +72 -87
- package/src/e2e/enum/DeviceLabels.ts +2 -4
- package/src/e2e/families/aptos.ts +11 -1
- package/src/e2e/families/cardano.ts +31 -29
- package/src/e2e/families/celo.ts +1 -1
- package/src/e2e/families/evm.ts +1 -1
- package/src/e2e/speculos.ts +28 -25
- package/src/families/aptos/__snapshots__/bridge.integration.test.ts.snap +84 -3
- package/src/families/aptos/config.ts +12 -0
- package/src/families/aptos/constants.ts +2 -0
- package/src/families/aptos/logic.ts +2 -0
- package/src/families/aptos/react.ts +89 -0
- package/src/families/aptos/setup.ts +2 -7
- package/src/families/aptos/staking.ts +2 -0
- package/src/families/aptos/types.ts +2 -0
- package/src/families/aptos/utils.ts +2 -0
- package/src/generated/deviceTransactionConfig.ts +0 -2
- package/src/modularDrawer/utils/index.test.ts +74 -0
- package/src/modularDrawer/utils/index.ts +29 -0
- package/lib/families/aptos/consts.d.ts +0 -4
- package/lib/families/aptos/consts.d.ts.map +0 -1
- package/lib/families/aptos/consts.js +0 -7
- package/lib/families/aptos/consts.js.map +0 -1
- package/lib-es/families/aptos/consts.d.ts +0 -4
- package/lib-es/families/aptos/consts.d.ts.map +0 -1
- package/lib-es/families/aptos/consts.js +0 -4
- package/lib-es/families/aptos/consts.js.map +0 -1
- package/src/families/aptos/consts.ts +0 -3
@@ -29,7 +29,7 @@ export async function sendCardano(tx: Transaction) {
|
|
29
29
|
await pressBoth();
|
30
30
|
await waitFor(DeviceLabels.TRANSACTION_FEE);
|
31
31
|
await pressBoth();
|
32
|
-
await waitFor(DeviceLabels.
|
32
|
+
await waitFor(DeviceLabels.CONFIRM);
|
33
33
|
if (isNanoS) {
|
34
34
|
await pressRightButton();
|
35
35
|
} else {
|
@@ -41,38 +41,40 @@ export async function sendCardano(tx: Transaction) {
|
|
41
41
|
|
42
42
|
export async function delegateCardano() {
|
43
43
|
const commonSteps = [
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
[DeviceLabels.NEW_ORDINARY, "both"],
|
45
|
+
[DeviceLabels.TRANSACTION_FEE, "both"],
|
46
|
+
[DeviceLabels.REGISTER, "both"],
|
47
|
+
[DeviceLabels.STAKE_KEY, "both"],
|
48
|
+
[DeviceLabels.DEPOSIT, "both"],
|
49
|
+
[DeviceLabels.CONFIRM, "both"],
|
50
|
+
[DeviceLabels.DELEGATE_STAKE, "both"],
|
51
|
+
[DeviceLabels.STAKE_KEY, "both"],
|
52
|
+
[DeviceLabels.CONFIRM, "both"],
|
53
|
+
[DeviceLabels.CONFIRM, "both"],
|
54
|
+
] as const;
|
54
55
|
|
55
56
|
const LNSSpecificSteps = [
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
];
|
57
|
+
[DeviceLabels.NEW_ORDINARY, "right"],
|
58
|
+
[DeviceLabels.TRANSACTION_FEE, "both"],
|
59
|
+
[DeviceLabels.REGISTER, "both"],
|
60
|
+
[DeviceLabels.STAKE_KEY, "both"],
|
61
|
+
[DeviceLabels.CONFIRM, "right"],
|
62
|
+
[DeviceLabels.DELEGATE_STAKE, "both"],
|
63
|
+
[DeviceLabels.STAKE_KEY, "both"],
|
64
|
+
[DeviceLabels.CONFIRM, "right"],
|
65
|
+
[DeviceLabels.CONFIRM, "right"],
|
66
|
+
] as const;
|
66
67
|
|
67
|
-
const
|
68
|
-
process.env.SPECULOS_DEVICE === Device.LNS ? LNSSpecificSteps : commonSteps;
|
68
|
+
const steps = process.env.SPECULOS_DEVICE === Device.LNS ? LNSSpecificSteps : commonSteps;
|
69
69
|
|
70
|
-
for (const
|
71
|
-
|
72
|
-
|
73
|
-
await pressBoth();
|
74
|
-
}
|
75
|
-
|
70
|
+
for (const [label, action] of steps) {
|
71
|
+
try {
|
72
|
+
await waitFor(label);
|
73
|
+
action === "both" ? await pressBoth() : await pressRightButton();
|
74
|
+
} catch (error) {
|
75
|
+
const message = error instanceof Error ? error.message : String(error);
|
76
|
+
console.error(`Error while waiting for "${label}":`, message);
|
77
|
+
break;
|
76
78
|
}
|
77
79
|
}
|
78
80
|
}
|
package/src/e2e/families/celo.ts
CHANGED
@@ -4,7 +4,7 @@ import { Delegate } from "../models/Delegate";
|
|
4
4
|
import expect from "expect";
|
5
5
|
|
6
6
|
export async function delegateCelo(tx: Delegate) {
|
7
|
-
await waitFor(DeviceLabels.
|
7
|
+
await waitFor(DeviceLabels.REVIEW_OPERATION);
|
8
8
|
const events = await pressUntilTextFound(DeviceLabels.ACCEPT);
|
9
9
|
const isAmountCorrect = containsSubstringInEvent(tx.amount, events);
|
10
10
|
expect(isAmountCorrect).toBeTruthy();
|
package/src/e2e/families/evm.ts
CHANGED
@@ -20,7 +20,7 @@ export async function sendEVM(tx: Transaction) {
|
|
20
20
|
}
|
21
21
|
|
22
22
|
export async function sendEvmNFT(tx: NFTTransaction) {
|
23
|
-
await waitFor(DeviceLabels.
|
23
|
+
await waitFor(DeviceLabels.REVIEW_OPERATION);
|
24
24
|
const events = await pressUntilTextFound(DeviceLabels.ACCEPT);
|
25
25
|
const isAddressCorrect = containsSubstringInEvent(tx.accountToCredit.address, events);
|
26
26
|
expect(isAddressCorrect).toBeTruthy();
|
package/src/e2e/speculos.ts
CHANGED
@@ -33,6 +33,7 @@ import { delegateCosmos, sendCosmos } from "./families/cosmos";
|
|
33
33
|
import { delegateSolana, sendSolana } from "./families/solana";
|
34
34
|
import { delegateTezos } from "./families/tezos";
|
35
35
|
import { delegateCelo } from "./families/celo";
|
36
|
+
import { delegateAptos } from "./families/aptos";
|
36
37
|
import { delegateMultiversX } from "./families/multiversX";
|
37
38
|
import { NFTTransaction, Transaction } from "./models/Transaction";
|
38
39
|
import { Delegate } from "./models/Delegate";
|
@@ -413,26 +414,23 @@ interface ResponseData {
|
|
413
414
|
events: Event[];
|
414
415
|
}
|
415
416
|
|
416
|
-
export async function waitFor(text: string, maxAttempts
|
417
|
-
const
|
418
|
-
const
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
const
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
const texts = responseData.events.map(event => event.text);
|
427
|
-
|
428
|
-
if (texts?.[0]?.includes(text)) {
|
429
|
-
textFound = true;
|
417
|
+
export async function waitFor(text: string, maxAttempts = 10): Promise<string[]> {
|
418
|
+
const port = getEnv("SPECULOS_API_PORT");
|
419
|
+
const address = process.env.SPECULOS_ADDRESS || "http://127.0.0.1";
|
420
|
+
const url = `${address}:${port}/events?stream=false¤tscreenonly=true`;
|
421
|
+
|
422
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
423
|
+
const { data } = await axios.get<ResponseData>(url);
|
424
|
+
const texts = data.events.map(event => event.text);
|
425
|
+
|
426
|
+
if (texts?.some(t => t?.toLowerCase().includes(text.toLowerCase()))) {
|
430
427
|
return texts;
|
431
428
|
}
|
432
|
-
|
429
|
+
|
433
430
|
await waitForTimeOut(500);
|
434
431
|
}
|
435
|
-
|
432
|
+
|
433
|
+
throw new Error(`Text "${text}" not found on device screen after ${maxAttempts} attempts.`);
|
436
434
|
}
|
437
435
|
|
438
436
|
export async function pressBoth() {
|
@@ -567,7 +565,11 @@ export async function expectValidAddressDevice(account: Account, addressDisplaye
|
|
567
565
|
break;
|
568
566
|
case Currency.DOT:
|
569
567
|
case Currency.ATOM:
|
570
|
-
deviceLabels = [
|
568
|
+
deviceLabels = [
|
569
|
+
DeviceLabels.PLEASE_REVIEW,
|
570
|
+
DeviceLabels.CAPS_APPROVE,
|
571
|
+
DeviceLabels.CAPS_REJECT,
|
572
|
+
];
|
571
573
|
break;
|
572
574
|
case Currency.BTC:
|
573
575
|
deviceLabels = [DeviceLabels.ADDRESS, DeviceLabels.CONFIRM, DeviceLabels.CANCEL];
|
@@ -631,12 +633,10 @@ export async function signSendTransaction(tx: Transaction) {
|
|
631
633
|
|
632
634
|
export async function signSendNFTTransaction(tx: NFTTransaction) {
|
633
635
|
const currencyName = tx.accountToDebit.currency;
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
default:
|
639
|
-
throw new Error(`Unsupported currency: ${currencyName.ticker}`);
|
636
|
+
if (currencyName === Currency.ETH) {
|
637
|
+
await sendEvmNFT(tx);
|
638
|
+
} else {
|
639
|
+
throw new Error(`Unsupported currency: ${currencyName.ticker}`);
|
640
640
|
}
|
641
641
|
}
|
642
642
|
|
@@ -666,20 +666,23 @@ export async function signDelegationTransaction(delegatingAccount: Delegate) {
|
|
666
666
|
case Account.CELO_1.currency.name:
|
667
667
|
await delegateCelo(delegatingAccount);
|
668
668
|
break;
|
669
|
+
case Account.APTOS_1.currency.name:
|
670
|
+
await delegateAptos(delegatingAccount);
|
671
|
+
break;
|
669
672
|
default:
|
670
673
|
throw new Error(`Unsupported currency: ${currencyName}`);
|
671
674
|
}
|
672
675
|
}
|
673
676
|
|
674
677
|
export async function verifyAmountsAndAcceptSwap(swap: Swap, amount: string) {
|
675
|
-
await waitFor(DeviceLabels.
|
678
|
+
await waitFor(DeviceLabels.REVIEW_OPERATION);
|
676
679
|
const events = await pressUntilTextFound(DeviceLabels.ACCEPT);
|
677
680
|
await verifySwapData(swap, events, amount);
|
678
681
|
await pressBoth();
|
679
682
|
}
|
680
683
|
|
681
684
|
export async function verifyAmountsAndRejectSwap(swap: Swap, amount: string) {
|
682
|
-
await waitFor(DeviceLabels.
|
685
|
+
await waitFor(DeviceLabels.REVIEW_OPERATION);
|
683
686
|
const events = await pressUntilTextFound(DeviceLabels.REJECT);
|
684
687
|
await verifySwapData(swap, events, amount);
|
685
688
|
await pressBoth();
|
@@ -3,6 +3,12 @@
|
|
3
3
|
exports[`aptos currency bridge scanAccounts aptos seed 1 1`] = `
|
4
4
|
[
|
5
5
|
{
|
6
|
+
"aptosResources": {
|
7
|
+
"activeBalance": "0",
|
8
|
+
"inactiveBalance": "0",
|
9
|
+
"pendingInactiveBalance": "0",
|
10
|
+
"stakingPositions": [],
|
11
|
+
},
|
6
12
|
"balance": "19949100",
|
7
13
|
"currencyId": "aptos",
|
8
14
|
"derivationMode": "aptos",
|
@@ -21,17 +27,23 @@ exports[`aptos currency bridge scanAccounts aptos seed 1 1`] = `
|
|
21
27
|
"xpub": "d1a8c6a1cdd52dd40c7ea61ee4571fb51fcae440a594c1eca18636928f1d3956",
|
22
28
|
},
|
23
29
|
{
|
24
|
-
"
|
30
|
+
"aptosResources": {
|
31
|
+
"activeBalance": "0",
|
32
|
+
"inactiveBalance": "0",
|
33
|
+
"pendingInactiveBalance": "0",
|
34
|
+
"stakingPositions": [],
|
35
|
+
},
|
36
|
+
"balance": "20050000",
|
25
37
|
"currencyId": "aptos",
|
26
38
|
"derivationMode": "aptos",
|
27
39
|
"freshAddress": "0xd20fa44192f94ba086ab16bfdf57e43ff118ada69b4c66fa9b9a9223cbc068c1",
|
28
40
|
"freshAddressPath": "44'/637'/1'/0'/0'",
|
29
41
|
"id": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos",
|
30
42
|
"index": 1,
|
31
|
-
"operationsCount":
|
43
|
+
"operationsCount": 5,
|
32
44
|
"pendingOperations": [],
|
33
45
|
"seedIdentifier": "d6816f4f22f867b56cf9304b776f452a16d107835d73ee8a33c4ced210300583",
|
34
|
-
"spendableBalance": "
|
46
|
+
"spendableBalance": "20050000",
|
35
47
|
"subAccounts": [],
|
36
48
|
"swapHistory": [],
|
37
49
|
"syncHash": undefined,
|
@@ -39,6 +51,12 @@ exports[`aptos currency bridge scanAccounts aptos seed 1 1`] = `
|
|
39
51
|
"xpub": "6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e",
|
40
52
|
},
|
41
53
|
{
|
54
|
+
"aptosResources": {
|
55
|
+
"activeBalance": "0",
|
56
|
+
"inactiveBalance": "0",
|
57
|
+
"pendingInactiveBalance": "0",
|
58
|
+
"stakingPositions": [],
|
59
|
+
},
|
42
60
|
"balance": "0",
|
43
61
|
"currencyId": "aptos",
|
44
62
|
"derivationMode": "aptos",
|
@@ -211,6 +229,27 @@ exports[`aptos currency bridge scanAccounts aptos seed 1 2`] = `
|
|
211
229
|
},
|
212
230
|
],
|
213
231
|
[
|
232
|
+
{
|
233
|
+
"accountId": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos",
|
234
|
+
"blockHash": "0xb71a59a5f43dc73c945da97ef88043721dab81f658df7a4a4207f95ce7cad0ee",
|
235
|
+
"blockHeight": 366009981,
|
236
|
+
"extra": {
|
237
|
+
"version": "2901622402",
|
238
|
+
},
|
239
|
+
"fee": "1100",
|
240
|
+
"hasFailed": false,
|
241
|
+
"hash": "0x1acd500f32be88a62692698502a296dcb977e5629bbbf12e448bc69737c18c40",
|
242
|
+
"id": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos-0x1acd500f32be88a62692698502a296dcb977e5629bbbf12e448bc69737c18c40-IN",
|
243
|
+
"recipients": [
|
244
|
+
"0xd20fa44192f94ba086ab16bfdf57e43ff118ada69b4c66fa9b9a9223cbc068c1",
|
245
|
+
],
|
246
|
+
"senders": [
|
247
|
+
"0xb69a68cc64f7aa193705193f4dd598320a0a74baf7e4b50c9980c5bd60a82390",
|
248
|
+
],
|
249
|
+
"transactionSequenceNumber": 179,
|
250
|
+
"type": "IN",
|
251
|
+
"value": "10000",
|
252
|
+
},
|
214
253
|
{
|
215
254
|
"accountId": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos",
|
216
255
|
"blockHash": "0x27db591a136924b48d10e6e152a3e856a5c38b332654767da252851adbb454b2",
|
@@ -232,6 +271,48 @@ exports[`aptos currency bridge scanAccounts aptos seed 1 2`] = `
|
|
232
271
|
"type": "IN",
|
233
272
|
"value": "20000000",
|
234
273
|
},
|
274
|
+
{
|
275
|
+
"accountId": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos",
|
276
|
+
"blockHash": "0xadfce17fba19584616fec77888c41c1bacd18ef8702dfe07ccfbfeafd8edfd17",
|
277
|
+
"blockHeight": 366013582,
|
278
|
+
"extra": {
|
279
|
+
"version": "2901672541",
|
280
|
+
},
|
281
|
+
"fee": "1100",
|
282
|
+
"hasFailed": false,
|
283
|
+
"hash": "0x494582adf8f3e2748a30453a687106524f18296bf5924e3c1ead8a2503894970",
|
284
|
+
"id": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos-0x494582adf8f3e2748a30453a687106524f18296bf5924e3c1ead8a2503894970-IN",
|
285
|
+
"recipients": [
|
286
|
+
"0xd20fa44192f94ba086ab16bfdf57e43ff118ada69b4c66fa9b9a9223cbc068c1",
|
287
|
+
],
|
288
|
+
"senders": [
|
289
|
+
"0xb69a68cc64f7aa193705193f4dd598320a0a74baf7e4b50c9980c5bd60a82390",
|
290
|
+
],
|
291
|
+
"transactionSequenceNumber": 182,
|
292
|
+
"type": "IN",
|
293
|
+
"value": "10000",
|
294
|
+
},
|
295
|
+
{
|
296
|
+
"accountId": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos",
|
297
|
+
"blockHash": "0x1647b469fb104624e4e0a9b7f0b0368facec96a232cde5f83be1235c1068b038",
|
298
|
+
"blockHeight": 366012016,
|
299
|
+
"extra": {
|
300
|
+
"version": "2901651004",
|
301
|
+
},
|
302
|
+
"fee": "1100",
|
303
|
+
"hasFailed": false,
|
304
|
+
"hash": "0x4f42472b8c92d3d6083d05a3a357f38ed97491f5e0750058da49cc04cef82794",
|
305
|
+
"id": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos-0x4f42472b8c92d3d6083d05a3a357f38ed97491f5e0750058da49cc04cef82794-IN",
|
306
|
+
"recipients": [
|
307
|
+
"0xd20fa44192f94ba086ab16bfdf57e43ff118ada69b4c66fa9b9a9223cbc068c1",
|
308
|
+
],
|
309
|
+
"senders": [
|
310
|
+
"0xb69a68cc64f7aa193705193f4dd598320a0a74baf7e4b50c9980c5bd60a82390",
|
311
|
+
],
|
312
|
+
"transactionSequenceNumber": 181,
|
313
|
+
"type": "IN",
|
314
|
+
"value": "10000",
|
315
|
+
},
|
235
316
|
{
|
236
317
|
"accountId": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos",
|
237
318
|
"blockHash": "0xf37ce698cf2e6d9e4a0048cd6d09fb3f19f417ab8251a3cc1f19b8d0e503538f",
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
2
|
+
import { useMemo } from "react";
|
3
|
+
import { getCurrentAptosPreloadData, getAptosPreloadData } from "@ledgerhq/coin-aptos/preload-data";
|
4
|
+
import type {
|
5
|
+
AptosAccount,
|
6
|
+
AptosMappedStakingPosition,
|
7
|
+
AptosPreloadData,
|
8
|
+
AptosValidator,
|
9
|
+
Transaction,
|
10
|
+
} from "./types";
|
11
|
+
import { useObservable } from "../../observable";
|
12
|
+
import { getAccountCurrency } from "../../account";
|
13
|
+
import { mapStakingPositions } from "./staking";
|
14
|
+
|
15
|
+
export function useAptosPreloadData(currency: CryptoCurrency): AptosPreloadData | undefined | null {
|
16
|
+
return useObservable(getAptosPreloadData(currency), getCurrentAptosPreloadData(currency));
|
17
|
+
}
|
18
|
+
|
19
|
+
export function useAptosValidators(currency: CryptoCurrency, search?: string): AptosValidator[] {
|
20
|
+
const data = useAptosPreloadData(currency);
|
21
|
+
|
22
|
+
return useMemo(() => {
|
23
|
+
const validators = data?.validators ?? [];
|
24
|
+
|
25
|
+
if (validators.length === 0 || !search || search === "") {
|
26
|
+
return validators;
|
27
|
+
}
|
28
|
+
|
29
|
+
const lowercaseSearch = search.toLowerCase();
|
30
|
+
|
31
|
+
const filtered = validators.filter(
|
32
|
+
validator =>
|
33
|
+
validator.name?.toLowerCase().includes(lowercaseSearch) ||
|
34
|
+
validator.address.toLowerCase().includes(lowercaseSearch),
|
35
|
+
);
|
36
|
+
|
37
|
+
const flags = [];
|
38
|
+
const output: AptosValidator[] = [];
|
39
|
+
for (let i = 0; i < filtered.length; i++) {
|
40
|
+
if (flags[filtered[i].address]) continue;
|
41
|
+
flags[filtered[i].address] = true;
|
42
|
+
output.push(filtered[i]);
|
43
|
+
}
|
44
|
+
return output;
|
45
|
+
}, [data, search]);
|
46
|
+
}
|
47
|
+
|
48
|
+
export function useAptosMappedStakingPositions(
|
49
|
+
account: AptosAccount,
|
50
|
+
): AptosMappedStakingPosition[] {
|
51
|
+
const validators = useAptosValidators(account.currency, "");
|
52
|
+
const stakingPositions = account.aptosResources?.stakingPositions;
|
53
|
+
|
54
|
+
const unit = getAccountCurrency(account).units[0];
|
55
|
+
|
56
|
+
return useMemo(() => {
|
57
|
+
const mappedStakingPositions = mapStakingPositions(stakingPositions || [], validators, unit);
|
58
|
+
return mappedStakingPositions;
|
59
|
+
}, [stakingPositions, validators, unit]);
|
60
|
+
}
|
61
|
+
|
62
|
+
export function useAptosStakingPositionsQuerySelector(
|
63
|
+
account: AptosAccount,
|
64
|
+
transaction: Transaction,
|
65
|
+
): {
|
66
|
+
options: AptosMappedStakingPosition[];
|
67
|
+
value: AptosMappedStakingPosition | undefined;
|
68
|
+
} {
|
69
|
+
const stakingPositions = useAptosMappedStakingPositions(account);
|
70
|
+
const options = useMemo<AptosMappedStakingPosition[]>(
|
71
|
+
() =>
|
72
|
+
stakingPositions.filter(sp =>
|
73
|
+
transaction.mode === "unstake" ? sp.active.gt(0) : sp.inactive.gt(0),
|
74
|
+
),
|
75
|
+
[stakingPositions, transaction],
|
76
|
+
);
|
77
|
+
|
78
|
+
const selectedValidatorAddress = transaction.recipient;
|
79
|
+
|
80
|
+
const value = useMemo(
|
81
|
+
() => stakingPositions.find(({ validatorId }) => validatorId === selectedValidatorAddress),
|
82
|
+
[stakingPositions, selectedValidatorAddress],
|
83
|
+
);
|
84
|
+
|
85
|
+
return {
|
86
|
+
options,
|
87
|
+
value,
|
88
|
+
};
|
89
|
+
}
|
@@ -1,11 +1,6 @@
|
|
1
1
|
// Goal of this file is to inject all necessary device/signer dependency to coin-modules
|
2
|
-
|
3
|
-
import {
|
4
|
-
AptosAccount,
|
5
|
-
TransactionStatus,
|
6
|
-
createBridges,
|
7
|
-
type Transaction,
|
8
|
-
} from "@ledgerhq/coin-aptos";
|
2
|
+
import { createBridges } from "@ledgerhq/coin-aptos";
|
3
|
+
import { AptosAccount, TransactionStatus, type Transaction } from "@ledgerhq/coin-aptos/types";
|
9
4
|
import Transport from "@ledgerhq/hw-transport";
|
10
5
|
import Aptos from "@ledgerhq/hw-app-aptos";
|
11
6
|
import type { Bridge } from "@ledgerhq/types-live";
|
@@ -47,7 +47,6 @@ export default {
|
|
47
47
|
xrp,
|
48
48
|
mina,
|
49
49
|
};
|
50
|
-
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_aptos } from "@ledgerhq/coin-aptos/bridge/deviceTransactionConfig";
|
51
50
|
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_casper } from "@ledgerhq/coin-casper/bridge/deviceTransactionConfig";
|
52
51
|
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_filecoin } from "@ledgerhq/coin-filecoin/bridge/deviceTransactionConfig";
|
53
52
|
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_stacks } from "@ledgerhq/coin-stacks/bridge/deviceTransactionConfig";
|
@@ -55,7 +54,6 @@ import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_polkadot } f
|
|
55
54
|
import { ExtraDeviceTransactionField as ExtraDeviceTransactionField_tron } from "@ledgerhq/coin-tron/bridge/deviceTransactionConfig";
|
56
55
|
|
57
56
|
export type ExtraDeviceTransactionField =
|
58
|
-
| ExtraDeviceTransactionField_aptos
|
59
57
|
| ExtraDeviceTransactionField_casper
|
60
58
|
| ExtraDeviceTransactionField_filecoin
|
61
59
|
| ExtraDeviceTransactionField_stacks
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { isCorrespondingCurrency, getEffectiveCurrency } from "./index";
|
2
|
+
|
3
|
+
import { createFixtureCryptoCurrency } from "../../mock/fixtures/cryptoCurrencies";
|
4
|
+
import { cryptocurrenciesById } from "@ledgerhq/cryptoassets";
|
5
|
+
import type { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
|
6
|
+
import type { CurrenciesByProviderId } from "../../deposit/type";
|
7
|
+
|
8
|
+
describe("isCorrespondingCurrency", () => {
|
9
|
+
const evmCurrency = createFixtureCryptoCurrency("evm");
|
10
|
+
const usdcToken: CryptoOrTokenCurrency = {
|
11
|
+
type: "TokenCurrency",
|
12
|
+
id: "ethereum/erc20/usdc",
|
13
|
+
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
14
|
+
parentCurrency: evmCurrency,
|
15
|
+
tokenType: "erc20",
|
16
|
+
name: "USD Coin",
|
17
|
+
ticker: "USDC",
|
18
|
+
units: [{ name: "USD Coin", code: "USDC", magnitude: 6 }],
|
19
|
+
};
|
20
|
+
const evmCrypto: CryptoOrTokenCurrency = evmCurrency;
|
21
|
+
|
22
|
+
it("returns true for a token whose parentCurrency.id matches the reference crypto", () => {
|
23
|
+
expect(isCorrespondingCurrency(usdcToken, evmCurrency)).toBe(true);
|
24
|
+
});
|
25
|
+
|
26
|
+
it("returns true for a token whose id matches the reference crypto", () => {
|
27
|
+
expect(isCorrespondingCurrency(usdcToken, usdcToken)).toBe(true);
|
28
|
+
});
|
29
|
+
|
30
|
+
it("returns true for a crypto whose id matches the reference crypto", () => {
|
31
|
+
expect(isCorrespondingCurrency(evmCrypto, evmCurrency)).toBe(true);
|
32
|
+
});
|
33
|
+
|
34
|
+
it("returns false for a token whose parentCurrency is different", () => {
|
35
|
+
const bitcoinCurrency = cryptocurrenciesById["bitcoin"];
|
36
|
+
const tokenWithOtherParent = { ...usdcToken, parentCurrency: bitcoinCurrency };
|
37
|
+
expect(isCorrespondingCurrency(tokenWithOtherParent, evmCurrency)).toBe(false);
|
38
|
+
});
|
39
|
+
|
40
|
+
it("returns false for a crypto whose id is different", () => {
|
41
|
+
const bitcoinCurrency = cryptocurrenciesById["bitcoin"];
|
42
|
+
expect(isCorrespondingCurrency(bitcoinCurrency, evmCurrency)).toBe(false);
|
43
|
+
});
|
44
|
+
});
|
45
|
+
|
46
|
+
describe("getEffectiveCurrency", () => {
|
47
|
+
const parent = createFixtureCryptoCurrency("evm");
|
48
|
+
const token: CryptoOrTokenCurrency = {
|
49
|
+
type: "TokenCurrency",
|
50
|
+
id: "ethereum/erc20/usdc",
|
51
|
+
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
52
|
+
parentCurrency: parent,
|
53
|
+
tokenType: "erc20",
|
54
|
+
name: "USD Coin",
|
55
|
+
ticker: "USDC",
|
56
|
+
units: [{ name: "USD Coin", code: "USDC", magnitude: 6 }],
|
57
|
+
};
|
58
|
+
const provider: CurrenciesByProviderId = {
|
59
|
+
providerId: "provider1",
|
60
|
+
currenciesByNetwork: [parent, token],
|
61
|
+
};
|
62
|
+
|
63
|
+
it("returns currency if id is in currencyIds", () => {
|
64
|
+
expect(getEffectiveCurrency(token, provider, [token.id])).toBe(token);
|
65
|
+
});
|
66
|
+
|
67
|
+
it("returns first matching currency from provider if id not in currencyIds", () => {
|
68
|
+
expect(getEffectiveCurrency(token, provider, [parent.id])).toBe(parent);
|
69
|
+
});
|
70
|
+
|
71
|
+
it("returns currency if no match in provider", () => {
|
72
|
+
expect(getEffectiveCurrency(token, provider, ["notfound"])).toBe(token);
|
73
|
+
});
|
74
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
|
2
|
+
import { CurrenciesByProviderId } from "../../deposit/type";
|
3
|
+
|
4
|
+
function isCorrespondingCurrency(
|
5
|
+
elem: CryptoOrTokenCurrency,
|
6
|
+
network: CryptoOrTokenCurrency,
|
7
|
+
): boolean {
|
8
|
+
if (elem.type === "TokenCurrency") {
|
9
|
+
return elem.parentCurrency?.id === network.id || elem.id === network.id;
|
10
|
+
}
|
11
|
+
if (elem.type === "CryptoCurrency") {
|
12
|
+
return elem.id === network.id;
|
13
|
+
}
|
14
|
+
return false;
|
15
|
+
}
|
16
|
+
|
17
|
+
const getEffectiveCurrency = (
|
18
|
+
currency: CryptoOrTokenCurrency,
|
19
|
+
provider: CurrenciesByProviderId,
|
20
|
+
currencyIds: string[],
|
21
|
+
) => {
|
22
|
+
const isCurrencyFiltered = currencyIds.includes(currency.id);
|
23
|
+
|
24
|
+
if (isCurrencyFiltered) return currency;
|
25
|
+
|
26
|
+
return provider.currenciesByNetwork.find(elem => currencyIds.includes(elem.id)) ?? currency;
|
27
|
+
};
|
28
|
+
|
29
|
+
export { isCorrespondingCurrency, getEffectiveCurrency };
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/families/aptos/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wCAAwC,QAAyC,CAAC;AAC/F,eAAO,MAAM,kCAAkC,oBAAoB,CAAC;AACpE,eAAO,MAAM,8BAA8B,sBAAsB,CAAC"}
|
@@ -1,7 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.APTOS_HARDENED_DERIVATION_PATH = exports.APTOS_NON_HARDENED_DERIVATION_PATH = exports.APTOS_NON_HARDENED_DERIVATION_PATH_REGEX = void 0;
|
4
|
-
exports.APTOS_NON_HARDENED_DERIVATION_PATH_REGEX = /^44'\/637'\/[0-9]+'\/[0-9]+\/[0-9]+$/;
|
5
|
-
exports.APTOS_NON_HARDENED_DERIVATION_PATH = "44'/637'/0'/0/0";
|
6
|
-
exports.APTOS_HARDENED_DERIVATION_PATH = "44'/637'/0'/0'/0'";
|
7
|
-
//# sourceMappingURL=consts.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../../src/families/aptos/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,wCAAwC,GAAG,sCAAsC,CAAC;AAClF,QAAA,kCAAkC,GAAG,iBAAiB,CAAC;AACvD,QAAA,8BAA8B,GAAG,mBAAmB,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/families/aptos/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wCAAwC,QAAyC,CAAC;AAC/F,eAAO,MAAM,kCAAkC,oBAAoB,CAAC;AACpE,eAAO,MAAM,8BAA8B,sBAAsB,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../../src/families/aptos/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wCAAwC,GAAG,sCAAsC,CAAC;AAC/F,MAAM,CAAC,MAAM,kCAAkC,GAAG,iBAAiB,CAAC;AACpE,MAAM,CAAC,MAAM,8BAA8B,GAAG,mBAAmB,CAAC"}
|