@ledgerhq/live-common 34.33.2-hotfix.0 → 34.34.0-nightly.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 (99) hide show
  1. package/lib/DataModel.d.ts.map +1 -1
  2. package/lib/DataModel.js +8 -0
  3. package/lib/DataModel.js.map +1 -1
  4. package/lib/DataModel.test.js +46 -0
  5. package/lib/DataModel.test.js.map +1 -1
  6. package/lib/domain/getTokensWithFunds.d.ts +3 -0
  7. package/lib/domain/getTokensWithFunds.d.ts.map +1 -0
  8. package/lib/domain/getTokensWithFunds.js +36 -0
  9. package/lib/domain/getTokensWithFunds.js.map +1 -0
  10. package/lib/domain/getTokensWithFunds.test.d.ts +2 -0
  11. package/lib/domain/getTokensWithFunds.test.d.ts.map +1 -0
  12. package/lib/domain/getTokensWithFunds.test.js +71 -0
  13. package/lib/domain/getTokensWithFunds.test.js.map +1 -0
  14. package/lib/e2e/index.d.ts +3 -0
  15. package/lib/e2e/index.d.ts.map +1 -1
  16. package/lib/env.react.d.ts +1 -1
  17. package/lib/env.react.d.ts.map +1 -1
  18. package/lib/exchange/swap/getIncompatibleCurrencyKeys.d.ts.map +1 -1
  19. package/lib/exchange/swap/getIncompatibleCurrencyKeys.js +4 -0
  20. package/lib/exchange/swap/getIncompatibleCurrencyKeys.js.map +1 -1
  21. package/lib/families/evm/config.d.ts.map +1 -1
  22. package/lib/families/evm/config.js +65 -2
  23. package/lib/families/evm/config.js.map +1 -1
  24. package/lib/families/solana/banner.test.js +1 -0
  25. package/lib/families/solana/banner.test.js.map +1 -1
  26. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  27. package/lib/featureFlags/defaultFeatures.js +8 -0
  28. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  29. package/lib/featureFlags/useFeature.d.ts +1 -1
  30. package/lib/featureFlags/useFeature.d.ts.map +1 -1
  31. package/lib/market/hooks/useLargeMoverDataProvider.d.ts +17 -0
  32. package/lib/market/hooks/useLargeMoverDataProvider.d.ts.map +1 -0
  33. package/lib/market/hooks/useLargeMoverDataProvider.js +48 -0
  34. package/lib/market/hooks/useLargeMoverDataProvider.js.map +1 -0
  35. package/lib/wallet-api/Exchange/server.d.ts +6 -1
  36. package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
  37. package/lib/wallet-api/Exchange/server.js +11 -1
  38. package/lib/wallet-api/Exchange/server.js.map +1 -1
  39. package/lib/wallet-api/Exchange/server.test.js +2 -0
  40. package/lib/wallet-api/Exchange/server.test.js.map +1 -1
  41. package/lib/wallet-api/constants.d.ts +1 -1
  42. package/lib-es/DataModel.d.ts.map +1 -1
  43. package/lib-es/DataModel.js +8 -0
  44. package/lib-es/DataModel.js.map +1 -1
  45. package/lib-es/DataModel.test.js +46 -0
  46. package/lib-es/DataModel.test.js.map +1 -1
  47. package/lib-es/domain/getTokensWithFunds.d.ts +3 -0
  48. package/lib-es/domain/getTokensWithFunds.d.ts.map +1 -0
  49. package/lib-es/domain/getTokensWithFunds.js +32 -0
  50. package/lib-es/domain/getTokensWithFunds.js.map +1 -0
  51. package/lib-es/domain/getTokensWithFunds.test.d.ts +2 -0
  52. package/lib-es/domain/getTokensWithFunds.test.d.ts.map +1 -0
  53. package/lib-es/domain/getTokensWithFunds.test.js +66 -0
  54. package/lib-es/domain/getTokensWithFunds.test.js.map +1 -0
  55. package/lib-es/e2e/index.d.ts +3 -0
  56. package/lib-es/e2e/index.d.ts.map +1 -1
  57. package/lib-es/env.react.d.ts +1 -1
  58. package/lib-es/env.react.d.ts.map +1 -1
  59. package/lib-es/exchange/swap/getIncompatibleCurrencyKeys.d.ts.map +1 -1
  60. package/lib-es/exchange/swap/getIncompatibleCurrencyKeys.js +4 -0
  61. package/lib-es/exchange/swap/getIncompatibleCurrencyKeys.js.map +1 -1
  62. package/lib-es/families/evm/config.d.ts.map +1 -1
  63. package/lib-es/families/evm/config.js +65 -2
  64. package/lib-es/families/evm/config.js.map +1 -1
  65. package/lib-es/families/solana/banner.test.js +1 -0
  66. package/lib-es/families/solana/banner.test.js.map +1 -1
  67. package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
  68. package/lib-es/featureFlags/defaultFeatures.js +8 -0
  69. package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
  70. package/lib-es/featureFlags/useFeature.d.ts +1 -1
  71. package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
  72. package/lib-es/market/hooks/useLargeMoverDataProvider.d.ts +17 -0
  73. package/lib-es/market/hooks/useLargeMoverDataProvider.d.ts.map +1 -0
  74. package/lib-es/market/hooks/useLargeMoverDataProvider.js +44 -0
  75. package/lib-es/market/hooks/useLargeMoverDataProvider.js.map +1 -0
  76. package/lib-es/wallet-api/Exchange/server.d.ts +6 -1
  77. package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
  78. package/lib-es/wallet-api/Exchange/server.js +11 -1
  79. package/lib-es/wallet-api/Exchange/server.js.map +1 -1
  80. package/lib-es/wallet-api/Exchange/server.test.js +2 -0
  81. package/lib-es/wallet-api/Exchange/server.test.js.map +1 -1
  82. package/lib-es/wallet-api/constants.d.ts +1 -1
  83. package/package.json +65 -65
  84. package/src/DataModel.test.ts +51 -0
  85. package/src/DataModel.ts +8 -2
  86. package/src/domain/getTokensWithFunds.test.ts +94 -0
  87. package/src/domain/getTokensWithFunds.ts +36 -0
  88. package/src/exchange/swap/getIncompatibleCurrencyKeys.ts +4 -0
  89. package/src/families/aptos/__snapshots__/bridge.integration.test.ts.snap +72 -6
  90. package/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap +4351 -745
  91. package/src/families/cosmos/datasets/__snapshots__/cosmos.integration.test.ts.snap +2 -2
  92. package/src/families/evm/config.ts +65 -2
  93. package/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap +1612 -0
  94. package/src/families/solana/banner.test.ts +1 -0
  95. package/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +254 -14
  96. package/src/featureFlags/defaultFeatures.ts +8 -0
  97. package/src/market/hooks/useLargeMoverDataProvider.ts +70 -0
  98. package/src/wallet-api/Exchange/server.test.ts +2 -0
  99. package/src/wallet-api/Exchange/server.ts +15 -0
