@ledgerhq/live-common 25.0.0-next.2 → 25.0.0-next.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 (77) hide show
  1. package/lib/__tests__/accounts/importAccounts.js +1 -1
  2. package/lib/__tests__/test-helpers/setup.js +1 -1
  3. package/lib/account/helpers.d.ts +5 -1
  4. package/lib/account/helpers.d.ts.map +1 -1
  5. package/lib/account/helpers.js +28 -1
  6. package/lib/account/helpers.js.map +1 -1
  7. package/lib/apps/filtering.test.js +1 -1
  8. package/lib/currencies/helpers.d.ts +9 -0
  9. package/lib/currencies/helpers.d.ts.map +1 -0
  10. package/lib/currencies/helpers.js +78 -0
  11. package/lib/currencies/helpers.js.map +1 -0
  12. package/lib/currencies/helpers.test.d.ts +2 -0
  13. package/lib/currencies/helpers.test.d.ts.map +1 -0
  14. package/lib/currencies/helpers.test.js +20 -0
  15. package/lib/currencies/helpers.test.js.map +1 -0
  16. package/lib/currencies/index.d.ts +1 -0
  17. package/lib/currencies/index.d.ts.map +1 -1
  18. package/lib/currencies/index.js +1 -0
  19. package/lib/currencies/index.js.map +1 -1
  20. package/lib/currencies/react.d.ts +4 -0
  21. package/lib/currencies/react.d.ts.map +1 -0
  22. package/lib/currencies/react.js +16 -0
  23. package/lib/currencies/react.js.map +1 -0
  24. package/lib/platform/PlatformAppProvider/api/api.mock.js +11 -11
  25. package/lib/platform/PlatformAppProvider/api/api.mock.js.map +1 -1
  26. package/lib/platform/PlatformAppProvider/helpers.d.ts +0 -7
  27. package/lib/platform/PlatformAppProvider/helpers.d.ts.map +1 -1
  28. package/lib/platform/PlatformAppProvider/helpers.js +1 -29
  29. package/lib/platform/PlatformAppProvider/helpers.js.map +1 -1
  30. package/lib/platform/converters.d.ts +4 -4
  31. package/lib/platform/converters.d.ts.map +1 -1
  32. package/lib/platform/converters.js +40 -2
  33. package/lib/platform/converters.js.map +1 -1
  34. package/lib/platform/filters.d.ts +18 -0
  35. package/lib/platform/filters.d.ts.map +1 -0
  36. package/lib/platform/filters.js +63 -0
  37. package/lib/platform/filters.js.map +1 -0
  38. package/lib/platform/helpers.d.ts +7 -0
  39. package/lib/platform/helpers.d.ts.map +1 -0
  40. package/lib/platform/helpers.js +22 -0
  41. package/lib/platform/helpers.js.map +1 -0
  42. package/lib/platform/logic.d.ts +1 -5
  43. package/lib/platform/logic.d.ts.map +1 -1
  44. package/lib/platform/logic.js +1 -18
  45. package/lib/platform/logic.js.map +1 -1
  46. package/lib/platform/providers/RemoteLiveAppProvider/api/mock.json +87 -246
  47. package/lib/platform/react.d.ts +11 -0
  48. package/lib/platform/react.d.ts.map +1 -0
  49. package/lib/platform/react.js +61 -0
  50. package/lib/platform/react.js.map +1 -0
  51. package/lib/platform/types.d.ts +8 -2
  52. package/lib/platform/types.d.ts.map +1 -1
  53. package/lib/platform/types.js +15 -0
  54. package/lib/platform/types.js.map +1 -1
  55. package/lib/platform/version.test.js +1 -1
  56. package/lib/walletconnect/walletconnect.test.js +0 -2
  57. package/lib/walletconnect/walletconnect.test.js.map +1 -1
  58. package/package.json +3 -2
  59. package/src/__tests__/accounts/importAccounts.ts +1 -1
  60. package/src/__tests__/test-helpers/setup.ts +1 -1
  61. package/src/account/helpers.ts +51 -0
  62. package/src/apps/filtering.test.ts +1 -1
  63. package/src/currencies/helpers.test.ts +21 -0
  64. package/src/currencies/helpers.ts +69 -0
  65. package/src/currencies/index.ts +1 -0
  66. package/src/currencies/react.ts +16 -0
  67. package/src/platform/PlatformAppProvider/api/api.mock.ts +11 -11
  68. package/src/platform/PlatformAppProvider/helpers.ts +0 -48
  69. package/src/platform/converters.ts +60 -6
  70. package/src/platform/filters.ts +102 -0
  71. package/src/platform/helpers.ts +33 -0
  72. package/src/platform/logic.ts +1 -20
  73. package/src/platform/providers/RemoteLiveAppProvider/api/mock.json +87 -246
  74. package/src/platform/react.ts +93 -0
  75. package/src/platform/types.ts +23 -1
  76. package/src/platform/version.test.ts +1 -1
  77. package/src/walletconnect/walletconnect.test.ts +0 -3
