@ledgerhq/live-common 34.40.0-nightly.1 → 34.40.0-nightly.3

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 (75) hide show
  1. package/lib/exchange/error.d.ts +1 -0
  2. package/lib/exchange/error.d.ts.map +1 -1
  3. package/lib/exchange/error.js +11 -1
  4. package/lib/exchange/error.js.map +1 -1
  5. package/lib/exchange/swap/api/v5/actions.d.ts +3 -0
  6. package/lib/exchange/swap/api/v5/actions.d.ts.map +1 -0
  7. package/lib/exchange/swap/api/v5/actions.js +36 -0
  8. package/lib/exchange/swap/api/v5/actions.js.map +1 -0
  9. package/lib/exchange/swap/getCompleteSwapHistory.js +1 -1
  10. package/lib/exchange/swap/getCompleteSwapHistory.js.map +1 -1
  11. package/lib/exchange/swap/postSwapState.d.ts.map +1 -1
  12. package/lib/exchange/swap/postSwapState.js +19 -9
  13. package/lib/exchange/swap/postSwapState.js.map +1 -1
  14. package/lib/exchange/swap/setBroadcastTransaction.d.ts +3 -2
  15. package/lib/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
  16. package/lib/exchange/swap/setBroadcastTransaction.js +4 -2
  17. package/lib/exchange/swap/setBroadcastTransaction.js.map +1 -1
  18. package/lib/exchange/swap/transactionStrategies.d.ts +25 -0
  19. package/lib/exchange/swap/transactionStrategies.d.ts.map +1 -0
  20. package/lib/exchange/swap/transactionStrategies.js +152 -0
  21. package/lib/exchange/swap/transactionStrategies.js.map +1 -0
  22. package/lib/exchange/swap/types.d.ts +59 -0
  23. package/lib/exchange/swap/types.d.ts.map +1 -1
  24. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  25. package/lib/featureFlags/defaultFeatures.js +1 -0
  26. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  27. package/lib/wallet-api/Exchange/server.d.ts +29 -10
  28. package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
  29. package/lib/wallet-api/Exchange/server.js +204 -7
  30. package/lib/wallet-api/Exchange/server.js.map +1 -1
  31. package/lib/wallet-api/Exchange/server.test.js +3 -1
  32. package/lib/wallet-api/Exchange/server.test.js.map +1 -1
  33. package/lib-es/exchange/error.d.ts +1 -0
  34. package/lib-es/exchange/error.d.ts.map +1 -1
  35. package/lib-es/exchange/error.js +9 -0
  36. package/lib-es/exchange/error.js.map +1 -1
  37. package/lib-es/exchange/swap/api/v5/actions.d.ts +3 -0
  38. package/lib-es/exchange/swap/api/v5/actions.d.ts.map +1 -0
  39. package/lib-es/exchange/swap/api/v5/actions.js +29 -0
  40. package/lib-es/exchange/swap/api/v5/actions.js.map +1 -0
  41. package/lib-es/exchange/swap/getCompleteSwapHistory.js +1 -1
  42. package/lib-es/exchange/swap/getCompleteSwapHistory.js.map +1 -1
  43. package/lib-es/exchange/swap/postSwapState.d.ts.map +1 -1
  44. package/lib-es/exchange/swap/postSwapState.js +17 -7
  45. package/lib-es/exchange/swap/postSwapState.js.map +1 -1
  46. package/lib-es/exchange/swap/setBroadcastTransaction.d.ts +3 -2
  47. package/lib-es/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
  48. package/lib-es/exchange/swap/setBroadcastTransaction.js +4 -2
  49. package/lib-es/exchange/swap/setBroadcastTransaction.js.map +1 -1
  50. package/lib-es/exchange/swap/transactionStrategies.d.ts +25 -0
  51. package/lib-es/exchange/swap/transactionStrategies.d.ts.map +1 -0
  52. package/lib-es/exchange/swap/transactionStrategies.js +140 -0
  53. package/lib-es/exchange/swap/transactionStrategies.js.map +1 -0
  54. package/lib-es/exchange/swap/types.d.ts +59 -0
  55. package/lib-es/exchange/swap/types.d.ts.map +1 -1
  56. package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
  57. package/lib-es/featureFlags/defaultFeatures.js +1 -0
  58. package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
  59. package/lib-es/wallet-api/Exchange/server.d.ts +29 -10
  60. package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
  61. package/lib-es/wallet-api/Exchange/server.js +206 -9
  62. package/lib-es/wallet-api/Exchange/server.js.map +1 -1
  63. package/lib-es/wallet-api/Exchange/server.test.js +3 -1
  64. package/lib-es/wallet-api/Exchange/server.test.js.map +1 -1
  65. package/package.json +40 -40
  66. package/src/exchange/error.ts +10 -0
  67. package/src/exchange/swap/api/v5/actions.ts +36 -0
  68. package/src/exchange/swap/getCompleteSwapHistory.ts +1 -1
  69. package/src/exchange/swap/postSwapState.ts +24 -6
  70. package/src/exchange/swap/setBroadcastTransaction.ts +6 -2
  71. package/src/exchange/swap/transactionStrategies.ts +234 -0
  72. package/src/exchange/swap/types.ts +64 -0
  73. package/src/featureFlags/defaultFeatures.ts +1 -0
  74. package/src/wallet-api/Exchange/server.test.ts +7 -5
  75. package/src/wallet-api/Exchange/server.ts +344 -32
