@ledgerhq/live-common 34.40.0-nightly.4 → 34.40.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 (145) hide show
  1. package/lib/e2e/enum/Provider.d.ts +0 -3
  2. package/lib/e2e/enum/Provider.d.ts.map +1 -1
  3. package/lib/e2e/enum/Provider.js +0 -3
  4. package/lib/e2e/enum/Provider.js.map +1 -1
  5. package/lib/exchange/error.d.ts +0 -1
  6. package/lib/exchange/error.d.ts.map +1 -1
  7. package/lib/exchange/error.js +1 -11
  8. package/lib/exchange/error.js.map +1 -1
  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 +9 -19
  13. package/lib/exchange/swap/postSwapState.js.map +1 -1
  14. package/lib/exchange/swap/setBroadcastTransaction.d.ts +2 -3
  15. package/lib/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
  16. package/lib/exchange/swap/setBroadcastTransaction.js +2 -4
  17. package/lib/exchange/swap/setBroadcastTransaction.js.map +1 -1
  18. package/lib/exchange/swap/types.d.ts +0 -59
  19. package/lib/exchange/swap/types.d.ts.map +1 -1
  20. package/lib/families/cardano/signerSerializer.js +2 -4
  21. package/lib/families/cardano/signerSerializer.js.map +1 -1
  22. package/lib/families/evm/bridge/mock.js +2 -2
  23. package/lib/families/evm/platformAdapter.js +2 -2
  24. package/lib/families/evm/platformAdapter.js.map +1 -1
  25. package/lib/families/evm/platformAdapter.test.js +4 -4
  26. package/lib/families/evm/platformAdapter.test.js.map +1 -1
  27. package/lib/families/evm/react.js +1 -1
  28. package/lib/families/evm/react.js.map +1 -1
  29. package/lib/families/evm/react.test.js +2 -2
  30. package/lib/families/evm/react.test.js.map +1 -1
  31. package/lib/families/evm/walletApiAdapter.js +1 -1
  32. package/lib/families/evm/walletApiAdapter.js.map +1 -1
  33. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  34. package/lib/featureFlags/defaultFeatures.js +0 -1
  35. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  36. package/lib/hw/connectManager.js +6 -6
  37. package/lib/hw/connectManager.js.map +1 -1
  38. package/lib/hw/getOnboardingStatePolling.d.ts.map +1 -1
  39. package/lib/hw/getOnboardingStatePolling.js +2 -0
  40. package/lib/hw/getOnboardingStatePolling.js.map +1 -1
  41. package/lib/hw/getOnboardingStatePolling.test.js +24 -0
  42. package/lib/hw/getOnboardingStatePolling.test.js.map +1 -1
  43. package/lib/mock/account.d.ts.map +1 -1
  44. package/lib/mock/account.js +0 -1
  45. package/lib/mock/account.js.map +1 -1
  46. package/lib/wallet-api/Exchange/server.d.ts +10 -29
  47. package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
  48. package/lib/wallet-api/Exchange/server.js +7 -204
  49. package/lib/wallet-api/Exchange/server.js.map +1 -1
  50. package/lib/wallet-api/Exchange/server.test.js +1 -3
  51. package/lib/wallet-api/Exchange/server.test.js.map +1 -1
  52. package/lib/wallet-api/useDappLogic.js +2 -2
  53. package/lib-es/e2e/enum/Provider.d.ts +0 -3
  54. package/lib-es/e2e/enum/Provider.d.ts.map +1 -1
  55. package/lib-es/e2e/enum/Provider.js +0 -3
  56. package/lib-es/e2e/enum/Provider.js.map +1 -1
  57. package/lib-es/exchange/error.d.ts +0 -1
  58. package/lib-es/exchange/error.d.ts.map +1 -1
  59. package/lib-es/exchange/error.js +0 -9
  60. package/lib-es/exchange/error.js.map +1 -1
  61. package/lib-es/exchange/swap/getCompleteSwapHistory.js +1 -1
  62. package/lib-es/exchange/swap/getCompleteSwapHistory.js.map +1 -1
  63. package/lib-es/exchange/swap/postSwapState.d.ts.map +1 -1
  64. package/lib-es/exchange/swap/postSwapState.js +7 -17
  65. package/lib-es/exchange/swap/postSwapState.js.map +1 -1
  66. package/lib-es/exchange/swap/setBroadcastTransaction.d.ts +2 -3
  67. package/lib-es/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
  68. package/lib-es/exchange/swap/setBroadcastTransaction.js +2 -4
  69. package/lib-es/exchange/swap/setBroadcastTransaction.js.map +1 -1
  70. package/lib-es/exchange/swap/types.d.ts +0 -59
  71. package/lib-es/exchange/swap/types.d.ts.map +1 -1
  72. package/lib-es/families/cardano/signerSerializer.js +2 -4
  73. package/lib-es/families/cardano/signerSerializer.js.map +1 -1
  74. package/lib-es/families/evm/bridge/mock.js +1 -1
  75. package/lib-es/families/evm/platformAdapter.js +1 -1
  76. package/lib-es/families/evm/platformAdapter.js.map +1 -1
  77. package/lib-es/families/evm/platformAdapter.test.js +1 -1
  78. package/lib-es/families/evm/platformAdapter.test.js.map +1 -1
  79. package/lib-es/families/evm/react.js +1 -1
  80. package/lib-es/families/evm/react.js.map +1 -1
  81. package/lib-es/families/evm/react.test.js +2 -2
  82. package/lib-es/families/evm/react.test.js.map +1 -1
  83. package/lib-es/families/evm/walletApiAdapter.js +1 -1
  84. package/lib-es/families/evm/walletApiAdapter.js.map +1 -1
  85. package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
  86. package/lib-es/featureFlags/defaultFeatures.js +0 -1
  87. package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
  88. package/lib-es/hw/connectManager.js +6 -6
  89. package/lib-es/hw/connectManager.js.map +1 -1
  90. package/lib-es/hw/getOnboardingStatePolling.d.ts.map +1 -1
  91. package/lib-es/hw/getOnboardingStatePolling.js +2 -0
  92. package/lib-es/hw/getOnboardingStatePolling.js.map +1 -1
  93. package/lib-es/hw/getOnboardingStatePolling.test.js +24 -0
  94. package/lib-es/hw/getOnboardingStatePolling.test.js.map +1 -1
  95. package/lib-es/mock/account.d.ts.map +1 -1
  96. package/lib-es/mock/account.js +0 -1
  97. package/lib-es/mock/account.js.map +1 -1
  98. package/lib-es/wallet-api/Exchange/server.d.ts +10 -29
  99. package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
  100. package/lib-es/wallet-api/Exchange/server.js +9 -206
  101. package/lib-es/wallet-api/Exchange/server.js.map +1 -1
  102. package/lib-es/wallet-api/Exchange/server.test.js +1 -3
  103. package/lib-es/wallet-api/Exchange/server.test.js.map +1 -1
  104. package/lib-es/wallet-api/useDappLogic.js +1 -1
  105. package/package.json +45 -45
  106. package/src/e2e/enum/Provider.ts +0 -3
  107. package/src/exchange/error.ts +0 -10
  108. package/src/exchange/swap/getCompleteSwapHistory.ts +1 -1
  109. package/src/exchange/swap/postSwapState.ts +6 -24
  110. package/src/exchange/swap/setBroadcastTransaction.ts +2 -6
  111. package/src/exchange/swap/types.ts +0 -64
  112. package/src/families/cardano/__snapshots__/bridge.integration.test.ts.snap +0 -1
  113. package/src/families/cardano/signerSerializer.ts +2 -4
  114. package/src/families/evm/bridge/mock.ts +1 -1
  115. package/src/families/evm/platformAdapter.test.ts +1 -1
  116. package/src/families/evm/platformAdapter.ts +1 -1
  117. package/src/families/evm/react.test.ts +3 -3
  118. package/src/families/evm/react.ts +1 -1
  119. package/src/families/evm/walletApiAdapter.ts +1 -1
  120. package/src/featureFlags/defaultFeatures.ts +0 -1
  121. package/src/hw/connectManager.ts +14 -14
  122. package/src/hw/getOnboardingStatePolling.test.ts +29 -0
  123. package/src/hw/getOnboardingStatePolling.ts +2 -0
  124. package/src/mock/account.ts +0 -1
  125. package/src/wallet-api/Exchange/server.test.ts +5 -7
  126. package/src/wallet-api/Exchange/server.ts +32 -344
  127. package/src/wallet-api/useDappLogic.ts +1 -1
  128. package/lib/exchange/swap/api/v5/actions.d.ts +0 -3
  129. package/lib/exchange/swap/api/v5/actions.d.ts.map +0 -1
  130. package/lib/exchange/swap/api/v5/actions.js +0 -36
  131. package/lib/exchange/swap/api/v5/actions.js.map +0 -1
  132. package/lib/exchange/swap/transactionStrategies.d.ts +0 -25
  133. package/lib/exchange/swap/transactionStrategies.d.ts.map +0 -1
  134. package/lib/exchange/swap/transactionStrategies.js +0 -152
  135. package/lib/exchange/swap/transactionStrategies.js.map +0 -1
  136. package/lib-es/exchange/swap/api/v5/actions.d.ts +0 -3
  137. package/lib-es/exchange/swap/api/v5/actions.d.ts.map +0 -1
  138. package/lib-es/exchange/swap/api/v5/actions.js +0 -29
  139. package/lib-es/exchange/swap/api/v5/actions.js.map +0 -1
  140. package/lib-es/exchange/swap/transactionStrategies.d.ts +0 -25
  141. package/lib-es/exchange/swap/transactionStrategies.d.ts.map +0 -1
  142. package/lib-es/exchange/swap/transactionStrategies.js +0 -140
  143. package/lib-es/exchange/swap/transactionStrategies.js.map +0 -1
  144. package/src/exchange/swap/api/v5/actions.ts +0 -36
  145. package/src/exchange/swap/transactionStrategies.ts +0 -234
