@ledgerhq/live-common 25.0.0-next.2 → 25.0.0-next.5

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 (175) 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/apps/support.d.ts.map +1 -1
  9. package/lib/apps/support.js +2 -1
  10. package/lib/apps/support.js.map +1 -1
  11. package/lib/currencies/helpers.d.ts +9 -0
  12. package/lib/currencies/helpers.d.ts.map +1 -0
  13. package/lib/currencies/helpers.js +78 -0
  14. package/lib/currencies/helpers.js.map +1 -0
  15. package/lib/currencies/helpers.test.d.ts +2 -0
  16. package/lib/currencies/helpers.test.d.ts.map +1 -0
  17. package/lib/currencies/helpers.test.js +20 -0
  18. package/lib/currencies/helpers.test.js.map +1 -0
  19. package/lib/currencies/index.d.ts +1 -0
  20. package/lib/currencies/index.d.ts.map +1 -1
  21. package/lib/currencies/index.js +1 -0
  22. package/lib/currencies/index.js.map +1 -1
  23. package/lib/currencies/react.d.ts +4 -0
  24. package/lib/currencies/react.d.ts.map +1 -0
  25. package/lib/currencies/react.js +16 -0
  26. package/lib/currencies/react.js.map +1 -0
  27. package/lib/families/cardano/bridge.integration.test.d.ts.map +1 -1
  28. package/lib/families/cardano/bridge.integration.test.js +36 -2
  29. package/lib/families/cardano/bridge.integration.test.js.map +1 -1
  30. package/lib/families/cardano/buildSubAccounts.d.ts.map +1 -1
  31. package/lib/families/cardano/buildSubAccounts.js +5 -3
  32. package/lib/families/cardano/buildSubAccounts.js.map +1 -1
  33. package/lib/families/cardano/deviceTransactionConfig.d.ts +11 -0
  34. package/lib/families/cardano/deviceTransactionConfig.d.ts.map +1 -0
  35. package/lib/families/cardano/deviceTransactionConfig.js +91 -0
  36. package/lib/families/cardano/deviceTransactionConfig.js.map +1 -0
  37. package/lib/families/cardano/errors.d.ts +4 -0
  38. package/lib/families/cardano/errors.d.ts.map +1 -1
  39. package/lib/families/cardano/errors.js +5 -1
  40. package/lib/families/cardano/errors.js.map +1 -1
  41. package/lib/families/cardano/js-estimateMaxSpendable.d.ts.map +1 -1
  42. package/lib/families/cardano/js-estimateMaxSpendable.js +3 -2
  43. package/lib/families/cardano/js-estimateMaxSpendable.js.map +1 -1
  44. package/lib/families/cardano/js-getTransactionStatus.d.ts.map +1 -1
  45. package/lib/families/cardano/js-getTransactionStatus.js +6 -5
  46. package/lib/families/cardano/js-getTransactionStatus.js.map +1 -1
  47. package/lib/families/cardano/js-signOperation.d.ts.map +1 -1
  48. package/lib/families/cardano/js-signOperation.js +10 -5
  49. package/lib/families/cardano/js-signOperation.js.map +1 -1
  50. package/lib/families/cardano/js-synchronisation.d.ts.map +1 -1
  51. package/lib/families/cardano/js-synchronisation.js +126 -98
  52. package/lib/families/cardano/js-synchronisation.js.map +1 -1
  53. package/lib/families/cardano/js-transaction.js +1 -1
  54. package/lib/families/cardano/js-transaction.js.map +1 -1
  55. package/lib/families/cardano/logic.d.ts +1 -0
  56. package/lib/families/cardano/logic.d.ts.map +1 -1
  57. package/lib/families/cardano/logic.js +11 -1
  58. package/lib/families/cardano/logic.js.map +1 -1
  59. package/lib/families/cardano/specs.d.ts.map +1 -1
  60. package/lib/families/cardano/specs.js +39 -1
  61. package/lib/families/cardano/specs.js.map +1 -1
  62. package/lib/families/cardano/speculos-deviceActions.d.ts.map +1 -1
  63. package/lib/families/cardano/speculos-deviceActions.js +15 -0
  64. package/lib/families/cardano/speculos-deviceActions.js.map +1 -1
  65. package/lib/families/hedera/api/mirror.js +1 -1
  66. package/lib/families/hedera/api/mirror.js.map +1 -1
  67. package/lib/families/hedera/api/network.d.ts.map +1 -1
  68. package/lib/families/hedera/api/network.js +3 -1
  69. package/lib/families/hedera/api/network.js.map +1 -1
  70. package/lib/families/hedera/deviceTransactionConfig.d.ts.map +1 -1
  71. package/lib/families/hedera/deviceTransactionConfig.js +7 -0
  72. package/lib/families/hedera/deviceTransactionConfig.js.map +1 -1
  73. package/lib/families/hedera/js-synchronisation.d.ts.map +1 -1
  74. package/lib/families/hedera/js-synchronisation.js +10 -7
  75. package/lib/families/hedera/js-synchronisation.js.map +1 -1
  76. package/lib/families/hedera/specs.d.ts.map +1 -1
  77. package/lib/families/hedera/specs.js +23 -0
  78. package/lib/families/hedera/specs.js.map +1 -1
  79. package/lib/families/hedera/speculos-deviceActions.d.ts.map +1 -1
  80. package/lib/families/hedera/speculos-deviceActions.js +5 -1
  81. package/lib/families/hedera/speculos-deviceActions.js.map +1 -1
  82. package/lib/families/hedera/transaction.d.ts.map +1 -1
  83. package/lib/families/hedera/transaction.js +2 -2
  84. package/lib/families/hedera/transaction.js.map +1 -1
  85. package/lib/families/hedera/types.d.ts +2 -5
  86. package/lib/families/hedera/types.d.ts.map +1 -1
  87. package/lib/families/hedera/types.js +0 -4
  88. package/lib/families/hedera/types.js.map +1 -1
  89. package/lib/families/hedera/utils.d.ts.map +1 -1
  90. package/lib/featureFlags/types.d.ts +1 -1
  91. package/lib/featureFlags/types.d.ts.map +1 -1
  92. package/lib/generated/deviceTransactionConfig.d.ts +2 -0
  93. package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
  94. package/lib/generated/deviceTransactionConfig.js +28 -26
  95. package/lib/generated/deviceTransactionConfig.js.map +1 -1
  96. package/lib/platform/PlatformAppProvider/api/api.mock.js +11 -11
  97. package/lib/platform/PlatformAppProvider/api/api.mock.js.map +1 -1
  98. package/lib/platform/PlatformAppProvider/helpers.d.ts +0 -7
  99. package/lib/platform/PlatformAppProvider/helpers.d.ts.map +1 -1
  100. package/lib/platform/PlatformAppProvider/helpers.js +1 -29
  101. package/lib/platform/PlatformAppProvider/helpers.js.map +1 -1
  102. package/lib/platform/converters.d.ts +4 -4
  103. package/lib/platform/converters.d.ts.map +1 -1
  104. package/lib/platform/converters.js +40 -2
  105. package/lib/platform/converters.js.map +1 -1
  106. package/lib/platform/filters.d.ts +18 -0
  107. package/lib/platform/filters.d.ts.map +1 -0
  108. package/lib/platform/filters.js +63 -0
  109. package/lib/platform/filters.js.map +1 -0
  110. package/lib/platform/helpers.d.ts +7 -0
  111. package/lib/platform/helpers.d.ts.map +1 -0
  112. package/lib/platform/helpers.js +22 -0
  113. package/lib/platform/helpers.js.map +1 -0
  114. package/lib/platform/logic.d.ts +1 -5
  115. package/lib/platform/logic.d.ts.map +1 -1
  116. package/lib/platform/logic.js +1 -18
  117. package/lib/platform/logic.js.map +1 -1
  118. package/lib/platform/providers/RemoteLiveAppProvider/api/mock.json +87 -246
  119. package/lib/platform/react.d.ts +11 -0
  120. package/lib/platform/react.d.ts.map +1 -0
  121. package/lib/platform/react.js +61 -0
  122. package/lib/platform/react.js.map +1 -0
  123. package/lib/platform/types.d.ts +8 -2
  124. package/lib/platform/types.d.ts.map +1 -1
  125. package/lib/platform/types.js +15 -0
  126. package/lib/platform/types.js.map +1 -1
  127. package/lib/platform/version.test.js +1 -1
  128. package/lib/walletconnect/walletconnect.test.js +0 -2
  129. package/lib/walletconnect/walletconnect.test.js.map +1 -1
  130. package/package.json +5 -4
  131. package/src/__tests__/accounts/importAccounts.ts +1 -1
  132. package/src/__tests__/test-helpers/setup.ts +1 -1
  133. package/src/account/helpers.ts +51 -0
  134. package/src/apps/filtering.test.ts +1 -1
  135. package/src/apps/support.ts +1 -0
  136. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +101 -0
  137. package/src/currencies/helpers.test.ts +21 -0
  138. package/src/currencies/helpers.ts +69 -0
  139. package/src/currencies/index.ts +1 -0
  140. package/src/currencies/react.ts +16 -0
  141. package/src/families/cardano/__snapshots__/bridge.integration.test.ts.snap +41 -1
  142. package/src/families/cardano/bridge.integration.test.ts +38 -0
  143. package/src/families/cardano/buildSubAccounts.ts +5 -3
  144. package/src/families/cardano/deviceTransactionConfig.ts +109 -0
  145. package/src/families/cardano/errors.ts +7 -0
  146. package/src/families/cardano/js-estimateMaxSpendable.ts +4 -1
  147. package/src/families/cardano/js-getTransactionStatus.ts +7 -7
  148. package/src/families/cardano/js-signOperation.ts +10 -5
  149. package/src/families/cardano/js-synchronisation.ts +52 -21
  150. package/src/families/cardano/js-transaction.ts +1 -1
  151. package/src/families/cardano/logic.ts +10 -0
  152. package/src/families/cardano/specs.ts +53 -1
  153. package/src/families/cardano/speculos-deviceActions.ts +15 -0
  154. package/src/families/hedera/api/mirror.ts +1 -1
  155. package/src/families/hedera/api/network.ts +1 -0
  156. package/src/families/hedera/deviceTransactionConfig.ts +8 -0
  157. package/src/families/hedera/js-synchronisation.ts +5 -3
  158. package/src/families/hedera/specs.ts +56 -5
  159. package/src/families/hedera/speculos-deviceActions.ts +1 -0
  160. package/src/families/hedera/transaction.ts +2 -0
  161. package/src/families/hedera/types.ts +2 -8
  162. package/src/families/hedera/utils.ts +1 -1
  163. package/src/featureFlags/types.ts +1 -0
  164. package/src/generated/deviceTransactionConfig.ts +3 -0
  165. package/src/platform/PlatformAppProvider/api/api.mock.ts +11 -11
  166. package/src/platform/PlatformAppProvider/helpers.ts +0 -48
  167. package/src/platform/converters.ts +60 -6
  168. package/src/platform/filters.ts +102 -0
  169. package/src/platform/helpers.ts +33 -0
  170. package/src/platform/logic.ts +1 -20
  171. package/src/platform/providers/RemoteLiveAppProvider/api/mock.json +87 -246
  172. package/src/platform/react.ts +93 -0
  173. package/src/platform/types.ts +23 -1
  174. package/src/platform/version.test.ts +1 -1
  175. package/src/walletconnect/walletconnect.test.ts +0 -3