@@ -11,13 +11,15 @@ export const setBroadcastTransaction = ({
11
11
  targetCurrencyId,
12
12
  hardwareWalletType,
13
13
  swapType,
14
+ swapAppVersion,
14
15
  }: {
15
- result: { operation: Operation; swapId: string };
16
+ result: { operation: Operation | string; swapId: string };
16
17
  provider: string;
17
18
  sourceCurrencyId?: string;
18
19
  targetCurrencyId?: string;
19
20
  hardwareWalletType?: DeviceModelId;
20
21
  swapType?: TradeMethod;
22
+ swapAppVersion?: string;
21
23
  }) => {
22
24
  const { operation, swapId } = result;
23
25
 
@@ -36,16 +38,18 @@ export const setBroadcastTransaction = ({
36
38
  targetCurrencyId,
37
39
  hardwareWalletType,
38
40
  swapType: swapType,
41
+ swapAppVersion,
39
42
  });
40
43
  } else {
41
44
  postSwapAccepted({
42
45
  provider,
43
46
  swapId,
44
- transactionId: operation.hash,
47
+ transactionId: typeof operation === "string" ? operation : operation.hash,
45
48
  sourceCurrencyId,
46
49
  targetCurrencyId,
47
50
  hardwareWalletType,
48
51
  swapType,
52
+ swapAppVersion,
49
53
  });
50
54
  }
51
55
  };
