@ledgerhq/live-common 27.2.0-nightly.3 → 27.2.0

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 (100) hide show
  1. package/lib/bot/specs.d.ts +0 -8
  2. package/lib/bot/specs.d.ts.map +1 -1
  3. package/lib/bot/specs.js +1 -45
  4. package/lib/bot/specs.js.map +1 -1
  5. package/lib/env.js +1 -1
  6. package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
  7. package/lib/exchange/swap/getExchangeRates.js +1 -1
  8. package/lib/exchange/swap/getExchangeRates.js.map +1 -1
  9. package/lib/exchange/swap/getProviders.d.ts.map +1 -1
  10. package/lib/exchange/swap/getProviders.js +5 -45
  11. package/lib/exchange/swap/getProviders.js.map +1 -1
  12. package/lib/exchange/swap/index.d.ts +1 -2
  13. package/lib/exchange/swap/index.d.ts.map +1 -1
  14. package/lib/exchange/swap/index.js +1 -11
  15. package/lib/exchange/swap/index.js.map +1 -1
  16. package/lib/exchange/swap/index.test.js +0 -22
  17. package/lib/exchange/swap/index.test.js.map +1 -1
  18. package/lib/exchange/swap/mock.js +1 -1
  19. package/lib/exchange/swap/mock.js.map +1 -1
  20. package/lib/exchange/swap/types.d.ts +0 -14
  21. package/lib/exchange/swap/types.d.ts.map +1 -1
  22. package/lib/families/algorand/speculos-deviceActions.d.ts.map +1 -1
  23. package/lib/families/algorand/speculos-deviceActions.js +29 -2
  24. package/lib/families/algorand/speculos-deviceActions.js.map +1 -1
  25. package/lib/families/bitcoin/speculos-deviceActions.d.ts.map +1 -1
  26. package/lib/families/bitcoin/speculos-deviceActions.js +22 -2
  27. package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
  28. package/lib/families/cardano/speculos-deviceActions.d.ts.map +1 -1
  29. package/lib/families/cardano/speculos-deviceActions.js +10 -2
  30. package/lib/families/cardano/speculos-deviceActions.js.map +1 -1
  31. package/lib/families/celo/speculos-deviceActions.d.ts.map +1 -1
  32. package/lib/families/celo/speculos-deviceActions.js +10 -3
  33. package/lib/families/celo/speculos-deviceActions.js.map +1 -1
  34. package/lib/families/elrond/speculos-deviceActions.d.ts.map +1 -1
  35. package/lib/families/elrond/speculos-deviceActions.js +8 -3
  36. package/lib/families/elrond/speculos-deviceActions.js.map +1 -1
  37. package/lib/families/ethereum/speculos-deviceActions.d.ts.map +1 -1
  38. package/lib/families/ethereum/speculos-deviceActions.js +33 -10
  39. package/lib/families/ethereum/speculos-deviceActions.js.map +1 -1
  40. package/lib/families/evm/specs.d.ts.map +1 -1
  41. package/lib/families/evm/specs.js +3 -7
  42. package/lib/families/evm/specs.js.map +1 -1
  43. package/lib/families/evm/speculos-deviceActions.d.ts.map +1 -1
  44. package/lib/families/evm/speculos-deviceActions.js +25 -5
  45. package/lib/families/evm/speculos-deviceActions.js.map +1 -1
  46. package/lib/families/filecoin/speculos-deviceActions.d.ts.map +1 -1
  47. package/lib/families/filecoin/speculos-deviceActions.js +10 -6
  48. package/lib/families/filecoin/speculos-deviceActions.js.map +1 -1
  49. package/lib/families/polkadot/speculos-deviceActions.d.ts.map +1 -1
  50. package/lib/families/polkadot/speculos-deviceActions.js +10 -3
  51. package/lib/families/polkadot/speculos-deviceActions.js.map +1 -1
  52. package/lib/families/ripple/speculos-deviceActions.d.ts.map +1 -1
  53. package/lib/families/ripple/speculos-deviceActions.js +22 -2
  54. package/lib/families/ripple/speculos-deviceActions.js.map +1 -1
  55. package/lib/families/solana/speculos-deviceActions.d.ts.map +1 -1
  56. package/lib/families/solana/speculos-deviceActions.js +7 -5
  57. package/lib/families/solana/speculos-deviceActions.js.map +1 -1
  58. package/lib/families/stellar/api/horizon.d.ts.map +1 -1
  59. package/lib/families/stellar/api/horizon.js +10 -15
  60. package/lib/families/stellar/api/horizon.js.map +1 -1
  61. package/lib/families/stellar/speculos-deviceActions.d.ts.map +1 -1
  62. package/lib/families/stellar/speculos-deviceActions.js +8 -4
  63. package/lib/families/stellar/speculos-deviceActions.js.map +1 -1
  64. package/lib/families/tezos/speculos-deviceActions.d.ts.map +1 -1
  65. package/lib/families/tezos/speculos-deviceActions.js +11 -6
  66. package/lib/families/tezos/speculos-deviceActions.js.map +1 -1
  67. package/lib/families/tron/speculos-deviceActions.d.ts.map +1 -1
  68. package/lib/families/tron/speculos-deviceActions.js +14 -2
  69. package/lib/families/tron/speculos-deviceActions.js.map +1 -1
  70. package/package.json +17 -17
  71. package/src/bot/specs.ts +0 -39
  72. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +35 -1
  73. package/src/env.ts +1 -1
  74. package/src/exchange/swap/getExchangeRates.ts +3 -7
  75. package/src/exchange/swap/getProviders.ts +8 -31
  76. package/src/exchange/swap/index.test.ts +1 -36
  77. package/src/exchange/swap/index.ts +0 -15
  78. package/src/exchange/swap/mock.ts +2 -2
  79. package/src/exchange/swap/types.ts +0 -11
  80. package/src/families/algorand/speculos-deviceActions.ts +35 -4
  81. package/src/families/bitcoin/speculos-deviceActions.ts +26 -3
  82. package/src/families/cardano/speculos-deviceActions.ts +14 -3
  83. package/src/families/celo/speculos-deviceActions.ts +14 -6
  84. package/src/families/elrond/speculos-deviceActions.ts +9 -4
  85. package/src/families/ethereum/speculos-deviceActions.ts +46 -16
  86. package/src/families/evm/specs.ts +6 -10
  87. package/src/families/evm/speculos-deviceActions.ts +35 -7
  88. package/src/families/filecoin/speculos-deviceActions.ts +11 -7
  89. package/src/families/polkadot/speculos-deviceActions.ts +16 -5
  90. package/src/families/ripple/speculos-deviceActions.ts +28 -3
  91. package/src/families/solana/speculos-deviceActions.ts +8 -6
  92. package/src/families/stellar/api/horizon.ts +6 -10
  93. package/src/families/stellar/speculos-deviceActions.ts +11 -5
  94. package/src/families/tezos/speculos-deviceActions.ts +16 -9
  95. package/src/families/tron/speculos-deviceActions.ts +12 -4
  96. package/lib/exchange/swap/getProviders.test.d.ts +0 -2
  97. package/lib/exchange/swap/getProviders.test.d.ts.map +0 -1
  98. package/lib/exchange/swap/getProviders.test.js +0 -519
  99. package/lib/exchange/swap/getProviders.test.js.map +0 -1
  100. package/src/exchange/swap/getProviders.test.ts +0 -450
