@ledgerhq/coin-framework 0.0.2-next.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 (471) hide show
  1. package/lib/account/accountId.d.ts +16 -0
  2. package/lib/account/accountId.d.ts.map +1 -0
  3. package/lib/account/accountId.js +85 -0
  4. package/lib/account/accountId.js.map +1 -0
  5. package/lib/account/accountName.d.ts +14 -0
  6. package/lib/account/accountName.d.ts.map +1 -0
  7. package/lib/account/accountName.js +17 -0
  8. package/lib/account/accountName.js.map +1 -0
  9. package/lib/account/addAccounts.d.ts +35 -0
  10. package/lib/account/addAccounts.d.ts.map +1 -0
  11. package/lib/account/addAccounts.js +209 -0
  12. package/lib/account/addAccounts.js.map +1 -0
  13. package/lib/account/balanceHistoryCache.d.ts +25 -0
  14. package/lib/account/balanceHistoryCache.d.ts.map +1 -0
  15. package/lib/account/balanceHistoryCache.js +115 -0
  16. package/lib/account/balanceHistoryCache.js.map +1 -0
  17. package/lib/account/groupOperations.d.ts +17 -0
  18. package/lib/account/groupOperations.d.ts.map +1 -0
  19. package/lib/account/groupOperations.js +127 -0
  20. package/lib/account/groupOperations.js.map +1 -0
  21. package/lib/account/helpers.d.ts +44 -0
  22. package/lib/account/helpers.d.ts.map +1 -0
  23. package/lib/account/helpers.js +333 -0
  24. package/lib/account/helpers.js.map +1 -0
  25. package/lib/account/helpers.test.d.ts +2 -0
  26. package/lib/account/helpers.test.d.ts.map +1 -0
  27. package/lib/account/helpers.test.js +366 -0
  28. package/lib/account/helpers.test.js.map +1 -0
  29. package/lib/account/index.d.ts +11 -0
  30. package/lib/account/index.d.ts.map +1 -0
  31. package/lib/account/index.js +27 -0
  32. package/lib/account/index.js.map +1 -0
  33. package/lib/account/ordering.d.ts +10 -0
  34. package/lib/account/ordering.d.ts.map +1 -0
  35. package/lib/account/ordering.js +110 -0
  36. package/lib/account/ordering.js.map +1 -0
  37. package/lib/account/pending.d.ts +33 -0
  38. package/lib/account/pending.d.ts.map +1 -0
  39. package/lib/account/pending.js +64 -0
  40. package/lib/account/pending.js.map +1 -0
  41. package/lib/account/serialization.d.ts +6 -0
  42. package/lib/account/serialization.d.ts.map +1 -0
  43. package/lib/account/serialization.js +118 -0
  44. package/lib/account/serialization.js.map +1 -0
  45. package/lib/account/support.d.ts +9 -0
  46. package/lib/account/support.d.ts.map +1 -0
  47. package/lib/account/support.js +72 -0
  48. package/lib/account/support.js.map +1 -0
  49. package/lib/account.test.d.ts +2 -0
  50. package/lib/account.test.d.ts.map +1 -0
  51. package/lib/account.test.js +257 -0
  52. package/lib/account.test.js.map +1 -0
  53. package/lib/bot/bot-test-context.d.ts +3 -0
  54. package/lib/bot/bot-test-context.d.ts.map +1 -0
  55. package/lib/bot/bot-test-context.js +26 -0
  56. package/lib/bot/bot-test-context.js.map +1 -0
  57. package/lib/bot/bot-test-context.test.d.ts +2 -0
  58. package/lib/bot/bot-test-context.test.d.ts.map +1 -0
  59. package/lib/bot/bot-test-context.test.js +41 -0
  60. package/lib/bot/bot-test-context.test.js.map +1 -0
  61. package/lib/bot/formatters.d.ts +2 -0
  62. package/lib/bot/formatters.d.ts.map +1 -0
  63. package/lib/bot/formatters.js +31 -0
  64. package/lib/bot/formatters.js.map +1 -0
  65. package/lib/bot/specs.d.ts +50 -0
  66. package/lib/bot/specs.d.ts.map +1 -0
  67. package/lib/bot/specs.js +204 -0
  68. package/lib/bot/specs.js.map +1 -0
  69. package/lib/bot/types.d.ts +178 -0
  70. package/lib/bot/types.d.ts.map +1 -0
  71. package/lib/bot/types.js +3 -0
  72. package/lib/bot/types.js.map +1 -0
  73. package/lib/bridge/getAddressWrapper.d.ts +6 -0
  74. package/lib/bridge/getAddressWrapper.d.ts.map +1 -0
  75. package/lib/bridge/getAddressWrapper.js +27 -0
  76. package/lib/bridge/getAddressWrapper.js.map +1 -0
  77. package/lib/bridge/jsHelpers.d.ts +63 -0
  78. package/lib/bridge/jsHelpers.d.ts.map +1 -0
  79. package/lib/bridge/jsHelpers.js +574 -0
  80. package/lib/bridge/jsHelpers.js.map +1 -0
  81. package/lib/cache.d.ts +10 -0
  82. package/lib/cache.d.ts.map +1 -0
  83. package/lib/cache.js +100 -0
  84. package/lib/cache.js.map +1 -0
  85. package/lib/cross.d.ts +42 -0
  86. package/lib/cross.d.ts.map +1 -0
  87. package/lib/cross.js +254 -0
  88. package/lib/cross.js.map +1 -0
  89. package/lib/cross.test.d.ts +2 -0
  90. package/lib/cross.test.d.ts.map +1 -0
  91. package/lib/cross.test.js +99 -0
  92. package/lib/cross.test.js.map +1 -0
  93. package/lib/currencies/BigNumberToLocaleString.d.ts +8 -0
  94. package/lib/currencies/BigNumberToLocaleString.d.ts.map +1 -0
  95. package/lib/currencies/BigNumberToLocaleString.js +65 -0
  96. package/lib/currencies/BigNumberToLocaleString.js.map +1 -0
  97. package/lib/currencies/BigNumberToLocaleString.test.d.ts +2 -0
  98. package/lib/currencies/BigNumberToLocaleString.test.d.ts.map +1 -0
  99. package/lib/currencies/BigNumberToLocaleString.test.js +108 -0
  100. package/lib/currencies/BigNumberToLocaleString.test.js.map +1 -0
  101. package/lib/currencies/CurrencyURIScheme.d.ts +13 -0
  102. package/lib/currencies/CurrencyURIScheme.d.ts.map +1 -0
  103. package/lib/currencies/CurrencyURIScheme.js +124 -0
  104. package/lib/currencies/CurrencyURIScheme.js.map +1 -0
  105. package/lib/currencies/chopCurrencyUnitDecimals.d.ts +3 -0
  106. package/lib/currencies/chopCurrencyUnitDecimals.d.ts.map +1 -0
  107. package/lib/currencies/chopCurrencyUnitDecimals.js +29 -0
  108. package/lib/currencies/chopCurrencyUnitDecimals.js.map +1 -0
  109. package/lib/currencies/formatCurrencyUnit.d.ts +33 -0
  110. package/lib/currencies/formatCurrencyUnit.d.ts.map +1 -0
  111. package/lib/currencies/formatCurrencyUnit.js +126 -0
  112. package/lib/currencies/formatCurrencyUnit.js.map +1 -0
  113. package/lib/currencies/formatShort.d.ts +8 -0
  114. package/lib/currencies/formatShort.d.ts.map +1 -0
  115. package/lib/currencies/formatShort.js +27 -0
  116. package/lib/currencies/formatShort.js.map +1 -0
  117. package/lib/currencies/index.d.ts +13 -0
  118. package/lib/currencies/index.d.ts.map +1 -0
  119. package/lib/currencies/index.js +65 -0
  120. package/lib/currencies/index.js.map +1 -0
  121. package/lib/currencies/localeUtility.d.ts +8 -0
  122. package/lib/currencies/localeUtility.d.ts.map +1 -0
  123. package/lib/currencies/localeUtility.js +49 -0
  124. package/lib/currencies/localeUtility.js.map +1 -0
  125. package/lib/currencies/parseCurrencyUnit.d.ts +4 -0
  126. package/lib/currencies/parseCurrencyUnit.d.ts.map +1 -0
  127. package/lib/currencies/parseCurrencyUnit.js +18 -0
  128. package/lib/currencies/parseCurrencyUnit.js.map +1 -0
  129. package/lib/currencies/sanitizeValueString.d.ts +6 -0
  130. package/lib/currencies/sanitizeValueString.d.ts.map +1 -0
  131. package/lib/currencies/sanitizeValueString.js +56 -0
  132. package/lib/currencies/sanitizeValueString.js.map +1 -0
  133. package/lib/currencies/support.d.ts +8 -0
  134. package/lib/currencies/support.d.ts.map +1 -0
  135. package/lib/currencies/support.js +101 -0
  136. package/lib/currencies/support.js.map +1 -0
  137. package/lib/currencies/valueFromUnit.d.ts +9 -0
  138. package/lib/currencies/valueFromUnit.d.ts.map +1 -0
  139. package/lib/currencies/valueFromUnit.js +14 -0
  140. package/lib/currencies/valueFromUnit.js.map +1 -0
  141. package/lib/derivation.d.ts +232 -0
  142. package/lib/derivation.d.ts.map +1 -0
  143. package/lib/derivation.js +501 -0
  144. package/lib/derivation.js.map +1 -0
  145. package/lib/env.d.ts +30 -0
  146. package/lib/env.d.ts.map +1 -0
  147. package/lib/env.js +783 -0
  148. package/lib/env.js.map +1 -0
  149. package/lib/errors.d.ts +7 -0
  150. package/lib/errors.d.ts.map +1 -0
  151. package/lib/errors.js +7 -0
  152. package/lib/errors.js.map +1 -0
  153. package/lib/errors.test.d.ts +2 -0
  154. package/lib/errors.test.d.ts.map +1 -0
  155. package/lib/errors.test.js +20 -0
  156. package/lib/errors.test.js.map +1 -0
  157. package/lib/mocks/account.d.ts +25 -0
  158. package/lib/mocks/account.d.ts.map +1 -0
  159. package/lib/mocks/account.js +368 -0
  160. package/lib/mocks/account.js.map +1 -0
  161. package/lib/mocks/fixtures/nfts.d.ts +27 -0
  162. package/lib/mocks/fixtures/nfts.d.ts.map +1 -0
  163. package/lib/mocks/fixtures/nfts.js +398 -0
  164. package/lib/mocks/fixtures/nfts.js.map +1 -0
  165. package/lib/mocks/fixtures/nfts.test.d.ts +2 -0
  166. package/lib/mocks/fixtures/nfts.test.d.ts.map +1 -0
  167. package/lib/mocks/fixtures/nfts.test.js +20 -0
  168. package/lib/mocks/fixtures/nfts.test.js.map +1 -0
  169. package/lib/mocks/helpers.d.ts +15 -0
  170. package/lib/mocks/helpers.d.ts.map +1 -0
  171. package/lib/mocks/helpers.js +32 -0
  172. package/lib/mocks/helpers.js.map +1 -0
  173. package/lib/network.d.ts +5 -0
  174. package/lib/network.d.ts.map +1 -0
  175. package/lib/network.js +125 -0
  176. package/lib/network.js.map +1 -0
  177. package/lib/nft/nftId.d.ts +8 -0
  178. package/lib/nft/nftId.d.ts.map +1 -0
  179. package/lib/nft/nftId.js +34 -0
  180. package/lib/nft/nftId.js.map +1 -0
  181. package/lib/operation.d.ts +24 -0
  182. package/lib/operation.d.ts.map +1 -0
  183. package/lib/operation.js +183 -0
  184. package/lib/operation.js.map +1 -0
  185. package/lib/promise.d.ts +21 -0
  186. package/lib/promise.d.ts.map +1 -0
  187. package/lib/promise.js +187 -0
  188. package/lib/promise.js.map +1 -0
  189. package/lib/promise.test.d.ts +2 -0
  190. package/lib/promise.test.d.ts.map +1 -0
  191. package/lib/promise.test.js +72 -0
  192. package/lib/promise.test.js.map +1 -0
  193. package/lib/rangeDates.d.ts +29 -0
  194. package/lib/rangeDates.d.ts.map +1 -0
  195. package/lib/rangeDates.js +94 -0
  196. package/lib/rangeDates.js.map +1 -0
  197. package/lib/rangeDates.test.d.ts +2 -0
  198. package/lib/rangeDates.test.d.ts.map +1 -0
  199. package/lib/rangeDates.test.js +51 -0
  200. package/lib/rangeDates.test.js.map +1 -0
  201. package/lib/test-helpers/staticTime.d.ts +2 -0
  202. package/lib/test-helpers/staticTime.d.ts.map +1 -0
  203. package/lib/test-helpers/staticTime.js +10 -0
  204. package/lib/test-helpers/staticTime.js.map +1 -0
  205. package/lib/transaction/common.d.ts +26 -0
  206. package/lib/transaction/common.d.ts.map +1 -0
  207. package/lib/transaction/common.js +123 -0
  208. package/lib/transaction/common.js.map +1 -0
  209. package/lib-es/account/accountId.d.ts +16 -0
  210. package/lib-es/account/accountId.d.ts.map +1 -0
  211. package/lib-es/account/accountId.js +74 -0
  212. package/lib-es/account/accountId.js.map +1 -0
  213. package/lib-es/account/accountName.d.ts +14 -0
  214. package/lib-es/account/accountName.d.ts.map +1 -0
  215. package/lib-es/account/accountName.js +12 -0
  216. package/lib-es/account/accountName.js.map +1 -0
  217. package/lib-es/account/addAccounts.d.ts +35 -0
  218. package/lib-es/account/addAccounts.d.ts.map +1 -0
  219. package/lib-es/account/addAccounts.js +200 -0
  220. package/lib-es/account/addAccounts.js.map +1 -0
  221. package/lib-es/account/balanceHistoryCache.d.ts +25 -0
  222. package/lib-es/account/balanceHistoryCache.d.ts.map +1 -0
  223. package/lib-es/account/balanceHistoryCache.js +109 -0
  224. package/lib-es/account/balanceHistoryCache.js.map +1 -0
  225. package/lib-es/account/groupOperations.d.ts +17 -0
  226. package/lib-es/account/groupOperations.d.ts.map +1 -0
  227. package/lib-es/account/groupOperations.js +122 -0
  228. package/lib-es/account/groupOperations.js.map +1 -0
  229. package/lib-es/account/helpers.d.ts +44 -0
  230. package/lib-es/account/helpers.d.ts.map +1 -0
  231. package/lib-es/account/helpers.js +303 -0
  232. package/lib-es/account/helpers.js.map +1 -0
  233. package/lib-es/account/helpers.test.d.ts +2 -0
  234. package/lib-es/account/helpers.test.d.ts.map +1 -0
  235. package/lib-es/account/helpers.test.js +361 -0
  236. package/lib-es/account/helpers.test.js.map +1 -0
  237. package/lib-es/account/index.d.ts +11 -0
  238. package/lib-es/account/index.d.ts.map +1 -0
  239. package/lib-es/account/index.js +11 -0
  240. package/lib-es/account/index.js.map +1 -0
  241. package/lib-es/account/ordering.d.ts +10 -0
  242. package/lib-es/account/ordering.d.ts.map +1 -0
  243. package/lib-es/account/ordering.js +103 -0
  244. package/lib-es/account/ordering.js.map +1 -0
  245. package/lib-es/account/pending.d.ts +33 -0
  246. package/lib-es/account/pending.d.ts.map +1 -0
  247. package/lib-es/account/pending.js +59 -0
  248. package/lib-es/account/pending.js.map +1 -0
  249. package/lib-es/account/serialization.d.ts +6 -0
  250. package/lib-es/account/serialization.d.ts.map +1 -0
  251. package/lib-es/account/serialization.js +112 -0
  252. package/lib-es/account/serialization.js.map +1 -0
  253. package/lib-es/account/support.d.ts +9 -0
  254. package/lib-es/account/support.d.ts.map +1 -0
  255. package/lib-es/account/support.js +64 -0
  256. package/lib-es/account/support.js.map +1 -0
  257. package/lib-es/account.test.d.ts +2 -0
  258. package/lib-es/account.test.d.ts.map +1 -0
  259. package/lib-es/account.test.js +252 -0
  260. package/lib-es/account.test.js.map +1 -0
  261. package/lib-es/bot/bot-test-context.d.ts +3 -0
  262. package/lib-es/bot/bot-test-context.d.ts.map +1 -0
  263. package/lib-es/bot/bot-test-context.js +21 -0
  264. package/lib-es/bot/bot-test-context.js.map +1 -0
  265. package/lib-es/bot/bot-test-context.test.d.ts +2 -0
  266. package/lib-es/bot/bot-test-context.test.d.ts.map +1 -0
  267. package/lib-es/bot/bot-test-context.test.js +39 -0
  268. package/lib-es/bot/bot-test-context.test.js.map +1 -0
  269. package/lib-es/bot/formatters.d.ts +2 -0
  270. package/lib-es/bot/formatters.d.ts.map +1 -0
  271. package/lib-es/bot/formatters.js +27 -0
  272. package/lib-es/bot/formatters.js.map +1 -0
  273. package/lib-es/bot/specs.d.ts +50 -0
  274. package/lib-es/bot/specs.d.ts.map +1 -0
  275. package/lib-es/bot/specs.js +193 -0
  276. package/lib-es/bot/specs.js.map +1 -0
  277. package/lib-es/bot/types.d.ts +178 -0
  278. package/lib-es/bot/types.d.ts.map +1 -0
  279. package/lib-es/bot/types.js +2 -0
  280. package/lib-es/bot/types.js.map +1 -0
  281. package/lib-es/bridge/getAddressWrapper.d.ts +6 -0
  282. package/lib-es/bridge/getAddressWrapper.d.ts.map +1 -0
  283. package/lib-es/bridge/getAddressWrapper.js +25 -0
  284. package/lib-es/bridge/getAddressWrapper.js.map +1 -0
  285. package/lib-es/bridge/jsHelpers.d.ts +63 -0
  286. package/lib-es/bridge/jsHelpers.d.ts.map +1 -0
  287. package/lib-es/bridge/jsHelpers.js +562 -0
  288. package/lib-es/bridge/jsHelpers.js.map +1 -0
  289. package/lib-es/cache.d.ts +10 -0
  290. package/lib-es/cache.d.ts.map +1 -0
  291. package/lib-es/cache.js +93 -0
  292. package/lib-es/cache.js.map +1 -0
  293. package/lib-es/cross.d.ts +42 -0
  294. package/lib-es/cross.d.ts.map +1 -0
  295. package/lib-es/cross.js +244 -0
  296. package/lib-es/cross.js.map +1 -0
  297. package/lib-es/cross.test.d.ts +2 -0
  298. package/lib-es/cross.test.d.ts.map +1 -0
  299. package/lib-es/cross.test.js +97 -0
  300. package/lib-es/cross.test.js.map +1 -0
  301. package/lib-es/currencies/BigNumberToLocaleString.d.ts +8 -0
  302. package/lib-es/currencies/BigNumberToLocaleString.d.ts.map +1 -0
  303. package/lib-es/currencies/BigNumberToLocaleString.js +61 -0
  304. package/lib-es/currencies/BigNumberToLocaleString.js.map +1 -0
  305. package/lib-es/currencies/BigNumberToLocaleString.test.d.ts +2 -0
  306. package/lib-es/currencies/BigNumberToLocaleString.test.d.ts.map +1 -0
  307. package/lib-es/currencies/BigNumberToLocaleString.test.js +106 -0
  308. package/lib-es/currencies/BigNumberToLocaleString.test.js.map +1 -0
  309. package/lib-es/currencies/CurrencyURIScheme.d.ts +13 -0
  310. package/lib-es/currencies/CurrencyURIScheme.d.ts.map +1 -0
  311. package/lib-es/currencies/CurrencyURIScheme.js +116 -0
  312. package/lib-es/currencies/CurrencyURIScheme.js.map +1 -0
  313. package/lib-es/currencies/chopCurrencyUnitDecimals.d.ts +3 -0
  314. package/lib-es/currencies/chopCurrencyUnitDecimals.d.ts.map +1 -0
  315. package/lib-es/currencies/chopCurrencyUnitDecimals.js +25 -0
  316. package/lib-es/currencies/chopCurrencyUnitDecimals.js.map +1 -0
  317. package/lib-es/currencies/formatCurrencyUnit.d.ts +33 -0
  318. package/lib-es/currencies/formatCurrencyUnit.d.ts.map +1 -0
  319. package/lib-es/currencies/formatCurrencyUnit.js +121 -0
  320. package/lib-es/currencies/formatCurrencyUnit.js.map +1 -0
  321. package/lib-es/currencies/formatShort.d.ts +8 -0
  322. package/lib-es/currencies/formatShort.d.ts.map +1 -0
  323. package/lib-es/currencies/formatShort.js +20 -0
  324. package/lib-es/currencies/formatShort.js.map +1 -0
  325. package/lib-es/currencies/index.d.ts +13 -0
  326. package/lib-es/currencies/index.d.ts.map +1 -0
  327. package/lib-es/currencies/index.js +16 -0
  328. package/lib-es/currencies/index.js.map +1 -0
  329. package/lib-es/currencies/localeUtility.d.ts +8 -0
  330. package/lib-es/currencies/localeUtility.d.ts.map +1 -0
  331. package/lib-es/currencies/localeUtility.js +43 -0
  332. package/lib-es/currencies/localeUtility.js.map +1 -0
  333. package/lib-es/currencies/parseCurrencyUnit.d.ts +4 -0
  334. package/lib-es/currencies/parseCurrencyUnit.d.ts.map +1 -0
  335. package/lib-es/currencies/parseCurrencyUnit.js +14 -0
  336. package/lib-es/currencies/parseCurrencyUnit.js.map +1 -0
  337. package/lib-es/currencies/sanitizeValueString.d.ts +6 -0
  338. package/lib-es/currencies/sanitizeValueString.d.ts.map +1 -0
  339. package/lib-es/currencies/sanitizeValueString.js +52 -0
  340. package/lib-es/currencies/sanitizeValueString.js.map +1 -0
  341. package/lib-es/currencies/support.d.ts +8 -0
  342. package/lib-es/currencies/support.d.ts.map +1 -0
  343. package/lib-es/currencies/support.js +92 -0
  344. package/lib-es/currencies/support.js.map +1 -0
  345. package/lib-es/currencies/valueFromUnit.d.ts +9 -0
  346. package/lib-es/currencies/valueFromUnit.d.ts.map +1 -0
  347. package/lib-es/currencies/valueFromUnit.js +10 -0
  348. package/lib-es/currencies/valueFromUnit.js.map +1 -0
  349. package/lib-es/derivation.d.ts +232 -0
  350. package/lib-es/derivation.d.ts.map +1 -0
  351. package/lib-es/derivation.js +473 -0
  352. package/lib-es/derivation.js.map +1 -0
  353. package/lib-es/env.d.ts +30 -0
  354. package/lib-es/env.d.ts.map +1 -0
  355. package/lib-es/env.js +768 -0
  356. package/lib-es/env.js.map +1 -0
  357. package/lib-es/errors.d.ts +7 -0
  358. package/lib-es/errors.d.ts.map +1 -0
  359. package/lib-es/errors.js +4 -0
  360. package/lib-es/errors.js.map +1 -0
  361. package/lib-es/errors.test.d.ts +2 -0
  362. package/lib-es/errors.test.d.ts.map +1 -0
  363. package/lib-es/errors.test.js +18 -0
  364. package/lib-es/errors.test.js.map +1 -0
  365. package/lib-es/mocks/account.d.ts +25 -0
  366. package/lib-es/mocks/account.d.ts.map +1 -0
  367. package/lib-es/mocks/account.js +358 -0
  368. package/lib-es/mocks/account.js.map +1 -0
  369. package/lib-es/mocks/fixtures/nfts.d.ts +27 -0
  370. package/lib-es/mocks/fixtures/nfts.d.ts.map +1 -0
  371. package/lib-es/mocks/fixtures/nfts.js +390 -0
  372. package/lib-es/mocks/fixtures/nfts.js.map +1 -0
  373. package/lib-es/mocks/fixtures/nfts.test.d.ts +2 -0
  374. package/lib-es/mocks/fixtures/nfts.test.d.ts.map +1 -0
  375. package/lib-es/mocks/fixtures/nfts.test.js +18 -0
  376. package/lib-es/mocks/fixtures/nfts.test.js.map +1 -0
  377. package/lib-es/mocks/helpers.d.ts +15 -0
  378. package/lib-es/mocks/helpers.d.ts.map +1 -0
  379. package/lib-es/mocks/helpers.js +26 -0
  380. package/lib-es/mocks/helpers.js.map +1 -0
  381. package/lib-es/network.d.ts +5 -0
  382. package/lib-es/network.d.ts.map +1 -0
  383. package/lib-es/network.js +118 -0
  384. package/lib-es/network.js.map +1 -0
  385. package/lib-es/nft/nftId.d.ts +8 -0
  386. package/lib-es/nft/nftId.d.ts.map +1 -0
  387. package/lib-es/nft/nftId.js +29 -0
  388. package/lib-es/nft/nftId.js.map +1 -0
  389. package/lib-es/operation.d.ts +24 -0
  390. package/lib-es/operation.d.ts.map +1 -0
  391. package/lib-es/operation.js +168 -0
  392. package/lib-es/operation.js.map +1 -0
  393. package/lib-es/promise.d.ts +21 -0
  394. package/lib-es/promise.d.ts.map +1 -0
  395. package/lib-es/promise.js +179 -0
  396. package/lib-es/promise.js.map +1 -0
  397. package/lib-es/promise.test.d.ts +2 -0
  398. package/lib-es/promise.test.d.ts.map +1 -0
  399. package/lib-es/promise.test.js +70 -0
  400. package/lib-es/promise.test.js.map +1 -0
  401. package/lib-es/rangeDates.d.ts +29 -0
  402. package/lib-es/rangeDates.d.ts.map +1 -0
  403. package/lib-es/rangeDates.js +84 -0
  404. package/lib-es/rangeDates.js.map +1 -0
  405. package/lib-es/rangeDates.test.d.ts +2 -0
  406. package/lib-es/rangeDates.test.d.ts.map +1 -0
  407. package/lib-es/rangeDates.test.js +49 -0
  408. package/lib-es/rangeDates.test.js.map +1 -0
  409. package/lib-es/test-helpers/staticTime.d.ts +2 -0
  410. package/lib-es/test-helpers/staticTime.d.ts.map +1 -0
  411. package/lib-es/test-helpers/staticTime.js +5 -0
  412. package/lib-es/test-helpers/staticTime.js.map +1 -0
  413. package/lib-es/transaction/common.d.ts +26 -0
  414. package/lib-es/transaction/common.d.ts.map +1 -0
  415. package/lib-es/transaction/common.js +115 -0
  416. package/lib-es/transaction/common.js.map +1 -0
  417. package/package.json +113 -0
  418. package/src/__snapshots__/account.test.ts.snap +2065 -0
  419. package/src/__snapshots__/cross.test.ts.snap +57 -0
  420. package/src/account/accountId.ts +93 -0
  421. package/src/account/accountName.ts +25 -0
  422. package/src/account/addAccounts.ts +236 -0
  423. package/src/account/balanceHistoryCache.ts +146 -0
  424. package/src/account/groupOperations.ts +164 -0
  425. package/src/account/helpers.test.ts +441 -0
  426. package/src/account/helpers.ts +380 -0
  427. package/src/account/index.ts +10 -0
  428. package/src/account/ordering.ts +109 -0
  429. package/src/account/pending.ts +66 -0
  430. package/src/account/serialization.ts +189 -0
  431. package/src/account/support.ts +96 -0
  432. package/src/account.test.ts +237 -0
  433. package/src/bot/bot-test-context.test.ts +37 -0
  434. package/src/bot/bot-test-context.ts +24 -0
  435. package/src/bot/formatters.ts +22 -0
  436. package/src/bot/specs.ts +275 -0
  437. package/src/bot/types.ts +224 -0
  438. package/src/bridge/getAddressWrapper.ts +40 -0
  439. package/src/bridge/jsHelpers.ts +645 -0
  440. package/src/cache.ts +65 -0
  441. package/src/cross.test.ts +112 -0
  442. package/src/cross.ts +366 -0
  443. package/src/currencies/BigNumberToLocaleString.test.ts +155 -0
  444. package/src/currencies/BigNumberToLocaleString.ts +80 -0
  445. package/src/currencies/CurrencyURIScheme.ts +114 -0
  446. package/src/currencies/chopCurrencyUnitDecimals.ts +34 -0
  447. package/src/currencies/formatCurrencyUnit.ts +167 -0
  448. package/src/currencies/formatShort.ts +24 -0
  449. package/src/currencies/index.ts +78 -0
  450. package/src/currencies/localeUtility.ts +50 -0
  451. package/src/currencies/parseCurrencyUnit.ts +16 -0
  452. package/src/currencies/sanitizeValueString.ts +58 -0
  453. package/src/currencies/support.ts +107 -0
  454. package/src/currencies/valueFromUnit.ts +10 -0
  455. package/src/derivation.ts +595 -0
  456. package/src/env.ts +790 -0
  457. package/src/errors.test.ts +21 -0
  458. package/src/errors.ts +9 -0
  459. package/src/mocks/account.ts +476 -0
  460. package/src/mocks/fixtures/nfts.test.ts +25 -0
  461. package/src/mocks/fixtures/nfts.ts +432 -0
  462. package/src/mocks/helpers.ts +38 -0
  463. package/src/network.ts +135 -0
  464. package/src/nft/nftId.ts +26 -0
  465. package/src/operation.ts +212 -0
  466. package/src/promise.test.ts +20 -0
  467. package/src/promise.ts +101 -0
  468. package/src/rangeDates.test.ts +66 -0
  469. package/src/rangeDates.ts +96 -0
  470. package/src/test-helpers/staticTime.ts +4 -0
  471. package/src/transaction/common.ts +157 -0
