@rabbitio/ui-kit 1.0.0-beta.9 → 1.0.0-beta.91

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 (369) hide show
  1. package/.gitlab-ci.yml +29 -0
  2. package/.husky/commit-msg +19 -0
  3. package/.husky/pre-push +1 -0
  4. package/CHANGELOG.md +0 -0
  5. package/README.md +27 -18
  6. package/coverage/base.css +224 -0
  7. package/coverage/block-navigation.js +87 -0
  8. package/coverage/clover.xml +16765 -0
  9. package/coverage/coverage-final.json +116 -0
  10. package/coverage/favicon.png +0 -0
  11. package/coverage/index.html +1001 -0
  12. package/coverage/prettify.css +1 -0
  13. package/coverage/prettify.js +2 -0
  14. package/coverage/rabbit-ui-kit/index.html +116 -0
  15. package/coverage/rabbit-ui-kit/index.js.html +88 -0
  16. package/coverage/rabbit-ui-kit/src/common-apis/adapters/analyticsAdapters/googleAnalyticsAdapter.js.html +148 -0
  17. package/coverage/rabbit-ui-kit/src/common-apis/adapters/analyticsAdapters/index.html +146 -0
  18. package/coverage/rabbit-ui-kit/src/common-apis/adapters/analyticsAdapters/metrikaAdapter.js.html +169 -0
  19. package/coverage/rabbit-ui-kit/src/common-apis/adapters/analyticsAdapters/mixpanelAdapter.js.html +199 -0
  20. package/coverage/rabbit-ui-kit/src/common-apis/adapters/axiosAdapter.js.html +190 -0
  21. package/coverage/rabbit-ui-kit/src/common-apis/adapters/index.html +131 -0
  22. package/coverage/rabbit-ui-kit/src/common-apis/adapters/qrUtils.js.html +139 -0
  23. package/coverage/rabbit-ui-kit/src/common-apis/external-apis/apiGroups.js.html +250 -0
  24. package/coverage/rabbit-ui-kit/src/common-apis/external-apis/emailAPI.js.html +133 -0
  25. package/coverage/rabbit-ui-kit/src/common-apis/external-apis/index.html +146 -0
  26. package/coverage/rabbit-ui-kit/src/common-apis/external-apis/ipAddressProviders.js.html +352 -0
  27. package/coverage/rabbit-ui-kit/src/common-apis/globalConstants.jsx.html +94 -0
  28. package/coverage/rabbit-ui-kit/src/common-apis/index.html +116 -0
  29. package/coverage/rabbit-ui-kit/src/common-apis/models/blockchain.js.html +115 -0
  30. package/coverage/rabbit-ui-kit/src/common-apis/models/coin.js.html +829 -0
  31. package/coverage/rabbit-ui-kit/src/common-apis/models/index.html +146 -0
  32. package/coverage/rabbit-ui-kit/src/common-apis/models/protocol.js.html +100 -0
  33. package/coverage/rabbit-ui-kit/src/common-apis/services/fiatCurrenciesService.js.html +544 -0
  34. package/coverage/rabbit-ui-kit/src/common-apis/services/index.html +116 -0
  35. package/coverage/rabbit-ui-kit/src/common-apis/utils/amountUtils.js.html +1162 -0
  36. package/coverage/rabbit-ui-kit/src/common-apis/utils/cache.js.html +811 -0
  37. package/coverage/rabbit-ui-kit/src/common-apis/utils/errorUtils.js.html +211 -0
  38. package/coverage/rabbit-ui-kit/src/common-apis/utils/index.html +191 -0
  39. package/coverage/rabbit-ui-kit/src/common-apis/utils/logging/index.html +131 -0
  40. package/coverage/rabbit-ui-kit/src/common-apis/utils/logging/logger.js.html +208 -0
  41. package/coverage/rabbit-ui-kit/src/common-apis/utils/logging/logsStorage.js.html +268 -0
  42. package/coverage/rabbit-ui-kit/src/common-apis/utils/postponeExecution.js.html +118 -0
  43. package/coverage/rabbit-ui-kit/src/common-apis/utils/rabbitTicker.js.html +157 -0
  44. package/coverage/rabbit-ui-kit/src/common-apis/utils/safeStringify.js.html +235 -0
  45. package/coverage/rabbit-ui-kit/src/index.html +116 -0
  46. package/coverage/rabbit-ui-kit/src/index.js.html +376 -0
  47. package/coverage/rabbit-ui-kit/src/robust-api-caller/cacheAndConcurrentRequestsResolver.js.html +1570 -0
  48. package/coverage/rabbit-ui-kit/src/robust-api-caller/cachedRobustExternalApiCallerService.js.html +526 -0
  49. package/coverage/rabbit-ui-kit/src/robust-api-caller/cancelProcessing.js.html +172 -0
  50. package/coverage/rabbit-ui-kit/src/robust-api-caller/concurrentCalculationsMetadataHolder.js.html +310 -0
  51. package/coverage/rabbit-ui-kit/src/robust-api-caller/externalApiProvider.js.html +553 -0
  52. package/coverage/rabbit-ui-kit/src/robust-api-caller/externalServicesStatsCollector.js.html +319 -0
  53. package/coverage/rabbit-ui-kit/src/robust-api-caller/index.html +206 -0
  54. package/coverage/rabbit-ui-kit/src/robust-api-caller/robustExternalAPICallerService.js.html +997 -0
  55. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/exolixSwapProvider.js.html +1825 -0
  56. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/index.html +161 -0
  57. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/letsExchangeSwapProvider.js.html +1618 -0
  58. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapProvider.js.html +1819 -0
  59. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapspaceSwapProvider.js.html +1861 -0
  60. package/coverage/rabbit-ui-kit/src/swaps-lib/models/baseSwapCreationInfo.js.html +319 -0
  61. package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwap.js.html +514 -0
  62. package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwapWithFiatData.js.html +529 -0
  63. package/coverage/rabbit-ui-kit/src/swaps-lib/models/index.html +176 -0
  64. package/coverage/rabbit-ui-kit/src/swaps-lib/models/partner.js.html +166 -0
  65. package/coverage/rabbit-ui-kit/src/swaps-lib/models/swapProviderCoinInfo.js.html +331 -0
  66. package/coverage/rabbit-ui-kit/src/swaps-lib/services/index.html +116 -0
  67. package/coverage/rabbit-ui-kit/src/swaps-lib/services/publicSwapService.js.html +1555 -0
  68. package/coverage/rabbit-ui-kit/src/swaps-lib/utils/index.html +116 -0
  69. package/coverage/rabbit-ui-kit/src/swaps-lib/utils/swapUtils.js.html +670 -0
  70. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/arrowIcon.jsx.html +124 -0
  71. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/arrowTosca.jsx.html +127 -0
  72. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/arrowWhite.jsx.html +127 -0
  73. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/darkRectangle.jsx.html +106 -0
  74. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/determinedError.jsx.html +439 -0
  75. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/failedValidationIcon.jsx.html +202 -0
  76. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/index.html +281 -0
  77. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/infoIcon.jsx.html +133 -0
  78. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/messageIcon.jsx.html +346 -0
  79. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/noticeQuestionIcon.jsx.html +247 -0
  80. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/successfulValidationIcon.jsx.html +163 -0
  81. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/supportDialogImage.jsx.html +268 -0
  82. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/walletIcon.jsx.html +151 -0
  83. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetIcon/AssetIcon.jsx.html +256 -0
  84. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetIcon/index.html +116 -0
  85. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetSelection/AssetSelection.jsx.html +289 -0
  86. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetSelection/index.html +116 -0
  87. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/BackgroundTitle/BackgroundTitle.jsx.html +187 -0
  88. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/BackgroundTitle/index.html +116 -0
  89. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/InformationMessage/InformationMessage.jsx.html +238 -0
  90. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/InformationMessage/index.html +116 -0
  91. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Input/Input.jsx.html +634 -0
  92. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Input/index.html +116 -0
  93. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/LoadingDots/LoadingDots.jsx.html +196 -0
  94. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/LoadingDots/index.html +116 -0
  95. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/NoticeIcon/NoticeIcon.jsx.html +277 -0
  96. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/NoticeIcon/index.html +116 -0
  97. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/QrCode/QrCode.jsx.html +217 -0
  98. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/QrCode/index.html +116 -0
  99. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/RateSelector/RateSelector.jsx.html +175 -0
  100. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/RateSelector/index.html +116 -0
  101. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/SupportChat/SupportChat.jsx.html +217 -0
  102. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/SupportChat/index.html +116 -0
  103. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Textarea/Textarea.jsx.html +529 -0
  104. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Textarea/index.html +116 -0
  105. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TitleBox/TitleBox.jsx.html +508 -0
  106. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TitleBox/index.html +116 -0
  107. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Tooltip/Tooltip.jsx.html +316 -0
  108. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Tooltip/index.html +116 -0
  109. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TwoLinesOfText/LinesOfText.jsx.html +313 -0
  110. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TwoLinesOfText/index.html +116 -0
  111. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Validation/Validation.jsx.html +202 -0
  112. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Validation/index.html +116 -0
  113. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Button/Button.jsx.html +712 -0
  114. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Button/index.html +116 -0
  115. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Close/Close.jsx.html +259 -0
  116. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Close/index.html +116 -0
  117. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/LinkButton/LinkButton.jsx.html +421 -0
  118. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/LinkButton/index.html +116 -0
  119. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/RadioButtonWithText/RadioButtonWithText.jsx.html +415 -0
  120. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/RadioButtonWithText/index.html +116 -0
  121. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/AmountInput/AmountInput.jsx.html +1429 -0
  122. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/AmountInput/index.html +116 -0
  123. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/CoinPicker/CoinPicker.jsx.html +1474 -0
  124. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/CoinPicker/index.html +116 -0
  125. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/ColoredNotice/ColoredNotice.jsx.html +211 -0
  126. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/ColoredNotice/index.html +116 -0
  127. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LineWithIconLink/LineWithIconLink.jsx.html +190 -0
  128. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LineWithIconLink/index.html +116 -0
  129. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LogoCarousel/LogoCarousel.jsx.html +307 -0
  130. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LogoCarousel/index.html +116 -0
  131. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/SearchableCoinsList/SearchableCoinsList.jsx.html +496 -0
  132. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/SearchableCoinsList/index.html +116 -0
  133. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/TitledLineWithIconLink/TitledLineWithIconLink.jsx.html +181 -0
  134. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/TitledLineWithIconLink/index.html +116 -0
  135. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/CoinPickerDialogStep/CoinPickerDialogStep.jsx.html +283 -0
  136. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/CoinPickerDialogStep/index.html +116 -0
  137. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/Dialog.jsx.html +1567 -0
  138. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogButtons/DialogButtons.jsx.html +481 -0
  139. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogButtons/index.html +116 -0
  140. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogStep/DialogStep.jsx.html +1747 -0
  141. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogStep/index.html +116 -0
  142. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/index.html +116 -0
  143. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/SwapForm/SwapForm.jsx.html +4207 -0
  144. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/SwapForm/index.html +116 -0
  145. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/WaitlistSubscription/WaitlistSubscription.jsx.html +559 -0
  146. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/WaitlistSubscription/index.html +116 -0
  147. package/coverage/rabbit-ui-kit/src/ui-kit/components/templates/DeterminedErrorDialogStep/DeterminedErrorDialogStep.jsx.html +316 -0
  148. package/coverage/rabbit-ui-kit/src/ui-kit/components/templates/DeterminedErrorDialogStep/index.html +116 -0
  149. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/index.html +146 -0
  150. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/useCallHandlingErrors.js.html +151 -0
  151. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/useIsHydrated.js.html +121 -0
  152. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/useReferredState.js.html +157 -0
  153. package/coverage/rabbit-ui-kit/src/ui-kit/utils/index.html +161 -0
  154. package/coverage/rabbit-ui-kit/src/ui-kit/utils/inputValueProviders.js.html +235 -0
  155. package/coverage/rabbit-ui-kit/src/ui-kit/utils/textUtils.js.html +139 -0
  156. package/coverage/rabbit-ui-kit/src/ui-kit/utils/uiUtils.js.html +121 -0
  157. package/coverage/rabbit-ui-kit/src/ui-kit/utils/urlQueryUtils.js.html +271 -0
  158. package/coverage/rabbit-ui-kit/stories/atoms/BackgroundTitle.stories.jsx.html +202 -0
  159. package/coverage/rabbit-ui-kit/stories/atoms/LinesOfText.stories.jsx.html +283 -0
  160. package/coverage/rabbit-ui-kit/stories/atoms/LoadingDots.stories.jsx.html +226 -0
  161. package/coverage/rabbit-ui-kit/stories/atoms/QrCode.stories.jsx.html +175 -0
  162. package/coverage/rabbit-ui-kit/stories/atoms/RateSelector.stories.jsx.html +136 -0
  163. package/coverage/rabbit-ui-kit/stories/atoms/Validation.stories.jsx.html +178 -0
  164. package/coverage/rabbit-ui-kit/stories/atoms/buttons/Button.stories.jsx.html +883 -0
  165. package/coverage/rabbit-ui-kit/stories/atoms/buttons/Close.stories.jsx.html +211 -0
  166. package/coverage/rabbit-ui-kit/stories/atoms/buttons/LinkButton.stories.jsx.html +301 -0
  167. package/coverage/rabbit-ui-kit/stories/atoms/buttons/index.html +146 -0
  168. package/coverage/rabbit-ui-kit/stories/atoms/index.html +191 -0
  169. package/coverage/rabbit-ui-kit/stories/molecules/AmountInput.stories.jsx.html +289 -0
  170. package/coverage/rabbit-ui-kit/stories/molecules/CoinPicker.stories.jsx.html +322 -0
  171. package/coverage/rabbit-ui-kit/stories/molecules/ColoredNotice.stories.jsx.html +178 -0
  172. package/coverage/rabbit-ui-kit/stories/molecules/LineWithIconLink.stories.jsx.html +154 -0
  173. package/coverage/rabbit-ui-kit/stories/molecules/LogoCarousel.stories.jsx.html +235 -0
  174. package/coverage/rabbit-ui-kit/stories/molecules/TitledLineWithIconLink.stories.jsx.html +160 -0
  175. package/coverage/rabbit-ui-kit/stories/molecules/index.html +191 -0
  176. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/Dialog.stories.jsx.html +523 -0
  177. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/DialogButtons.stories.jsx.html +328 -0
  178. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/index.html +116 -0
  179. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/DialogStep.stories.jsx.html +337 -0
  180. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/index.html +116 -0
  181. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/index.html +116 -0
  182. package/coverage/rabbit-ui-kit/stories/organisms/WaitlistSubscription.stories.jsx.html +151 -0
  183. package/coverage/rabbit-ui-kit/stories/organisms/index.html +116 -0
  184. package/coverage/rabbit-ui-kit/stories/stubs/coins.jsx.html +6880 -0
  185. package/coverage/rabbit-ui-kit/stories/stubs/exampleContent.jsx.html +145 -0
  186. package/coverage/rabbit-ui-kit/stories/stubs/index.html +131 -0
  187. package/coverage/rabbit-ui-kit/stories/templates/DeterminedErrorDialogStep.stories.jsx.html +190 -0
  188. package/coverage/rabbit-ui-kit/stories/templates/index.html +116 -0
  189. package/coverage/sort-arrow-sprite.png +0 -0
  190. package/coverage/sorter.js +196 -0
  191. package/dist/global.css +197 -0
  192. package/dist/global.css.map +1 -0
  193. package/dist/index.cjs +12451 -25
  194. package/dist/index.cjs.map +1 -1
  195. package/dist/index.css +2339 -8491
  196. package/dist/index.css.map +1 -1
  197. package/dist/index.modern.js +9597 -26
  198. package/dist/index.modern.js.map +1 -1
  199. package/dist/index.module.js +12357 -27
  200. package/dist/index.module.js.map +1 -1
  201. package/dist/index.umd.js +12442 -29
  202. package/dist/index.umd.js.map +1 -1
  203. package/package.json +35 -9
  204. package/raw +1000 -0
  205. package/src/common-apis/adapters/analyticsAdapters/googleAnalyticsAdapter.js +21 -0
  206. package/src/common-apis/adapters/analyticsAdapters/metrikaAdapter.js +28 -0
  207. package/src/common-apis/adapters/analyticsAdapters/mixpanelAdapter.js +38 -0
  208. package/src/common-apis/adapters/axiosAdapter.js +35 -0
  209. package/src/common-apis/adapters/qrUtils.js +18 -0
  210. package/src/common-apis/external-apis/apiGroups.js +55 -0
  211. package/src/common-apis/external-apis/emailAPI.js +16 -0
  212. package/src/common-apis/external-apis/ipAddressProviders.js +89 -0
  213. package/src/common-apis/globalConstants.jsx +3 -0
  214. package/src/common-apis/models/blockchain.js +10 -0
  215. package/src/common-apis/models/coin.js +248 -0
  216. package/src/common-apis/models/protocol.js +5 -0
  217. package/src/{common → common-apis/services}/fiatCurrenciesService.js +4 -12
  218. package/src/common-apis/tests/integration/external-apis/ipAddressProviders/getClientIpAddress.test.js +12 -0
  219. package/src/common-apis/tests/units/utils/amountUtils/composeRateText.test.js +152 -0
  220. package/src/{common → common-apis/utils}/amountUtils.js +72 -136
  221. package/src/common-apis/utils/cache.js +242 -0
  222. package/src/{common → common-apis/utils}/errorUtils.js +15 -0
  223. package/src/common-apis/utils/logging/logger.js +41 -0
  224. package/src/common-apis/utils/logging/logsStorage.js +61 -0
  225. package/src/common-apis/utils/postponeExecution.js +11 -0
  226. package/src/common-apis/utils/rabbitTicker.js +24 -0
  227. package/src/common-apis/utils/safeStringify.js +50 -0
  228. package/src/index.js +96 -9
  229. package/src/robust-api-caller/cacheAndConcurrentRequestsResolver.js +495 -0
  230. package/src/robust-api-caller/cachedRobustExternalApiCallerService.js +147 -0
  231. package/src/robust-api-caller/cancelProcessing.js +29 -0
  232. package/src/robust-api-caller/concurrentCalculationsMetadataHolder.js +75 -0
  233. package/src/robust-api-caller/externalApiProvider.js +156 -0
  234. package/src/robust-api-caller/externalServicesStatsCollector.js +78 -0
  235. package/src/robust-api-caller/robustExternalAPICallerService.js +304 -0
  236. package/src/robust-api-caller/tests/robustExternalAPICallerService/robustExternalAPICallerService/callExternalAPI/_performCallAttempt.test.js +533 -0
  237. package/src/robust-api-caller/tests/robustExternalAPICallerService/robustExternalAPICallerService/callExternalAPI/callExternalAPI.test.js +532 -0
  238. package/src/robust-api-caller/tests/robustExternalAPICallerService/robustExternalAPICallerService/constructor.test.js +19 -0
  239. package/src/swaps-lib/external-apis/exolixSwapProvider.js +580 -0
  240. package/src/swaps-lib/external-apis/letsExchangeSwapProvider.js +511 -0
  241. package/src/swaps-lib/external-apis/swapProvider.js +578 -0
  242. package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +592 -0
  243. package/src/swaps-lib/models/baseSwapCreationInfo.js +78 -0
  244. package/src/swaps-lib/models/existingSwap.js +143 -0
  245. package/src/swaps-lib/models/existingSwapWithFiatData.js +148 -0
  246. package/src/swaps-lib/models/partner.js +27 -0
  247. package/src/swaps-lib/models/swapProviderCoinInfo.js +82 -0
  248. package/src/swaps-lib/services/publicSwapService.js +490 -0
  249. package/src/swaps-lib/test/external-apis/exolixSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +34 -0
  250. package/src/swaps-lib/test/external-apis/exolixSwapProvider/createSwap.test.js +1043 -0
  251. package/src/swaps-lib/test/external-apis/exolixSwapProvider/getSwapInfo.test.js +611 -0
  252. package/src/swaps-lib/test/external-apis/swapProvider/getAllSupportedCurrencies.test.js +63 -0
  253. package/src/swaps-lib/test/external-apis/swapProvider/getDepositCurrencies.test.js +73 -0
  254. package/src/swaps-lib/test/external-apis/swapProvider/getWithdrawalCurrencies.test.js +102 -0
  255. package/src/swaps-lib/test/external-apis/swapProvider/removeProtocolNameFromCoinName.test.js +152 -0
  256. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +536 -0
  257. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/createSwap.test.js +1214 -0
  258. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getSwapInfo.test.js +1707 -0
  259. package/src/swaps-lib/test/utils/swapUtils/safeHandleRequestsLimitExceeding.test.js +80 -0
  260. package/src/swaps-lib/utils/swapUtils.js +195 -0
  261. package/{styles → src/ui-kit/assets/styles}/_functions.scss +5 -0
  262. package/{styles → src/ui-kit/assets/styles}/_mixins.scss +2 -2
  263. package/{styles → src/ui-kit/assets/styles}/_placeholder.scss +3 -3
  264. package/{styles → src/ui-kit/assets/styles}/_variables.scss +17 -15
  265. package/src/ui-kit/assets/styles/fonts/NunitoSans-Bold.ttf +0 -0
  266. package/src/ui-kit/assets/styles/fonts/NunitoSans-ExtraBold.ttf +0 -0
  267. package/src/ui-kit/assets/styles/fonts/NunitoSans-Light.ttf +0 -0
  268. package/src/ui-kit/assets/styles/fonts/NunitoSans-Regular.ttf +0 -0
  269. package/src/ui-kit/assets/styles/fonts/NunitoSans-SemiBold.ttf +0 -0
  270. package/src/ui-kit/assets/styles/global.scss +171 -0
  271. package/src/ui-kit/assets/styles/index.scss +10 -0
  272. package/src/ui-kit/assets/wrappedImages/arrowIcon.jsx +13 -0
  273. package/src/ui-kit/assets/wrappedImages/arrowTosca.jsx +14 -0
  274. package/src/ui-kit/assets/wrappedImages/arrowWhite.jsx +14 -0
  275. package/src/ui-kit/assets/wrappedImages/darkRectangle.jsx +7 -0
  276. package/src/ui-kit/assets/wrappedImages/determinedError.jsx +118 -0
  277. package/src/ui-kit/assets/wrappedImages/failedValidationIcon.jsx +39 -0
  278. package/src/ui-kit/assets/wrappedImages/infoIcon.jsx +16 -0
  279. package/src/ui-kit/assets/wrappedImages/messageIcon.jsx +87 -0
  280. package/src/ui-kit/assets/wrappedImages/noticeQuestionIcon.jsx +54 -0
  281. package/src/ui-kit/assets/wrappedImages/successfulValidationIcon.jsx +26 -0
  282. package/src/ui-kit/assets/wrappedImages/supportDialogImage.jsx +61 -0
  283. package/src/ui-kit/assets/wrappedImages/walletIcon.jsx +22 -0
  284. package/src/ui-kit/components/atoms/AssetIcon/AssetIcon.jsx +57 -0
  285. package/src/{components → ui-kit/components}/atoms/AssetIcon/asset-icon.module.scss +1 -1
  286. package/src/ui-kit/components/atoms/AssetSelection/AssetSelection.jsx +68 -0
  287. package/src/ui-kit/components/atoms/AssetSelection/asset-selection.module.scss +56 -0
  288. package/src/ui-kit/components/atoms/BackgroundTitle/BackgroundTitle.jsx +34 -0
  289. package/src/ui-kit/components/atoms/BackgroundTitle/background-title.module.scss +52 -0
  290. package/src/ui-kit/components/atoms/InformationMessage/InformationMessage.jsx +51 -0
  291. package/src/ui-kit/components/atoms/InformationMessage/information-message.module.scss +38 -0
  292. package/src/ui-kit/components/atoms/Input/Input.jsx +183 -0
  293. package/src/ui-kit/components/atoms/Input/input.module.scss +107 -0
  294. package/src/{components → ui-kit/components}/atoms/LoadingDots/LoadingDots.jsx +8 -28
  295. package/src/{components → ui-kit/components}/atoms/LoadingDots/LoadingDots.module.scss +3 -2
  296. package/src/ui-kit/components/atoms/NoticeIcon/NoticeIcon.jsx +64 -0
  297. package/src/ui-kit/components/atoms/NoticeIcon/notice-icon.module.scss +14 -0
  298. package/src/ui-kit/components/atoms/QrCode/QrCode.jsx +44 -0
  299. package/src/ui-kit/components/atoms/QrCode/qr-code.module.scss +15 -0
  300. package/src/ui-kit/components/atoms/RateSelector/RateSelector.jsx +30 -0
  301. package/src/ui-kit/components/atoms/RateSelector/rate-selector.module.scss +47 -0
  302. package/src/{components → ui-kit/components}/atoms/SupportChat/SupportChat.jsx +5 -1
  303. package/src/ui-kit/components/atoms/Textarea/Textarea.jsx +148 -0
  304. package/src/ui-kit/components/atoms/Textarea/textarea.module.scss +71 -0
  305. package/src/ui-kit/components/atoms/TitleBox/TitleBox.jsx +141 -0
  306. package/src/ui-kit/components/atoms/TitleBox/title-box.module.scss +32 -0
  307. package/src/ui-kit/components/atoms/Tooltip/Tooltip.jsx +77 -0
  308. package/src/ui-kit/components/atoms/Tooltip/tooltip.module.scss +237 -0
  309. package/src/ui-kit/components/atoms/TwoLinesOfText/LinesOfText.jsx +76 -0
  310. package/src/ui-kit/components/atoms/TwoLinesOfText/lines-of-text.module.scss +65 -0
  311. package/src/ui-kit/components/atoms/Validation/Validation.jsx +39 -0
  312. package/src/ui-kit/components/atoms/Validation/validation.module.scss +19 -0
  313. package/src/{components → ui-kit/components}/atoms/buttons/Button/Button.jsx +24 -50
  314. package/src/{components → ui-kit/components}/atoms/buttons/Button/Button.module.scss +1 -1
  315. package/src/ui-kit/components/atoms/buttons/Close/Close.jsx +58 -0
  316. package/src/ui-kit/components/atoms/buttons/Close/close.module.scss +75 -0
  317. package/src/ui-kit/components/atoms/buttons/LinkButton/LinkButton.jsx +112 -0
  318. package/src/ui-kit/components/atoms/buttons/LinkButton/link-button.module.scss +49 -0
  319. package/src/ui-kit/components/atoms/buttons/RadioButtonWithText/RadioButtonWithText.jsx +110 -0
  320. package/src/ui-kit/components/atoms/buttons/RadioButtonWithText/radio-button-with-text.module.scss +86 -0
  321. package/src/ui-kit/components/molecules/AmountInput/AmountInput.jsx +448 -0
  322. package/src/ui-kit/components/molecules/AmountInput/amount-input.module.scss +233 -0
  323. package/src/ui-kit/components/molecules/CoinPicker/CoinPicker.jsx +463 -0
  324. package/src/ui-kit/components/molecules/CoinPicker/coin-picker.module.scss +207 -0
  325. package/src/ui-kit/components/molecules/ColoredNotice/ColoredNotice.jsx +42 -0
  326. package/src/ui-kit/components/molecules/ColoredNotice/colored-notice.module.scss +20 -0
  327. package/src/ui-kit/components/molecules/LineWithIconLink/LineWithIconLink.jsx +35 -0
  328. package/src/ui-kit/components/molecules/LineWithIconLink/line-with-icon-link.module.scss +25 -0
  329. package/src/ui-kit/components/molecules/LogoCarousel/LogoCarousel.jsx +74 -0
  330. package/src/ui-kit/components/molecules/LogoCarousel/logo-carousel.module.scss +106 -0
  331. package/src/ui-kit/components/molecules/SearchableCoinsList/SearchableCoinsList.jsx +137 -0
  332. package/src/ui-kit/components/molecules/TitledLineWithIconLink/TitledLineWithIconLink.jsx +32 -0
  333. package/src/ui-kit/components/organisms/CoinPickerDialogStep/CoinPickerDialogStep.jsx +66 -0
  334. package/src/ui-kit/components/organisms/Dialog/Dialog.jsx +494 -0
  335. package/src/ui-kit/components/organisms/Dialog/DialogButtons/DialogButtons.jsx +132 -0
  336. package/src/ui-kit/components/organisms/Dialog/DialogButtons/dialog-buttons.module.scss +25 -0
  337. package/src/ui-kit/components/organisms/Dialog/DialogStep/DialogStep.jsx +554 -0
  338. package/src/ui-kit/components/organisms/Dialog/DialogStep/dialog-step.module.scss +381 -0
  339. package/src/ui-kit/components/organisms/Dialog/dialog.module.scss +226 -0
  340. package/src/ui-kit/components/organisms/SwapForm/SwapForm.jsx +1374 -0
  341. package/src/ui-kit/components/organisms/SwapForm/swap-form.module.scss +134 -0
  342. package/src/ui-kit/components/organisms/WaitlistSubscription/WaitlistSubscription.jsx +158 -0
  343. package/src/ui-kit/components/templates/DeterminedErrorDialogStep/DeterminedErrorDialogStep.jsx +77 -0
  344. package/src/ui-kit/hooks/useCallHandlingErrors.js +22 -0
  345. package/src/ui-kit/hooks/useIsHydrated.js +12 -0
  346. package/src/ui-kit/hooks/useReferredState.js +24 -0
  347. package/src/ui-kit/tests/utils/inputValueProviders/provideFormatOfFloatValueByInputString.test.js +146 -0
  348. package/src/ui-kit/tests/utils/urlQueryUtils/getQueryParameterValues.test.js +65 -0
  349. package/src/ui-kit/tests/utils/urlQueryUtils/saveQueryParameterAndValues.test.js +104 -0
  350. package/src/ui-kit/utils/inputValueProviders.js +50 -0
  351. package/src/ui-kit/utils/textUtils.js +18 -0
  352. package/src/ui-kit/utils/uiUtils.js +12 -0
  353. package/src/ui-kit/utils/urlQueryUtils.js +62 -0
  354. package/stories/font.scss +40 -0
  355. package/stories/stubs/coins.jsx +2266 -0
  356. package/stories/stubs/exampleContent.jsx +20 -0
  357. package/src/components/atoms/AssetIcon/AssetIcon.jsx +0 -55
  358. package/styles/_global-classes.scss +0 -433
  359. package/styles/fonts/NunitoSans-Bold.ttf +0 -0
  360. package/styles/fonts/NunitoSans-ExtraBold.ttf +0 -0
  361. package/styles/fonts/NunitoSans-Light.ttf +0 -0
  362. package/styles/fonts/NunitoSans-Regular.ttf +0 -0
  363. package/styles/fonts/NunitoSans-SemiBold.ttf +0 -0
  364. package/styles/global-styles-index.scss +0 -74
  365. package/styles/index.scss +0 -33
  366. /package/{styles → src/ui-kit/assets/styles}/colors/_light-colors.scss +0 -0
  367. /package/{styles → src/ui-kit/assets/styles}/colors/_solid-colors.scss +0 -0
  368. /package/{styles → src/ui-kit/assets/styles}/size/_margin-size.scss +0 -0
  369. /package/{styles → src/ui-kit/assets/styles}/size/_padding-size.scss +0 -0
