@ledgerhq/live-common 34.41.0-nightly.3 → 34.41.0-nightly.4

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.
Files changed (174) hide show
  1. package/lib/DataModel.js +2 -2
  2. package/lib/DataModel.js.map +1 -1
  3. package/lib/DataModel.test.js +4 -4
  4. package/lib/DataModel.test.js.map +1 -1
  5. package/lib/e2e/enum/DeviceLabels.d.ts +2 -4
  6. package/lib/e2e/enum/DeviceLabels.d.ts.map +1 -1
  7. package/lib/e2e/enum/DeviceLabels.js +2 -4
  8. package/lib/e2e/enum/DeviceLabels.js.map +1 -1
  9. package/lib/e2e/families/aptos.d.ts +2 -0
  10. package/lib/e2e/families/aptos.d.ts.map +1 -1
  11. package/lib/e2e/families/aptos.js +13 -1
  12. package/lib/e2e/families/aptos.js.map +1 -1
  13. package/lib/e2e/families/cardano.d.ts.map +1 -1
  14. package/lib/e2e/families/cardano.js +29 -26
  15. package/lib/e2e/families/cardano.js.map +1 -1
  16. package/lib/e2e/families/celo.js +1 -1
  17. package/lib/e2e/families/celo.js.map +1 -1
  18. package/lib/e2e/families/evm.js +1 -1
  19. package/lib/e2e/families/evm.js.map +1 -1
  20. package/lib/e2e/index.d.ts +1 -0
  21. package/lib/e2e/index.d.ts.map +1 -1
  22. package/lib/e2e/speculos.d.ts.map +1 -1
  23. package/lib/e2e/speculos.js +24 -21
  24. package/lib/e2e/speculos.js.map +1 -1
  25. package/lib/env.react.d.ts +1 -1
  26. package/lib/env.react.d.ts.map +1 -1
  27. package/lib/families/aptos/config.d.ts +4 -0
  28. package/lib/families/aptos/config.d.ts.map +1 -0
  29. package/lib/families/aptos/config.js +13 -0
  30. package/lib/families/aptos/config.js.map +1 -0
  31. package/lib/families/aptos/constants.d.ts +2 -0
  32. package/lib/families/aptos/constants.d.ts.map +1 -0
  33. package/lib/families/aptos/constants.js +19 -0
  34. package/lib/families/aptos/constants.js.map +1 -0
  35. package/lib/families/aptos/logic.d.ts +2 -0
  36. package/lib/families/aptos/logic.d.ts.map +1 -0
  37. package/lib/families/aptos/logic.js +19 -0
  38. package/lib/families/aptos/logic.js.map +1 -0
  39. package/lib/families/aptos/react.d.ts +10 -0
  40. package/lib/families/aptos/react.d.ts.map +1 -0
  41. package/lib/families/aptos/react.js +56 -0
  42. package/lib/families/aptos/react.js.map +1 -0
  43. package/lib/families/aptos/setup.d.ts +1 -1
  44. package/lib/families/aptos/setup.d.ts.map +1 -1
  45. package/lib/families/aptos/setup.js +1 -1
  46. package/lib/families/aptos/setup.js.map +1 -1
  47. package/lib/families/aptos/staking.d.ts +2 -0
  48. package/lib/families/aptos/staking.d.ts.map +1 -0
  49. package/lib/families/aptos/staking.js +19 -0
  50. package/lib/families/aptos/staking.js.map +1 -0
  51. package/lib/families/aptos/types.d.ts +2 -0
  52. package/lib/families/aptos/types.d.ts.map +1 -0
  53. package/lib/families/aptos/types.js +19 -0
  54. package/lib/families/aptos/types.js.map +1 -0
  55. package/lib/families/aptos/utils.d.ts +2 -0
  56. package/lib/families/aptos/utils.d.ts.map +1 -0
  57. package/lib/families/aptos/utils.js +19 -0
  58. package/lib/families/aptos/utils.js.map +1 -0
  59. package/lib/generated/bridge/js.d.ts +1 -1
  60. package/lib/generated/cli-transaction.d.ts +2 -2
  61. package/lib/generated/deviceTransactionConfig.d.ts +1 -2
  62. package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
  63. package/lib/generated/specs.d.ts +1 -1
  64. package/lib/generated/transaction.d.ts +3 -3
  65. package/lib/modularDrawer/utils/index.d.ts +6 -0
  66. package/lib/modularDrawer/utils/index.d.ts.map +1 -0
  67. package/lib/modularDrawer/utils/index.js +21 -0
  68. package/lib/modularDrawer/utils/index.js.map +1 -0
  69. package/lib/modularDrawer/utils/index.test.d.ts +2 -0
  70. package/lib/modularDrawer/utils/index.test.d.ts.map +1 -0
  71. package/lib/modularDrawer/utils/index.test.js +64 -0
  72. package/lib/modularDrawer/utils/index.test.js.map +1 -0
  73. package/lib-es/DataModel.js +1 -1
  74. package/lib-es/DataModel.js.map +1 -1
  75. package/lib-es/DataModel.test.js +2 -2
  76. package/lib-es/DataModel.test.js.map +1 -1
  77. package/lib-es/e2e/enum/DeviceLabels.d.ts +2 -4
  78. package/lib-es/e2e/enum/DeviceLabels.d.ts.map +1 -1
  79. package/lib-es/e2e/enum/DeviceLabels.js +2 -4
  80. package/lib-es/e2e/enum/DeviceLabels.js.map +1 -1
  81. package/lib-es/e2e/families/aptos.d.ts +2 -0
  82. package/lib-es/e2e/families/aptos.d.ts.map +1 -1
  83. package/lib-es/e2e/families/aptos.js +9 -1
  84. package/lib-es/e2e/families/aptos.js.map +1 -1
  85. package/lib-es/e2e/families/cardano.d.ts.map +1 -1
  86. package/lib-es/e2e/families/cardano.js +29 -26
  87. package/lib-es/e2e/families/cardano.js.map +1 -1
  88. package/lib-es/e2e/families/celo.js +1 -1
  89. package/lib-es/e2e/families/celo.js.map +1 -1
  90. package/lib-es/e2e/families/evm.js +1 -1
  91. package/lib-es/e2e/families/evm.js.map +1 -1
  92. package/lib-es/e2e/index.d.ts +1 -0
  93. package/lib-es/e2e/index.d.ts.map +1 -1
  94. package/lib-es/e2e/speculos.d.ts.map +1 -1
  95. package/lib-es/e2e/speculos.js +24 -21
  96. package/lib-es/e2e/speculos.js.map +1 -1
  97. package/lib-es/env.react.d.ts +1 -1
  98. package/lib-es/env.react.d.ts.map +1 -1
  99. package/lib-es/families/aptos/config.d.ts +4 -0
  100. package/lib-es/families/aptos/config.d.ts.map +1 -0
  101. package/lib-es/families/aptos/config.js +10 -0
  102. package/lib-es/families/aptos/config.js.map +1 -0
  103. package/lib-es/families/aptos/constants.d.ts +2 -0
  104. package/lib-es/families/aptos/constants.d.ts.map +1 -0
  105. package/lib-es/families/aptos/constants.js +3 -0
  106. package/lib-es/families/aptos/constants.js.map +1 -0
  107. package/lib-es/families/aptos/logic.d.ts +2 -0
  108. package/lib-es/families/aptos/logic.d.ts.map +1 -0
  109. package/lib-es/families/aptos/logic.js +3 -0
  110. package/lib-es/families/aptos/logic.js.map +1 -0
  111. package/lib-es/families/aptos/react.d.ts +10 -0
  112. package/lib-es/families/aptos/react.d.ts.map +1 -0
  113. package/lib-es/families/aptos/react.js +49 -0
  114. package/lib-es/families/aptos/react.js.map +1 -0
  115. package/lib-es/families/aptos/setup.d.ts +1 -1
  116. package/lib-es/families/aptos/setup.d.ts.map +1 -1
  117. package/lib-es/families/aptos/setup.js +1 -1
  118. package/lib-es/families/aptos/setup.js.map +1 -1
  119. package/lib-es/families/aptos/staking.d.ts +2 -0
  120. package/lib-es/families/aptos/staking.d.ts.map +1 -0
  121. package/lib-es/families/aptos/staking.js +3 -0
  122. package/lib-es/families/aptos/staking.js.map +1 -0
  123. package/lib-es/families/aptos/types.d.ts +2 -0
  124. package/lib-es/families/aptos/types.d.ts.map +1 -0
  125. package/lib-es/families/aptos/types.js +3 -0
  126. package/lib-es/families/aptos/types.js.map +1 -0
  127. package/lib-es/families/aptos/utils.d.ts +2 -0
  128. package/lib-es/families/aptos/utils.d.ts.map +1 -0
  129. package/lib-es/families/aptos/utils.js +3 -0
  130. package/lib-es/families/aptos/utils.js.map +1 -0
  131. package/lib-es/generated/bridge/js.d.ts +1 -1
  132. package/lib-es/generated/cli-transaction.d.ts +2 -2
  133. package/lib-es/generated/deviceTransactionConfig.d.ts +1 -2
  134. package/lib-es/generated/deviceTransactionConfig.d.ts.map +1 -1
  135. package/lib-es/generated/specs.d.ts +1 -1
  136. package/lib-es/generated/transaction.d.ts +3 -3
  137. package/lib-es/modularDrawer/utils/index.d.ts +6 -0
  138. package/lib-es/modularDrawer/utils/index.d.ts.map +1 -0
  139. package/lib-es/modularDrawer/utils/index.js +17 -0
  140. package/lib-es/modularDrawer/utils/index.js.map +1 -0
  141. package/lib-es/modularDrawer/utils/index.test.d.ts +2 -0
  142. package/lib-es/modularDrawer/utils/index.test.d.ts.map +1 -0
  143. package/lib-es/modularDrawer/utils/index.test.js +62 -0
  144. package/lib-es/modularDrawer/utils/index.test.js.map +1 -0
  145. package/package.json +62 -62
  146. package/src/DataModel.test.ts +5 -4
  147. package/src/DataModel.ts +1 -1
  148. package/src/e2e/enum/DeviceLabels.ts +2 -4
  149. package/src/e2e/families/aptos.ts +11 -1
  150. package/src/e2e/families/cardano.ts +31 -29
  151. package/src/e2e/families/celo.ts +1 -1
  152. package/src/e2e/families/evm.ts +1 -1
  153. package/src/e2e/speculos.ts +28 -25
  154. package/src/families/aptos/__snapshots__/bridge.integration.test.ts.snap +84 -3
  155. package/src/families/aptos/config.ts +12 -0
  156. package/src/families/aptos/constants.ts +2 -0
  157. package/src/families/aptos/logic.ts +2 -0
  158. package/src/families/aptos/react.ts +89 -0
  159. package/src/families/aptos/setup.ts +2 -7
  160. package/src/families/aptos/staking.ts +2 -0
  161. package/src/families/aptos/types.ts +2 -0
  162. package/src/families/aptos/utils.ts +2 -0
  163. package/src/generated/deviceTransactionConfig.ts +0 -2
  164. package/src/modularDrawer/utils/index.test.ts +74 -0
  165. package/src/modularDrawer/utils/index.ts +29 -0
  166. package/lib/families/aptos/consts.d.ts +0 -4
  167. package/lib/families/aptos/consts.d.ts.map +0 -1
  168. package/lib/families/aptos/consts.js +0 -7
  169. package/lib/families/aptos/consts.js.map +0 -1
  170. package/lib-es/families/aptos/consts.d.ts +0 -4
  171. package/lib-es/families/aptos/consts.d.ts.map +0 -1
  172. package/lib-es/families/aptos/consts.js +0 -4
  173. package/lib-es/families/aptos/consts.js.map +0 -1
  174. package/src/families/aptos/consts.ts +0 -3