@@ -1,58 +1,48 @@
1
1
  /* eslint-disable no-console */
2
- import {
3
- getMainAccount,
4
- getParentAccount,
5
- makeEmptyTokenAccount,
6
- } from "@ledgerhq/coin-framework/account/index";
7
- import { findTokenById, listTokensForCryptoCurrency } from "@ledgerhq/cryptoassets";
8
- import { decodeSwapPayload } from "@ledgerhq/hw-app-exchange";
9
- import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
10
- import { Account, AccountLike, getCurrencyForAccount, TokenAccount } from "@ledgerhq/types-live";
2
+ import { RPCHandler, customWrapper } from "@ledgerhq/wallet-api-server";
11
3
  import {
12
4
  createAccountNotFound,
13
5
  createCurrencyNotFound,
14
- createUnknownError,
15
6
  deserializeTransaction,
16
7
  ServerError,
17
8
  } from "@ledgerhq/wallet-api-core";
9
+ import {
10
+ getParentAccount,
11
+ getMainAccount,
12
+ makeEmptyTokenAccount,
13
+ } from "@ledgerhq/coin-framework/account/index";
14
+ import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
15
+ import { AccountLike, getCurrencyForAccount, TokenAccount } from "@ledgerhq/types-live";
16
+ import { findTokenById, listTokensForCryptoCurrency } from "@ledgerhq/cryptoassets";
18
17
  import {
19
18
  ExchangeCompleteParams,
20
19
  ExchangeCompleteResult,
21
20
  ExchangeStartParams,
22
- ExchangeStartResult,
23
- ExchangeStartSellParams,
24
21
  ExchangeStartSwapParams,
25
- ExchangeSwapParams,
22
+ ExchangeStartResult,
26
23
  ExchangeType,
24
+ ExchangeStartSellParams,
27
25
  SwapLiveError,
28
- SwapResult,
29
26
  } from "@ledgerhq/wallet-api-exchange-module";