@@ -0,0 +1,234 @@
1
+ import { BigNumber } from "bignumber.js";
2
+
3
+ import {
4
+ CosmosTransaction,
5
+ ElrondTransaction,
6
+ RippleTransaction,
7
+ SolanaTransaction,
8
+ StellarTransaction,
9
+ TonTransaction,
10
+ Transaction,
11
+ TransactionCommon,
12
+ } from "@ledgerhq/wallet-api-client";
13
+
14
+ export type { SwapLiveError } from "@ledgerhq/wallet-api-exchange-module";
15
+
16
+ export function defaultTransaction({
17
+ family,
18
+ amount,
19
+ recipient,
20
+ customFeeConfig,
21
+ }: TransactionWithCustomFee): Transaction {
22
+ return <Transaction>{
23
+ family,
24
+ amount,
25
+ recipient,
26
+ ...customFeeConfig,
27
+ };
28
+ }
29
+
30
+ export function modeSendTransaction({
31
+ family,
32
+ amount,
33
+ recipient,
34
+ customFeeConfig,
35
+ }: TransactionWithCustomFee): Transaction {
36
+ return {
37
+ ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
38
+ mode: "send",
39
+ };
40
+ }
41
+
42
+ export function stellarTransaction({
43
+ family,
44
+ amount,
45
+ recipient,
46
+ customFeeConfig,
47
+ payinExtraId,
48
+ customErrorType,
49
+ }: TransactionWithCustomFee): StellarTransaction {
50
+ if (!payinExtraId)
51
+ throw {
52
+ error: new Error("Missing payinExtraId"),
53
+ step: "PayinExtraIdStepError",
54
+ customErrorType,
55
+ };
56
+
57
+ return {
58
+ ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
59
+ family: "stellar",
60
+ memoValue: payinExtraId,
61
+ memoType: "MEMO_TEXT",
62
+ };
63
+ }
64
+
65
+ export function rippleTransaction({
66
+ amount,
67
+ recipient,
68
+ customFeeConfig,
69
+ payinExtraId,
70
+ customErrorType,
71
+ }: TransactionWithCustomFee): RippleTransaction {
72
+ if (!payinExtraId)
73
+ throw {
74
+ error: new Error("Missing payinExtraId"),
75
+ step: "PayinExtraIdStepError",
76
+ customErrorType,
77
+ };
78
+
79
+ const transaction: RippleTransaction = {
80
+ family: "ripple",
81
+ amount,
82
+ recipient,
83
+ ...customFeeConfig,
84
+ tag: new BigNumber(payinExtraId).toNumber(),
85
+ };
86
+ return transaction;
87
+ }
88
+
89
+ // Function to remove gasLimit from customFeeConfig for Ethereum or Bitcoin
90
+ export function withoutGasLimitTransaction({
91
+ family,
92
+ amount,
93
+ recipient,
94
+ customFeeConfig,
95
+ extraTransactionParameters,
96
+ }: TransactionWithCustomFee): Transaction {
97
+ if (customFeeConfig?.gasLimit) {
98
+ delete customFeeConfig.gasLimit;
99
+ }
100
+
101
+ if (extraTransactionParameters) {
102
+ return <Transaction>{
103
+ family,
104
+ amount,
105
+ recipient,
106
+ ...customFeeConfig,
107
+ data: Buffer.from(extraTransactionParameters, "hex"),
108
+ };
109
+ }
110
+ return defaultTransaction({ family, amount, recipient, customFeeConfig });
111
+ }
112
+
113
+ export function bitcoinTransaction({
114
+ amount,
115
+ recipient,
116
+ customFeeConfig,
117
+ extraTransactionParameters,
118
+ }: TransactionWithCustomFee): Transaction {
119
+ if (extraTransactionParameters) {
120
+ return {
121
+ family: "bitcoin",
122
+ amount,
123
+ recipient,
124
+ ...customFeeConfig,
125
+ opReturnData: Buffer.from(extraTransactionParameters, "utf-8"),
126
+ };
127
+ }
128
+ return {
129
+ family: "bitcoin",
130
+ amount,
131
+ recipient,
132
+ ...customFeeConfig,
133
+ };
134
+ }
135
+
136
+ export function solanaTransaction({
137
+ family,
138
+ amount,
139
+ recipient,
140
+ customFeeConfig,
141
+ }: TransactionWithCustomFee): SolanaTransaction {
142
+ return {
143
+ ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
144
+ family: "solana",
145
+ model: { kind: "transfer", uiState: {} },
146
+ };
147
+ }
148
+
149
+ export function elrondTransaction({
150
+ amount,
151
+ recipient,
152
+ customFeeConfig,
153
+ }: TransactionWithCustomFee): ElrondTransaction {
154
+ const transaction: ElrondTransaction = {
155
+ family: "elrond",
156
+ amount,
157
+ recipient,
158
+ mode: "send",
159
+ ...customFeeConfig,
160
+ gasLimit: 0, // FIXME: Placeholder, adjust as needed
161
+ };
162
+ return transaction;
163
+ }
164
+
165
+ function tonTransaction({
166
+ family,
167
+ amount,
168
+ recipient,
169
+ customFeeConfig,
170
+ }: TransactionWithCustomFee): TonTransaction {
171
+ return {
172
+ ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
173
+ family: "ton",
174
+ comment: { isEncrypted: false, text: "" },
175
+ fees: new BigNumber(0), // Set default value as completeExchange call prepareTransaction, which set again fees.
176
+ };
177
+ }
178
+
179
+ export function cosmosTransaction({
180
+ family,
181
+ amount,
182
+ recipient,
183
+ customFeeConfig,
184
+ payinExtraId,
185
+ }: TransactionWithCustomFee): CosmosTransaction {
186
+ return <CosmosTransaction>{
187
+ ...defaultTransaction({ family, amount, recipient, customFeeConfig }),
188
+ family: "cosmos",
189
+ mode: "send",
190
+ memo: payinExtraId ?? undefined,
191
+ };
192
+ }
193
+
194
+ export type TransactionWithCustomFee = TransactionCommon & {
195
+ customFeeConfig: {
196
+ [key: string]: BigNumber;
197
+ };
198
+ payinExtraId?: string;
199
+ customErrorType?: "swap";
200
+ extraTransactionParameters?: string;
201
+ };
202
+
203
+ // Define a specific type for the strategy functions, assuming they might need parameters
204
+ export type TransactionStrategyFunction = (params: TransactionWithCustomFee) => Transaction;
205
+
206
+ export const transactionStrategy: {
207
+ [K in Transaction["family"]]: TransactionStrategyFunction;
208
+ } = {
209
+ algorand: defaultTransaction,
210
+ aptos: defaultTransaction,
211
+ bitcoin: bitcoinTransaction,
212
+ cardano: modeSendTransaction,
213
+ celo: defaultTransaction,
214
+ cosmos: cosmosTransaction,
215
+ crypto_org: defaultTransaction,
216
+ elrond: elrondTransaction,
217
+ ethereum: withoutGasLimitTransaction,
218
+ filecoin: defaultTransaction,
219
+ hedera: defaultTransaction,
220
+ near: modeSendTransaction,
221
+ neo: defaultTransaction,
222
+ polkadot: defaultTransaction,
223
+ ripple: rippleTransaction,
224
+ solana: solanaTransaction,
225
+ stacks: defaultTransaction,
226
+ stellar: stellarTransaction,
227
+ tezos: modeSendTransaction,
228
+ ton: tonTransaction,
229
+ tron: modeSendTransaction,
230
+ vechain: defaultTransaction,
231
+ casper: defaultTransaction,
232
+ sui: defaultTransaction,
233
+ internet_computer: defaultTransaction,
234
+ };
@@ -4,6 +4,7 @@ import { Account, AccountLike, AccountRaw, AccountRawLike, Operation } from "@le
4
4
  import { BigNumber } from "bignumber.js";
