@ledgerhq/coin-multiversx 0.2.0-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 (378) hide show
  1. package/.eslintrc.js +23 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +31 -0
  4. package/CHANGELOG.md +400 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/lib/api/apiCalls.d.ts +22 -0
  8. package/lib/api/apiCalls.d.ts.map +1 -0
  9. package/lib/api/apiCalls.js +153 -0
  10. package/lib/api/apiCalls.js.map +1 -0
  11. package/lib/api/dtos/multiversx-account.d.ts +9 -0
  12. package/lib/api/dtos/multiversx-account.d.ts.map +1 -0
  13. package/lib/api/dtos/multiversx-account.js +17 -0
  14. package/lib/api/dtos/multiversx-account.js.map +1 -0
  15. package/lib/api/index.d.ts +2 -0
  16. package/lib/api/index.d.ts.map +1 -0
  17. package/lib/api/index.js +16 -0
  18. package/lib/api/index.js.map +1 -0
  19. package/lib/api/sdk.d.ts +29 -0
  20. package/lib/api/sdk.d.ts.map +1 -0
  21. package/lib/api/sdk.js +281 -0
  22. package/lib/api/sdk.js.map +1 -0
  23. package/lib/bridge/js.d.ts +11 -0
  24. package/lib/bridge/js.d.ts.map +1 -0
  25. package/lib/bridge/js.js +62 -0
  26. package/lib/bridge/js.js.map +1 -0
  27. package/lib/bridge.integration.test.d.ts +4 -0
  28. package/lib/bridge.integration.test.d.ts.map +1 -0
  29. package/lib/bridge.integration.test.js +142 -0
  30. package/lib/bridge.integration.test.js.map +1 -0
  31. package/lib/broadcast.d.ts +9 -0
  32. package/lib/broadcast.d.ts.map +1 -0
  33. package/lib/broadcast.js +16 -0
  34. package/lib/broadcast.js.map +1 -0
  35. package/lib/buildOptimisticOperation.d.ts +4 -0
  36. package/lib/buildOptimisticOperation.d.ts.map +1 -0
  37. package/lib/buildOptimisticOperation.js +100 -0
  38. package/lib/buildOptimisticOperation.js.map +1 -0
  39. package/lib/buildOptimisticOperation.test.d.ts +2 -0
  40. package/lib/buildOptimisticOperation.test.d.ts.map +1 -0
  41. package/lib/buildOptimisticOperation.test.js +78 -0
  42. package/lib/buildOptimisticOperation.test.js.map +1 -0
  43. package/lib/buildSubAccounts.d.ts +11 -0
  44. package/lib/buildSubAccounts.d.ts.map +1 -0
  45. package/lib/buildSubAccounts.js +117 -0
  46. package/lib/buildSubAccounts.js.map +1 -0
  47. package/lib/buildTransaction.d.ts +19 -0
  48. package/lib/buildTransaction.d.ts.map +1 -0
  49. package/lib/buildTransaction.js +49 -0
  50. package/lib/buildTransaction.js.map +1 -0
  51. package/lib/buildTransaction.unit.test.d.ts +2 -0
  52. package/lib/buildTransaction.unit.test.d.ts.map +1 -0
  53. package/lib/buildTransaction.unit.test.js +47 -0
  54. package/lib/buildTransaction.unit.test.js.map +1 -0
  55. package/lib/cli-transaction.d.ts +16 -0
  56. package/lib/cli-transaction.d.ts.map +1 -0
  57. package/lib/cli-transaction.js +35 -0
  58. package/lib/cli-transaction.js.map +1 -0
  59. package/lib/config.d.ts +14 -0
  60. package/lib/config.d.ts.map +1 -0
  61. package/lib/config.js +16 -0
  62. package/lib/config.js.map +1 -0
  63. package/lib/constants.d.ts +21 -0
  64. package/lib/constants.d.ts.map +1 -0
  65. package/lib/constants.js +27 -0
  66. package/lib/constants.js.map +1 -0
  67. package/lib/createTransaction.d.ts +9 -0
  68. package/lib/createTransaction.d.ts.map +1 -0
  69. package/lib/createTransaction.js +26 -0
  70. package/lib/createTransaction.js.map +1 -0
  71. package/lib/datasets/multiversx1.d.ts +3 -0
  72. package/lib/datasets/multiversx1.d.ts.map +1 -0
  73. package/lib/datasets/multiversx1.js +21 -0
  74. package/lib/datasets/multiversx1.js.map +1 -0
  75. package/lib/deviceTransactionConfig.d.ts +10 -0
  76. package/lib/deviceTransactionConfig.d.ts.map +1 -0
  77. package/lib/deviceTransactionConfig.js +60 -0
  78. package/lib/deviceTransactionConfig.js.map +1 -0
  79. package/lib/encode.d.ts +11 -0
  80. package/lib/encode.d.ts.map +1 -0
  81. package/lib/encode.js +39 -0
  82. package/lib/encode.js.map +1 -0
  83. package/lib/errors.d.ts +16 -0
  84. package/lib/errors.d.ts.map +1 -0
  85. package/lib/errors.js +10 -0
  86. package/lib/errors.js.map +1 -0
  87. package/lib/estimateMaxSpendable.d.ts +10 -0
  88. package/lib/estimateMaxSpendable.d.ts.map +1 -0
  89. package/lib/estimateMaxSpendable.js +35 -0
  90. package/lib/estimateMaxSpendable.js.map +1 -0
  91. package/lib/formatters.d.ts +11 -0
  92. package/lib/formatters.d.ts.map +1 -0
  93. package/lib/formatters.js +65 -0
  94. package/lib/formatters.js.map +1 -0
  95. package/lib/getTransactionStatus.d.ts +5 -0
  96. package/lib/getTransactionStatus.d.ts.map +1 -0
  97. package/lib/getTransactionStatus.js +107 -0
  98. package/lib/getTransactionStatus.js.map +1 -0
  99. package/lib/helpers/denominate.d.ts +9 -0
  100. package/lib/helpers/denominate.d.ts.map +1 -0
  101. package/lib/helpers/denominate.js +75 -0
  102. package/lib/helpers/denominate.js.map +1 -0
  103. package/lib/helpers/handleTransactionStatus.d.ts +7 -0
  104. package/lib/helpers/handleTransactionStatus.d.ts.map +1 -0
  105. package/lib/helpers/handleTransactionStatus.js +18 -0
  106. package/lib/helpers/handleTransactionStatus.js.map +1 -0
  107. package/lib/helpers/hasMinimumDelegableBalance.d.ts +3 -0
  108. package/lib/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
  109. package/lib/helpers/hasMinimumDelegableBalance.js +7 -0
  110. package/lib/helpers/hasMinimumDelegableBalance.js.map +1 -0
  111. package/lib/helpers/randomizeProviders.d.ts +7 -0
  112. package/lib/helpers/randomizeProviders.d.ts.map +1 -0
  113. package/lib/helpers/randomizeProviders.js +12 -0
  114. package/lib/helpers/randomizeProviders.js.map +1 -0
  115. package/lib/hw-getAddress.d.ts +6 -0
  116. package/lib/hw-getAddress.d.ts.map +1 -0
  117. package/lib/hw-getAddress.js +14 -0
  118. package/lib/hw-getAddress.js.map +1 -0
  119. package/lib/logic.d.ts +15 -0
  120. package/lib/logic.d.ts.map +1 -0
  121. package/lib/logic.js +77 -0
  122. package/lib/logic.js.map +1 -0
  123. package/lib/preload.d.ts +11 -0
  124. package/lib/preload.d.ts.map +1 -0
  125. package/lib/preload.js +94 -0
  126. package/lib/preload.js.map +1 -0
  127. package/lib/prepareTransaction.d.ts +10 -0
  128. package/lib/prepareTransaction.d.ts.map +1 -0
  129. package/lib/prepareTransaction.js +72 -0
  130. package/lib/prepareTransaction.js.map +1 -0
  131. package/lib/reconciliation.d.ts +3 -0
  132. package/lib/reconciliation.d.ts.map +1 -0
  133. package/lib/reconciliation.js +56 -0
  134. package/lib/reconciliation.js.map +1 -0
  135. package/lib/serialization.d.ts +9 -0
  136. package/lib/serialization.d.ts.map +1 -0
  137. package/lib/serialization.js +65 -0
  138. package/lib/serialization.js.map +1 -0
  139. package/lib/signOperation.d.ts +10 -0
  140. package/lib/signOperation.d.ts.map +1 -0
  141. package/lib/signOperation.js +65 -0
  142. package/lib/signOperation.js.map +1 -0
  143. package/lib/signer.d.ts +16 -0
  144. package/lib/signer.d.ts.map +1 -0
  145. package/lib/signer.js +3 -0
  146. package/lib/signer.js.map +1 -0
  147. package/lib/specs.d.ts +7 -0
  148. package/lib/specs.d.ts.map +1 -0
  149. package/lib/specs.js +286 -0
  150. package/lib/specs.js.map +1 -0
  151. package/lib/speculos-deviceActions.d.ts +16 -0
  152. package/lib/speculos-deviceActions.d.ts.map +1 -0
  153. package/lib/speculos-deviceActions.js +250 -0
  154. package/lib/speculos-deviceActions.js.map +1 -0
  155. package/lib/synchronisation.d.ts +5 -0
  156. package/lib/synchronisation.d.ts.map +1 -0
  157. package/lib/synchronisation.js +69 -0
  158. package/lib/synchronisation.js.map +1 -0
  159. package/lib/transaction.d.ts +15 -0
  160. package/lib/transaction.d.ts.map +1 -0
  161. package/lib/transaction.js +62 -0
  162. package/lib/transaction.js.map +1 -0
  163. package/lib/types.d.ts +188 -0
  164. package/lib/types.d.ts.map +1 -0
  165. package/lib/types.js +17 -0
  166. package/lib/types.js.map +1 -0
  167. package/lib/utils/binary.utils.d.ts +5 -0
  168. package/lib/utils/binary.utils.d.ts.map +1 -0
  169. package/lib/utils/binary.utils.js +16 -0
  170. package/lib/utils/binary.utils.js.map +1 -0
  171. package/lib-es/api/apiCalls.d.ts +22 -0
  172. package/lib-es/api/apiCalls.d.ts.map +1 -0
  173. package/lib-es/api/apiCalls.js +147 -0
  174. package/lib-es/api/apiCalls.js.map +1 -0
  175. package/lib-es/api/dtos/multiversx-account.d.ts +9 -0
  176. package/lib-es/api/dtos/multiversx-account.d.ts.map +1 -0
  177. package/lib-es/api/dtos/multiversx-account.js +13 -0
  178. package/lib-es/api/dtos/multiversx-account.js.map +1 -0
  179. package/lib-es/api/index.d.ts +2 -0
  180. package/lib-es/api/index.d.ts.map +1 -0
  181. package/lib-es/api/index.js +2 -0
  182. package/lib-es/api/index.js.map +1 -0
  183. package/lib-es/api/sdk.d.ts +29 -0
  184. package/lib-es/api/sdk.d.ts.map +1 -0
  185. package/lib-es/api/sdk.js +264 -0
  186. package/lib-es/api/sdk.js.map +1 -0
  187. package/lib-es/bridge/js.d.ts +11 -0
  188. package/lib-es/bridge/js.d.ts.map +1 -0
  189. package/lib-es/bridge/js.js +53 -0
  190. package/lib-es/bridge/js.js.map +1 -0
  191. package/lib-es/bridge.integration.test.d.ts +4 -0
  192. package/lib-es/bridge.integration.test.d.ts.map +1 -0
  193. package/lib-es/bridge.integration.test.js +139 -0
  194. package/lib-es/bridge.integration.test.js.map +1 -0
  195. package/lib-es/broadcast.d.ts +9 -0
  196. package/lib-es/broadcast.d.ts.map +1 -0
  197. package/lib-es/broadcast.js +12 -0
  198. package/lib-es/broadcast.js.map +1 -0
  199. package/lib-es/buildOptimisticOperation.d.ts +4 -0
  200. package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
  201. package/lib-es/buildOptimisticOperation.js +93 -0
  202. package/lib-es/buildOptimisticOperation.js.map +1 -0
  203. package/lib-es/buildOptimisticOperation.test.d.ts +2 -0
  204. package/lib-es/buildOptimisticOperation.test.d.ts.map +1 -0
  205. package/lib-es/buildOptimisticOperation.test.js +73 -0
  206. package/lib-es/buildOptimisticOperation.test.js.map +1 -0
  207. package/lib-es/buildSubAccounts.d.ts +11 -0
  208. package/lib-es/buildSubAccounts.d.ts.map +1 -0
  209. package/lib-es/buildSubAccounts.js +112 -0
  210. package/lib-es/buildSubAccounts.js.map +1 -0
  211. package/lib-es/buildTransaction.d.ts +19 -0
  212. package/lib-es/buildTransaction.d.ts.map +1 -0
  213. package/lib-es/buildTransaction.js +44 -0
  214. package/lib-es/buildTransaction.js.map +1 -0
  215. package/lib-es/buildTransaction.unit.test.d.ts +2 -0
  216. package/lib-es/buildTransaction.unit.test.d.ts.map +1 -0
  217. package/lib-es/buildTransaction.unit.test.js +42 -0
  218. package/lib-es/buildTransaction.unit.test.js.map +1 -0
  219. package/lib-es/cli-transaction.d.ts +16 -0
  220. package/lib-es/cli-transaction.d.ts.map +1 -0
  221. package/lib-es/cli-transaction.js +29 -0
  222. package/lib-es/cli-transaction.js.map +1 -0
  223. package/lib-es/config.d.ts +14 -0
  224. package/lib-es/config.d.ts.map +1 -0
  225. package/lib-es/config.js +11 -0
  226. package/lib-es/config.js.map +1 -0
  227. package/lib-es/constants.d.ts +21 -0
  228. package/lib-es/constants.d.ts.map +1 -0
  229. package/lib-es/constants.js +21 -0
  230. package/lib-es/constants.js.map +1 -0
  231. package/lib-es/createTransaction.d.ts +9 -0
  232. package/lib-es/createTransaction.d.ts.map +1 -0
  233. package/lib-es/createTransaction.js +19 -0
  234. package/lib-es/createTransaction.js.map +1 -0
  235. package/lib-es/datasets/multiversx1.d.ts +3 -0
  236. package/lib-es/datasets/multiversx1.d.ts.map +1 -0
  237. package/lib-es/datasets/multiversx1.js +18 -0
  238. package/lib-es/datasets/multiversx1.js.map +1 -0
  239. package/lib-es/deviceTransactionConfig.d.ts +10 -0
  240. package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
  241. package/lib-es/deviceTransactionConfig.js +55 -0
  242. package/lib-es/deviceTransactionConfig.js.map +1 -0
  243. package/lib-es/encode.d.ts +11 -0
  244. package/lib-es/encode.d.ts.map +1 -0
  245. package/lib-es/encode.js +35 -0
  246. package/lib-es/encode.js.map +1 -0
  247. package/lib-es/errors.d.ts +16 -0
  248. package/lib-es/errors.d.ts.map +1 -0
  249. package/lib-es/errors.js +7 -0
  250. package/lib-es/errors.js.map +1 -0
  251. package/lib-es/estimateMaxSpendable.d.ts +10 -0
  252. package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
  253. package/lib-es/estimateMaxSpendable.js +31 -0
  254. package/lib-es/estimateMaxSpendable.js.map +1 -0
  255. package/lib-es/formatters.d.ts +11 -0
  256. package/lib-es/formatters.d.ts.map +1 -0
  257. package/lib-es/formatters.js +60 -0
  258. package/lib-es/formatters.js.map +1 -0
  259. package/lib-es/getTransactionStatus.d.ts +5 -0
  260. package/lib-es/getTransactionStatus.d.ts.map +1 -0
  261. package/lib-es/getTransactionStatus.js +100 -0
  262. package/lib-es/getTransactionStatus.js.map +1 -0
  263. package/lib-es/helpers/denominate.d.ts +9 -0
  264. package/lib-es/helpers/denominate.d.ts.map +1 -0
  265. package/lib-es/helpers/denominate.js +71 -0
  266. package/lib-es/helpers/denominate.js.map +1 -0
  267. package/lib-es/helpers/handleTransactionStatus.d.ts +7 -0
  268. package/lib-es/helpers/handleTransactionStatus.d.ts.map +1 -0
  269. package/lib-es/helpers/handleTransactionStatus.js +14 -0
  270. package/lib-es/helpers/handleTransactionStatus.js.map +1 -0
  271. package/lib-es/helpers/hasMinimumDelegableBalance.d.ts +3 -0
  272. package/lib-es/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
  273. package/lib-es/helpers/hasMinimumDelegableBalance.js +3 -0
  274. package/lib-es/helpers/hasMinimumDelegableBalance.js.map +1 -0
  275. package/lib-es/helpers/randomizeProviders.d.ts +7 -0
  276. package/lib-es/helpers/randomizeProviders.d.ts.map +1 -0
  277. package/lib-es/helpers/randomizeProviders.js +8 -0
  278. package/lib-es/helpers/randomizeProviders.js.map +1 -0
  279. package/lib-es/hw-getAddress.d.ts +6 -0
  280. package/lib-es/hw-getAddress.d.ts.map +1 -0
  281. package/lib-es/hw-getAddress.js +12 -0
  282. package/lib-es/hw-getAddress.js.map +1 -0
  283. package/lib-es/logic.d.ts +15 -0
  284. package/lib-es/logic.d.ts.map +1 -0
  285. package/lib-es/logic.js +65 -0
  286. package/lib-es/logic.js.map +1 -0
  287. package/lib-es/preload.d.ts +11 -0
  288. package/lib-es/preload.d.ts.map +1 -0
  289. package/lib-es/preload.js +85 -0
  290. package/lib-es/preload.js.map +1 -0
  291. package/lib-es/prepareTransaction.d.ts +10 -0
  292. package/lib-es/prepareTransaction.d.ts.map +1 -0
  293. package/lib-es/prepareTransaction.js +68 -0
  294. package/lib-es/prepareTransaction.js.map +1 -0
  295. package/lib-es/reconciliation.d.ts +3 -0
  296. package/lib-es/reconciliation.d.ts.map +1 -0
  297. package/lib-es/reconciliation.js +52 -0
  298. package/lib-es/reconciliation.js.map +1 -0
  299. package/lib-es/serialization.d.ts +9 -0
  300. package/lib-es/serialization.d.ts.map +1 -0
  301. package/lib-es/serialization.js +53 -0
  302. package/lib-es/serialization.js.map +1 -0
  303. package/lib-es/signOperation.d.ts +10 -0
  304. package/lib-es/signOperation.d.ts.map +1 -0
  305. package/lib-es/signOperation.js +61 -0
  306. package/lib-es/signOperation.js.map +1 -0
  307. package/lib-es/signer.d.ts +16 -0
  308. package/lib-es/signer.d.ts.map +1 -0
  309. package/lib-es/signer.js +2 -0
  310. package/lib-es/signer.js.map +1 -0
  311. package/lib-es/specs.d.ts +7 -0
  312. package/lib-es/specs.d.ts.map +1 -0
  313. package/lib-es/specs.js +281 -0
  314. package/lib-es/specs.js.map +1 -0
  315. package/lib-es/speculos-deviceActions.d.ts +16 -0
  316. package/lib-es/speculos-deviceActions.d.ts.map +1 -0
  317. package/lib-es/speculos-deviceActions.js +244 -0
  318. package/lib-es/speculos-deviceActions.js.map +1 -0
  319. package/lib-es/synchronisation.d.ts +5 -0
  320. package/lib-es/synchronisation.d.ts.map +1 -0
  321. package/lib-es/synchronisation.js +62 -0
  322. package/lib-es/synchronisation.js.map +1 -0
  323. package/lib-es/transaction.d.ts +15 -0
  324. package/lib-es/transaction.d.ts.map +1 -0
  325. package/lib-es/transaction.js +56 -0
  326. package/lib-es/transaction.js.map +1 -0
  327. package/lib-es/types.d.ts +188 -0
  328. package/lib-es/types.d.ts.map +1 -0
  329. package/lib-es/types.js +12 -0
  330. package/lib-es/types.js.map +1 -0
  331. package/lib-es/utils/binary.utils.d.ts +5 -0
  332. package/lib-es/utils/binary.utils.d.ts.map +1 -0
  333. package/lib-es/utils/binary.utils.js +12 -0
  334. package/lib-es/utils/binary.utils.js.map +1 -0
  335. package/package.json +86 -0
  336. package/src/__snapshots__/bridge.integration.test.ts.snap +181 -0
  337. package/src/api/apiCalls.ts +243 -0
  338. package/src/api/dtos/multiversx-account.ts +20 -0
  339. package/src/api/index.ts +13 -0
  340. package/src/api/sdk.ts +368 -0
  341. package/src/bridge/js.ts +77 -0
  342. package/src/bridge.integration.test.ts +147 -0
  343. package/src/broadcast.ts +16 -0
  344. package/src/buildOptimisticOperation.test.ts +88 -0
  345. package/src/buildOptimisticOperation.ts +120 -0
  346. package/src/buildSubAccounts.ts +153 -0
  347. package/src/buildTransaction.ts +67 -0
  348. package/src/buildTransaction.unit.test.ts +49 -0
  349. package/src/cli-transaction.ts +41 -0
  350. package/src/config.ts +26 -0
  351. package/src/constants.ts +24 -0
  352. package/src/createTransaction.ts +21 -0
  353. package/src/datasets/multiversx1.ts +19 -0
  354. package/src/deviceTransactionConfig.ts +74 -0
  355. package/src/encode.ts +46 -0
  356. package/src/errors.ts +19 -0
  357. package/src/estimateMaxSpendable.ts +43 -0
  358. package/src/formatters.ts +76 -0
  359. package/src/getTransactionStatus.ts +151 -0
  360. package/src/helpers/denominate.ts +95 -0
  361. package/src/helpers/handleTransactionStatus.ts +26 -0
  362. package/src/helpers/hasMinimumDelegableBalance.ts +6 -0
  363. package/src/helpers/randomizeProviders.ts +20 -0
  364. package/src/hw-getAddress.ts +19 -0
  365. package/src/logic.ts +83 -0
  366. package/src/preload.ts +95 -0
  367. package/src/prepareTransaction.ts +78 -0
  368. package/src/reconciliation.ts +64 -0
  369. package/src/serialization.ts +72 -0
  370. package/src/signOperation.ts +99 -0
  371. package/src/signer.ts +21 -0
  372. package/src/specs.ts +387 -0
  373. package/src/speculos-deviceActions.ts +269 -0
  374. package/src/synchronisation.ts +74 -0
  375. package/src/transaction.ts +76 -0
  376. package/src/types.ts +235 -0
  377. package/src/utils/binary.utils.ts +13 -0
  378. package/tsconfig.json +13 -0
