@ledgerhq/coin-hedera 1.10.1 → 1.10.2-nightly.0

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 (248) hide show
  1. package/.eslintrc.js +1 -0
  2. package/CHANGELOG.md +10 -0
  3. package/lib/api/mirror.d.ts +3 -20
  4. package/lib/api/mirror.d.ts.map +1 -1
  5. package/lib/api/mirror.js +32 -90
  6. package/lib/api/mirror.js.map +1 -1
  7. package/lib/api/mirror.test.js +59 -4
  8. package/lib/api/mirror.test.js.map +1 -1
  9. package/lib/api/network.d.ts +3 -3
  10. package/lib/api/network.d.ts.map +1 -1
  11. package/lib/api/network.js +46 -3
  12. package/lib/api/network.js.map +1 -1
  13. package/lib/api/types.d.ts +44 -0
  14. package/lib/api/types.d.ts.map +1 -0
  15. package/lib/api/types.js +3 -0
  16. package/lib/api/types.js.map +1 -0
  17. package/lib/api/utils.d.ts +8 -0
  18. package/lib/api/utils.d.ts.map +1 -0
  19. package/lib/api/utils.js +132 -0
  20. package/lib/api/utils.js.map +1 -0
  21. package/lib/bridge/broadcast.d.ts.map +1 -1
  22. package/lib/bridge/broadcast.js +2 -0
  23. package/lib/bridge/broadcast.js.map +1 -1
  24. package/lib/bridge/buildOptimisticOperation.d.ts +2 -2
  25. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
  26. package/lib/bridge/buildOptimisticOperation.integration.test.d.ts +2 -0
  27. package/lib/bridge/buildOptimisticOperation.integration.test.d.ts.map +1 -0
  28. package/lib/bridge/buildOptimisticOperation.integration.test.js +82 -0
  29. package/lib/bridge/buildOptimisticOperation.integration.test.js.map +1 -0
  30. package/lib/bridge/buildOptimisticOperation.js +87 -5
  31. package/lib/bridge/buildOptimisticOperation.js.map +1 -1
  32. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  33. package/lib/bridge/estimateMaxSpendable.js +8 -2
  34. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  35. package/lib/bridge/getTransactionStatus.d.ts +3 -3
  36. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  37. package/lib/bridge/getTransactionStatus.js +116 -23
  38. package/lib/bridge/getTransactionStatus.js.map +1 -1
  39. package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
  40. package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
  41. package/lib/bridge/getTransactionStatus.test.js +176 -0
  42. package/lib/bridge/getTransactionStatus.test.js.map +1 -0
  43. package/lib/bridge/index.d.ts +4 -4
  44. package/lib/bridge/index.d.ts.map +1 -1
  45. package/lib/bridge/index.js +9 -6
  46. package/lib/bridge/index.js.map +1 -1
  47. package/lib/bridge/js-estimateMaxSpendable.integration.test.js +28 -44
  48. package/lib/bridge/js-estimateMaxSpendable.integration.test.js.map +1 -1
  49. package/lib/bridge/js-transaction.test.js +10 -49
  50. package/lib/bridge/js-transaction.test.js.map +1 -1
  51. package/lib/bridge/prepareTransaction.d.ts +0 -1
  52. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  53. package/lib/bridge/prepareTransaction.js +0 -1
  54. package/lib/bridge/prepareTransaction.js.map +1 -1
  55. package/lib/bridge/serialization.d.ts +7 -0
  56. package/lib/bridge/serialization.d.ts.map +1 -0
  57. package/lib/bridge/serialization.js +36 -0
  58. package/lib/bridge/serialization.js.map +1 -0
  59. package/lib/bridge/serialization.test.d.ts +2 -0
  60. package/lib/bridge/serialization.test.d.ts.map +1 -0
  61. package/lib/bridge/serialization.test.js +27 -0
  62. package/lib/bridge/serialization.test.js.map +1 -0
  63. package/lib/bridge/synchronisation.d.ts +3 -3
  64. package/lib/bridge/synchronisation.d.ts.map +1 -1
  65. package/lib/bridge/synchronisation.js +37 -15
  66. package/lib/bridge/synchronisation.js.map +1 -1
  67. package/lib/bridge/transaction.test.js +18 -59
  68. package/lib/bridge/transaction.test.js.map +1 -1
  69. package/lib/bridge/utils.d.ts +22 -8
  70. package/lib/bridge/utils.d.ts.map +1 -1
  71. package/lib/bridge/utils.integration.test.js +415 -73
  72. package/lib/bridge/utils.integration.test.js.map +1 -1
  73. package/lib/bridge/utils.js +300 -15
  74. package/lib/bridge/utils.js.map +1 -1
  75. package/lib/constants.d.ts +32 -0
  76. package/lib/constants.d.ts.map +1 -0
  77. package/lib/constants.js +37 -0
  78. package/lib/constants.js.map +1 -0
  79. package/lib/deviceTransactionConfig.d.ts.map +1 -1
  80. package/lib/deviceTransactionConfig.js +17 -15
  81. package/lib/deviceTransactionConfig.js.map +1 -1
  82. package/lib/logic.d.ts +9 -3
  83. package/lib/logic.d.ts.map +1 -1
  84. package/lib/logic.js +31 -3
  85. package/lib/logic.js.map +1 -1
  86. package/lib/logic.test.js +103 -50
  87. package/lib/logic.test.js.map +1 -1
  88. package/lib/test/fixtures/account.fixture.d.ts +19 -0
  89. package/lib/test/fixtures/account.fixture.d.ts.map +1 -0
  90. package/lib/test/fixtures/account.fixture.js +116 -0
  91. package/lib/test/fixtures/account.fixture.js.map +1 -0
  92. package/lib/test/fixtures/currency.fixture.d.ts +5 -0
  93. package/lib/test/fixtures/currency.fixture.d.ts.map +1 -0
  94. package/lib/test/fixtures/currency.fixture.js +67 -0
  95. package/lib/test/fixtures/currency.fixture.js.map +1 -0
  96. package/lib/test/fixtures/mirror.fixture.d.ts +3 -0
  97. package/lib/test/fixtures/mirror.fixture.d.ts.map +1 -0
  98. package/lib/test/fixtures/mirror.fixture.js +17 -0
  99. package/lib/test/fixtures/mirror.fixture.js.map +1 -0
  100. package/lib/test/fixtures/operation.fixture.d.ts +3 -0
  101. package/lib/test/fixtures/operation.fixture.d.ts.map +1 -0
  102. package/lib/test/fixtures/operation.fixture.js +26 -0
  103. package/lib/test/fixtures/operation.fixture.js.map +1 -0
  104. package/lib/test/fixtures/transaction.fixture.d.ts +4 -0
  105. package/lib/test/fixtures/transaction.fixture.d.ts.map +1 -0
  106. package/lib/test/fixtures/transaction.fixture.js +28 -0
  107. package/lib/test/fixtures/transaction.fixture.js.map +1 -0
  108. package/lib/types/bridge.d.ts +25 -1
  109. package/lib/types/bridge.d.ts.map +1 -1
  110. package/lib-es/api/mirror.d.ts +3 -20
  111. package/lib-es/api/mirror.d.ts.map +1 -1
  112. package/lib-es/api/mirror.js +29 -88
  113. package/lib-es/api/mirror.js.map +1 -1
  114. package/lib-es/api/mirror.test.js +60 -5
  115. package/lib-es/api/mirror.test.js.map +1 -1
  116. package/lib-es/api/network.d.ts +3 -3
  117. package/lib-es/api/network.d.ts.map +1 -1
  118. package/lib-es/api/network.js +44 -4
  119. package/lib-es/api/network.js.map +1 -1
  120. package/lib-es/api/types.d.ts +44 -0
  121. package/lib-es/api/types.d.ts.map +1 -0
  122. package/lib-es/api/types.js +2 -0
  123. package/lib-es/api/types.js.map +1 -0
  124. package/lib-es/api/utils.d.ts +8 -0
  125. package/lib-es/api/utils.d.ts.map +1 -0
  126. package/lib-es/api/utils.js +124 -0
  127. package/lib-es/api/utils.js.map +1 -0
  128. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  129. package/lib-es/bridge/broadcast.js +2 -0
  130. package/lib-es/bridge/broadcast.js.map +1 -1
  131. package/lib-es/bridge/buildOptimisticOperation.d.ts +2 -2
  132. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
  133. package/lib-es/bridge/buildOptimisticOperation.integration.test.d.ts +2 -0
  134. package/lib-es/bridge/buildOptimisticOperation.integration.test.d.ts.map +1 -0
  135. package/lib-es/bridge/buildOptimisticOperation.integration.test.js +77 -0
  136. package/lib-es/bridge/buildOptimisticOperation.integration.test.js.map +1 -0
  137. package/lib-es/bridge/buildOptimisticOperation.js +84 -5
  138. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
  139. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  140. package/lib-es/bridge/estimateMaxSpendable.js +8 -2
  141. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  142. package/lib-es/bridge/getTransactionStatus.d.ts +3 -3
  143. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  144. package/lib-es/bridge/getTransactionStatus.js +114 -24
  145. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  146. package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
  147. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
  148. package/lib-es/bridge/getTransactionStatus.test.js +148 -0
  149. package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
  150. package/lib-es/bridge/index.d.ts +4 -4
  151. package/lib-es/bridge/index.d.ts.map +1 -1
  152. package/lib-es/bridge/index.js +9 -6
  153. package/lib-es/bridge/index.js.map +1 -1
  154. package/lib-es/bridge/js-estimateMaxSpendable.integration.test.js +28 -44
  155. package/lib-es/bridge/js-estimateMaxSpendable.integration.test.js.map +1 -1
  156. package/lib-es/bridge/js-transaction.test.js +10 -49
  157. package/lib-es/bridge/js-transaction.test.js.map +1 -1
  158. package/lib-es/bridge/prepareTransaction.d.ts +0 -1
  159. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  160. package/lib-es/bridge/prepareTransaction.js +0 -1
  161. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  162. package/lib-es/bridge/serialization.d.ts +7 -0
  163. package/lib-es/bridge/serialization.d.ts.map +1 -0
  164. package/lib-es/bridge/serialization.js +29 -0
  165. package/lib-es/bridge/serialization.js.map +1 -0
  166. package/lib-es/bridge/serialization.test.d.ts +2 -0
  167. package/lib-es/bridge/serialization.test.d.ts.map +1 -0
  168. package/lib-es/bridge/serialization.test.js +25 -0
  169. package/lib-es/bridge/serialization.test.js.map +1 -0
  170. package/lib-es/bridge/synchronisation.d.ts +3 -3
  171. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  172. package/lib-es/bridge/synchronisation.js +39 -17
  173. package/lib-es/bridge/synchronisation.js.map +1 -1
  174. package/lib-es/bridge/transaction.test.js +18 -59
  175. package/lib-es/bridge/transaction.test.js.map +1 -1
  176. package/lib-es/bridge/utils.d.ts +22 -8
  177. package/lib-es/bridge/utils.d.ts.map +1 -1
  178. package/lib-es/bridge/utils.integration.test.js +416 -74
  179. package/lib-es/bridge/utils.integration.test.js.map +1 -1
  180. package/lib-es/bridge/utils.js +295 -15
  181. package/lib-es/bridge/utils.js.map +1 -1
  182. package/lib-es/constants.d.ts +32 -0
  183. package/lib-es/constants.d.ts.map +1 -0
  184. package/lib-es/constants.js +34 -0
  185. package/lib-es/constants.js.map +1 -0
  186. package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
  187. package/lib-es/deviceTransactionConfig.js +17 -15
  188. package/lib-es/deviceTransactionConfig.js.map +1 -1
  189. package/lib-es/logic.d.ts +9 -3
  190. package/lib-es/logic.d.ts.map +1 -1
  191. package/lib-es/logic.js +26 -3
  192. package/lib-es/logic.js.map +1 -1
  193. package/lib-es/logic.test.js +104 -51
  194. package/lib-es/logic.test.js.map +1 -1
  195. package/lib-es/test/fixtures/account.fixture.d.ts +19 -0
  196. package/lib-es/test/fixtures/account.fixture.d.ts.map +1 -0
  197. package/lib-es/test/fixtures/account.fixture.js +107 -0
  198. package/lib-es/test/fixtures/account.fixture.js.map +1 -0
  199. package/lib-es/test/fixtures/currency.fixture.d.ts +5 -0
  200. package/lib-es/test/fixtures/currency.fixture.d.ts.map +1 -0
  201. package/lib-es/test/fixtures/currency.fixture.js +58 -0
  202. package/lib-es/test/fixtures/currency.fixture.js.map +1 -0
  203. package/lib-es/test/fixtures/mirror.fixture.d.ts +3 -0
  204. package/lib-es/test/fixtures/mirror.fixture.d.ts.map +1 -0
  205. package/lib-es/test/fixtures/mirror.fixture.js +13 -0
  206. package/lib-es/test/fixtures/mirror.fixture.js.map +1 -0
  207. package/lib-es/test/fixtures/operation.fixture.d.ts +3 -0
  208. package/lib-es/test/fixtures/operation.fixture.d.ts.map +1 -0
  209. package/lib-es/test/fixtures/operation.fixture.js +19 -0
  210. package/lib-es/test/fixtures/operation.fixture.js.map +1 -0
  211. package/lib-es/test/fixtures/transaction.fixture.d.ts +4 -0
  212. package/lib-es/test/fixtures/transaction.fixture.d.ts.map +1 -0
  213. package/lib-es/test/fixtures/transaction.fixture.js +20 -0
  214. package/lib-es/test/fixtures/transaction.fixture.js.map +1 -0
  215. package/lib-es/types/bridge.d.ts +25 -1
  216. package/lib-es/types/bridge.d.ts.map +1 -1
  217. package/package.json +11 -9
  218. package/src/api/mirror.test.ts +79 -5
  219. package/src/api/mirror.ts +30 -111
  220. package/src/api/network.ts +71 -4
  221. package/src/api/types.ts +48 -0
  222. package/src/api/utils.ts +150 -0
  223. package/src/bridge/broadcast.ts +2 -0
  224. package/src/bridge/buildOptimisticOperation.integration.test.ts +88 -0
  225. package/src/bridge/buildOptimisticOperation.ts +118 -7
  226. package/src/bridge/estimateMaxSpendable.ts +8 -2
  227. package/src/bridge/getTransactionStatus.test.ts +200 -0
  228. package/src/bridge/getTransactionStatus.ts +166 -32
  229. package/src/bridge/index.ts +13 -10
  230. package/src/bridge/js-estimateMaxSpendable.integration.test.ts +37 -46
  231. package/src/bridge/js-transaction.test.ts +13 -54
  232. package/src/bridge/prepareTransaction.ts +1 -2
  233. package/src/bridge/serialization.test.ts +39 -0
  234. package/src/bridge/serialization.ts +43 -0
  235. package/src/bridge/synchronisation.ts +65 -27
  236. package/src/bridge/transaction.test.ts +22 -64
  237. package/src/bridge/utils.integration.test.ts +525 -76
  238. package/src/bridge/utils.ts +423 -24
  239. package/src/constants.ts +35 -0
  240. package/src/deviceTransactionConfig.ts +16 -15
  241. package/src/logic.test.ts +147 -57
  242. package/src/logic.ts +58 -7
  243. package/src/test/fixtures/account.fixture.ts +123 -0
  244. package/src/test/fixtures/currency.fixture.ts +66 -0
  245. package/src/test/fixtures/mirror.fixture.ts +14 -0
  246. package/src/test/fixtures/operation.fixture.ts +20 -0
  247. package/src/test/fixtures/transaction.fixture.ts +22 -0
  248. package/src/types/bridge.ts +33 -0
