@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
@@ -1,20 +1,380 @@
1
- import type { CurrenciesData } from "@ledgerhq/types-live";
1
+ import BigNumber from "bignumber.js";
2
+ import {
3
+ AmountRequired,
4
+ InvalidAddress,
5
+ InvalidAddressBecauseDestinationIsAlsoSource,
6
+ NotEnoughBalance,
7
+ } from "@ledgerhq/errors";
8
+ import "../../../__tests__/test-helpers/setup";
9
+ import TransactionModule from "../transaction";
10
+ import { CeloAllFundsWarning } from "../errors";
11
+ import type {
12
+ AccountRaw,
13
+ CurrenciesData,
14
+ TransactionStatusCommon,
15
+ } from "@ledgerhq/types-live";
2
16
  import type { Transaction } from "../types";
3
17
 
18
+ // This account is registered for staking and has available funds, locked voting funds,
19
+ // locked non-voting funds, and withdrawable funds.
20
+ const LEDGER_CELO_ACCOUNT_1 = "0xcfD48e0FAf9f19377509cE68a6A6F4D9C85ff8AB";
21
+ // This account has no funds and isn't registered for staking.
22
+ const LEDGER_CELO_ACCOUNT_2 = "0x2cC7E5913bADa8FA2895bDeF7F4C2E36C2368Abb";
23
+ const VALIDATOR_ACCOUNT_1 = "0x0861a61Bf679A30680510EcC238ee43B82C5e843";
24
+
4
25
  const dataset: CurrenciesData<Transaction> = {
5
26
  scanAccounts: [
6
27
  {
7
- name: "celo seed 1",
28
+ name: "Celo 1",
8
29
  apdus: `
9
30
  => e00200000d038000002c8000ce1080000000
10
- <= 41040bd7f9f57b882469eeace7c1b393563e5e1748be7717620a406b4f2d9a01514fe50fcb3366435a99ac21b4f7a807a6ca99782cdb0cb082c49fa6110eb385cadc28336533343162333437436245336232413131363765303643383461366233383543413343396634319000
31
+ <= 410453390dcc1e6f1be0fb34f837b278ed1b4c84097c7493c13a0d915c735af1d8aa445d2738a95e8f50bc22abd2e17cb868d4db22a623d99d861740eb93373d50a328383735443736394535333337363338363732386136374632463564326435666561374637356233399000
11
32
  => e002000015058000002c8000ce10800000000000000000000000
12
- <= 4104d2705d8760cc776edeaef9a99895bcce6e9f19de51640aecf5dcf58be2eca4b9c95882a52c5525b838e69e2b719a6677dfb832b1c0a3f106c303412789621cc928314335443942343735303565314338653432433644443144314435623730423065664334324241309000
33
+ <= 4104eedca4417737f2dae0e12320edba0e845e4ced411e6e2978a9165dde3891099402ff4906ecaab03232f8273592287a94866f14f17b5e2bf6e31837278127919c28636644343865304641663966313933373735303963453638613641364634443943383566663841429000
13
34
  => e002000015058000002c8000ce10800000010000000000000000
14
- <= 41040699e39aa6ee84133dec1f0346f95516ace36d521764823624a2bf0bdfd97bd4b3ddd8f42b08ba251a53ef25a0f658de9fbb57600d2165dab69d10ebf34388a928336337383462383934343964413330313443356261654532374232326263313833343746314639629000
35
+ <= 41042304dfd28a236eb03471986b90f0a3a111537b35766ae8ff78a9f588071f56ec127531a2498b36e856c759bc2734297a07f9f4b331153a8c9c21171f6488884e28326343374535393133624144613846413238393562446546374634433245333643323336384162629000
15
36
  `,
16
37
  },
17
38
  ],
39
+ accounts: [
40
+ {
41
+ // Ignoring the "balance is sum of ops" test since that
42
+ // doesn't seem to take into account staked tokens properly.
43
+ FIXME_tests: ["balance is sum of ops"],
44
+ raw: {
45
+ id: `js:2:celo:${LEDGER_CELO_ACCOUNT_1}:`,
46
+ seedIdentifier:
47
+ "0453390dcc1e6f1be0fb34f837b278ed1b4c84097c7493c13a0d915c735af1d8aa445d2738a95e8f50bc22abd2e17cb868d4db22a623d99d861740eb93373d50a3",
48
+ name: "Celo 1",
49
+ derivationMode: "",
50
+ index: 0,
51
+ freshAddress: LEDGER_CELO_ACCOUNT_1,
52
+ freshAddressPath: "44'/52752'/0'/0/0",
53
+ freshAddresses: [],
54
+ blockHeight: 0,
55
+ operations: [],
56
+ pendingOperations: [],
57
+ currencyId: "celo",
58
+ unitMagnitude: 18,
59
+ lastSyncDate: "",
60
+ balance: "399893159500000000",
61
+ celoResources: {
62
+ registrationStatus: true,
63
+ lockedBalance: "1000000",
64
+ nonvotingLockedBalance: "900000",
65
+ pendingWithdrawals: [],
66
+ votes: [
67
+ {
68
+ validatorGroup: VALIDATOR_ACCOUNT_1,
69
+ amount: "100000",
70
+ activatable: true,
71
+ revokable: true,
72
+ type: "active",
73
+ index: 0,
74
+ },
75
+ ],
76
+ electionAddress: "0x8D6677192144292870907E3Fa8A5527fE55A7ff6",
77
+ lockedGoldAddress: "0x6cC083Aed9e3ebe302A6336dBC7c921C9f03349E",
78
+ },
79
+ } as AccountRaw,
80
+ transactions: [
81
+ {
82
+ name: "Same as Recipient",
83
+ transaction: (t) => ({
84
+ ...t,
85
+ amount: new BigNumber(100),
86
+ recipient: LEDGER_CELO_ACCOUNT_1,
87
+ }),
88
+ expectedStatus: {
89
+ errors: {
90
+ recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
91
+ },
92
+ warnings: {},
93
+ },
94
+ },
95
+ {
96
+ name: "Invalid Address",
97
+ transaction: (t) => ({
98
+ ...t,
99
+ amount: new BigNumber(100),
100
+ recipient: "dsadasdasdasdas",
101
+ }),
102
+ expectedStatus: {
103
+ errors: {
104
+ recipient: new InvalidAddress(),
105
+ },
106
+ warnings: {},
107
+ },
108
+ },
109
+ {
110
+ name: "Amount Required",
111
+ transaction: TransactionModule.fromTransactionRaw({
112
+ family: "celo",
113
+ recipient: LEDGER_CELO_ACCOUNT_2,
114
+ amount: "0",
115
+ mode: "send",
116
+ fees: null,
117
+ index: 0,
118
+ }),
119
+ expectedStatus: {
120
+ errors: {
121
+ amount: new AmountRequired(),
122
+ },
123
+ warnings: {},
124
+ },
125
+ },
126
+ {
127
+ name: "Not enough balance",
128
+ transaction: TransactionModule.fromTransactionRaw({
129
+ family: "celo",
130
+ recipient: LEDGER_CELO_ACCOUNT_2,
131
+ amount: "399893159500000005",
132
+ mode: "send",
133
+ fees: null,
134
+ index: 0,
135
+ }),
136
+ expectedStatus: {
137
+ errors: {
138
+ amount: new NotEnoughBalance(),
139
+ },
140
+ warnings: {},
141
+ },
142
+ },
143
+ {
144
+ name: "[send] use all amount - should warn all funds",
145
+ transaction: (t) => ({
146
+ ...t,
147
+ useAllAmount: true,
148
+ mode: "send",
149
+ recipient: LEDGER_CELO_ACCOUNT_2,
150
+ }),
151
+ expectedStatus: (account) => ({
152
+ errors: {},
153
+ warnings: {
154
+ amount: new CeloAllFundsWarning(),
155
+ },
156
+ totalSpent: account.spendableBalance,
157
+ }),
158
+ },
159
+ {
160
+ name: "Lock - success",
161
+ transaction: (t) => ({
162
+ ...t,
163
+ mode: "lock",
164
+ amount: new BigNumber(5000),
165
+ }),
166
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
167
+ return {
168
+ errors: {},
169
+ warnings: {},
170
+ amount: new BigNumber(5000),
171
+ };
172
+ },
173
+ },
174
+ {
175
+ name: "Unlock - success",
176
+ transaction: (t) => ({
177
+ ...t,
178
+ mode: "unlock",
179
+ amount: new BigNumber(50000),
180
+ }),
181
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
182
+ return {
183
+ errors: {},
184
+ warnings: {},
185
+ amount: new BigNumber(50000),
186
+ };
187
+ },
188
+ },
189
+ {
190
+ name: "Lock - amount required",
191
+ transaction: (t) => ({
192
+ ...t,
193
+ mode: "lock",
194
+ }),
195
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
196
+ return {
197
+ errors: {
198
+ amount: new AmountRequired(),
199
+ },
200
+ warnings: {},
201
+ };
202
+ },
203
+ },
204
+ {
205
+ name: "Unlock - amount required",
206
+ transaction: (t) => ({
207
+ ...t,
208
+ mode: "unlock",
209
+ }),
210
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
211
+ return {
212
+ errors: {
213
+ amount: new AmountRequired(),
214
+ },
215
+ warnings: {},
216
+ };
217
+ },
218
+ },
219
+ {
220
+ name: "Unlock - Not enough balance",
221
+ transaction: (t) => ({
222
+ ...t,
223
+ mode: "unlock",
224
+ amount: new BigNumber(200000000000000000),
225
+ }),
226
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
227
+ return {
228
+ errors: {
229
+ amount: new NotEnoughBalance(),
230
+ },
231
+ warnings: {},
232
+ };
233
+ },
234
+ },
235
+ {
236
+ name: "Vote - success",
237
+ transaction: (t) => ({
238
+ ...t,
239
+ mode: "vote",
240
+ useAllAmount: true,
241
+ recipient: VALIDATOR_ACCOUNT_1,
242
+ }),
243
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
244
+ return {
245
+ errors: {},
246
+ warnings: {},
247
+ amount: new BigNumber(100000000000000000),
248
+ };
249
+ },
250
+ },
251
+ {
252
+ name: "Vote - Not enough balance",
253
+ transaction: (t) => ({
254
+ ...t,
255
+ mode: "vote",
256
+ recipient: VALIDATOR_ACCOUNT_1,
257
+ amount: new BigNumber(200000000000000000),
258
+ }),
259
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
260
+ return {
261
+ errors: {
262
+ amount: new NotEnoughBalance(),
263
+ },
264
+ warnings: {},
265
+ };
266
+ },
267
+ },
268
+ {
269
+ name: "Activate Vote - success",
270
+ transaction: (t) => ({
271
+ ...t,
272
+ mode: "activate",
273
+ recipient: VALIDATOR_ACCOUNT_1,
274
+ }),
275
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
276
+ return {
277
+ errors: {},
278
+ warnings: {},
279
+ };
280
+ },
281
+ },
282
+ {
283
+ name: "Revoke Vote - success",
284
+ transaction: (t) => ({
285
+ ...t,
286
+ mode: "revoke",
287
+ recipient: VALIDATOR_ACCOUNT_1,
288
+ amount: new BigNumber(9000000),
289
+ index: 0,
290
+ }),
291
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
292
+ return {
293
+ errors: {},
294
+ warnings: {},
295
+ };
296
+ },
297
+ },
298
+ {
299
+ name: "Revoke Vote - Not enough balance",
300
+ transaction: (t) => ({
301
+ ...t,
302
+ mode: "revoke",
303
+ recipient: VALIDATOR_ACCOUNT_1,
304
+ amount: new BigNumber(20000000000000000000),
305
+ index: 0,
306
+ }),
307
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
308
+ return {
309
+ errors: {
310
+ amount: new NotEnoughBalance(),
311
+ },
312
+ warnings: {},
313
+ };
314
+ },
315
+ },
316
+ {
317
+ name: "Revoke Vote - voted amount should be used when revoke amount is set",
318
+ transaction: (t) => ({
319
+ ...t,
320
+ mode: "revoke",
321
+ recipient: VALIDATOR_ACCOUNT_1,
322
+ useAllAmount: true,
323
+ index: 0,
324
+ }),
325
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
326
+ return {
327
+ errors: {},
328
+ warnings: {},
329
+ };
330
+ },
331
+ },
332
+ ],
333
+ },
334
+ {
335
+ FIXME_tests: ["balance is sum of ops"],
336
+ raw: {
337
+ id: `js:2:celo:${LEDGER_CELO_ACCOUNT_2}:`,
338
+ seedIdentifier:
339
+ "0453390dcc1e6f1be0fb34f837b278ed1b4c84097c7493c13a0d915c735af1d8aa445d2738a95e8f50bc22abd2e17cb868d4db22a623d99d861740eb93373d50a3",
340
+ name: "Celo 1",
341
+ derivationMode: "",
342
+ index: 0,
343
+ freshAddress: LEDGER_CELO_ACCOUNT_2,
344
+ freshAddressPath: "44'/52752'/0'/0/0",
345
+ freshAddresses: [],
346
+ blockHeight: 0,
347
+ operations: [],
348
+ pendingOperations: [],
349
+ currencyId: "celo",
350
+ unitMagnitude: 18,
351
+ lastSyncDate: "",
352
+ balance: "399893159500000000",
353
+ celoResources: {
354
+ registrationStatus: false,
355
+ lockedBalance: "0",
356
+ nonvotingLockedBalance: "0",
357
+ pendingWithdrawals: [],
358
+ votes: [],
359
+ electionAddress: "0x8D6677192144292870907E3Fa8A5527fE55A7ff6",
360
+ lockedGoldAddress: "0x6cC083Aed9e3ebe302A6336dBC7c921C9f03349E",
361
+ },
362
+ } as AccountRaw,
363
+ transactions: [
364
+ {
365
+ name: "Register Account - success",
366
+ transaction: (t) => ({
367
+ ...t,
368
+ mode: "register",
369
+ }),
370
+ expectedStatus: {
371
+ errors: {},
372
+ warnings: {},
373
+ },
374
+ },
375
+ ],
376
+ },
377
+ ],
18
378
  };
