@ledgerhq/live-common 34.44.0 → 34.45.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 (143) hide show
  1. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +3 -1
  2. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
  3. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js +6 -0
  4. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
  5. package/lib/device/use-cases/listAppsUseCase.test.js +2 -2
  6. package/lib/device/use-cases/listAppsUseCase.test.js.map +1 -1
  7. package/lib/deviceSDK/tasks/core.d.ts +1 -0
  8. package/lib/deviceSDK/tasks/core.d.ts.map +1 -1
  9. package/lib/deviceSDK/tasks/core.js +3 -2
  10. package/lib/deviceSDK/tasks/core.js.map +1 -1
  11. package/lib/e2e/index.d.ts +3 -0
  12. package/lib/e2e/index.d.ts.map +1 -1
  13. package/lib/env.react.d.ts +1 -1
  14. package/lib/env.react.d.ts.map +1 -1
  15. package/lib/exchange/index.d.ts.map +1 -1
  16. package/lib/exchange/index.js +1 -0
  17. package/lib/exchange/index.js.map +1 -1
  18. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +22 -10
  19. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -1
  20. package/lib/exchange/swap/hooks/wrapper.d.ts +3 -0
  21. package/lib/exchange/swap/hooks/wrapper.d.ts.map +1 -0
  22. package/lib/exchange/swap/hooks/wrapper.js +40 -0
  23. package/lib/exchange/swap/hooks/wrapper.js.map +1 -0
  24. package/lib/exchange/swap/postSwapState.d.ts.map +1 -1
  25. package/lib/exchange/swap/postSwapState.js +63 -4
  26. package/lib/exchange/swap/postSwapState.js.map +1 -1
  27. package/lib/exchange/swap/setBroadcastTransaction.d.ts +4 -1
  28. package/lib/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
  29. package/lib/exchange/swap/setBroadcastTransaction.js +7 -1
  30. package/lib/exchange/swap/setBroadcastTransaction.js.map +1 -1
  31. package/lib/exchange/swap/types.d.ts +7 -0
  32. package/lib/exchange/swap/types.d.ts.map +1 -1
  33. package/lib/families/evm/config.d.ts.map +1 -1
  34. package/lib/families/evm/config.js +8 -2
  35. package/lib/families/evm/config.js.map +1 -1
  36. package/lib/families/stellar/ui.d.ts.map +1 -1
  37. package/lib/families/stellar/ui.js +8 -2
  38. package/lib/families/stellar/ui.js.map +1 -1
  39. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  40. package/lib/featureFlags/defaultFeatures.js +1 -0
  41. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  42. package/lib/featureFlags/useFeature.d.ts +1 -1
  43. package/lib/featureFlags/useFeature.d.ts.map +1 -1
  44. package/lib/hw/customLockScreenLoad.d.ts +1 -9
  45. package/lib/hw/customLockScreenLoad.d.ts.map +1 -1
  46. package/lib/hw/customLockScreenLoad.js +5 -1
  47. package/lib/hw/customLockScreenLoad.js.map +1 -1
  48. package/lib/hw/hooks/useGenuineCheck.d.ts +2 -1
  49. package/lib/hw/hooks/useGenuineCheck.d.ts.map +1 -1
  50. package/lib/hw/hooks/useGenuineCheck.js +10 -2
  51. package/lib/hw/hooks/useGenuineCheck.js.map +1 -1
  52. package/lib/modularDrawer/utils/getBalanceAndFiatValue.d.ts +20 -0
  53. package/lib/modularDrawer/utils/getBalanceAndFiatValue.d.ts.map +1 -0
  54. package/lib/modularDrawer/utils/getBalanceAndFiatValue.js +39 -0
  55. package/lib/modularDrawer/utils/getBalanceAndFiatValue.js.map +1 -0
  56. package/lib/modularDrawer/utils/index.d.ts +2 -1
  57. package/lib/modularDrawer/utils/index.d.ts.map +1 -1
  58. package/lib/modularDrawer/utils/index.js +3 -1
  59. package/lib/modularDrawer/utils/index.js.map +1 -1
  60. package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
  61. package/lib/wallet-api/Exchange/server.js +10 -0
  62. package/lib/wallet-api/Exchange/server.js.map +1 -1
  63. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +3 -1
  64. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
  65. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js +6 -0
  66. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
  67. package/lib-es/device/use-cases/listAppsUseCase.test.js +1 -1
  68. package/lib-es/device/use-cases/listAppsUseCase.test.js.map +1 -1
  69. package/lib-es/deviceSDK/tasks/core.d.ts +1 -0
  70. package/lib-es/deviceSDK/tasks/core.d.ts.map +1 -1
  71. package/lib-es/deviceSDK/tasks/core.js +1 -1
  72. package/lib-es/deviceSDK/tasks/core.js.map +1 -1
  73. package/lib-es/e2e/index.d.ts +3 -0
  74. package/lib-es/e2e/index.d.ts.map +1 -1
  75. package/lib-es/env.react.d.ts +1 -1
  76. package/lib-es/env.react.d.ts.map +1 -1
  77. package/lib-es/exchange/index.d.ts.map +1 -1
  78. package/lib-es/exchange/index.js +1 -0
  79. package/lib-es/exchange/index.js.map +1 -1
  80. package/lib-es/exchange/swap/hooks/usePickDefaultAccount.test.js +21 -9
  81. package/lib-es/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -1
  82. package/lib-es/exchange/swap/hooks/wrapper.d.ts +3 -0
  83. package/lib-es/exchange/swap/hooks/wrapper.d.ts.map +1 -0
  84. package/lib-es/exchange/swap/hooks/wrapper.js +13 -0
  85. package/lib-es/exchange/swap/hooks/wrapper.js.map +1 -0
  86. package/lib-es/exchange/swap/postSwapState.d.ts.map +1 -1
  87. package/lib-es/exchange/swap/postSwapState.js +63 -4
  88. package/lib-es/exchange/swap/postSwapState.js.map +1 -1
  89. package/lib-es/exchange/swap/setBroadcastTransaction.d.ts +4 -1
  90. package/lib-es/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
  91. package/lib-es/exchange/swap/setBroadcastTransaction.js +7 -1
  92. package/lib-es/exchange/swap/setBroadcastTransaction.js.map +1 -1
  93. package/lib-es/exchange/swap/types.d.ts +7 -0
  94. package/lib-es/exchange/swap/types.d.ts.map +1 -1
  95. package/lib-es/families/evm/config.d.ts.map +1 -1
  96. package/lib-es/families/evm/config.js +8 -2
  97. package/lib-es/families/evm/config.js.map +1 -1
  98. package/lib-es/families/stellar/ui.d.ts.map +1 -1
  99. package/lib-es/families/stellar/ui.js +8 -2
  100. package/lib-es/families/stellar/ui.js.map +1 -1
  101. package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
  102. package/lib-es/featureFlags/defaultFeatures.js +1 -0
  103. package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
  104. package/lib-es/featureFlags/useFeature.d.ts +1 -1
  105. package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
  106. package/lib-es/hw/customLockScreenLoad.d.ts +1 -9
  107. package/lib-es/hw/customLockScreenLoad.d.ts.map +1 -1
  108. package/lib-es/hw/customLockScreenLoad.js +5 -1
  109. package/lib-es/hw/customLockScreenLoad.js.map +1 -1
  110. package/lib-es/hw/hooks/useGenuineCheck.d.ts +2 -1
  111. package/lib-es/hw/hooks/useGenuineCheck.d.ts.map +1 -1
  112. package/lib-es/hw/hooks/useGenuineCheck.js +10 -2
  113. package/lib-es/hw/hooks/useGenuineCheck.js.map +1 -1
  114. package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.d.ts +20 -0
  115. package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.d.ts.map +1 -0
  116. package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.js +32 -0
  117. package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.js.map +1 -0
  118. package/lib-es/modularDrawer/utils/index.d.ts +2 -1
  119. package/lib-es/modularDrawer/utils/index.d.ts.map +1 -1
  120. package/lib-es/modularDrawer/utils/index.js +2 -1
  121. package/lib-es/modularDrawer/utils/index.js.map +1 -1
  122. package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
  123. package/lib-es/wallet-api/Exchange/server.js +10 -0
  124. package/lib-es/wallet-api/Exchange/server.js.map +1 -1
  125. package/package.json +73 -73
  126. package/src/bridge/generic-alpaca/alpaca/network/network-alpaca.ts +10 -0
  127. package/src/device/use-cases/listAppsUseCase.test.ts +1 -1
  128. package/src/deviceSDK/tasks/core.ts +1 -1
  129. package/src/exchange/index.ts +1 -0
  130. package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +25 -12
  131. package/src/exchange/swap/hooks/wrapper.tsx +18 -0
  132. package/src/exchange/swap/postSwapState.ts +97 -2
  133. package/src/exchange/swap/setBroadcastTransaction.ts +12 -0
  134. package/src/exchange/swap/types.ts +7 -0
  135. package/src/families/evm/config.ts +8 -2
  136. package/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +283 -3
  137. package/src/families/stellar/ui.ts +10 -3
  138. package/src/featureFlags/defaultFeatures.ts +1 -0
  139. package/src/hw/customLockScreenLoad.ts +7 -11
  140. package/src/hw/hooks/useGenuineCheck.ts +15 -4
  141. package/src/modularDrawer/utils/getBalanceAndFiatValue.ts +53 -0
  142. package/src/modularDrawer/utils/index.ts +7 -1
  143. package/src/wallet-api/Exchange/server.ts +10 -0
