@ledgerhq/live-common 34.46.0-nightly.5 → 34.47.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 (88) hide show
  1. package/lib/families/sui/constants.d.ts +2 -0
  2. package/lib/families/sui/constants.d.ts.map +1 -0
  3. package/lib/families/sui/constants.js +19 -0
  4. package/lib/families/sui/constants.js.map +1 -0
  5. package/lib/families/sui/logic.d.ts +2 -0
  6. package/lib/families/sui/logic.d.ts.map +1 -0
  7. package/lib/families/sui/logic.js +19 -0
  8. package/lib/families/sui/logic.js.map +1 -0
  9. package/lib/families/sui/react.d.ts +8 -0
  10. package/lib/families/sui/react.d.ts.map +1 -0
  11. package/lib/families/sui/react.js +85 -0
  12. package/lib/families/sui/react.js.map +1 -0
  13. package/lib/families/sui/types.d.ts +2 -0
  14. package/lib/families/sui/types.d.ts.map +1 -0
  15. package/lib/families/sui/types.js +19 -0
  16. package/lib/families/sui/types.js.map +1 -0
  17. package/lib/modularDrawer/hooks/modules/useAssetAccountCounts.d.ts +19 -0
  18. package/lib/modularDrawer/hooks/modules/useAssetAccountCounts.d.ts.map +1 -0
  19. package/lib/modularDrawer/hooks/modules/useAssetAccountCounts.js +16 -0
  20. package/lib/modularDrawer/hooks/modules/useAssetAccountCounts.js.map +1 -0
  21. package/lib/modularDrawer/hooks/modules/useLeftApyModule.d.ts +52 -0
  22. package/lib/modularDrawer/hooks/modules/useLeftApyModule.d.ts.map +1 -0
  23. package/lib/modularDrawer/hooks/modules/useLeftApyModule.js +18 -0
  24. package/lib/modularDrawer/hooks/modules/useLeftApyModule.js.map +1 -0
  25. package/lib/modularDrawer/types.d.ts +2 -0
  26. package/lib/modularDrawer/types.d.ts.map +1 -0
  27. package/lib/modularDrawer/types.js +3 -0
  28. package/lib/modularDrawer/types.js.map +1 -0
  29. package/lib/wallet-api/Exchange/error.d.ts +1 -0
  30. package/lib/wallet-api/Exchange/error.d.ts.map +1 -1
  31. package/lib/wallet-api/Exchange/error.js +11 -1
  32. package/lib/wallet-api/Exchange/error.js.map +1 -1
  33. package/lib/wallet-api/Exchange/server.d.ts +2 -0
  34. package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
  35. package/lib/wallet-api/Exchange/server.js +29 -5
  36. package/lib/wallet-api/Exchange/server.js.map +1 -1
  37. package/lib/wallet-api/Exchange/server.test.js +3 -0
  38. package/lib/wallet-api/Exchange/server.test.js.map +1 -1
  39. package/lib-es/families/sui/constants.d.ts +2 -0
  40. package/lib-es/families/sui/constants.d.ts.map +1 -0
  41. package/lib-es/families/sui/constants.js +3 -0
  42. package/lib-es/families/sui/constants.js.map +1 -0
  43. package/lib-es/families/sui/logic.d.ts +2 -0
  44. package/lib-es/families/sui/logic.d.ts.map +1 -0
  45. package/lib-es/families/sui/logic.js +3 -0
  46. package/lib-es/families/sui/logic.js.map +1 -0
  47. package/lib-es/families/sui/react.d.ts +8 -0
  48. package/lib-es/families/sui/react.d.ts.map +1 -0
  49. package/lib-es/families/sui/react.js +78 -0
  50. package/lib-es/families/sui/react.js.map +1 -0
  51. package/lib-es/families/sui/types.d.ts +2 -0
  52. package/lib-es/families/sui/types.d.ts.map +1 -0
  53. package/lib-es/families/sui/types.js +3 -0
  54. package/lib-es/families/sui/types.js.map +1 -0
  55. package/lib-es/modularDrawer/hooks/modules/useAssetAccountCounts.d.ts +19 -0
  56. package/lib-es/modularDrawer/hooks/modules/useAssetAccountCounts.d.ts.map +1 -0
  57. package/lib-es/modularDrawer/hooks/modules/useAssetAccountCounts.js +12 -0
  58. package/lib-es/modularDrawer/hooks/modules/useAssetAccountCounts.js.map +1 -0
  59. package/lib-es/modularDrawer/hooks/modules/useLeftApyModule.d.ts +52 -0
  60. package/lib-es/modularDrawer/hooks/modules/useLeftApyModule.d.ts.map +1 -0
  61. package/lib-es/modularDrawer/hooks/modules/useLeftApyModule.js +11 -0
  62. package/lib-es/modularDrawer/hooks/modules/useLeftApyModule.js.map +1 -0
  63. package/lib-es/modularDrawer/types.d.ts +2 -0
  64. package/lib-es/modularDrawer/types.d.ts.map +1 -0
  65. package/lib-es/modularDrawer/types.js +2 -0
  66. package/lib-es/modularDrawer/types.js.map +1 -0
  67. package/lib-es/wallet-api/Exchange/error.d.ts +1 -0
  68. package/lib-es/wallet-api/Exchange/error.d.ts.map +1 -1
  69. package/lib-es/wallet-api/Exchange/error.js +9 -0
  70. package/lib-es/wallet-api/Exchange/error.js.map +1 -1
  71. package/lib-es/wallet-api/Exchange/server.d.ts +2 -0
  72. package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
  73. package/lib-es/wallet-api/Exchange/server.js +30 -6
  74. package/lib-es/wallet-api/Exchange/server.js.map +1 -1
  75. package/lib-es/wallet-api/Exchange/server.test.js +3 -0
  76. package/lib-es/wallet-api/Exchange/server.test.js.map +1 -1
  77. package/package.json +47 -47
  78. package/src/families/sui/__snapshots__/bridge.integration.test.ts.snap +3 -1
  79. package/src/families/sui/constants.ts +2 -0
  80. package/src/families/sui/logic.ts +2 -0
  81. package/src/families/sui/react.ts +115 -0
  82. package/src/families/sui/types.ts +2 -0
  83. package/src/modularDrawer/hooks/modules/useAssetAccountCounts.tsx +36 -0
  84. package/src/modularDrawer/hooks/modules/useLeftApyModule.tsx +26 -0
  85. package/src/modularDrawer/types.ts +1 -0
  86. package/src/wallet-api/Exchange/error.ts +10 -0
  87. package/src/wallet-api/Exchange/server.test.ts +5 -1
  88. package/src/wallet-api/Exchange/server.ts +44 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ledgerhq/live-common",