@@ -1,6 +1,7 @@
1
1
  import type { DeviceAction } from "../../bot/types";
2
2
  import type { Transaction } from "./types";
3
- import { deviceActionFlow, formatDeviceAmount } from "../../bot/specs";
3
+ import { formatCurrencyUnit } from "../../currencies";
4
+ import { deviceActionFlow } from "../../bot/specs";
4
5
 
5
6
  export const acceptTransaction: DeviceAction<Transaction, any> =
6
7
  deviceActionFlow({
@@ -14,13 +15,37 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
14
15
  title: "Amount",
15
16
  button: "Rr",
16
17
  expectedValue: ({ account, status }) =>
17
- formatDeviceAmount(account.currency, status.amount),
18
+ formatCurrencyUnit(
19
+ {
20
+ ...account.unit,
21
+ code: account.currency.deviceTicker || account.unit.code,
22
+ prefixCode: true,
23
+ },
24
+ status.amount,
25
+ {
26
+ showCode: true,
27
+ disableRounding: true,
28
+ joinFragmentsSeparator: " ",
29
+ }
30
+ ).replace(/\s/g, " "),
18
31
  },
19
32
  {
20
33
  title: "Fee",
21
34
  button: "Rr",
22
35
  expectedValue: ({ account, status }) =>
23
- formatDeviceAmount(account.currency, status.estimatedFees),
36
+ formatCurrencyUnit(
37
+ {
38
+ ...account.unit,
39
+ code: account.currency.deviceTicker || account.unit.code,
40
+ prefixCode: true,
41
+ },
42
+ status.estimatedFees,
43
+ {
44
+ showCode: true,
45
+ disableRounding: true,
46
+ joinFragmentsSeparator: " ",
47
+ }
48
+ ).replace(/\s/g, " "),
24
49
  },
25
50
  {
26
51
  title: "Destination Tag",
@@ -1,6 +1,7 @@
1
1
  import type { DeviceAction } from "../../bot/types";
2
2
  import type { Transaction } from "./types";
3
- import { deviceActionFlow, formatDeviceAmount } from "../../bot/specs";
3
+ import { formatCurrencyUnit } from "../../currencies";
4
+ import { deviceActionFlow } from "../../bot/specs";
4
5
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
5
6
  import BigNumber from "bignumber.js";
6
7
  import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
@@ -16,11 +17,12 @@ function ellipsis(str: string) {
16
17
  return `${str.slice(0, 7)}..${str.slice(-7)}`;
17
18
  }
18
19
 
19
- function formatAmount(c: CryptoCurrency, amount: number) {
20
- const currency = getMainCurrency(c);
21
- return formatDeviceAmount(currency, new BigNumber(amount), {
22
- postfixCode: true,
23
- });
20
+ function formatAmount(currency: CryptoCurrency, amount: number) {
21
+ const unit = getMainCurrency(currency).units[0];
22
+ return formatCurrencyUnit(unit, new BigNumber(amount), {
23
+ disableRounding: true,
24
+ showCode: true,
25
+ }).replace(/\s/g, " ");
24
26
  }
25
27
 
26
28
  export const acceptTransferTransaction: DeviceAction<Transaction, any> =
@@ -3,7 +3,7 @@ import StellarSdk, {
3
3
  // @ts-expect-error stellar-sdk ts definition missing?
4
4
  AccountRecord,
5
5
  NotFoundError,
6
- NetworkError as StellarSdkNetworkError,
6
+ NetworkError,
7
7
  } from "stellar-sdk";
8
8
  import { getEnv } from "../../../env";
9
9
  import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
@@ -14,7 +14,7 @@ import {
14
14
  rawOperationsToOperations,
15
15
  getReservedBalance,
16
16
  } from "../logic";
17
- import { LedgerAPI4xx, LedgerAPI5xx, NetworkError } from "@ledgerhq/errors";
17
+ import { NetworkDown, LedgerAPI4xx, LedgerAPI5xx } from "@ledgerhq/errors";
18
18
  import { requestInterceptor, responseInterceptor } from "../../../network";
19
19
  import type { BalanceAsset } from "../types";
20
20
  import { NetworkCongestionLevel, Signer } from "../types";
@@ -127,12 +127,8 @@ export const fetchAccount = async (
127
127
  assets = account.balances?.filter((balance) => {
128
128
  return balance.asset_type !== "native";
129
129
  });
130
- } catch (e: any) {
131
- if (e instanceof NotFoundError || e?.response?.status === 400) {
132
- balance.balance = "0";
133
- } else {
134
- throw new NetworkError();
135
- }
130
+ } catch (e) {
131
+ balance.balance = "0";
136
132
  }
137
133
 
138
134
  const formattedBalance = parseCurrencyUnit(
@@ -209,11 +205,11 @@ export const fetchOperations = async ({
209
205
  }
210
206
 
211
207
  if (
212
- e instanceof StellarSdkNetworkError ||
208
+ e instanceof NetworkError ||
213
209
  errorMsg.match(/ECONNRESET|ECONNREFUSED|ENOTFOUND|EPIPE|ETIMEDOUT/) ||
214
210
  errorMsg.match(/undefined is not an object/)
215
211
  ) {
216
- throw new NetworkError();
212
+ throw new NetworkDown();
217
213
  }
218
214
 
219
215
  throw e;
@@ -1,11 +1,14 @@
1
1
  import type { DeviceAction } from "../../bot/types";
2
2
  import type { Transaction } from "./types";
3
3
  import { formatCurrencyUnit } from "../../currencies";
4
- import { deviceActionFlow, formatDeviceAmount } from "../../bot/specs";
4
+ import { deviceActionFlow } from "../../bot/specs";
5
5
 
6
6
  const expectedAmount = ({ account, status, transaction }) => {
7
7
  if (transaction.assetCode && transaction.assetIssuer) {
8
- const amount = formatDeviceAmount(account.currency, status.amount);
8
+ const amount = formatCurrencyUnit(account.unit, status.amount, {
9
+ disableRounding: true,
10
+ useGrouping: false,
11
+ });
9
12
 
10
13
  return `${amount} ${transaction.assetCode}@${truncateAddress(
11
14
  transaction.assetIssuer,
@@ -14,9 +17,12 @@ const expectedAmount = ({ account, status, transaction }) => {
14
17
  )}`;
15
18
  }
16
19
 
17
- return formatDeviceAmount(account.currency, status.amount, {
18
- postfixCode: true,
19
- });
20
+ return (
21
+ formatCurrencyUnit(account.unit, status.amount, {
22
+ disableRounding: true,
23
+ useGrouping: false,
24
+ }) + " XLM"
25
+ );
20
26
  };
21
27
 
22
28
  const truncateAddress = (stellarAddress: string, start = 6, end = 6) =>
@@ -1,7 +1,8 @@
1
1
  // @flow
2
2
  import type { DeviceAction } from "../../bot/types";
3
3
  import type { Transaction } from "./types";
4
- import { deviceActionFlow, formatDeviceAmount } from "../../bot/specs";
4
+ import { formatCurrencyUnit } from "../../currencies";
5
+ import { deviceActionFlow } from "../../bot/specs";
5
6
 
6
7
  export const acceptTransaction: DeviceAction<Transaction, any> =
7
8
  deviceActionFlow({
@@ -37,18 +38,24 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
37
38
  {
38
39
  title: "Amount",
39
40
  button: "Rr",
40
- expectedValue: ({ account, transaction }) =>
41
- formatDeviceAmount(account.currency, transaction.amount, {
42
- hideCode: true,
43
- }),
41
+ expectedValue: ({ account, transaction }) => {
42
+ const amount = transaction.amount;
43
+ return formatCurrencyUnit(account.unit, amount, {
44
+ disableRounding: true,
45
+ joinFragmentsSeparator: " ",
46
+ }).replace(/\s/g, " ");
47
+ },
44
48
  },
45
49
  {
46
50
  title: "Fee",
47
51
  button: "Rr",
48
- expectedValue: ({ account, status }) =>
49
- formatDeviceAmount(account.currency, status.estimatedFees, {
50
- hideCode: true,
51
- }),
52
+ expectedValue: ({ account, status }) => {
53
+ const amount = status.estimatedFees;
54
+ return formatCurrencyUnit(account.currency.units[0], amount, {
55
+ disableRounding: true,
56
+ joinFragmentsSeparator: " ",
57
+ }).replace(/\s/g, " ");
58
+ },
52
59
  },
53
60
  {
54
61
  title: "Source",
@@ -1,5 +1,6 @@
1
1
  import type { DeviceAction } from "../../bot/types";
2
- import { deviceActionFlow, formatDeviceAmount } from "../../bot/specs";
2
+ import { deviceActionFlow } from "../../bot/specs";
3
+ import { formatCurrencyUnit } from "../../currencies";
3
4
  import type { Transaction, Vote } from "./types";
4
5
 
5
6
  function subAccount(subAccountId, account) {
@@ -39,9 +40,16 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
39
40
  title: "Amount",
40
41
  button: "Rr",
41
42
  expectedValue: ({ account, status }) =>
42
- formatDeviceAmount(account.currency, status.amount, {
43
- hideCode: true,
44
- }),
43
+ formatCurrencyUnit(
44
+ {
45
+ ...account.unit,
46
+ code: account.currency.deviceTicker || account.unit.code,
47
+ },
48
+ status.amount,
49
+ {
50
+ disableRounding: true,
51
+ }
52
+ ),
45
53
  },
46
54
  {
47
55
  title: "Token",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=getProviders.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getProviders.test.d.ts","sourceRoot":"","sources":["../../../src/exchange/swap/getProviders.test.ts"],"names":[],"mappings":""}