@@ -0,0 +1,55 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
3
+ import { decodeTokenAccountId, getAccountCurrency } from "@ledgerhq/coin-framework/account";
4
+ import { isAmountSpentFromBalance } from "./logic";
5
+ function getDeviceTransactionConfig({ account, transaction, status: { estimatedFees }, }) {
6
+ const fields = [];
7
+ const { subAccountId } = transaction;
8
+ const isEsdtTransfer = subAccountId !== undefined && subAccountId !== null;
9
+ if (isEsdtTransfer) {
10
+ const { token } = decodeTokenAccountId(subAccountId);
11
+ if (token) {
12
+ fields.push({
13
+ type: "text",
14
+ label: "Token",
15
+ value: token.name,
16
+ });
17
+ fields.push({
18
+ type: "amount",
19
+ label: "Value",
20
+ });
21
+ }
22
+ }
23
+ fields.push({
24
+ type: "address",
25
+ label: "Receiver",
26
+ address: transaction.recipient,
27
+ });
28
+ if (!isEsdtTransfer) {
29
+ if (!isAmountSpentFromBalance(transaction.mode)) {
30
+ fields.push({
31
+ type: "text",
32
+ label: "Amount",
33
+ value: formatCurrencyUnit(getAccountCurrency(account).units[0], new BigNumber(0), {
34
+ showCode: true,
35
+ disableRounding: true,
36
+ }),
37
+ });
38
+ }
39
+ else {
40
+ fields.push({
41
+ type: "amount",
42
+ label: "Amount",
43
+ });
44
+ }
45
+ }
46
+ if (!estimatedFees.isZero()) {
47
+ fields.push({
48
+ type: "fees",
49
+ label: "Fee",
50
+ });
51
+ }
52
+ return fields;
53
+ }
54
+ export default getDeviceTransactionConfig;
55
+ //# sourceMappingURL=deviceTransactionConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceTransactionConfig.js","sourceRoot":"","sources":["../src/deviceTransactionConfig.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAE5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD,SAAS,0BAA0B,CAAC,EAClC,OAAO,EACP,WAAW,EACX,MAAM,EAAE,EAAE,aAAa,EAAE,GAK1B;IACC,MAAM,MAAM,GAAkC,EAAE,CAAC;IAEjD,MAAM,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC;IACrC,MAAM,cAAc,GAAG,YAAY,KAAK,SAAS,IAAI,YAAY,KAAK,IAAI,CAAC;IAE3E,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,EAAE,KAAK,EAAE,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAC;QAErD,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,OAAO;gBACd,KAAK,EAAE,KAAK,CAAC,IAAI;aAClB,CAAC,CAAC;YAEH,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,OAAO;aACf,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM,CAAC,IAAI,CAAC;QACV,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,WAAW,CAAC,SAAS;KAC/B,CAAC,CAAC;IAEH,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,IAAI,CAAC,wBAAwB,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,QAAQ;gBACf,KAAK,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE;oBAChF,QAAQ,EAAE,IAAI;oBACd,eAAe,EAAE,IAAI;iBACtB,CAAC;aACH,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,QAAQ;aAChB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { SubAccount } from "@ledgerhq/types-live";
2
+ import type { Transaction } from "./types";
3
+ export declare class MultiversXEncodeTransaction {
4
+ static ESDTTransfer(t: Transaction, ta: SubAccount): string;
5
+ static delegate(): string;
6
+ static claimRewards(): string;
7
+ static withdraw(): string;
8
+ static reDelegateRewards(): string;
9
+ static unDelegate(t: Transaction): string;
10
+ }
11
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,qBAAa,2BAA2B;IACtC,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,UAAU,GAAG,MAAM;IAa3D,MAAM,CAAC,QAAQ,IAAI,MAAM;IAIzB,MAAM,CAAC,YAAY,IAAI,MAAM;IAI7B,MAAM,CAAC,QAAQ,IAAI,MAAM;IAIzB,MAAM,CAAC,iBAAiB,IAAI,MAAM;IAIlC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM;CAU1C"}
@@ -0,0 +1,35 @@
1
+ import { decodeTokenAccountId } from "@ledgerhq/coin-framework/account";
2
+ import { extractTokenId } from "./logic";
3
+ export class MultiversXEncodeTransaction {
4
+ static ESDTTransfer(t, ta) {
5
+ const { token } = decodeTokenAccountId(ta.id);
6
+ const tokenIdentifierHex = token && extractTokenId(token.id);
7
+ let amountHex = t.useAllAmount ? ta.balance.toString(16) : t.amount.toString(16);
8
+ //hex amount length must be even so protocol would treat it as an ESDT transfer
9
+ if (amountHex.length % 2 !== 0) {
10
+ amountHex = "0" + amountHex;
11
+ }
12
+ return Buffer.from(`ESDTTransfer@${tokenIdentifierHex}@${amountHex}`).toString("base64");
13
+ }
14
+ static delegate() {
15
+ return Buffer.from(`delegate`).toString("base64");
16
+ }
17
+ static claimRewards() {
18
+ return Buffer.from(`claimRewards`).toString("base64");
19
+ }
20
+ static withdraw() {
21
+ return Buffer.from(`withdraw`).toString("base64");
22
+ }
23
+ static reDelegateRewards() {
24
+ return Buffer.from(`reDelegateRewards`).toString("base64");
25
+ }
26
+ static unDelegate(t) {
27
+ let amountHex = t.amount.toString(16);
28
+ //hex amount length must be even
29
+ if (amountHex.length % 2 !== 0) {
30
+ amountHex = "0" + amountHex;
31
+ }
32
+ return Buffer.from(`unDelegate@${amountHex}`).toString("base64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,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,CAAC,iBAAiB;QACtB,OAAO,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,CAAc;QAC9B,IAAI,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAEtC,gCAAgC;QAChC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,SAAS,GAAG,GAAG,GAAG,SAAS,CAAC;QAC9B,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,cAAc,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ export declare const MultiversXDecimalsLimitReached: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
2
+ [key: string]: unknown;
3
+ }>;
4
+ export declare const MultiversXMinDelegatedAmountError: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
5
+ [key: string]: unknown;
6
+ }>;
7
+ export declare const MultiversXMinUndelegatedAmountError: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
8
+ [key: string]: unknown;
9
+ }>;
10
+ export declare const MultiversXDelegationBelowMinimumError: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
11
+ [key: string]: unknown;
12
+ }>;
13
+ export declare const NotEnoughEGLDForFees: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
14
+ [key: string]: unknown;
15
+ }>;
16
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,8BAA8B;;EAE1C,CAAC;AAEF,eAAO,MAAM,iCAAiC;;EAE7C,CAAC;AAEF,eAAO,MAAM,mCAAmC;;EAE/C,CAAC;AAEF,eAAO,MAAM,qCAAqC;;EAEjD,CAAC;AAEF,eAAO,MAAM,oBAAoB;;EAAiD,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { createCustomErrorClass } from "@ledgerhq/errors";
2
+ export const MultiversXDecimalsLimitReached = createCustomErrorClass("MultiversXDecimalsLimitReached");
3
+ export const MultiversXMinDelegatedAmountError = createCustomErrorClass("MultiversXMinDelegatedAmountError");
4
+ export const MultiversXMinUndelegatedAmountError = createCustomErrorClass("MultiversXMinUndelegatedAmountError");
5
+ export const MultiversXDelegationBelowMinimumError = createCustomErrorClass("MultiversXDelegationBelowMinimumError");
6
+ export const NotEnoughEGLDForFees = createCustomErrorClass("NotEnoughEGLDForFees");
7
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,CAAC,MAAM,8BAA8B,GAAG,sBAAsB,CAClE,gCAAgC,CACjC,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAG,sBAAsB,CACrE,mCAAmC,CACpC,CAAC;AAEF,MAAM,CAAC,MAAM,mCAAmC,GAAG,sBAAsB,CACvE,qCAAqC,CACtC,CAAC;AAEF,MAAM,CAAC,MAAM,qCAAqC,GAAG,sBAAsB,CACzE,uCAAuC,CACxC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { AccountBridge } from "@ledgerhq/types-live";
2
+ import type { Transaction } from "./types";
3
+ /**
4
+ * Returns the maximum possible amount for transaction
5
+ *
6
+ * @param {Object} param - the account, parentAccount and transaction
7
+ */
8
+ export declare const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"];
9
+ export default estimateMaxSpendable;
10
+ //# sourceMappingURL=estimateMaxSpendable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../src/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI3C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,sBAAsB,CA4BnF,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import { findSubAccountById, getMainAccount } from "@ledgerhq/coin-framework/account";
3
+ import { getFees } from "./api";
4
+ import { createTransaction } from "./createTransaction";
5
+ /**
6
+ * Returns the maximum possible amount for transaction
7
+ *
8
+ * @param {Object} param - the account, parentAccount and transaction
9
+ */
10
+ export const estimateMaxSpendable = async ({ account, parentAccount, transaction, }) => {
11
+ const mainAccount = getMainAccount(account, parentAccount);
12
+ const tx = {
13
+ ...createTransaction(account),
14
+ subAccountId: account.type === "Account" ? null : account.id,
15
+ ...transaction,
16
+ useAllAmount: true,
17
+ };
18
+ const tokenAccount = tx.subAccountId
19
+ ? findSubAccountById(mainAccount, tx.subAccountId)
20
+ : undefined;
21
+ if (tokenAccount) {
22
+ return tokenAccount.balance;
23
+ }
24
+ const fees = await getFees(tx);
25
+ if (fees.gt(mainAccount.spendableBalance)) {
26
+ return new BigNumber(0);
27
+ }
28
+ return mainAccount.spendableBalance.minus(fees);
29
+ };
30
+ export default estimateMaxSpendable;
31
+ //# sourceMappingURL=estimateMaxSpendable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../src/estimateMaxSpendable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE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versXAccount } from "./types";
4
+ declare function formatAccountSpecifics(account: MultiversXAccount): string;
5
+ declare function formatOperationSpecifics(op: Operation, unit: Unit | null | undefined): string;
6
+ declare const _default: {
7
+ formatAccountSpecifics: typeof formatAccountSpecifics;
8
+ formatOperationSpecifics: typeof formatOperationSpecifics;
9
+ };
10
+ export default _default;
11
+ //# sourceMappingURL=formatters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,SAAS,CAAC;AAGtE,iBAAS,sBAAsB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CA+ClE;AAED,iBAAS,wBAAwB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAatF;;;;;AAED,wBAGE"}
@@ -0,0 +1,60 @@
1
+ import invariant from "invariant";
2
+ import { getAccountCurrency } from "@ledgerhq/coin-framework/account";
3
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
4
+ import BigNumber from "bignumber.js";
5
+ function formatAccountSpecifics(account) {
6
+ const { multiversxResources } = account;
7
+ invariant(multiversxResources, "multiversx account expected");
8
+ const unit = getAccountCurrency(account).units[0];
9
+ const formatConfig = {
10
+ disableRounding: true,
11
+ alwaysShowSign: false,
12
+ showCode: true,
13
+ };
14
+ let str = " ";
15
+ if (account.spendableBalance) {
16
+ str += formatCurrencyUnit(unit, account.spendableBalance, formatConfig) + " spendable. ";
17
+ }
18
+ else {
19
+ str += " 0 spendable.";
20
+ }
21
+ if (multiversxResources && multiversxResources.nonce) {
22
+ str += "\n nonce : " + multiversxResources.nonce;
23
+ }
24
+ if (multiversxResources && multiversxResources.delegations) {
25
+ let delegated = new BigNumber(0);
26
+ let undelegating = new BigNumber(0);
27
+ let rewards = new BigNumber(0);
28
+ for (const delegation of multiversxResources.delegations) {
29
+ delegated = delegated.plus(delegation.userActiveStake);
30
+ undelegating = delegation.userUndelegatedList.reduce((sum, undelegation) => sum.plus(undelegation.amount), undelegating);
31
+ rewards = rewards.plus(delegation.claimableRewards);
32
+ }
33
+ str +=
34
+ delegated && delegated.gt(0)
35
+ ? `\n delegated: ${unit ? formatCurrencyUnit(unit, delegated, formatConfig) : delegated}`
36
+ : undelegating && undelegating.gt(0)
37
+ ? `\n undelegating: ${unit ? formatCurrencyUnit(unit, undelegating, formatConfig) : undelegating}`
38
+ : rewards && rewards.gt(0)
39
+ ? `\n rewards: ${unit ? formatCurrencyUnit(unit, rewards, formatConfig) : rewards}`
40
+ : "";
41
+ }
42
+ return str;
43
+ }
44
+ function formatOperationSpecifics(op, unit) {
45
+ const { amount } = op.extra;
46
+ return amount?.gt && amount.gt(0)
47
+ ? " amount: " +
48
+ `${unit
49
+ ? formatCurrencyUnit(unit, new BigNumber(amount), {
50
+ showCode: true,
51
+ disableRounding: true,
52
+ }).padEnd(16)
53
+ : amount}`
54
+ : "";
55
+ }
56
+ export default {
57
+ formatAccountSpecifics,
58
+ formatOperationSpecifics,
59
+ };
60
+ //# sourceMappingURL=formatters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatters.js","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,SAAS,sBAAsB,CAAC,OAA0B;IACxD,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IACxC,SAAS,CAAC,mBAAmB,EAAE,6BAA6B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2
+ import { AccountBridge } from "@ledgerhq/types-live";
3
+ export declare const getTransactionStatus: AccountBridge<Transaction, MultiversXAccount, TransactionStatus>["getTransactionStatus"];
4
+ export default getTransactionStatus;
5
+ //# sourceMappingURL=getTransactionStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../src/getTransactionStatus.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AASjF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAC9C,WAAW,EACX,iBAAiB,EACjB,iBAAiB,CAClB,CAAC,sBAAsB,CAwHvB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,100 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { NotEnoughBalance, RecipientRequired, InvalidAddress, FeeNotLoaded, InvalidAddressBecauseDestinationIsAlsoSource, FeeTooHigh, AmountRequired, } from "@ledgerhq/errors";
3
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
4
+ import { getAccountCurrency } from "@ledgerhq/coin-framework/account";
5
+ import { DECIMALS_LIMIT, MIN_DELEGATION_AMOUNT } from "./constants";
6
+ import { isValidAddress, isSelfTransaction, isAmountSpentFromBalance } from "./logic";
7
+ import { MultiversXDecimalsLimitReached, MultiversXMinDelegatedAmountError, MultiversXMinUndelegatedAmountError, MultiversXDelegationBelowMinimumError, NotEnoughEGLDForFees, } from "./errors";
8
+ export const getTransactionStatus = async (account, transaction) => {
9
+ const errors = {};
10
+ const warnings = {};
11
+ if (!transaction.recipient) {
12
+ errors.recipient = new RecipientRequired();
13
+ }
14
+ else if (isSelfTransaction(account, transaction)) {
15
+ errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
16
+ }
17
+ else if (!isValidAddress(transaction.recipient)) {
18
+ errors.recipient = new InvalidAddress("", {
19
+ currencyName: account.currency.name,
20
+ });
21
+ }
22
+ if (!transaction.fees) {
23
+ errors.fees = new FeeNotLoaded();
24
+ }
25
+ if (!errors.amount &&
26
+ transaction.amount.eq(0) &&
27
+ !transaction.useAllAmount &&
28
+ !["unDelegate", "withdraw", "reDelegateRewards", "claimRewards"].includes(transaction.mode)) {
29
+ errors.amount = new AmountRequired();
30
+ }
31
+ let totalSpent = new BigNumber(0); // Will be in token amount for token transactions
32
+ let totalSpentEgld = new BigNumber(0); // Amount spent in main currency (EGLD)
33
+ const tokenAccount = (transaction.subAccountId &&
34
+ account.subAccounts &&
35
+ account.subAccounts.find(ta => ta.id === transaction.subAccountId)) ||
36
+ null;
37
+ if (tokenAccount) {
38
+ totalSpent = transaction.amount;
39
+ totalSpentEgld = transaction.fees || new BigNumber(0);
40
+ if (!errors.amount && transaction.amount.gt(tokenAccount.balance)) {
41
+ errors.amount = new NotEnoughBalance();
42
+ }
43
+ if (!errors.amount && !totalSpentEgld.decimalPlaces(DECIMALS_LIMIT).isEqualTo(totalSpentEgld)) {
44
+ errors.amount = new MultiversXDecimalsLimitReached();
45
+ }
46
+ }
47
+ else {
48
+ totalSpent = totalSpentEgld = isAmountSpentFromBalance(transaction.mode)
49
+ ? transaction.fees?.plus(transaction.amount) || transaction.amount
50
+ : transaction.fees || new BigNumber(0);
51
+ if (transaction.mode === "send" &&
52
+ transaction.fees &&
53
+ transaction.amount.div(10).lt(transaction.fees)) {
54
+ warnings.feeTooHigh = new FeeTooHigh();
55
+ }
56
+ // All delegate and undelegate transactions must have an amount >= 1 EGLD
57
+ if (!errors.amount && transaction.amount.lt(MIN_DELEGATION_AMOUNT)) {
58
+ const formattedAmount = formatCurrencyUnit(getAccountCurrency(account).units[0], MIN_DELEGATION_AMOUNT, {
59
+ showCode: true,
60
+ });
61
+ if (transaction.mode === "delegate") {
62
+ errors.amount = new MultiversXMinDelegatedAmountError("", {
63
+ formattedAmount,
64
+ });
65
+ }
66
+ else if (transaction.mode === "unDelegate") {
67
+ errors.amount = new MultiversXMinUndelegatedAmountError("", {
68
+ formattedAmount,
69
+ });
70
+ }
71
+ }
72
+ // When undelegating, unless undelegating all, the delegation must remain >= 1 EGLD
73
+ const delegationBalance = account.multiversxResources.delegations.find(d => d.contract === transaction.recipient)?.userActiveStake;
74
+ const delegationRemainingBalance = new BigNumber(delegationBalance || 0).minus(transaction.amount);
75
+ const delegationBalanceForbidden = delegationRemainingBalance.gt(0) && delegationRemainingBalance.lt(MIN_DELEGATION_AMOUNT);
76
+ if (!errors.amount && transaction.mode === "unDelegate" && delegationBalanceForbidden) {
77
+ const formattedAmount = formatCurrencyUnit(getAccountCurrency(account).units[0], MIN_DELEGATION_AMOUNT, {
78
+ showCode: true,
79
+ });
80
+ errors.amount = new MultiversXDelegationBelowMinimumError("", {
81
+ formattedAmount,
82
+ });
83
+ }
84
+ }
85
+ if (!errors.amount && totalSpentEgld.gt(account.spendableBalance)) {
86
+ errors.amount =
87
+ tokenAccount || !["delegate", "send"].includes(transaction.mode)
88
+ ? new NotEnoughEGLDForFees()
89
+ : new NotEnoughBalance();
90
+ }
91
+ return {
92
+ errors,
93
+ warnings,
94
+ estimatedFees: transaction.fees || new BigNumber(0),
95
+ amount: transaction.amount,
96
+ totalSpent,
97
+ };
98
+ };
99
+ export default getTransactionStatus;
100
+ //# sourceMappingURL=getTransactionStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../src/getTransactionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,4CAA4C,EAC5C,UAAU,EACV,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC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AC,qBAAqB,CAAC,CAAC;QAE3F,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,WAAW,CAAC,IAAI,KAAK,YAAY,IAAI,0BAA0B,EAAE,CAAC;YACtF,MAAM,eAAe,GAAG,kBAAkB,CACxC,kBAAkB,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EACpC,qBAAqB,EACrB;gBACE,QAAQ,EAAE,IAAI;aACf,CACF,CAAC;YACF,MAAM,CAAC,MAAM,GAAG,IAAI,qCAAqC,CAAC,EAAE,EAAE;gBAC5D,eAAe;aAChB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,cAAc,CAAC,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAClE,MAAM,CAAC,MAAM;YACX,YAAY,IAAI,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC;gBAC9D,CAAC,CAAC,IAAI,oBAAoB,EAAE;gBAC5B,CAAC,CAAC,IAAI,gBAAgB,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO;QACL,MAAM;QACN,QAAQ;QACR,aAAa,EAAE,WAAW,CAAC,IAAI,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC;QACnD,MAAM,EAAE,WAAW,CAAC,MAAM;QAC1B,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,9 @@
1
+ export interface DenominateType {
2
+ input: string;
3
+ denomination?: number;
4
+ decimals?: number;
5
+ showLastNonZeroDecimal?: boolean;
6
+ addCommas?: boolean;
7
+ }
8
+ export declare const denominate: (parameters: DenominateType) => string;
9
+ //# sourceMappingURL=denominate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"denominate.d.ts","sourceRoot":"","sources":["../../src/helpers/denominate.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAMD,eAAO,MAAM,UAAU,eAAgB,cAAc,WA8EpD,CAAC"}
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Declare the type of the denomination function's parameters.
3
+ */
4
+ /*
5
+ * Declare function itself and return the denominated value as a string.
6
+ */
7
+ export const denominate = (parameters) => {
8
+ const { denomination, decimals, showLastNonZeroDecimal = false, addCommas = true } = parameters;
9
+ let { input } = parameters;
10
+ if (input === "...") {
11
+ return input;
12
+ }
13
+ if (input === "" || input === "0" || input === undefined) {
14
+ input = "0";
15
+ }
16
+ const format = (big, denomination = 18, decimals = 2, showLastNonZeroDecimal, addCommas) => {
17
+ const showLastNonZeroDecimalCheck = typeof showLastNonZeroDecimal !== "undefined" ? showLastNonZeroDecimal : false;
18
+ let array = big.toString().split("");
19
+ if (denomination !== 0) {
20
+ // make sure we have enough characters
21
+ while (array.length < denomination + 1) {
22
+ array.unshift("0");
23
+ }
24
+ // add our dot
25
+ array.splice(array.length - denomination, 0, ".");
26
+ // make sure there are enough decimals after the dot
27
+ while (array.length - array.indexOf(".") <= decimals) {
28
+ array.push("0");
29
+ }
30
+ if (showLastNonZeroDecimalCheck) {
31
+ let nonZeroDigitIndex = 0;
32
+ for (let i = array.length - 1; i > 0; i--) {
33
+ if (array[i] !== "0") {
34
+ nonZeroDigitIndex = i + 1;
35
+ break;
36
+ }
37
+ }
38
+ const decimalsIndex = array.indexOf(".") + decimals + 1;
39
+ const sliceIndex = Math.max(decimalsIndex, nonZeroDigitIndex);
40
+ array = array.slice(0, sliceIndex);
41
+ }
42
+ else {
43
+ // trim unnecessary characters after the dot
44
+ array = array.slice(0, array.indexOf(".") + decimals + 1);
45
+ }
46
+ }
47
+ if (addCommas) {
48
+ // add comas every 3 characters
49
+ array = array.reverse();
50
+ const reference = denomination ? array.length - array.indexOf(".") - 1 : array.length;
51
+ const count = Math.floor(reference / 3);
52
+ for (let i = 1; i <= count; i++) {
53
+ const position = array.indexOf(".") + 3 * i + i;
54
+ if (position !== array.length) {
55
+ array.splice(position, 0, ",");
56
+ }
57
+ }
58
+ array = array.reverse();
59
+ }
60
+ const allDecimalsZero = array
61
+ .slice(array.indexOf(".") + 1)
62
+ .every(digit => digit.toString() === "0");
63
+ const string = array.join("");
64
+ if (allDecimalsZero) {
65
+ return string.split(".")[0];
66
+ }
67
+ return decimals === 0 ? string.split(".").join("") : string;
68
+ };
69
+ return format(input, denomination, decimals, showLastNonZeroDecimal, addCommas);
70
+ };
71
+ //# sourceMappingURL=denominate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"denominate.js","sourceRoot":"","sources":["../../src/helpers/denominate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH;;GAEG;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,UAA0B,EAAE,EAAE;IACvD,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,sBAAsB,GAAG,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,UAAU,CAAC;IAChG,IAAI,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC;IAE3B,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzD,KAAK,GAAG,GAAG,CAAC;IACd,CAAC;IAED,MAAM,MAAM,GAAG,CACb,GAAW,EACX,YAAY,GAAG,EAAE,EACjB,QAAQ,GAAG,CAAC,EACZ,sBAA+B,EAC/B,SAAkB,EAClB,EAAE;QACF,MAAM,2BAA2B,GAC/B,OAAO,sBAAsB,KAAK,WAAW,CAAC,CAAC,CAAC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AAC,CAAC;QAC9B,CAAC;QAED,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAC;AAClF,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { TransactionStatus } from "../types";
2
+ export interface handleTransactionStatusType {
3
+ warning: Error | false;
4
+ error: Error | false;
5
+ }
6
+ export declare const handleTransactionStatus: (status: TransactionStatus) => handleTransactionStatusType;
7
+ //# sourceMappingURL=handleTransactionStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleTransactionStatus.d.ts","sourceRoot":"","sources":["../../src/helpers/handleTransactionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAMlD,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC;CACtB;AAMD,eAAO,MAAM,uBAAuB,WAAY,iBAAiB,KAAG,2BAUnE,CAAC"}
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Return an object, of the function, with the error and warning keys, as boolean values.
3
+ */
4
+ export const handleTransactionStatus = (status) => {
5
+ const [[warning], [error]] = [
6
+ Object.keys(status.warnings || {}),
7
+ Object.keys(status.errors || {}),
8
+ ];
9
+ return {
10
+ warning: status.warnings[warning],
11
+ error: status.errors[error],
12
+ };
13
+ };
14
+ //# sourceMappingURL=handleTransactionStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleTransactionStatus.js","sourceRoot":"","sources":["../../src/helpers/handleTransactionStatus.ts"],"names":[],"mappings":"AAWA;;GAEG;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAyB,EAA+B,EAAE;IAChG,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG;QAC3B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;KACjC,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QACjC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;KAC5B,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Account } from "@ledgerhq/types-live";
2
+ export declare const hasMinimumDelegableBalance: (account: Account) => boolean;
3
+ //# sourceMappingURL=hasMinimumDelegableBalance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasMinimumDelegableBalance.d.ts","sourceRoot":"","sources":["../../src/helpers/hasMinimumDelegableBalance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAI/C,eAAO,MAAM,0BAA0B,YAAa,OAAO,YACa,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { MIN_DELEGATION_AMOUNT } from "../constants";
2
+ export const hasMinimumDelegableBalance = (account) => account.spendableBalance.isGreaterThanOrEqualTo(MIN_DELEGATION_AMOUNT);
3
+ //# sourceMappingURL=hasMinimumDelegableBalance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasMinimumDelegableBalance.js","sourceRoot":"","sources":["../../src/helpers/hasMinimumDelegableBalance.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,OAAgB,EAAE,EAAE,CAC7D,OAAO,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { MultiversXProvider } from "../types";
2
+ export interface SortedValidatorType {
3
+ provider: MultiversXProvider;
4
+ sort: number;
5
+ }
6
+ export declare const randomizeProviders: (providers: MultiversXProvider[]) => MultiversXProvider[];
7
+ //# sourceMappingURL=randomizeProviders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"randomizeProviders.d.ts","sourceRoot":"","sources":["../../src/helpers/randomizeProviders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMnD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAMD,eAAO,MAAM,kBAAkB,cAAe,kBAAkB,EAAE,yBAIZ,CAAC"}
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Map through the providers, assign a random number, sort by that, then return the original providers' list.
3
+ */
4
+ export const randomizeProviders = (providers) => providers
5
+ .map(provider => ({ provider, sort: Math.random() }))
6
+ .sort((alpha, beta) => alpha.sort - beta.sort)
7
+ .map((item) => item.provider);
8
+ //# sourceMappingURL=randomizeProviders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"randomizeProviders.js","sourceRoot":"","sources":["../../src/helpers/randomizeProviders.ts"],"names":[],"mappings":"AAWA;;GAEG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,SAA+B,EAAE,EAAE,CACpE,SAAS;KACN,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;KACpD,IAAI,CAAC,CAAC,KAA0B,EAAE,IAAyB,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;KACvF,GAAG,CAAC,CAAC,IAAyB,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
2
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
3
+ import { MultiversXSigner } from "./signer";
4
+ declare const resolver: (signerContext: SignerContext<MultiversXSigner>) => GetAddressFn;
5
+ export default resolver;
6
+ //# sourceMappingURL=hw-getAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hw-getAddress.d.ts","sourceRoot":"","sources":["../src/hw-getAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mDAAmD,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,QAAA,MAAM,QAAQ,kBAAmB,cAAc,gBAAgB,CAAC,KAAG,YAWlE,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,12 @@
1
+ const resolver = (signerContext) => {
2
+ return async (deviceId, { path, verify }) => {
3
+ const { address, publicKey } = await signerContext(deviceId, signer => signer.getAddress(path, verify || false));
4
+ return {
5
+ address: address,
6
+ publicKey: publicKey,
7
+ path,
8
+ };
9
+ };
10
+ };
11
+ export default resolver;
12
+ //# sourceMappingURL=hw-getAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hw-getAddress.js","sourceRoot":"","sources":["../src/hw-getAddress.ts"],"names":[],"mappings":"AAKA,MAAM,QAAQ,GAAG,CAAC,aAA8C,EAAgB,EAAE;IAChF,OAAO,KAAK,EAAE,QAAgB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAqB,EAAE,EAAE;QACrE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CACpE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK,CAAC,CACzC,CAAC;QACF,OAAO;YACL,OAAO,EAAE,OAAO;YAChB,SAAS,EAAE,SAAS;YACpB,IAAI;SACL,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}