@ledgerhq/live-common 27.0.1-next.0 → 27.1.0-next.2

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 (190) hide show
  1. package/lib/account/serialization.d.ts +2 -0
  2. package/lib/account/serialization.d.ts.map +1 -1
  3. package/lib/account/serialization.js +23 -8
  4. package/lib/account/serialization.js.map +1 -1
  5. package/lib/api/explorerConfig/index.js +1 -1
  6. package/lib/api/explorerConfig/index.js.map +1 -1
  7. package/lib/apps/support.d.ts.map +1 -1
  8. package/lib/apps/support.js +1 -0
  9. package/lib/apps/support.js.map +1 -1
  10. package/lib/families/celo/api/hubble.d.ts +6 -1
  11. package/lib/families/celo/api/hubble.d.ts.map +1 -1
  12. package/lib/families/celo/api/hubble.js +135 -13
  13. package/lib/families/celo/api/hubble.js.map +1 -1
  14. package/lib/families/celo/api/index.d.ts +1 -1
  15. package/lib/families/celo/api/index.d.ts.map +1 -1
  16. package/lib/families/celo/api/index.js +2 -1
  17. package/lib/families/celo/api/index.js.map +1 -1
  18. package/lib/families/celo/api/sdk.d.ts +22 -0
  19. package/lib/families/celo/api/sdk.d.ts.map +1 -1
  20. package/lib/families/celo/api/sdk.js +168 -1
  21. package/lib/families/celo/api/sdk.js.map +1 -1
  22. package/lib/families/celo/bridge/js.d.ts.map +1 -1
  23. package/lib/families/celo/bridge/js.js +4 -42
  24. package/lib/families/celo/bridge/js.js.map +1 -1
  25. package/lib/families/celo/cli-transaction.d.ts +12 -2
  26. package/lib/families/celo/cli-transaction.d.ts.map +1 -1
  27. package/lib/families/celo/cli-transaction.js +38 -4
  28. package/lib/families/celo/cli-transaction.js.map +1 -1
  29. package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts +1 -0
  30. package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts.map +1 -1
  31. package/lib/families/celo/datasets/celo.scanAccounts.1.js +298 -2
  32. package/lib/families/celo/datasets/celo.scanAccounts.1.js.map +1 -1
  33. package/lib/families/celo/errors.d.ts +2 -0
  34. package/lib/families/celo/errors.d.ts.map +1 -0
  35. package/lib/families/celo/errors.js +6 -0
  36. package/lib/families/celo/errors.js.map +1 -0
  37. package/lib/families/celo/js-buildTransaction.d.ts +2 -3
  38. package/lib/families/celo/js-buildTransaction.d.ts.map +1 -1
  39. package/lib/families/celo/js-buildTransaction.js +194 -19
  40. package/lib/families/celo/js-buildTransaction.js.map +1 -1
  41. package/lib/families/celo/js-createTransaction.d.ts.map +1 -1
  42. package/lib/families/celo/js-createTransaction.js +3 -1
  43. package/lib/families/celo/js-createTransaction.js.map +1 -1
  44. package/lib/families/celo/js-estimateMaxSpendable.d.ts.map +1 -1
  45. package/lib/families/celo/js-estimateMaxSpendable.js.map +1 -1
  46. package/lib/families/celo/js-getFeesForTransaction.d.ts +2 -3
  47. package/lib/families/celo/js-getFeesForTransaction.d.ts.map +1 -1
  48. package/lib/families/celo/js-getFeesForTransaction.js +137 -10
  49. package/lib/families/celo/js-getFeesForTransaction.js.map +1 -1
  50. package/lib/families/celo/js-getTransactionStatus.d.ts +2 -3
  51. package/lib/families/celo/js-getTransactionStatus.d.ts.map +1 -1
  52. package/lib/families/celo/js-getTransactionStatus.js +97 -41
  53. package/lib/families/celo/js-getTransactionStatus.js.map +1 -1
  54. package/lib/families/celo/js-prepareTransaction.d.ts +2 -3
  55. package/lib/families/celo/js-prepareTransaction.d.ts.map +1 -1
  56. package/lib/families/celo/js-prepareTransaction.js +8 -3
  57. package/lib/families/celo/js-prepareTransaction.js.map +1 -1
  58. package/lib/families/celo/js-signOperation.d.ts.map +1 -1
  59. package/lib/families/celo/js-signOperation.js +17 -3
  60. package/lib/families/celo/js-signOperation.js.map +1 -1
  61. package/lib/families/celo/js-synchronisation.d.ts.map +1 -1
  62. package/lib/families/celo/js-synchronisation.js +51 -6
  63. package/lib/families/celo/js-synchronisation.js.map +1 -1
  64. package/lib/families/celo/logic.d.ts +21 -0
  65. package/lib/families/celo/logic.d.ts.map +1 -0
  66. package/lib/families/celo/logic.js +132 -0
  67. package/lib/families/celo/logic.js.map +1 -0
  68. package/lib/families/celo/preload.d.ts +10 -0
  69. package/lib/families/celo/preload.d.ts.map +1 -0
  70. package/lib/families/celo/preload.js +118 -0
  71. package/lib/families/celo/preload.js.map +1 -0
  72. package/lib/families/celo/react.d.ts +4 -0
  73. package/lib/families/celo/react.d.ts.map +1 -0
  74. package/lib/families/celo/react.js +47 -0
  75. package/lib/families/celo/react.js.map +1 -0
  76. package/lib/families/celo/serialization.d.ts +4 -0
  77. package/lib/families/celo/serialization.d.ts.map +1 -0
  78. package/lib/families/celo/serialization.js +55 -0
  79. package/lib/families/celo/serialization.js.map +1 -0
  80. package/lib/families/celo/specs/createActivateVoteMutation.d.ts +4 -0
  81. package/lib/families/celo/specs/createActivateVoteMutation.d.ts.map +1 -0
  82. package/lib/families/celo/specs/createActivateVoteMutation.js +38 -0
  83. package/lib/families/celo/specs/createActivateVoteMutation.js.map +1 -0
  84. package/lib/families/celo/specs/createLockMutation.d.ts +4 -0
  85. package/lib/families/celo/specs/createLockMutation.d.ts.map +1 -0
  86. package/lib/families/celo/specs/createLockMutation.js +40 -0
  87. package/lib/families/celo/specs/createLockMutation.js.map +1 -0
  88. package/lib/families/celo/specs/createRegisterAccountMutation.d.ts +4 -0
  89. package/lib/families/celo/specs/createRegisterAccountMutation.d.ts.map +1 -0
  90. package/lib/families/celo/specs/createRegisterAccountMutation.js +31 -0
  91. package/lib/families/celo/specs/createRegisterAccountMutation.js.map +1 -0
  92. package/lib/families/celo/specs/createRevokeVoteMutation.d.ts +4 -0
  93. package/lib/families/celo/specs/createRevokeVoteMutation.d.ts.map +1 -0
  94. package/lib/families/celo/specs/createRevokeVoteMutation.js +39 -0
  95. package/lib/families/celo/specs/createRevokeVoteMutation.js.map +1 -0
  96. package/lib/families/celo/specs/createSendMutation.d.ts +5 -0
  97. package/lib/families/celo/specs/createSendMutation.d.ts.map +1 -0
  98. package/lib/families/celo/specs/createSendMutation.js +44 -0
  99. package/lib/families/celo/specs/createSendMutation.js.map +1 -0
  100. package/lib/families/celo/specs/createUnlockMutation.d.ts +4 -0
  101. package/lib/families/celo/specs/createUnlockMutation.d.ts.map +1 -0
  102. package/lib/families/celo/specs/createUnlockMutation.js +37 -0
  103. package/lib/families/celo/specs/createUnlockMutation.js.map +1 -0
  104. package/lib/families/celo/specs/createVoteMutation.d.ts +4 -0
  105. package/lib/families/celo/specs/createVoteMutation.d.ts.map +1 -0
  106. package/lib/families/celo/specs/createVoteMutation.js +51 -0
  107. package/lib/families/celo/specs/createVoteMutation.js.map +1 -0
  108. package/lib/families/celo/specs/createWithdrawMutation.d.ts +4 -0
  109. package/lib/families/celo/specs/createWithdrawMutation.d.ts.map +1 -0
  110. package/lib/families/celo/specs/createWithdrawMutation.js +36 -0
  111. package/lib/families/celo/specs/createWithdrawMutation.js.map +1 -0
  112. package/lib/families/celo/specs/index.d.ts +9 -0
  113. package/lib/families/celo/specs/index.d.ts.map +1 -0
  114. package/lib/families/celo/specs/index.js +25 -0
  115. package/lib/families/celo/specs/index.js.map +1 -0
  116. package/lib/families/celo/specs.d.ts +1 -1
  117. package/lib/families/celo/specs.d.ts.map +1 -1
  118. package/lib/families/celo/specs.js +20 -37
  119. package/lib/families/celo/specs.js.map +1 -1
  120. package/lib/families/celo/speculos-deviceActions.d.ts.map +1 -1
  121. package/lib/families/celo/speculos-deviceActions.js +22 -0
  122. package/lib/families/celo/speculos-deviceActions.js.map +1 -1
  123. package/lib/families/celo/transaction.d.ts.map +1 -1
  124. package/lib/families/celo/transaction.js +8 -6
  125. package/lib/families/celo/transaction.js.map +1 -1
  126. package/lib/families/celo/types.d.ts +102 -1
  127. package/lib/families/celo/types.d.ts.map +1 -1
  128. package/lib/families/celo/validators.d.ts +3 -0
  129. package/lib/families/celo/validators.d.ts.map +1 -0
  130. package/lib/families/celo/validators.js +6 -0
  131. package/lib/families/celo/validators.js.map +1 -0
  132. package/lib/families/cosmos/banner.d.ts +10 -0
  133. package/lib/families/cosmos/banner.d.ts.map +1 -0
  134. package/lib/families/cosmos/banner.js +133 -0
  135. package/lib/families/cosmos/banner.js.map +1 -0
  136. package/lib/families/cosmos/banner.test.d.ts +2 -0
  137. package/lib/families/cosmos/banner.test.d.ts.map +1 -0
  138. package/lib/families/cosmos/banner.test.js +233 -0
  139. package/lib/families/cosmos/banner.test.js.map +1 -0
  140. package/lib/families/solana/api/chain/instruction/token/types.d.ts +2 -2
  141. package/lib/generated/cli-transaction.d.ts +12 -2
  142. package/lib/generated/cli-transaction.d.ts.map +1 -1
  143. package/lib/operation.d.ts.map +1 -1
  144. package/lib/operation.js +6 -0
  145. package/lib/operation.js.map +1 -1
  146. package/lib/reconciliation.d.ts.map +1 -1
  147. package/lib/reconciliation.js +11 -0
  148. package/lib/reconciliation.js.map +1 -1
  149. package/package.json +3 -4
  150. package/src/account/serialization.ts +22 -2
  151. package/src/api/explorerConfig/index.ts +1 -1
  152. package/src/apps/support.ts +1 -0
  153. package/src/families/celo/__snapshots__/bridge.integration.test.ts.snap +134 -857
  154. package/src/families/celo/api/hubble.ts +113 -16
  155. package/src/families/celo/api/index.ts +1 -1
  156. package/src/families/celo/api/sdk.ts +88 -0
  157. package/src/families/celo/bridge/js.ts +2 -3
  158. package/src/families/celo/cli-transaction.ts +46 -2
  159. package/src/families/celo/datasets/celo.scanAccounts.1.ts +365 -5
  160. package/src/families/celo/errors.ts +5 -0
  161. package/src/families/celo/js-buildTransaction.ts +173 -20
  162. package/src/families/celo/js-createTransaction.ts +2 -0
  163. package/src/families/celo/js-estimateMaxSpendable.ts +2 -2
  164. package/src/families/celo/js-getFeesForTransaction.ts +118 -19
  165. package/src/families/celo/js-getTransactionStatus.ts +72 -17
  166. package/src/families/celo/js-prepareTransaction.ts +13 -7
  167. package/src/families/celo/js-signOperation.ts +22 -5
  168. package/src/families/celo/js-synchronisation.ts +32 -0
  169. package/src/families/celo/logic.ts +184 -0
  170. package/src/families/celo/preload.ts +78 -0
  171. package/src/families/celo/react.ts +35 -0
  172. package/src/families/celo/serialization.ts +61 -0
  173. package/src/families/celo/specs/createActivateVoteMutation.ts +44 -0
  174. package/src/families/celo/specs/createLockMutation.ts +46 -0
  175. package/src/families/celo/specs/createRegisterAccountMutation.ts +34 -0
  176. package/src/families/celo/specs/createRevokeVoteMutation.ts +43 -0
  177. package/src/families/celo/specs/createSendMutation.ts +44 -0
  178. package/src/families/celo/specs/createUnlockMutation.ts +44 -0
  179. package/src/families/celo/specs/createVoteMutation.ts +67 -0
  180. package/src/families/celo/specs/createWithdrawMutation.ts +44 -0
  181. package/src/families/celo/specs/index.ts +8 -0
  182. package/src/families/celo/specs.ts +32 -34
  183. package/src/families/celo/speculos-deviceActions.ts +21 -2
  184. package/src/families/celo/transaction.ts +12 -4
  185. package/src/families/celo/types.ts +113 -0
  186. package/src/families/celo/validators.ts +2 -0
  187. package/src/families/cosmos/banner.test.ts +160 -0
  188. package/src/families/cosmos/banner.ts +87 -0
  189. package/src/operation.ts +6 -0
  190. package/src/reconciliation.ts +22 -0