5
5
  import { Result as UseBridgeTransactionResult } from "../../bridge/useBridgeTransaction";
6
6
  import { Transaction, TransactionRaw } from "../../generated/types";
7
+
7
8
  export type { SwapLiveError } from "@ledgerhq/wallet-api-exchange-module";
8
9
 
9
10
  export type ExchangeSwap = {
@@ -198,6 +199,7 @@ type SwapStateRequest = {
198
199
  targetCurrencyId: string;
199
200
  hardwareWalletType: DeviceModelId;
200
201
  swapType: TradeMethod;
202
+ swapAppVersion?: string;
201
203
  }>;
202
204
 
203
205
  export type SwapStateAcceptedRequest = SwapStateRequest & {
@@ -336,3 +338,65 @@ export type SwapTransactionType = UseBridgeTransactionResult & {
336
338
  fromAmountError?: Error;
337
339
  fromAmountWarning?: Error;
338
340
  };
341
+
342
+ export type SwapPayloadRequestData = {
343
+ provider: string;
344
+ deviceTransactionId: string;
345
+ fromAccountAddress: string;
346
+ toAccountAddress: string;
347
+ fromAccountCurrency: string;
348
+ toAccountCurrency: string;
349
+ amount: string;
350
+ amountInAtomicUnit: number;
351
+ quoteId?: string;
352
+ toNewTokenId?: string;
353
+ };
354
+ export type SwapPayloadResponse = {
355
+ binaryPayload: string;
356
+ signature: string;
357
+ payinAddress: string;
358
+ swapId: string;
359
+ payinExtraId?: string;
360
+ extraTransactionParameters?: string;
361
+ };
362
+
363
+ export type ConfirmSwapRequest = {
364
+ provider: string;
365
+ swapId: string;
366
+ transactionId: string;
367
+ sourceCurrencyId?: string;
368
+ targetCurrencyId?: string;
369
+ hardwareWalletType?: string;
370
+ };
371
+
372
+ export type CancelSwapRequest = {
373
+ provider: string;
374
+ swapId: string;
375
+ statusCode?: string;
376
+ errorMessage?: string;
377
+ sourceCurrencyId?: string;
378
+ targetCurrencyId?: string;
379
+ hardwareWalletType?: string;
380
+ swapType?: string;
381
+ swapStep?: string;
382
+ };
383
+
384
+ export type SwapBackendResponse = {
385
+ provider: string;
386
+ swapId: string;
387
+ apiExtraFee: number;
388
+ apiFee: number;
389
+ refundAddress: string;
390
+ amountExpectedFrom: number;
391
+ amountExpectedTo: number;
392
+ status: string;
393
+ from: string;
394
+ to: string;
395
+ payinAddress: string;
396
+ payoutAddress: string;
397
+ createdAt: string; // ISO-8601
398
+ binaryPayload: string;
399
+ signature: string;
400
+ payinExtraId?: string;
401
+ extraTransactionParameters?: string;
402
+ };
@@ -153,6 +153,7 @@ export const DEFAULT_FEATURES: Features = {
153
153
  protectServicesDesktop: {
154
154
  enabled: false,
155
155
  params: {
156
+ openWithDevTools: false,
156
157
  availableOnDesktop: false,
157
158
  isNew: false,
158
159
  ledgerliveStorageState: false,
@@ -1,14 +1,14 @@
1
- import { handlers } from "./server";
2
- import { AppBranch, AppPlatform, Visibility } from "../types";
3
- import { of } from "rxjs";
1
+ import { RpcRequest } from "@ledgerhq/wallet-api-core";
4
2
  import {
5
3
  ExchangeStartParams,
6
4
  ExchangeStartSellParams,
7
5
  ExchangeStartSwapParams,
8
6
  } from "@ledgerhq/wallet-api-exchange-module";
9
- import { RpcRequest } from "@ledgerhq/wallet-api-core";
10
- import { genAccount } from "../../mock/account";
11
7
  import { WalletContext, WalletHandlers } from "@ledgerhq/wallet-api-server";
8
+ import { of } from "rxjs";
9
+ import { genAccount } from "../../mock/account";
10
+ import { AppBranch, AppPlatform, Visibility } from "../types";
11
+ import { handlers } from "./server";
12
12
 
13
13
  const mockTracking = {
14
14
  startExchangeRequested: jest.fn(),
@@ -46,6 +46,7 @@ const testAppManifest = {
46
46
 
47
47
  const mockUiStartExchange = jest.fn();
48
48
  const mockUiCompleteExchange = jest.fn();
49
+ const mockUiSwap = jest.fn();
49
50
  const mockUiError = jest.fn();
50
51
  const mockIsReady = jest.fn();
51
52
 
@@ -54,6 +55,7 @@ const mockUiHooks = {
54
55
  "custom.exchange.complete": mockUiCompleteExchange,
55
56
  "custom.exchange.error": mockUiError,
56
57
  "custom.isReady": mockIsReady,
58
+ "custom.exchange.swap": mockUiSwap,
57
59
  };
58
60
 
59
61
  // Mock converter id to send back the id received in params.