3
3
  "description": "Common ground for the Ledger Live apps",
4
- "version": "34.46.0-nightly.5",
4
+ "version": "34.47.0-nightly.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/LedgerHQ/ledger-live.git"
@@ -165,76 +165,76 @@
165
165
  "xstate": "^5.19.2",
166
166
  "yargs": "^17.0.0",
167
167
  "zod": "^3.22.4",
168
- "@ledgerhq/coin-algorand": "^0.9.18-nightly.2",
169
- "@ledgerhq/coin-aptos": "^3.1.1-nightly.2",
170
- "@ledgerhq/coin-bitcoin": "^0.21.0-nightly.2",
171
- "@ledgerhq/coin-canton": "^0.2.2-nightly.2",
172
- "@ledgerhq/coin-cardano": "^0.11.2-nightly.2",
173
- "@ledgerhq/coin-casper": "^2.0.9-nightly.2",
174
- "@ledgerhq/coin-celo": "^1.2.1-nightly.4",
175
- "@ledgerhq/coin-cosmos": "^0.16.7-nightly.2",
176
- "@ledgerhq/coin-evm": "^2.28.0-nightly.4",
177
- "@ledgerhq/coin-filecoin": "^1.10.1-nightly.2",
178
- "@ledgerhq/coin-framework": "^6.2.0-nightly.2",
179
- "@ledgerhq/coin-hedera": "^1.11.0-nightly.2",
180
- "@ledgerhq/coin-icon": "^0.11.5-nightly.2",
181
- "@ledgerhq/coin-internet_computer": "^1.7.18-nightly.2",
182
- "@ledgerhq/coin-mina": "^1.1.17-nightly.2",
183
- "@ledgerhq/coin-multiversx": "^0.4.18-nightly.2",
184
- "@ledgerhq/coin-near": "^0.12.1-nightly.2",
185
- "@ledgerhq/coin-polkadot": "^6.7.1-nightly.2",
186
- "@ledgerhq/coin-solana": "^0.32.0-nightly.2",
187
- "@ledgerhq/coin-stacks": "^0.8.18-nightly.2",
188
- "@ledgerhq/coin-stellar": "^6.2.0-nightly.2",
189
- "@ledgerhq/coin-sui": "^0.10.1-nightly.2",
190
- "@ledgerhq/coin-tezos": "^6.1.1-nightly.2",
191
- "@ledgerhq/coin-ton": "^0.13.7-nightly.2",
192
- "@ledgerhq/coin-tron": "^5.1.1-nightly.2",
193
- "@ledgerhq/coin-vechain": "^2.8.2-nightly.2",
194
- "@ledgerhq/coin-xrp": "^7.2.0-nightly.2",
168
+ "@ledgerhq/coin-algorand": "^0.9.18",
169
+ "@ledgerhq/coin-aptos": "^3.1.1",
170
+ "@ledgerhq/coin-bitcoin": "^0.20.2",
171
+ "@ledgerhq/coin-canton": "^0.3.0",
172
+ "@ledgerhq/coin-cardano": "^0.11.2",
173
+ "@ledgerhq/coin-casper": "^2.0.9",
174
+ "@ledgerhq/coin-celo": "^1.2.1",
175
+ "@ledgerhq/coin-cosmos": "^0.16.7",
176
+ "@ledgerhq/coin-evm": "^2.28.0",
177
+ "@ledgerhq/coin-filecoin": "^1.10.1",
178
+ "@ledgerhq/coin-framework": "^6.2.0",
179
+ "@ledgerhq/coin-hedera": "^1.10.1",
180
+ "@ledgerhq/coin-icon": "^0.11.5",
181
+ "@ledgerhq/coin-internet_computer": "^1.7.18",
182
+ "@ledgerhq/coin-mina": "^1.1.17",
183
+ "@ledgerhq/coin-multiversx": "^0.4.18",
184
+ "@ledgerhq/coin-near": "^0.12.1",
185
+ "@ledgerhq/coin-polkadot": "^6.8.0",
186
+ "@ledgerhq/coin-solana": "^0.31.1",
187
+ "@ledgerhq/coin-stacks": "^0.8.18",
188
+ "@ledgerhq/coin-stellar": "^6.2.0",
189
+ "@ledgerhq/coin-sui": "^0.12.0-nightly.0",
190
+ "@ledgerhq/coin-tezos": "^6.2.0",
191
+ "@ledgerhq/coin-ton": "^0.13.8-nightly.0",
192
+ "@ledgerhq/coin-tron": "^5.3.0-nightly.0",
193
+ "@ledgerhq/coin-vechain": "^2.8.2",
194
+ "@ledgerhq/coin-xrp": "^7.2.0",
195
195
  "@ledgerhq/crypto-icons-ui": "^1.18.0-nightly.0",