@@ -0,0 +1,152 @@
1
+ import sinon from "sinon";
2
+ import should from "should";
3
+
4
+ import { beforeEach, afterEach, describe, it } from "vitest";
5
+ import BigNumber from "bignumber.js";
6
+ import { AmountUtils } from "../../../../utils/amountUtils.js";
7
+
8
+ describe("AmountUtils", function () {
9
+ let toIntegerStringStub;
10
+
11
+ beforeEach(function () {
12
+ toIntegerStringStub = sinon.stub(AmountUtils, "toIntegerString").callsFake(number => number.toFixed(0));
13
+ });
14
+
15
+ afterEach(function () {
16
+ toIntegerStringStub.restore();
17
+ });
18
+
19
+ describe("composeRateText", function () {
20
+ it("Should handle simple rate calculation", function () {
21
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.1");
22
+
23
+ result.should.equal("1 BTC ~ 0.10000000 ETH");
24
+ });
25
+
26
+ it("Should handle rate with strictRate set to true", function () {
27
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.1", 8, true);
28
+
29
+ result.should.equal("1 BTC = 0.10000000 ETH");
30
+ });
31
+
32
+ it("Should handle rate with high precision", function () {
33
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.12345678903422", 8);
34
+
35
+ result.should.equal("1 BTC ~ 0.12345678 ETH");
36
+ });
37
+
38
+ it("Should handle very small rates by scaling up", function () {
39
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.000000000000001", 8);
40
+
41
+ result.should.equal("100000000 BTC ~ 0.00000010 ETH");
42
+ });
43
+
44
+ it("Should handle large rates", function () {
45
+ const result = AmountUtils.composeRateText("BTC", "ETH", "1000000000000000", 8);
46
+
47
+ result.should.equal("1 BTC ~ 1000000000000000.00000000 ETH");
48
+ });
49
+
50
+ it("Should return '?' for invalid rate input", function () {
51
+ const result = AmountUtils.composeRateText("BTC", "ETH", "invalid");
52
+
53
+ result.should.equal("1 BTC ~ ? ETH");
54
+ });
55
+
56
+ it("Should return correct format for null rate", function () {
57
+ const result = AmountUtils.composeRateText("BTC", "ETH", null);
58
+
59
+ result.should.equal("1 BTC ~ ? ETH");
60
+ });
61
+
62
+ it("Should ensure that toIntegerString is called with correct parameter", function () {
63
+ AmountUtils.composeRateText("BTC", "ETH", "0.1");
64
+
65
+ toIntegerStringStub.calledWith(BigNumber("1")).should.be.true();
66
+ });
67
+
68
+ it("Should handle rate with different rightCurrencyDigitsAfterDots", function () {
69
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.123456789", 5);
70
+
71
+ result.should.equal("1 BTC ~ 0.12345 ETH");
72
+ });
73
+
74
+ it("Should handle rate with max rightCurrencyDigitsAfterDots", function () {
75
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.123456789", 10);
76
+
77
+ result.should.equal("1 BTC ~ 0.1234567890 ETH");
78
+ });
79
+
80
+ it("Should ensure proper rounding of right amount", function () {
81
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.123456789", 4);
82
+
83
+ result.should.equal("1 BTC ~ 0.1234 ETH");
84
+ });
85
+
86
+ it("Should handle great rightCurrencyDigitsAfterDots", function () {
87
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.123456789", 20);
88
+
89
+ result.should.equal("1 BTC ~ 0.12345678900000000000 ETH");
90
+ });
91
+
92
+ it("Should handle empty rate", function () {
93
+ const result = AmountUtils.composeRateText("BTC", "ETH", "");
94
+
95
+ result.should.equal("1 BTC ~ ? ETH");
96
+ });
97
+
98
+ it("Should handle negative rate", function () {
99
+ const result = AmountUtils.composeRateText("BTC", "ETH", "-0.1");
100
+
101
+ result.should.equal("1 BTC ~ -0.10000000 ETH");
102
+ });
103
+
104
+ it("Should return proper result for rate equal to zero", function () {
105
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0");
106
+
107
+ result.should.equal("1 BTC ~ 0.00000000 ETH");
108
+ });
109
+
110
+ it("Should ensure that toIntegerString is called the correct number of times", function () {
111
+ AmountUtils.composeRateText("BTC", "ETH", "0.1");
112
+
113
+ toIntegerStringStub.callCount.should.equal(1);
114
+ });
115
+
116
+ it("Should handle rate with exponential notation", function () {
117
+ const result = AmountUtils.composeRateText("BTC", "ETH", "1e-8");
118
+
119
+ result.should.equal("1 BTC ~ 0.00000001 ETH");
120
+ });
121
+
122
+ it("Should return correct format when rate has a lot of trailing zeros", function () {
123
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.1000000000000000000000");
124
+
125
+ result.should.equal("1 BTC ~ 0.10000000 ETH");
126
+ });
127
+
128
+ it("Should handle zero rightCurrencyDigitsAfterDots", function () {
129
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.123456789", 0);
130
+
131
+ result.should.equal("100 BTC ~ 12 ETH");
132
+ });
133
+
134
+ it("Should handle negative rightCurrencyDigitsAfterDots", function () {
135
+ const result = AmountUtils.composeRateText("BTC", "ETH", "0.123456789", -1);
136
+
137
+ result.should.equal("1 BTC ~ 0.12345678 ETH");
138
+ });
139
+
140
+ it("Should handle rate input with trailing spaces", function () {
141
+ const result = AmountUtils.composeRateText("BTC", "ETH", " 0.1 ");
142
+
143
+ result.should.equal("1 BTC ~ 0.10000000 ETH");
144
+ });
145
+
146
+ it("Should handle rate input in scientific notation", function () {
147
+ const result = AmountUtils.composeRateText("BTC", "ETH", "1e-5");
148
+
149
+ result.should.equal("1 BTC ~ 0.00001000 ETH");
150
+ });
151
+ });
152
+ });
@@ -1,6 +1,6 @@
1
1
  import { BigNumber } from "bignumber.js";
