@ledgerhq/live-common 21.5.1-btcjs.0 → 21.7.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 (328) hide show
  1. package/lib/account/addAccounts.d.ts.map +1 -1
  2. package/lib/account/addAccounts.js +1 -2
  3. package/lib/account/addAccounts.js.map +1 -1
  4. package/lib/account/support.d.ts.map +1 -1
  5. package/lib/account/support.js +1 -24
  6. package/lib/account/support.js.map +1 -1
  7. package/lib/api/explorerConfig/index.js +15 -15
  8. package/lib/bot/index.d.ts +1 -2
  9. package/lib/bot/index.d.ts.map +1 -1
  10. package/lib/bot/index.js +15 -19
  11. package/lib/bot/index.js.map +1 -1
  12. package/lib/bot/test.bot.js +1 -4
  13. package/lib/bot/test.bot.js.map +1 -1
  14. package/lib/bridge/jsHelpers.d.ts +1 -6
  15. package/lib/bridge/jsHelpers.d.ts.map +1 -1
  16. package/lib/bridge/jsHelpers.js +3 -11
  17. package/lib/bridge/jsHelpers.js.map +1 -1
  18. package/lib/env.js +1 -1
  19. package/lib/env.js.map +1 -1
  20. package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
  21. package/lib/exchange/swap/getExchangeRates.js +9 -8
  22. package/lib/exchange/swap/getExchangeRates.js.map +1 -1
  23. package/lib/exchange/swap/hooks/index.d.ts +11 -0
  24. package/lib/exchange/swap/hooks/index.d.ts.map +1 -0
  25. package/lib/exchange/swap/hooks/index.js +23 -0
  26. package/lib/exchange/swap/hooks/index.js.map +1 -0
  27. package/lib/exchange/swap/hooks/useFromState.d.ts +15 -0
  28. package/lib/exchange/swap/hooks/useFromState.d.ts.map +1 -0
  29. package/lib/exchange/swap/hooks/useFromState.js +67 -0
  30. package/lib/exchange/swap/hooks/useFromState.js.map +1 -0
  31. package/lib/exchange/swap/hooks/useFromState.test.d.ts +2 -0
  32. package/lib/exchange/swap/hooks/useFromState.test.d.ts.map +1 -0
  33. package/lib/exchange/swap/hooks/useFromState.test.js +141 -0
  34. package/lib/exchange/swap/hooks/useFromState.test.js.map +1 -0
  35. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts +5 -0
  36. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -0
  37. package/lib/exchange/swap/hooks/usePickDefaultAccount.js +37 -0
  38. package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -0
  39. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts +2 -0
  40. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts.map +1 -0
  41. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +185 -0
  42. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -0
  43. package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts +3 -0
  44. package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts.map +1 -0
  45. package/lib/exchange/swap/hooks/usePickDefaultCurrency.js +17 -0
  46. package/lib/exchange/swap/hooks/usePickDefaultCurrency.js.map +1 -0
  47. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts +2 -0
  48. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts.map +1 -0
  49. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js +73 -0
  50. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js.map +1 -0
  51. package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts +12 -0
  52. package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts.map +1 -0
  53. package/lib/exchange/swap/hooks/usePollKYCStatus.js +105 -0
  54. package/lib/exchange/swap/hooks/usePollKYCStatus.js.map +1 -0
  55. package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts +2 -0
  56. package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts.map +1 -0
  57. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js +78 -0
  58. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js.map +1 -0
  59. package/lib/exchange/swap/hooks/useProviderRates.d.ts +20 -0
  60. package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -0
  61. package/lib/exchange/swap/hooks/useProviderRates.js +174 -0
  62. package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -0
  63. package/lib/exchange/swap/hooks/useProviderRates.test.d.ts +2 -0
  64. package/lib/exchange/swap/hooks/useProviderRates.test.d.ts.map +1 -0
  65. package/lib/exchange/swap/hooks/useProviderRates.test.js +261 -0
  66. package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -0
  67. package/lib/exchange/swap/hooks/useReverseAccounts.d.ts +15 -0
  68. package/lib/exchange/swap/hooks/useReverseAccounts.d.ts.map +1 -0
  69. package/lib/exchange/swap/hooks/useReverseAccounts.js +35 -0
  70. package/lib/exchange/swap/hooks/useReverseAccounts.js.map +1 -0
  71. package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts +2 -0
  72. package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts.map +1 -0
  73. package/lib/exchange/swap/hooks/useReverseAccounts.test.js +79 -0
  74. package/lib/exchange/swap/hooks/useReverseAccounts.test.js.map +1 -0
  75. package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts +5 -0
  76. package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts.map +1 -0
  77. package/lib/exchange/swap/hooks/useSelectableCurrencies.js +43 -0
  78. package/lib/exchange/swap/hooks/useSelectableCurrencies.js.map +1 -0
  79. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts +2 -0
  80. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts.map +1 -0
  81. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js +32 -0
  82. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js.map +1 -0
  83. package/lib/exchange/swap/hooks/useSwapProviders.d.ts +14 -0
  84. package/lib/exchange/swap/hooks/useSwapProviders.d.ts.map +1 -0
  85. package/lib/exchange/swap/hooks/useSwapProviders.js +104 -0
  86. package/lib/exchange/swap/hooks/useSwapProviders.js.map +1 -0
  87. package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts +2 -0
  88. package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts.map +1 -0
  89. package/lib/exchange/swap/hooks/useSwapProviders.test.js +174 -0
  90. package/lib/exchange/swap/hooks/useSwapProviders.test.js.map +1 -0
  91. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +53 -0
  92. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -0
  93. package/lib/exchange/swap/hooks/useSwapTransaction.js +109 -0
  94. package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -0
  95. package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts +2 -0
  96. package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts.map +1 -0
  97. package/lib/exchange/swap/hooks/useSwapTransaction.test.js +50 -0
  98. package/lib/exchange/swap/hooks/useSwapTransaction.test.js.map +1 -0
  99. package/lib/exchange/swap/hooks/useToState.d.ts +12 -0
  100. package/lib/exchange/swap/hooks/useToState.d.ts.map +1 -0
  101. package/lib/exchange/swap/hooks/useToState.js +73 -0
  102. package/lib/exchange/swap/hooks/useToState.js.map +1 -0
  103. package/lib/exchange/swap/hooks/useToState.test.d.ts +2 -0
  104. package/lib/exchange/swap/hooks/useToState.test.d.ts.map +1 -0
  105. package/lib/exchange/swap/hooks/useToState.test.js +107 -0
  106. package/lib/exchange/swap/hooks/useToState.test.js.map +1 -0
  107. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +15 -0
  108. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -0
  109. package/lib/{families/bitcoin/getAccountNetworkInfo.js → exchange/swap/hooks/useUpdateMaxAmount.js} +47 -65
  110. package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -0
  111. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts +2 -0
  112. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts.map +1 -0
  113. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +217 -0
  114. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -0
  115. package/lib/exchange/swap/mock.d.ts +6 -2
  116. package/lib/exchange/swap/mock.d.ts.map +1 -1
  117. package/lib/exchange/swap/mock.js +21 -6
  118. package/lib/exchange/swap/mock.js.map +1 -1
  119. package/lib/exchange/swap/types.d.ts +1 -1
  120. package/lib/exchange/swap/types.d.ts.map +1 -1
  121. package/lib/exchange/swap/utils/index.d.ts +16 -0
  122. package/lib/exchange/swap/utils/index.d.ts.map +1 -0
  123. package/lib/exchange/swap/utils/index.js +49 -0
  124. package/lib/exchange/swap/utils/index.js.map +1 -0
  125. package/lib/exchange/swap/utils/index.test.d.ts +2 -0
  126. package/lib/exchange/swap/utils/index.test.d.ts.map +1 -0
  127. package/lib/exchange/swap/utils/index.test.js +238 -0
  128. package/lib/exchange/swap/utils/index.test.js.map +1 -0
  129. package/lib/families/bitcoin/account.d.ts.map +1 -1
  130. package/lib/families/bitcoin/account.js +2 -3
  131. package/lib/families/bitcoin/account.js.map +1 -1
  132. package/lib/families/bitcoin/datasets/bitcoin.js +6 -6
  133. package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
  134. package/lib/families/bitcoin/datasets/litecoin.js +3 -3
  135. package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
  136. package/lib/families/bitcoin/serialization.d.ts +2 -2
  137. package/lib/families/bitcoin/serialization.d.ts.map +1 -1
  138. package/lib/families/bitcoin/serialization.js +4 -8
  139. package/lib/families/bitcoin/serialization.js.map +1 -1
  140. package/lib/families/bitcoin/specs.d.ts +1 -0
  141. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  142. package/lib/families/bitcoin/specs.js +17 -8
  143. package/lib/families/bitcoin/specs.js.map +1 -1
  144. package/lib/families/bitcoin/speculos-deviceActions.js +2 -2
  145. package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
  146. package/lib/families/bitcoin/test-dataset.js +1 -1
  147. package/lib/families/bitcoin/test-dataset.js.map +1 -1
  148. package/lib/families/bitcoin/transaction.d.ts +3 -3
  149. package/lib/families/bitcoin/transaction.d.ts.map +1 -1
  150. package/lib/families/bitcoin/transaction.js +61 -64
  151. package/lib/families/bitcoin/transaction.js.map +1 -1
  152. package/lib/families/bitcoin/types.d.ts +36 -66
  153. package/lib/families/bitcoin/types.d.ts.map +1 -1
  154. package/lib/families/bitcoin/types.js +1 -16
  155. package/lib/families/bitcoin/types.js.map +1 -1
  156. package/lib/families/crypto_org/datasets/croeseid.d.ts.map +1 -1
  157. package/lib/families/crypto_org/datasets/croeseid.js +2 -6
  158. package/lib/families/crypto_org/datasets/croeseid.js.map +1 -1
  159. package/lib/families/elrond/api/apiCalls.d.ts +0 -4
  160. package/lib/families/elrond/api/apiCalls.d.ts.map +1 -1
  161. package/lib/families/elrond/api/apiCalls.js +3 -37
  162. package/lib/families/elrond/api/apiCalls.js.map +1 -1
  163. package/lib/families/elrond/api/sdk.js +2 -2
  164. package/lib/families/elrond/api/sdk.js.map +1 -1
  165. package/lib/families/elrond/js-transaction.d.ts +2 -0
  166. package/lib/families/elrond/js-transaction.d.ts.map +1 -1
  167. package/lib/families/elrond/types.d.ts +2 -0
  168. package/lib/families/elrond/types.d.ts.map +1 -1
  169. package/lib/families/elrond/types.js.map +1 -1
  170. package/lib/families/tezos/bridge/js.js.map +1 -1
  171. package/lib/generated/bridge/js.d.ts +0 -4
  172. package/lib/generated/bridge/js.d.ts.map +1 -1
  173. package/lib/generated/bridge/js.js +18 -20
  174. package/lib/generated/bridge/js.js.map +1 -1
  175. package/lib/generated/specs.d.ts +1 -0
  176. package/lib/generated/specs.d.ts.map +1 -1
  177. package/lib/migrations/accounts-dataset.d.ts.map +1 -1
  178. package/lib/migrations/accounts-dataset.js +2 -4
  179. package/lib/migrations/accounts-dataset.js.map +1 -1
  180. package/lib/migrations/accounts.d.ts.map +1 -1
  181. package/lib/migrations/accounts.js +0 -17
  182. package/lib/migrations/accounts.js.map +1 -1
  183. package/lib/mock/account.d.ts +2 -1
  184. package/lib/mock/account.d.ts.map +1 -1
  185. package/lib/mock/account.js +5 -4
  186. package/lib/mock/account.js.map +1 -1
  187. package/package.json +12 -13
  188. package/src/.DS_Store +0 -0
  189. package/src/__tests__/.DS_Store +0 -0
  190. package/src/__tests__/__snapshots__/.DS_Store +0 -0
  191. package/src/__tests__/__snapshots__/all.libcore.ts.snap +10 -10
  192. package/src/account/addAccounts.ts +1 -2
  193. package/src/account/support.ts +1 -24
  194. package/src/api/explorerConfig/index.ts +15 -15
  195. package/src/bot/index.ts +3 -8
  196. package/src/bot/test.bot.ts +1 -6
  197. package/src/bridge/jsHelpers.ts +2 -22
  198. package/src/env.ts +1 -1
  199. package/src/exchange/swap/getExchangeRates.ts +8 -5
  200. package/src/exchange/swap/hooks/index.ts +10 -0
  201. package/src/exchange/swap/hooks/useFromState.test.ts +134 -0
  202. package/src/exchange/swap/hooks/useFromState.ts +84 -0
  203. package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +167 -0
  204. package/src/exchange/swap/hooks/usePickDefaultAccount.ts +47 -0
  205. package/src/exchange/swap/hooks/usePickDefaultCurrency.test.ts +107 -0
  206. package/src/exchange/swap/hooks/usePickDefaultCurrency.ts +20 -0
  207. package/src/exchange/swap/hooks/usePollKYCStatus.test.ts +89 -0
  208. package/src/exchange/swap/hooks/usePollKYCStatus.ts +43 -0
  209. package/src/exchange/swap/hooks/useProviderRates.test.ts +200 -0
  210. package/src/exchange/swap/hooks/useProviderRates.ts +130 -0
  211. package/src/exchange/swap/hooks/useReverseAccounts.test.ts +83 -0
  212. package/src/exchange/swap/hooks/useReverseAccounts.ts +56 -0
  213. package/src/exchange/swap/hooks/useSelectableCurrencies.test.ts +39 -0
  214. package/src/exchange/swap/hooks/useSelectableCurrencies.ts +26 -0
  215. package/src/exchange/swap/hooks/useSwapProviders.test.ts +113 -0
  216. package/src/exchange/swap/hooks/useSwapProviders.ts +57 -0
  217. package/src/exchange/swap/hooks/useSwapTransaction.test.ts +54 -0
  218. package/src/exchange/swap/hooks/useSwapTransaction.ts +170 -0
  219. package/src/exchange/swap/hooks/useToState.test.ts +53 -0
  220. package/src/exchange/swap/hooks/useToState.ts +86 -0
  221. package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +132 -0
  222. package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +67 -0
  223. package/src/exchange/swap/mock.ts +22 -3
  224. package/src/exchange/swap/types.ts +2 -1
  225. package/src/exchange/swap/utils/index.test.ts +224 -0
  226. package/src/exchange/swap/utils/index.ts +67 -0
  227. package/src/families/bitcoin/account.ts +1 -2
  228. package/src/families/bitcoin/datasets/bitcoin.ts +6 -6
  229. package/src/families/bitcoin/datasets/litecoin.ts +6 -6
  230. package/src/families/bitcoin/serialization.ts +0 -6
  231. package/src/families/bitcoin/specs.ts +14 -5
  232. package/src/families/bitcoin/speculos-deviceActions.ts +1 -1
  233. package/src/families/bitcoin/test-dataset.ts +1 -1
  234. package/src/families/bitcoin/transaction.ts +93 -98
  235. package/src/families/bitcoin/types.ts +37 -95
  236. package/src/families/crypto_org/datasets/croeseid.ts +7 -9
  237. package/src/families/elrond/api/apiCalls.ts +3 -31
  238. package/src/families/elrond/api/sdk.ts +2 -2
  239. package/src/families/elrond/types.ts +2 -0
  240. package/src/families/tezos/bridge/js.ts +1 -1
  241. package/src/generated/bridge/js.ts +0 -3
  242. package/src/migrations/accounts-dataset.ts +0 -3
  243. package/src/migrations/accounts.ts +0 -18
  244. package/src/mock/account.ts +2 -4
  245. package/lib/__tests__/families/bitcoin/logic.d.ts +0 -2
  246. package/lib/__tests__/families/bitcoin/logic.d.ts.map +0 -1
  247. package/lib/__tests__/families/bitcoin/logic.js +0 -39
  248. package/lib/__tests__/families/bitcoin/logic.js.map +0 -1
  249. package/lib/families/bitcoin/bridge/js.d.ts +0 -8
  250. package/lib/families/bitcoin/bridge/js.d.ts.map +0 -1
  251. package/lib/families/bitcoin/bridge/js.js +0 -149
  252. package/lib/families/bitcoin/bridge/js.js.map +0 -1
  253. package/lib/families/bitcoin/cache.d.ts +0 -28
  254. package/lib/families/bitcoin/cache.d.ts.map +0 -1
  255. package/lib/families/bitcoin/cache.js +0 -109
  256. package/lib/families/bitcoin/cache.js.map +0 -1
  257. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts +0 -6
  258. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +0 -1
  259. package/lib/families/bitcoin/getAccountNetworkInfo.js.map +0 -1
  260. package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts +0 -2
  261. package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts.map +0 -1
  262. package/lib/families/bitcoin/getAccountNetworkInfo.test.js +0 -71
  263. package/lib/families/bitcoin/getAccountNetworkInfo.test.js.map +0 -1
  264. package/lib/families/bitcoin/js-broadcast.d.ts +0 -11
  265. package/lib/families/bitcoin/js-broadcast.d.ts.map +0 -1
  266. package/lib/families/bitcoin/js-broadcast.js +0 -80
  267. package/lib/families/bitcoin/js-broadcast.js.map +0 -1
  268. package/lib/families/bitcoin/js-buildTransaction.d.ts +0 -5
  269. package/lib/families/bitcoin/js-buildTransaction.d.ts.map +0 -1
  270. package/lib/families/bitcoin/js-buildTransaction.js +0 -106
  271. package/lib/families/bitcoin/js-buildTransaction.js.map +0 -1
  272. package/lib/families/bitcoin/js-createTransaction.d.ts +0 -9
  273. package/lib/families/bitcoin/js-createTransaction.d.ts.map +0 -1
  274. package/lib/families/bitcoin/js-createTransaction.js +0 -27
  275. package/lib/families/bitcoin/js-createTransaction.js.map +0 -1
  276. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts +0 -15
  277. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +0 -1
  278. package/lib/families/bitcoin/js-estimateMaxSpendable.js +0 -95
  279. package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +0 -1
  280. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts +0 -26
  281. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts.map +0 -1
  282. package/lib/families/bitcoin/js-getFeesForTransaction.js +0 -100
  283. package/lib/families/bitcoin/js-getFeesForTransaction.js.map +0 -1
  284. package/lib/families/bitcoin/js-getTransactionStatus.d.ts +0 -5
  285. package/lib/families/bitcoin/js-getTransactionStatus.d.ts.map +0 -1
  286. package/lib/families/bitcoin/js-getTransactionStatus.js +0 -131
  287. package/lib/families/bitcoin/js-getTransactionStatus.js.map +0 -1
  288. package/lib/families/bitcoin/js-prepareTransaction.d.ts +0 -5
  289. package/lib/families/bitcoin/js-prepareTransaction.d.ts.map +0 -1
  290. package/lib/families/bitcoin/js-prepareTransaction.js +0 -80
  291. package/lib/families/bitcoin/js-prepareTransaction.js.map +0 -1
  292. package/lib/families/bitcoin/js-signOperation.d.ts +0 -10
  293. package/lib/families/bitcoin/js-signOperation.d.ts.map +0 -1
  294. package/lib/families/bitcoin/js-signOperation.js +0 -212
  295. package/lib/families/bitcoin/js-signOperation.js.map +0 -1
  296. package/lib/families/bitcoin/js-synchronisation.d.ts +0 -10
  297. package/lib/families/bitcoin/js-synchronisation.d.ts.map +0 -1
  298. package/lib/families/bitcoin/js-synchronisation.js +0 -411
  299. package/lib/families/bitcoin/js-synchronisation.js.map +0 -1
  300. package/lib/families/bitcoin/logic.d.ts +0 -34
  301. package/lib/families/bitcoin/logic.d.ts.map +0 -1
  302. package/lib/families/bitcoin/logic.js +0 -292
  303. package/lib/families/bitcoin/logic.js.map +0 -1
  304. package/lib/families/bitcoin/networks.d.ts +0 -3
  305. package/lib/families/bitcoin/networks.d.ts.map +0 -1
  306. package/lib/families/bitcoin/networks.js +0 -379
  307. package/lib/families/bitcoin/networks.js.map +0 -1
  308. package/lib/families/bitcoin/wallet.d.ts +0 -6
  309. package/lib/families/bitcoin/wallet.d.ts.map +0 -1
  310. package/lib/families/bitcoin/wallet.js +0 -66
  311. package/lib/families/bitcoin/wallet.js.map +0 -1
  312. package/src/__tests__/families/bitcoin/logic.ts +0 -40
  313. package/src/families/bitcoin/bridge/js.ts +0 -76
  314. package/src/families/bitcoin/cache.ts +0 -76
  315. package/src/families/bitcoin/getAccountNetworkInfo.test.ts +0 -27
  316. package/src/families/bitcoin/getAccountNetworkInfo.ts +0 -61
  317. package/src/families/bitcoin/js-broadcast.ts +0 -30
  318. package/src/families/bitcoin/js-buildTransaction.ts +0 -57
  319. package/src/families/bitcoin/js-createTransaction.ts +0 -27
  320. package/src/families/bitcoin/js-estimateMaxSpendable.ts +0 -36
  321. package/src/families/bitcoin/js-getFeesForTransaction.ts +0 -59
  322. package/src/families/bitcoin/js-getTransactionStatus.ts +0 -118
  323. package/src/families/bitcoin/js-prepareTransaction.ts +0 -35
  324. package/src/families/bitcoin/js-signOperation.ts +0 -164
  325. package/src/families/bitcoin/js-synchronisation.ts +0 -362
  326. package/src/families/bitcoin/logic.ts +0 -253
  327. package/src/families/bitcoin/networks.ts +0 -360
  328. package/src/families/bitcoin/wallet.ts +0 -21
