@ledgerhq/live-common 34.45.0-nightly.0 → 34.45.0-nightly.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 (298) hide show
  1. package/lib/__tests__/test-helpers/bridge.d.ts.map +1 -1
  2. package/lib/__tests__/test-helpers/bridge.js +3 -1
  3. package/lib/__tests__/test-helpers/bridge.js.map +1 -1
  4. package/lib/braze/anonymousUsers.d.ts +1 -0
  5. package/lib/braze/anonymousUsers.d.ts.map +1 -1
  6. package/lib/braze/anonymousUsers.js +7 -5
  7. package/lib/braze/anonymousUsers.js.map +1 -1
  8. package/lib/bridge/generic-alpaca/accountBridge.d.ts +1 -1
  9. package/lib/bridge/generic-alpaca/accountBridge.d.ts.map +1 -1
  10. package/lib/bridge/generic-alpaca/accountBridge.js.map +1 -1
  11. package/lib/bridge/generic-alpaca/alpaca/index.d.ts +1 -1
  12. package/lib/bridge/generic-alpaca/alpaca/index.d.ts.map +1 -1
  13. package/lib/bridge/generic-alpaca/alpaca/index.js +4 -2
  14. package/lib/bridge/generic-alpaca/alpaca/index.js.map +1 -1
  15. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +4 -4
  16. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
  17. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js +10 -10
  18. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
  19. package/lib/bridge/generic-alpaca/broadcast.d.ts +1 -1
  20. package/lib/bridge/generic-alpaca/broadcast.d.ts.map +1 -1
  21. package/lib/bridge/generic-alpaca/broadcast.js.map +1 -1
  22. package/lib/bridge/generic-alpaca/buildSubAccounts.d.ts +17 -0
  23. package/lib/bridge/generic-alpaca/buildSubAccounts.d.ts.map +1 -0
  24. package/lib/bridge/generic-alpaca/buildSubAccounts.js +75 -0
  25. package/lib/bridge/generic-alpaca/buildSubAccounts.js.map +1 -0
  26. package/lib/bridge/generic-alpaca/createTransaction.d.ts +17 -9
  27. package/lib/bridge/generic-alpaca/createTransaction.d.ts.map +1 -1
  28. package/lib/bridge/generic-alpaca/createTransaction.js +36 -10
  29. package/lib/bridge/generic-alpaca/createTransaction.js.map +1 -1
  30. package/lib/bridge/generic-alpaca/currencyBridge.d.ts +1 -1
  31. package/lib/bridge/generic-alpaca/currencyBridge.d.ts.map +1 -1
  32. package/lib/bridge/generic-alpaca/currencyBridge.js.map +1 -1
  33. package/lib/bridge/generic-alpaca/estimateMaxSpendable.d.ts +1 -1
  34. package/lib/bridge/generic-alpaca/estimateMaxSpendable.d.ts.map +1 -1
  35. package/lib/bridge/generic-alpaca/estimateMaxSpendable.js +9 -0
  36. package/lib/bridge/generic-alpaca/estimateMaxSpendable.js.map +1 -1
  37. package/lib/bridge/generic-alpaca/getAccountShape.d.ts +1 -1
  38. package/lib/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
  39. package/lib/bridge/generic-alpaca/getAccountShape.js +66 -37
  40. package/lib/bridge/generic-alpaca/getAccountShape.js.map +1 -1
  41. package/lib/bridge/generic-alpaca/getTransactionStatus.d.ts +1 -1
  42. package/lib/bridge/generic-alpaca/getTransactionStatus.d.ts.map +1 -1
  43. package/lib/bridge/generic-alpaca/getTransactionStatus.js +27 -15
  44. package/lib/bridge/generic-alpaca/getTransactionStatus.js.map +1 -1
  45. package/lib/bridge/generic-alpaca/prepareTransaction.d.ts +5 -1
  46. package/lib/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
  47. package/lib/bridge/generic-alpaca/prepareTransaction.js +28 -5
  48. package/lib/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
  49. package/lib/bridge/generic-alpaca/signOperation.d.ts +1 -1
  50. package/lib/bridge/generic-alpaca/signOperation.d.ts.map +1 -1
  51. package/lib/bridge/generic-alpaca/signOperation.js +64 -13
  52. package/lib/bridge/generic-alpaca/signOperation.js.map +1 -1
  53. package/lib/bridge/generic-alpaca/signer/index.d.ts +1 -1
  54. package/lib/bridge/generic-alpaca/signer/index.d.ts.map +1 -1
  55. package/lib/bridge/generic-alpaca/signer/index.js +38 -5
  56. package/lib/bridge/generic-alpaca/signer/index.js.map +1 -1
  57. package/lib/bridge/generic-alpaca/signer/signTransaction.d.ts +2 -0
  58. package/lib/bridge/generic-alpaca/signer/signTransaction.d.ts.map +1 -1
  59. package/lib/bridge/generic-alpaca/signer/signTransaction.js +8 -1
  60. package/lib/bridge/generic-alpaca/signer/signTransaction.js.map +1 -1
  61. package/lib/bridge/generic-alpaca/signer/types.d.ts +3 -0
  62. package/lib/bridge/generic-alpaca/signer/types.d.ts.map +1 -1
  63. package/lib/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js +70 -46
  64. package/lib/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js.map +1 -1
  65. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js +1 -1
  66. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
  67. package/lib/bridge/generic-alpaca/tests/signOperation.test.js +25 -22
  68. package/lib/bridge/generic-alpaca/tests/signOperation.test.js.map +1 -1
  69. package/lib/bridge/generic-alpaca/tests/utils.test.d.ts.map +1 -0
  70. package/lib/bridge/generic-alpaca/{utils.test.js → tests/utils.test.js} +1 -1
  71. package/lib/bridge/generic-alpaca/tests/utils.test.js.map +1 -0
  72. package/lib/bridge/generic-alpaca/utils.d.ts +36 -1
  73. package/lib/bridge/generic-alpaca/utils.d.ts.map +1 -1
  74. package/lib/bridge/generic-alpaca/utils.js +130 -14
  75. package/lib/bridge/generic-alpaca/utils.js.map +1 -1
  76. package/lib/bridge/impl.d.ts.map +1 -1
  77. package/lib/bridge/impl.js +5 -4
  78. package/lib/bridge/impl.js.map +1 -1
  79. package/lib/e2e/enum/Account.js +4 -4
  80. package/lib/e2e/enum/Account.js.map +1 -1
  81. package/lib/e2e/enum/AppInfos.d.ts +1 -1
  82. package/lib/e2e/enum/AppInfos.d.ts.map +1 -1
  83. package/lib/e2e/enum/AppInfos.js +1 -1
  84. package/lib/e2e/enum/AppInfos.js.map +1 -1
  85. package/lib/e2e/enum/Currency.d.ts.map +1 -1
  86. package/lib/e2e/enum/Currency.js +3 -3
  87. package/lib/e2e/enum/Currency.js.map +1 -1
  88. package/lib/e2e/speculos.js +2 -2
  89. package/lib/e2e/speculos.js.map +1 -1
  90. package/lib/exchange/index.d.ts.map +1 -1
  91. package/lib/exchange/index.js +1 -0
  92. package/lib/exchange/index.js.map +1 -1
  93. package/lib/families/stellar/bridge/logic.d.ts +1 -1
  94. package/lib/families/stellar/bridge/logic.d.ts.map +1 -1
  95. package/lib/families/stellar/bridge/logic.js +1 -1
  96. package/lib/families/stellar/bridge/logic.js.map +1 -1
  97. package/lib/families/stellar/bridge/mock.js +2 -2
  98. package/lib/families/stellar/bridge/mock.js.map +1 -1
  99. package/lib/families/stellar/setup.d.ts +3 -6
  100. package/lib/families/stellar/setup.d.ts.map +1 -1
  101. package/lib/families/stellar/setup.js +3 -12
  102. package/lib/families/stellar/setup.js.map +1 -1
  103. package/lib/families/xrp/bridge/mock.js +2 -2
  104. package/lib/families/xrp/bridge/mock.js.map +1 -1
  105. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  106. package/lib/featureFlags/defaultFeatures.js +4 -2
  107. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  108. package/lib/generated/bridge/js.d.ts +0 -1
  109. package/lib/generated/bridge/js.d.ts.map +1 -1
  110. package/lib/generated/bridge/js.js +12 -14
  111. package/lib/generated/bridge/js.js.map +1 -1
  112. package/lib/generated/transaction.d.ts +1 -1
  113. package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.js +229 -14
  114. package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.js.map +1 -1
  115. package/lib/modularDrawer/enums.d.ts +0 -1
  116. package/lib/modularDrawer/enums.d.ts.map +1 -1
  117. package/lib/modularDrawer/enums.js +0 -1
  118. package/lib/modularDrawer/enums.js.map +1 -1
  119. package/lib/modularDrawer/useModularDrawerVisibility.d.ts +7 -1
  120. package/lib/modularDrawer/useModularDrawerVisibility.d.ts.map +1 -1
  121. package/lib/modularDrawer/useModularDrawerVisibility.js +18 -2
  122. package/lib/modularDrawer/useModularDrawerVisibility.js.map +1 -1
  123. package/lib-es/__tests__/test-helpers/bridge.d.ts.map +1 -1
  124. package/lib-es/__tests__/test-helpers/bridge.js +3 -1
  125. package/lib-es/__tests__/test-helpers/bridge.js.map +1 -1
  126. package/lib-es/braze/anonymousUsers.d.ts +1 -0
  127. package/lib-es/braze/anonymousUsers.d.ts.map +1 -1
  128. package/lib-es/braze/anonymousUsers.js +5 -4
  129. package/lib-es/braze/anonymousUsers.js.map +1 -1
  130. package/lib-es/bridge/generic-alpaca/accountBridge.d.ts +1 -1
  131. package/lib-es/bridge/generic-alpaca/accountBridge.d.ts.map +1 -1
  132. package/lib-es/bridge/generic-alpaca/accountBridge.js.map +1 -1
  133. package/lib-es/bridge/generic-alpaca/alpaca/index.d.ts +1 -1
  134. package/lib-es/bridge/generic-alpaca/alpaca/index.d.ts.map +1 -1
  135. package/lib-es/bridge/generic-alpaca/alpaca/index.js +4 -2
  136. package/lib-es/bridge/generic-alpaca/alpaca/index.js.map +1 -1
  137. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +4 -4
  138. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
  139. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js +10 -10
  140. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
  141. package/lib-es/bridge/generic-alpaca/broadcast.d.ts +1 -1
  142. package/lib-es/bridge/generic-alpaca/broadcast.d.ts.map +1 -1
  143. package/lib-es/bridge/generic-alpaca/broadcast.js.map +1 -1
  144. package/lib-es/bridge/generic-alpaca/buildSubAccounts.d.ts +17 -0
  145. package/lib-es/bridge/generic-alpaca/buildSubAccounts.d.ts.map +1 -0
  146. package/lib-es/bridge/generic-alpaca/buildSubAccounts.js +65 -0
  147. package/lib-es/bridge/generic-alpaca/buildSubAccounts.js.map +1 -0
  148. package/lib-es/bridge/generic-alpaca/createTransaction.d.ts +17 -9
  149. package/lib-es/bridge/generic-alpaca/createTransaction.d.ts.map +1 -1
  150. package/lib-es/bridge/generic-alpaca/createTransaction.js +35 -9
  151. package/lib-es/bridge/generic-alpaca/createTransaction.js.map +1 -1
  152. package/lib-es/bridge/generic-alpaca/currencyBridge.d.ts +1 -1
  153. package/lib-es/bridge/generic-alpaca/currencyBridge.d.ts.map +1 -1
  154. package/lib-es/bridge/generic-alpaca/currencyBridge.js.map +1 -1
  155. package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.d.ts +1 -1
  156. package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.d.ts.map +1 -1
  157. package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.js +9 -0
  158. package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.js.map +1 -1
  159. package/lib-es/bridge/generic-alpaca/getAccountShape.d.ts +1 -1
  160. package/lib-es/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
  161. package/lib-es/bridge/generic-alpaca/getAccountShape.js +66 -37
  162. package/lib-es/bridge/generic-alpaca/getAccountShape.js.map +1 -1
  163. package/lib-es/bridge/generic-alpaca/getTransactionStatus.d.ts +1 -1
  164. package/lib-es/bridge/generic-alpaca/getTransactionStatus.d.ts.map +1 -1
  165. package/lib-es/bridge/generic-alpaca/getTransactionStatus.js +27 -15
  166. package/lib-es/bridge/generic-alpaca/getTransactionStatus.js.map +1 -1
  167. package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts +5 -1
  168. package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
  169. package/lib-es/bridge/generic-alpaca/prepareTransaction.js +26 -4
  170. package/lib-es/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
  171. package/lib-es/bridge/generic-alpaca/signOperation.d.ts +1 -1
  172. package/lib-es/bridge/generic-alpaca/signOperation.d.ts.map +1 -1
  173. package/lib-es/bridge/generic-alpaca/signOperation.js +61 -13
  174. package/lib-es/bridge/generic-alpaca/signOperation.js.map +1 -1
  175. package/lib-es/bridge/generic-alpaca/signer/index.d.ts +1 -1
  176. package/lib-es/bridge/generic-alpaca/signer/index.d.ts.map +1 -1
  177. package/lib-es/bridge/generic-alpaca/signer/index.js +39 -6
  178. package/lib-es/bridge/generic-alpaca/signer/index.js.map +1 -1
  179. package/lib-es/bridge/generic-alpaca/signer/signTransaction.d.ts +2 -0
  180. package/lib-es/bridge/generic-alpaca/signer/signTransaction.d.ts.map +1 -1
  181. package/lib-es/bridge/generic-alpaca/signer/signTransaction.js +6 -0
  182. package/lib-es/bridge/generic-alpaca/signer/signTransaction.js.map +1 -1
  183. package/lib-es/bridge/generic-alpaca/signer/types.d.ts +3 -0
  184. package/lib-es/bridge/generic-alpaca/signer/types.d.ts.map +1 -1
  185. package/lib-es/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js +70 -46
  186. package/lib-es/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js.map +1 -1
  187. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js +1 -1
  188. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
  189. package/lib-es/bridge/generic-alpaca/tests/signOperation.test.js +25 -22
  190. package/lib-es/bridge/generic-alpaca/tests/signOperation.test.js.map +1 -1
  191. package/lib-es/bridge/generic-alpaca/tests/utils.test.d.ts.map +1 -0
  192. package/lib-es/bridge/generic-alpaca/{utils.test.js → tests/utils.test.js} +1 -1
  193. package/lib-es/bridge/generic-alpaca/tests/utils.test.js.map +1 -0
  194. package/lib-es/bridge/generic-alpaca/utils.d.ts +36 -1
  195. package/lib-es/bridge/generic-alpaca/utils.d.ts.map +1 -1
  196. package/lib-es/bridge/generic-alpaca/utils.js +130 -14
  197. package/lib-es/bridge/generic-alpaca/utils.js.map +1 -1
  198. package/lib-es/bridge/impl.d.ts.map +1 -1
  199. package/lib-es/bridge/impl.js +5 -4
  200. package/lib-es/bridge/impl.js.map +1 -1
  201. package/lib-es/e2e/enum/Account.js +4 -4
  202. package/lib-es/e2e/enum/Account.js.map +1 -1
  203. package/lib-es/e2e/enum/AppInfos.d.ts +1 -1
  204. package/lib-es/e2e/enum/AppInfos.d.ts.map +1 -1
  205. package/lib-es/e2e/enum/AppInfos.js +1 -1
  206. package/lib-es/e2e/enum/AppInfos.js.map +1 -1
  207. package/lib-es/e2e/enum/Currency.d.ts.map +1 -1
  208. package/lib-es/e2e/enum/Currency.js +3 -3
  209. package/lib-es/e2e/enum/Currency.js.map +1 -1
  210. package/lib-es/e2e/speculos.js +2 -2
  211. package/lib-es/e2e/speculos.js.map +1 -1
  212. package/lib-es/exchange/index.d.ts.map +1 -1
  213. package/lib-es/exchange/index.js +1 -0
  214. package/lib-es/exchange/index.js.map +1 -1
  215. package/lib-es/families/stellar/bridge/logic.d.ts +1 -1
  216. package/lib-es/families/stellar/bridge/logic.d.ts.map +1 -1
  217. package/lib-es/families/stellar/bridge/logic.js +1 -1
  218. package/lib-es/families/stellar/bridge/logic.js.map +1 -1
  219. package/lib-es/families/stellar/bridge/mock.js +2 -2
  220. package/lib-es/families/stellar/bridge/mock.js.map +1 -1
  221. package/lib-es/families/stellar/setup.d.ts +3 -6
  222. package/lib-es/families/stellar/setup.d.ts.map +1 -1
  223. package/lib-es/families/stellar/setup.js +2 -10
  224. package/lib-es/families/stellar/setup.js.map +1 -1
  225. package/lib-es/families/xrp/bridge/mock.js +2 -2
  226. package/lib-es/families/xrp/bridge/mock.js.map +1 -1
  227. package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
  228. package/lib-es/featureFlags/defaultFeatures.js +4 -2
  229. package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
  230. package/lib-es/generated/bridge/js.d.ts +0 -1
  231. package/lib-es/generated/bridge/js.d.ts.map +1 -1
  232. package/lib-es/generated/bridge/js.js +0 -2
  233. package/lib-es/generated/bridge/js.js.map +1 -1
  234. package/lib-es/generated/transaction.d.ts +1 -1
  235. package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.js +229 -14
  236. package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.js.map +1 -1
  237. package/lib-es/modularDrawer/enums.d.ts +0 -1
  238. package/lib-es/modularDrawer/enums.d.ts.map +1 -1
  239. package/lib-es/modularDrawer/enums.js +0 -1
  240. package/lib-es/modularDrawer/enums.js.map +1 -1
  241. package/lib-es/modularDrawer/useModularDrawerVisibility.d.ts +7 -1
  242. package/lib-es/modularDrawer/useModularDrawerVisibility.d.ts.map +1 -1
  243. package/lib-es/modularDrawer/useModularDrawerVisibility.js +18 -2
  244. package/lib-es/modularDrawer/useModularDrawerVisibility.js.map +1 -1
  245. package/package.json +49 -48
  246. package/src/__tests__/test-helpers/bridge.ts +3 -1
  247. package/src/braze/anonymousUsers.ts +7 -4
  248. package/src/bridge/generic-alpaca/accountBridge.ts +1 -4
  249. package/src/bridge/generic-alpaca/alpaca/index.ts +7 -2
  250. package/src/bridge/generic-alpaca/alpaca/network/network-alpaca.ts +17 -22
  251. package/src/bridge/generic-alpaca/broadcast.ts +1 -4
  252. package/src/bridge/generic-alpaca/buildSubAccounts.ts +110 -0
  253. package/src/bridge/generic-alpaca/createTransaction.ts +48 -18
  254. package/src/bridge/generic-alpaca/currencyBridge.ts +1 -1
  255. package/src/bridge/generic-alpaca/estimateMaxSpendable.ts +13 -4
  256. package/src/bridge/generic-alpaca/getAccountShape.ts +84 -46
  257. package/src/bridge/generic-alpaca/getTransactionStatus.ts +46 -22
  258. package/src/bridge/generic-alpaca/prepareTransaction.ts +41 -7
  259. package/src/bridge/generic-alpaca/signOperation.ts +85 -18
  260. package/src/bridge/generic-alpaca/signer/index.ts +43 -7
  261. package/src/bridge/generic-alpaca/signer/signTransaction.ts +11 -0
  262. package/src/bridge/generic-alpaca/signer/types.ts +1 -0
  263. package/src/bridge/generic-alpaca/tests/estimateMaxSpendable.test.ts +72 -47
  264. package/src/bridge/generic-alpaca/tests/prepareTransaction.test.ts +1 -1
  265. package/src/bridge/generic-alpaca/tests/signOperation.test.ts +28 -26
  266. package/src/bridge/generic-alpaca/{utils.test.ts → tests/utils.test.ts} +1 -1
  267. package/src/bridge/generic-alpaca/utils.ts +158 -18
  268. package/src/bridge/impl.ts +5 -4
  269. package/src/e2e/enum/Account.ts +4 -4
  270. package/src/e2e/enum/AppInfos.ts +1 -1
  271. package/src/e2e/enum/Currency.ts +3 -13
  272. package/src/e2e/speculos.ts +2 -2
  273. package/src/exchange/index.ts +1 -0
  274. package/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +569 -2068
  275. package/src/families/stellar/bridge/logic.ts +1 -1
  276. package/src/families/stellar/bridge/mock.ts +2 -2
  277. package/src/families/stellar/setup.ts +2 -22
  278. package/src/families/xrp/bridge/mock.ts +2 -2
  279. package/src/featureFlags/defaultFeatures.ts +4 -2
  280. package/src/generated/bridge/js.ts +0 -2
  281. package/src/modularDrawer/__test__/useModularDrawerVisibility.test.ts +345 -14
  282. package/src/modularDrawer/enums.ts +0 -1
  283. package/src/modularDrawer/useModularDrawerVisibility.ts +26 -2
  284. package/lib/bridge/generic-alpaca/utils.test.d.ts.map +0 -1
  285. package/lib/bridge/generic-alpaca/utils.test.js.map +0 -1
  286. package/lib/families/canton/bridge.integration.test.d.ts +0 -2
  287. package/lib/families/canton/bridge.integration.test.d.ts.map +0 -1
  288. package/lib/families/canton/bridge.integration.test.js +0 -7
  289. package/lib/families/canton/bridge.integration.test.js.map +0 -1
  290. package/lib-es/bridge/generic-alpaca/utils.test.d.ts.map +0 -1
  291. package/lib-es/bridge/generic-alpaca/utils.test.js.map +0 -1
  292. package/lib-es/families/canton/bridge.integration.test.d.ts +0 -2
  293. package/lib-es/families/canton/bridge.integration.test.d.ts.map +0 -1
  294. package/lib-es/families/canton/bridge.integration.test.js +0 -5
  295. package/lib-es/families/canton/bridge.integration.test.js.map +0 -1
  296. package/src/families/canton/bridge.integration.test.ts +0 -6
  297. /package/lib/bridge/generic-alpaca/{utils.test.d.ts → tests/utils.test.d.ts} +0 -0
  298. /package/lib-es/bridge/generic-alpaca/{utils.test.d.ts → tests/utils.test.d.ts} +0 -0