@@ -7,6 +7,8 @@ import type {
7
7
  GetGenuineCheckFromDeviceIdResult,
8
8
  GetGenuineCheckFromDeviceIdOutput,
9
9
  } from "../getGenuineCheckFromDeviceId";
10
+ import { isDmkError } from "../../deviceSDK/tasks/core";
11
+ import { DmkError } from "@ledgerhq/device-management-kit";
10
12
 
11
13
  export type GenuineState = "unchecked" | "genuine" | "non-genuine";
12
14
  export type DevicePermissionState =
@@ -33,7 +35,7 @@ export type UseGenuineCheckDependencies = {
33
35
  export type UseGenuineCheckResult = {
34
36
  genuineState: GenuineState;
35
37
  devicePermissionState: DevicePermissionState;
36
- error: Error | null;
38
+ error: Error | DmkError | null;
37
39
  resetGenuineCheckState: () => void;
38
40
  };
39
41
 
@@ -46,6 +48,9 @@ const clearTimeoutRef = (timeoutRef: MutableRefObject<NodeJS.Timeout | null>) =>
46
48
  }
47
49
  };
48
50
 
51
+ const isDmkDeviceDisconnectedError = (e: unknown): e is DmkError =>
52
+ isDmkError(e) && e._tag === "DeviceDisconnectedWhileSendingError";
53
+
49
54
  /**
50
55
  * Hook to check that a device is genuine
51
56
  * It replaces a DeviceAction if we're only interested in getting the genuine check
@@ -71,7 +76,7 @@ export const useGenuineCheck = ({
71
76
  const [genuineState, setGenuineState] = useState<GenuineState>("unchecked");
72
77
  const [devicePermissionState, setDevicePermissionState] =
73
78
  useState<DevicePermissionState>("unrequested");
74
- const [error, setError] = useState<Error | null>(null);
79
+ const [error, setError] = useState<Error | DmkError | null>(null);
75
80
  const timeoutRef = useRef<NodeJS.Timeout | null>(null);
76
81
 
77
82
  const resetGenuineCheckState = useCallback(() => {
@@ -126,7 +131,7 @@ export const useGenuineCheck = ({
126
131
  clearTimeoutRef(timeoutRef);
127
132
  if (e instanceof UserRefusedAllowManager) {
128
133
  setDevicePermissionState("refused");
129
- } else if (e instanceof Error) {
134
+ } else if (e instanceof Error || isDmkDeviceDisconnectedError(e)) {
130
135
  // Probably an error of type DisconnectedDeviceDuringOperation or something else
131
136
  setError(e);
132
137
  } else {
@@ -138,7 +143,13 @@ export const useGenuineCheck = ({
138
143
  return () => {
139
144
  sub.unsubscribe();
140
145
  };
141
- }, [isHookEnabled, deviceId, lockedDeviceTimeoutMs, getGenuineCheckFromDeviceId]);
146
+ }, [
147
+ isHookEnabled,
148
+ deviceId,
149
+ lockedDeviceTimeoutMs,
150
+ getGenuineCheckFromDeviceId,
151
+ permissionTimeoutMs,
152
+ ]);
142
153
 
143
154
  return {
144
155
  genuineState,
@@ -0,0 +1,53 @@
1
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
2
+ import { isAccount } from "@ledgerhq/coin-framework/account/helpers";
3
+ import {
4
+ getPortfolioCount,
5
+ getBalanceHistoryWithCountervalue,
6
+ } from "@ledgerhq/live-countervalues/portfolio";
7
+ import type { CounterValuesState } from "@ledgerhq/live-countervalues/types";
8
+ import { Currency } from "@ledgerhq/types-cryptoassets";
9
+ import { Account, TokenAccount } from "@ledgerhq/types-live";
10
+ import BigNumber from "bignumber.js";
11
+
12
+ /**
13
+ *
14
+ * @param account - The account to get the balance and fiat value for
15
+ * @param state - The current state of countervalues
16
+ * @param toCurrency - The currency to convert to
17
+ * @param discreet - Whether to show the balance in discreet mode
18
+ * @param showCode - Whether to show the currency code in the formatted balance
19
+ * @returns An object containing the balance and fiat value
20
+ */
21
+ export const getBalanceAndFiatValue = (
22
+ account: Account | TokenAccount,
23
+ state: CounterValuesState,
24
+ toCurrency: Currency,
25
+ discreet: boolean = false,
26
+ showCode: boolean = true,
27
+ ) => {
28
+ const isAnAccount = isAccount(account);
29
+ const details = isAnAccount ? account.currency : account.token;
30
+ const balance = formatCurrencyUnit(details.units[0], account.balance, {
31
+ showCode,
32
+ discreet,
33
+ });
34
+
35
+ const count = getPortfolioCount([account], "day");
36
+ const { history, countervalueAvailable } = getBalanceHistoryWithCountervalue(
37
+ account,
38
+ "day",
39
+ count,
40
+ state,
41
+ toCurrency,
42
+ );
43
+
44
+ if (!countervalueAvailable) return { balance, fiatValue: undefined };
45
+
46
+ const { countervalue } = history[history.length - 1] ?? {};
47
+ const fiatValue = formatCurrencyUnit(toCurrency.units[0], BigNumber(countervalue ?? 0), {
48
+ showCode,
49
+ discreet,
50
+ });
51
+
52
+ return { balance, fiatValue };
53
+ };
@@ -1,6 +1,7 @@
1
1
  import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
