@ledgerhq/live-common 33.3.0 → 33.4.0-next.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 (153) hide show
  1. package/lib/deposit/api.d.ts.map +1 -1
  2. package/lib/deposit/api.js.map +1 -1
  3. package/lib/deposit/deposit.integration.test.d.ts +2 -0
  4. package/lib/deposit/deposit.integration.test.d.ts.map +1 -0
  5. package/lib/deposit/deposit.integration.test.js +22 -0
  6. package/lib/deposit/deposit.integration.test.js.map +1 -0
  7. package/lib/deposit/deposit.test.js +2 -2
  8. package/lib/deposit/deposit.test.js.map +1 -1
  9. package/lib/deposit/helper.d.ts +5 -5
  10. package/lib/deposit/helper.d.ts.map +1 -1
  11. package/lib/deposit/helper.js +45 -13
  12. package/lib/deposit/helper.js.map +1 -1
  13. package/lib/deposit/type.d.ts +4 -0
  14. package/lib/deposit/type.d.ts.map +1 -1
  15. package/lib/deposit/useGroupedCurrenciesByProvider.hook.d.ts +2 -6
  16. package/lib/deposit/useGroupedCurrenciesByProvider.hook.d.ts.map +1 -1
  17. package/lib/deposit/useGroupedCurrenciesByProvider.hook.js +10 -31
  18. package/lib/deposit/useGroupedCurrenciesByProvider.hook.js.map +1 -1
  19. package/lib/deviceSDK/hooks/useBatteryStatuses.d.ts +2 -2
  20. package/lib/deviceSDK/hooks/useBatteryStatuses.d.ts.map +1 -1
  21. package/lib/deviceSDK/hooks/useBatteryStatuses.js +4 -1
  22. package/lib/deviceSDK/hooks/useBatteryStatuses.js.map +1 -1
  23. package/lib/deviceSDK/hooks/useBatteryStatuses.test.d.ts +2 -0
  24. package/lib/deviceSDK/hooks/useBatteryStatuses.test.d.ts.map +1 -0
  25. package/lib/deviceSDK/hooks/useBatteryStatuses.test.js +20 -0
  26. package/lib/deviceSDK/hooks/useBatteryStatuses.test.js.map +1 -0
  27. package/lib/exchange/swap/hooks/index.d.ts +1 -1
  28. package/lib/exchange/swap/hooks/index.d.ts.map +1 -1
  29. package/lib/exchange/swap/hooks/index.js +1 -1
  30. package/lib/exchange/swap/hooks/index.js.map +1 -1
  31. package/lib/exchange/swap/hooks/live-app-migration/useIsCurrencySupported.d.ts +12 -0
  32. package/lib/exchange/swap/hooks/live-app-migration/useIsCurrencySupported.d.ts.map +1 -0
  33. package/lib/exchange/swap/hooks/live-app-migration/useIsCurrencySupported.js +18 -0
  34. package/lib/exchange/swap/hooks/live-app-migration/useIsCurrencySupported.js.map +1 -0
  35. package/lib/exchange/swap/hooks/{useIsSwapLiveApp.d.ts → live-app-migration/useIsSwapLiveApp.d.ts} +4 -1
  36. package/lib/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.d.ts.map +1 -0
  37. package/lib/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.js +27 -0
  38. package/lib/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.js.map +1 -0
  39. package/lib/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.test.d.ts.map +1 -0
  40. package/lib/exchange/swap/hooks/{useIsSwapLiveApp.test.js → live-app-migration/useIsSwapLiveApp.test.js} +12 -12
  41. package/lib/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.test.js.map +1 -0
  42. package/lib/exchange/swap/index.js +1 -1
  43. package/lib/exchange/swap/index.js.map +1 -1
  44. package/lib/families/cardano/hw-getAddress.js +5 -5
  45. package/lib/families/cardano/hw-getAddress.js.map +1 -1
  46. package/lib/families/cardano/js-synchronisation.js +4 -4
  47. package/lib/families/cardano/js-synchronisation.js.map +1 -1
  48. package/lib/families/cardano/logic.js +4 -4
  49. package/lib/families/cardano/logic.js.map +1 -1
  50. package/lib/families/cardano/specs.d.ts.map +1 -1
  51. package/lib/families/cardano/specs.js +31 -34
  52. package/lib/families/cardano/specs.js.map +1 -1
  53. package/lib/families/cardano/speculos-deviceActions.d.ts.map +1 -1
  54. package/lib/families/cardano/speculos-deviceActions.js +17 -18
  55. package/lib/families/cardano/speculos-deviceActions.js.map +1 -1
  56. package/lib/families/cardano/tx-helpers.js +8 -8
  57. package/lib/families/cardano/tx-helpers.js.map +1 -1
  58. package/lib/postOnboarding/hooks/useStartPostOnboardingCallback.d.ts.map +1 -1
  59. package/lib/postOnboarding/hooks/useStartPostOnboardingCallback.js +1 -0
  60. package/lib/postOnboarding/hooks/useStartPostOnboardingCallback.js.map +1 -1
  61. package/lib-es/deposit/api.d.ts.map +1 -1
  62. package/lib-es/deposit/api.js.map +1 -1
  63. package/lib-es/deposit/deposit.integration.test.d.ts +2 -0
  64. package/lib-es/deposit/deposit.integration.test.d.ts.map +1 -0
  65. package/lib-es/deposit/deposit.integration.test.js +20 -0
  66. package/lib-es/deposit/deposit.integration.test.js.map +1 -0
  67. package/lib-es/deposit/deposit.test.js +2 -2
  68. package/lib-es/deposit/deposit.test.js.map +1 -1
  69. package/lib-es/deposit/helper.d.ts +5 -5
  70. package/lib-es/deposit/helper.d.ts.map +1 -1
  71. package/lib-es/deposit/helper.js +45 -15
  72. package/lib-es/deposit/helper.js.map +1 -1
  73. package/lib-es/deposit/type.d.ts +4 -0
  74. package/lib-es/deposit/type.d.ts.map +1 -1
  75. package/lib-es/deposit/useGroupedCurrenciesByProvider.hook.d.ts +2 -6
  76. package/lib-es/deposit/useGroupedCurrenciesByProvider.hook.d.ts.map +1 -1
  77. package/lib-es/deposit/useGroupedCurrenciesByProvider.hook.js +13 -34
  78. package/lib-es/deposit/useGroupedCurrenciesByProvider.hook.js.map +1 -1
  79. package/lib-es/deviceSDK/hooks/useBatteryStatuses.d.ts +2 -2
  80. package/lib-es/deviceSDK/hooks/useBatteryStatuses.d.ts.map +1 -1
  81. package/lib-es/deviceSDK/hooks/useBatteryStatuses.js +4 -1
  82. package/lib-es/deviceSDK/hooks/useBatteryStatuses.js.map +1 -1
  83. package/lib-es/deviceSDK/hooks/useBatteryStatuses.test.d.ts +2 -0
  84. package/lib-es/deviceSDK/hooks/useBatteryStatuses.test.d.ts.map +1 -0
  85. package/lib-es/deviceSDK/hooks/useBatteryStatuses.test.js +18 -0
  86. package/lib-es/deviceSDK/hooks/useBatteryStatuses.test.js.map +1 -0
  87. package/lib-es/exchange/swap/hooks/index.d.ts +1 -1
  88. package/lib-es/exchange/swap/hooks/index.d.ts.map +1 -1
  89. package/lib-es/exchange/swap/hooks/index.js +1 -1
  90. package/lib-es/exchange/swap/hooks/index.js.map +1 -1
  91. package/lib-es/exchange/swap/hooks/live-app-migration/useIsCurrencySupported.d.ts +12 -0
  92. package/lib-es/exchange/swap/hooks/live-app-migration/useIsCurrencySupported.d.ts.map +1 -0
  93. package/lib-es/exchange/swap/hooks/live-app-migration/useIsCurrencySupported.js +14 -0
  94. package/lib-es/exchange/swap/hooks/live-app-migration/useIsCurrencySupported.js.map +1 -0
  95. package/lib-es/exchange/swap/hooks/{useIsSwapLiveApp.d.ts → live-app-migration/useIsSwapLiveApp.d.ts} +4 -1
  96. package/lib-es/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.d.ts.map +1 -0
  97. package/lib-es/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.js +23 -0
  98. package/lib-es/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.js.map +1 -0
  99. package/lib-es/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.test.d.ts.map +1 -0
  100. package/lib-es/exchange/swap/hooks/{useIsSwapLiveApp.test.js → live-app-migration/useIsSwapLiveApp.test.js} +12 -12
  101. package/lib-es/exchange/swap/hooks/live-app-migration/useIsSwapLiveApp.test.js.map +1 -0
  102. package/lib-es/exchange/swap/index.js +1 -1
  103. package/lib-es/exchange/swap/index.js.map +1 -1
  104. package/lib-es/families/cardano/hw-getAddress.js +1 -1
  105. package/lib-es/families/cardano/hw-getAddress.js.map +1 -1
  106. package/lib-es/families/cardano/js-synchronisation.js +1 -1
  107. package/lib-es/families/cardano/js-synchronisation.js.map +1 -1
  108. package/lib-es/families/cardano/logic.js +1 -1
  109. package/lib-es/families/cardano/logic.js.map +1 -1
  110. package/lib-es/families/cardano/specs.d.ts.map +1 -1
  111. package/lib-es/families/cardano/specs.js +31 -34
  112. package/lib-es/families/cardano/specs.js.map +1 -1
  113. package/lib-es/families/cardano/speculos-deviceActions.d.ts.map +1 -1
  114. package/lib-es/families/cardano/speculos-deviceActions.js +17 -18
  115. package/lib-es/families/cardano/speculos-deviceActions.js.map +1 -1
  116. package/lib-es/families/cardano/tx-helpers.js +1 -1
  117. package/lib-es/families/cardano/tx-helpers.js.map +1 -1
  118. package/lib-es/postOnboarding/hooks/useStartPostOnboardingCallback.d.ts.map +1 -1
  119. package/lib-es/postOnboarding/hooks/useStartPostOnboardingCallback.js +2 -1
  120. package/lib-es/postOnboarding/hooks/useStartPostOnboardingCallback.js.map +1 -1
  121. package/package.json +5 -5
  122. package/src/deposit/api.ts +0 -1
  123. package/src/deposit/deposit.integration.test.ts +11 -0
  124. package/src/deposit/deposit.test.ts +2 -3
  125. package/src/deposit/helper.ts +41 -19
  126. package/src/deposit/type.ts +5 -0
  127. package/src/deposit/useGroupedCurrenciesByProvider.hook.ts +15 -34
  128. package/src/deviceSDK/hooks/useBatteryStatuses.test.ts +9 -0
  129. package/src/deviceSDK/hooks/useBatteryStatuses.ts +7 -3
  130. package/src/exchange/swap/hooks/index.ts +1 -1
  131. package/src/exchange/swap/hooks/live-app-migration/useIsCurrencySupported.ts +32 -0
  132. package/src/exchange/swap/hooks/{useIsSwapLiveApp.test.ts → live-app-migration/useIsSwapLiveApp.test.ts} +12 -12
  133. package/src/exchange/swap/hooks/{useIsSwapLiveApp.ts → live-app-migration/useIsSwapLiveApp.ts} +14 -11
  134. package/src/exchange/swap/index.ts +1 -1
  135. package/src/families/cardano/hw-getAddress.ts +1 -1
  136. package/src/families/cardano/js-synchronisation.ts +1 -1
  137. package/src/families/cardano/logic.ts +1 -1
  138. package/src/families/cardano/specs.ts +42 -45
  139. package/src/families/cardano/speculos-deviceActions.ts +17 -18
  140. package/src/families/cardano/tx-helpers.ts +1 -1
  141. package/src/postOnboarding/hooks/useStartPostOnboardingCallback.ts +2 -1
  142. package/lib/exchange/swap/hooks/useIsSwapLiveApp.d.ts.map +0 -1
  143. package/lib/exchange/swap/hooks/useIsSwapLiveApp.js +0 -24
  144. package/lib/exchange/swap/hooks/useIsSwapLiveApp.js.map +0 -1
  145. package/lib/exchange/swap/hooks/useIsSwapLiveApp.test.d.ts.map +0 -1
  146. package/lib/exchange/swap/hooks/useIsSwapLiveApp.test.js.map +0 -1
  147. package/lib-es/exchange/swap/hooks/useIsSwapLiveApp.d.ts.map +0 -1
  148. package/lib-es/exchange/swap/hooks/useIsSwapLiveApp.js +0 -20
  149. package/lib-es/exchange/swap/hooks/useIsSwapLiveApp.js.map +0 -1
  150. package/lib-es/exchange/swap/hooks/useIsSwapLiveApp.test.d.ts.map +0 -1
  151. package/lib-es/exchange/swap/hooks/useIsSwapLiveApp.test.js.map +0 -1
  152. /package/lib/exchange/swap/hooks/{useIsSwapLiveApp.test.d.ts → live-app-migration/useIsSwapLiveApp.test.d.ts} +0 -0
  153. /package/lib-es/exchange/swap/hooks/{useIsSwapLiveApp.test.d.ts → live-app-migration/useIsSwapLiveApp.test.d.ts} +0 -0