196
- "@ledgerhq/cryptoassets": "^13.26.0-nightly.1",
197
- "@ledgerhq/device-core": "^0.6.1-nightly.2",
196
+ "@ledgerhq/cryptoassets": "^13.26.0",
197
+ "@ledgerhq/device-core": "^0.6.1",
198
198
  "@ledgerhq/devices": "8.5.1-nightly.0",
199
199
  "@ledgerhq/errors": "^6.25.0-nightly.0",
200
200
  "@ledgerhq/hw-app-algorand": "^6.31.6-nightly.0",
201
201
  "@ledgerhq/hw-app-aptos": "^6.34.6-nightly.0",
202
202
  "@ledgerhq/hw-app-btc": "^10.10.2-nightly.0",
203
- "@ledgerhq/hw-app-celo": "^6.34.1-nightly.2",
203
+ "@ledgerhq/hw-app-celo": "^6.34.1",
204
204
  "@ledgerhq/hw-app-cosmos": "^6.32.6-nightly.0",
205
- "@ledgerhq/hw-app-eth": "^6.45.16-nightly.2",
206
- "@ledgerhq/hw-app-exchange": "^0.12.1-nightly.0",
205
+ "@ledgerhq/hw-app-eth": "^6.45.16",
206
+ "@ledgerhq/hw-app-exchange": "^0.13.0",
207
207
  "@ledgerhq/hw-app-hedera": "^1.2.6-nightly.0",