@@ -1,4 +1,5 @@
1
1
  import invariant from "invariant";
2
+ import { BigNumber } from "bignumber.js";
2
3
  import { Account, getDerivationScheme, runDerivationScheme } from "../../types";
3
4
  import type {
4
5
  GetAccountShape,
@@ -31,14 +32,15 @@ const getAccountShape: GetAccountShape = async (
31
32
 
32
33
  // grab latest operation's consensus timestamp for incremental sync
33
34
  const oldOperations = initialAccount?.operations ?? [];
34
- const latestOperationTimestamp =
35
- oldOperations[0]?.extra?.consensus_timestamp ?? 0;
35
+ const latestOperationTimestamp = oldOperations[0]
36
+ ? Math.floor(oldOperations[0].date.getTime() / 1000)
37
+ : 0;
36
38
 
37
39
  // merge new operations w/ previously synced ones
38
40
  const newOperations = await getOperationsForAccount(
39
41
  liveAccountId,
40
42
  address,
41
- latestOperationTimestamp
43
+ new BigNumber(latestOperationTimestamp).toString()
42
44
  );
43
45
  const operations = mergeOps(oldOperations, newOperations);
44
46
 
@@ -2,12 +2,18 @@ import expect from "expect";
2
2
  import invariant from "invariant";
3
3
  import { getCryptoCurrencyById, parseCurrencyUnit } from "../../currencies";
4
4
  import { DeviceModelId } from "@ledgerhq/devices";
5
- import type { AppSpec } from "../../bot/types";
5
+ import type {
6
+ AppSpec,
7
+ TransactionTestInput,
8
+ TransactionArg,
9
+ TransactionRes,
10
+ } from "../../bot/types";
6
11
  import type { Transaction } from "./types";
7
12
  import { pickSiblings } from "../../bot/specs";
8
13
  import { isAccountEmpty } from "../../account";
9
14
 
10
15
  const currency = getCryptoCurrencyById("hedera");
16
+ const memoTestMessage = "This is a test memo.";
11
17
 
12
18
  // Ensure that, when the recipient corresponds to an empty account,
13
19
  // the amount to send is greater or equal to the required minimum
@@ -41,7 +47,11 @@ const hedera: AppSpec<Transaction> = {
41
47
  {
42
48
  name: "Send ~50%",
43
49
  maxRun: 2,
44
- transaction: ({ account, siblings, bridge }) => {
50
+ transaction: ({
51
+ account,
52
+ siblings,
53
+ bridge,
54
+ }: TransactionArg<Transaction>): TransactionRes<Transaction> => {
45
55
  const sibling = pickSiblings(siblings, 4);
46
56
  const recipient = sibling.freshAddress;
47
57
 
@@ -58,7 +68,11 @@ const hedera: AppSpec<Transaction> = {
58
68
  updates: [{ amount }, { recipient }],
59
69
  };
60
70
  },
61
- test: ({ account, accountBeforeTransaction, operation }) => {
71
+ test: ({
72
+ account,
73
+ accountBeforeTransaction,
74
+ operation,
75
+ }: TransactionTestInput<Transaction>): void => {
62
76
  expect(account.balance.toString()).toBe(
63
77
  accountBeforeTransaction.balance.minus(operation.value).toString()
64
78
  );
@@ -67,7 +81,11 @@ const hedera: AppSpec<Transaction> = {
67
81
  {
68
82
  name: "Send max",
69
83
  maxRun: 2,
70
- transaction: ({ account, siblings, bridge }) => {
84
+ transaction: ({
85
+ account,
86
+ siblings,
87
+ bridge,
88
+ }: TransactionArg<Transaction>): TransactionRes<Transaction> => {
71
89
  const sibling = pickSiblings(siblings, 4);
72
90
  const recipient = sibling.freshAddress;
73
91
 
@@ -78,7 +96,12 @@ const hedera: AppSpec<Transaction> = {
78
96
  updates: [{ recipient }, { useAllAmount: true }],
79
97
  };
80
98
  },
81
- test: ({ accountBeforeTransaction, account, operation, transaction }) => {
99
+ test: ({
100
+ accountBeforeTransaction,
101
+ account,
102
+ operation,
103
+ transaction,
104
+ }: TransactionTestInput<Transaction>): void => {
82
105
  const accountBalanceAfterTx = account.balance.toNumber();
83
106
 
84
107
  // NOTE: operation.fee is the ACTUAL (not estimated) fee cost of the transaction
@@ -89,6 +112,34 @@ const hedera: AppSpec<Transaction> = {
89
112
  expect(accountBalanceAfterTx).toBe(amount);
90
113
  },
91
114
  },
115
+ {
116
+ name: "Memo",
117
+ maxRun: 2,
118
+ transaction: ({
119
+ account,
120
+ siblings,
121
+ bridge,
122
+ }: TransactionArg<Transaction>): TransactionRes<Transaction> => {
123
+ const sibling = pickSiblings(siblings, 4);
124
+ const recipient = sibling.freshAddress;
125
+
126
+ const transaction = bridge.createTransaction(account);
127
+
128
+ const amount = account.balance
129
+ .div(1.9 + 0.2 * Math.random())
130
+ .integerValue();
131
+
132
+ checkSendableToEmptyAccount(amount, sibling);
133
+
134
+ return {
135
+ transaction,
136
+ updates: [{ recipient }, { amount }, { memo: memoTestMessage }],
137
+ };
138
+ },
139
+ test: ({ transaction }: TransactionTestInput<Transaction>): void => {
140
+ expect(transaction.memo).toBe(memoTestMessage);
141
+ },
142
+ },
92
143
  ],
93
144
  };
94
145
 
@@ -53,6 +53,7 @@ const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
53
53
  {
54
54
  title: "Memo",
55
55
  button: "Rr",
56
+ expectedValue: ({ transaction }) => transaction.memo as string,
56
57
  },
57
58
  {
58
59
  title: "Confirm",
@@ -29,6 +29,7 @@ export function fromTransactionRaw(tr: TransactionRaw): Transaction {
29
29
  return {
30
30
  ...common,
31
31
  family: tr.family,
32
+ memo: tr.memo,
32
33
  };
33
34
  }
34
35
 
@@ -38,6 +39,7 @@ export function toTransactionRaw(t: Transaction): TransactionRaw {
38
39
  return {
39
40
  ...common,
40
41
  family: t.family,
42
+ memo: t.memo,
41
43
  };
42
44
  }
43
45
 
@@ -3,11 +3,6 @@ import type {
3
3
  TransactionCommonRaw,
4
4
  } from "../../types/transaction";
5
5
 
6
- export type CoreStatics = Record<string, never>;
7
- export type CoreAccountSpecifics = Record<string, never>;
8
- export type CoreOperationSpecifics = Record<string, never>;
9
- export type CoreCurrencySpecifics = Record<string, never>;
10
-
11
6
  export type NetworkInfo = {
12
7
  family: "hedera";
13
8
  };
@@ -18,11 +13,10 @@ export type NetworkInfoRaw = {
18
13
 
19
14
  export type Transaction = TransactionCommon & {
20
15
  family: "hedera";
16
+ memo?: string;
21
17
  };
22
18
 
23
19
  export type TransactionRaw = TransactionCommonRaw & {
24
20
  family: "hedera";
21
+ memo?: string;
25
22
  };
26
-
27
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
28
- export const reflect = (_declare: any) => {};
@@ -31,7 +31,7 @@ export async function calculateAmount({
31
31
  }
32
32
 
33
33
  // NOTE: convert from the non-url-safe version of base64 to the url-safe version (that the explorer uses)
34
- export function base64ToUrlSafeBase64(data: string) {
34
+ export function base64ToUrlSafeBase64(data: string): string {
35
35
  // Might be nice to use this alternative if .nvmrc changes to >= Node v14.18.0
36
36
  // base64url encoding option isn't supported until then
37
37
  // Buffer.from(data, "base64").toString("base64url");
@@ -6,6 +6,7 @@ export type FeatureId =
6
6
  | "ratings"
7
7
  | "counterValue"
8
8
  | "buyDeviceFromLive"
9
+ | "ptxSmartRouting"
9
10
  | string;
10
11
 
11
12
  // We use objects instead of direct booleans for potential future improvements
@@ -2,6 +2,8 @@ import algorand from "../families/algorand/deviceTransactionConfig";
2
2
 
3
3
  import bitcoin from "../families/bitcoin/deviceTransactionConfig";
4
4
 
5
+ import cardano from "../families/cardano/deviceTransactionConfig";
6
+
5
7
  import celo from "../families/celo/deviceTransactionConfig";
6
8
 
7
9
  import cosmos from "../families/cosmos/deviceTransactionConfig";
@@ -32,6 +34,7 @@ import tron from "../families/tron/deviceTransactionConfig";
32
34
  export default {
33
35
  algorand,
34
36
  bitcoin,
37
+ cardano,
35
38
  celo,
36
39
  cosmos,
37
40
  crypto_org,
@@ -10,7 +10,7 @@ const manifest: AppManifest[] = [
10
10
  supportUrl: "https://paraswap.io",
11
11
  icon: "https://cdn.live.ledger.com/icons/platform/paraswap.png",
12
12
  platform: "all",
13
- apiVersion: "0.0.1",
13
+ apiVersion: "^1.0.0 || ~0.0.1",
14
14
  manifestVersion: "1",
15
15
  branch: "stable",
16
16
  params: ["accountId"],
@@ -56,7 +56,7 @@ const manifest: AppManifest[] = [
56
56
  homepageUrl: "https://lido.fi/",
57
57
  icon: "https://cdn.live.ledger.com/icons/platform/lido.png",
58
58
  platform: "all",
59
- apiVersion: "0.0.1",
59
+ apiVersion: "^1.0.0 || ~0.0.1",
60
60
  manifestVersion: "1",
61
61
  branch: "stable",
62
62
  categories: ["staking", "defi"],
@@ -79,7 +79,7 @@ const manifest: AppManifest[] = [
79
79
  homepageUrl: "https://www.sendwyre.com/",
80
80
  icon: "https://cdn.live.ledger.com/icons/platform/wyre.png",
81
81
  platform: "all",
82
- apiVersion: "0.0.1",
82
+ apiVersion: "^1.0.0 || ~0.0.1",
83
83
  manifestVersion: "1",
84
84
  branch: "stable",
85
85
  categories: ["exchange", "buy"],
@@ -109,7 +109,7 @@ const manifest: AppManifest[] = [
109
109
  homepageUrl: "https://zerion.io/",
110
110
  icon: "https://cdn.live.ledger.com/icons/platform/zerion.png",
111
111
  platform: "all",
112
- apiVersion: "0.0.1",
112
+ apiVersion: "^1.0.0 || ~0.0.1",
113
113
  manifestVersion: "1",
114
114
  branch: "stable",
115
115
  categories: ["portfolio", "defi"],
@@ -132,7 +132,7 @@ const manifest: AppManifest[] = [
132
132
  homepageUrl: "https://rainbow.me",
133
133
  icon: "https://cdn.live.ledger.com/icons/platform/rainbow.png",
134
134
  platform: "all",
135
- apiVersion: "0.0.1",
135
+ apiVersion: "^1.0.0 || ~0.0.1",
136
136
  manifestVersion: "1",
137
137
  branch: "stable",
138
138
  categories: ["nft"],
@@ -155,7 +155,7 @@ const manifest: AppManifest[] = [
155
155
  homepageUrl: "https://aave.com/",
156
156
  icon: "https://cdn.live.ledger.com/icons/platform/aave.png",
157
157
  platform: "all",
158
- apiVersion: "0.0.1",
158
+ apiVersion: "^1.0.0 || ~0.0.1",
159
159
  manifestVersion: "1",
160
160
  branch: "soon",
161
161
  categories: ["lend"],
@@ -178,7 +178,7 @@ const manifest: AppManifest[] = [
178
178
  homepageUrl: "https://compound.finance/",
179
179
  icon: "https://cdn.live.ledger.com/icons/platform/compound.png",
180
180
  platform: "all",
181
- apiVersion: "0.0.1",
181
+ apiVersion: "^1.0.0 || ~0.0.1",
182
182
  manifestVersion: "1",
183
183
  branch: "soon",
184
184
  categories: ["lend", "compound"],
@@ -201,7 +201,7 @@ const manifest: AppManifest[] = [
201
201
  homepageUrl: "https://www.deversifi.com/",
202
202
  icon: "https://cdn.live.ledger.com/icons/platform/deversifi.png",
203
203
  platform: "all",
204
- apiVersion: "0.0.1",
204
+ apiVersion: "^1.0.0 || ~0.0.1",
205
205
  manifestVersion: "1",
206
206
  branch: "soon",
207
207
  categories: ["dex"],
@@ -224,7 +224,7 @@ const manifest: AppManifest[] = [
224
224
  homepageUrl: "https://1inch.io/",
225
225
  icon: "https://cdn.live.ledger.com/icons/platform/1inch.png",
226
226
  platform: "all",
227
- apiVersion: "0.0.1",
227
+ apiVersion: "^1.0.0 || ~0.0.1",
228
228
  manifestVersion: "1",
229
229
  branch: "soon",
230
230
  categories: ["swap", "defi"],
@@ -247,7 +247,7 @@ const manifest: AppManifest[] = [
247
247
  homepageUrl: "https://developers.ledger.com/",
248
248
  icon: "https://cdn.live.ledger.com/icons/platform/debugger.png",
249
249
  platform: "all",
250
- apiVersion: "0.0.1",
250
+ apiVersion: "^1.0.0 || ~0.0.1",
251
251
  manifestVersion: "1",
252
252
  branch: "debug",
253
253
  categories: ["tools"],
@@ -274,7 +274,7 @@ const manifest: AppManifest[] = [
274
274
  homepageUrl: "https://developers.ledger.com/",
275
275
  icon: "",
276
276
  platform: "all",
277
- apiVersion: "0.0.1",
277
+ apiVersion: "^1.0.0 || ~0.0.1",
278
278
  manifestVersion: "1",
279
279
  branch: "stable",
280
280
  categories: ["tools"],
@@ -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
- }