@@ -0,0 +1,212 @@
1
+ import type { Account, AccountLike, Operation } from "@ledgerhq/types-live";
2
+ import { BigNumber } from "bignumber.js";
3
+
4
+ export function findOperationInAccount(
5
+ { operations, pendingOperations }: AccountLike,
6
+ operationId: string
7
+ ): Operation | null | undefined {
8
+ for (let i = 0; i < operations.length; i++) {
9
+ const op = operations[i];
10
+ if (op.id === operationId) return op;
11
+
12
+ if (op.internalOperations) {
13
+ const internalOps = op.internalOperations;
14
+
15
+ for (let j = 0; j < internalOps.length; j++) {
16
+ const internalOp = internalOps[j];
17
+ if (internalOp.id === operationId) return internalOp;
18
+ }
19
+ }
20
+
21
+ if (op.nftOperations) {
22
+ const nftOps = op.nftOperations;
23
+
24
+ for (let j = 0; j < nftOps.length; j++) {
25
+ const nftOp = nftOps[j];
26
+
27
+ if (nftOp.id === operationId) return nftOp;
28
+ }
29
+ }
30
+ }
31
+
32
+ for (let i = 0; i < pendingOperations.length; i++) {
33
+ const op = pendingOperations[i];
34
+ if (op.id === operationId) return op;
35
+
36
+ if (op.nftOperations) {
37
+ const nftOps = op.nftOperations;
38
+
39
+ for (let j = 0; j < nftOps.length; j++) {
40
+ const nftOp = nftOps[j];
41
+
42
+ if (nftOp.id === operationId) return nftOp;
43
+ }
44
+ }
45
+ }
46
+
47
+ return null;
48
+ }
49
+
50
+ export function encodeOperationId(
51
+ accountId: string,
52
+ hash: string,
53
+ type: string
54
+ ): string {
55
+ return `${accountId}-${hash}-${type}`;
56
+ }
57
+
58
+ export function decodeOperationId(id: string): {
59
+ accountId: string;
60
+ hash: string;
61
+ type: string;
62
+ } {
63
+ const [accountId, hash, type] = id.split("-");
64
+ return {
65
+ accountId,
66
+ hash,
67
+ type,
68
+ };
69
+ }
70
+
71
+ export function encodeSubOperationId(
72
+ accountId: string,
73
+ hash: string,
74
+ type: string,
75
+ index: string | number
76
+ ): string {
77
+ return `${accountId}-${hash}-${type}-i${index}`;
78
+ }
79
+
80
+ export function decodeSubOperationId(id: string): {
81
+ accountId: string;
82
+ hash: string;
83
+ type: string;
84
+ index: number;
85
+ } {
86
+ const [accountId, hash, type, index] = id.split("-");
87
+ return {
88
+ accountId,
89
+ hash,
90
+ type,
91
+ index: Number(index),
92
+ };
93
+ }
94
+
95
+ export function patchOperationWithHash(
96
+ operation: Operation,
97
+ hash: string
98
+ ): Operation {
99
+ return {
100
+ ...operation,
101
+ hash,
102
+ id: encodeOperationId(operation.accountId, hash, operation.type),
103
+ subOperations:
104
+ operation.subOperations &&
105
+ operation.subOperations.map((op) => ({
106
+ ...op,
107
+ hash,
108
+ id: encodeOperationId(op.accountId, hash, op.type),
109
+ })),
110
+ };
111
+ }
112
+
113
+ export function flattenOperationWithInternalsAndNfts(
114
+ op: Operation
115
+ ): Operation[] {
116
+ let ops: Operation[] = [];
117
+
118
+ // ops of type NONE does not appear in lists
119
+ if (op.type !== "NONE") {
120
+ ops.push(op);
121
+ }
122
+
123
+ // all internal operations are expanded after the main op
124
+ if (op.internalOperations) {
125
+ ops = ops.concat(op.internalOperations);
126
+ }
127
+
128
+ // all nfts operations are expanded after the main op
129
+ if (op.nftOperations) {
130
+ ops = ops.concat(op.nftOperations);
131
+ }
132
+
133
+ return ops;
134
+ }
135
+
136
+ export function getOperationAmountNumber(op: Operation): BigNumber {
137
+ switch (op.type) {
138
+ case "IN":
139
+ case "REWARD":
140
+ case "REWARD_PAYOUT":
141
+ case "SUPPLY":
142
+ case "WITHDRAW":
143
+ return op.value;
144
+
145
+ case "OUT":
146
+ case "REVEAL":
147
+ case "CREATE":
148
+ case "FEES":
149
+ case "DELEGATE":
150
+ case "REDELEGATE":
151
+ case "UNDELEGATE":
152
+ case "OPT_IN":
153
+ case "OPT_OUT":
154
+ case "REDEEM":
155
+ case "SLASH":
156
+ case "LOCK":
157
+ return op.value.negated();
158
+
159
+ case "FREEZE":
160
+ case "UNFREEZE":
161
+ case "VOTE":
162
+ case "BOND":
163
+ case "UNBOND":
164
+ case "WITHDRAW_UNBONDED":
165
+ case "SET_CONTROLLER":
166
+ case "NOMINATE":
167
+ case "CHILL":
168
+ case "REVOKE":
169
+ case "APPROVE":
170
+ case "ACTIVATE":
171
+ case "UNLOCK":
172
+ case "STAKE":
173
+ case "UNSTAKE":
174
+ case "WITHDRAW_UNSTAKED":
175
+ return op.fee.negated();
176
+
177
+ default:
178
+ return new BigNumber(0);
179
+ }
180
+ }
181
+
182
+ export function getOperationAmountNumberWithInternals(
183
+ op: Operation
184
+ ): BigNumber {
185
+ return flattenOperationWithInternalsAndNfts(op).reduce(
186
+ (amount: BigNumber, op) => amount.plus(getOperationAmountNumber(op)),
187
+ new BigNumber(0)
188
+ );
189
+ }
190
+
191
+ export const getOperationConfirmationNumber = (
192
+ operation: Operation,
193
+ account: Account
194
+ ): number =>
195
+ operation.blockHeight ? account.blockHeight - operation.blockHeight + 1 : 0;
196
+
197
+ export const getOperationConfirmationDisplayableNumber = (
198
+ operation: Operation,
199
+ account: Account
200
+ ): string =>
201
+ account.blockHeight && operation.blockHeight && account.currency.blockAvgTime
202
+ ? String(account.blockHeight - operation.blockHeight + 1)
203
+ : "";
204
+
205
+ export const isConfirmedOperation = (
206
+ operation: Operation,
207
+ account: Account,
208
+ confirmationsNb: number
209
+ ): boolean =>
210
+ operation.blockHeight
211
+ ? account.blockHeight - operation.blockHeight + 1 >= confirmationsNb
212
+ : false;
@@ -0,0 +1,20 @@
1
+ import { promiseAllBatched } from "./promise";
2
+ test("promiseAllBatched", async () => {
3
+ const promisifyIdPlusOne = (a: number) => Promise.resolve(a + 1);
4
+
5
+ const p = promiseAllBatched(5, [], promisifyIdPlusOne);
6
+ expect(typeof p.then).toBe("function");
7
+ expect(await p).toEqual([]);
8
+ expect(
9
+ await promiseAllBatched(5, [1, 2, 3, 4, 5, 6, 7, 8], promisifyIdPlusOne)
10
+ ).toEqual([2, 3, 4, 5, 6, 7, 8, 9]);
11
+ expect(
12
+ await promiseAllBatched(1, [1, 2, 3, 4, 5, 6, 7, 8], promisifyIdPlusOne)
13
+ ).toEqual([2, 3, 4, 5, 6, 7, 8, 9]);
14
+ expect(
15
+ await promiseAllBatched(10, [1, 2, 3, 4, 5, 6, 7, 8], promisifyIdPlusOne)
16
+ ).toEqual([2, 3, 4, 5, 6, 7, 8, 9]);
17
+ expect(
18
+ await promiseAllBatched(2, Array(6).fill(0), (_, i) => Promise.resolve(i))
19
+ ).toEqual([0, 1, 2, 3, 4, 5]);
20
+ });
package/src/promise.ts ADDED
@@ -0,0 +1,101 @@
1
+ import { log } from "@ledgerhq/logs";
2
+ export const delay = (ms: number): Promise<void> =>
3
+ new Promise((f) => setTimeout(f, ms));
4
+ const defaults = {
5
+ maxRetry: 4,
6
+ interval: 300,
7
+ intervalMultiplicator: 1.5,
8
+ context: "",
9
+ };
10
+ export function retry<A>(
11
+ f: () => Promise<A>,
12
+ options?: Partial<typeof defaults>
13
+ ): Promise<A> {
14
+ const { maxRetry, interval, intervalMultiplicator, context } = {
15
+ ...defaults,
16
+ ...options,
17
+ };
18
+
19
+ function rec(remainingTry: number, i: number): Promise<A> {
20
+ const result = f();
21
+
22
+ if (remainingTry <= 0) {
23
+ return result;
24
+ }
25
+
26
+ // In case of failure, wait the interval, retry the action
27
+ return result.catch((e) => {
28
+ log(
29
+ "promise-retry",
30
+ context + " failed. " + remainingTry + " retry remain. " + String(e)
31
+ );
32
+ return delay(i).then(() =>
33
+ rec(remainingTry - 1, i * intervalMultiplicator)
34
+ );
35
+ });
36
+ }
37
+
38
+ return rec(maxRetry, interval);
39
+ }
40
+ type Job<R, A extends Array<any>> = (...args: A) => Promise<R>;
41
+ export const atomicQueue = <R, A extends Array<any>>(
42
+ job: Job<R, A>,
43
+ queueIdentifier: (...args: A) => string = () => ""
44
+ ): Job<R, A> => {
45
+ const queues: Record<string, any> = {};
46
+ return (...args) => {
47
+ const id = queueIdentifier(...args);
48
+ const queue = queues[id] || Promise.resolve();
49
+ const p = queue.then(() => job(...args));
50
+ queues[id] = p.catch(() => {});
51
+ return p;
52
+ };
53
+ };
54
+ export function execAndWaitAtLeast<A>(
55
+ ms: number,
56
+ cb: () => Promise<A>
57
+ ): Promise<A> {
58
+ const startTime = Date.now();
59
+ return cb().then((r) => {
60
+ const remaining = ms - (Date.now() - startTime);
61
+ if (remaining <= 0) return r;
62
+ return delay(remaining).then(() => r);
63
+ });
64
+ }
65
+
66
+ /**
67
+ * promiseAllBatched(n, items, i => f(i))
68
+ * is essentially like
69
+ * Promise.all(items.map(i => f(i)))
70
+ * but with a guarantee that it will not create more than n concurrent call to f
71
+ * where f is a function that returns a promise
72
+ */
73
+ export async function promiseAllBatched<A, B>(
74
+ batch: number,
75
+ items: Array<A>,
76
+ fn: (arg0: A, arg1: number) => Promise<B>
77
+ ): Promise<B[]> {
78
+ const data = Array(items.length);
79
+ const queue = items.map((item, index) => ({
80
+ item,
81
+ index,
82
+ }));
83
+
84
+ async function step() {
85
+ if (queue.length === 0) return;
86
+ const first = queue.shift();
87
+ if (first) {
88
+ const { item, index } = first;
89
+ data[index] = await fn(item, index);
90
+ }
91
+ await step(); // each time an item redeem, we schedule another one
92
+ }
93
+
94
+ // initially, we schedule <batch> items in parallel
95
+ await Promise.all(
96
+ Array(Math.min(batch, items.length))
97
+ .fill(() => undefined)
98
+ .map(step)
99
+ );
100
+ return data;
101
+ }
@@ -0,0 +1,66 @@
1
+ import {
2
+ startOfHour,
3
+ startOfMonth,
4
+ startOfDay,
5
+ startOfWeek,
6
+ getPortfolioRangeConfig,
7
+ getDates,
8
+ getRanges,
9
+ } from "./rangeDates";
10
+
11
+ describe("startOfHour", () => {
12
+ test("basic test", () => {
13
+ expect(startOfHour(new Date(1655827384305)).toISOString()).toBe(
14
+ "2022-06-21T16:00:00.000Z"
15
+ );
16
+ });
17
+ });
18
+ describe("startOfDay", () => {
19
+ test("basic test", () => {
20
+ expect(startOfDay(new Date(1655827384305)).toISOString()).toBe(
21
+ "2022-06-21T04:00:00.000Z"
22
+ );
23
+ });
24
+ });
25
+ describe("startOfMonth", () => {
26
+ test("basic test", () => {
27
+ expect(startOfMonth(new Date(1655827384305)).toISOString()).toBe(
28
+ "2022-06-01T04:00:00.000Z"
29
+ );
30
+ });
31
+ });
32
+ describe("startOfWeek", () => {
33
+ test("basic test", () => {
34
+ expect(startOfWeek(new Date(1655827384305)).toISOString()).toBe(
35
+ "2022-06-19T04:00:00.000Z"
36
+ );
37
+ });
38
+ });
39
+ describe("getPortfolioRangeConfig", () => {
40
+ test("returns a value for day", () => {
41
+ expect(getPortfolioRangeConfig("day")).toBeDefined();
42
+ });
43
+ test("returns a value for week", () => {
44
+ expect(getPortfolioRangeConfig("week")).toBeDefined();
45
+ });
46
+ test("returns a value for month", () => {
47
+ expect(getPortfolioRangeConfig("month")).toBeDefined();
48
+ });
49
+ });
50
+ describe("getDates", () => {
51
+ test("day returns an array of asked size", () => {
52
+ expect(getDates("day", 100).length).toEqual(100);
53
+ });
54
+ test("week returns an array of asked size", () => {
55
+ expect(getDates("week", 100).length).toEqual(100);
56
+ });
57
+ test("month returns an array of asked size", () => {
58
+ expect(getDates("month", 100).length).toEqual(100);
59
+ });
60
+ });
61
+
62
+ describe("getRanges", () => {
63
+ test("returns a non empty array", () => {
64
+ expect(getRanges().length).toBeGreaterThan(0);
65
+ });
66
+ });
@@ -0,0 +1,96 @@
1
+ import type {
2
+ PortfolioRangeConfig,
3
+ PortfolioRange,
4
+ } from "@ledgerhq/types-live";
5
+
6
+ export const hourIncrement = 60 * 60 * 1000;
7
+ export const dayIncrement = 24 * hourIncrement;
8
+ export const weekIncrement = 7 * dayIncrement;
9
+
10
+ export function startOfHour(t: Date): Date {
11
+ return new Date(t.getFullYear(), t.getMonth(), t.getDate(), t.getHours());
12
+ }
13
+
14
+ export function startOfMonth(t: Date): Date {
15
+ return new Date(t.getFullYear(), t.getMonth(), 1);
16
+ }
17
+
18
+ export function startOfDay(t: Date): Date {
19
+ return new Date(t.getFullYear(), t.getMonth(), t.getDate());
20
+ }
21
+
22
+ export function startOfWeek(t: Date): Date {
23
+ const d = startOfDay(t);
24
+ return new Date(d.getTime() - d.getDay() * dayIncrement);
25
+ }
26
+
27
+ export function getPortfolioRangeConfig(
28
+ r: PortfolioRange
29
+ ): PortfolioRangeConfig {
30
+ return ranges[r];
31
+ }
32
+ export const granularities = {
33
+ WEEK: {
34
+ increment: weekIncrement,
35
+ startOf: startOfWeek,
36
+ maxDatapoints: 1000, // (essentially no limit)
37
+ },
38
+ DAY: {
39
+ increment: dayIncrement,
40
+ startOf: startOfDay,
41
+ maxDatapoints: 400, // we only need a year
42
+ },
43
+ HOUR: {
44
+ increment: hourIncrement,
45
+ startOf: startOfHour,
46
+ maxDatapoints: 8 * 24, // we only need a week
47
+ },
48
+ };
49
+ // TODO Protfolio: this would require to introduce Account#olderOperationDate
50
+ const ranges: Record<PortfolioRange, PortfolioRangeConfig> = {
51
+ all: {
52
+ increment: weekIncrement,
53
+ startOf: startOfWeek,
54
+ granularityId: "WEEK",
55
+ },
56
+ year: {
57
+ count: 52,
58
+ increment: weekIncrement,
59
+ startOf: startOfWeek,
60
+ granularityId: "WEEK",
61
+ },
62
+ month: {
63
+ count: 30,
64
+ increment: dayIncrement,
65
+ startOf: startOfDay,
66
+ granularityId: "DAY",
67
+ },
68
+ week: {
69
+ count: 7 * 24,
70
+ increment: hourIncrement,
71
+ startOf: startOfHour,
72
+ granularityId: "HOUR",
73
+ },
74
+ day: {
75
+ count: 24,
76
+ increment: hourIncrement,
77
+ startOf: startOfHour,
78
+ granularityId: "HOUR",
79
+ },
80
+ };
81
+ export function getDates(r: PortfolioRange, count: number): Date[] {
82
+ const now = new Date(Date.now());
83
+ if (count === 1) return [now];
84
+ const conf = getPortfolioRangeConfig(r);
85
+ const last = new Date((conf.startOf(now) as any) - 1);
86
+ const dates = [now];
87
+
88
+ for (let i = 0; i < count - 1; i++) {
89
+ dates.unshift(new Date((last as any) - conf.increment * i));
90
+ }
91
+
92
+ return dates;
93
+ }
94
+ export function getRanges(): string[] {
95
+ return Object.keys(ranges);
96
+ }
@@ -0,0 +1,4 @@
1
+ import timemachine from "timemachine";
2
+ timemachine.config({
3
+ dateString: "March 14, 2018 13:34:42",
4
+ });
@@ -0,0 +1,157 @@
1
+ import { deserializeError, serializeError } from "@ledgerhq/errors";
2
+ import type {
3
+ Account,
4
+ TransactionCommon,
5
+ TransactionCommonRaw,
6
+ TransactionStatusCommon,
7
+ TransactionStatusCommonRaw,
8
+ } from "@ledgerhq/types-live";
9
+ import { BigNumber } from "bignumber.js";
10
+ import { mapValues } from "lodash";
11
+
12
+ import { getAccountUnit } from "../account";
13
+ import { formatCurrencyUnit } from "../currencies";
14
+
15
+ type tooltipArgs = Record<string, string>;
16
+ export type CommonDeviceTransactionField =
17
+ | {
18
+ type: "amount";
19
+ label: string;
20
+ }
21
+ | {
22
+ type: "address";
23
+ label: string;
24
+ address: string;
25
+ }
26
+ | {
27
+ type: "fees";
28
+ label: string;
29
+ }
30
+ | {
31
+ type: "text";
32
+ label: string;
33
+ value: string;
34
+ tooltipI18nKey?: string;
35
+ tooltipI18nArgs?: tooltipArgs;
36
+ };
37
+
38
+ export const fromTransactionCommonRaw = (
39
+ raw: TransactionCommonRaw
40
+ ): TransactionCommon => {
41
+ const common: TransactionCommon = {
42
+ amount: new BigNumber(raw.amount),
43
+ recipient: raw.recipient,
44
+ };
45
+
46
+ if ("useAllAmount" in raw) {
47
+ common.useAllAmount = raw.useAllAmount;
48
+ }
49
+
50
+ if ("subAccountId" in raw) {
51
+ common.subAccountId = raw.subAccountId;
52
+ }
53
+
54
+ return common;
55
+ };
56
+
57
+ export const toTransactionCommonRaw = (
58
+ raw: TransactionCommon
59
+ ): TransactionCommonRaw => {
60
+ const common: TransactionCommonRaw = {
61
+ amount: raw.amount.toString(),
62
+ recipient: raw.recipient,
63
+ };
64
+
65
+ if ("useAllAmount" in raw) {
66
+ common.useAllAmount = raw.useAllAmount;
67
+ }
68
+
69
+ if ("subAccountId" in raw) {
70
+ common.subAccountId = raw.subAccountId;
71
+ }
72
+
73
+ return common;
74
+ };
75
+
76
+ const fromErrorRaw = (raw: string): Error => {
77
+ return deserializeError(JSON.parse(raw)) || new Error("unknown reason");
78
+ };
79
+
80
+ const toErrorRaw = (raw: Error): string =>
81
+ JSON.stringify(serializeError(raw)) || "{}";
82
+
83
+ export const fromTransactionStatusRawCommon = (
84
+ ts: TransactionStatusCommonRaw
85
+ ): TransactionStatusCommon => ({
86
+ errors: mapValues(ts.errors, fromErrorRaw),
87
+ warnings: mapValues(ts.warnings, fromErrorRaw),
88
+ estimatedFees: new BigNumber(ts.estimatedFees),
89
+ amount: new BigNumber(ts.amount),
90
+ totalSpent: new BigNumber(ts.totalSpent),
91
+ recipientIsReadOnly: ts.recipientIsReadOnly,
92
+ });
93
+
94
+ export const toTransactionStatusRawCommon = (
95
+ ts: TransactionStatusCommon
96
+ ): TransactionStatusCommonRaw => ({
97
+ errors: mapValues<Record<string, Error>, string>(ts.errors, toErrorRaw),
98
+ warnings: mapValues<Record<string, Error>, string>(ts.warnings, toErrorRaw),
99
+ estimatedFees: ts.estimatedFees.toString(),
100
+ amount: ts.amount.toString(),
101
+ totalSpent: ts.totalSpent.toString(),
102
+ recipientIsReadOnly: ts.recipientIsReadOnly,
103
+ });
104
+
105
+ const formatErrorSmall = (e: Error): string =>
106
+ e.name === "Error" ? e.message : e.name;
107
+
108
+ export const formatTransactionStatusCommon = (
109
+ t: TransactionCommon,
110
+ {
111
+ errors,
112
+ warnings,
113
+ estimatedFees,
114
+ amount,
115
+ totalSpent,
116
+ }: TransactionStatusCommon,
117
+ mainAccount: Account
118
+ ): string => {
119
+ let str = "";
120
+ const account =
121
+ (t.subAccountId &&
122
+ (mainAccount.subAccounts || []).find((a) => a.id === t.subAccountId)) ||
123
+ mainAccount;
124
+
125
+ str +=
126
+ "\n amount: " +
127
+ formatCurrencyUnit(getAccountUnit(account), amount, {
128
+ showCode: true,
129
+ disableRounding: true,
130
+ });
131
+ str +=
132
+ "\n estimated fees: " +
133
+ formatCurrencyUnit(getAccountUnit(mainAccount), estimatedFees, {
134
+ showCode: true,
135
+ disableRounding: true,
136
+ });
137
+ str +=
138
+ "\n total spent: " +
139
+ formatCurrencyUnit(getAccountUnit(account), totalSpent, {
140
+ showCode: true,
141
+ disableRounding: true,
142
+ });
143
+
144
+ str +=
145
+ "\n" +
146
+ `errors: ${Object.entries(errors)
147
+ .map(([key, error]) => `${key} ${formatErrorSmall(error)}`)
148
+ .join(", ")}`;
149
+
150
+ str +=
151
+ "\n" +
152
+ `errors: ${Object.entries(warnings)
153
+ .map(([key, warning]) => `${key} ${formatErrorSmall(warning)}`)
154
+ .join(", ")}`;
155
+
156
+ return str;
157
+ };