@@ -1,19 +1,24 @@
1
1
  import { createApi as createXrpApi } from "@ledgerhq/coin-xrp/api/index";
2
+ import { createApi as createStellarApi } from "@ledgerhq/coin-stellar/api/index";
2
3
  import { getCurrencyConfiguration } from "../../../config";
3
4
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
4
5
  import { getNetworkAlpacaApi } from "./network/network-alpaca";
5
6
  import { Api } from "@ledgerhq/coin-framework/api/types";
6
7
  import { XrpCoinConfig } from "@ledgerhq/coin-xrp/config";
8
+ import { StellarCoinConfig } from "@ledgerhq/coin-stellar/config";
7
9
 
8
- export function getAlpacaApi(network: string, kind: "local" | "remote"): Api<any> {
10
+ export function getAlpacaApi(network, kind): Api<any> {
9
11
  if (kind === "local") {
10
12
  switch (network) {
11
13
  case "ripple":
12
14
  case "xrp":
13
15
  return createXrpApi(
14
16
  getCurrencyConfiguration<XrpCoinConfig>(getCryptoCurrencyById("ripple")),
17
+ ) as Api<any>; // FIXME: createXrpApi returns a strongly typed Api<XrpSender>, fix Api<any> to allow it
18
+ case "stellar":
19
+ return createStellarApi(
20
+ getCurrencyConfiguration<StellarCoinConfig>(getCryptoCurrencyById("stellar")),
15
21
  ) as Api<any>;
16
- // as unknown as Api<any>; // FIXME: createXrpApi returns a strongly typed Api<XrpSender>, fix Api<any> to allow it
17
22
  }
18
23
  }
19
24
  return getNetworkAlpacaApi(network) satisfies Partial<Api<any>> as Api<any>;
@@ -1,5 +1,4 @@
1
- import {
2
- Account,
1
+ import type {
3
2
  Balance,
4
3
  Block,
5
4
  BlockInfo,
@@ -7,10 +6,9 @@ import {
7
6
  FeeEstimation,
8
7
  Pagination,
9
8
  TransactionIntent,
10
- Transaction,
11
9
  TransactionValidation,
12
- AccountInfo,
13
10
  Api,
11
+ AssetInfo,
14
12
  Cursor,
15
13
  Page,
16
14
  Stake,
@@ -18,7 +16,7 @@ import {
18
16
  } from "@ledgerhq/coin-framework/api/index";
19
17
  import network from "@ledgerhq/live-network";
20
18
 
21
- function adaptOp(backendOp: any): Operation<any> {
19
+ function adaptOp<T extends AssetInfo>(backendOp: Operation<T>): Operation<T> {
22
20
  const { date } = backendOp.tx;
23
21
  const newDate = new Date(date);
24
22
 
@@ -31,7 +29,7 @@ function adaptOp(backendOp: any): Operation<any> {
31
29
 
32
30
  const ALPACA_URL = "http://0.0.0.0:3000";
33
31
 
34
- const buildBroadcast = (networkFamily: string) =>
32
+ const buildBroadcast = networkFamily =>
35
33
  async function broadcast(signedOperation: string): Promise<string> {
36
34
  const { data } = await network<
37
35
  {
@@ -50,7 +48,7 @@ const buildBroadcast = (networkFamily: string) =>
50
48
  return data.transactionIdentifier;
51
49
  };
52
50
 
53
- const buildCombine = (networkFamily: string) =>
51
+ const buildCombine = networkFamily =>
54
52
  async function combine(tx: string, signature: string, pubKey?: string): Promise<string> {
55
53
  const { data } = await network<
56
54
  {
@@ -69,7 +67,7 @@ const buildCombine = (networkFamily: string) =>
69
67
  return data.signedTransaction;
70
68
  };
71
69
 
72
- const buildEstimateFees = (networkFamily: string) =>
70
+ const buildEstimateFees = networkFamily =>
73
71
  async function estimateFees(intent: TransactionIntent<any>): Promise<FeeEstimation> {
74
72
  const { data } = await network<{ fee: string }, unknown>({
75
73
  method: "POST",
@@ -86,11 +84,8 @@ const buildEstimateFees = (networkFamily: string) =>
86
84
  };
87
85
  };
88
86
 
89
- const buildValidateIntent = (networkFamily: string) =>
90
- async function validateIntent(
91
- account: Account,
92
- transaction: Transaction,
93
- ): Promise<TransactionValidation> {
87
+ const buildValidateIntent = networkFamily =>
88
+ async function validateIntent(transaction: TransactionIntent): Promise<TransactionValidation> {
94
89
  const { data } = await network<
95
90
  {
96
91
  errors: Record<string, Error>;
@@ -105,7 +100,6 @@ const buildValidateIntent = (networkFamily: string) =>
105
100
  url: `${ALPACA_URL}/${networkFamily}/transaction/validate`,
106
101
  data: {
107
102
  transaction,
108
- account,
109
103
  },
110
104
  });
111
105
  return data;
@@ -122,13 +116,14 @@ const buildGetBalance = (networkFamily: string) =>
122
116
  {
123
117
  value: BigInt(data.value),
124
118
  asset: data.asset,
119
+ locked: BigInt(data?.locked ?? "0"),
125
120
  },
126
121
  ];
127
122
  };
128
123
 
129
- const buildGetAccountInfo = (networkFamily: string) =>
130
- async function getBalance(address: string): Promise<AccountInfo> {
131
- const { data } = await network<AccountInfo, unknown>({
124
+ const buildGetSequence = (networkFamily: string) =>
125
+ async function getSequence(address: string): Promise<number> {
126
+ const { data } = await network<number, unknown>({
132
127
  method: "GET",
133
128
  url: `${ALPACA_URL}/${networkFamily}/account/${address}/info`,
134
129
  });
@@ -136,10 +131,10 @@ const buildGetAccountInfo = (networkFamily: string) =>
136
131
  return data;
137
132
  };
138
133
 
139
- const buildListOperations = (networkFamily: string) =>
134
+ const buildListOperations = networkFamily =>
140
135
  async function listOperations(
141
136
  address: string,
142
- pagination: Pagination,
137
+ pagination: Pagination = { minHeight: 0 },
143
138
  ): Promise<[Operation<any>[], string]> {
144
139
  const { data } = await network<{ operations: Operation<any>[] }, unknown>({
145
140
  method: "GET",
@@ -151,7 +146,7 @@ const buildListOperations = (networkFamily: string) =>
151
146
  return [data.operations.map(op => adaptOp(op)), ""];
152
147
  };
153
148
 
154
- const buildLastBlock = (networkFamily: string) =>
149
+ const buildLastBlock = networkFamily =>
155
150
  async function lastBlock(): Promise<BlockInfo> {
156
151
  const { data } = await network<any, unknown>({
157
152
  method: "GET",
@@ -164,7 +159,7 @@ const buildLastBlock = (networkFamily: string) =>
164
159
  };
165
160
  };
166
161
 
167
- const buildCraftTransaction = (networkFamily: string) =>
162
+ const buildCraftTransaction = networkFamily =>
168
163
  async function craftTransaction(intent: TransactionIntent<any>): Promise<string> {
169
164
  const { data } = await network<any, unknown>({
170
165
  method: "POST",
@@ -186,7 +181,7 @@ export const getNetworkAlpacaApi = (networkFamily: string) =>
186
181
  validateIntent: buildValidateIntent(networkFamily),
187
182
  estimateFees: buildEstimateFees(networkFamily),
188
183
  getBalance: buildGetBalance(networkFamily),
189
- getAccountInfo: buildGetAccountInfo(networkFamily),
184
+ getSequence: buildGetSequence(networkFamily),
190
185
  listOperations: buildListOperations(networkFamily),
191
186
  lastBlock: buildLastBlock(networkFamily),
192
187
  craftTransaction: buildCraftTransaction(networkFamily),
@@ -2,10 +2,7 @@ import { AccountBridge, TransactionCommon } from "@ledgerhq/types-live";
2
2
  import { patchOperationWithHash } from "../../operation";
3
3
  import { getAlpacaApi } from "./alpaca";
4
4
 
5
- export const genericBroadcast: (
6
- network: string,
7
- kind: "local" | "remote",
8
- ) => AccountBridge<TransactionCommon>["broadcast"] =
5
+ export const genericBroadcast: (network, kind) => AccountBridge<TransactionCommon>["broadcast"] =
9
6
  (network, kind) =>
10
7
  async ({ signedOperation: { signature, operation } }) => {
11
8
  const hash = await getAlpacaApi(network, kind).broadcast(signature);
@@ -0,0 +1,110 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
3
+ import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
4
+ import type { Operation, SyncConfig, TokenAccount } from "@ledgerhq/types-live";
5
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
6
+ import { listTokensForCryptoCurrency } from "@ledgerhq/cryptoassets";
7
+ import { AssetInfo, Balance } from "@ledgerhq/coin-framework/api/types";
8
+ import { findTokenById } from "@ledgerhq/cryptoassets/tokens";
9
+
10
+ export interface OperationCommon extends Operation {
11
+ extra: Record<string, any>;
12
+ }
13
+
14
+ export const getAssetIdFromTokenId = (tokenId: string): string => tokenId.split("/")[2];
15
+
16
+ export const getAssetIdFromAsset = (asset: AssetInfo) =>
17
+ asset.type !== "native" && "assetReference" in asset && "assetOwner" in asset
18
+ ? `${asset.assetReference}:${asset.assetOwner}`
19
+ : "";
20
+
21
+ function buildTokenAccount({
22
+ parentAccountId,
23
+ assetBalance,
24
+ token,
25
+ operations,
26
+ }: {
27
+ parentAccountId: string;
28
+ assetBalance: Balance;
29
+ token: TokenCurrency;
30
+ operations: OperationCommon[];
31
+ }): TokenAccount {
32
+ const assetId = getAssetIdFromTokenId(token.id);
33
+ const id = `${parentAccountId}+${assetId}`;
34
+ const balance = new BigNumber(assetBalance.value.toString() || "0");
35
+
36
+ // TODO: recheck this logic
37
+ const spendableBalance = new BigNumber(assetBalance.value.toString()).minus(
38
+ new BigNumber(assetBalance.locked?.toString() || "0"),
39
+ );
40
+
41
+ const tokenOperations = operations.map(op => ({
42
+ ...op,
43
+ id: encodeOperationId(id, op.hash, op.extra?.ledgerOpType),
44
+ accountId: id,
45
+ type: op.extra?.ledgerOpType,
46
+ value: op.extra?.assetAmount ? new BigNumber(op.extra?.assetAmount) : op.value,
47
+ }));
48
+
49
+ return {
50
+ type: "TokenAccount",
51
+ id,
52
+ parentId: parentAccountId,
53
+ token,
54
+ operationsCount: operations.length,
55
+ operations: tokenOperations,
56
+ pendingOperations: [],
57
+ balance,
58
+ spendableBalance: spendableBalance,
59
+ swapHistory: [],
60
+ creationDate: operations.length > 0 ? operations[operations.length - 1].date : new Date(),
61
+ balanceHistoryCache: emptyHistoryCache, // calculated in the jsHelpers
62
+ };
63
+ }
64
+
65
+ export function buildSubAccounts({
66
+ currency,
67
+ accountId,
68
+ assetsBalance,
69
+ syncConfig,
70
+ operations,
71
+ }: {
72
+ currency: CryptoCurrency;
73
+ accountId: string;
74
+ assetsBalance: Balance[];
75
+ syncConfig: SyncConfig;
76
+ operations: OperationCommon[];
77
+ }): TokenAccount[] | undefined {
78
+ const { blacklistedTokenIds = [] } = syncConfig;
79
+ const allTokens = listTokensForCryptoCurrency(currency);
80
+
81
+ if (allTokens.length === 0 || assetsBalance.length === 0) {
82
+ return undefined;
83
+ }
84
+ const tokenAccounts: TokenAccount[] = [];
85
+ assetsBalance
86
+ .filter(b => b.asset.type !== "native") // NOTE: this could be removed, keeping here while fixing things up
87
+ .map(balance => {
88
+ const token = findToken(currency, balance);
89
+ // NOTE: for future tokens, will need to check over currencyName/standard(erc20,trc10,trc20, etc)/id
90
+ if (token && !blacklistedTokenIds.includes(token.id)) {
91
+ tokenAccounts.push(
92
+ buildTokenAccount({
93
+ parentAccountId: accountId,
94
+ assetBalance: balance,
95
+ token,
96
+ operations: operations.filter(
97
+ op =>
98
+ op.extra.assetReference === balance.asset?.["assetReference"] &&
99
+ op.extra.assetOwner === balance.asset?.["assetOwner"], // NOTE: we could narrow type
100
+ ),
101
+ }),
102
+ );
103
+ }
104
+ });
105
+ return tokenAccounts;
106
+ }
107
+
108
+ export function findToken(currency: CryptoCurrency, balance: Balance): TokenCurrency | undefined {
109
+ return findTokenById(`${currency.family}/asset/${getAssetIdFromAsset(balance.asset)}`);
110
+ }
@@ -1,27 +1,57 @@
1
- import { Account, TransactionCommon } from "@ledgerhq/types-live";
1
+ import { Account, TokenAccount, TransactionCommon } from "@ledgerhq/types-live";
2
2
  import BigNumber from "bignumber.js";
3
3
  import type { Unit } from "@ledgerhq/types-cryptoassets";
4
4
 
5
+ export enum NetworkCongestionLevel {
6
+ LOW = "LOW",
7
+ MEDIUM = "MEDIUM",
8
+ HIGH = "HIGH",
9
+ }
10
+
5
11
  export type NetworkInfo = {
6
- family: "xrp";
7
- serverFee: BigNumber;
8
- baseReserve: BigNumber;
12
+ fees: BigNumber;
9
13
  };
10
14
 
11
- export function createTransaction(account: Account): TransactionCommon & {
15
+ export function createTransaction(account: Account | TokenAccount): TransactionCommon & {
12
16
  family: string;
13
- fee: BigNumber | null | undefined;
14
- networkInfo: NetworkInfo | null | undefined;
15
- tag: number | null | undefined;
16
- feeCustomUnit: Unit | null | undefined;
17
+ fees?: BigNumber | null;
18
+ tag?: number | null | undefined;
19
+ feeCustomUnit?: Unit | null | undefined;
20
+ memoType?: string | null;
21
+ memoValue?: string | null;
22
+ mode?: "send" | "changeTrust";
23
+ assetReference?: string;
24
+ assetOwner?: string;
25
+ networkInfo?: NetworkInfo | null;
17
26
  } {
18
- return {
19
- family: account.currency.family,
20
- amount: BigNumber(0),
21
- recipient: "",
22
- fee: null,
23
- tag: undefined,
24
- networkInfo: null,
25
- feeCustomUnit: null,
26
- };
27
+ const currency =
28
+ account.type === "TokenAccount" ? account.token.parentCurrency : account.currency;
29
+ switch (currency.family) {
30
+ case "xrp":
31
+ case "ripple":
32
+ return {
33
+ family: currency.family,
34
+ amount: BigNumber(0),
35
+ recipient: "",
36
+ fees: null,
37
+ tag: undefined,
38
+ feeCustomUnit: null, // NOTE: XRP does not use custom units for fees anymore
39
+ };
40
+ case "stellar":
41
+ return {
42
+ family: currency.family,
43
+ amount: new BigNumber(0),
44
+ fees: null,
45
+ recipient: "",
46
+ memoValue: null,
47
+ memoType: null,
48
+ useAllAmount: false,
49
+ mode: "send",
50
+ assetReference: "",
51
+ assetOwner: "",
52
+ networkInfo: null,
53
+ };
54
+ default:
55
+ throw new Error(`Unsupported currency family: ${currency.family}`);
56
+ }
27
57
  }
@@ -3,7 +3,7 @@ import { CurrencyBridge } from "@ledgerhq/types-live";
3
3
  import { genericGetAccountShape } from "./getAccountShape";
4
4
  import { getSigner } from "./signer";
5
5
 
6
- export function getAlpacaCurrencyBridge(network: string, kind: "local" | "remote"): CurrencyBridge {
6
+ export function getAlpacaCurrencyBridge(network: string, kind: string): CurrencyBridge {
7
7
  return {
8
8
  preload: () => Promise.resolve({}),
9
9
  hydrate: () => {
@@ -6,21 +6,30 @@ import { transactionToIntent } from "./utils";
6
6
  import BigNumber from "bignumber.js";
7
7
 
8
8
  export function genericEstimateMaxSpendable(
9
- network: string,
10
- kind: "local" | "remote",
9
+ network,
10
+ kind,
11
11
  ): AccountBridge<any>["estimateMaxSpendable"] {
12
12
  return async ({ account, parentAccount, transaction }) => {
13
+ if (account.type === "TokenAccount") {
14
+ return account.spendableBalance;
15
+ }
13
16
  const mainAccount = getMainAccount(account, parentAccount);
14
-
15
17
  const draftTransaction = {
16
18
  ...createTransaction(account as any),
17
19
  ...transaction,
18
20
  amount: mainAccount.spendableBalance,
21
+ useAllAmount: true,
22
+ fees: transaction?.fees ? BigInt(transaction.fees.toString()) : 0n,
19
23
  };
20
24
  const fees = await getAlpacaApi(network, kind).estimateFees(
21
25
  transactionToIntent(mainAccount, draftTransaction),
22
26
  );
23
-
27
+ const { amount } = await getAlpacaApi(network, kind).validateIntent(
28
+ transactionToIntent(account, { ...draftTransaction }),
29
+ );
30
+ if (network === "stellar") {
31
+ return amount > 0 ? new BigNumber(amount.toString()) : new BigNumber(0);
32
+ }
24
33
  const bnFee = BigNumber(fees.value.toString());
25
34
  return BigNumber.max(0, account.spendableBalance.minus(bnFee));
26
35
  };
@@ -3,59 +3,97 @@ import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHel
3
3
  import BigNumber from "bignumber.js";
4
4
  import { getAlpacaApi } from "./alpaca";
5
5
  import { adaptCoreOperationToLiveOperation, extractBalance } from "./utils";
6
+ import { inferSubOperations } from "@ledgerhq/coin-framework/serialization";
7
+ import { findToken } from "./buildSubAccounts";
8
+ import { buildSubAccounts, OperationCommon } from "./buildSubAccounts";
6
9
 
7
- export function genericGetAccountShape(network: string, kind: "local" | "remote"): GetAccountShape {
8
- return async info => {
9
- try {
10
- const { address, initialAccount, currency, derivationMode } = info;
11
- const accountId = encodeAccountId({
12
- type: "js",
13
- version: "2",
14
- currencyId: currency.id,
15
- xpubOrAddress: address,
16
- derivationMode,
17
- });
18
-
19
- const blockInfo = await getAlpacaApi(network, kind).lastBlock();
20
-
21
- const balances = await getAlpacaApi(network, kind).getBalance(address);
22
- const nativeBalance = extractBalance(balances, "native");
23
- const balance = BigNumber(nativeBalance.value.toString());
24
-
25
- let spendableBalance: BigNumber;
26
- if (nativeBalance.locked) {
27
- spendableBalance = BigNumber.max(
28
- balance.minus(BigNumber(nativeBalance.locked.toString())),
29
- BigNumber(0),
30
- );
31
- } else {
32
- spendableBalance = initialAccount?.spendableBalance || balance;
10
+ export function genericGetAccountShape(network: string, kind: string): GetAccountShape {
11
+ return async (info, syncConfig) => {
12
+ const { address, initialAccount, currency, derivationMode } = info;
13
+ const alpacaApi = getAlpacaApi(network, kind);
14
+
15
+ if (alpacaApi.getChainSpecificRules) {
16
+ const chainSpecificValidation = alpacaApi.getChainSpecificRules();
17
+ if (chainSpecificValidation.getAccountShape) {
18
+ chainSpecificValidation.getAccountShape(address);
33
19
  }
34
- const oldOperations = initialAccount?.operations || [];
20
+ }
21
+
22
+ const accountId = encodeAccountId({
23
+ type: "js",
24
+ version: "2",
25
+ currencyId: currency.id,
26
+ xpubOrAddress: address,
27
+ derivationMode,
28
+ });
29
+
30
+ const blockInfo = await alpacaApi.lastBlock();
31
+ const balanceRes = await alpacaApi.getBalance(address);
32
+ const nativeAsset = extractBalance(balanceRes, "native");
33
+
34
+ const assetsBalance = balanceRes
35
+ .filter(b => b.asset.type !== "native")
36
+ .filter(b => findToken(currency, b));
37
+
38
+ const nativeBalance = BigInt(nativeAsset?.value ?? "0");
39
+
40
+ const spendableBalance = BigInt(nativeBalance - BigInt(nativeAsset?.locked ?? "0"));
35
41
 
36
- const blockHeight = oldOperations.length ? (oldOperations[0].blockHeight ?? 0) + 1 : 0;
42
+ const oldOps = (initialAccount?.operations || []) as OperationCommon[];
43
+ const lastPagingToken = oldOps[0]?.extra?.pagingToken || "";
37
44
 
38
- const [newOperations] = await getAlpacaApi(network, kind).listOperations(address, {
39
- minHeight: blockHeight,
40
- });
45
+ const blockHeight = oldOps.length ? (oldOps[0].blockHeight ?? 0) + 1 : 0;
46
+ const paginationParams: any = { minHeight: blockHeight };
47
+ if (lastPagingToken) {
48
+ paginationParams.lastPagingToken = lastPagingToken;
49
+ }
50
+
51
+ const [newCoreOps] = await alpacaApi.listOperations(address, paginationParams);
52
+ const newOps = newCoreOps.map(op =>
53
+ adaptCoreOperationToLiveOperation(accountId, op),
54
+ ) as OperationCommon[];
55
+ const mergedOps = mergeOps(oldOps, newOps) as OperationCommon[];
56
+
57
+ const assetOperations: OperationCommon[] = [];
58
+ mergedOps.forEach(operation => {
59
+ if (
60
+ operation?.extra?.assetReference &&
61
+ operation?.extra?.assetOwner &&
62
+ !["OPT_IN", "OPT_OUT"].includes(operation.type)
63
+ ) {
64
+ assetOperations.push(operation);
65
+ }
66
+ });
41
67
 
42
- const operations = mergeOps(
43
- oldOperations,
44
- newOperations.map(op => adaptCoreOperationToLiveOperation(accountId, op)),
45
- );
68
+ const subAccounts =
69
+ buildSubAccounts({
70
+ currency,
71
+ accountId,
72
+ assetsBalance,
73
+ syncConfig,
74
+ operations: assetOperations,
75
+ }) || [];
76
+
77
+ const operationsWithSubs = mergedOps.map(op => {
78
+ const subOperations = inferSubOperations(op.hash, subAccounts);
46
79
 
47
80
  return {
48
- id: accountId,
49
- xpub: address,
50
- blockHeight: operations.length === 0 ? 0 : blockInfo.height || initialAccount?.blockHeight,
51
- balance,
52
- spendableBalance,
53
- operations,
54
- operationsCount: operations.length,
81
+ ...op,
82
+ subOperations,
55
83
  };
56
- } catch (e) {
57
- console.error("Error in getAccountShape", e);
58
- throw e;
59
- }
84
+ });
85
+
86
+ const res = {
87
+ id: accountId,
88
+ xpub: address,
89
+ blockHeight:
90
+ operationsWithSubs.length === 0 ? 0 : blockInfo.height || initialAccount?.blockHeight,
91
+ balance: new BigNumber(nativeBalance.toString()),
92
+ spendableBalance: new BigNumber(spendableBalance.toString()),
93
+ operations: operationsWithSubs,
94
+ subAccounts,
95
+ operationsCount: operationsWithSubs.length,
96
+ };
97
+ return res;
60
98
  };
61
99
  }
@@ -1,38 +1,62 @@
1
1
  import { AccountBridge, TransactionCommon } from "@ledgerhq/types-live";
2
+ import { AccountAwaitingSendPendingOperations } from "@ledgerhq/errors";
2
3
  import BigNumber from "bignumber.js";
3
4
  import { getAlpacaApi } from "./alpaca";
5
+ import { transactionToIntent } from "./utils";
4
6
 
5
7
  // => alpaca validateIntent
6
8
  export function genericGetTransactionStatus(
7
- network: string,
8
- kind: "local" | "remote",
9
+ network,
10
+ kind,
9
11
  ): AccountBridge<any>["getTransactionStatus"] {
10
- return async (account, transaction: TransactionCommon & { fees: BigNumber }) => {
11
- const { freshAddress, balance, currency } = account;
12
+ return async (
13
+ account,
14
+ transaction: TransactionCommon & {
15
+ fees: BigNumber | null | undefined;
16
+ assetReference?: string;
17
+ assetOwner?: string;
18
+ mode?: string;
19
+ subAccountId?: string;
20
+ memoType?: string;
21
+ memoValue?: string;
22
+ },
23
+ ) => {
12
24
  const alpacaApi = getAlpacaApi(network, kind);
13
- const { errors, warnings } = await alpacaApi.validateIntent(
14
- {
15
- currencyName: currency.name,
16
- address: freshAddress,
17
- balance: BigInt(balance.toString()),
18
- currencyUnit: currency.units[0],
19
- },
20
- {
21
- type: "PAYMENT", // NOTE: assuming payment by default here
22
- recipient: transaction.recipient,
23
- amount: BigInt(transaction.amount?.toString() ?? "0"),
24
- fee: BigInt(transaction.fees?.toString() ?? "0"),
25
- },
26
- );
25
+ const draftTransaction = {
26
+ mode: transaction?.mode,
27
+ recipient: transaction.recipient,
28
+ amount: transaction.amount ?? new BigNumber(0),
29
+ fees: transaction.fees ? BigInt(transaction.fees.toString()) : 0n,
30
+ useAllAmount: !!transaction.useAllAmount,
31
+ assetReference: transaction.assetReference || "",
32
+ assetOwner: transaction.assetOwner || "",
33
+ subAccountId: transaction.subAccountId || "",
34
+ memoType: transaction.memoType || "",
35
+ memoValue: transaction.memoValue || "",
36
+ };
37
+
38
+ if (alpacaApi.getChainSpecificRules) {
39
+ const chainSpecificValidation = alpacaApi.getChainSpecificRules();
40
+ if (chainSpecificValidation.getTransactionStatus.throwIfPendingOperation) {
41
+ if (account.pendingOperations.length > 0) {
42
+ throw new AccountAwaitingSendPendingOperations();
43
+ }
44
+ }
45
+ }
27
46
 
28
- const estimatedFees = transaction.fees || new BigNumber(0);
47
+ const { errors, warnings, estimatedFees, amount, totalSpent } = await alpacaApi.validateIntent(
48
+ transactionToIntent(account, draftTransaction),
49
+ );
29
50
 
30
51
  return Promise.resolve({
31
52
  errors,
32
53
  warnings,
33
- estimatedFees,
34
- amount: transaction.amount,
35
- totalSpent: transaction.amount.plus(transaction.fees),
54
+ estimatedFees:
55
+ !transaction.fees || transaction.fees.isZero()
56
+ ? new BigNumber(estimatedFees.toString())
57
+ : transaction.fees,
58
+ amount: transaction.amount.eq(0) ? new BigNumber(amount.toString()) : transaction.amount,
59
+ totalSpent: new BigNumber(totalSpent.toString()),
36
60
  });
37
61
  };
38
62
  }