@@ -0,0 +1,224 @@
1
+ import BigNumber from "bignumber.js";
2
+
3
+ import { pickExchangeRate, getAccountTuplesForCurrency } from "./index";
4
+ import { getMockExchangeRate } from "../mock";
5
+ import { genAccount } from "../../../mock/account";
6
+ import type {
7
+ Account,
8
+ CryptoCurrency,
9
+ SubAccount,
10
+ TokenCurrency,
11
+ } from "../../../types";
12
+ import { getCryptoCurrencyById } from "../../../currencies";
13
+ import { getTokenById } from "@ledgerhq/cryptoassets/lib/tokens";
14
+
15
+ describe("swap/utils/pickExchangeRate", () => {
16
+ test("calls the callback function with null when no exchange rates are passed", () => {
17
+ const setExchangeRate = jest.fn();
18
+ pickExchangeRate([], undefined, setExchangeRate);
19
+
20
+ expect(setExchangeRate).toHaveBeenCalledTimes(1);
21
+ expect(setExchangeRate).toHaveBeenCalledWith(null);
22
+ });
23
+
24
+ test("calls the callback function with null when no exchange rates are passed but there is an exchange rate", () => {
25
+ const setExchangeRate = jest.fn();
26
+ const exchangeRate = getMockExchangeRate({ provider: "wyre" });
27
+ pickExchangeRate([], exchangeRate, setExchangeRate);
28
+
29
+ expect(setExchangeRate).toHaveBeenCalledTimes(1);
30
+ expect(setExchangeRate).toHaveBeenCalledWith(null);
31
+ });
32
+
33
+ test("calls the callback function with the first exchange rate when the exchange passed isn't included in the list", () => {
34
+ const setExchangeRate = jest.fn();
35
+ const firstExchangeRate = getMockExchangeRate({
36
+ provider: "changelly",
37
+ tradeMethod: "fixed",
38
+ });
39
+ const exchangeRates = [
40
+ firstExchangeRate,
41
+ getMockExchangeRate({ provider: "changelly", tradeMethod: "float" }),
42
+ ];
43
+ const exchangeRate = getMockExchangeRate({ provider: "wyre" });
44
+
45
+ pickExchangeRate(exchangeRates, exchangeRate, setExchangeRate);
46
+
47
+ expect(setExchangeRate).toHaveBeenCalledTimes(1);
48
+ expect(setExchangeRate).toHaveBeenCalledWith(firstExchangeRate);
49
+ });
50
+
51
+ test("calls the callback function with the passed exchange rate when the exchange passed is included in the list", () => {
52
+ const setExchangeRate = jest.fn();
53
+ const exchangeRate = getMockExchangeRate({
54
+ provider: "changelly",
55
+ tradeMethod: "fixed",
56
+ });
57
+ const exchangeRates = [
58
+ getMockExchangeRate({ provider: "changelly", tradeMethod: "float" }),
59
+ exchangeRate,
60
+ ];
61
+
62
+ pickExchangeRate(exchangeRates, exchangeRate, setExchangeRate);
63
+
64
+ expect(setExchangeRate).toHaveBeenCalledTimes(1);
65
+ expect(setExchangeRate).toHaveBeenCalledWith(exchangeRate);
66
+ });
67
+ });
68
+
69
+ /* TODO: Refacto these two function and move them to mock/account.ts if needed */
70
+ function* accountGenerator(currency: CryptoCurrency): Generator<Account> {
71
+ let id = 0;
72
+ while (true) {
73
+ id += 1;
74
+ yield genAccount(`mocked-account-${id}`, { currency, operationsSize: 0 });
75
+ }
76
+ }
77
+ const getAccountCreator = (currencyId: string) => {
78
+ const generator = accountGenerator(getCryptoCurrencyById(currencyId));
79
+ return () => generator.next().value;
80
+ };
81
+
82
+ describe("swap/utils/getAccountTuplesForCurrency", () => {
83
+ const getEthAccount = getAccountCreator("ethereum");
84
+ const getBtcAccount = getAccountCreator("bitcoin");
85
+ const getPolkadotAccount = getAccountCreator("polkadot");
86
+ const getCosmosAccount = getAccountCreator("cosmos");
87
+
88
+ describe("CryptoCurrency", () => {
89
+ test("returns all accounts associated to the CryptoCurrency", () => {
90
+ const ethCurrency = getCryptoCurrencyById("ethereum");
91
+ const ethAccounts = [getEthAccount(), getEthAccount()];
92
+ const allAccounts: Account[] = [
93
+ getCosmosAccount(),
94
+ ...ethAccounts,
95
+ getBtcAccount(),
96
+ getPolkadotAccount(),
97
+ ];
98
+
99
+ const results = getAccountTuplesForCurrency(
100
+ ethCurrency,
101
+ allAccounts,
102
+ false
103
+ );
104
+
105
+ expect(results).toHaveLength(2);
106
+ results.forEach((result, index) => {
107
+ expect(result.account).toEqual(ethAccounts[index]);
108
+ expect(result.subAccount).toBeNull();
109
+ });
110
+ });
111
+
112
+ test("returns only associated accounts if they have a balance greater than 0 when the flag is passed", () => {
113
+ const ethCurrency = getCryptoCurrencyById("ethereum");
114
+ const richEthAccounts = [
115
+ { ...getEthAccount(), balance: new BigNumber(10) },
116
+ { ...getEthAccount(), balance: new BigNumber(10) },
117
+ ];
118
+ const poorEthAccounts = { ...getEthAccount(), balance: new BigNumber(0) };
119
+
120
+ const allAccounts: Account[] = [
121
+ getCosmosAccount(),
122
+ ...richEthAccounts,
123
+ poorEthAccounts,
124
+ getBtcAccount(),
125
+ getPolkadotAccount(),
126
+ ];
127
+
128
+ const results = getAccountTuplesForCurrency(
129
+ ethCurrency,
130
+ allAccounts,
131
+ true
132
+ );
133
+
134
+ expect(results).toHaveLength(richEthAccounts.length);
135
+ results.forEach((result, index) => {
136
+ expect(result.account).toEqual(richEthAccounts[index]);
137
+ expect(result.subAccount).toBeNull();
138
+ });
139
+ });
140
+
141
+ test("returns an empty array if the CryptoCurrency passed has no associated account", () => {
142
+ const ethCurrency = getCryptoCurrencyById("ethereum");
143
+ const allAccounts: Account[] = [
144
+ getCosmosAccount(),
145
+ getBtcAccount(),
146
+ getPolkadotAccount(),
147
+ ];
148
+
149
+ const results = getAccountTuplesForCurrency(
150
+ ethCurrency,
151
+ allAccounts,
152
+ false
153
+ );
154
+
155
+ expect(results).toHaveLength(0);
156
+ });
157
+ });
158
+
159
+ describe("TokenCurrency", () => {
160
+ const aaveToken = Object.freeze(getTokenById("ethereum/erc20/aave"));
161
+
162
+ test("returns correct parent accounts including a new subAccount when a TokenCurrency is provided", () => {
163
+ const ethAccounts = [
164
+ { ...getEthAccount(), subAccounts: [] },
165
+ { ...getEthAccount(), subAccounts: [] },
166
+ ];
167
+ const allAccounts: Account[] = [
168
+ getCosmosAccount(),
169
+ ...ethAccounts,
170
+ getBtcAccount(),
171
+ getPolkadotAccount(),
172
+ ];
173
+
174
+ const results = getAccountTuplesForCurrency(
175
+ aaveToken,
176
+ allAccounts,
177
+ false
178
+ );
179
+
180
+ expect(results).toHaveLength(ethAccounts.length);
181
+ results.forEach((result, index) => {
182
+ expect(result.account).toEqual(ethAccounts[index]);
183
+ expect(
184
+ (result.subAccount as SubAccount & { token: TokenCurrency }).token
185
+ ).toEqual(aaveToken);
186
+ });
187
+ });
188
+
189
+ test("returns correct parent accounts including already existing subAccounts when a TokenCurrency is provided", () => {
190
+ const ethAccounts = [{ ...getEthAccount(), subAccounts: [aaveToken] }];
191
+ const allAccounts: Account[] = [
192
+ getCosmosAccount(),
193
+ ...ethAccounts,
194
+ getBtcAccount(),
195
+ getPolkadotAccount(),
196
+ ];
197
+
198
+ const results = getAccountTuplesForCurrency(
199
+ aaveToken,
200
+ allAccounts,
201
+ false
202
+ );
203
+
204
+ expect(results).toHaveLength(ethAccounts.length);
205
+ results.forEach((result, index) => {
206
+ expect(result.account).toEqual(ethAccounts[index]);
207
+ expect(
208
+ (result.subAccount as SubAccount & { token: TokenCurrency }).token
209
+ ).toEqual(aaveToken);
210
+ });
211
+ });
212
+
213
+ test("returns an empty array when a TokenCurrency is provided but the accounts list is empty", () => {
214
+ const allAccounts: Account[] = [];
215
+
216
+ const results = getAccountTuplesForCurrency(
217
+ aaveToken,
218
+ allAccounts,
219
+ false
220
+ );
221
+ expect(results).toHaveLength(0);
222
+ });
223
+ });
224
+ });
@@ -0,0 +1,67 @@
1
+ import { CryptoCurrency, TokenCurrency } from "@ledgerhq/cryptoassets";
2
+ import { makeEmptyTokenAccount } from "../../../account";
3
+ import { Account, SubAccount } from "../../../types";
4
+ import type { ExchangeRate } from "../types";
5
+
6
+ export const KYC_STATUS = {
7
+ pending: "pending",
8
+ rejected: "closed",
9
+ approved: "approved",
10
+ };
11
+
12
+ export type KYCStatus = keyof typeof KYC_STATUS;
13
+
14
+ export const pickExchangeRate = (
15
+ exchangeRates: ExchangeRate[],
16
+ exchangeRate: ExchangeRate | null | undefined,
17
+ setExchangeRate: (rate?: ExchangeRate | null) => void
18
+ ): void => {
19
+ const hasRates = exchangeRates?.length > 0;
20
+ // If the user picked an exchange rate before, try to select the new one that matches.
21
+ // Otherwise pick the first one.
22
+ const rate =
23
+ hasRates &&
24
+ ((exchangeRate &&
25
+ exchangeRates.find(
26
+ ({ tradeMethod, provider }) =>
27
+ tradeMethod === exchangeRate.tradeMethod &&
28
+ provider === exchangeRate.provider
29
+ )) ||
30
+ exchangeRates[0]);
31
+ setExchangeRate(rate || null);
32
+ };
33
+
34
+ export type AccountTuple = {
35
+ account: Account | null | undefined;
36
+ subAccount: SubAccount | null | undefined;
37
+ };
38
+
39
+ export function getAccountTuplesForCurrency(
40
+ currency: CryptoCurrency | TokenCurrency,
41
+ allAccounts: Account[],
42
+ hideEmpty?: boolean
43
+ ): AccountTuple[] {
44
+ if (currency.type === "TokenCurrency") {
45
+ return allAccounts
46
+ .filter((account) => account.currency.id === currency.parentCurrency.id)
47
+ .map((account) => ({
48
+ account,
49
+ subAccount:
50
+ (account.subAccounts &&
51
+ account.subAccounts.find(
52
+ (subAcc: SubAccount) =>
53
+ subAcc.type === "TokenAccount" &&
54
+ subAcc.token.id === currency.id
55
+ )) ||
56
+ makeEmptyTokenAccount(account, currency),
57
+ }))
58
+ .filter((a) => (hideEmpty ? a.subAccount?.balance.gt(0) : true));
59
+ }
60
+ return allAccounts
61
+ .filter((account) => account.currency.id === currency.id)
62
+ .map((account) => ({
63
+ account,
64
+ subAccount: null,
65
+ }))
66
+ .filter((a) => (hideEmpty ? a.account?.balance.gt(0) : true));
67
+ }
@@ -2,7 +2,7 @@ import type { Account } from "../../types";
2
2
  import type { BitcoinOutput, BitcoinInput } from "./types";