2
2
  import { CurrenciesByProviderId } from "../../deposit/type";
3
3
  import { haveOneCommonProvider } from "./haveOneCommonProvider";
4
+ import { getBalanceAndFiatValue } from "./getBalanceAndFiatValue";
4
5
 
5
6
  function isCorrespondingCurrency(
6
7
  elem: CryptoOrTokenCurrency,
@@ -27,4 +28,9 @@ const getEffectiveCurrency = (
27
28
  return provider.currenciesByNetwork.find(elem => currencyIds.includes(elem.id)) ?? currency;
28
29
  };
29
30
 
30
- export { isCorrespondingCurrency, getEffectiveCurrency, haveOneCommonProvider };
31
+ export {
32
+ isCorrespondingCurrency,
33
+ getEffectiveCurrency,
34
+ haveOneCommonProvider,
35
+ getBalanceAndFiatValue,
36
+ };
@@ -571,6 +571,9 @@ export const handlers = ({
571
571
  targetCurrencyId: toCurrency?.id,
572
572
  hardwareWalletType: deviceInfo?.modelId as DeviceModelId,
573
573
  swapAppVersion,
574
+ fromAccountId: fromAccount.id,
575
+ toAccountId: toAccount?.id,
576
+ amount: amountExpectedTo.toString(),
574
577
  });
575
578
 
576
579
  resolve({ operationHash, swapId });
@@ -587,6 +590,13 @@ export const handlers = ({
587
590
  hardwareWalletType: deviceInfo?.modelId as DeviceModelId,
588
591
  swapType: quoteId ? "fixed" : "float",
589
592
  swapAppVersion,
593
+ fromAccountId: fromAccount.id,
594
+ toAccountId: toAccount?.id,
595
+ refundAddress,
596
+ payoutAddress,
597
+ amount: amountExpectedTo.toString(),
598
+ seedIdFrom: mainFromAccount.seedIdentifier,
599
+ seedIdTo: toParentAccount?.seedIdentifier || (toAccount as Account)?.seedIdentifier,
590
600
  });
591
601
 
592
602
  reject(error);