@@ -1,38 +1,60 @@
1
1
  import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
2
- import { MappedAsset, CurrenciesByProviderId } from "./type";
2
+ import { MappedAsset, CurrenciesByProviderId, GroupedCurrencies } from "./type";
3
+ import { currenciesByMarketcap } from "../currencies";
4
+ import { getMappedAssets } from "./api";
3
5
 
4
- const groupCurrenciesByProvider = (
6
+ export const loadCurrenciesByProvider = async (
7
+ coinsAndTokensSupported: CryptoOrTokenCurrency[],
8
+ ): Promise<GroupedCurrencies> => {
9
+ const [sortedCurrenciesSupported, assets] = await Promise.all([
10
+ currenciesByMarketcap(coinsAndTokensSupported),
11
+ getMappedAssets(),
12
+ ]);
13
+ return groupCurrenciesByProvider(assets, sortedCurrenciesSupported);
14
+ };
15
+
16
+ export const groupCurrenciesByProvider = (
5
17
  assets: MappedAsset[],
6
- currenciesSupported: CryptoOrTokenCurrency[],
7
- ) => {
8
- const assetsByLedgerId: Record<string, MappedAsset> = {};
18
+ sortedCurrencies: CryptoOrTokenCurrency[],
19
+ ): GroupedCurrencies => {
20
+ const assetsByLedgerId: Map<string, MappedAsset> = new Map();
9
21
  for (const asset of assets) {
10
- assetsByLedgerId[asset.ledgerId.toLowerCase()] = asset;
22
+ /// FIXME(LIVE-10508) drop usage of toLowerCase
23
+ assetsByLedgerId.set(asset.ledgerId.toLowerCase(), asset);
11
24
  }
12
- const assetsByProviderId: Record<string, CurrenciesByProviderId> = {};
13
- for (const ledgerCurrency of currenciesSupported) {
14
- const asset = assetsByLedgerId[ledgerCurrency.id.toLowerCase()];
25
+ const assetsByProviderId: Map<string, CurrenciesByProviderId> = new Map();
26
+ const sortedCryptoCurrencies: CryptoOrTokenCurrency[] = [];
27
+ // iterate over currencies by preserving their order
28
+ for (const ledgerCurrency of sortedCurrencies) {
29
+ /// FIXME(LIVE-10508) drop usage of toLowerCase
30
+ const asset = assetsByLedgerId.get(ledgerCurrency.id.toLowerCase());
15
31
  if (asset) {
16
- if (!assetsByProviderId[asset.providerId]) {
17
- assetsByProviderId[asset.providerId] = {
32
+ // we only yield the intersection of currencies and mapped assets
33
+ const existingEntry = assetsByProviderId.get(asset.providerId);
34
+ if (!existingEntry) {
35
+ assetsByProviderId.set(asset.providerId, {
18
36
  providerId: asset.providerId,
19
- currenciesByNetwork: [],
20
- };
37
+ currenciesByNetwork: [ledgerCurrency],
38
+ });
39
+ // in this case, the first currency of the provider is the one we want to display
40
+ sortedCryptoCurrencies.push(ledgerCurrency);
41
+ } else {
42
+ existingEntry.currenciesByNetwork.push(ledgerCurrency);
21
43
  }
22
- assetsByProviderId[asset.providerId].currenciesByNetwork.push(ledgerCurrency);
23
44
  }
24
45
  }
25
- return Object.values(assetsByProviderId);
46
+ return {
47
+ currenciesByProvider: Array.from(assetsByProviderId.values()),
48
+ sortedCryptoCurrencies,
49
+ };
26
50
  };
27
51
 
28
- const searchByProviderId = (list: MappedAsset[], providerId: string) =>
52
+ export const searchByProviderId = (list: MappedAsset[], providerId: string) =>
29
53
  list.filter(elem => elem.providerId.toLowerCase() === providerId.toLowerCase());
30
54
 
31
- const searchByNameOrTicker = (list: MappedAsset[], nameOrTicker: string) =>
55
+ export const searchByNameOrTicker = (list: MappedAsset[], nameOrTicker: string) =>
32
56
  list.filter(
33
57
  elem =>
34
58
  elem.name.toLowerCase().includes(nameOrTicker.toLowerCase()) ||
35
59
  elem.ticker.toLowerCase().includes(nameOrTicker.toLowerCase()),
36
60
  );
37
-
38
- export { searchByProviderId, searchByNameOrTicker, groupCurrenciesByProvider };
@@ -26,3 +26,8 @@ export type CurrenciesByProviderId = {
26
26
  currenciesByNetwork: CryptoOrTokenCurrency[];
27
27
  providerId: string;
28
28
  };
29
+
30
+ export type GroupedCurrencies = {
31
+ currenciesByProvider: CurrenciesByProviderId[];
32
+ sortedCryptoCurrencies: CryptoOrTokenCurrency[];
33
+ };
@@ -1,48 +1,29 @@
1
- import { CurrenciesByProviderId } from "./type";
1
+ import { GroupedCurrencies } from "./type";
2
2
  import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
3
- import { useCallback, useEffect, useMemo, useState } from "react";
4
- import {
5
- isCurrencySupported,
6
- listSupportedCurrencies,
7
- listTokens,
8
- currenciesByMarketcap,
9
- } from "../currencies";
10
- import { getMappedAssets } from "./api";
11
- import { groupCurrenciesByProvider } from "./helper";
3
+ import { useEffect, useMemo, useState } from "react";
4
+ import { isCurrencySupported, listSupportedCurrencies, listTokens } from "../currencies";
5
+ import { loadCurrenciesByProvider } from "./helper";
12
6
 
7
+ // FIXME(LIVE-10505): bad performane & shared utility to move to coin-framework
13
8
  const listSupportedTokens = () => listTokens().filter(t => isCurrencySupported(t.parentCurrency));
14
9
 
10
+ const initialResult: GroupedCurrencies = {
11
+ sortedCryptoCurrencies: [],
12
+ currenciesByProvider: [],
13
+ };
14
+
15
15
  export const useGroupedCurrenciesByProvider = () => {
16
- const [currencies, setCurrencies] = useState<CryptoOrTokenCurrency[]>([]);
17
- const [currenciesByProvider, setCurrenciesByProvider] = useState<CurrenciesByProviderId[]>([]);
16
+ const [result, setResult] = useState(initialResult);
18
17
 
19
- // Get Supported Currencies and sort them by marketcap
20
18
  const coinsAndTokensSupported = useMemo(
21
19
  () => (listSupportedCurrencies() as CryptoOrTokenCurrency[]).concat(listSupportedTokens()),
22
20
  [],
23
21
  );
24
22
 
25
- // Get mapped assets filtered by supported currencies and grouped by provider id
26
- const getCurrenciesAndGroupThemByProvider = useCallback(async () => {
27
- const [sortedCurrenciesSupported, assets] = await Promise.all([
28
- currenciesByMarketcap(coinsAndTokensSupported),
29
- getMappedAssets(),
30
- ]);
31
- const currenciesByProvider = groupCurrenciesByProvider(assets, sortedCurrenciesSupported);
32
- setCurrenciesByProvider(currenciesByProvider);
33
- setCurrencies(
34
- currenciesByProvider
35
- .filter(value => value.currenciesByNetwork && value.currenciesByNetwork.length > 0)
36
- .map(value => value.currenciesByNetwork[0]),
37
- );
38
- }, [coinsAndTokensSupported]);
39
-
23
+ // Get mapped assets filtered by supported & sorted currencies, grouped by provider id
40
24
  useEffect(() => {
41
- getCurrenciesAndGroupThemByProvider();
42
- }, [getCurrenciesAndGroupThemByProvider]);
25
+ loadCurrenciesByProvider(coinsAndTokensSupported).then(setResult);
26
+ }, [coinsAndTokensSupported]);
43
27
 
44
- return {
45
- currenciesByProvider,
46
- sortedCryptoCurrencies: currencies,
47
- };
28
+ return result;
48
29
  };
@@ -0,0 +1,9 @@
1
+ import { renderHook } from "@testing-library/react-hooks";
2
+ import { useBatteryStatuses } from "./useBatteryStatuses";
3
+
4
+ describe("useBatteryStatuses", () => {
5
+ it("should return an initial cancelRequest method that is callable", async () => {
6
+ const { result } = renderHook(() => useBatteryStatuses({ statuses: [] }));
7
+ expect(() => result.current.cancelRequest()).not.toThrow();
8
+ });
9
+ });
@@ -9,7 +9,7 @@ import {
9
9
  import { BatteryStatusTypes } from "../../hw/getBatteryStatus";
10
10
  import { useEnv } from "../../env.react";
11
11
 
12
- export type UseBateryStatusesArgs = {
12
+ export type UseBatteryStatusesArgs = {
13
13
  deviceId?: string;
14
14
  statuses: BatteryStatusTypes[];
15
15
  };
@@ -29,7 +29,7 @@ export type UseBateryStatusesArgs = {
29
29
  export const useBatteryStatuses = ({
30
30
  deviceId,
31
31
  statuses,
32
- }: UseBateryStatusesArgs): {
32
+ }: UseBatteryStatusesArgs): {
33
33
  batteryStatusesState: GetBatteryStatusesActionState;
34
34
  requestCompleted: boolean;
35
35
  triggerRequest: () => void;
@@ -41,7 +41,11 @@ export const useBatteryStatuses = ({
41
41
  useState<GetBatteryStatusesActionState>(initialState);
42
42
  const [requestCompleted, setRequestCompleted] = useState<boolean>(false);
43
43
  const [nonce, setNonce] = useState(0);
44
- const [cancelRequest, setCancelRequest] = useState<() => void>(() => {});
44
+
45
+ // when passing a function to useState, the function is used as an initializer,
46
+ // i.e its return value will be the initial state value,
47
+ // cf. https://react.dev/reference/react/useState#parameters
48
+ const [cancelRequest, setCancelRequest] = useState(() => () => {});
45
49
  const [isBatteryLow, setIsBatteryLow] = useState<boolean>(false);
46
50
  const lowBatteryPercentage = useEnv("LOW_BATTERY_PERCENTAGE");
47
51
 
@@ -8,4 +8,4 @@ export * from "./useToState";
8
8
  export * from "./usePageState";
9
9
  export * from "./v5";
10
10
  export * from "./useSwapableAccounts";
11
- export * from "./useIsSwapLiveApp";
11
+ export * from "./live-app-migration/useIsSwapLiveApp";
@@ -0,0 +1,32 @@
1
+ import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
2
+ import { isCryptoCurrency } from "../../../../currencies";
3
+
4
+ type UseIsCurrencySupportedProps = {
5
+ currencyFrom?: CryptoOrTokenCurrency;
6
+ params: {
7
+ families: string;
8
+ currencies: Array<unknown>;
9
+ };
10
+ defaultValue: boolean;
11
+ };
12
+
13
+ export function useIsCurrencySupported({
14
+ currencyFrom,
15
+ params,
16
+ defaultValue,
17
+ }: UseIsCurrencySupportedProps) {
18
+ const { families, currencies } = params || {};
19
+
20
+ if (!currencyFrom || (!families && !currencies)) {
21
+ return defaultValue;
22
+ }
23
+
24
+ const familyOfCurrencyFrom = isCryptoCurrency(currencyFrom)
25
+ ? currencyFrom.family
26
+ : currencyFrom.parentCurrency.family;
27
+
28
+ const familyIsEnabled = families?.length ? families.includes(familyOfCurrencyFrom) : true;
29
+ const currencyIsEnabled = currencies?.length ? currencies.includes(currencyFrom.id) : true;
30
+
31
+ return familyIsEnabled || currencyIsEnabled;
32
+ }
@@ -22,7 +22,7 @@ describe("useIsSwapLiveApp hook", () => {
22
22
  useIsSwapLiveApp({ currencyFrom: undefined, swapWebManifestId: "swap-live-app-demo-0" }),
23
23
  );
24
24
 
25
- expect(result.current).toBe(true);
25
+ expect(result.current.enabled).toBe(true);
26
26
  });
27
27
 
28
28
  it("returns the enabled flag when families and currencies are not defined", () => {
@@ -35,7 +35,7 @@ describe("useIsSwapLiveApp hook", () => {
35
35
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
36
36
  );
37
37
 
38
- expect(result.current).toBe(true);
38
+ expect(result.current.enabled).toBe(true);
39
39
  });
40
40
 
41
41
  it("returns true when currencyFrom family is in families array and feature is enabled", () => {
@@ -48,7 +48,7 @@ describe("useIsSwapLiveApp hook", () => {
48
48
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
49
49
  );
50
50
 
51
- expect(result.current).toBe(true);
51
+ expect(result.current.enabled).toBe(true);
52
52
  });
53
53
 
54
54
  it("returns true when currencyFrom is in currencies array and feature is enabled", () => {
@@ -61,7 +61,7 @@ describe("useIsSwapLiveApp hook", () => {
61
61
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
62
62
  );
63
63
 
64
- expect(result.current).toBe(true);
64
+ expect(result.current.enabled).toBe(true);
65
65
  });
66
66
 
67
67
  it("returns false when currencyFrom family is not in families, currencyFrom is not in currencies, and feature is disabled", () => {
@@ -74,7 +74,7 @@ describe("useIsSwapLiveApp hook", () => {
74
74
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
75
75
  );
76
76
 
77
- expect(result.current).toBe(false);
77
+ expect(result.current.enabled).toBe(false);
78
78
  });
79
79
 
80
80
  it("returns enabled flag if both families and currencies are empty arrays", () => {
@@ -87,7 +87,7 @@ describe("useIsSwapLiveApp hook", () => {
87
87
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
88
88
  );
89
89
 
90
- expect(result.current).toBe(true);
90
+ expect(result.current.enabled).toBe(true);
91
91
  });
92
92
  });
93
93
  describe("flag with nested manifest properties", () => {
@@ -98,7 +98,7 @@ describe("useIsSwapLiveApp hook", () => {
98
98
  useIsSwapLiveApp({ currencyFrom: undefined, swapWebManifestId: "swap-live-app-demo-0" }),
99
99
  );
100
100
 
101
- expect(result.current).toBe(true);
101
+ expect(result.current.enabled).toBe(true);
102
102
  });
103
103
 
104
104
  it("returns the enabled flag when families and currencies are not defined", () => {
@@ -112,7 +112,7 @@ describe("useIsSwapLiveApp hook", () => {
112
112
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
113
113
  );
114
114
 
115
- expect(result.current).toBe(true);
115
+ expect(result.current.enabled).toBe(true);
116
116
  });
117
117
 
118
118
  it("returns true when currencyFrom family is in families array and feature is enabled", () => {
@@ -128,7 +128,7 @@ describe("useIsSwapLiveApp hook", () => {
128
128
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
129
129
  );
130
130
 
131
- expect(result.current).toBe(true);
131
+ expect(result.current.enabled).toBe(true);
132
132
  });
133
133
 
134
134
  it("returns true when currencyFrom is in currencies array and feature is enabled", () => {
@@ -144,7 +144,7 @@ describe("useIsSwapLiveApp hook", () => {
144
144
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
145
145
  );
146
146
 
147
- expect(result.current).toBe(true);
147
+ expect(result.current.enabled).toBe(true);
148
148
  });
149
149
 
150
150
  it("returns false when currencyFrom family is not in families, currencyFrom is not in currencies, and feature is disabled", () => {
@@ -160,7 +160,7 @@ describe("useIsSwapLiveApp hook", () => {
160
160
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
161
161
  );
162
162
 
163
- expect(result.current).toBe(false);
163
+ expect(result.current.enabled).toBe(false);
164
164
  });
165
165
 
166
166
  it("returns enabled flag if both families and currencies are empty arrays", () => {
@@ -176,7 +176,7 @@ describe("useIsSwapLiveApp hook", () => {
176
176
  useIsSwapLiveApp({ currencyFrom: bitcoin, swapWebManifestId: "swap-live-app-demo-0" }),
177
177
  );
178
178
 
179
- expect(result.current).toBe(true);
179
+ expect(result.current.enabled).toBe(true);
180
180
  });
181
181
  });
182
182
  });
@@ -1,6 +1,7 @@
1
1
  import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
2
2
  import { useFeature } from "@ledgerhq/live-config/featureFlags/index";
3
- import { isCryptoCurrency } from "../../../currencies";
3
+ import { useIsCurrencySupported } from "./useIsCurrencySupported";
4
+ import { useCallback, useState } from "react";
4
5
 
5
6
  type Props = {
6
7
  currencyFrom?: CryptoOrTokenCurrency;
@@ -16,18 +17,20 @@ export function useIsSwapLiveApp({ currencyFrom, swapWebManifestId }: Props) {
16
17
  : ptxSwapLiveApp;
17
18
 
18
19
  const { enabled, params } = flagConfig || {};
19
- const { families, currencies } = params || {};
20
20
 
21
- if (!currencyFrom || (!families && !currencies)) {
22
- return enabled;
23
- }
21
+ const isCurrencySupported = useIsCurrencySupported({
22
+ params,
23
+ currencyFrom,
24
+ defaultValue: enabled,
25
+ });
24
26
 
25
- const familyOfCurrencyFrom = isCryptoCurrency(currencyFrom)
26
- ? currencyFrom.family
27
- : currencyFrom.parentCurrency.family;
27
+ const [crashed, setHasCrashed] = useState(false);
28
+ const onLiveAppCrashed = useCallback(() => setHasCrashed(true), []);
28
29
 
29
- const familyIsEnabled = families?.length ? families.includes(familyOfCurrencyFrom) : true;
30
- const currencyIsEnabled = currencies?.length ? currencies.includes(currencyFrom.id) : true;
30
+ const liveAppAvailable = Boolean(enabled && isCurrencySupported && !crashed);
31
31
 
32
- return enabled && (familyIsEnabled || currencyIsEnabled);
32
+ return {
33
+ enabled: liveAppAvailable,
34
+ onLiveAppCrashed,
35
+ };
33
36
  }
@@ -102,7 +102,7 @@ const swapProviders: Record<string, ProviderConfig> = {
102
102
  "3045022100e35f78bbdf543614fa7db7ccc45622186b727d1d5b0accbdaf220ac54d4cd2fb02200f7decbb5a6e822668af73bf0ddcde822121e29642436aa6de11feabf12cf2f0",
103
103
  "hex",
104
104
  ),
105
- needsKYC: false,
105
+ needsKYC: true,
106
106
  needsBearerToken: false,
107
107
  type: "CEX",
108
108
  version: 2,
@@ -1,6 +1,6 @@
1
1
  import type { Resolver } from "../../hw/getAddress/types";
2
2
  import Ada, { Networks, AddressType } from "@cardano-foundation/ledgerjs-hw-app-cardano";
3
- import { str_to_path } from "@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils";
3
+ import { str_to_path } from "@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils/address";
4
4
  import { getBipPathFromString, getBipPathString } from "./logic";
5
5
  import { StakeChain } from "./types";
6
6
  import { STAKING_ADDRESS_INDEX } from "./constants";
@@ -9,7 +9,7 @@ import { encodeAccountId, inferSubOperations } from "@ledgerhq/coin-framework/ac
9
9
 
10
10
  import BigNumber from "bignumber.js";
11
11
  import Ada, { ExtendedPublicKey } from "@cardano-foundation/ledgerjs-hw-app-cardano";
12
- import { str_to_path } from "@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils";
12
+ import { str_to_path } from "@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils/address";
13
13
  import { utils as TyphonUtils } from "@stricahq/typhonjs";
14
14
  import { APITransaction, HashType } from "./api/api-types";
15
15
  import {
@@ -39,7 +39,7 @@ import {
39
39
  TxOutputDestination,
40
40
  TxOutputDestinationType,
41
41
  } from "@cardano-foundation/ledgerjs-hw-app-cardano";
42
- import { str_to_path } from "@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils";
42
+ import { str_to_path } from "@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils/address";
43
43
 
44
44
  /**
45
45
  * returns BipPath object with account, chain and index field for cardano
@@ -17,7 +17,7 @@ const currency = getCryptoCurrencyById("cardano");
17
17
  const minBalanceRequired = parseCurrencyUnit(currency.units[0], "2.2");
18
18
  const minBalanceRequiredForMaxSend = parseCurrencyUnit(currency.units[0], "1");
19
19
  const minBalanceRequiredForDelegate = parseCurrencyUnit(currency.units[0], "3");
20
- const minSpendableRequiredForTokenTx = parseCurrencyUnit(currency.units[0], "3");
20
+ const minSpendableRequiredForTokenTx = parseCurrencyUnit(currency.units[0], "1");
21
21
 
22
22
  const cardano: AppSpec<Transaction> = {
23
23
  name: "cardano",
@@ -25,14 +25,52 @@ const cardano: AppSpec<Transaction> = {
25
25
  appQuery: {
26
26
  model: DeviceModelId.nanoSP,
27
27
  appName: "CardanoADA",
28
- // FIXME latest app version requires to update cardano libs
29
- // https://ledgerhq.atlassian.net/browse/LIVE-5447
30
- appVersion: "5.0.0",
31
28
  },
32
29
  minViableAmount: minBalanceRequired,
33
30
  genericDeviceAction: acceptTransaction,
34
31
  testTimeout: 5 * 60 * 1000,
35
32
  mutations: [
33
+ {
34
+ name: "move ~10% token",
35
+ maxRun: 1,
36
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
37
+ invariant(maxSpendable.gte(minSpendableRequiredForTokenTx), "balance is too low");
38
+ const sibling = pickSiblings(siblings, maxAccounts);
39
+ const recipient = sibling.freshAddress;
40
+ const transaction = bridge.createTransaction(account);
41
+
42
+ const subAccount = account.subAccounts?.find(subAccount =>
43
+ subAccount.balance.gt(1),
44
+ ) as SubAccount;
45
+ invariant(subAccount, "No token account with balance");
46
+
47
+ const updates = [
48
+ { subAccountId: subAccount.id },
49
+ { recipient },
50
+ {
51
+ amount: new BigNumber(subAccount.balance.dividedBy(10)).dp(0, BigNumber.ROUND_CEIL),
52
+ },
53
+ ];
54
+
55
+ return {
56
+ transaction,
57
+ updates,
58
+ };
59
+ },
60
+ test: ({ operation, transaction }): void => {
61
+ botTest("subOperations is defined", () => expect(operation.subOperations).toBeTruthy());
62
+
63
+ botTest("there's only one subOperation", () =>
64
+ expect(operation.subOperations?.length).toEqual(1),
65
+ );
66
+
67
+ const subOperation = operation.subOperations && operation.subOperations[0];
68
+
69
+ botTest("subOperation have correct tx amount", () =>
70
+ expect(subOperation?.value).toEqual(transaction.amount),
71
+ );
72
+ },
73
+ },
36
74
  {
37
75
  testDestination: genericTestDestination,
38
76
  name: "move ~50%",
@@ -116,47 +154,6 @@ const cardano: AppSpec<Transaction> = {
116
154
  );
117
155
  },
118
156
  },
119
- {
120
- name: "move ~10% token",
121
- maxRun: 1,
122
- transaction: ({ account, siblings, bridge, maxSpendable }) => {
123
- invariant(maxSpendable.gte(minSpendableRequiredForTokenTx), "balance is too low");
124
- const sibling = pickSiblings(siblings, maxAccounts);
125
- const recipient = sibling.freshAddress;
126
- const transaction = bridge.createTransaction(account);
127
-
128
- const subAccount = account.subAccounts?.find(subAccount =>
129
- subAccount.balance.gt(1),
130
- ) as SubAccount;
131
- invariant(subAccount, "No token account with balance");
132
-
133
- const updates = [
134
- { subAccountId: subAccount.id },
135
- { recipient },
136
- {
137
- amount: new BigNumber(subAccount.balance.dividedBy(10)).dp(0, BigNumber.ROUND_CEIL),
138
- },
139
- ];
140
-
141
- return {
142
- transaction,
143
- updates,
144
- };
145
- },
146
- test: ({ operation, transaction }): void => {
147
- botTest("subOperations is defined", () => expect(operation.subOperations).toBeTruthy());
148
-
149
- botTest("there's only one subOperation", () =>
150
- expect(operation.subOperations?.length).toEqual(1),
151
- );
152
-
153
- const subOperation = operation.subOperations && operation.subOperations[0];
154
-
155
- botTest("subOperation have correct tx amount", () =>
156
- expect(subOperation?.value).toEqual(transaction.amount),
157
- );
158
- },
159
- },
160
157
  {
161
158
  name: "delegate to pool",
162
159
  maxRun: 1,
@@ -21,6 +21,18 @@ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlo
21
21
  title: "Auxiliary data hash",
22
22
  button: SpeculosButton.BOTH,
23
23
  },
24
+ {
25
+ title: "Send to address (1/3)",
26
+ button: SpeculosButton.RIGHT,
27
+ },
28
+ {
29
+ title: "Send to address (2/3)",
30
+ button: SpeculosButton.RIGHT,
31
+ },
32
+ {
33
+ title: "Send to address (3/3)",
34
+ button: SpeculosButton.BOTH,
35
+ },
24
36
  {
25
37
  title: "Send to address (1/2)",
26
38
  button: SpeculosButton.RIGHT,
@@ -30,7 +42,7 @@ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlo
30
42
  button: SpeculosButton.BOTH,
31
43
  },
32
44
  {
33
- title: "end", // FIXME: Should be Send but in some case cardano OCR doesn't recognize S : https://github.com/LedgerHQ/speculos/issues/204
45
+ title: "Send",
34
46
  button: SpeculosButton.BOTH,
35
47
  ignoreAssertionFailure: true,
36
48
  expectedValue: ({ account, status }) => formatDeviceAmount(account.currency, status.amount),
@@ -64,11 +76,11 @@ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlo
64
76
  title: "Deregister",
65
77
  },
66
78
  {
67
- title: "staking key",
79
+ title: "stake key",
68
80
  button: SpeculosButton.BOTH,
69
81
  },
70
82
  {
71
- title: "Staking key",
83
+ title: "Stake key",
72
84
  button: SpeculosButton.BOTH,
73
85
  expectedValue: ({ account }) => {
74
86
  const stakeCred = getAccountStakeCredential(account.xpub as string, account.index);
@@ -96,24 +108,11 @@ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlo
96
108
  button: SpeculosButton.BOTH,
97
109
  },
98
110
  {
99
- // sometimes the poolId fits on a single screen
100
- title: "Delegate stake to",
101
- button: SpeculosButton.BOTH,
102
- },
103
- {
104
- title: "Delegate stake to (1/2)",
105
- button: SpeculosButton.RIGHT,
106
- },
107
- {
108
- title: "Delegate stake to (2/2)",
109
- button: SpeculosButton.BOTH,
110
- },
111
- {
112
- title: "Delegate s...ke to (1/2)",
111
+ title: "Delegate stake (1/2)",
113
112
  button: SpeculosButton.RIGHT,
114
113
  },
115
114
  {
116
- title: "Delegate ...ke to (2/2)",
115
+ title: "Delegate stake (2/2)",
117
116
  button: SpeculosButton.BOTH,
118
117
  },
119
118
  {
@@ -6,7 +6,7 @@ import {
6
6
  StakeDeregistrationParams,
7
7
  Withdrawal,
8
8
  } from "@cardano-foundation/ledgerjs-hw-app-cardano";
9
- import { str_to_path } from "@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils";
9
+ import { str_to_path } from "@cardano-foundation/ledgerjs-hw-app-cardano/dist/utils/address";
10
10
  import { types as TyphonTypes, address as TyphonAddress } from "@stricahq/typhonjs";
11
11
  import groupBy from "lodash/groupBy";
12
12
  import {
@@ -3,7 +3,7 @@ import { DeviceModelId } from "@ledgerhq/types-devices";
3
3
  import { usePostOnboardingContext } from "./usePostOnboardingContext";
4
4
  import { useCallback } from "react";
5
5
  import { useFeatureFlags } from "@ledgerhq/live-config/featureFlags/index";
6
- import { initPostOnboarding } from "../actions";
6
+ import { initPostOnboarding, postOnboardingSetFinished } from "../actions";
7
7
 
8
8
  type StartPostOnboardingOptions = {
9
9
  deviceModelId: DeviceModelId;
@@ -44,6 +44,7 @@ export function useStartPostOnboardingCallback(): (options: StartPostOnboardingO
44
44
 
45
45
  if (actions.length === 0) {
46
46
  if (fallbackIfNoAction) {
47
+ dispatch(postOnboardingSetFinished());
47
48
  fallbackIfNoAction();
48
49
  }
49
50
  return;
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIsSwapLiveApp.d.ts","sourceRoot":"","sources":["../../../../src/exchange/swap/hooks/useIsSwapLiveApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAIrE,KAAK,KAAK,GAAG;IACX,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACrC,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAAE,YAAY,EAAE,iBAAiB,EAAE,EAAE,KAAK,OAuB1E"}
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useIsSwapLiveApp = void 0;
4
- const index_1 = require("@ledgerhq/live-config/featureFlags/index");
5
- const currencies_1 = require("../../../currencies");
6
- function useIsSwapLiveApp({ currencyFrom, swapWebManifestId }) {
7
- const ptxSwapLiveApp = (0, index_1.useFeature)("ptxSwapLiveApp");
8
- const flagConfig = ptxSwapLiveApp && ptxSwapLiveApp[swapWebManifestId]
9
- ? ptxSwapLiveApp[swapWebManifestId]
10
- : ptxSwapLiveApp;
11
- const { enabled, params } = flagConfig || {};
12
- const { families, currencies } = params || {};
13
- if (!currencyFrom || (!families && !currencies)) {
14
- return enabled;
15
- }
16
- const familyOfCurrencyFrom = (0, currencies_1.isCryptoCurrency)(currencyFrom)
17
- ? currencyFrom.family
18
- : currencyFrom.parentCurrency.family;
19
- const familyIsEnabled = (families === null || families === void 0 ? void 0 : families.length) ? families.includes(familyOfCurrencyFrom) : true;
20
- const currencyIsEnabled = (currencies === null || currencies === void 0 ? void 0 : currencies.length) ? currencies.includes(currencyFrom.id) : true;
21
- return enabled && (familyIsEnabled || currencyIsEnabled);
22
- }
23
- exports.useIsSwapLiveApp = useIsSwapLiveApp;
24
- //# sourceMappingURL=useIsSwapLiveApp.js.map