@@ -0,0 +1,94 @@
1
+ import { genAccount } from "@ledgerhq/coin-framework/lib/mocks/account";
2
+ import { getCryptoCurrencyById } from "@ledgerhq/live-common/currencies/index";
3
+ import { Account } from "@ledgerhq/types-live";
4
+ import BigNumber from "bignumber.js";
5
+ import { getTokensWithFunds } from "./getTokensWithFunds";
6
+
7
+ const ETH = getCryptoCurrencyById("ethereum");
8
+
9
+ const mockedAccounts: Account[] = [
10
+ genAccount("mocked-account-2", {
11
+ currency: ETH,
12
+ }),
13
+ ];
14
+
15
+ describe("getTokensWithFunds", () => {
16
+ it("should return empty array if no accounts", () => {
17
+ const result = getTokensWithFunds([]);
18
+ expect(result).toEqual([]);
19
+ });
20
+
21
+ it("should return array with accounts with funds", () => {
22
+ const account = mockedAccounts[0];
23
+ const result = getTokensWithFunds(mockedAccounts);
24
+
25
+ expect(account.balance).toBeTruthy();
26
+ expect(account.balance instanceof BigNumber).toBe(true);
27
+ expect(account.balance.gt(0)).toBe(true);
28
+
29
+ expect(account.subAccounts).toBeDefined();
30
+ expect(account.subAccounts?.length).toBe(2);
31
+
32
+ const [zrxAccount, repAccount] = account.subAccounts || [];
33
+
34
+ expect(zrxAccount.balance).toBeTruthy();
35
+ expect(zrxAccount.balance instanceof BigNumber).toBe(true);
36
+ expect(zrxAccount.balance.gt(0)).toBe(true);
37
+
38
+ expect(repAccount.balance).toBeTruthy();
39
+ expect(repAccount.balance instanceof BigNumber).toBe(true);
40
+ expect(repAccount.balance.gt(0)).toBe(true);
41
+
42
+ expect(result).toEqual(["ETH on Ethereum", "ZRX on Ethereum", "REP on Ethereum"]);
43
+ });
44
+
45
+ it("should return array with accounts with funds", () => {
46
+ const account = mockedAccounts[0];
47
+
48
+ expect(account.balance).toBeTruthy();
49
+ expect(account.balance instanceof BigNumber).toBe(true);
50
+ expect(account.balance.gt(0)).toBe(true);
51
+
52
+ expect(account.subAccounts).toBeDefined();
53
+ expect(account.subAccounts?.length).toBe(2);
54
+
55
+ const [zrxAccount, repAccount] = account.subAccounts || [];
56
+
57
+ const emptyRepAccount = { ...repAccount, balance: new BigNumber(0) };
58
+
59
+ expect(zrxAccount.balance).toBeTruthy();
60
+ expect(zrxAccount.balance instanceof BigNumber).toBe(true);
61
+ expect(zrxAccount.balance.gt(0)).toBe(true);
62
+
63
+ expect(emptyRepAccount.balance).toBeTruthy();
64
+ expect(emptyRepAccount.balance instanceof BigNumber).toBe(true);
65
+ expect(emptyRepAccount.balance.gt(0)).toBe(false);
66
+
67
+ const accounts = { ...account, subAccounts: [zrxAccount, emptyRepAccount] };
68
+
69
+ const result = getTokensWithFunds([accounts]);
70
+
71
+ expect(result).toEqual(["ETH on Ethereum", "ZRX on Ethereum"]);
72
+ });
73
+
74
+ it("should return array with accounts with funds without duplication", () => {
75
+ const account = mockedAccounts[0];
76
+
77
+ expect(account.balance).toBeTruthy();
78
+ expect(account.balance instanceof BigNumber).toBe(true);
79
+ expect(account.balance.gt(0)).toBe(true);
80
+
81
+ expect(account.subAccounts).toBeDefined();
82
+ expect(account.subAccounts?.length).toBe(2);
83
+
84
+ const [zrxAccount, repAccount] = account.subAccounts || [];
85
+
86
+ const accounts = { ...account, subAccounts: [zrxAccount, repAccount, repAccount] };
87
+
88
+ expect(accounts.subAccounts.length).toBe(3);
89
+
90
+ const result = getTokensWithFunds([accounts]);
91
+
92
+ expect(result).toEqual(["ETH on Ethereum", "ZRX on Ethereum", "REP on Ethereum"]);
93
+ });
94
+ });
@@ -0,0 +1,36 @@
1
+ import { getParentAccount } from "@ledgerhq/coin-framework/account/helpers";
2
+ import { Account } from "@ledgerhq/types-live";
3
+
4
+ export const getTokensWithFunds = (accounts: Account[]): string[] => {
5
+ if (!accounts?.length) return [];
6
+
7
+ const tokensMap = new Map<string, { ticker: string; networkName: string }>();
8
+
9
+ for (const account of accounts) {
10
+ const { balance, currency } = account || {};
11
+ if (!balance?.gt(0) || !currency) continue;
12
+
13
+ const parentAccount = getParentAccount(account, accounts);
14
+ const networkName = parentAccount?.currency?.name;
15
+ if (!networkName) continue;
16
+
17
+ const mainKey = `${currency.ticker}:${networkName}`;
18
+ tokensMap.set(mainKey, {
19
+ ticker: currency.ticker,
20
+ networkName,
21
+ });
22
+
23
+ account.subAccounts?.forEach(subAccount => {
24
+ const { balance, token } = subAccount || {};
25
+ if (!balance?.gt(0) || !token) return;
26
+
27
+ const subKey = `${token.ticker}:${networkName}`;
28
+ tokensMap.set(subKey, {
29
+ ticker: token.ticker,
30
+ networkName,
31
+ });
32
+ });
33
+ }
34
+
35
+ return Array.from(tokensMap.values(), ({ ticker, networkName }) => `${ticker} on ${networkName}`);
36
+ };
@@ -20,6 +20,10 @@ const INCOMPATIBLE_NANO_S_TOKENS_KEYS: Keys = {
20
20
  title: "swap.incompatibility.spl_tokens_title",
21
21
  description: "swap.incompatibility.spl_tokens_description",
22
22
  },
