@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
@@ -2,52 +2,29 @@ import qs from "qs";
2
2
  import { getEnv } from "../../env";
3
3
  import { SwapNoAvailableProviders } from "../../errors";
4
4
  import network from "../../network";
5
- import {
6
- getAvailableProviders,
7
- getSwapAPIBaseURL,
8
- getSwapAPIVersion,
9
- } from "./";
5
+ import { getAvailableProviders, getSwapAPIBaseURL } from "./";
10
6
  import { mockGetProviders } from "./mock";
11
- import type { GetProviders, ProvidersResponseV4 } from "./types";
7
+ import type { GetProviders } from "./types";
12
8
 
13
9
  const getProviders: GetProviders = async () => {
14
10
  if (getEnv("MOCK")) return mockGetProviders();
15
11
 
16
- const version = getSwapAPIVersion();
12
+ // Rely on the api base to determine the version logic
13
+ const usesV3 = getSwapAPIBaseURL().endsWith("v3");
17
14
 
18
15
  const res = await network({
19
16
  method: "GET",
20
17
  url: `${getSwapAPIBaseURL()}/providers`,
21
- params: version >= 3 ? { whitelist: getAvailableProviders() } : undefined,
18
+ params: usesV3 ? { whitelist: getAvailableProviders() } : undefined,
22
19
  paramsSerializer: (params) =>
23
20
  qs.stringify(params, { arrayFormat: "comma" }),
24
21
  });
25
22
 
26
- if (version < 4) {
27
- if (!res.data.length) {
28
- throw new SwapNoAvailableProviders();
29
- }
30
- return res.data;
31
- }
32
-
33
- const responseV4 = res.data as ProvidersResponseV4;
34
- if (!responseV4.providers || !Object.keys(responseV4.providers).length) {
23
+ if (!res.data.length) {
35
24
  throw new SwapNoAvailableProviders();
36
25
  }
37
- return Object.entries(responseV4.providers).flatMap(([provider, groups]) => ({
38
- provider: provider,
39
- pairs: groups.flatMap((group) =>
40
- group.methods.flatMap((tradeMethod) =>
41
- Object.entries(group.pairs).flatMap(([from, toArray]) =>
42
- (toArray as number[]).map((to) => ({
43
- from: responseV4.currencies[from],
44
- to: responseV4.currencies[to.toString()],
45
- tradeMethod,
46
- }))
47
- )
48
- )
49
- ),
50
- }));
26
+
27
+ return res.data;
51
28
  };
52
29
 
53
30
  export default getProviders;
@@ -1,6 +1,4 @@
1
- import { isSwapOperationPending, getSwapAPIVersion } from ".";
2
-
3
- import { getEnv, setEnv } from "../../env";
1
+ import { isSwapOperationPending } from ".";
4
2
 
5
3
  describe("swap/index", () => {
6
4
  describe("isSwapOperationPending", () => {
@@ -35,37 +33,4 @@ describe("swap/index", () => {
35
33
  expect(result).toBe(true);
36
34
  });
37
35
  });
38
-
39
- describe("getSwapAPIVersion", () => {
40
- const DEFAULT_SWAP_API_BASE = getEnv("SWAP_API_BASE");
41
-
42
- afterEach(() => {
43
- // Restore DEFAULT_SWAP_API_BASE
44
- setEnv("SWAP_API_BASE", DEFAULT_SWAP_API_BASE);
45
- });
46
-
47
- test("should return version when SWAP_API_BASE contains one", () => {
48
- const result = getSwapAPIVersion();
49
-
50
- expect(result).toBe(4);
51
- });
52
-
53
- test("should throw an error if no version in SWAP_API_BASE", () => {
54
- setEnv("SWAP_API_BASE", "https://swap.ledger.com");
55
-
56
- expect(getSwapAPIVersion).toThrow(Error);
57
- expect(getSwapAPIVersion).toThrow(
58
- "Configured swap API base URL is invalid, should end with /v<number>"
59
- );
60
- });
61
-
62
- test("should throw an error if version is NaN", () => {
63
- setEnv("SWAP_API_BASE", "https://swap.ledger.com/vtest");
64
-
65
- expect(getSwapAPIVersion).toThrow(Error);
66
- expect(getSwapAPIVersion).toThrow(
67
- "Configured swap API base URL is invalid, should end with /v<number>"
68
- );
69
- });
70
- });
71
36
  });
@@ -11,7 +11,6 @@ import {
11
11
  JSONRPCResponseError,
12
12
  NoIPHeaderError,
13
13
  NotImplementedError,
14
- SwapGenericAPIError,
15
14
  TradeMethodNotSupportedError,
16
15
  UnexpectedError,
17
16
  ValidationError,
@@ -37,19 +36,6 @@ export const isSwapOperationPending: (status: string) => boolean = (status) =>
37
36
 
38
37
  const getSwapAPIBaseURL: () => string = () => getEnv("SWAP_API_BASE");
39
38
 
40
- const SWAP_API_BASE_PATTERN = /.*\/v(?<version>\d+)\/*$/;
41
- const getSwapAPIVersion: () => number = () => {
42
- const version = Number(
43
- getSwapAPIBaseURL().match(SWAP_API_BASE_PATTERN)?.groups?.version
44
- );
45
- if (version == null || isNaN(version)) {
46
- throw new SwapGenericAPIError(
47
- "Configured swap API base URL is invalid, should end with /v<number>"
48
- );
49
- }
50
- return version;
51
- };
52
-
53
39
  const ftx = {
54
40
  nameAndPubkey: Buffer.concat([
55
41
  Buffer.from([3]),
@@ -193,7 +179,6 @@ export const getSwapAPIError = (errorCode: number, errorMessage?: string) => {
193
179
 
194
180
  export {
195
181
  getSwapAPIBaseURL,
196
- getSwapAPIVersion,
197
182
  getProviderConfig,
198
183
  getProviders,
199
184
  getExchangeRates,
@@ -7,7 +7,7 @@ import {
7
7
  SwapExchangeRateAmountTooHigh,
8
8
  SwapExchangeRateAmountTooLow,
9
9
  } from "../../errors";
10
- import { getSwapAPIVersion } from "./";
10
+ import { getSwapAPIBaseURL } from "./";
11
11
  import type {
12
12
  CheckQuote,
13
13
  Exchange,
@@ -129,7 +129,7 @@ export const mockInitSwap = (
129
129
  export const mockGetProviders: GetProviders = async () => {
130
130
  //Fake delay to show loading UI
131
131
  await new Promise((r) => setTimeout(r, 800));
132
- const usesV3 = getSwapAPIVersion() >= 3;
132
+ const usesV3 = getSwapAPIBaseURL().endsWith("v3");
133
133
 
134
134
  return usesV3
135
135
  ? [
@@ -83,17 +83,6 @@ export type AvailableProviderV3 = {
83
83
  pairs: Array<{ from: string; to: string; tradeMethod: string }>;
84
84
  };
85
85
 
86
- type TradeMethodGroup = {
87
- methods: TradeMethod[];
88
- pairs: {
89
- [currencyIndex: number]: number[];
90
- };
91
- };
92
- export type ProvidersResponseV4 = {
93
- currencies: { [currencyIndex: number]: string };
94
- providers: { [providerName: string]: TradeMethodGroup[] };
95
- };
96
-
97
86
  type CheckQuoteOkStatus = {
98
87
  codeName: "RATE_VALID";
99
88
  };
@@ -1,10 +1,26 @@
1
1
  import type { DeviceAction } from "../../bot/types";
2
2
  import type { AlgorandTransaction } from "./types";
3
- import { findTokenById } from "../../currencies";
4
- import { deviceActionFlow, formatDeviceAmount } from "../../bot/specs";
3
+ import { formatCurrencyUnit, findTokenById } from "../../currencies";
4
+ import { deviceActionFlow } from "../../bot/specs";
5
5
  import { extractTokenId, addPrefixToken } from "./tokens";
6
6
  import { displayTokenValue } from "./deviceTransactionConfig";
7
7
 
8
+ // Will be useful when unit is gonna be algo
9
+ const expectedAmount = ({ account, status }) =>
10
+ formatCurrencyUnit(
11
+ {
12
+ ...account.unit,
13
+ code: account.currency.deviceTicker || account.unit.code,
14
+ prefixCode: true,
15
+ },
16
+ status.amount,
17
+ {
18
+ showCode: true,
19
+ disableRounding: true,
20
+ joinFragmentsSeparator: " ",
21
+ }
22
+ );
23
+
8
24
  export const acceptTransaction: DeviceAction<AlgorandTransaction, any> =
9
25
  deviceActionFlow({
10
26
  steps: [
@@ -26,7 +42,19 @@ export const acceptTransaction: DeviceAction<AlgorandTransaction, any> =
26
42
  title: "Fee",
27
43
  button: "Rr",
28
44
  expectedValue: ({ account, status }) =>
29
- formatDeviceAmount(account.currency, status.estimatedFees),
45
+ formatCurrencyUnit(
46
+ {
47
+ ...account.unit,
48
+ code: account.currency.deviceTicker || account.unit.code,
49
+ prefixCode: true,
50
+ },
51
+ status.estimatedFees,
52
+ {
53
+ showCode: true,
54
+ disableRounding: true,
55
+ joinFragmentsSeparator: " ",
56
+ }
57
+ ),
30
58
  },
31
59
  {
32
60
  title: "Asset ID",
@@ -67,7 +95,10 @@ export const acceptTransaction: DeviceAction<AlgorandTransaction, any> =
67
95
  expectedValue: ({ account, status, transaction }) =>
68
96
  transaction.mode === "claimReward"
69
97
  ? "0"
70
- : formatDeviceAmount(account.currency, status.amount),
98
+ : expectedAmount({
99
+ account,
100
+ status,
101
+ }),
71
102
  },
72
103
  {
73
104
  title: "APPROVE",
@@ -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 { perCoinLogic } from "./logic";
5
6
 
6
7
  export const acceptTransaction: DeviceAction<Transaction, any> =
@@ -10,15 +11,37 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
10
11
  title: "Amount",
11
12
  button: "Rr",
12
13
  ignoreAssertionFailure: true,
14
+ // https://ledgerhq.atlassian.net/browse/LLC-676
13
15
  expectedValue: ({ account, status }) =>
14
- formatDeviceAmount(account.currency, status.amount),
16
+ formatCurrencyUnit(
17
+ {
18
+ ...account.unit,
19
+ code: account.currency.deviceTicker || account.unit.code,
20
+ },
21
+ status.amount,
22
+ {
23
+ showCode: true,
24
+ disableRounding: true,
25
+ }
26
+ ).replace(/\s/g, " "),
15
27
  },
16
28
  {
17
29
  title: "Fees",
18
30
  button: "Rr",
19
31
  ignoreAssertionFailure: true,
32
+ // https://ledgerhq.atlassian.net/browse/LLC-676
20
33
  expectedValue: ({ account, status }) =>
21
- formatDeviceAmount(account.currency, status.estimatedFees),
34
+ formatCurrencyUnit(
35
+ {
36
+ ...account.unit,
37
+ code: account.currency.deviceTicker || account.unit.code,
38
+ },
39
+ status.estimatedFees,
40
+ {
41
+ showCode: true,
42
+ disableRounding: true,
43
+ }
44
+ ).replace(/\s/g, " "),
22
45
  },
23
46
  {
24
47
  title: "Address",
@@ -1,6 +1,17 @@
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";
5
+ import type { Unit } from "@ledgerhq/types-cryptoassets";
6
+ import BigNumber from "bignumber.js";
7
+
8
+ function expectedValue(unit: Unit, value: BigNumber) {
9
+ return formatCurrencyUnit(unit, value, {
10
+ showCode: true,
11
+ disableRounding: true,
12
+ showAllDigits: true,
13
+ });
14
+ }
4
15
 
5
16
  export const acceptTransaction: DeviceAction<Transaction, any> =
6
17
  deviceActionFlow({
@@ -27,7 +38,7 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
27
38
  button: "LRlr",
28
39
  ignoreAssertionFailure: true,
29
40
  expectedValue: ({ account, status }) =>
30
- formatDeviceAmount(account.currency, status.amount),
41
+ expectedValue(account.unit, status.amount),
31
42
  },
32
43
  {
33
44
  title: "Asset fingerprint",
@@ -49,7 +60,7 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
49
60
  button: "LRlr",
50
61
  ignoreAssertionFailure: true,
51
62
  expectedValue: ({ account, status }) =>
52
- formatDeviceAmount(account.currency, status.estimatedFees),
63
+ expectedValue(account.unit, status.estimatedFees),
53
64
  },
54
65
  {
55
66
  title: "Transaction TTL",
@@ -1,7 +1,7 @@
1
1
  import type { DeviceAction } from "../../bot/types";
2
2
  import type { Transaction } from "./types";
3
- import { deviceActionFlow, formatDeviceAmount } from "../../bot/specs";
4
-
3
+ import { deviceActionFlow } from "../../bot/specs";
4
+ import { formatCurrencyUnit } from "../../currencies";
5
5
  const typeWording = {
6
6
  send: "Send",
7
7
  lock: "Lock",
@@ -23,10 +23,18 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
23
23
  {
24
24
  title: "Amount",
25
25
  button: "Rr",
26
- expectedValue: ({ account, status }) =>
27
- formatDeviceAmount(account.currency, status.amount, {
28
- forceFloating: true,
29
- }),
26
+ expectedValue: ({ account, status }) => {
27
+ const formattedValue =
28
+ "CELO " +
29
+ formatCurrencyUnit(account.unit, status.amount, {
30
+ disableRounding: true,
31
+ });
32
+ if (!formattedValue.includes(".")) {
33
+ // if the value is pure integer, in the app it will automatically add an .0
34
+ return formattedValue + ".0";
35
+ }
36
+ return formattedValue;
37
+ },
30
38
  },
31
39
  {
32
40
  title: "Address",
@@ -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 { deviceActionFlow } from "../../bot/specs";
4
+ import { formatCurrencyUnit } from "../../currencies";
4
5
 
5
6
  export const acceptTransaction: DeviceAction<Transaction, any> =
6
7
  deviceActionFlow({
@@ -14,9 +15,13 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
14
15
  title: "Amount",
15
16
  button: "Rr",
16
17
  expectedValue: ({ account, transaction }) =>
17
- formatDeviceAmount(account.currency, transaction.amount, {
18
- postfixCode: true,
19
- }),
18
+ formatCurrencyUnit(account.unit, transaction.amount, {
19
+ showCode: true,
20
+ disableRounding: true,
21
+ joinFragmentsSeparator: " ",
22
+ })
23
+ .replace(/\s+/g, " ")
24
+ .replace("egld", "EGLD"), // FIXME
20
25
  },
21
26
  {
22
27
  title: "Fee",
@@ -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, findCompoundToken } from "../../currencies";
4
+ import { deviceActionFlow } from "../../bot/specs";
4
5
 
5
6
  function subAccount(subAccountId, account) {
6
7
  const sub = (account.subAccounts || []).find((a) => a.id === subAccountId);
@@ -9,8 +10,28 @@ function subAccount(subAccountId, account) {
9
10
  return sub;
10
11
  }
11
12
 
13
+ function expectedCompoundToken(t) {
14
+ if (!t) {
15
+ throw new Error("compound token was expected");
16
+ }
17
+
18
+ return t;
19
+ }
20
+
12
21
  const maxFeesExpectedValue = ({ account, status }) =>
13
- formatDeviceAmount(account.currency, status.estimatedFees);
22
+ formatCurrencyUnit(
23
+ {
24
+ ...account.unit,
25
+ code: account.currency.deviceTicker || account.unit.code,
26
+ prefixCode: true,
27
+ },
28
+ status.estimatedFees,
29
+ {
30
+ showCode: true,
31
+ disableRounding: true,
32
+ joinFragmentsSeparator: " ",
33
+ }
34
+ ).replace(/\s/g, " ");
14
35
 
15
36
  export const acceptTransaction: DeviceAction<Transaction, any> =
16
37
  deviceActionFlow({
@@ -45,6 +66,16 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
45
66
  return "Unlimited " + a.token.ticker;
46
67
  }
47
68
 
69
+ const unit = !a
70
+ ? {
71
+ ...account.unit,
72
+ code: account.currency.deviceTicker || account.unit.code,
73
+ }
74
+ : (transaction.mode === "compound.withdraw" &&
75
+ transaction.useAllAmount
76
+ ? expectedCompoundToken(findCompoundToken(a.token))
77
+ : a.token
78
+ ).units[0];
48
79
  const amount =
49
80
  a &&
50
81
  a.compoundBalance &&
@@ -52,20 +83,19 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
52
83
  transaction.useAllAmount
53
84
  ? a.compoundBalance
54
85
  : status.amount;
55
-
56
- if (
57
- a &&
58
- transaction.mode === "compound.withdraw" &&
59
- transaction.useAllAmount
60
- ) {
61
- return formatDeviceAmount(a.compoundBalance, amount);
62
- }
63
-
64
- if (a) {
65
- return formatDeviceAmount(a.token, amount);
66
- }
67
-
68
- return formatDeviceAmount(account.currency, amount);
86
+ return formatCurrencyUnit(
87
+ {
88
+ ...unit,
89
+ code: account.currency.deviceTicker || account.unit.code,
90
+ prefixCode: true,
91
+ },
92
+ amount,
93
+ {
94
+ showCode: true,
95
+ disableRounding: true,
96
+ joinFragmentsSeparator: " ",
97
+ }
98
+ ).replace(/\s/g, " ");
69
99
  },
70
100
  },
71
101
  {
@@ -3,7 +3,7 @@ import invariant from "invariant";
3
3
  import { DeviceModelId } from "@ledgerhq/devices";
4
4
  import { getCryptoCurrencyById, parseCurrencyUnit } from "../../currencies";
5
5
  import { acceptTransaction } from "./speculos-deviceActions";
6
- import { botTest, pickSiblings } from "../../bot/specs";
6
+ import { pickSiblings } from "../../bot/specs";
7
7
  import type { AppSpec } from "../../bot/types";
8
8
  import type { Transaction } from "./types";
9
9
 
@@ -45,17 +45,13 @@ const evmBasicMutations = ({ maxAccount }) => [
45
45
  "operation time to be older than 60s"
46
46
  );
47
47
  const estimatedGas = transaction.gasLimit.times(
48
- transaction.gasPrice || transaction.maxFeePerGas || 0
48
+ transaction.gasPrice || 0
49
49
  );
50
- botTest("operation fee is not exceeding estimated gas", () =>
51
- expect(operation.fee.toNumber()).toBeLessThanOrEqual(
52
- estimatedGas.toNumber()
53
- )
50
+ expect(operation.fee.toNumber()).toBeLessThanOrEqual(
51
+ estimatedGas.toNumber()
54
52
  );
55
- botTest("account balance moved with operation value", () =>
56
- expect(account.balance.toString()).toBe(
57
- accountBeforeTransaction.balance.minus(operation.value).toString()
58
- )
53
+ expect(account.balance.toString()).toBe(
54
+ accountBeforeTransaction.balance.minus(operation.value).toString()
59
55
  );
60
56
  },
61
57
  },
@@ -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
  function subAccount(subAccountId, account) {
6
7
  const sub = (account.subAccounts || []).find((a) => a.id === subAccountId);
@@ -10,7 +11,19 @@ function subAccount(subAccountId, account) {
10
11
  }
11
12
 
12
13
  const maxFeesExpectedValue = ({ account, status }) =>
13
- formatDeviceAmount(account.currency, status.estimatedFees);
14
+ formatCurrencyUnit(
15
+ {
16
+ ...account.unit,
17
+ code: account.currency.deviceTicker || account.unit.code,
18
+ prefixCode: true,
19
+ },
20
+ status.estimatedFees,
21
+ {
22
+ showCode: true,
23
+ disableRounding: true,
24
+ joinFragmentsSeparator: " ",
25
+ }
26
+ ).replace(/\s/g, " ");
14
27
 
15
28
  export const acceptTransaction: DeviceAction<Transaction, any> =
16
29
  deviceActionFlow({
@@ -31,11 +44,26 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
31
44
  ? subAccount(transaction.subAccountId, account)
32
45
  : null;
33
46
 
34
- if (a) {
35
- return formatDeviceAmount(a.token, status.amount);
36
- }
37
-
38
- return formatDeviceAmount(account.currency, status.amount);
47
+ const unit = !a
48
+ ? {
49
+ ...account.unit,
50
+ code: account.currency.deviceTicker || account.unit.code,
51
+ }
52
+ : a.token.units[0];
53
+ const amount = status.amount;
54
+ return formatCurrencyUnit(
55
+ {
56
+ ...unit,
57
+ code: account.currency.deviceTicker || account.unit.code,
58
+ prefixCode: true,
59
+ },
60
+ amount,
61
+ {
62
+ showCode: true,
63
+ disableRounding: true,
64
+ joinFragmentsSeparator: " ",
65
+ }
66
+ ).replace(/\s/g, " ");
39
67
  },
40
68
  },
41
69
  {
@@ -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 { deviceActionFlow } from "../../bot/specs";
4
+ import { formatCurrencyUnit } from "../../currencies";
4
5
 
5
6
  export const acceptTransaction: DeviceAction<Transaction, any> =
6
7
  deviceActionFlow({
@@ -24,8 +25,9 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
24
25
  title: "Value",
25
26
  button: "Rr",
26
27
  expectedValue: ({ account, status }) =>
27
- formatDeviceAmount(account.currency, status.amount, {
28
- hideCode: true,
28
+ formatCurrencyUnit(account.unit, status.amount, {
29
+ disableRounding: true,
30
+ showAllDigits: true,
29
31
  }),
30
32
  },
31
33
  {
@@ -37,16 +39,18 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
37
39
  title: "Gas Premium",
38
40
  button: "Rr",
39
41
  expectedValue: ({ account, transaction }) =>
40
- formatDeviceAmount(account.currency, transaction.gasPremium, {
41
- hideCode: true,
42
+ formatCurrencyUnit(account.unit, transaction.gasPremium, {
43
+ disableRounding: true,
44
+ showAllDigits: true,
42
45
  }),
43
46
  },
44
47
  {
45
48
  title: "Gas Fee Cap",
46
49
  button: "Rr",
47
50
  expectedValue: ({ account, transaction }) =>
48
- formatDeviceAmount(account.currency, transaction.gasFeeCap, {
49
- hideCode: true,
51
+ formatCurrencyUnit(account.unit, transaction.gasFeeCap, {
52
+ disableRounding: true,
53
+ showAllDigits: true,
50
54
  }),
51
55
  },
52
56
  {
@@ -1,6 +1,7 @@
1
1
  import type { DeviceAction } from "../../bot/types";
2
2
  import type { PolkadotAccount, Transaction } from "./types";
3
- import { deviceActionFlow, formatDeviceAmount } from "../../bot/specs";
3
+ import { deviceActionFlow } from "../../bot/specs";
4
+ import { formatCurrencyUnit } from "../../currencies";
4
5
 
5
6
  export const acceptTransaction: DeviceAction<Transaction, any> =
6
7
  deviceActionFlow({
@@ -21,10 +22,20 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
21
22
  {
22
23
  title: "Amount",
23
24
  button: "Rr",
24
- expectedValue: ({ account, transaction }) =>
25
- formatDeviceAmount(account.currency, transaction.amount, {
26
- forceFloating: true,
27
- }),
25
+ expectedValue: ({ account, transaction }) => {
26
+ const formattedValue =
27
+ "DOT " +
28
+ formatCurrencyUnit(account.unit, transaction.amount, {
29
+ disableRounding: true,
30
+ });
31
+
32
+ if (!formattedValue.includes(".")) {
33
+ // if the value is pure integer, in the app it will automatically add an .0
34
+ return formattedValue + ".0";
35
+ }
36
+
37
+ return formattedValue;
38
+ },
28
39
  },
29
40
  {
30
41
  title: "Chain",