30
- import { customWrapper, RPCHandler } from "@ledgerhq/wallet-api-server";
31
- import { BigNumber } from "bignumber.js";
32
- import { getAccountBridge } from "../../bridge";
33
- import { retrieveSwapPayload } from "../../exchange/swap/api/v5/actions";
34
- import { transactionStrategy } from "../../exchange/swap/transactionStrategies";
35
- import { ExchangeSwap } from "../../exchange/swap/types";
36
- import { Exchange } from "../../exchange/types";
37
- import { Transaction } from "../../generated/types";
27
+ import { decodeSwapPayload } from "@ledgerhq/hw-app-exchange";
28
+ import { TrackingAPI } from "./tracking";
29
+ import { AppManifest } from "../types";
38
30
  import {
39
31
  getAccountIdFromWalletAccountId,
40
32
  getWalletAPITransactionSignFlowInfos,
41
33
  } from "../converters";
42
- import { AppManifest } from "../types";
34
+ import { getAccountBridge } from "../../bridge";
35
+ import { Exchange } from "../../exchange/types";
36
+ import { Transaction } from "../../generated/types";
43
37
  import {
38
+ ExchangeError,
44
39
  createAccounIdNotFound,
45
40
  createWrongSellParams,
46
41
  createWrongSwapParams,
47
- ExchangeError,
48
42
  } from "./error";
49
- import { TrackingAPI } from "./tracking";
50
- import { getSwapStepFromError } from "../../exchange/error";
51
- import { postSwapCancelled } from "../../exchange/swap";
52
- import { DeviceModelId } from "@ledgerhq/types-devices";
53
- import { setBroadcastTransaction } from "../../exchange/swap/setBroadcastTransaction";
54
43
 