23
+ ton: {
24
+ title: "swap.incompatibility.ton_tokens_title",
25
+ description: "swap.incompatibility.ton_tokens_description",
26
+ },
23
27
  };
24
28
 
25
29
  const INCOMPATIBLE_NANO_S_CURRENCY_KEYS: Keys = {
@@ -3,34 +3,36 @@
3
3
  exports[`aptos currency bridge scanAccounts aptos seed 1 1`] = `
4
4
  [
5
5
  {
6
- "balance": "30100",
6
+ "balance": "19949100",
7
7
  "currencyId": "aptos",
8
8
  "derivationMode": "aptos",
9
9
  "freshAddress": "0x445fa0013887abd1a0c14acdec6e48090e0ad3fed3e08202aac15ca14f3be26b",
10
10
  "freshAddressPath": "44'/637'/0'/0'/0'",
11
11
  "id": "js:2:aptos:d1a8c6a1cdd52dd40c7ea61ee4571fb51fcae440a594c1eca18636928f1d3956:aptos",
12
12
  "index": 0,
13
- "operationsCount": 5,
13
+ "operationsCount": 7,
14
14
  "pendingOperations": [],
15
15
  "seedIdentifier": "d6816f4f22f867b56cf9304b776f452a16d107835d73ee8a33c4ced210300583",
16
- "spendableBalance": "30100",
16
+ "spendableBalance": "19949100",
17
+ "subAccounts": [],
17
18
  "swapHistory": [],
18
19
  "syncHash": undefined,
19
20
  "used": true,
20
21
  "xpub": "d1a8c6a1cdd52dd40c7ea61ee4571fb51fcae440a594c1eca18636928f1d3956",
21
22
  },
22
23
  {
23
- "balance": "20000",
24
+ "balance": "20020000",
24
25
  "currencyId": "aptos",
25
26
  "derivationMode": "aptos",
26
27
  "freshAddress": "0xd20fa44192f94ba086ab16bfdf57e43ff118ada69b4c66fa9b9a9223cbc068c1",
27
28
  "freshAddressPath": "44'/637'/1'/0'/0'",
28
29
  "id": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos",
29
30
  "index": 1,
30
- "operationsCount": 1,
31
+ "operationsCount": 2,
31
32
  "pendingOperations": [],
32
33
  "seedIdentifier": "d6816f4f22f867b56cf9304b776f452a16d107835d73ee8a33c4ced210300583",
33
- "spendableBalance": "20000",
34
+ "spendableBalance": "20020000",
35
+ "subAccounts": [],
34
36
  "swapHistory": [],
35
37
  "syncHash": undefined,
36
38
  "used": true,
@@ -48,6 +50,7 @@ exports[`aptos currency bridge scanAccounts aptos seed 1 1`] = `
48
50
  "pendingOperations": [],
49
51
  "seedIdentifier": "d6816f4f22f867b56cf9304b776f452a16d107835d73ee8a33c4ced210300583",
50
52
  "spendableBalance": "0",
53
+ "subAccounts": [],
51
54
  "swapHistory": [],
52
55
  "syncHash": undefined,
53
56
  "used": false,
@@ -122,6 +125,27 @@ exports[`aptos currency bridge scanAccounts aptos seed 1 2`] = `
122
125
  "type": "IN",
123
126
  "value": "20000",
124
127
  },
128
+ {
129
+ "accountId": "js:2:aptos:d1a8c6a1cdd52dd40c7ea61ee4571fb51fcae440a594c1eca18636928f1d3956:aptos",
130
+ "blockHash": "0xf9429d651797c3c3254773407bccf9c0e4c5009104d360b97e08286429b7c79a",
131
+ "blockHeight": 302070324,
132
+ "extra": {
133
+ "version": "2463183347",
134
+ },
135
+ "fee": "30100",
136
+ "hasFailed": true,
137
+ "hash": "0x93b7213cb4facc242726d80cf7a14ec1c9c10daa7d2dccc4ad47958c2f88ee0e",
138
+ "id": "js:2:aptos:d1a8c6a1cdd52dd40c7ea61ee4571fb51fcae440a594c1eca18636928f1d3956:aptos-0x93b7213cb4facc242726d80cf7a14ec1c9c10daa7d2dccc4ad47958c2f88ee0e-OUT",
139
+ "recipients": [
140
+ "0xd20fa44192f94ba086ab16bfdf57e43ff118ada69b4c66fa9b9a9223cbc068c1",
141
+ ],
142
+ "senders": [
143
+ "0x445fa0013887abd1a0c14acdec6e48090e0ad3fed3e08202aac15ca14f3be26b",
144
+ ],
145
+ "transactionSequenceNumber": 1,
146
+ "type": "OUT",
147
+ "value": "30100",
148
+ },
125
149
  {
126
150
  "accountId": "js:2:aptos:d1a8c6a1cdd52dd40c7ea61ee4571fb51fcae440a594c1eca18636928f1d3956:aptos",
127
151
  "blockHash": "0x1bbe17059abba7dc500aca2eb174c217e71f3dcd7486cd4b27dc6136cce8a60a",
@@ -143,6 +167,27 @@ exports[`aptos currency bridge scanAccounts aptos seed 1 2`] = `
143
167
  "type": "IN",
144
168
  "value": "10000",
145
169
  },