2
2
 
3
- import { FiatCurrenciesService } from "./fiatCurrenciesService.js";
3
+ import { FiatCurrenciesService } from "../services/fiatCurrenciesService.js";
4
4
  import { improveAndRethrow } from "./errorUtils.js";
5
5
 
6
6
  // TODO: [dev] return addCommasToAmountString internal method to encapsulate commas adding
@@ -38,54 +38,29 @@ export class AmountUtils {
38
38
  try {
39
39
  const params = { ...this.defaultFiatParams, ...passedParams };
40
40
 
41
- if (
42
- this._checkIfAmountInvalid(amount, true) ||
43
- typeof currencyCode !== "string"
44
- )
45
- return "NULL";
46
-
47
- const currencySymbol =
48
- FiatCurrenciesService.getCurrencySymbolByCode(currencyCode);
49
- const currencyDecimalCount =
50
- FiatCurrenciesService.getCurrencyDecimalCountByCode(
51
- currencyCode
52
- );
41
+ if (this._checkIfAmountInvalid(amount, true) || typeof currencyCode !== "string") return "NULL";
42
+
43
+ const currencySymbol = FiatCurrenciesService.getCurrencySymbolByCode(currencyCode);
44
+ const currencyDecimalCount = FiatCurrenciesService.getCurrencyDecimalCountByCode(currencyCode);
53
45
 
54
- const trimmedByMaxDigits = BigNumber(amount).toFixed(
55
- currencyDecimalCount,
56
- BigNumber.ROUND_FLOOR
57
- );
46
+ const trimmedByMaxDigits = BigNumber(amount).toFixed(currencyDecimalCount, BigNumber.ROUND_FLOOR);
58
47
 
59
48
  let processedAmount = BigNumber(trimmedByMaxDigits);
60
- if (
61
- params.collapsible &&
62
- processedAmount.gte(BigNumber("1000000"))
63
- ) {
49
+ if (params.collapsible && processedAmount.gte(BigNumber("1000000"))) {
64
50
  processedAmount = this._collapseToMillionsAndFormat(
65
51
  processedAmount,
66
52
  this.collapsedDecimalCount,
67
53
  params
68
54
  );
69
55
  } else {
70
- const limitResult = this._limitTotalAmountLengthIfNeeded(
71
- trimmedByMaxDigits,
72
- params
73
- );
74
- processedAmount = BigNumber(
75
- limitResult.processedAmount
76
- ).toFormat(); // Adds commas to integer part
56
+ const limitResult = this._limitTotalAmountLengthIfNeeded(trimmedByMaxDigits, params);
57
+ processedAmount = BigNumber(limitResult.processedAmount).toFormat(); // Adds commas to integer part
77
58
  }
78
59
 
79
60
  // Add the currency code or currency symbol, if symbol is enabled and available
80
61
  if (params.ticker) {
81
- if (
82
- typeof currencySymbol === "string" &&
83
- params.enableCurrencySymbols
84
- ) {
85
- processedAmount =
86
- currencySymbol +
87
- (currencySymbol.length > 1 ? " " : "") +
88
- processedAmount;
62
+ if (typeof currencySymbol === "string" && params.enableCurrencySymbols) {
63
+ processedAmount = currencySymbol + (currencySymbol.length > 1 ? " " : "") + processedAmount;
89
64
  } else {
90
65
  processedAmount = processedAmount + " " + currencyCode;
91
66
  }
@@ -104,6 +79,7 @@ export class AmountUtils {
104
79
  limitTotalLength: true, // Limits the total amount length to maxTotalLength
105
80
  extraSmallLength: false, // Limits the total amount length to extraSmallMaxTotalLength
106
81
  periods: true, // Whether we add periods ("..") as suffix for trimmed numbers
82
+ numberPartsSeparator: true, // Whether we add separators e.g. for 1000000 -> 1,000,000
107
83
  };
108
84
 
109
85
  static cryptoWoTicker(amount, digits) {
@@ -132,6 +108,16 @@ export class AmountUtils {
132
108
  });
133
109
  }
134
110
 
111
+ static cryptoFullPureNumber(amount, digits) {
112
+ return this.crypto(amount, null, digits, {
113
+ ticker: false,
114
+ collapsible: false,
115
+ trim: false,
116
+ limitTotalLength: false,
117
+ numberPartsSeparator: false,
118
+ });
119
+ }
120
+
135
121
  /**
136
122
  * Universal method for rendering of crypto amounts, taking into account the rules of
137
123
  * the passed ticker. Requires the number of digits after period to be less of equal to
@@ -143,33 +129,19 @@ export class AmountUtils {
143
129
  * @param passedParams {object} Formatting parameters
144
130
  * @return {string} Formatted crypto amount string
145
131
  */
146
- static crypto(
147
- amount,
148
- ticker,
149
- digits = this.significantDecimalCount,
150
- passedParams
151
- ) {
132
+ static crypto(amount, ticker, digits = this.significantDecimalCount, passedParams) {
152
133
  try {
153
134
  const params = { ...this.defaultCryptoParams, ...passedParams };
154
135
 
155
- if (
156
- this._checkIfAmountInvalid(amount) ||
157
- (typeof ticker !== "string" && params.ticker)
158
- )
159
- return "NULL";
136
+ if (this._checkIfAmountInvalid(amount) || (typeof ticker !== "string" && params.ticker)) return "NULL";
160
137
 
161
138
  let addPeriods = false;
162
139
 
163
140
  const amountBigNumber = BigNumber(amount);
164
141
 
165
- let processedAmount = amountBigNumber.toFixed(
166
- digits,
167
- BigNumber.ROUND_FLOOR
168
- );
169
- processedAmount =
170
- this.removeRedundantRightZerosFromNumberString(processedAmount);
171
- const originalAmountDecimalPlaces =
172
- BigNumber(processedAmount).decimalPlaces();
142
+ let processedAmount = amountBigNumber.toFixed(digits, BigNumber.ROUND_FLOOR);
143
+ processedAmount = this.removeRedundantRightZerosFromNumberString(processedAmount);
144
+ const originalAmountDecimalPlaces = BigNumber(processedAmount).decimalPlaces();
173
145
  // Check decimal count and throw an error, if the amount has more decimal digits than supported by the asset
174
146
  if (originalAmountDecimalPlaces > digits) {
175
147
  const errorMessage = `An attempt to render a crypto value with too many digits after period was made: ${amount}, allowed digits: ${digits}. This is a no-op, since the logical and visually rendered values would differ, which is not acceptable for crypto amounts. Please trim the amount before rendering, using the trimCryptoAmountByCoin(amount, coin) method.`;
@@ -180,21 +152,13 @@ export class AmountUtils {
180
152
 
181
153
  // Shortening the value to general significant number of digits after period
182
154
  if (params.trim) {
183
- processedAmount =
184
- this.removeRedundantRightZerosFromNumberString(
185
- amountBigNumber.toFixed(
186
- this.significantDecimalCount,
187
- BigNumber.ROUND_FLOOR
188
- )
189
- );
190
- addPeriods =
191
- originalAmountDecimalPlaces > this.significantDecimalCount;
155
+ processedAmount = this.removeRedundantRightZerosFromNumberString(
156
+ amountBigNumber.toFixed(this.significantDecimalCount, BigNumber.ROUND_FLOOR)
157
+ );
158
+ addPeriods = originalAmountDecimalPlaces > this.significantDecimalCount;
192
159
  }
193
160
 
194
- const limitResult = this._limitTotalAmountLengthIfNeeded(
195
- processedAmount,
196
- params
197
- );
161
+ const limitResult = this._limitTotalAmountLengthIfNeeded(processedAmount, params);
198
162
  processedAmount = limitResult.processedAmount;
199
163
  addPeriods ||= limitResult.addPeriods;
200
164
 
@@ -207,7 +171,7 @@ export class AmountUtils {
207
171
  params
208
172
  );
209
173
  wereMillionsCollapsed = true;
210
- } else {
174
+ } else if (params.numberPartsSeparator) {
211
175
  // Add separators to integer part of the amount
212
176
  processedAmount = BigNumber(processedAmount).toFormat();
213
177
  }
@@ -224,11 +188,7 @@ export class AmountUtils {
224
188
 
225
189
  return processedAmount;
226
190
  } catch (e) {
227
- improveAndRethrow(
228
- e,
229
- "crypto",
230
- `Passed: ${amount}, ${ticker}, ${digits}`
231
- );
191
+ improveAndRethrow(e, "crypto", `Passed: ${amount}, ${ticker}, ${digits}`);
232
192
  }
233
193
  }
234
194
 
@@ -262,11 +222,13 @@ export class AmountUtils {
262
222
  }
263
223
 
264
224
  /**
225
+ * Returns integer part of number as a string.
226
+ *
265
227
  * @param amount {BigNumber|number|string|null|undefined} The number value to be trimmed.
266
228
  * HEX strings also allowed "0x..." and JS hex numbers
267
229
  * @return {string|null}
268
230
  */
269
- static intStr(amount) {
231
+ static toIntegerString(amount) {
270
232
  return this.trim(amount, 0);
271
233
  }
272
234
 
@@ -278,32 +240,17 @@ export class AmountUtils {
278
240
  * @param params {object} params object
279
241
  * @return {string} A shortened string, converted into "millions" format, if the amount exceeds 1 million
280
242
  */
281
- static _collapseToMillionsAndFormat(
282
- amountBigNumber,
283
- decimalCount,
284
- params = {}
285
- ) {
243
+ static _collapseToMillionsAndFormat(amountBigNumber, decimalCount, params = {}) {
286
244
  try {
287
245
  // TODO: [feature, moderate] use local format here - take from JS locales (comma/dot etc.)
288
246
  const millionBigNumber = BigNumber("1000000");
289
- const millions = amountBigNumber
290
- .div(millionBigNumber)
291
- .toFixed(decimalCount, BigNumber.ROUND_FLOOR);
292
- const limitedResult = this._limitTotalAmountLengthIfNeeded(
293
- millions,
294
- params
295
- );
296
- const formatted = BigNumber(
297
- limitedResult.processedAmount
298
- ).toFormat();
247
+ const millions = amountBigNumber.div(millionBigNumber).toFixed(decimalCount, BigNumber.ROUND_FLOOR);
248
+ const limitedResult = this._limitTotalAmountLengthIfNeeded(millions, params);
249
+ const formatted = BigNumber(limitedResult.processedAmount).toFormat();
299
250
 
300
251
  return formatted + "M";
301
252
  } catch (e) {
302
- improveAndRethrow(
303
- e,
304
- "_collapseAmountAndFormat",
305
- `Passed: ${amountBigNumber.toFixed()}, ${decimalCount}`
306
- );
253
+ improveAndRethrow(e, "_collapseAmountAndFormat", `Passed: ${amountBigNumber.toFixed()}, ${decimalCount}`);
307
254
  }
308
255
  }
309
256
 
@@ -316,13 +263,10 @@ export class AmountUtils {
316
263
  try {
317
264
  let addPeriods = false;
318
265
  if (params.limitTotalLength || params.extraSmallLength) {
319
- const maxLength = params.extraSmallLength
320
- ? this.extraSmallMaxTotalLength
321
- : this.maxTotalLength;
266
+ const maxLength = params.extraSmallLength ? this.extraSmallMaxTotalLength : this.maxTotalLength;
322
267
  if (amountString.length > maxLength) {
323
268
  const delta = amountString.length - maxLength;
324
- const currentDecimalsCount =
325
- BigNumber(amountString).decimalPlaces();
269
+ const currentDecimalsCount = BigNumber(amountString).decimalPlaces();
326
270
  const newDecimalCount = currentDecimalsCount - delta;
327
271
  amountString = BigNumber(amountString).toFixed(
328
272
  newDecimalCount > 2 ? newDecimalCount : 2,
@@ -334,62 +278,58 @@ export class AmountUtils {
334
278
 
335
279
  return { addPeriods: addPeriods, processedAmount: amountString };
336
280
  } catch (e) {
337
- improveAndRethrow(
338
- e,
339
- "_limitTotalAmountLengthIfNeeded",
340
- `Passed: ${amountString}, ${params}`
341
- );
281
+ improveAndRethrow(e, "_limitTotalAmountLengthIfNeeded", `Passed: ${amountString}, ${params}`);
342
282
  }
343
283
  }
344
284
 
345
285
  /**
346
- * Safely composes rate string (handles small/big rates)
286
+ * Safely composes rate string (handles small/big rates).
287
+ * Here we try to calculate a clear rate for the user. The difficulty is that the rate value can be pretty
288
+ * small as some coins have significantly higher price than the other. For such cases we calculate
289
+ * not the "1 <coin_A> is X <coin B>" but "Y <coin_A> is X <coin B>" where Y is one of the powers of 100.
347
290
  *
348
291
  * @param leftTicker {string}
349
292
  * @param rightTicker {string}
350
293
  * @param rate {number|string|BigNumber}
351
294
  * @param [rightCurrencyDigitsAfterDots=8] {number}
295
+ * @param [strictRate=false] {boolean} true if the rate is strict and false if approximate
352
296
  * @return {string}
353
297
  */
354
298
  static composeRateText(
355
299
  leftTicker,
356
300
  rightTicker,
357
301
  rate,
358
- rightCurrencyDigitsAfterDots = this.significantDecimalCount
302
+ rightCurrencyDigitsAfterDots = this.significantDecimalCount,
303
+ strictRate = false
359
304
  ) {
360
305
  try {
361
- /* Here we try to calculate a clear rate for the user. The difficulty is that the rate value can be pretty
362
- * small as some coins have significantly higher price than the other. For such cases we calculate
363
- * not the "1 <coin_A> is X <coin B>" but "Y <coin_A> is X <coin B>" where Y is one of the powers of 100.
364
- */
306
+ if (rightCurrencyDigitsAfterDots < 0) {
307
+ rightCurrencyDigitsAfterDots = this.significantDecimalCount;
308
+ }
365
309
  let leftNumber = BigNumber("1");
366
310
  const multiplier = BigNumber("100");
367
311
  const maxAttemptsToGetRate = 10;
368
312
  let right = null;
369
313
  const rateBigNumber = BigNumber(rate);
370
- for (let i = 0; i < maxAttemptsToGetRate; ++i) {
371
- const rightNumberAttempt = rateBigNumber
372
- .times(leftNumber)
373
- .toFixed(
374
- rightCurrencyDigitsAfterDots,
375
- BigNumber.ROUND_FLOOR
376
- );
377
- if (!BigNumber(rightNumberAttempt).eq(BigNumber("0"))) {
378
- right = BigNumber(rightNumberAttempt);
379
- break;
380
- } else {
381
- leftNumber = leftNumber.times(multiplier);
314
+ if (BigNumber(rate).eq("0")) {
315
+ right = BigNumber("0");
316
+ } else if (rate && (BigNumber.isBigNumber(rate) || !Number.isNaN(+rate))) {
317
+ for (let i = 0; i < maxAttemptsToGetRate; ++i) {
318
+ const rightNumberAttempt = rateBigNumber
319
+ .times(leftNumber)
320
+ .toFixed(rightCurrencyDigitsAfterDots, BigNumber.ROUND_FLOOR);
321
+ if (!BigNumber(rightNumberAttempt).eq(BigNumber("0"))) {
322
+ right = BigNumber(rightNumberAttempt);
323
+ break;
324
+ } else {
325
+ leftNumber = leftNumber.times(multiplier);
326
+ }
382
327
  }
383
328
  }
384
- const leftAmountString = AmountUtils.intStr(leftNumber);
329
+ const leftAmountString = AmountUtils.toIntegerString(leftNumber);
385
330
  const rightAmountString =
386
- right != null
387
- ? right.toFixed(
388
- rightCurrencyDigitsAfterDots,
389
- BigNumber.ROUND_FLOOR
390
- )
391
- : null;
392
- return `${leftAmountString} ${leftTicker} ~ ${
331
+ right != null ? right.toFixed(rightCurrencyDigitsAfterDots, BigNumber.ROUND_FLOOR) : null;
332
+ return `${leftAmountString} ${leftTicker} ${strictRate ? "=" : "~"} ${
393
333
  rightAmountString ?? "?"
394
334
  } ${rightTicker}`;
395
335
  } catch (e) {
@@ -413,11 +353,7 @@ export class AmountUtils {
413
353
 
414
354
  return `${parts[0]}${right?.length ? `.${right}` : ""}`;
415
355
  } catch (e) {
416
- improveAndRethrow(
417
- e,
418
- "removeRedundantRightZerosFromNumberString",
419
- `Passed: ${numberAsAString}`
420
- );
356
+ improveAndRethrow(e, "removeRedundantRightZerosFromNumberString", `Passed: ${numberAsAString}`);
421
357
  }
422
358
  }
423
359
  }