208
208
  "@ledgerhq/hw-app-icon": "^1.3.6-nightly.0",
209
209
  "@ledgerhq/hw-app-multiversx": "^6.25.1-nightly.0",
210
210
  "@ledgerhq/hw-app-near": "^6.31.6-nightly.0",
211
211
  "@ledgerhq/hw-app-polkadot": "^6.34.6-nightly.0",
212
212
  "@ledgerhq/hw-app-str": "^7.2.6-nightly.0",
213
- "@ledgerhq/hw-app-sui": "^1.3.0-nightly.0",
213
+ "@ledgerhq/hw-app-sui": "^1.4.0-nightly.0",
214
214
  "@ledgerhq/hw-app-tezos": "^6.31.6-nightly.0",
215
215
  "@ledgerhq/hw-app-trx": "^6.31.6-nightly.0",
216
- "@ledgerhq/hw-app-vet": "^0.5.14-nightly.1",
216
+ "@ledgerhq/hw-app-vet": "^0.5.14",
217
217
  "@ledgerhq/hw-app-xrp": "^6.32.4-nightly.0",
218
218
  "@ledgerhq/hw-transport": "^6.31.10-nightly.0",
219
219
  "@ledgerhq/hw-transport-mocker": "^6.29.10-nightly.0",
220
220
  "@ledgerhq/ledger-cal-service": "^1.3.1-nightly.1",
221
221
  "@ledgerhq/live-config": "^3.2.0-nightly.0",
222
- "@ledgerhq/live-countervalues": "^0.7.0-nightly.2",
223
- "@ledgerhq/live-countervalues-react": "^0.4.1-nightly.2",
224
- "@ledgerhq/live-dmk-shared": "^0.12.1-nightly.0",
222
+ "@ledgerhq/live-countervalues": "^0.6.2",
223
+ "@ledgerhq/live-countervalues-react": "^0.5.0",
224
+ "@ledgerhq/live-dmk-shared": "^0.12.1",
225
225
  "@ledgerhq/live-env": "^2.15.0-nightly.1",
226
226
  "@ledgerhq/live-hooks": "0.1.0",
227
227
  "@ledgerhq/live-network": "^2.0.16-nightly.1",
228
- "@ledgerhq/live-nft": "^0.8.18-nightly.2",
228
+ "@ledgerhq/live-nft": "^0.8.18",
229
229
  "@ledgerhq/live-promise": "^0.1.1",
230
- "@ledgerhq/live-signer-canton": "^0.2.2-nightly.2",
231
- "@ledgerhq/live-signer-evm": "^0.7.1-nightly.4",
232
- "@ledgerhq/live-signer-solana": "^0.5.3-nightly.2",
233
- "@ledgerhq/live-wallet": "^0.13.0-nightly.2",
230
+ "@ledgerhq/live-signer-canton": "^0.2.3-nightly.0",
231
+ "@ledgerhq/live-signer-evm": "^0.7.1",
232
+ "@ledgerhq/live-signer-solana": "^0.5.3",
233
+ "@ledgerhq/live-wallet": "^0.12.2",
234
234
  "@ledgerhq/logs": "^6.13.0",