@@ -3,6 +3,9 @@ import network from "../../../network";
3
3
  import { getEnv } from "../../../env";
4
4
  import { Operation, OperationType } from "@ledgerhq/types-live";
5
5
  import { encodeOperationId } from "../../../operation";
6
+ import { CeloValidatorGroup, FigmentIndexerTransaction } from "../types";
7
+ import { isDefaultValidatorGroup } from "../logic";
8
+ import { celoKit } from "./sdk";
6
9
 
7
10
  const DEFAULT_TRANSACTIONS_LIMIT = 200;
8
11
  const getUrl = (route): string => `${getEnv("API_CELO_INDEXER")}${route || ""}`;
@@ -28,12 +31,36 @@ const fetchStatus = async () => {
28
31
  return data;
29
32
  };
30
33
 
34
+ const fetchValidatorGroups = async () => {
35
+ const { data } = await network({
36
+ method: "GET",
37
+ url: getUrl(`/validator_groups`),
38
+ });
39
+ return data.items;
40
+ };
41
+
31
42
  const getOperationType = (type: string): OperationType => {
32
43
  switch (type) {
33
44
  case "InternalTransferSent":
34
45
  return "OUT";
35
46
  case "InternalTransferReceived":
36
47
  return "IN";
48
+ case "GoldLocked":
49
+ return "LOCK";
50
+ case "GoldUnlocked":
51
+ return "UNLOCK";
52
+ case "GoldWithdrawn":
53
+ return "WITHDRAW";
54
+ case "ValidatorGroupVoteCastSent":
55
+ return "VOTE";
56
+ case "ValidatorGroupActiveVoteRevokedSent":
57
+ return "REVOKE";
58
+ case "ValidatorGroupPendingVoteRevokedSent":
59
+ return "REVOKE";
60
+ case "ValidatorGroupVoteActivatedSent":
61
+ return "ACTIVATE";
62
+ case "AccountCreated":
63
+ return "REGISTER";
37
64
  case "AccountSlashed":
38
65
  return "SLASH";
39
66
  default:
@@ -44,44 +71,87 @@ const getOperationType = (type: string): OperationType => {
44
71
  const transactionToOperation = (
45
72
  address: string,
46
73
  accountId: string,
47
- transaction
74
+ transaction: FigmentIndexerTransaction
48
75
  ): Operation => {
49
76
  const type: OperationType = getOperationType(transaction.kind);
50
- const hasFailed = transaction.data.success
51
- ? !transaction.data.success
77
+ const hasFailed = transaction.data?.success
78
+ ? !transaction.data?.success
52
79
  : false;
53
- const senders = transaction.data.from ? [transaction.data.from] : [];
54
- const recipients = transaction.data.to ? [transaction.data.to] : [];
80
+ const data = transaction.data;
81
+ const sender = data?.Account || data?.from;
82
+ const recipient = data?.Group || data?.to || data?.Raw?.address;
83
+ const fee = new BigNumber(transaction.data?.gas_used || 0).times(
84
+ new BigNumber(transaction.data?.gas_price || 0)
85
+ );
86
+
87
+ const value = [
88
+ "LOCK",
89
+ "UNLOCK",
90
+ "ACTIVATE",
91
+ "VOTE",
92
+ "REVOKE",
93
+ "REGISTER",
94
+ ].includes(type)
95
+ ? new BigNumber(fee)
96
+ : new BigNumber(transaction.amount);
55
97
 
56
98
  return {
57
99
  id: encodeOperationId(accountId, transaction.transaction_hash, type),
58
100
  hash: transaction.transaction_hash,
59
101
  accountId,
60
- fee: new BigNumber(0),
61
- value: new BigNumber(transaction.amount),
102
+ fee,
103
+ value,
62
104
  type,
63
105
  blockHeight: transaction.height,
64
106
  date: new Date(transaction.time),
65
- senders,
66
- recipients,
107
+ senders: sender ? [sender] : [],
108
+ recipients: recipient ? [recipient] : [],
67
109
  hasFailed,
68
110
  blockHash: null,
69
- extra: {},
111
+ extra: {
112
+ celoOperationValue: new BigNumber(transaction.amount),
113
+ ...(["ACTIVATE", "VOTE", "REVOKE"].includes(type)
114
+ ? {
115
+ celoSourceValidator: recipient,
116
+ }
117
+ : {}),
118
+ },
70
119
  };
71
120
  };
72
121
 
73
- export const getAccountDetails = async (address: string, accountId: string) => {
122
+ export const getAccountDetails = async (
123
+ address: string,
124
+ accountId: string
125
+ ): Promise<{
126
+ blockHeight: any;
127
+ balance: BigNumber;
128
+ spendableBalance: BigNumber;
129
+ operations: Operation[];
130
+ lockedBalance: BigNumber;
131
+ nonvotingLockedBalance: BigNumber;
132
+ }> => {
74
133
  const accountDetails = await fetchAccountDetails(address);
75
134
  const spendableBalance = new BigNumber(accountDetails.gold_balance);
76
135
  const lockedBalance = new BigNumber(accountDetails.total_locked_gold);
136
+ const nonvotingLockedBalance = new BigNumber(
137
+ accountDetails.total_nonvoting_locked_gold
138
+ );
77
139
  const balance = spendableBalance.plus(lockedBalance);
78
140
  const indexerStatus = await fetchStatus();
141
+ const kit = celoKit();
142
+ const lockedGold = await kit.contracts.getLockedGold();
79
143
 
80
- const allTransactions = accountDetails.internal_transfers.concat(
81
- accountDetails.transactions
82
- );
83
- const operations = allTransactions.map((transaction) =>
84
- transactionToOperation(address, accountId, transaction)
144
+ const allTransactions = accountDetails.internal_transfers
145
+ .filter(
146
+ (transfer) =>
147
+ transfer.data?.to != lockedGold.address &&
148
+ transfer.data?.from != lockedGold.address
149
+ )
150
+ .concat(accountDetails.transactions);
151
+
152
+ const operations: Operation[] = allTransactions.map(
153
+ (transaction: FigmentIndexerTransaction) =>
154
+ transactionToOperation(address, accountId, transaction)
85
155
  );
86
156
 
87
157
  return {
@@ -89,5 +159,32 @@ export const getAccountDetails = async (address: string, accountId: string) => {
89
159
  balance,
90
160
  spendableBalance,
91
161
  operations,
162
+ lockedBalance,
163
+ nonvotingLockedBalance,
92
164
  };
93
165
  };
166
+
167
+ export const getValidatorGroups = async (): Promise<CeloValidatorGroup[]> => {
168
+ const validatorGroups = await fetchValidatorGroups();
169
+
170
+ const result = validatorGroups.map((validatorGroup) => ({
171
+ address: validatorGroup.address,
172
+ name: validatorGroup.name || validatorGroup.address,
173
+ votes: new BigNumber(validatorGroup.active_votes).plus(
174
+ new BigNumber(validatorGroup.pending_votes)
175
+ ),
176
+ }));
177
+ return customValidatorGroupsOrder(result);
178
+ };
179
+
180
+ const customValidatorGroupsOrder = (validatorGroups): CeloValidatorGroup[] => {
181
+ const defaultValidatorGroup = validatorGroups.find(isDefaultValidatorGroup);
182
+
183
+ const sortedValidatorGroups = [...validatorGroups]
184
+ .sort((a, b) => b.votes.minus(a.votes))
185
+ .filter((group) => !isDefaultValidatorGroup(group));
186
+
187
+ return defaultValidatorGroup
188
+ ? [defaultValidatorGroup, ...sortedValidatorGroups]
189
+ : sortedValidatorGroups;
190
+ };
@@ -1 +1 @@
1
- export { getAccountDetails } from "./hubble";
1
+ export { getAccountDetails, getValidatorGroups } from "./hubble";
@@ -1,8 +1,96 @@
1
1
  import { ContractKit, newKit } from "@celo/contractkit";
2
2
  import { getEnv } from "../../../env";
3
+ import { CeloVote } from "../types";
4
+ import { makeLRUCache } from "../../../cache";
3
5
 
4
6
  let kit: ContractKit;
5
7
  export const celoKit = () => {
6
8
  if (!kit) kit = newKit(getEnv("API_CELO_NODE"));
7
9
  return kit;
8
10
  };
11
+
12
+ /**
13
+ * Fetch account registered status. To lock any Celo, account needs to be registered first
14
+ */
15
+ export const getAccountRegistrationStatus = async (
16
+ address: string
17
+ ): Promise<boolean> => {
18
+ const accounts = await celoKit().contracts.getAccounts();
19
+ return await accounts.isAccount(address);
20
+ };
21
+
22
+ /**
23
+ * Fetch pending withdrawals, with an index
24
+ */
25
+ export const getPendingWithdrawals = async (address: string) => {
26
+ const lockedGold = await celoKit().contracts.getLockedGold();
27
+ const pendingWithdrawals = await lockedGold.getPendingWithdrawals(address);
28
+ const pendingWithdrawalsWithIndexes = pendingWithdrawals
29
+ .map((withdrawal, index) => ({
30
+ ...withdrawal,
31
+ index,
32
+ }))
33
+ .sort((a, b) => a.time.minus(b.time).toNumber());
34
+ return pendingWithdrawalsWithIndexes;
35
+ };
36
+
37
+ /**
38
+ * Fetch all votes
39
+ */
40
+ export const getVotes = async (address: string): Promise<CeloVote[]> => {
41
+ const election = await celoKit().contracts.getElection();
42
+ const voter = await election.getVoter(await voteSignerAccount(address));
43
+ const activates = await getActivateTransactionObjects(address);
44
+ const activatableValidatorGroups = activates.map(
45
+ (activate) => activate.txo.arguments[0]
46
+ );
47
+
48
+ const votes: CeloVote[] = [];
49
+ voter.votes.forEach((vote) => {
50
+ let activeVoteRevokable = true;
51
+ if (vote.pending.gt(0)) {
52
+ // If there's a pending vote, it has to be revoked first
53
+ activeVoteRevokable = false;
54
+ votes.push({
55
+ validatorGroup: vote.group,
56
+ amount: vote.pending,
57
+ // Not all pending votes can be activated, 24h has to pass
58
+ activatable: activatableValidatorGroups.includes(vote.group),
59
+ revokable: true,
60
+ index: 0,
61
+ type: "pending",
62
+ });
63
+ }
64
+ if (vote.active.gt(0))
65
+ votes.push({
66
+ validatorGroup: vote.group,
67
+ amount: vote.active,
68
+ activatable: false,
69
+ revokable: activeVoteRevokable,
70
+ index: 1,
71
+ type: "active",
72
+ });
73
+ });
74
+
75
+ return votes;
76
+ };
77
+
78
+ const getActivateTransactionObjects = async (address: string) => {
79
+ const election = await celoKit().contracts.getElection();
80
+ return await election.activate(await voteSignerAccount(address));
81
+ };
82
+
83
+ /**
84
+ * Fetch and cache address of a vote signer account
85
+ * Cache it for 1h since vote signer is usually the same account as our address
86
+ */
87
+ export const voteSignerAccount = makeLRUCache(
88
+ async (address: string): Promise<string> => {
89
+ const accounts = await celoKit().contracts.getAccounts();
90
+ return await accounts.voteSignerToAccount(address);
91
+ },
92
+ (address) => address,
93
+ {
94
+ maxAge: 60 * 60 * 1000, // 1 hour
95
+ }
96
+ );
@@ -2,6 +2,7 @@ import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
2
2
  import type { Transaction } from "../types";
3
3
  import { makeAccountBridgeReceive } from "../../../bridge/jsHelpers";
4
4
  import { sync, scanAccounts } from "../js-synchronisation";
5
+ import { getPreloadStrategy, preload, hydrate } from "../preload";
5
6
  import signOperation from "../js-signOperation";
6
7
  import getTransactionStatus from "../js-getTransactionStatus";
7
8
  import broadcast from "../js-broadcast";
@@ -13,10 +14,8 @@ const updateTransaction = (t, patch) => ({ ...t, ...patch });
13
14
 
14
15
  const receive = makeAccountBridgeReceive();
15
16
 
16
- const preload = async () => Promise.resolve({});
17
- const hydrate = (): void => {};
18
-
19
17
  const currencyBridge: CurrencyBridge = {
18
+ getPreloadStrategy,
20
19
  preload,
21
20
  hydrate,
22
21
  scanAccounts,
@@ -3,11 +3,26 @@ import type {
3
3
  AccountLike,
4
4
  AccountLikeArray,
5
5
  } from "@ledgerhq/types-live";
6
+
7
+ import { from } from "rxjs";
8
+ import { map } from "rxjs/operators";
9
+ import { getValidatorGroups } from "../celo/api";
6
10
  import invariant from "invariant";
7
11
  import flatMap from "lodash/flatMap";
8
12
  import type { Transaction } from "../celo/types";
9
13
 
10
- const options = [];
14
+ const options = [
15
+ {
16
+ name: "mode",
17
+ type: String,
18
+ desc: "mode of transaction: send, lock, unlock, withdraw, vote, revoke, activate, register",
19
+ },
20
+ {
21
+ name: "transactionIndex",
22
+ type: String,
23
+ desc: "transaction index of a pending withdraw in case of withdraw mode",
24
+ },
25
+ ];
11
26
 
12
27
  function inferAccounts(account: Account): AccountLikeArray {
13
28
  invariant(account.currency.family === "celo", "celo family");
@@ -21,20 +36,49 @@ function inferTransactions(
21
36
  account: AccountLike;
22
37
  transaction: Transaction;
23
38
  mainAccount: Account;
24
- }>
39
+ }>,
40
+ opts: Record<string, any>
25
41
  ): Transaction[] {
42
+ const mode = opts.mode || "send";
43
+ invariant(
44
+ [
45
+ "send",
46
+ "lock",
47
+ "unlock",
48
+ "withdraw",
49
+ "vote",
50
+ "revoke",
51
+ "activate",
52
+ "register",
53
+ ].includes(mode),
54
+ `Unexpected mode: ${mode}`
55
+ );
56
+
26
57
  return flatMap(transactions, ({ transaction }) => {
27
58
  invariant(transaction.family === "celo", "celo family");
28
59
 
29
60
  return {
30
61
  ...transaction,
31
62
  family: "celo",
63
+ mode,
64
+ index: opts.transactionIndex || null,
32
65
  } as Transaction;
33
66
  });
34
67
  }
35
68
 
69
+ const celoValidatorGroups = {
70
+ args: [],
71
+ job: () =>
72
+ from(getValidatorGroups()).pipe(
73
+ map((validatorGroup) => JSON.stringify(validatorGroup))
74
+ ),
75
+ };
76
+
36
77
  export default {
37
78
  options,
38
79
  inferAccounts,
39
80
  inferTransactions,
81
+ commands: {
82
+ celoValidatorGroups,
83
+ },
40
84
  };