19
379
 
20
380
  export default dataset;
@@ -0,0 +1,5 @@
1
+ import { createCustomErrorClass } from "@ledgerhq/errors";
2
+
3
+ export const CeloAllFundsWarning = createCustomErrorClass(
4
+ "CeloAllFundsWarning"
5
+ );
@@ -1,32 +1,185 @@
1
- import type { Transaction } from "./types";
1
+ import type { CeloAccount, Transaction } from "./types";
2
2
  import { CeloTx } from "@celo/connect";
3
3
  import { celoKit } from "./api/sdk";
4
- import { Account } from "@ledgerhq/types-live";
4
+ import { BigNumber } from "bignumber.js";
5
+ import { getPendingStakingOperationAmounts, getVote } from "./logic";
5
6
 
6
- const buildTransaction = async (account: Account, transaction: Transaction) => {
7
+ const buildTransaction = async (
8
+ account: CeloAccount,
9
+ transaction: Transaction
10
+ ) => {
7
11
  const kit = celoKit();
8
- const { amount } = transaction;
9
- const value = transaction.useAllAmount
10
- ? account.spendableBalance.minus(transaction.fees || 0)
11
- : amount;
12
-
13
- const celoToken = await kit.contracts.getGoldToken();
14
-
15
- const celoTransaction = {
16
- from: account.freshAddress,
17
- to: celoToken.address,
18
- data: celoToken
19
- .transfer(transaction.recipient, value.toFixed())
20
- .txo.encodeABI(),
21
- };
22
12
 
23
- return {
13
+ const value = transactionValue(account, transaction);
14
+
15
+ let celoTransaction: CeloTx;
16
+
17
+ if (transaction.mode === "lock") {
18
+ const lockedGold = await kit.contracts.getLockedGold();
19
+ celoTransaction = {
20
+ from: account.freshAddress,
21
+ value: value.toFixed(),
22
+ to: lockedGold.address,
23
+ data: lockedGold.lock().txo.encodeABI(),
24
+ gas: await lockedGold.lock().txo.estimateGas({
25
+ from: account.freshAddress,
26
+ value: value.toFixed(),
27
+ }),
28
+ };
29
+ } else if (transaction.mode === "unlock") {
30
+ const lockedGold = await kit.contracts.getLockedGold();
31
+ celoTransaction = {
32
+ from: account.freshAddress,
33
+ to: lockedGold.address,
34
+ data: lockedGold.unlock(value).txo.encodeABI(),
35
+ gas: await lockedGold.unlock(value).txo.estimateGas({
36
+ from: account.freshAddress,
37
+ }),
38
+ };
39
+ } else if (transaction.mode === "withdraw") {
40
+ const lockedGold = await kit.contracts.getLockedGold();
41
+
42
+ celoTransaction = {
43
+ from: account.freshAddress,
44
+ to: lockedGold.address,
45
+ data: lockedGold.withdraw(transaction.index || 0).txo.encodeABI(),
46
+ gas: await lockedGold.withdraw(transaction.index || 0).txo.estimateGas({
47
+ from: account.freshAddress,
48
+ value: value.toFixed(),
49
+ }),
50
+ };
51
+ } else if (transaction.mode === "vote") {
52
+ const election = await kit.contracts.getElection();
53
+ const vote = await election.vote(
54
+ transaction.recipient,
55
+ new BigNumber(value)
56
+ );
57
+
58
+ celoTransaction = {
59
+ from: account.freshAddress,
60
+ to: election.address,
61
+ data: vote.txo.encodeABI(),
62
+ gas: await vote.txo.estimateGas({ from: account.freshAddress }),
63
+ };
64
+ } else if (transaction.mode === "revoke") {
65
+ const election = await kit.contracts.getElection();
66
+ const accounts = await kit.contracts.getAccounts();
67
+ const voteSignerAccount = await accounts.voteSignerToAccount(
68
+ account.freshAddress
69
+ );
70
+
71
+ const revokes = await election.revoke(
72
+ voteSignerAccount,
73
+ transaction.recipient,
74
+ new BigNumber(value)
75
+ );
76
+
77
+ const revoke = revokes.find((transactionObject) => {
78
+ return (
79
+ (transactionObject.txo as any)._method.name ===
80
+ (transaction.index === 0 ? "revokePending" : "revokeActive")
81
+ );
82
+ });
83
+ if (!revoke) throw new Error("No votes to revoke");
84
+
85
+ celoTransaction = {
86
+ from: account.freshAddress,
87
+ to: election.address,
88
+ data: revoke.txo.encodeABI(),
89
+ gas: await revoke.txo.estimateGas({ from: account.freshAddress }),
90
+ };
91
+ } else if (transaction.mode === "activate") {
92
+ const election = await kit.contracts.getElection();
93
+ const accounts = await kit.contracts.getAccounts();
94
+ const voteSignerAccount = await accounts.voteSignerToAccount(
95
+ account.freshAddress
96
+ );
97
+
98
+ const activates = await election.activate(voteSignerAccount);
99
+ const activate = activates.find(
100
+ (a) => a.txo.arguments[0] === transaction.recipient
101
+ );
102
+ if (!activate) throw new Error("No votes to activate");
103
+
104
+ celoTransaction = {
105
+ from: account.freshAddress,
106
+ to: election.address,
107
+ data: activate.txo.encodeABI(),
108
+ gas: await activate.txo.estimateGas({
109
+ from: account.freshAddress,
110
+ }),
111
+ };
112
+ } else if (transaction.mode === "register") {
113
+ const accounts = await kit.contracts.getAccounts();
114
+ celoTransaction = {
115
+ from: account.freshAddress,
116
+ to: accounts.address,
117
+ data: accounts.createAccount().txo.encodeABI(),
118
+ gas: await accounts
119
+ .createAccount()
120
+ .txo.estimateGas({ from: account.freshAddress }),
121
+ };
122
+ } else {
123
+ // Send
124
+ const celoToken = await kit.contracts.getGoldToken();
125
+ celoTransaction = {
126
+ from: account.freshAddress,
127
+ to: celoToken.address,
128
+ data: celoToken
129
+ .transfer(transaction.recipient, value.toFixed())
130
+ .txo.encodeABI(),
131
+ };
132
+
133
+ const gas = await kit.connection.estimateGasWithInflationFactor(
134
+ celoTransaction
135
+ );
136
+
137
+ celoTransaction = {
138
+ ...celoTransaction,
139
+ gas,
140
+ };
141
+ }
142
+ const tx: CeloTx = {
24
143
  ...celoTransaction,
25
144
  chainId: await kit.connection.chainId(),
26
145
  nonce: await kit.connection.nonce(account.freshAddress),
27
- gas: await kit.connection.estimateGasWithInflationFactor(celoTransaction),
28
146
  gasPrice: await kit.connection.gasPrice(),
29
- } as CeloTx;
147
+ };
148
+
149
+ return tx;
150
+ };
151
+
152
+ const transactionValue = (
153
+ account: CeloAccount,
154
+ transaction: Transaction
155
+ ): BigNumber => {
156
+ let value = transaction.amount;
157
+
158
+ if (transaction.useAllAmount) {
159
+ if (
160
+ (transaction.mode === "unlock" || transaction.mode === "vote") &&
161
+ account.celoResources
162
+ ) {
163
+ // Deduct the amount of pending vote transactions from
164
+ // the total non-voting locked balance to get the true non-voting locked balance.
165
+ const pendingOperationAmounts =
166
+ getPendingStakingOperationAmounts(account);
167
+ const pendingOperationAmount =
168
+ transaction.mode === "vote"
169
+ ? pendingOperationAmounts.vote
170
+ : new BigNumber(0);
171
+ value = account.celoResources.nonvotingLockedBalance.minus(
172
+ pendingOperationAmount
173
+ );
174
+ } else if (transaction.mode === "revoke" && account.celoResources) {
175
+ const revoke = getVote(account, transaction.recipient, transaction.index);
176
+ if (revoke?.amount) value = revoke.amount;
177
+ } else {
178
+ value = account.spendableBalance.minus(transaction.fees || 0);
179
+ }
180
+ }
181
+
182
+ return value;
30
183
  };
31
184
 
32
185
  export default buildTransaction;
@@ -7,6 +7,8 @@ const createTransaction = (): Transaction => ({
7
7
  recipient: "",
8
8
  useAllAmount: false,
9
9
  fees: null,
10
+ mode: "send",
11
+ index: null,
10
12
  });
11
13
 
12
14
  export default createTransaction;
@@ -1,4 +1,4 @@
1
- import { Transaction } from "./types";
1
+ import { CeloAccount, Transaction } from "./types";
2
2
  import { BigNumber } from "bignumber.js";
3
3
  import { getMainAccount } from "../../account";
4
4
  import getTransactionStatus from "./js-getTransactionStatus";
@@ -15,7 +15,7 @@ const estimateMaxSpendable = async ({
15
15
  parentAccount: Account;
16
16
  transaction: Transaction;
17
17
  }): Promise<BigNumber> => {
18
- const mainAccount = getMainAccount(account, parentAccount);
18
+ const mainAccount = getMainAccount(account, parentAccount) as CeloAccount;
19
19
  const t = await prepareTransaction(mainAccount, {
20
20
  ...createTransaction(),
21
21
  ...transaction,