@@ -0,0 +1,93 @@
1
+ import { useCallback, useMemo } from "react";
2
+ import { AccountLike } from "../types";
3
+ import {
4
+ accountToPlatformAccount,
5
+ currencyToPlatformCurrency,
6
+ } from "./converters";
7
+ import {
8
+ filterPlatformAccounts,
9
+ filterPlatformCurrencies,
10
+ AccountFilters,
11
+ CurrencyFilters,
12
+ } from "./filters";
13
+ import { isPlatformSupportedCurrency } from "./helpers";
14
+ import {
15
+ ListPlatformAccount,
16
+ ListPlatformCurrency,
17
+ PlatformCurrency,
18
+ AppManifest,
19
+ } from "./types";
20
+ import { getParentAccount } from "../account";
21
+ import { listCurrencies } from "../currencies";
22
+
23
+ export function usePlatformUrl(
24
+ manifest: AppManifest,
25
+ params: { background: string; text: string; loadDate?: Date },
26
+ inputs: Record<string, string>
27
+ ): URL {
28
+ return useMemo(() => {
29
+ const url = new URL(manifest.url.toString());
30
+
31
+ if (inputs) {
32
+ for (const key in inputs) {
33
+ if (Object.prototype.hasOwnProperty.call(inputs, key)) {
34
+ url.searchParams.set(key, inputs[key]);
35
+ }
36
+ }
37
+ }
38
+
39
+ url.searchParams.set("backgroundColor", params.background);
40
+ url.searchParams.set("textColor", params.text);
41
+ if (params.loadDate) {
42
+ url.searchParams.set("loadDate", params.loadDate.valueOf().toString());
43
+ }
44
+
45
+ if (manifest.params) {
46
+ url.searchParams.set("params", JSON.stringify(manifest.params));
47
+ }
48
+
49
+ return url;
50
+ }, [manifest.url, manifest.params, params, inputs]);
51
+ }
52
+
53
+ export function useListPlatformAccounts(
54
+ accounts: AccountLike[]
55
+ ): ListPlatformAccount {
56
+ const platformAccounts = useMemo(() => {
57
+ return accounts.map((account) => {
58
+ const parentAccount = getParentAccount(account, accounts);
59
+
60
+ return accountToPlatformAccount(account, parentAccount);
61
+ });
62
+ }, [accounts]);
63
+
64
+ return useCallback(
65
+ (filters: AccountFilters = {}) => {
66
+ return filterPlatformAccounts(platformAccounts, filters);
67
+ },
68
+ [platformAccounts]
69
+ );
70
+ }
71
+
72
+ export function usePlatformCurrencies(
73
+ includeTokens = false
74
+ ): PlatformCurrency[] {
75
+ return useMemo(
76
+ () =>
77
+ listCurrencies(includeTokens)
78
+ .filter(isPlatformSupportedCurrency)
79
+ .map(currencyToPlatformCurrency),
80
+ [includeTokens]
81
+ );
82
+ }
83
+
84
+ export function useListPlatformCurrencies(): ListPlatformCurrency {
85
+ const currencies = usePlatformCurrencies(true);
86
+
87
+ return useCallback(
88
+ (filters?: CurrencyFilters) => {
89
+ return filterPlatformCurrencies(currencies, filters || {});
90
+ },
91
+ [currencies]
92
+ );
93
+ }
@@ -1,10 +1,22 @@
1
- import type { SignedOperation } from "../types";
1
+ import { SignedOperation, CryptoCurrency, TokenCurrency } from "../types";
2
+ import { AccountFilters, CurrencyFilters } from "./filters";
3
+ import {
4
+ Account as PlatformAccount,
5
+ Currency as PlatformCurrency,
6
+ } from "@ledgerhq/live-app-sdk";
2
7
 
3
8
  export type {
4
9
  Account as PlatformAccount,
5
10
  Currency as PlatformCurrency,
6
11
  Unit as PlatformUnit,
7
12
  Transaction as PlatformTransaction,
13
+ CryptoCurrency as PlatformCryptoCurrency,
14
+ ERC20TokenCurrency as PlatformERC20TokenCurrency,
15
+ } from "@ledgerhq/live-app-sdk";
16
+
17
+ export {
18
+ CurrencyType as PlatformCurrencyType,
19
+ TokenStandard as PlatformTokenStandard,
8
20
  } from "@ledgerhq/live-app-sdk";
9
21
 
10
22
  export type TranslatableString = {
@@ -52,3 +64,13 @@ export type PlatformApi = {
52
64
  };
53
65
 
54
66
  export type PlatformSignedTransaction = SignedOperation;
67
+
68
+ export type ListPlatformAccount = (
69
+ filters?: AccountFilters
70
+ ) => PlatformAccount[];
71
+
72
+ export type ListPlatformCurrency = (
73
+ filters?: CurrencyFilters
74
+ ) => PlatformCurrency[];
75
+
76
+ export type PlatformSupportedCurrency = CryptoCurrency | TokenCurrency;
@@ -1,5 +1,5 @@
1
1
  import "../__tests__/test-helpers/setup";
2
2
  import { getPlatformVersion } from "./version";
3
3
  test("version is defined by setup", () => {
4
- expect(getPlatformVersion()).toBe("0.0.1");
4
+ expect(getPlatformVersion()).toBe("1.0.0");
5
5
  });
@@ -8,9 +8,6 @@ import { getCryptoCurrencyById, setSupportedCurrencies } from "../currencies";
8
8
  import type { Account } from "../types/account";
9
9
  import { emptyHistoryCache } from "../account";
10
10
  import { setEnv } from "../env";
11
- import { setPlatformVersion } from "../platform/version";
12
-
13
- setPlatformVersion("0.0.1");
14
11
 
15
12
  describe("walletconnect", () => {
16
13
  const account: Account = {