170
+ {
171
+ "accountId": "js:2:aptos:d1a8c6a1cdd52dd40c7ea61ee4571fb51fcae440a594c1eca18636928f1d3956:aptos",
172
+ "blockHash": "0xd9ffa9abc5a6aae3f342e353a55ab115d50d582a400e909f37cd48063487de5f",
173
+ "blockHeight": 302074007,
174
+ "extra": {
175
+ "version": "2463213242",
176
+ },
177
+ "fee": "1100",
178
+ "hasFailed": false,
179
+ "hash": "0xf8c8a486c8e0c0c530f92ea5b26220829e8f8e24f8b0d9f35b57dbd804d36daf",
180
+ "id": "js:2:aptos:d1a8c6a1cdd52dd40c7ea61ee4571fb51fcae440a594c1eca18636928f1d3956:aptos-0xf8c8a486c8e0c0c530f92ea5b26220829e8f8e24f8b0d9f35b57dbd804d36daf-IN",
181
+ "recipients": [
182
+ "0x445fa0013887abd1a0c14acdec6e48090e0ad3fed3e08202aac15ca14f3be26b",
183
+ ],
184
+ "senders": [
185
+ "0xa0d8abc262e3321f87d745bd5d687e8f3fb14c87d48f840b6b56867df0026ec8",
186
+ ],
187
+ "transactionSequenceNumber": 86,
188
+ "type": "IN",
189
+ "value": "20000000",
190
+ },
146
191
  {
147
192
  "accountId": "js:2:aptos:d1a8c6a1cdd52dd40c7ea61ee4571fb51fcae440a594c1eca18636928f1d3956:aptos",
148
193
  "blockHash": "0xf37ce698cf2e6d9e4a0048cd6d09fb3f19f417ab8251a3cc1f19b8d0e503538f",
@@ -166,6 +211,27 @@ exports[`aptos currency bridge scanAccounts aptos seed 1 2`] = `
166
211
  },
167
212
  ],
168
213
  [
214
+ {
215
+ "accountId": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos",
216
+ "blockHash": "0x27db591a136924b48d10e6e152a3e856a5c38b332654767da252851adbb454b2",
217
+ "blockHeight": 302074528,
218
+ "extra": {
219
+ "version": "2463216946",
220
+ },
221
+ "fee": "1100",
222
+ "hasFailed": false,
223
+ "hash": "0x40d445cdfc3ab007a9a7c809a5f12d9488c6137ba691a3ab5ade1ff619cab61f",
224
+ "id": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos-0x40d445cdfc3ab007a9a7c809a5f12d9488c6137ba691a3ab5ade1ff619cab61f-IN",
225
+ "recipients": [
226
+ "0xd20fa44192f94ba086ab16bfdf57e43ff118ada69b4c66fa9b9a9223cbc068c1",
227
+ ],
228
+ "senders": [
229
+ "0xa0d8abc262e3321f87d745bd5d687e8f3fb14c87d48f840b6b56867df0026ec8",
230
+ ],
231
+ "transactionSequenceNumber": 87,
232
+ "type": "IN",
233
+ "value": "20000000",
234
+ },
169
235
  {
170
236
  "accountId": "js:2:aptos:6a7712fdac0cb4ed27076c707e7798be52cf6c93a2d43d5cf9b874d0a45a111e:aptos",
171
237
  "blockHash": "0xf37ce698cf2e6d9e4a0048cd6d09fb3f19f417ab8251a3cc1f19b8d0e503538f",