@@ -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: number = 10): Promise<string[]> {
417
- const speculosApiPort = getEnv("SPECULOS_API_PORT");
418
- const speculosAddress = process.env.SPECULOS_ADDRESS || "http://127.0.0.1";
419
- let attempts = 0;
420
- let textFound: boolean = false;
421
- while (attempts < maxAttempts && !textFound) {
422
- const response = await axios.get<ResponseData>(
423
- `${speculosAddress}:${speculosApiPort}/events?stream=false&currentscreenonly=true`,
424
- );
425
- const responseData = response.data;
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&currentscreenonly=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
- attempts++;
429
+
433
430
  await waitForTimeOut(500);
434
431
  }
435
- return [];
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 = [DeviceLabels.ADDRESS, DeviceLabels.CAPS_APPROVE, DeviceLabels.CAPS_REJECT];
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
- switch (currencyName) {
635
- case Currency.ETH:
636
- await sendEvmNFT(tx);
637
- break;
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.REVIEW_TRANSACTION);
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.REVIEW_TRANSACTION);
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
- "balance": "20020000",
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": 2,
43
+ "operationsCount": 5,
32
44
  "pendingOperations": [],
33
45
  "seedIdentifier": "d6816f4f22f867b56cf9304b776f452a16d107835d73ee8a33c4ced210300583",
