@ledgerhq/live-common 34.42.1 → 34.43.0-nightly.1

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 (229) hide show
  1. package/lib/__tests__/migration/account-migration.js +3 -0
  2. package/lib/__tests__/migration/account-migration.js.map +1 -1
  3. package/lib/__tests__/test-helpers/environment.js +3 -0
  4. package/lib/__tests__/test-helpers/environment.js.map +1 -1
  5. package/lib/bridge/crypto-assets/index.d.ts +4 -0
  6. package/lib/bridge/crypto-assets/index.d.ts.map +1 -0
  7. package/lib/bridge/crypto-assets/index.js +52 -0
  8. package/lib/bridge/crypto-assets/index.js.map +1 -0
  9. package/lib/bridge/crypto-assets/index.test.d.ts +2 -0
  10. package/lib/bridge/crypto-assets/index.test.d.ts.map +1 -0
  11. package/lib/bridge/crypto-assets/index.test.js +85 -0
  12. package/lib/bridge/crypto-assets/index.test.js.map +1 -0
  13. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +3 -1
  14. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
  15. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js +6 -0
  16. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
  17. package/lib/bridge/impl.d.ts +2 -0
  18. package/lib/bridge/impl.d.ts.map +1 -1
  19. package/lib/bridge/impl.js +8 -1
  20. package/lib/bridge/impl.js.map +1 -1
  21. package/lib/bridge/useBridgeTransaction.test.js +1 -1
  22. package/lib/bridge/useBridgeTransaction.test.js.map +1 -1
  23. package/lib/e2e/families/osmosis.d.ts +3 -0
  24. package/lib/e2e/families/osmosis.d.ts.map +1 -0
  25. package/lib/e2e/families/osmosis.js +19 -0
  26. package/lib/e2e/families/osmosis.js.map +1 -0
  27. package/lib/e2e/index.d.ts +9 -0
  28. package/lib/e2e/index.d.ts.map +1 -1
  29. package/lib/e2e/speculos.d.ts.map +1 -1
  30. package/lib/e2e/speculos.js +50 -17
  31. package/lib/e2e/speculos.js.map +1 -1
  32. package/lib/e2e/speculosCI.d.ts.map +1 -1
  33. package/lib/e2e/speculosCI.js +22 -4
  34. package/lib/e2e/speculosCI.js.map +1 -1
  35. package/lib/env.react.d.ts +1 -1
  36. package/lib/env.react.d.ts.map +1 -1
  37. package/lib/exchange/error.d.ts +2 -1
  38. package/lib/exchange/error.d.ts.map +1 -1
  39. package/lib/exchange/error.js +5 -3
  40. package/lib/exchange/error.js.map +1 -1
  41. package/lib/exchange/swap/completeExchange.js +2 -2
  42. package/lib/exchange/swap/completeExchange.js.map +1 -1
  43. package/lib/families/evm/config.d.ts.map +1 -1
  44. package/lib/families/evm/config.js +51 -0
  45. package/lib/families/evm/config.js.map +1 -1
  46. package/lib/families/evm/walletApiAdapter.js +1 -1
  47. package/lib/families/solana/bridge/mock-data.d.ts.map +1 -1
  48. package/lib/families/solana/bridge/mock-data.js +46 -316
  49. package/lib/families/solana/bridge/mock-data.js.map +1 -1
  50. package/lib/families/solana/bridge/mock.js +2 -2
  51. package/lib/families/solana/bridge/mock.js.map +1 -1
  52. package/lib/featureFlags/defaultFeatures.d.ts +3 -0
  53. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  54. package/lib/featureFlags/defaultFeatures.js +4 -0
  55. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  56. package/lib/featureFlags/useFeature.d.ts +1 -1
  57. package/lib/featureFlags/useFeature.d.ts.map +1 -1
  58. package/lib/modularDrawer/__mocks__/accounts.mock.d.ts +18 -0
  59. package/lib/modularDrawer/__mocks__/accounts.mock.d.ts.map +1 -0
  60. package/lib/modularDrawer/__mocks__/accounts.mock.js +48 -0
  61. package/lib/modularDrawer/__mocks__/accounts.mock.js.map +1 -0
  62. package/lib/modularDrawer/__mocks__/currencies.mock.d.ts +17 -0
  63. package/lib/modularDrawer/__mocks__/currencies.mock.d.ts.map +1 -0
  64. package/lib/modularDrawer/__mocks__/currencies.mock.js +60 -0
  65. package/lib/modularDrawer/__mocks__/currencies.mock.js.map +1 -0
  66. package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.d.ts +22 -0
  67. package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.d.ts.map +1 -0
  68. package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js +41 -0
  69. package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js.map +1 -0
  70. package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts +2 -0
  71. package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts.map +1 -0
  72. package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js +28 -0
  73. package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js.map +1 -0
  74. package/lib/modularDrawer/utils/haveOneCommonProvider.d.ts +11 -0
  75. package/lib/modularDrawer/utils/haveOneCommonProvider.d.ts.map +1 -0
  76. package/lib/modularDrawer/utils/haveOneCommonProvider.js +29 -0
  77. package/lib/modularDrawer/utils/haveOneCommonProvider.js.map +1 -0
  78. package/lib/modularDrawer/utils/index.d.ts +2 -1
  79. package/lib/modularDrawer/utils/index.d.ts.map +1 -1
  80. package/lib/modularDrawer/utils/index.js +3 -1
  81. package/lib/modularDrawer/utils/index.js.map +1 -1
  82. package/lib/utils/__tests__/composeHooks.test.d.ts +2 -0
  83. package/lib/utils/__tests__/composeHooks.test.d.ts.map +1 -0
  84. package/lib/utils/__tests__/composeHooks.test.js +35 -0
  85. package/lib/utils/__tests__/composeHooks.test.js.map +1 -0
  86. package/lib/utils/__tests__/getAccountTuplesForCurrency.test.d.ts +2 -0
  87. package/lib/utils/__tests__/getAccountTuplesForCurrency.test.d.ts.map +1 -0
  88. package/lib/utils/__tests__/getAccountTuplesForCurrency.test.js +104 -0
  89. package/lib/utils/__tests__/getAccountTuplesForCurrency.test.js.map +1 -0
  90. package/lib/utils/composeHooks.d.ts +11 -0
  91. package/lib/utils/composeHooks.d.ts.map +1 -0
  92. package/lib/utils/composeHooks.js +25 -0
  93. package/lib/utils/composeHooks.js.map +1 -0
  94. package/lib/utils/getAccountTuplesForCurrency.d.ts +8 -0
  95. package/lib/utils/getAccountTuplesForCurrency.d.ts.map +1 -0
  96. package/lib/utils/getAccountTuplesForCurrency.js +19 -0
  97. package/lib/utils/getAccountTuplesForCurrency.js.map +1 -0
  98. package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
  99. package/lib/wallet-api/Exchange/server.js +6 -6
  100. package/lib/wallet-api/Exchange/server.js.map +1 -1
  101. package/lib-es/__tests__/migration/account-migration.js +3 -0
  102. package/lib-es/__tests__/migration/account-migration.js.map +1 -1
  103. package/lib-es/__tests__/test-helpers/environment.js +3 -0
  104. package/lib-es/__tests__/test-helpers/environment.js.map +1 -1
  105. package/lib-es/bridge/crypto-assets/index.d.ts +4 -0
  106. package/lib-es/bridge/crypto-assets/index.d.ts.map +1 -0
  107. package/lib-es/bridge/crypto-assets/index.js +24 -0
  108. package/lib-es/bridge/crypto-assets/index.js.map +1 -0
  109. package/lib-es/bridge/crypto-assets/index.test.d.ts +2 -0
  110. package/lib-es/bridge/crypto-assets/index.test.d.ts.map +1 -0
  111. package/lib-es/bridge/crypto-assets/index.test.js +60 -0
  112. package/lib-es/bridge/crypto-assets/index.test.js.map +1 -0
  113. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +3 -1
  114. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
  115. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js +6 -0
  116. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
  117. package/lib-es/bridge/impl.d.ts +2 -0
  118. package/lib-es/bridge/impl.d.ts.map +1 -1
  119. package/lib-es/bridge/impl.js +6 -0
  120. package/lib-es/bridge/impl.js.map +1 -1
  121. package/lib-es/bridge/useBridgeTransaction.test.js +1 -1
  122. package/lib-es/bridge/useBridgeTransaction.test.js.map +1 -1
  123. package/lib-es/e2e/families/osmosis.d.ts +3 -0
  124. package/lib-es/e2e/families/osmosis.d.ts.map +1 -0
  125. package/lib-es/e2e/families/osmosis.js +12 -0
  126. package/lib-es/e2e/families/osmosis.js.map +1 -0
  127. package/lib-es/e2e/index.d.ts +9 -0
  128. package/lib-es/e2e/index.d.ts.map +1 -1
  129. package/lib-es/e2e/speculos.d.ts.map +1 -1
  130. package/lib-es/e2e/speculos.js +50 -17
  131. package/lib-es/e2e/speculos.js.map +1 -1
  132. package/lib-es/e2e/speculosCI.d.ts.map +1 -1
  133. package/lib-es/e2e/speculosCI.js +22 -4
  134. package/lib-es/e2e/speculosCI.js.map +1 -1
  135. package/lib-es/env.react.d.ts +1 -1
  136. package/lib-es/env.react.d.ts.map +1 -1
  137. package/lib-es/exchange/error.d.ts +2 -1
  138. package/lib-es/exchange/error.d.ts.map +1 -1
  139. package/lib-es/exchange/error.js +5 -3
  140. package/lib-es/exchange/error.js.map +1 -1
  141. package/lib-es/exchange/swap/completeExchange.js +2 -2
  142. package/lib-es/exchange/swap/completeExchange.js.map +1 -1
  143. package/lib-es/families/evm/config.d.ts.map +1 -1
  144. package/lib-es/families/evm/config.js +51 -0
  145. package/lib-es/families/evm/config.js.map +1 -1
  146. package/lib-es/families/evm/walletApiAdapter.js +1 -1
  147. package/lib-es/families/solana/bridge/mock-data.d.ts.map +1 -1
  148. package/lib-es/families/solana/bridge/mock-data.js +46 -316
  149. package/lib-es/families/solana/bridge/mock-data.js.map +1 -1
  150. package/lib-es/families/solana/bridge/mock.js +3 -3
  151. package/lib-es/families/solana/bridge/mock.js.map +1 -1
  152. package/lib-es/featureFlags/defaultFeatures.d.ts +3 -0
  153. package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
  154. package/lib-es/featureFlags/defaultFeatures.js +4 -0
  155. package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
  156. package/lib-es/featureFlags/useFeature.d.ts +1 -1
  157. package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
  158. package/lib-es/modularDrawer/__mocks__/accounts.mock.d.ts +18 -0
  159. package/lib-es/modularDrawer/__mocks__/accounts.mock.d.ts.map +1 -0
  160. package/lib-es/modularDrawer/__mocks__/accounts.mock.js +42 -0
  161. package/lib-es/modularDrawer/__mocks__/accounts.mock.js.map +1 -0
  162. package/lib-es/modularDrawer/__mocks__/currencies.mock.d.ts +17 -0
  163. package/lib-es/modularDrawer/__mocks__/currencies.mock.d.ts.map +1 -0
  164. package/lib-es/modularDrawer/__mocks__/currencies.mock.js +55 -0
  165. package/lib-es/modularDrawer/__mocks__/currencies.mock.js.map +1 -0
  166. package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.d.ts +22 -0
  167. package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.d.ts.map +1 -0
  168. package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js +38 -0
  169. package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js.map +1 -0
  170. package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts +2 -0
  171. package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.d.ts.map +1 -0
  172. package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js +26 -0
  173. package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js.map +1 -0
  174. package/lib-es/modularDrawer/utils/haveOneCommonProvider.d.ts +11 -0
  175. package/lib-es/modularDrawer/utils/haveOneCommonProvider.d.ts.map +1 -0
  176. package/lib-es/modularDrawer/utils/haveOneCommonProvider.js +25 -0
  177. package/lib-es/modularDrawer/utils/haveOneCommonProvider.js.map +1 -0
  178. package/lib-es/modularDrawer/utils/index.d.ts +2 -1
  179. package/lib-es/modularDrawer/utils/index.d.ts.map +1 -1
  180. package/lib-es/modularDrawer/utils/index.js +2 -1
  181. package/lib-es/modularDrawer/utils/index.js.map +1 -1
  182. package/lib-es/utils/__tests__/composeHooks.test.d.ts +2 -0
  183. package/lib-es/utils/__tests__/composeHooks.test.d.ts.map +1 -0
  184. package/lib-es/utils/__tests__/composeHooks.test.js +33 -0
  185. package/lib-es/utils/__tests__/composeHooks.test.js.map +1 -0
  186. package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.d.ts +2 -0
  187. package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.d.ts.map +1 -0
  188. package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.js +102 -0
  189. package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.js.map +1 -0
  190. package/lib-es/utils/composeHooks.d.ts +11 -0
  191. package/lib-es/utils/composeHooks.d.ts.map +1 -0
  192. package/lib-es/utils/composeHooks.js +21 -0
  193. package/lib-es/utils/composeHooks.js.map +1 -0
  194. package/lib-es/utils/getAccountTuplesForCurrency.d.ts +8 -0
  195. package/lib-es/utils/getAccountTuplesForCurrency.d.ts.map +1 -0
  196. package/lib-es/utils/getAccountTuplesForCurrency.js +15 -0
  197. package/lib-es/utils/getAccountTuplesForCurrency.js.map +1 -0
  198. package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
  199. package/lib-es/wallet-api/Exchange/server.js +6 -6
  200. package/lib-es/wallet-api/Exchange/server.js.map +1 -1
  201. package/package.json +50 -50
  202. package/src/__tests__/migration/account-migration.ts +3 -0
  203. package/src/__tests__/test-helpers/environment.ts +3 -0
  204. package/src/bridge/crypto-assets/index.test.ts +71 -0
  205. package/src/bridge/crypto-assets/index.ts +30 -0
  206. package/src/bridge/generic-alpaca/alpaca/network/network-alpaca.ts +8 -1
  207. package/src/bridge/impl.ts +8 -0
  208. package/src/bridge/useBridgeTransaction.test.ts +1 -1
  209. package/src/e2e/families/osmosis.ts +13 -0
  210. package/src/e2e/speculos.ts +82 -23
  211. package/src/e2e/speculosCI.ts +32 -10
  212. package/src/exchange/error.ts +5 -3
  213. package/src/exchange/swap/completeExchange.ts +2 -2
  214. package/src/families/evm/config.ts +51 -0
  215. package/src/families/evm/walletApiAdapter.ts +1 -1
  216. package/src/families/solana/bridge/mock-data.ts +52 -316
  217. package/src/families/solana/bridge/mock.ts +3 -3
  218. package/src/featureFlags/defaultFeatures.ts +4 -0
  219. package/src/modularDrawer/__mocks__/accounts.mock.ts +43 -0
  220. package/src/modularDrawer/__mocks__/currencies.mock.ts +62 -0
  221. package/src/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.ts +49 -0
  222. package/src/modularDrawer/utils/__tests__/haveOneCommonProvider.test.ts +34 -0
  223. package/src/modularDrawer/utils/haveOneCommonProvider.ts +31 -0
  224. package/src/modularDrawer/utils/index.ts +2 -1
  225. package/src/utils/__tests__/composeHooks.test.ts +46 -0
  226. package/src/utils/__tests__/getAccountTuplesForCurrency.test.ts +138 -0
  227. package/src/utils/composeHooks.ts +26 -0
  228. package/src/utils/getAccountTuplesForCurrency.ts +34 -0
  229. package/src/wallet-api/Exchange/server.ts +7 -6