3
3
  import { formatCurrencyUnit } from "../../currencies";
4
4
  import { getEnv } from "../../env";
5
- import { perCoinLogic } from "./logic";
5
+ import { perCoinLogic } from "./transaction";
6
6
 
7
7
  const sortUTXO = (a, b) => b.value.minus(a.value).toNumber();
8
8
 
@@ -31,7 +31,6 @@ export function formatOutput(account: Account, o: BitcoinOutput): string {
31
31
  }).padEnd(12),
32
32
  o.address,
33
33
  o.path,
34
- o.isChange ? "(change)" : "",
35
34
  o.rbf ? "rbf" : "",
36
35
  o.hash,
37
36
  `@${o.outputIndex} (${
@@ -50,8 +50,8 @@ const dataset: CurrenciesData<Transaction> = {
50
50
  expectedStatus: {
51
51
  amount: new BigNumber("999"),
52
52
  // FIXME fee are reloaded?
53
- // estimatedFees: new BigNumber("250"),
54
- // totalSpent: new BigNumber("1249"),
53
+ // estimatedFees: BigNumber("250"),
54
+ // totalSpent: BigNumber("1249"),
55
55
  errors: {},
56
56
  warnings: {
57
57
  // feeTooHigh: new FeeTooHigh()
@@ -76,8 +76,8 @@ const dataset: CurrenciesData<Transaction> = {
76
76
  expectedStatus: {
77
77
  amount: new BigNumber("998"),
78
78
  // FIXME fee are reloaded?
79
- // estimatedFees: new BigNumber("250"),
80
- // totalSpent: new BigNumber("1248"),
79
+ // estimatedFees: BigNumber("250"),
80
+ // totalSpent: BigNumber("1248"),
81
81
  errors: {},
82
82
  warnings: {
83
83
  // feeTooHigh: new FeeTooHigh()
@@ -102,8 +102,8 @@ const dataset: CurrenciesData<Transaction> = {
102
102
  expectedStatus: {
103
103
  amount: new BigNumber("997"),
104
104
  // FIXME fee are reloaded?
105
- // estimatedFees: new BigNumber("250"),
106
- // totalSpent: new BigNumber("1247"),
105
+ // estimatedFees: BigNumber("250"),
106
+ // totalSpent: BigNumber("1247"),
107
107
  errors: {},
108
108
  warnings: {
109
109
  // feeTooHigh: new FeeTooHigh(),
@@ -50,8 +50,8 @@ const dataset: CurrenciesData<Transaction> = {
50
50
  expectedStatus: {
51
51
  errors: {},
52
52
  warnings: {},
53
- // estimatedFees: new BigNumber("5694"),
54
- amount: new BigNumber("200000"), // totalSpent: new BigNumber("205694")
53
+ // estimatedFees: BigNumber("5694"),
54
+ amount: new BigNumber("200000"), // totalSpent: BigNumber("205694")
55
55
  },
56
56
  },
57
57
  {
@@ -73,8 +73,8 @@ const dataset: CurrenciesData<Transaction> = {
73
73
  expectedStatus: {
74
74
  errors: {},
75
75
  warnings: {},
76
- // estimatedFees: new BigNumber("5694"),
77
- amount: new BigNumber("147200"), // totalSpent: new BigNumber("152894")
76
+ // estimatedFees: BigNumber("5694"),
77
+ amount: new BigNumber("147200"), // totalSpent: BigNumber("152894")
78
78
  },
79
79
  },
80
80
  {
@@ -96,8 +96,8 @@ const dataset: CurrenciesData<Transaction> = {
96
96
  expectedStatus: {
97
97
  errors: {},
98
98
  warnings: {},
99
- // estimatedFees: new BigNumber("5694"),
100
- amount: new BigNumber("205273"), // totalSpent: new BigNumber("210967")
99
+ // estimatedFees: BigNumber("5694"),
100
+ amount: new BigNumber("205273"), // totalSpent: BigNumber("210967")
101
101
  },
102
102
  },
103
103
  ],
@@ -38,7 +38,6 @@ export function toBitcoinOutputRaw({
38
38
  outputIndex,
39
39
  blockHeight,
40
40
  address,
41
- isChange,
42
41
  path,
43
42
  value,
44
43
  rbf,
@@ -48,7 +47,6 @@ export function toBitcoinOutputRaw({
48
47
  outputIndex,
49
48
  blockHeight,
50
49
  address,
51
- isChange ? 1 : 0,
52
50
  path,
53
51
  value.toString(),
54
52
  rbf ? 1 : 0,
@@ -59,7 +57,6 @@ export function fromBitcoinOutputRaw([
59
57
  outputIndex,
60
58
  blockHeight,
61
59
  address,
62
- isChange,
63
60
  path,
64
61
  value,
65
62
  rbf,
@@ -69,7 +66,6 @@ export function fromBitcoinOutputRaw([
69
66
  outputIndex,
70
67
  blockHeight: blockHeight || undefined,
71
68
  address: address || undefined,
72
- isChange: !!isChange,
73
69
  path: path || undefined,
74
70
  value: new BigNumber(value),
75
71
  rbf: !!rbf,
@@ -80,7 +76,6 @@ export function toBitcoinResourcesRaw(
80
76
  ): BitcoinResourcesRaw {
81
77
  return {
82
78
  utxos: r.utxos.map(toBitcoinOutputRaw),
83
- serializedData: r.serializedData,
84
79
  };
85
80
  }
86
81
  export function fromBitcoinResourcesRaw(
@@ -88,6 +83,5 @@ export function fromBitcoinResourcesRaw(
88
83
  ): BitcoinResources {
89
84
  return {
90
85
  utxos: r.utxos.map(fromBitcoinOutputRaw),
91
- serializedData: r.serializedData,
92
86
  };
93
87
  }
@@ -10,7 +10,8 @@ import { pickSiblings } from "../../bot/specs";
10
10
  import { bitcoinPickingStrategy } from "./types";
11
11
  import type { MutationSpec, AppSpec } from "../../bot/types";
12
12
  import { LowerThanMinimumRelayFee } from "../../errors";
13
- import { getMinRelayFee, getUTXOStatus, isChangeOutput } from "./logic";
13
+ import { getMinRelayFee } from "./fees";
14
+ import { isChangeOutput, getUTXOStatus } from "./transaction";
14
15
  import { DeviceModelId } from "@ledgerhq/devices";
15
16
  type Arg = Partial<{
16
17
  minimalAmount: BigNumber;
@@ -80,11 +81,7 @@ const genericTest = ({
80
81
  ? operation.senders
81
82
  : txInputs.map((t) => t.address).filter(Boolean),
82
83
  recipients: txOutputs
83
- // TODO REPLACE >>>>>>>>>>>>>>>>>>
84
84
  .filter((o) => !isChangeOutput(o))
85
- /*/ WITH <<<<<<<<<<<<<<<<<<<<<<<<<
86
- .filter((o) => !o.isChange)
87
- //*/
88
85
  .map((t) => t.address)
89
86
  .filter(Boolean),
90
87
  })
@@ -372,6 +369,17 @@ const stakenet: AppSpec<Transaction> = {
372
369
  test: genericTest,
373
370
  mutations: bitcoinLikeMutations(),
374
371
  };
372
+ const stratis: AppSpec<Transaction> = {
373
+ name: "Stratis",
374
+ currency: getCryptoCurrencyById("stratis"),
375
+ dependency: "Bitcoin",
376
+ appQuery: {
377
+ model: DeviceModelId.nanoS,
378
+ appName: "Stratis",
379
+ },
380
+ test: genericTest,
381
+ mutations: bitcoinLikeMutations(),
382
+ };
375
383
  const vertcoin: AppSpec<Transaction> = {
376
384
  name: "Vertcoin",
377
385
  currency: getCryptoCurrencyById("vertcoin"),
@@ -541,6 +549,7 @@ export default {
541
549
  qtum,
542
550
  stakenet,
543
551
  stealthcoin,
552
+ stratis,
544
553
  vertcoin,
545
554
  viacoin,
546
555
  zcash,
@@ -2,7 +2,7 @@ import type { DeviceAction } from "../../bot/types";
2
2
  import type { Transaction } from "./types";
3
3
  import { formatCurrencyUnit } from "../../currencies";
4
4
  import { deviceActionFlow } from "../../bot/specs";
5
- import { perCoinLogic } from "./logic";
5
+ import { perCoinLogic } from "./transaction";
6
6
  const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
7
7
  steps: [
8
8
  {
@@ -19,7 +19,7 @@ import vertcoin from "./datasets/vertcoin";
19
19
  import viacoin from "./datasets/viacoin";
20
20
  import zcash from "./datasets/zcash";
21
21
  const dataset: DatasetTest<Transaction> = {
22
- implementations: ["js", "mock"],
22
+ implementations: ["libcore", "mock"],
23
23
  currencies: {
24
24
  bitcoin_cash,
25
25
  bitcoin_gold,
@@ -25,102 +25,6 @@ import { formatCurrencyUnit } from "../../currencies";
25
25
  import type { CryptoCurrencyIds } from "../../types";
26
26
  import { libcoreAmountToBigNumber } from "../../libcore/buildBigNumber";
27
27
 
28
- const fromFeeItemsRaw = (fir: FeeItemsRaw): FeeItems => ({
29
- items: fir.items.map((fi) => ({
30
- key: fi.key,
31
- speed: fi.speed,
32
- feePerByte: new BigNumber(fi.feePerByte),
33
- })),
34
- defaultFeePerByte: new BigNumber(fir.defaultFeePerByte),
35
- });
36
-
37
- const toFeeItemsRaw = (fir: FeeItems): FeeItemsRaw => ({
38
- items: fir.items.map((fi) => ({
39
- key: fi.key,
40
- speed: fi.speed,
41
- feePerByte: fi.feePerByte.toString(),
42
- })),
43
- defaultFeePerByte: fir.defaultFeePerByte.toString(),
44
- });
45
-
46
- export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
47
- const common = fromTransactionCommonRaw(tr);
48
- return {
49
- ...common,
50
- rbf: tr.rbf,
51
- utxoStrategy: tr.utxoStrategy,
52
- family: tr.family,
53
- feePerByte: tr.feePerByte ? new BigNumber(tr.feePerByte) : null,
54
- networkInfo: tr.networkInfo && {
55
- family: tr.networkInfo.family,
56
- feeItems: fromFeeItemsRaw(tr.networkInfo.feeItems),
57
- },
58
- feesStrategy: tr.feesStrategy,
59
- };
60
- };
61
- export const toTransactionRaw = (t: Transaction): TransactionRaw => {
62
- const common = toTransactionCommonRaw(t);
63
- return {
64
- ...common,
65
- rbf: t.rbf,
66
- utxoStrategy: t.utxoStrategy,
67
- family: t.family,
68
- feePerByte: t.feePerByte ? t.feePerByte.toString() : null,
69
- networkInfo: t.networkInfo && {
70
- family: t.networkInfo.family,
71
- feeItems: toFeeItemsRaw(t.networkInfo.feeItems),
72
- },
73
- feesStrategy: t.feesStrategy,
74
- };
75
- };
76
-
77
- const formatNetworkInfo = (
78
- networkInfo:
79
- | {
80
- feeItems: FeeItems;
81
- }
82
- | null
83
- | undefined
84
- ) => {
85
- if (!networkInfo) return "network info not loaded";
86
- return `network fees: ${networkInfo.feeItems.items
87
- .map((i) => i.key + "=" + i.feePerByte.toString())
88
- .join(", ")}`;
89
- };
90
-
91
- export const formatTransaction = (t: Transaction, account: Account): string => {
92
- const n = getEnv("DEBUG_UTXO_DISPLAY");
93
- const { excludeUTXOs, strategy, pickUnconfirmedRBF } = t.utxoStrategy;
94
- const displayAll = excludeUTXOs.length <= n;
95
- return `
96
- SEND ${
97
- t.useAllAmount
98
- ? "MAX"
99
- : formatCurrencyUnit(getAccountUnit(account), t.amount, {
100
- showCode: true,
101
- disableRounding: true,
102
- })
103
- }
104
- TO ${t.recipient}
105
- with feePerByte=${
106
- t.feePerByte ? t.feePerByte.toString() : "?"
107
- } (${formatNetworkInfo(t.networkInfo)})
108
- ${[
109
- Object.keys(bitcoinPickingStrategy).find(
110
- (k) => bitcoinPickingStrategy[k] === strategy
111
- ),
112
- pickUnconfirmedRBF && "pick-unconfirmed",
113
- t.rbf && "RBF-enabled",
114
- ]
115
- .filter(Boolean)
116
- .join(" ")}${excludeUTXOs
117
- .slice(0, displayAll ? excludeUTXOs.length : n)
118
- .map((utxo) => `\nexclude ${utxo.hash} @${utxo.outputIndex}`)
119
- .join("")}`;
120
- };
121
-
122
- // TODO vvvvv DEPRECATED, TO BE REMOVED vvvvv
123
-
124
28
  function bchExplicit(str: string): string {
125
29
  const explicit = str.includes(":") ? str : "bitcoincash:" + str;
126
30
 
@@ -254,7 +158,6 @@ export async function parseBitcoinOutput(
254
158
  outputIndex,
255
159
  blockHeight,
256
160
  address,
257
- isChange: false,
258
161
  path,
259
162
  value,
260
163
  rbf,
@@ -298,8 +201,100 @@ export function isChangeOutput(output: BitcoinOutput): boolean {
298
201
  const p = output.path.split("/");
299
202
  return p[p.length - 2] === "1";
300
203
  }
301
- // ==============================================================================
302
204
 
205
+ const fromFeeItemsRaw = (fir: FeeItemsRaw): FeeItems => ({
206
+ items: fir.items.map((fi) => ({
207
+ key: fi.key,
208
+ speed: fi.speed,
209
+ feePerByte: new BigNumber(fi.feePerByte),
210
+ })),
211
+ defaultFeePerByte: new BigNumber(fir.defaultFeePerByte),
212
+ });
213
+
214
+ const toFeeItemsRaw = (fir: FeeItems): FeeItemsRaw => ({
215
+ items: fir.items.map((fi) => ({
216
+ key: fi.key,
217
+ speed: fi.speed,
218
+ feePerByte: fi.feePerByte.toString(),
219
+ })),
220
+ defaultFeePerByte: fir.defaultFeePerByte.toString(),
221
+ });
222
+
223
+ export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
224
+ const common = fromTransactionCommonRaw(tr);
225
+ return {
226
+ ...common,
227
+ rbf: tr.rbf,
228
+ utxoStrategy: tr.utxoStrategy,
229
+ family: tr.family,
230
+ feePerByte: tr.feePerByte ? new BigNumber(tr.feePerByte) : null,
231
+ networkInfo: tr.networkInfo && {
232
+ family: tr.networkInfo.family,
233
+ feeItems: fromFeeItemsRaw(tr.networkInfo.feeItems),
234
+ },
235
+ feesStrategy: tr.feesStrategy,
236
+ };
237
+ };
238
+ export const toTransactionRaw = (t: Transaction): TransactionRaw => {
239
+ const common = toTransactionCommonRaw(t);
240
+ return {
241
+ ...common,
242
+ rbf: t.rbf,
243
+ utxoStrategy: t.utxoStrategy,
244
+ family: t.family,
245
+ feePerByte: t.feePerByte ? t.feePerByte.toString() : null,
246
+ networkInfo: t.networkInfo && {
247
+ family: t.networkInfo.family,
248
+ feeItems: toFeeItemsRaw(t.networkInfo.feeItems),
249
+ },
250
+ feesStrategy: t.feesStrategy,
251
+ };
252
+ };
253
+
254
+ const formatNetworkInfo = (
255
+ networkInfo:
256
+ | {
257
+ feeItems: FeeItems;
258
+ }
259
+ | null
260
+ | undefined
261
+ ) => {
262
+ if (!networkInfo) return "network info not loaded";
263
+ return `network fees: ${networkInfo.feeItems.items
264
+ .map((i) => i.key + "=" + i.feePerByte.toString())
265
+ .join(", ")}`;
266
+ };
267
+
268
+ export const formatTransaction = (t: Transaction, account: Account): string => {
269
+ const n = getEnv("DEBUG_UTXO_DISPLAY");
270
+ const { excludeUTXOs, strategy, pickUnconfirmedRBF } = t.utxoStrategy;
271
+ const displayAll = excludeUTXOs.length <= n;
272
+ return `
273
+ SEND ${
274
+ t.useAllAmount
275
+ ? "MAX"
276
+ : formatCurrencyUnit(getAccountUnit(account), t.amount, {
277
+ showCode: true,
278
+ disableRounding: true,
279
+ })
280
+ }
281
+ TO ${t.recipient}
282
+ with feePerByte=${
283
+ t.feePerByte ? t.feePerByte.toString() : "?"
284
+ } (${formatNetworkInfo(t.networkInfo)})
285
+ ${[
286
+ Object.keys(bitcoinPickingStrategy).find(
287
+ (k) => bitcoinPickingStrategy[k] === strategy
288
+ ),
289
+ pickUnconfirmedRBF && "pick-unconfirmed",
290
+ t.rbf && "RBF-enabled",
291
+ ]
292
+ .filter(Boolean)
293
+ .join(" ")}${excludeUTXOs
294
+ .slice(0, displayAll ? excludeUTXOs.length : n)
295
+ .map((utxo) => `\nexclude ${utxo.hash} @${utxo.outputIndex}`)
296
+ .join("")}`;
297
+ };
303
298
  export default {
304
299
  fromTransactionRaw,
305
300
  toTransactionRaw,