34
- "spendableBalance": "20020000",
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,12 @@
1
+ import { CurrencyLiveConfigDefinition } from "../../config";
2
+
3
+ const aptosConfig: CurrencyLiveConfigDefinition = {
4
+ config_currency_aptos: {
5
+ type: "object",
6
+ default: {
7
+ status: { type: "active" },
8
+ },
9
+ },
10
+ };
11
+
12
+ export { aptosConfig };
@@ -0,0 +1,2 @@
1
+ // Encapsulate for LLD and LLM
2
+ export * from "@ledgerhq/coin-aptos/constants";
@@ -0,0 +1,2 @@
1
+ // Encapsulate for LLD and LLM
2
+ export * from "@ledgerhq/coin-aptos/bridge/logic";
@@ -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";
@@ -0,0 +1,2 @@
1
+ // Encapsulate for LLD et LLM
2
+ export * from "@ledgerhq/coin-aptos/logic/staking";
@@ -0,0 +1,2 @@
1
+ // Encapsulate for LLD and LLM
2
+ export * from "@ledgerhq/coin-aptos/types";
@@ -0,0 +1,2 @@
1
+ // Encapsulate for LLD and LLM
2
+ export * from "@ledgerhq/coin-aptos/utils";
@@ -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,4 +0,0 @@
1
- export declare const APTOS_NON_HARDENED_DERIVATION_PATH_REGEX: RegExp;
2
- export declare const APTOS_NON_HARDENED_DERIVATION_PATH = "44'/637'/0'/0/0";
3
- export declare const APTOS_HARDENED_DERIVATION_PATH = "44'/637'/0'/0'/0'";
4
- //# sourceMappingURL=consts.d.ts.map
@@ -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,4 +0,0 @@
1
- export declare const APTOS_NON_HARDENED_DERIVATION_PATH_REGEX: RegExp;
2
- export declare const APTOS_NON_HARDENED_DERIVATION_PATH = "44'/637'/0'/0/0";
3
- export declare const APTOS_HARDENED_DERIVATION_PATH = "44'/637'/0'/0'/0'";
4
- //# sourceMappingURL=consts.d.ts.map
@@ -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,4 +0,0 @@
1
- export const APTOS_NON_HARDENED_DERIVATION_PATH_REGEX = /^44'\/637'\/[0-9]+'\/[0-9]+\/[0-9]+$/;
2
- export const APTOS_NON_HARDENED_DERIVATION_PATH = "44'/637'/0'/0/0";
3
- export const APTOS_HARDENED_DERIVATION_PATH = "44'/637'/0'/0'/0'";
4
- //# sourceMappingURL=consts.js.map
@@ -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"}
@@ -1,3 +0,0 @@
1
- export const APTOS_NON_HARDENED_DERIVATION_PATH_REGEX = /^44'\/637'\/[0-9]+'\/[0-9]+\/[0-9]+$/;
2
- export const APTOS_NON_HARDENED_DERIVATION_PATH = "44'/637'/0'/0/0";
3
- export const APTOS_HARDENED_DERIVATION_PATH = "44'/637'/0'/0'/0'";