@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
@@ -1,54 +1,6 @@
1
1
  import type { AppManifest } from "../types";
2
- import semver from "semver";
3
- export type FilterParams = {
4
- branches?: string[];
5
- platform?: string;
6
- private?: boolean;
7
- version?: string;
8
- };
9
2
  import { getEnv } from "../../env";
10
3
 
11
- function matchVersion(filterParams: FilterParams, manifest: AppManifest) {
12
- return (
13
- !filterParams.version ||
14
- semver.satisfies(
15
- semver.coerce(filterParams.version) || "",
16
- manifest.apiVersion
17
- )
18
- );
19
- }
20
-
21
- function matchBranches(filterParams: FilterParams, manifest: AppManifest) {
22
- return (
23
- !filterParams.branches || filterParams.branches.includes(manifest.branch)
24
- );
25
- }
26
-
27
- function matchPlatform(filterParams: FilterParams, manifest: AppManifest) {
28
- return (
29
- !filterParams.platform ||
30
- manifest.platform === "all" ||
31
- filterParams.platform === manifest.platform
32
- );
33
- }
34
-
35
- function matchPrivate(filterParams: FilterParams, manifest: AppManifest) {
36
- return filterParams.private === true || !(manifest.private === true);
37
- }
38
-
39
- export function filterPlatformApps(
40
- appManifests: AppManifest[],
41
- filterParams: FilterParams
42
- ): AppManifest[] {
43
- return appManifests.filter((appManifest: AppManifest) => {
44
- return (
45
- matchBranches(filterParams, appManifest) &&
46
- matchPlatform(filterParams, appManifest) &&
47
- matchPrivate(filterParams, appManifest) &&
48
- matchVersion(filterParams, appManifest)
49
- );
50
- });
51
- }
52
4
  export function mergeManifestLists(
53
5
  list1: AppManifest[],
54
6
  list2: AppManifest[]
@@ -1,13 +1,44 @@
1
1
  import byFamily from "../generated/platformAdapter";
2
-
3
- import type { Account, CryptoCurrency, Transaction } from "../types";
4
- import type {
2
+ import { isTokenAccount, isSubAccount } from "../account";
3
+ import { Account, AccountLike, Transaction } from "../types";
4
+ import {
5
5
  PlatformAccount,
6
6
  PlatformCurrency,
7
7
  PlatformTransaction,
8
+ PlatformCurrencyType,
9
+ PlatformTokenStandard,
10
+ PlatformSupportedCurrency,
8
11
  } from "./types";
9
12
 
10
- export function accountToPlatformAccount(account: Account): PlatformAccount {
13
+ export function accountToPlatformAccount(
14
+ account: AccountLike,
15
+ parentAccount?: Account
16
+ ): PlatformAccount {
17
+ if (isSubAccount(account)) {
18
+ if (!parentAccount) {
19
+ throw new Error("No 'parentAccount' account provided for token account");
20
+ }
21
+
22
+ return {
23
+ id: account.id,
24
+ balance: account.balance,
25
+ address: parentAccount.freshAddress,
26
+ blockHeight: parentAccount.blockHeight,
27
+ lastSyncDate: parentAccount.lastSyncDate,
28
+ ...(isTokenAccount(account)
29
+ ? {
30
+ name: `${parentAccount.name} (${account.token.ticker})`,
31
+ currency: account.token.id,
32
+ spendableBalance: account.spendableBalance,
33
+ }
34
+ : {
35
+ name: account.name,
36
+ currency: account.currency.id,
37
+ spendableBalance: parentAccount.spendableBalance,
38
+ }),
39
+ };
40
+ }
41
+
11
42
  return {
12
43
  id: account.id,
13
44
  name: account.name,
@@ -19,11 +50,34 @@ export function accountToPlatformAccount(account: Account): PlatformAccount {
19
50
  lastSyncDate: account.lastSyncDate,
20
51
  };
21
52
  }
53
+
22
54
  export function currencyToPlatformCurrency(
23
- currency: CryptoCurrency
55
+ currency: PlatformSupportedCurrency
24
56
  ): PlatformCurrency {
57
+ if (currency.type === "TokenCurrency") {
58
+ if (currency.parentCurrency.family !== "ethereum") {
59
+ throw new Error("Only ERC20 tokens are supported");
60
+ }
61
+
62
+ return {
63
+ type: PlatformCurrencyType.TokenCurrency,
64
+ standard: PlatformTokenStandard.ERC20,
65
+ id: currency.id,
66
+ ticker: currency.ticker,
67
+ contract: currency.contractAddress,
68
+ name: currency.name,
69
+ parent: currency.parentCurrency.id,
70
+ color: currency.parentCurrency.color,
71
+ units: currency.units.map((unit) => ({
72
+ name: unit.name,
73
+ code: unit.code,
74
+ magnitude: unit.magnitude,
75
+ })),
76
+ };
77
+ }
78
+
25
79
  return {
26
- type: currency.type,
80
+ type: PlatformCurrencyType.CryptoCurrency,
27
81
  id: currency.id,
28
82
  ticker: currency.ticker,
29
83
  name: currency.name,
@@ -0,0 +1,102 @@
1
+ import { makeRe } from "minimatch";
2
+ import { PlatformAccount, PlatformCurrency, AppManifest } from "./types";
3
+ import { isPlatformTokenCurrency } from "./helpers";
4
+ import semver from "semver";
5
+
6
+ export type FilterParams = {
7
+ branches?: string[];
8
+ platform?: string;
9
+ private?: boolean;
10
+ version?: string;
11
+ };
12
+
13
+ export type AccountFilters = {
14
+ currencies?: string[];
15
+ };
16
+
17
+ export function filterPlatformAccounts(
18
+ accounts: PlatformAccount[],
19
+ filters: AccountFilters
20
+ ): PlatformAccount[] {
21
+ const filterCurrencyRegexes = filters.currencies
22
+ ? filters.currencies.map((filter) => makeRe(filter))
23
+ : null;
24
+
25
+ return accounts.filter((account) => {
26
+ if (
27
+ filterCurrencyRegexes &&
28
+ !filterCurrencyRegexes.some((regex) => account.currency.match(regex))
29
+ ) {
30
+ return false;
31
+ }
32
+ return true;
33
+ });
34
+ }
35
+
36
+ export type CurrencyFilters = {
37
+ includeTokens?: boolean;
38
+ currencies?: string[];
39
+ };
40
+
41
+ export function filterPlatformCurrencies(
42
+ currencies: PlatformCurrency[],
43
+ filters: CurrencyFilters
44
+ ): PlatformCurrency[] {
45
+ const filterCurrencyRegexes = filters.currencies
46
+ ? filters.currencies.map((filter) => makeRe(filter))
47
+ : null;
48
+
49
+ return currencies.filter((currency) => {
50
+ if (!filters.includeTokens && isPlatformTokenCurrency(currency)) {
51
+ return false;
52
+ }
53
+
54
+ if (
55
+ filterCurrencyRegexes &&
56
+ !filterCurrencyRegexes.some((regex) => currency.id.match(regex))
57
+ ) {
58
+ return false;
59
+ }
60
+
61
+ return true;
62
+ });
63
+ }
64
+
65
+ function matchVersion(filterParams: FilterParams, manifest: AppManifest) {
66
+ return (
67
+ !filterParams.version ||
68
+ semver.satisfies(filterParams.version, manifest.apiVersion)
69
+ );
70
+ }
71
+
72
+ function matchBranches(filterParams: FilterParams, manifest: AppManifest) {
73
+ return (
74
+ !filterParams.branches || filterParams.branches.includes(manifest.branch)
75
+ );
76
+ }
77
+
78
+ function matchPlatform(filterParams: FilterParams, manifest: AppManifest) {
79
+ return (
80
+ !filterParams.platform ||
81
+ manifest.platform === "all" ||
82
+ filterParams.platform === manifest.platform
83
+ );
84
+ }
85
+
86
+ function matchPrivate(filterParams: FilterParams, manifest: AppManifest) {
87
+ return filterParams.private === true || !(manifest.private === true);
88
+ }
89
+
90
+ export function filterPlatformApps(
91
+ appManifests: AppManifest[],
92
+ filterParams: FilterParams
93
+ ): AppManifest[] {
94
+ return appManifests.filter((appManifest: AppManifest) => {
95
+ return (
96
+ matchBranches(filterParams, appManifest) &&
97
+ matchPlatform(filterParams, appManifest) &&
98
+ matchPrivate(filterParams, appManifest) &&
99
+ matchVersion(filterParams, appManifest)
100
+ );
101
+ });
102
+ }
@@ -0,0 +1,33 @@
1
+ import { isCryptoCurrency, isTokenCurrency } from "../currencies";
2
+ import { Currency } from "../types";
3
+ import {
4
+ PlatformCurrency,
5
+ PlatformSupportedCurrency,
6
+ PlatformERC20TokenCurrency,
7
+ PlatformCryptoCurrency,
8
+ PlatformCurrencyType,
9
+ } from "./types";
10
+
11
+ export function isPlatformSupportedCurrency(
12
+ currency: Currency
13
+ ): currency is PlatformSupportedCurrency {
14
+ return isCryptoCurrency(currency) || isTokenCurrency(currency);
15
+ }
16
+
17
+ export function isPlatformCryptoCurrency(
18
+ currency: PlatformCurrency
19
+ ): currency is PlatformCryptoCurrency {
20
+ return currency.type === PlatformCurrencyType.CryptoCurrency;
21
+ }
22
+
23
+ export function isPlatformTokenCurrency(
24
+ currency: PlatformCurrency
25
+ ): currency is PlatformERC20TokenCurrency {
26
+ return currency.type === PlatformCurrencyType.TokenCurrency;
27
+ }
28
+
29
+ export function isPlatformERC20TokenCurrency(
30
+ currency: PlatformCurrency
31
+ ): currency is PlatformERC20TokenCurrency {
32
+ return (currency as PlatformERC20TokenCurrency).standard === "ERC20";
33
+ }
@@ -1,23 +1,4 @@
1
- import semver from "semver";
2
- import type { AppManifest, AppPlatform, AppBranch } from "./types";
3
- import { getPlatformVersion } from "./version";
4
-
5
- export function translateContent(content: any, locale = "en") {
1
+ export function translateContent(content: any, locale = "en"): string {
6
2
  if (!content || typeof content !== "object") return content;
7
3
  return content[locale] || content.en;
8
4
  }
9
-
10
- export function isSupported(manifest: AppManifest) {
11
- return semver.satisfies(
12
- semver.coerce(getPlatformVersion()) || "",
13
- manifest.apiVersion
14
- );
15
- }
16
-
17
- export function matchBranches(manifest: AppManifest, branches: AppBranch[]) {
18
- return branches.indexOf(manifest.branch) > -1;
19
- }
20
-
21
- export function matchPlatform(manifest: AppManifest, platform: AppPlatform) {
22
- return manifest.platform === "all" || manifest.platform === platform;
23
- }