235
235
  "@ledgerhq/speculos-transport": "^0.2.9-nightly.1",
236
236
  "@ledgerhq/wallet-api-acre-module": "^0.6.0",
237
- "@ledgerhq/wallet-api-exchange-module": "^0.16.0-nightly.0"
237
+ "@ledgerhq/wallet-api-exchange-module": "^0.16.0-nightly.1"
238
238
  },
239
239
  "devDependencies": {
240
240
  "@solana/web3.js": "1.95.4",
@@ -282,10 +282,10 @@
282
282
  "undici": "6.19.2",
283
283
  "uuid": "^8.3.2",
284
284
  "ws": "7",
285
- "@ledgerhq/device-react": "^0.2.42-nightly.2",
285
+ "@ledgerhq/device-react": "^0.2.42",
286
286
  "@ledgerhq/types-cryptoassets": "^7.26.0-nightly.0",
287
- "@ledgerhq/types-devices": "^6.26.0",
288
- "@ledgerhq/types-live": "^6.82.0-nightly.2"
287
+ "@ledgerhq/types-devices": "^6.27.0",
288
+ "@ledgerhq/types-live": "^6.82.0"
289
289
  },
290
290
  "scripts": {
291
291
  "build": "zx ./scripts/build-ts.mjs",
@@ -14,9 +14,10 @@ exports[`sui currency bridge scanAccounts sui seed 1 1`] = `
14
14
  "pendingOperations": [],
15
15
  "seedIdentifier": "e5fb8c817b97e9e9aec677b9e822e8a60c7471624f36b701c94560b88195a8e7",
16
16
  "spendableBalance": "102696240",
17
+ "subAccounts": [],
17
18
  "suiResources": {},
18
19
  "swapHistory": [],
19
- "syncHash": undefined,
20
+ "syncHash": "6p9XjoTwZ81o9xTkodgswDbETbrN5Lkv1b2shBN4p99s",
20
21
  "used": true,
21
22
  },
22
23
  {
@@ -31,6 +32,7 @@ exports[`sui currency bridge scanAccounts sui seed 1 1`] = `
31
32
  "pendingOperations": [],
32
33
  "seedIdentifier": "e5fb8c817b97e9e9aec677b9e822e8a60c7471624f36b701c94560b88195a8e7",
33
34
  "spendableBalance": "0",
35
+ "subAccounts": [],
34
36
  "suiResources": {},
35
37
  "swapHistory": [],
36
38
  "syncHash": undefined,
@@ -0,0 +1,2 @@
1
+ // Encapsulate for LLD et LLM
2
+ export * from "@ledgerhq/coin-sui/constants";
@@ -0,0 +1,2 @@
1
+ // Encapsulate for LLD et LLM
2
+ export * from "@ledgerhq/coin-sui/logic";
@@ -0,0 +1,115 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { FIGMENT_SUI_VALIDATOR_ADDRESS } from "@ledgerhq/coin-sui/constants";
3
+ import { BigNumber } from "bignumber.js";
4
+ import { SuiAccount, SuiResources, SuiValidator, MappedStake } from "./types";
5
+ import { getAccountCurrency } from "../../account";
6
+ import { Unit } from "@ledgerhq/types-cryptoassets";
7
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
8
+ import { getCurrentSuiPreloadData } from "@ledgerhq/coin-sui/preload";
9
+ import { getOperationExtra } from "@ledgerhq/coin-sui/getOperationExtra";
10
+ import { OperationType } from "@ledgerhq/types-live";
11
+
12
+ export function useSuiMappedStakingPositions(account: SuiAccount) {
13
+ const { validators } = getCurrentSuiPreloadData();
14
+ const stakingPositions = account.suiResources?.stakes;
15
+
16
+ const unit = getAccountCurrency(account).units[0];
17
+
18
+ return useMemo(
19
+ () => mapStakingPositions(stakingPositions ?? [], validators, unit),
20
+ [stakingPositions, validators, unit],
21
+ );
22
+ }
23
+
24
+ export function useGetExtraDetails(account: SuiAccount, type: OperationType, digest: string) {
25
+ if (!account.suiResources) {
26
+ account.suiResources = {};
27
+ }
28
+ if (!account.suiResources.cachedOps) {
29
+ account.suiResources.cachedOps = {};
30
+ }
31
+ const cache = account.suiResources.cachedOps;
32
+ const [data, setData] = useState(cache[digest]);
33
+
34
+ useEffect(() => {
35
+ if (type !== "DELEGATE" && type !== "UNDELEGATE") return;
36
+ if (data) return;
37
+ getOperationExtra(digest).then(result => {
38
+ setData(result);
39
+ cache[digest] = result;
40
+ });
41
+ }, [data, digest, cache, type]);
42
+
43
+ return data;
44
+ }
45
+
46
+ export function useLedgerFirstShuffledValidatorsSui(search: string) {
47
+ const { validators: unorderedValidators } = getCurrentSuiPreloadData();
48
+ const validators = reorderValidators(unorderedValidators);
49
+ return useMemo(() => {
50
+ if (validators.length === 0 || !search || search === "") {
51
+ return validators;
52
+ }
53
+
54
+ const lowercaseSearch = search.toLowerCase();
55
+
56
+ const filtered = validators.filter(
57
+ validator =>
58
+ validator.suiAddress?.toLowerCase().includes(lowercaseSearch) ||
59
+ validator.name.toLowerCase().includes(lowercaseSearch),
60
+ );
61
+
62
+ return filtered;
63
+ }, [validators, search]);
64
+ }
65
+
66
+ function reorderValidators(validators: SuiValidator[]): SuiValidator[] {
67
+ const sortedValidators = [...validators].sort((a, b) =>
68
+ new BigNumber(b.stakingPoolSuiBalance).minus(new BigNumber(a.stakingPoolSuiBalance)).toNumber(),
69
+ );
70
+
71
+ // move Ledger validator to the first position
72
+ const ledgerValidator = sortedValidators.find(
73
+ v => v.suiAddress === FIGMENT_SUI_VALIDATOR_ADDRESS,
74
+ );
75
+
76
+ if (ledgerValidator) {
77
+ const sortedValidatorsLedgerFirst = sortedValidators.filter(
78
+ v => v.suiAddress !== FIGMENT_SUI_VALIDATOR_ADDRESS,
79
+ );
80
+ sortedValidatorsLedgerFirst.unshift(ledgerValidator);
81
+
82
+ return sortedValidatorsLedgerFirst;
83
+ }
84
+
85
+ return sortedValidators;
86
+ }
87
+
88
+ type Stake = Required<SuiResources>["stakes"];
89
+
90
+ export const mapStakingPositions = (
91
+ stakingPositions: Stake,
92
+ validators: SuiValidator[],
93
+ unit: Unit,
94
+ ): MappedStake[] => {
95
+ const data = stakingPositions.flatMap(sp =>
96
+ sp.stakes.map(s => ({ ...s, validatorAddress: sp.validatorAddress })),
97
+ );
98
+ return data.map<MappedStake>(sp => {
99
+ const rank = validators.findIndex(v => v.suiAddress === sp.validatorAddress);
100
+ const validator = validators[rank] ?? sp;
101
+ const formatConfig = {
102
+ disableRounding: false,
103
+ alwaysShowSign: false,
104
+ showCode: true,
105
+ };
106
+
107
+ return {
108
+ ...sp,
109
+ rank,
110
+ validator,
111
+ stakedSuiId: sp.stakedSuiId,
112
+ formattedAmount: formatCurrencyUnit(unit, BigNumber(sp.principal), formatConfig),
113
+ };
114
+ });
115
+ };
@@ -0,0 +1,2 @@
1
+ // Encapsulate for LLD et LLM
2
+ export * from "@ledgerhq/coin-sui/types";
@@ -0,0 +1,36 @@
1
+ import { Observable } from "rxjs";
2
+ import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import { getAccountTuplesForCurrency } from "../../../utils/getAccountTuplesForCurrency";
4
+ import type { Account } from "@ledgerhq/types-live";
5
+ import { WalletAPIAccount } from "../../../wallet-api/types";
6
+
7
+ type AccountModuleParams = {
8
+ assets: CryptoOrTokenCurrency[];
9
+ nestedAccounts: Account[];
10
+ accountIds: Map<string, boolean> | undefined;
11
+ formatLabel: (count: number) => string;
12
+ accounts$?: Observable<WalletAPIAccount[]>;
13
+ };
14
+
15
+ export type AssetCountItem = {
16
+ asset: CryptoOrTokenCurrency;
17
+ label: string;
18
+ count: number;
19
+ };
20
+
21
+ export const useAssetAccountCounts = ({
22
+ assets,
23
+ nestedAccounts,
24
+ accountIds,
25
+ formatLabel,
26
+ }: AccountModuleParams): AssetCountItem[] =>
27
+ assets
28
+ .map(asset => {
29
+ const { length } = getAccountTuplesForCurrency(asset, nestedAccounts, accountIds);
30
+ return {
31
+ asset,
32
+ label: formatLabel(length),
33
+ count: length,
34
+ };
35
+ })
36
+ .sort((a, b) => b.count - a.count);
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import { ApyType } from "../../types";
4
+
5
+ const createApyItem = ({
6
+ value,
7
+ type,
8
+ ApyIndicator,
9
+ }: {
10
+ value: number;
11
+ type: ApyType;
12
+ ApyIndicator: React.ComponentType<{ value: number; type: ApyType }>;
13
+ }) => <ApyIndicator value={value} type={type} />;
14
+
15
+ export const useLeftApyModule = (
16
+ assets: CryptoOrTokenCurrency[],
17
+ ApyIndicator: React.ComponentType<{ value: number; type: ApyType }>,
18
+ ) => {
19
+ const value = 5.11; // TODO to be retrieved from DADA
20
+ const type = "APY"; // TODO to be retrieved from DADA
21
+
22
+ return assets.map(asset => ({
23
+ ...asset,
24
+ leftElement: createApyItem({ value, type, ApyIndicator }),
25
+ }));
26
+ };
@@ -0,0 +1 @@
1
+ export type ApyType = "NRR" | "APY" | "APR";
@@ -24,6 +24,16 @@ export function createWrongSellParams(params: unknown): ExchangeErrorData {
24
24
  };
25
25
  }