@@ -0,0 +1,46 @@
1
+ import { composeHooks } from "../composeHooks";
2
+
3
+ describe("composeHooks", () => {
4
+ it("should compose hooks and merge their results", () => {
5
+ const hook1 = (items: Array<{ id: number }>) =>
6
+ items.map(item => ({ id: item.id, extra: item.id * 2 }));
7
+ const hook2 = (items: Array<{ id: number; extra: number }>) =>
8
+ items.map(item => ({ ...item, final: item.extra + 1 }));
9
+
10
+ const composed = composeHooks(hook1, hook2);
11
+
12
+ const input: Array<{ id: number }> = [{ id: 1 }, { id: 2 }];
13
+ const processedInput = input.map(item => ({ id: item.id, extra: item.id * 2 }));
14
+ const result = composed(processedInput);
15
+
16
+ expect(result).toEqual([
17
+ { id: 1, extra: 2, final: 3 },
18
+ { id: 2, extra: 4, final: 5 },
19
+ ]);
20
+ });
21
+
22
+ it("should handle hooks that return undefined", () => {
23
+ const hook1 = (items: Array<{ id: number }>) =>
24
+ items.map(item => ({ id: item.id, extra: item.id * 2 }));
25
+ const hook2 = () => undefined;
26
+
27
+ const composed = composeHooks(hook1, hook2);
28
+
29
+ const input = [{ id: 1 }, { id: 2 }];
30
+ const result = composed(input);
31
+
32
+ expect(result).toEqual([
33
+ { id: 1, extra: 2 },
34
+ { id: 2, extra: 4 },
35
+ ]);
36
+ });
37
+
38
+ it("should return the original items if no hooks are provided", () => {
39
+ const composed = composeHooks();
40
+
41
+ const input = [{ id: 1 }, { id: 2 }];
42
+ const result = composed(input);
43
+
44
+ expect(result).toEqual(input);
45
+ });
46
+ });
@@ -0,0 +1,138 @@
1
+ import { getCryptoCurrencyById, getTokenById } from "@ledgerhq/cryptoassets";
2
+ import { genAccount } from "@ledgerhq/live-common/mock/account";
3
+ import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
4
+ import type { Account, TokenAccount } from "@ledgerhq/types-live";
5
+ import { getAccountTuplesForCurrency } from "../getAccountTuplesForCurrency";
6
+
7
+ function* accountGenerator(currency: CryptoCurrency): Generator<Account> {
8
+ let id = 0;
9
+ while (true) {
10
+ id += 1;
11
+ yield genAccount(`mocked-account-${id}`, { currency, operationsSize: 0 });
12
+ }
13
+ }
14
+ const getAccountCreator = (currencyId: string) => {
15
+ const generator = accountGenerator(getCryptoCurrencyById(currencyId));
16
+ return () => generator.next().value;
17
+ };
18
+
19
+ describe("getAccountTuplesForCurrency", () => {
20
+ const getEthAccount = getAccountCreator("ethereum");
21
+ const getBtcAccount = getAccountCreator("bitcoin");
22
+ const getPolkadotAccount = getAccountCreator("polkadot");
23
+ const getCosmosAccount = getAccountCreator("cosmos");
24
+
25
+ describe("CryptoCurrency", () => {
26
+ test("returns all accounts associated to the CryptoCurrency", () => {
27
+ const ethCurrency = getCryptoCurrencyById("ethereum");
28
+ const ethAccounts = [getEthAccount(), getEthAccount()];
29
+ const allAccounts: Account[] = [
30
+ getCosmosAccount(),
31
+ ...ethAccounts,
32
+ getBtcAccount(),
33
+ getPolkadotAccount(),
34
+ ];
35
+
36
+ const results = getAccountTuplesForCurrency(ethCurrency, allAccounts);
37
+
38
+ expect(results).toHaveLength(2);
39
+ results.forEach((result, index) => {
40
+ expect(result.account).toEqual(ethAccounts[index]);
41
+ expect(result.subAccount).toBeNull();
42
+ });
43
+ });
44
+
45
+ test("returns an empty array if the CryptoCurrency passed has no associated account", () => {
46
+ const ethCurrency = getCryptoCurrencyById("ethereum");
47
+ const allAccounts: Account[] = [getCosmosAccount(), getBtcAccount(), getPolkadotAccount()];
48
+
49
+ const results = getAccountTuplesForCurrency(ethCurrency, allAccounts);
50
+
51
+ expect(results).toHaveLength(0);
52
+ });
53
+
54
+ test("filters based on the accountId map", () => {
55
+ const ethCurrency = getCryptoCurrencyById("ethereum");
56
+ const ethAccounts = [getEthAccount(), getEthAccount(), getEthAccount(), getEthAccount()];
57
+
58
+ const results = getAccountTuplesForCurrency(
59
+ ethCurrency,
60
+ ethAccounts,
61
+ new Map([[ethAccounts[0].id, true]]),
62
+ );
63
+
64
+ expect(results).toHaveLength(1);
65
+ });
66
+ });
67
+
68
+ describe("TokenCurrency", () => {
69
+ const aaveToken = getTokenById("ethereum/erc20/aave");
70
+
71
+ test("returns correct parent accounts including a new subAccount when a TokenCurrency is provided", () => {
72
+ const ethAccounts = [
73
+ { ...getEthAccount(), subAccounts: [] },
74
+ { ...getEthAccount(), subAccounts: [] },
75
+ ];
76
+ const allAccounts: Account[] = [
77
+ getCosmosAccount(),
78
+ ...ethAccounts,
79
+ getBtcAccount(),
80
+ getPolkadotAccount(),
81
+ ];
82
+
83
+ const results = getAccountTuplesForCurrency(aaveToken, allAccounts);
84
+
85
+ expect(results).toHaveLength(ethAccounts.length);
86
+ results.forEach((result, index) => {
87
+ expect(result.account).toEqual(ethAccounts[index]);
88
+ expect((result.subAccount as TokenAccount & { token: TokenCurrency }).token).toEqual(
89
+ aaveToken,
90
+ );
91
+ });
92
+ });
93
+
94
+ test("returns correct parent accounts including already existing subAccounts when a TokenCurrency is provided", () => {
95
+ const ethAccounts = [{ ...getEthAccount(), subAccounts: [aaveToken] }];
96
+ const allAccounts: Account[] = [
97
+ getCosmosAccount(),
98
+ ...ethAccounts,
99
+ getBtcAccount(),
100
+ getPolkadotAccount(),
101
+ ];
102
+
103
+ const results = getAccountTuplesForCurrency(aaveToken, allAccounts);
104
+
105
+ expect(results).toHaveLength(ethAccounts.length);
106
+ results.forEach((result, index) => {
107
+ expect(result.account).toEqual(ethAccounts[index]);
108
+ expect((result.subAccount as TokenAccount & { token: TokenCurrency }).token).toEqual(
109
+ aaveToken,
110
+ );
111
+ });
112
+ });
113
+
114
+ test("returns an empty array when a TokenCurrency is provided but the accounts list is empty", () => {
115
+ const allAccounts: Account[] = [];
116
+
117
+ const results = getAccountTuplesForCurrency(aaveToken, allAccounts);
118
+ expect(results).toHaveLength(0);
119
+ });
120
+
121
+ test("does not filter based on the accountId map", () => {
122
+ const aaveAccounts = [
123
+ { ...getEthAccount(), subAccounts: [aaveToken] },
124
+ { ...getEthAccount(), subAccounts: [aaveToken] },
125
+ { ...getEthAccount(), subAccounts: [aaveToken] },
126
+ { ...getEthAccount(), subAccounts: [aaveToken] },
127
+ ];
128
+
129
+ const results = getAccountTuplesForCurrency(
130
+ aaveToken,
131
+ aaveAccounts,
132
+ new Map([[aaveAccounts[0].id, true]]),
133
+ );
134
+
135
+ expect(results).toHaveLength(4);
136
+ });
137
+ });
138
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ *
3
+ * @param hooks - An array of functions that take an array of items of type T and return an array of items of type U or undefined.
4
+ * @template T - The type of the items in the input array.
5
+ * @template U - The type of the items in the output array.
6
+ * @description This function composes multiple hooks into a single hook that processes an array of items of type T and returns an array of items of type T & U.
7
+ * @returns A function that takes an array of items of type T and returns an array of items of type T & U.
8
+ *
9
+ */
10
+
11
+ export function composeHooks<T, U>(
12
+ ...hooks: Array<(items: T[]) => U[] | undefined>
13
+ ): (items: T[]) => (T & U)[] {
14
+ return (items: T[]): (T & U)[] => {
15
+ return hooks.reduce<(T & U)[]>(
16
+ (acc, hook) => {
17
+ const result = hook?.(acc as T[]) ?? [];
18
+ return acc.map((item, i) => ({
19
+ ...item,
20
+ ...result[i],
21
+ }));
22
+ },
23
+ items as (T & U)[],
24
+ );
25
+ };
26
+ }
@@ -0,0 +1,34 @@
1
+ import type { Account, TokenAccount } from "@ledgerhq/types-live";
2
+ import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import { makeEmptyTokenAccount } from "@ledgerhq/coin-framework/account/helpers";
4
+
5
+ export type AccountTuple = {
6
+ account: Account;
7
+ subAccount: TokenAccount | null;
8
+ };
9
+
10
+ export function getAccountTuplesForCurrency(
11
+ currency: CryptoCurrency | TokenCurrency,
12
+ allAccounts: Account[],
13
+ accountIds?: Map<string, boolean>,
14
+ ): AccountTuple[] {
15
+ const isToken = currency.type === "TokenCurrency";
16
+ const targetCurrencyId = isToken ? currency.parentCurrency.id : currency.id;
17
+
18
+ return allAccounts
19
+ .filter(
20
+ account =>
21
+ account.currency.id === targetCurrencyId &&
22
+ (isToken ? true : accountIds ? accountIds.has(account.id) : true),
23
+ )
24
+ .map(account => {
25
+ const subAccount = isToken
26
+ ? account.subAccounts?.find(
27
+ (subAcc): subAcc is TokenAccount =>
28
+ subAcc.type === "TokenAccount" && subAcc.token.id === currency.id,
29
+ ) || makeEmptyTokenAccount(account, currency)
30
+ : null;
31
+
32
+ return { account, subAccount };
33
+ });
34
+ }
@@ -51,6 +51,7 @@ import { getSwapStepFromError } from "../../exchange/error";
51
51
  import { postSwapCancelled } from "../../exchange/swap";
52
52
  import { DeviceModelId } from "@ledgerhq/types-devices";
53
53
  import { setBroadcastTransaction } from "../../exchange/swap/setBroadcastTransaction";
54
+ import { FAMILIES_MAPPING_LL_TO_WAPI } from "../constants";
54
55
 
55
56
  export { ExchangeType };
56
57
 
@@ -485,7 +486,9 @@ export const handlers = ({
485
486
  });
486
487
 
487
488
  const mainFromAccount = getMainAccount(fromAccount, fromParentAccount);
488
- const mainFromAccountFamily = mainFromAccount.currency.family;
489
+ const mainFromAccountFamily =
490
+ FAMILIES_MAPPING_LL_TO_WAPI[mainFromAccount.currency.family] ||
491
+ mainFromAccount.currency.family;
489
492
 
490
493
  if (transaction.family !== mainFromAccountFamily) {
491
494
  return Promise.reject(
@@ -741,9 +744,7 @@ async function getStrategy(
741
744
  customErrorType?: any,
742
745
  ): Promise<Transaction> {
743
746
  const family =
744
- currency.type === "TokenCurrency"
745
- ? (currency.parentCurrency?.family as Transaction["family"])
746
- : (currency.family as Transaction["family"]);
747
+ currency.type === "TokenCurrency" ? currency.parentCurrency?.family : currency.family;
747
748
 
748
749
  if (!family) {
749
750
  throw new Error(`TokenCurrency missing parentCurrency family: ${currency.id}`);
@@ -755,7 +756,7 @@ async function getStrategy(
755
756
  }
756
757
 
757
758
  // Normalize family key for strategy lookup
758
- const familyKey = family === "evm" ? "ethereum" : family;
759
+ const familyKey = FAMILIES_MAPPING_LL_TO_WAPI[family] || family;
759
760
  const strategy = transactionStrategy?.[familyKey];
760
761
 
761
762
  if (!strategy) {
@@ -764,7 +765,7 @@ async function getStrategy(
764
765
 
765
766
  try {
766
767
  return await strategy({
767
- family,
768
+ family: familyKey,
768
769
  amount,
769
770
  recipient,
770
771
  customFeeConfig: customFeeConfig || {},