@@ -1,14 +1,15 @@
1
1
  import { getSerializedAddressParameters, makeScanAccounts, makeSync, updateTransaction, } from "@ledgerhq/coin-framework/bridge/jsHelpers";
2
- import resolver from "../signer/index";
3
2
  import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
4
- import { getTransactionStatus } from "./getTransactionStatus";
3
+ import { broadcast } from "./broadcast";
4
+ import { createTransaction } from "./createTransaction";
5
5
  import { estimateMaxSpendable } from "./estimateMaxSpendable";
6
+ import { getTransactionStatus } from "./getTransactionStatus";
6
7
  import { prepareTransaction } from "./prepareTransaction";
7
- import { createTransaction } from "./createTransaction";
8
- import { getAccountShape, buildIterateResult } from "./synchronisation";
9
- import { buildSignOperation } from "./signOperation";
10
- import { broadcast } from "./broadcast";
11
8
  import { receive } from "./receive";
9
+ import { buildSignOperation } from "./signOperation";
10
+ import { getAccountShape, buildIterateResult } from "./synchronisation";
11
+ import { assignFromAccountRaw, assignToAccountRaw } from "./serialization";
12
+ import resolver from "../signer/index";
12
13
  function buildCurrencyBridge(signerContext) {
13
14
  const getAddress = resolver(signerContext);
14
15
  const scanAccounts = makeScanAccounts({
@@ -32,6 +33,8 @@ function buildAccountBridge(signerContext) {
32
33
  updateTransaction,
33
34
  getTransactionStatus,
34
35
  prepareTransaction,
36
+ assignToAccountRaw,
37
+ assignFromAccountRaw,
35
38
  sync,
36
39
  receive: receive(getAddressWrapper(getAddress)),
37
40
  signOperation,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bridge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,QAAQ,EACR,iBAAiB,GAClB,MAAM,2CAA2C,CAAC;AACnD,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,iBAAiB,MAAM,mDAAmD,CAAC;AAIlF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAA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AG,QAAQ,CAAC,aAAa,CAAC,CAAC;IAE3C,MAAM,aAAa,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAC;IAExD,OAAO;QACL,oBAAoB;QACpB,iBAAiB;QACjB,iBAAiB;QACjB,oBAAoB;QACpB,kBAAkB;QAClB,kBAAkB;QAClB,oBAAoB;QACpB,IAAI;QACJ,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAC/C,aAAa;QACb,SAAS;QACT,8BAA8B;KAC/B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,aAA0C;IACtE,OAAO;QACL,cAAc,EAAE,mBAAmB,CAAC,aAAa,CAAC;QAClD,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC;KACjD,CAAC;AACJ,CAAC"}
@@ -1,58 +1,42 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import { createBridges } from ".";
3
3
  import { getEstimatedFees } from "./utils";
4
- // Balance is 1 Hbar
5
- const account = {
6
- type: "Account",
7
- id: "",
8
- seedIdentifier: "",
9
- derivationMode: "",
10
- index: 0,
11
- freshAddress: "",
12
- freshAddressPath: "",
13
- used: false,
14
- balance: new BigNumber(100000000),
15
- spendableBalance: new BigNumber(0),
16
- creationDate: new Date(),
17
- blockHeight: 0,
18
- currency: {
19
- type: "CryptoCurrency",
20
- id: "hedera",
21
- managerAppName: "",
22
- coinType: 0,
23
- scheme: "",
24
- color: "",
25
- family: "",
26
- explorerViews: [],
27
- name: "",
28
- ticker: "",
29
- units: [],
30
- },
31
- operationsCount: 0,
32
- operations: [],
33
- pendingOperations: [],
34
- lastSyncDate: new Date(),
35
- balanceHistoryCache: {
36
- HOUR: { latestDate: null, balances: [] },
37
- DAY: { latestDate: null, balances: [] },
38
- WEEK: { latestDate: null, balances: [] },
39
- },
40
- swapHistory: [],
41
- };
4
+ import { getMockedAccount, getMockedTokenAccount } from "../test/fixtures/account.fixture";
5
+ import { getMockedTokenCurrency } from "../test/fixtures/currency.fixture";
6
+ import { HEDERA_OPERATION_TYPES } from "../constants";
42
7
  describe("js-estimateMaxSpendable", () => {
43
8
  let bridge;
44
- let estimatedFees = new BigNumber("150200").multipliedBy(2); // 0.001502 ℏ (as of 2023-03-14)
9
+ let estimatedFees;
45
10
  beforeAll(async () => {
46
11
  const signer = jest.fn();
47
12
  bridge = createBridges(signer);
48
- estimatedFees = await getEstimatedFees(account);
13
+ const mockedAccount = getMockedAccount();
14
+ const crypto = await getEstimatedFees(mockedAccount, HEDERA_OPERATION_TYPES.CryptoTransfer);
15
+ estimatedFees = { crypto };
49
16
  });
50
- test("estimateMaxSpendable", async () => {
17
+ test("estimateMaxSpendable returns balance minus fee", async () => {
18
+ const mockedAccount = getMockedAccount();
51
19
  const result = await bridge.accountBridge.estimateMaxSpendable({
52
- account,
20
+ account: mockedAccount,
53
21
  });
54
- const data = account.balance.minus(estimatedFees);
55
- expect(result).toEqual(data);
22
+ expect(result).toEqual(mockedAccount.balance.minus(estimatedFees.crypto));
23
+ });
24
+ test("estimateMaxSpendable returns 0 if balance < estimated fees", async () => {
25
+ const mockedAccount = getMockedAccount({ balance: estimatedFees.crypto.minus(1) });
26
+ const result = await bridge.accountBridge.estimateMaxSpendable({
27
+ account: mockedAccount,
28
+ });
29
+ expect(result).toEqual(new BigNumber(0));
30
+ });
31
+ test("estimateMaxSpendable returns token balance for token account", async () => {
32
+ const mockedTokenCurrency = getMockedTokenCurrency();
33
+ const mockedTokenAccount = getMockedTokenAccount(mockedTokenCurrency);
34
+ const mockedAccount = getMockedAccount({ subAccounts: [mockedTokenAccount] });
35
+ const result = await bridge.accountBridge.estimateMaxSpendable({
36
+ account: mockedTokenAccount,
37
+ parentAccount: mockedAccount,
38
+ });
39
+ expect(result).toEqual(mockedTokenAccount.balance);
56
40
  });
57
41
  });
58
42
  //# sourceMappingURL=js-estimateMaxSpendable.integration.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"js-estimateMaxSpendable.integration.test.js","sourceRoot":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AE,EAAE;CAChB,CAAC;AAEF,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,IAAI,MAAwC,CAAC;IAC7C,IAAI,aAAa,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,gCAAgC;IAE7F,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QACzB,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAC/B,aAAa,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,oBAAoB,CAAC;YAC7D,OAAO;SACR,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAElD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"js-estimateMaxSpendable.integration.test.js","sourceRoot":"","sources":["../../src/bridge/js-estimateMaxSpendable.integration.test.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,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EAAE,CAAC;QACrD,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;QACtE,MAAM,aAAa,GAAG,gBAAgB,CAAC,EAAE,WAAW,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;QAE9E,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,oBAAoB,CAAC;YAC7D,OAAO,EAAE,kBAAkB;YAC3B,aAAa,EAAE,aAAa;SAC7B,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,58 +1,19 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import { updateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
3
3
  import { createBridges } from ".";
4
- const account = {
5
- type: "Account",
6
- id: "",
7
- seedIdentifier: "",
8
- derivationMode: "",
9
- index: 0,
10
- freshAddress: "",
11
- freshAddressPath: "",
12
- used: false,
13
- balance: new BigNumber(200000),
14
- spendableBalance: new BigNumber(0),
15
- creationDate: new Date(),
16
- blockHeight: 0,
17
- currency: {
18
- type: "CryptoCurrency",
19
- id: "hedera",
20
- managerAppName: "",
21
- coinType: 0,
22
- scheme: "",
23
- color: "",
24
- family: "",
25
- explorerViews: [],
26
- name: "",
27
- ticker: "",
28
- units: [],
29
- },
30
- operationsCount: 0,
31
- operations: [],
32
- pendingOperations: [],
33
- lastSyncDate: new Date(),
34
- balanceHistoryCache: {
35
- HOUR: { latestDate: null, balances: [] },
36
- DAY: { latestDate: null, balances: [] },
37
- WEEK: { latestDate: null, balances: [] },
38
- },
39
- swapHistory: [],
40
- };
41
- const transaction = {
42
- family: "hedera",
43
- amount: new BigNumber(0),
44
- recipient: "",
45
- useAllAmount: false,
46
- };
4
+ import { getMockedAccount } from "../test/fixtures/account.fixture";
5
+ import { getMockedTransaction } from "../test/fixtures/transaction.fixture";
47
6
  describe("js-transaction", () => {
48
7
  let bridge;
8
+ const mockedAccount = getMockedAccount();
9
+ const mockedTransaction = getMockedTransaction();
49
10
  beforeAll(() => {
50
11
  const signer = jest.fn();
51
12
  bridge = createBridges(signer);
52
13
  });
53
14
  test("createTransaction", () => {
54
- const data = transaction;
55
- const result = bridge.accountBridge.createTransaction(account);
15
+ const data = mockedTransaction;
16
+ const result = bridge.accountBridge.createTransaction(mockedAccount);
56
17
  expect(result).toEqual(data);
57
18
  });
58
19
  test("updateTransaction", () => {
@@ -61,13 +22,13 @@ describe("js-transaction", () => {
61
22
  recipient: "0.0.3",
62
23
  useAllAmount: true,
63
24
  };
64
- const data = { ...transaction, ...patch };
65
- const result = updateTransaction(transaction, patch);
25
+ const data = { ...mockedTransaction, ...patch };
26
+ const result = updateTransaction(mockedTransaction, patch);
66
27
  expect(result).toEqual(data);
67
28
  });
68
29
  test("prepareTransaction", async () => {
69
- const data = transaction;
70
- const result = await bridge.accountBridge.prepareTransaction(account, transaction);
30
+ const data = mockedTransaction;
31
+ const result = await bridge.accountBridge.prepareTransaction(mockedAccount, mockedTransaction);
71
32
  expect(result).toEqual(data);
72
33
  });
73
34
  });
@@ -1 +1 @@
1
- {"version":3,"file":"js-transaction.test.js","sourceRoot":"","sources":["../../src/bridge/js-transaction.test.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAElC,MAAM,OAAO,GAAY;IACvB,IAAI,EAAE,SAAS;IACf,EAAE,EAAE,EAAE;IACN,cAAc,EAAE,EAAE;IAClB,cAAc,EAAE,EAAE;IAClB,KAAK,EAAE,CAAC;IACR,YAAY,EAAE,EAAE;IAChB,gBAAgB,EAAE,EAAE;IACpB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,IAAI,SAAS,CAAC,MAA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AC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -7,7 +7,6 @@ import type { Transaction } from "../types";
7
7
  * Hedera has fully client-side transactions and the fee
8
8
  * is not possible to estimate ahead-of-time.
9
9
  *
10
- * @returns {Transaction}
11
10
  */
12
11
  export declare const prepareTransaction: AccountBridge<Transaction>["prepareTransaction"];
13
12
  //# sourceMappingURL=prepareTransaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepareTransaction.d.ts","sourceRoot":"","sources":["../../src/bridge/prepareTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAU/E,CAAC"}
1
+ {"version":3,"file":"prepareTransaction.d.ts","sourceRoot":"","sources":["../../src/bridge/prepareTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAU/E,CAAC"}
@@ -6,7 +6,6 @@ import { calculateAmount } from "./utils";
6
6
  * Hedera has fully client-side transactions and the fee
7
7
  * is not possible to estimate ahead-of-time.
8
8
  *
9
- * @returns {Transaction}
10
9
  */
11
10
  export const prepareTransaction = async (account, transaction) => {
12
11
  // explicitly calculate transaction amount to account for `useAllAmount` flag (send max flow)
@@ -1 +1 @@
1
- {"version":3,"file":"prepareTransaction.js","sourceRoot":"","sources":["../../src/bridge/prepareTransaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAqD,KAAK,EACvF,OAAO,EACP,WAAW,EACX,EAAE;IACF,6FAA6F;IAC7F,uHAAuH;IACvH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,eAAe,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IACnE,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC;IAE5B,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC"}
1
+ {"version":3,"file":"prepareTransaction.js","sourceRoot":"","sources":["../../src/bridge/prepareTransaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAqD,KAAK,EACvF,OAAO,EACP,WAAW,EACW,EAAE;IACxB,6FAA6F;IAC7F,uHAAuH;IACvH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,eAAe,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IACnE,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC;IAE5B,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { AccountRaw, Account } from "@ledgerhq/types-live";
2
+ import type { HederaResources, HederaResourcesRaw } from "../types";
3
+ export declare function toHederaResourcesRaw(resources: HederaResources): HederaResourcesRaw;
4
+ export declare function fromHederaResourcesRaw(rawResources: HederaResourcesRaw): HederaResources;
5
+ export declare function assignToAccountRaw(account: Account, accountRaw: AccountRaw): void;
6
+ export declare function assignFromAccountRaw(accountRaw: AccountRaw, account: Account): void;
7
+ //# sourceMappingURL=serialization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../src/bridge/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAGV,eAAe,EACf,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAElB,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,eAAe,GAAG,kBAAkB,CAOnF;AAED,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,kBAAkB,GAAG,eAAe,CAOxF;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAOjF;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,QAO5E"}
@@ -0,0 +1,29 @@
1
+ export function toHederaResourcesRaw(resources) {
2
+ const { maxAutomaticTokenAssociations, isAutoTokenAssociationEnabled } = resources;
3
+ return {
4
+ maxAutomaticTokenAssociations,
5
+ isAutoTokenAssociationEnabled,
6
+ };
7
+ }
8
+ export function fromHederaResourcesRaw(rawResources) {
9
+ const { maxAutomaticTokenAssociations, isAutoTokenAssociationEnabled } = rawResources;
10
+ return {
11
+ maxAutomaticTokenAssociations,
12
+ isAutoTokenAssociationEnabled,
13
+ };
14
+ }
15
+ export function assignToAccountRaw(account, accountRaw) {
16
+ const hederaAccount = account;
17
+ const hederaAccountRaw = accountRaw;
18
+ if (hederaAccount.hederaResources) {
19
+ hederaAccountRaw.hederaResources = toHederaResourcesRaw(hederaAccount.hederaResources);
20
+ }
21
+ }
22
+ export function assignFromAccountRaw(accountRaw, account) {
23
+ const hederaAccount = account;
24
+ const hederaAccountRaw = accountRaw;
25
+ if (hederaAccountRaw.hederaResources) {
26
+ hederaAccount.hederaResources = fromHederaResourcesRaw(hederaAccountRaw.hederaResources);
27
+ }
28
+ }
29
+ //# sourceMappingURL=serialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../../src/bridge/serialization.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,oBAAoB,CAAC,SAA0B;IAC7D,MAAM,EAAE,6BAA6B,EAAE,6BAA6B,EAAE,GAAG,SAAS,CAAC;IAEnF,OAAO;QACL,6BAA6B;QAC7B,6BAA6B;KAC9B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,YAAgC;IACrE,MAAM,EAAE,6BAA6B,EAAE,6BAA6B,EAAE,GAAG,YAAY,CAAC;IAEtF,OAAO;QACL,6BAA6B;QAC7B,6BAA6B;KAC9B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAgB,EAAE,UAAsB;IACzE,MAAM,aAAa,GAAG,OAAwB,CAAC;IAC/C,MAAM,gBAAgB,GAAG,UAA8B,CAAC;IAExD,IAAI,aAAa,CAAC,eAAe,EAAE,CAAC;QAClC,gBAAgB,CAAC,eAAe,GAAG,oBAAoB,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IACzF,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAsB,EAAE,OAAgB;IAC3E,MAAM,aAAa,GAAG,OAAwB,CAAC;IAC/C,MAAM,gBAAgB,GAAG,UAA8B,CAAC;IAExD,IAAI,gBAAgB,CAAC,eAAe,EAAE,CAAC;QACrC,aAAa,CAAC,eAAe,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC3F,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=serialization.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.test.d.ts","sourceRoot":"","sources":["../../src/bridge/serialization.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import { getMockedAccount, getMockedAccountRaw, mockHederaResources, mockHederaResourcesRaw, } from "../test/fixtures/account.fixture";
2
+ import { assignFromAccountRaw, assignToAccountRaw, fromHederaResourcesRaw, toHederaResourcesRaw, } from "./serialization";
3
+ const mockedAccount = getMockedAccount();
4
+ const mockedAccountRaw = getMockedAccountRaw();
5
+ describe("serialization", () => {
6
+ test("toHederaResourcesRaw should convert HederaResources to HederaResourcesRaw", () => {
7
+ const result = toHederaResourcesRaw(mockHederaResources);
8
+ expect(result).toEqual(mockHederaResourcesRaw);
9
+ });
10
+ test("fromHederaResourcesRaw should convert HederaResourcesRaw to HederaResources", () => {
11
+ const result = fromHederaResourcesRaw(mockHederaResourcesRaw);
12
+ expect(result).toEqual(mockHederaResources);
13
+ });
14
+ test("assignToAccountRaw should assign HederaResources to AccountRaw", () => {
15
+ assignToAccountRaw(mockedAccount, mockedAccountRaw);
16
+ expect(typeof mockedAccountRaw.hederaResources).toBe("object");
17
+ expect(mockedAccountRaw.hederaResources).not.toBeNull();
18
+ });
19
+ test("assignFromAccountRaw should assign HederaResourcesRaw to Account", () => {
20
+ assignFromAccountRaw(mockedAccountRaw, mockedAccount);
21
+ expect(typeof mockedAccountRaw.hederaResources).toBe("object");
22
+ expect(mockedAccountRaw.hederaResources).not.toBeNull();
23
+ });
24
+ });
25
+ //# sourceMappingURL=serialization.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.test.js","sourceRoot":"","sources":["../../src/bridge/serialization.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;AACzC,MAAM,gBAAgB,GAAG,mBAAmB,EAAE,CAAC;AAE/C,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,CAAC,2EAA2E,EAAE,GAAG,EAAE;QACrF,MAAM,MAAM,GAAG,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;QACzD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6EAA6E,EAAE,GAAG,EAAE;QACvF,MAAM,MAAM,GAAG,sBAAsB,CAAC,sBAAsB,CAAC,CAAC;QAC9D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,gEAAgE,EAAE,GAAG,EAAE;QAC1E,kBAAkB,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;QACpD,MAAM,CAAC,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/D,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,kEAAkE,EAAE,GAAG,EAAE;QAC5E,oBAAoB,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;QACtD,MAAM,CAAC,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/D,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { Account } from "@ledgerhq/types-live";
2
- import { GetAccountShape, IterateResultBuilder } from "@ledgerhq/coin-framework/bridge/jsHelpers";
3
- export declare const getAccountShape: GetAccountShape<Account>;
1
+ import type { GetAccountShape, IterateResultBuilder } from "@ledgerhq/coin-framework/bridge/jsHelpers";
2
+ import type { HederaAccount } from "../types";
3
+ export declare const getAccountShape: GetAccountShape<HederaAccount>;
4
4
  export declare const buildIterateResult: IterateResultBuilder;
5
5
  //# sourceMappingURL=synchronisation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"synchronisation.d.ts","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EACL,eAAe,EACf,oBAAoB,EAErB,MAAM,2CAA2C,CAAC;AAInD,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,OAAO,CA2CpD,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,oBAoBhC,CAAC"}
1
+ {"version":3,"file":"synchronisation.d.ts","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACrB,MAAM,2CAA2C,CAAC;AAWnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,aAAa,CA4E1D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,oBAqBhC,CAAC"}
@@ -1,11 +1,12 @@
1
- import invariant from "invariant";
2
- import { getDerivationScheme, runDerivationScheme, } from "@ledgerhq/coin-framework/derivation";
3
1
  import { BigNumber } from "bignumber.js";
4
- import { getAccountsForPublicKey, getOperationsForAccount } from "../api/mirror";
5
- import { mergeOps, } from "@ledgerhq/coin-framework/bridge/jsHelpers";
2
+ import invariant from "invariant";
3
+ import { getDerivationScheme, runDerivationScheme } from "@ledgerhq/coin-framework/derivation";
4
+ import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
6
5
  import { encodeAccountId } from "@ledgerhq/coin-framework/account";
7
- import { getAccountBalance } from "../api/network";
8
- export const getAccountShape = async (info) => {
6
+ import { getAccount, getAccountsForPublicKey, getAccountTokens } from "../api/mirror";
7
+ import { getSubAccounts, prepareOperations, applyPendingExtras, mergeSubAccounts, getSyncHash, } from "./utils";
8
+ import { getOperationsForAccount } from "../api/utils";
9
+ export const getAccountShape = async (info, { blacklistedTokenIds }) => {
9
10
  const { currency, derivationMode, address, initialAccount } = info;
10
11
  invariant(address, "an hedera address is expected");
11
12
  const liveAccountId = encodeAccountId({
@@ -15,31 +16,52 @@ export const getAccountShape = async (info) => {
15
16
  xpubOrAddress: address,
16
17
  derivationMode,
17
18
  });
18
- // get current account balance
19
- const accountBalance = await getAccountBalance(address);
20
- // grab latest operation's consensus timestamp for incremental sync
19
+ // get current account balance and tokens
20
+ // tokens are fetched with separate requests to get "created_timestamp" for each token
21
+ // based on this, ASSOCIATE_TOKEN operations can be connected with tokens
22
+ const [mirrorAccount, mirrorTokens] = await Promise.all([
23
+ getAccount(address),
24
+ getAccountTokens(address),
25
+ ]);
26
+ // we should sync again when new tokens are added or blacklist changes
27
+ const syncHash = getSyncHash(currency, blacklistedTokenIds);
28
+ const shouldSyncFromScratch = !initialAccount || syncHash !== initialAccount?.syncHash;
21
29
  const oldOperations = initialAccount?.operations ?? [];
22
- const latestOperationTimestamp = oldOperations[0]
30
+ const pendingOperations = initialAccount?.pendingOperations ?? [];
31
+ // grab latest operation's consensus timestamp for incremental sync
32
+ const latestOperationTimestamp = !shouldSyncFromScratch && oldOperations[0]
23
33
  ? new BigNumber(Math.floor(oldOperations[0].date.getTime() / 1000))
24
34
  : null;
25
- // merge new operations w/ previously synced ones
26
- const newOperations = await getOperationsForAccount(liveAccountId, address, latestOperationTimestamp ? latestOperationTimestamp.toString() : null);
27
- const operations = mergeOps(oldOperations, newOperations);
35
+ const latestAccountOperations = await getOperationsForAccount(liveAccountId, address, latestOperationTimestamp ? latestOperationTimestamp.toString() : null);
36
+ const newSubAccounts = await getSubAccounts(liveAccountId, latestAccountOperations.tokenOperations, mirrorTokens);
37
+ const subAccounts = mergeSubAccounts(initialAccount, newSubAccounts);
38
+ const newOperations = prepareOperations(latestAccountOperations.coinOperations, latestAccountOperations.tokenOperations, mirrorTokens);
39
+ const enrichedNewOperations = applyPendingExtras(newOperations, pendingOperations);
40
+ const operations = shouldSyncFromScratch
41
+ ? enrichedNewOperations
42
+ : mergeOps(oldOperations, enrichedNewOperations);
28
43
  return {
29
44
  id: liveAccountId,
30
45
  freshAddress: address,
31
- balance: accountBalance.balance,
32
- spendableBalance: accountBalance.balance,
46
+ syncHash,
47
+ lastSyncDate: new Date(),
48
+ balance: new BigNumber(mirrorAccount.balance.balance),
49
+ spendableBalance: new BigNumber(mirrorAccount.balance.balance),
33
50
  operations,
34
51
  operationsCount: operations.length,
35
52
  // NOTE: there are no "blocks" in hedera
36
53
  // Set a value just so that operations are considered confirmed according to isConfirmedOperation
37
54
  blockHeight: 10,
55
+ subAccounts,
56
+ hederaResources: {
57
+ maxAutomaticTokenAssociations: mirrorAccount.max_automatic_token_associations,
58
+ isAutoTokenAssociationEnabled: mirrorAccount.max_automatic_token_associations === -1,
59
+ },
38
60
  };
39
61
  };
40
62
  export const buildIterateResult = async ({ result: rootResult }) => {
41
- const accounts = await getAccountsForPublicKey(rootResult.publicKey);
42
- const addresses = accounts.map(a => a.accountId.toString());
63
+ const mirrorAccounts = await getAccountsForPublicKey(rootResult.publicKey);
64
+ const addresses = mirrorAccounts.map(a => a.account);
43
65
  return async ({ currency, derivationMode, index }) => {
44
66
  const derivationScheme = getDerivationScheme({
45
67
  derivationMode,
@@ -1 +1 @@
1
- {"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,mBAAmB,EAEnB,mBAAmB,GACpB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAGL,QAAQ,GACT,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,CAAC,MA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,kBAAkB,GAAyB,KAAK,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE;IACvF,MAAM,cAAc,GAAG,MAAM,uBAAuB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAC3E,MAAM,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAErD,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,EAAE;QACnD,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;YAC3C,cAAc;YACd,QAAQ;SACT,CAAC,CAAC;QACH,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,gBAAgB,EAAE,QAAQ,EAAE;YACvE,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC,KAAK,CAAC;YACrB,CAAC,CAAE;gBACC,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC;gBACzB,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC;gBAC3B,IAAI,EAAE,gBAAgB;aACZ;YACd,CAAC,CAAC,IAAI,CAAC;IACX,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,72 +1,31 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import { formatTransaction, fromTransactionRaw, toTransactionRaw } from "../transaction";
3
- const account = {
4
- type: "Account",
5
- id: "",
6
- seedIdentifier: "",
7
- derivationMode: "",
8
- index: 0,
9
- freshAddress: "",
10
- freshAddressPath: "",
11
- used: false,
12
- balance: new BigNumber(200000),
13
- spendableBalance: new BigNumber(0),
14
- creationDate: new Date(),
15
- blockHeight: 0,
16
- currency: {
17
- type: "CryptoCurrency",
18
- id: "hedera",
19
- managerAppName: "",
20
- coinType: 0,
21
- scheme: "",
22
- color: "",
23
- family: "",
24
- explorerViews: [],
25
- name: "",
26
- ticker: "",
27
- units: [
28
- {
29
- name: "",
30
- code: "",
31
- magnitude: 0,
32
- },
33
- ],
34
- },
35
- operationsCount: 0,
36
- operations: [],
37
- pendingOperations: [],
38
- lastSyncDate: new Date(),
39
- balanceHistoryCache: {
40
- HOUR: { latestDate: null, balances: [] },
41
- DAY: { latestDate: null, balances: [] },
42
- WEEK: { latestDate: null, balances: [] },
43
- },
44
- swapHistory: [],
45
- };
46
- const transaction = {
47
- family: "hedera",
48
- amount: new BigNumber(1),
49
- recipient: "0.0.3",
50
- };
51
- const transactionRaw = {
52
- family: "hedera",
53
- amount: "1",
54
- recipient: "0.0.3",
55
- };
3
+ import { getMockedAccount } from "../test/fixtures/account.fixture";
4
+ import { getMockedTransaction, getMockedTransactionRaw, } from "../test/fixtures/transaction.fixture";
56
5
  describe("transaction", () => {
6
+ const mockedAccount = getMockedAccount();
7
+ const mockedTransaction = getMockedTransaction({
8
+ amount: new BigNumber(100000000),
9
+ recipient: "0.0.3",
10
+ });
11
+ const mockedTransactionRaw = getMockedTransactionRaw({
12
+ amount: "100000000",
13
+ recipient: "0.0.3",
14
+ });
57
15
  test("formatTransaction", () => {
58
- const result = formatTransaction(transaction, account);
59
- const string = `SEND 1\nTO 0.0.3`;
16
+ const result = formatTransaction(mockedTransaction, mockedAccount);
17
+ const nonBreakingSpace = String.fromCharCode(160);
18
+ const string = `SEND 1${nonBreakingSpace}HBAR\nTO 0.0.3`;
60
19
  expect(result).toEqual(string);
61
20
  });
62
21
  test("fromTransactionRaw", () => {
63
- const result = fromTransactionRaw(transactionRaw);
64
- const data = transaction;
22
+ const result = fromTransactionRaw(mockedTransactionRaw);
23
+ const data = mockedTransaction;
65
24
  expect(result).toEqual(data);
66
25
  });
67
26
  test("toTransactionRaw", () => {
68
- const result = toTransactionRaw(transaction);
69
- const data = transactionRaw;
27
+ const result = toTransactionRaw(mockedTransaction);
28
+ const data = mockedTransactionRaw;
70
29
  expect(result).toEqual(data);
71
30
  });
72
31
  });
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.test.js","sourceRoot":"","sources":["../../src/bridge/transa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I,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,15 +1,29 @@
1
1
  import BigNumber from "bignumber.js";
2
- import type { Account, Operation } from "@ledgerhq/types-live";
2
+ import type { Account, Operation, TokenAccount } from "@ledgerhq/types-live";
3
+ import type { CryptoCurrency, Currency } from "@ledgerhq/types-cryptoassets";
3
4
  import type { HederaOperationExtra, Transaction } from "../types";
4
- export declare const estimatedFeeSafetyRate = 2;
5
- export declare function getEstimatedFees(account: Account): Promise<BigNumber>;
6
- export declare function calculateAmount({ account, transaction, }: {
7
- account: Account;
8
- transaction: Transaction;
9
- }): Promise<{
5
+ import type { HederaMirrorToken } from "../api/types";
6
+ import { HEDERA_OPERATION_TYPES } from "../constants";
7
+ export declare const getCurrencyToUSDRate: import("@ledgerhq/live-network/cache").CacheRes<[currency: Currency], BigNumber | null>;
8
+ export declare const getEstimatedFees: (account: Account, operationType: HEDERA_OPERATION_TYPES) => Promise<BigNumber>;
9
+ interface CalculateAmountResult {
10
10
  amount: BigNumber;
11
11
  totalSpent: BigNumber;
12
- }>;
12
+ }
13
+ export declare const calculateAmount: ({ account, transaction, }: {
14
+ account: Account;
15
+ transaction: Transaction;
16
+ }) => Promise<CalculateAmountResult>;
13
17
  export declare function base64ToUrlSafeBase64(data: string): string;
18
+ export declare const getSyncHash: (currency: CryptoCurrency, blacklistedTokenIds?: string[]) => string;
19
+ export declare const getSubAccounts: (accountId: string, lastTokenOperations: Operation[], mirrorTokens: HederaMirrorToken[]) => Promise<TokenAccount[]>;
20
+ export declare const prepareOperations: (coinOperations: Operation[], tokenOperations: Operation[], mirrorTokens: HederaMirrorToken[]) => Operation[];
21
+ /**
22
+ * In charge of smartly merging sub accounts while maintaining references as much as possible
23
+ */
24
+ export declare const mergeSubAccounts: (initialAccount: Account | undefined, newSubAccounts: TokenAccount[]) => Array<TokenAccount>;
25
+ export declare const applyPendingExtras: (existing: Operation[], pending: Operation[]) => Operation[];
14
26
  export declare function patchOperationWithExtra(operation: Operation, extra: HederaOperationExtra): Operation;
27
+ export declare const checkAccountTokenAssociationStatus: import("@ledgerhq/live-network/cache").CacheRes<[accountId: string, tokenId: string], boolean>;
28
+ export {};
15
29
  //# sourceMappingURL=utils.d.ts.map