55
44
  export { ExchangeType };
45
+ import { BigNumber } from "bignumber.js";
56
46
 
57
47
  type Handlers = {
58
48
  "custom.exchange.start": RPCHandler<
@@ -62,7 +52,6 @@ type Handlers = {
62
52
  "custom.exchange.complete": RPCHandler<ExchangeCompleteResult, ExchangeCompleteParams>;
63
53
  "custom.exchange.error": RPCHandler<void, SwapLiveError>;
64
54
  "custom.isReady": RPCHandler<void, void>;
65
- "custom.exchange.swap": RPCHandler<SwapResult, ExchangeSwapParams>;
66
55
  };
67
56
 
68
57
  export type CompleteExchangeUiRequest = {
@@ -79,33 +68,21 @@ export type CompleteExchangeUiRequest = {
79
68
  refundAddress?: string;
80
69
  payoutAddress?: string;
81
70
  };
82
- type FundStartParamsUiRequest = {
83
- exchangeType: "FUND";
84
- };
85
-
86
- type SellStartParamsUiRequest = {
87
- exchangeType: "SELL";
88
- provider: string;
89
- exchange: Partial<Exchange> | undefined;
90
- };
91
-
92
- type SwapStartParamsUiRequest = {
93
- exchangeType: "SWAP";
94
- provider: string;
95
- exchange: Partial<ExchangeSwap>;
96
- };
97
71
 
98
72
  type ExchangeStartParamsUiRequest =
99
- | FundStartParamsUiRequest
100
- | SellStartParamsUiRequest
101
- | SwapStartParamsUiRequest;
102
-
103
- export type SwapUiRequest = CompleteExchangeUiRequest & {
104
- provider?: string;
105
- fromAccountId?: string;
106
- toAccountId?: string;
107
- tokenCurrency?: string;
108
- };
73
+ | {
74
+ exchangeType: "FUND";
75
+ }
76
+ | {
77
+ exchangeType: "SELL";
78
+ provider: string;
79
+ exchange: Partial<Exchange> | undefined;
80
+ }
81
+ | {
82
+ exchangeType: "SWAP";
83
+ provider: string;
84
+ exchange: Partial<Exchange>;
85
+ };
109
86
 
110
87
  type ExchangeUiHooks = {
111
88
  "custom.exchange.start": (params: {
@@ -124,11 +101,6 @@ type ExchangeUiHooks = {
124
101
  onCancel: () => void;
125
102
  }) => void;
126
103
  "custom.isReady": (params: { onSuccess: () => void; onCancel: () => void }) => void;
127
- "custom.exchange.swap": (params: {
128
- exchangeParams: SwapUiRequest;
129
- onSuccess: ({ operationHash, swapId }: { operationHash: string; swapId: string }) => void;
130
- onCancel: (error: Error) => void;
131
- }) => void;
132
104
  };
133
105
 
134
106
  export const handlers = ({
@@ -140,7 +112,6 @@ export const handlers = ({
140
112
  "custom.exchange.complete": uiExchangeComplete,
141
113
  "custom.exchange.error": uiError,
142
114
  "custom.isReady": uiIsReady,
143
- "custom.exchange.swap": uiSwap,
144
115
  },
145
116
  }: {
146
117
  accounts: AccountLike[];
@@ -372,228 +343,6 @@ export const handlers = ({
372
343
  }),
373
344
  );
374
345
  }),
375
- "custom.exchange.swap": customWrapper<ExchangeSwapParams, SwapResult>(async params => {
376
- if (!params) {
377
- tracking.startExchangeNoParams(manifest);
378
- throw new ServerError(createUnknownError({ message: "params is undefined" }));
379
- }
380
-
381
- const {
382
- provider,
383
- fromAmount,
384
- fromAmountAtomic,
385
- quoteId,
386
- toNewTokenId,
387
- customFeeConfig,
388
- swapAppVersion,
389
- } = params;
390
-
391
- const trackingParams = {
392
- provider: params.provider,
393
- exchangeType: params.exchangeType,
394
- };
395
-
396
- tracking.startExchangeRequested(trackingParams);
397
-
398
- const exchangeStartParams: ExchangeStartParamsUiRequest = extractSwapStartParam(
399
- params,
400
- accounts,
401
- ) as SwapStartParamsUiRequest;
402
-
403
- const {
404
- fromCurrency,
405
- fromAccount,
406
- fromParentAccount,
407
- toCurrency,
408
- toAccount,
409
- toParentAccount,
410
- } = exchangeStartParams.exchange;
411
-
412
- if (!fromAccount || !fromCurrency) {
413
- throw new ServerError(createAccountNotFound(params.fromAccountId));
414
- }
415
-
416
- const fromAccountAddress = fromParentAccount
417
- ? fromParentAccount.freshAddress
418
- : (fromAccount as Account).freshAddress;
419
-
420
- const toAccountAddress = toParentAccount
421
- ? toParentAccount.freshAddress
422
- : (toAccount as Account).freshAddress;
423
-
424
- // Step 1: Open the drawer and open exchange app
425
- const startExchange = async () => {
426
- console.log("LLD custom.exchange.swap uiExchangeStart", exchangeStartParams);
427
-
428
- return new Promise<{ transactionId: string; device?: ExchangeStartResult["device"] }>(
429
- (resolve, reject) => {
430
- uiExchangeStart({
431
- exchangeParams: exchangeStartParams,
432
- onSuccess: (nonce, device) => {
433
- tracking.startExchangeSuccess(trackingParams);
434
- resolve({ transactionId: nonce, device });
435
- },
436
- onCancel: error => {
437
- tracking.startExchangeFail(trackingParams);
438
- reject(error);
439
- },
440
- });
441
- },
442
- );
443
- };
444
-
445
- const { transactionId, device: deviceInfo } = await startExchange();
446
-
447
- const {
448
- binaryPayload,
449
- signature,
450
- payinAddress,
451
- swapId,
452
- payinExtraId,
453
- extraTransactionParameters,
454
- } = await retrieveSwapPayload({
455
- provider,
456
- deviceTransactionId: transactionId,
457
- fromAccountAddress,
458
- toAccountAddress,
459
- fromAccountCurrency: fromCurrency!.id,
460
- toAccountCurrency: toCurrency!.id,
461
- amount: fromAmount,
462
- amountInAtomicUnit: fromAmountAtomic,
463
- quoteId,
464
- toNewTokenId,
465
- }).catch((error: Error) => {
466
- throw error;
467
- });
468
-
469
- // Complete Swap
470
- const trackingCompleteParams = {
471
- provider: params.provider,
472
- exchangeType: params.exchangeType,
473
- };
474
- tracking.completeExchangeRequested(trackingCompleteParams);
475
-
476
- const strategyData = {
477
- recipient: payinAddress,
478
- amount: fromAmountAtomic,
479
- currency: fromCurrency as CryptoOrTokenCurrency,
480
- customFeeConfig: customFeeConfig ?? {},
481
- payinExtraId,
482
- extraTransactionParameters,
483
- };
484
-
485
- const transaction = await getStrategy(strategyData, "swap").catch(async error => {
486
- throw error;
487
- });
488
-
489
- const mainFromAccount = getMainAccount(fromAccount, fromParentAccount);
490
- const mainFromAccountFamily = mainFromAccount.currency.family;
491
-
492
- if (transaction.family !== mainFromAccountFamily) {
493
- return Promise.reject(
494
- new Error(
495
- `Account and transaction must be from the same family. Account family: ${mainFromAccountFamily}, Transaction family: ${transaction.family}`,
496
- ),
497
- );
498
- }
499
-
500
- const accountBridge = getAccountBridge(fromAccount, fromParentAccount);
501
-
502
- /**
503
- * 'subAccountId' is used for ETH and it's ERC-20 tokens.
504
- * This field is ignored for BTC
505
- */
506
- const subAccountId =
507
- fromParentAccount && fromParentAccount.id !== fromAccount.id ? fromAccount.id : undefined;
508
-
509
- const bridgeTx = accountBridge.createTransaction(fromAccount);
510
- /**
511
- * We append the `recipient` to the tx created from `createTransaction`
512
- * to avoid having userGasLimit reset to null for ETH txs
513
- * cf. libs/ledger-live-common/src/families/ethereum/updateTransaction.ts
514
- */
515
- const tx = accountBridge.updateTransaction(
516
- {
517
- ...bridgeTx,
518
- recipient: transaction.recipient,
519
- },
520
- {
521
- ...transaction,
522
- feesStrategy: params.feeStrategy.toLowerCase(),
523
- subAccountId,
524
- },
525
- );
526
-
527
- // Get amountExpectedTo and magnitudeAwareRate from binary payload
528
- const decodePayload = await decodeSwapPayload(binaryPayload);
529
- const amountExpectedTo = new BigNumber(decodePayload.amountToWallet.toString());
530
- const magnitudeAwareRate = tx.amount && amountExpectedTo.dividedBy(tx.amount);
531
- const refundAddress = decodePayload.refundAddress;
532
- const payoutAddress = decodePayload.payoutAddress;
533
-
534
- // tx.amount should be BigNumber
535
- tx.amount = new BigNumber(tx.amount);
536
-
537
- return new Promise((resolve, reject) =>
538
- uiSwap({
539
- exchangeParams: {
540
- exchangeType: ExchangeType.SWAP,
541
- provider: params.provider,
542
- transaction: tx,
543
- signature: signature,
544
- binaryPayload: binaryPayload,
545
- exchange: {
546
- fromAccount,
547
- fromParentAccount,
548
- toAccount,
549
- toParentAccount,
550
- fromCurrency: fromCurrency!,
551
- toCurrency: toCurrency!,
552
- },
553
- feesStrategy: params.feeStrategy,
554
- swapId: swapId,
555
- amountExpectedTo: amountExpectedTo.toNumber(),
556
- magnitudeAwareRate,
557
- refundAddress,
558
- payoutAddress,
559
- },
560
- onSuccess: ({ operationHash, swapId }: { operationHash: string; swapId: string }) => {
561
- tracking.completeExchangeSuccess({
562
- ...trackingParams,
563
- currency: transaction.family,
564
- });
565
-
566
- setBroadcastTransaction({
567
- provider,
568
- result: { operation: operationHash, swapId },
569
- sourceCurrencyId: fromCurrency.id,
570
- targetCurrencyId: toCurrency?.id,
571
- hardwareWalletType: deviceInfo?.modelId as DeviceModelId,
572
- swapAppVersion,
573
- });
574
-
575
- resolve({ operationHash, swapId });
576
- },
577
- onCancel: error => {
578
- postSwapCancelled({
579
- provider: provider,
580
- swapId: swapId,
581
- swapStep: getSwapStepFromError(error),
582
- statusCode: error.name,
583
- errorMessage: error.message,
584
- sourceCurrencyId: fromCurrency.id,
585
- targetCurrencyId: toCurrency?.id,
586
- hardwareWalletType: deviceInfo?.modelId as DeviceModelId,
587
- swapType: quoteId ? "fixed" : "float",
588
- swapAppVersion,
589
- });
590
-
591
- reject(error);
592
- },
593
- }),
594
- );
595
- }),
596
-
597
346
  "custom.isReady": customWrapper<void, void>(async () => {
598
347
  return new Promise((resolve, reject) =>
599
348
  uiIsReady({
@@ -653,10 +402,8 @@ function extractSwapStartParam(
653
402
  exchange: {
654
403
  fromAccount,
655
404
  fromParentAccount,
656
- fromCurrency: getCurrencyForAccount(fromAccount),
657
405
  toAccount: newTokenAccount ? newTokenAccount : toAccount,
658
406
  toParentAccount: newTokenAccount ? toAccount : toParentAccount,
659
- toCurrency: getCurrencyForAccount(toAccount),
660
407
  },
661
408
  };
662
409
  }
@@ -721,62 +468,3 @@ async function getToCurrency(
721
468
 
722
469
  return newTokenAccount?.token ?? getCurrencyForAccount(toAccount);
723
470
  }
724
-
725
- interface StrategyParams {
726
- recipient: string;
727
- amount: BigNumber | number | string;
728
- currency: CryptoOrTokenCurrency;
729
- customFeeConfig?: Record<string, unknown>;
730
- payinExtraId?: string;
731
- extraTransactionParameters?: string;
732
- }
733
-
734
- async function getStrategy(
735
- {
736
- recipient,
737
- amount,
738
- currency,
739
- customFeeConfig,
740
- payinExtraId,
741
- extraTransactionParameters,
742
- }: StrategyParams,
743
- customErrorType?: any,
744
- ): Promise<Transaction> {
745
- const family =
746
- currency.type === "TokenCurrency"
747
- ? (currency.parentCurrency?.family as Transaction["family"])
748
- : (currency.family as Transaction["family"]);
749
-
750
- if (!family) {
751
- throw new Error(`TokenCurrency missing parentCurrency family: ${currency.id}`);
752
- }
753
-
754
- // Remove unsupported utxoStrategy for now
755
- if (customFeeConfig?.utxoStrategy) {
756
- delete customFeeConfig.utxoStrategy;
757
- }
758
-
759
- // Normalize family key for strategy lookup
760
- const familyKey = family === "evm" ? "ethereum" : family;
761
- const strategy = transactionStrategy?.[familyKey];
762
-
763
- if (!strategy) {
764
- throw new Error(`No transaction strategy found for family: ${familyKey}`);
765
- }
766
-
767
- try {
768
- return await strategy({
769
- family,
770
- amount,
771
- recipient,
772
- customFeeConfig: customFeeConfig || {},
773
- payinExtraId,
774
- extraTransactionParameters,
775
- customErrorType,
776
- });
777
- } catch (error) {
778
- throw new Error(
779
- `Failed to execute transaction strategy for family: ${familyKey}. Reason: ${(error as Error).message}`,
780
- );
781
- }
782
- }
@@ -12,7 +12,7 @@ import { findTokenByAddress, getCryptoCurrencyById } from "@ledgerhq/cryptoasset
12
12
  import { prepareMessageToSign } from "../hw/signMessage/index";
13
13
  import { CurrentAccountHistDB, UiHook, usePermission } from "./react";
14
14
  import BigNumber from "bignumber.js";
15
- import { safeEncodeEIP55 } from "@ledgerhq/coin-evm/utils";
15
+ import { safeEncodeEIP55 } from "@ledgerhq/coin-evm/logic";
16
16
  import { SmartWebsocket } from "./SmartWebsocket";
17
17
  import { stripHexPrefix } from "./helpers";
18
18
  import { getTxType } from "./utils/txTrackingHelper";
@@ -1,3 +0,0 @@
1
- import { SwapPayloadRequestData, SwapPayloadResponse } from "../../types";
2
- export declare function retrieveSwapPayload(data: SwapPayloadRequestData): Promise<SwapPayloadResponse>;
3
- //# sourceMappingURL=actions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../../src/exchange/swap/api/v5/actions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE1E,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CA6B9B"}
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.retrieveSwapPayload = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const __1 = require("../..");
9
- async function retrieveSwapPayload(data) {
10
- const SWAP_API_BASE = (0, __1.getSwapAPIBaseURL)();
11
- const swapAxiosClient = axios_1.default.create({
12
- baseURL: SWAP_API_BASE,
13
- });
14
- const request = {
15
- provider: data.provider,
16
- deviceTransactionId: data.deviceTransactionId,
17
- from: data.fromAccountCurrency,
18
- to: data.toNewTokenId || data.toAccountCurrency,
19
- address: data.toAccountAddress,
20
- refundAddress: data.fromAccountAddress,
21
- amountFrom: data.amount,
22
- amountFromInSmallestDenomination: Number(data.amountInAtomicUnit),
23
- rateId: data.quoteId,
24
- };
25
- const res = await swapAxiosClient.post(`${SWAP_API_BASE}/swap`, request);
26
- return {
27
- binaryPayload: res.data?.binaryPayload,
28
- signature: res.data?.signature,
29
- payinAddress: res.data?.payinAddress,
30
- swapId: res.data?.swapId,
31
- payinExtraId: res.data?.payinExtraId,
32
- extraTransactionParameters: res.data?.extraTransactionParameters,
33
- };
34
- }
35
- exports.retrieveSwapPayload = retrieveSwapPayload;
36
- //# sourceMappingURL=actions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../../../src/exchange/swap/api/v5/actions.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,6BAA0C;AAGnC,KAAK,UAAU,mBAAmB,CACvC,IAA4B;IAE5B,MAAM,aAAa,GAAG,IAAA,qBAAiB,GAAE,CAAC;IAE1C,MAAM,eAAe,GAAG,eAAK,CAAC,MAAM,CAAC;QACnC,OAAO,EAAE,aAAa;KACvB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG;QACd,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;QAC7C,IAAI,EAAE,IAAI,CAAC,mBAAmB;QAC9B,EAAE,EAAE,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,iBAAiB;QAC/C,OAAO,EAAE,IAAI,CAAC,gBAAgB;QAC9B,aAAa,EAAE,IAAI,CAAC,kBAAkB;QACtC,UAAU,EAAE,IAAI,CAAC,MAAM;QACvB,gCAAgC,EAAE,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC;QACjE,MAAM,EAAE,IAAI,CAAC,OAAO;KACrB,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,GAAG,aAAa,OAAO,EAAE,OAAO,CAAC,CAAC;IAEzE,OAAO;QACL,aAAa,EAAE,GAAG,CAAC,IAAI,EAAE,aAAa;QACtC,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE,SAAS;QAC9B,YAAY,EAAE,GAAG,CAAC,IAAI,EAAE,YAAY;QACpC,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM;QACxB,YAAY,EAAE,GAAG,CAAC,IAAI,EAAE,YAAY;QACpC,0BAA0B,EAAE,GAAG,CAAC,IAAI,EAAE,0BAA0B;KACjE,CAAC;AACJ,CAAC;AA/BD,kDA+BC"}
@@ -1,25 +0,0 @@
1
- import { BigNumber } from "bignumber.js";
2
- import { CosmosTransaction, ElrondTransaction, RippleTransaction, SolanaTransaction, StellarTransaction, Transaction, TransactionCommon } from "@ledgerhq/wallet-api-client";
3
- export type { SwapLiveError } from "@ledgerhq/wallet-api-exchange-module";
4
- export declare function defaultTransaction({ family, amount, recipient, customFeeConfig, }: TransactionWithCustomFee): Transaction;
5
- export declare function modeSendTransaction({ family, amount, recipient, customFeeConfig, }: TransactionWithCustomFee): Transaction;
6
- export declare function stellarTransaction({ family, amount, recipient, customFeeConfig, payinExtraId, customErrorType, }: TransactionWithCustomFee): StellarTransaction;
7
- export declare function rippleTransaction({ amount, recipient, customFeeConfig, payinExtraId, customErrorType, }: TransactionWithCustomFee): RippleTransaction;
8
- export declare function withoutGasLimitTransaction({ family, amount, recipient, customFeeConfig, extraTransactionParameters, }: TransactionWithCustomFee): Transaction;
9
- export declare function bitcoinTransaction({ amount, recipient, customFeeConfig, extraTransactionParameters, }: TransactionWithCustomFee): Transaction;
10
- export declare function solanaTransaction({ family, amount, recipient, customFeeConfig, }: TransactionWithCustomFee): SolanaTransaction;
11
- export declare function elrondTransaction({ amount, recipient, customFeeConfig, }: TransactionWithCustomFee): ElrondTransaction;
12
- export declare function cosmosTransaction({ family, amount, recipient, customFeeConfig, payinExtraId, }: TransactionWithCustomFee): CosmosTransaction;
13
- export type TransactionWithCustomFee = TransactionCommon & {
14
- customFeeConfig: {
15
- [key: string]: BigNumber;
16
- };
17
- payinExtraId?: string;
18
- customErrorType?: "swap";
19
- extraTransactionParameters?: string;
20
- };
21
- export type TransactionStrategyFunction = (params: TransactionWithCustomFee) => Transaction;
22
- export declare const transactionStrategy: {
23
- [K in Transaction["family"]]: TransactionStrategyFunction;
24
- };
25
- //# sourceMappingURL=transactionStrategies.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transactionStrategies.d.ts","sourceRoot":"","sources":["../../../src/exchange/swap/transactionStrategies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAElB,WAAW,EACX,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAErC,YAAY,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAE1E,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,MAAM,EACN,SAAS,EACT,eAAe,GAChB,EAAE,wBAAwB,GAAG,WAAW,CAOxC;AAED,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,MAAM,EACN,SAAS,EACT,eAAe,GAChB,EAAE,wBAAwB,GAAG,WAAW,CAKxC;AAED,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,MAAM,EACN,SAAS,EACT,eAAe,EACf,YAAY,EACZ,eAAe,GAChB,EAAE,wBAAwB,GAAG,kBAAkB,CAc/C;AAED,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,SAAS,EACT,eAAe,EACf,YAAY,EACZ,eAAe,GAChB,EAAE,wBAAwB,GAAG,iBAAiB,CAgB9C;AAGD,wBAAgB,0BAA0B,CAAC,EACzC,MAAM,EACN,MAAM,EACN,SAAS,EACT,eAAe,EACf,0BAA0B,GAC3B,EAAE,wBAAwB,GAAG,WAAW,CAexC;AAED,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,SAAS,EACT,eAAe,EACf,0BAA0B,GAC3B,EAAE,wBAAwB,GAAG,WAAW,CAgBxC;AAED,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,MAAM,EACN,SAAS,EACT,eAAe,GAChB,EAAE,wBAAwB,GAAG,iBAAiB,CAM9C;AAED,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,SAAS,EACT,eAAe,GAChB,EAAE,wBAAwB,GAAG,iBAAiB,CAU9C;AAgBD,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,MAAM,EACN,SAAS,EACT,eAAe,EACf,YAAY,GACb,EAAE,wBAAwB,GAAG,iBAAiB,CAO9C;AAED,MAAM,MAAM,wBAAwB,GAAG,iBAAiB,GAAG;IACzD,eAAe,EAAE;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;KAC1B,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC,CAAC;AAGF,MAAM,MAAM,2BAA2B,GAAG,CAAC,MAAM,EAAE,wBAAwB,KAAK,WAAW,CAAC;AAE5F,eAAO,MAAM,mBAAmB,EAAE;KAC/B,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,2BAA2B;CA2B1D,CAAC"}