26
26
 
27
+ export function createWrongFundParams(params: unknown): ExchangeErrorData {
28
+ return {
29
+ code: "WRONG_FUND_PARAMS",
30
+ message: "fund params are not correctly set",
31
+ data: {
32
+ params,
33
+ },
34
+ };
35
+ }
36
+
27
37
  export function createAccounIdNotFound(accountId: string): ExchangeErrorData {
28
38
  return {
29
39
  code: "ACCOUNT_ID_NOT_FOUND",
@@ -3,6 +3,7 @@ import {
3
3
  ExchangeStartParams,
4
4
  ExchangeStartSellParams,
5
5
  ExchangeStartSwapParams,
6
+ ExchangeStartFundParams,
6
7
  } from "@ledgerhq/wallet-api-exchange-module";
7
8
  import { WalletContext, WalletHandlers } from "@ledgerhq/wallet-api-server";
8
9
  import { of } from "rxjs";
@@ -153,8 +154,10 @@ describe("handlers", () => {
153
154
  uiHooks: mockUiHooks,
154
155
  });
155
156
 
156
- const params: ExchangeStartParams = {
157
+ const params: ExchangeStartFundParams = {
157
158
  exchangeType: "FUND",
159
+ provider: "TestFundProvider",
160
+ fromAccountId: accounts[0].id,
158
161
  };
159
162
  const { request, context, walletHandlers } = prepareSellRequest(params);
160
163
 
@@ -170,6 +173,7 @@ describe("handlers", () => {
170
173
  expect(mockUiStartExchange).toHaveBeenCalledTimes(1);
171
174
  const receivedParams = mockUiStartExchange.mock.calls[0][0].exchangeParams;
172
175
  expect(receivedParams.exchangeType).toBe("FUND");
176
+ expect(receivedParams.provider).toBe("TestFundProvider");
173
177
  expect(mockUiCompleteExchange).not.toHaveBeenCalled();
174
178
  });
175
179
  });
@@ -22,6 +22,7 @@ import {
22
22
  ExchangeStartResult,
23
23
  ExchangeStartSellParams,
24
24
  ExchangeStartSwapParams,
25
+ ExchangeStartFundParams,
25
26
  ExchangeSwapParams,
26
27
  ExchangeType,
27
28
  SwapLiveError,
@@ -44,6 +45,7 @@ import {
44
45
  createAccounIdNotFound,
45
46
  createWrongSellParams,
46
47
  createWrongSwapParams,
48
+ createWrongFundParams,
47
49
  ExchangeError,
48
50
  } from "./error";
49
51
  import { TrackingAPI } from "./tracking";
@@ -82,6 +84,8 @@ export type CompleteExchangeUiRequest = {
82
84
  };
83
85
  type FundStartParamsUiRequest = {
84
86
  exchangeType: "FUND";
87
+ provider: string;
88
+ exchange: Partial<Exchange> | undefined;
85
89
  };
86
90
 
87
91
  type SellStartParamsUiRequest = {
@@ -158,8 +162,6 @@ export const handlers = ({
158
162
  }
159
163
 
160
164
  const trackingParams = {
161
- // @ts-expect-error ExchangeStartFundParams does not yet have the provider. Will be added in another iteration after a bugfix is confirmed
162
- // TODO: expect-error to be deleted after
163
165
  provider: params.provider,
164
166
  exchangeType: params.exchangeType,
165
167
  };
@@ -174,9 +176,7 @@ export const handlers = ({
174
176
  } else if (params.exchangeType == "SELL") {
175
177
  exchangeParams = extractSellStartParam(params, accounts);
176
178
  } else {
177
- exchangeParams = {
178
- exchangeType: params.exchangeType,
179
- };
179
+ exchangeParams = extractFundStartParam(params, accounts);
180
180
  }
181
181
 
182
182
  return new Promise((resolve, reject) =>
@@ -711,6 +711,45 @@ function extractSellStartParam(
711
711
  };
712
712
  }
713
713
 
714
+ function extractFundStartParam(
715
+ params: ExchangeStartFundParams,
716
+ accounts: AccountLike[],
717
+ ): ExchangeStartParamsUiRequest {
718
+ if (!("provider" in params)) {
719
+ throw new ExchangeError(createWrongFundParams(params));
720
+ }
721
+
722
+ if (!params.fromAccountId) {
723
+ return {
724
+ exchangeType: params.exchangeType,
725
+ provider: params.provider,
726
+ } as ExchangeStartParamsUiRequest;
727
+ }
728
+
729
+ const realFromAccountId = getAccountIdFromWalletAccountId(params?.fromAccountId);
730
+
731
+ if (!realFromAccountId) {
732
+ throw new ExchangeError(createAccounIdNotFound(params.fromAccountId));
733
+ }
734
+
735
+ const fromAccount = accounts?.find(acc => acc.id === realFromAccountId);
736
+
737
+ if (!fromAccount) {
738
+ throw new ServerError(createAccountNotFound(params.fromAccountId));
739
+ }
740
+
741
+ const fromParentAccount = getParentAccount(fromAccount, accounts);
742
+
743
+ return {
744
+ exchangeType: params.exchangeType,
745
+ provider: params.provider,
746
+ exchange: {
747
+ fromAccount,
748
+ fromParentAccount,
749
+ },
750
+ };
751
+ }
752
+
714
753
  async function getToCurrency(
715
754
  binaryPayload: string,
716
755
  toAccount: AccountLike,