@rabbitio/ui-kit 1.0.0-beta.6 → 1.0.0-beta.60

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 (312) hide show
  1. package/.gitlab-ci.yml +29 -0
  2. package/.husky/commit-msg +14 -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 +17121 -0
  9. package/coverage/coverage-final.json +157 -0
  10. package/coverage/favicon.png +0 -0
  11. package/coverage/index.html +1226 -0
  12. package/coverage/prettify.css +1 -0
  13. package/coverage/prettify.js +2 -0
  14. package/coverage/sort-arrow-sprite.png +0 -0
  15. package/coverage/sorter.js +196 -0
  16. package/coverage/ui-kit/index.html +116 -0
  17. package/coverage/ui-kit/index.js.html +88 -0
  18. package/coverage/ui-kit/src/assets/wrappedImages/arrowIcon.jsx.html +142 -0
  19. package/coverage/ui-kit/src/assets/wrappedImages/arrowTosca.jsx.html +145 -0
  20. package/coverage/ui-kit/src/assets/wrappedImages/arrowWhite.jsx.html +145 -0
  21. package/coverage/ui-kit/src/assets/wrappedImages/darkRectangle.jsx.html +139 -0
  22. package/coverage/ui-kit/src/assets/wrappedImages/determinedError.jsx.html +472 -0
  23. package/coverage/ui-kit/src/assets/wrappedImages/failedValidationIcon.jsx.html +244 -0
  24. package/coverage/ui-kit/src/assets/wrappedImages/index.html +251 -0
  25. package/coverage/ui-kit/src/assets/wrappedImages/infoIcon.jsx.html +151 -0
  26. package/coverage/ui-kit/src/assets/wrappedImages/noticeQuestionIcon.jsx.html +265 -0
  27. package/coverage/ui-kit/src/assets/wrappedImages/successfulValidationIcon.jsx.html +205 -0
  28. package/coverage/ui-kit/src/assets/wrappedImages/walletIcon.jsx.html +199 -0
  29. package/coverage/ui-kit/src/common/adapters/axiosAdapter.js.html +190 -0
  30. package/coverage/ui-kit/src/common/adapters/index.html +131 -0
  31. package/coverage/ui-kit/src/common/adapters/qrUtils.js.html +139 -0
  32. package/coverage/ui-kit/src/common/amountUtils.js.html +1393 -0
  33. package/coverage/ui-kit/src/common/errorUtils.js.html +211 -0
  34. package/coverage/ui-kit/src/common/external-apis/apiGroups.js.html +250 -0
  35. package/coverage/ui-kit/src/common/external-apis/index.html +131 -0
  36. package/coverage/ui-kit/src/common/external-apis/ipAddressProviders.js.html +499 -0
  37. package/coverage/ui-kit/src/common/fiatCurrenciesService.js.html +568 -0
  38. package/coverage/ui-kit/src/common/index.html +146 -0
  39. package/coverage/ui-kit/src/common/models/blockchain.js.html +115 -0
  40. package/coverage/ui-kit/src/common/models/coin.js.html +556 -0
  41. package/coverage/ui-kit/src/common/models/index.html +146 -0
  42. package/coverage/ui-kit/src/common/models/protocol.js.html +100 -0
  43. package/coverage/ui-kit/src/common/utils/cache.js.html +889 -0
  44. package/coverage/ui-kit/src/common/utils/emailAPI.js.html +139 -0
  45. package/coverage/ui-kit/src/common/utils/index.html +161 -0
  46. package/coverage/ui-kit/src/common/utils/logging/index.html +131 -0
  47. package/coverage/ui-kit/src/common/utils/logging/logger.js.html +229 -0
  48. package/coverage/ui-kit/src/common/utils/logging/logsStorage.js.html +268 -0
  49. package/coverage/ui-kit/src/common/utils/postponeExecution.js.html +118 -0
  50. package/coverage/ui-kit/src/common/utils/safeStringify.js.html +235 -0
  51. package/coverage/ui-kit/src/components/atoms/AssetIcon/AssetIcon.jsx.html +277 -0
  52. package/coverage/ui-kit/src/components/atoms/AssetIcon/index.html +116 -0
  53. package/coverage/ui-kit/src/components/atoms/AssetSelection/AssetSelection.jsx.html +310 -0
  54. package/coverage/ui-kit/src/components/atoms/AssetSelection/index.html +116 -0
  55. package/coverage/ui-kit/src/components/atoms/BackgroundTitle/BackgroundTitle.jsx.html +217 -0
  56. package/coverage/ui-kit/src/components/atoms/BackgroundTitle/index.html +116 -0
  57. package/coverage/ui-kit/src/components/atoms/InformationMessage/InformationMessage.jsx.html +265 -0
  58. package/coverage/ui-kit/src/components/atoms/InformationMessage/index.html +116 -0
  59. package/coverage/ui-kit/src/components/atoms/Input/Input.jsx.html +679 -0
  60. package/coverage/ui-kit/src/components/atoms/Input/index.html +116 -0
  61. package/coverage/ui-kit/src/components/atoms/LoadingDots/LoadingDots.jsx.html +256 -0
  62. package/coverage/ui-kit/src/components/atoms/LoadingDots/index.html +116 -0
  63. package/coverage/ui-kit/src/components/atoms/NoticeIcon/NoticeIcon.jsx.html +298 -0
  64. package/coverage/ui-kit/src/components/atoms/NoticeIcon/index.html +116 -0
  65. package/coverage/ui-kit/src/components/atoms/QrCode/QrCode.jsx.html +187 -0
  66. package/coverage/ui-kit/src/components/atoms/QrCode/index.html +116 -0
  67. package/coverage/ui-kit/src/components/atoms/SupportChat/SupportChat.jsx.html +229 -0
  68. package/coverage/ui-kit/src/components/atoms/SupportChat/index.html +116 -0
  69. package/coverage/ui-kit/src/components/atoms/Textarea/Textarea.jsx.html +559 -0
  70. package/coverage/ui-kit/src/components/atoms/Textarea/index.html +116 -0
  71. package/coverage/ui-kit/src/components/atoms/TitleBox/TitleBox.jsx.html +577 -0
  72. package/coverage/ui-kit/src/components/atoms/TitleBox/index.html +116 -0
  73. package/coverage/ui-kit/src/components/atoms/Tooltip/Tooltip.jsx.html +295 -0
  74. package/coverage/ui-kit/src/components/atoms/Tooltip/index.html +116 -0
  75. package/coverage/ui-kit/src/components/atoms/TwoLinesOfText/LinesOfText.jsx.html +325 -0
  76. package/coverage/ui-kit/src/components/atoms/TwoLinesOfText/index.html +116 -0
  77. package/coverage/ui-kit/src/components/atoms/Validation/Validation.jsx.html +202 -0
  78. package/coverage/ui-kit/src/components/atoms/Validation/index.html +116 -0
  79. package/coverage/ui-kit/src/components/atoms/buttons/Button/Button.jsx.html +802 -0
  80. package/coverage/ui-kit/src/components/atoms/buttons/Button/index.html +116 -0
  81. package/coverage/ui-kit/src/components/atoms/buttons/Close/Close.jsx.html +262 -0
  82. package/coverage/ui-kit/src/components/atoms/buttons/Close/index.html +116 -0
  83. package/coverage/ui-kit/src/components/atoms/buttons/LinkButton/LinkButton.jsx.html +430 -0
  84. package/coverage/ui-kit/src/components/atoms/buttons/LinkButton/index.html +116 -0
  85. package/coverage/ui-kit/src/components/atoms/buttons/RadioButtonWithText/RadioButtonWithText.jsx.html +469 -0
  86. package/coverage/ui-kit/src/components/atoms/buttons/RadioButtonWithText/index.html +116 -0
  87. package/coverage/ui-kit/src/components/hooks/index.html +131 -0
  88. package/coverage/ui-kit/src/components/hooks/useCallHandlingErrors.js.html +163 -0
  89. package/coverage/ui-kit/src/components/hooks/useReferredState.js.html +157 -0
  90. package/coverage/ui-kit/src/components/molecules/AmountInput/AmountInput.jsx.html +1348 -0
  91. package/coverage/ui-kit/src/components/molecules/AmountInput/index.html +116 -0
  92. package/coverage/ui-kit/src/components/molecules/CoinPicker/CoinPicker.jsx.html +2011 -0
  93. package/coverage/ui-kit/src/components/molecules/CoinPicker/index.html +116 -0
  94. package/coverage/ui-kit/src/components/molecules/LineWithIconLink/LineWithIconLink.jsx.html +205 -0
  95. package/coverage/ui-kit/src/components/molecules/LineWithIconLink/index.html +116 -0
  96. package/coverage/ui-kit/src/components/molecules/TitledLineWithIconLink/TitledLineWithIconLink.jsx.html +175 -0
  97. package/coverage/ui-kit/src/components/molecules/TitledLineWithIconLink/index.html +116 -0
  98. package/coverage/ui-kit/src/components/organisms/CoinPickerDialogStep/CoinPickerDialogStep.jsx.html +283 -0
  99. package/coverage/ui-kit/src/components/organisms/CoinPickerDialogStep/index.html +116 -0
  100. package/coverage/ui-kit/src/components/organisms/Dialog/Dialog.jsx.html +1630 -0
  101. package/coverage/ui-kit/src/components/organisms/Dialog/DialogButtons/DialogButtons.jsx.html +451 -0
  102. package/coverage/ui-kit/src/components/organisms/Dialog/DialogButtons/index.html +116 -0
  103. package/coverage/ui-kit/src/components/organisms/Dialog/DialogStep/DialogStep.jsx.html +2146 -0
  104. package/coverage/ui-kit/src/components/organisms/Dialog/DialogStep/index.html +116 -0
  105. package/coverage/ui-kit/src/components/organisms/Dialog/index.html +116 -0
  106. package/coverage/ui-kit/src/components/organisms/SwapForm/SwapForm.jsx.html +3817 -0
  107. package/coverage/ui-kit/src/components/organisms/SwapForm/index.html +116 -0
  108. package/coverage/ui-kit/src/components/templates/DeterminedErrorDialogStep/DeterminedErrorDialogStep.jsx.html +316 -0
  109. package/coverage/ui-kit/src/components/templates/DeterminedErrorDialogStep/index.html +116 -0
  110. package/coverage/ui-kit/src/components/utils/index.html +161 -0
  111. package/coverage/ui-kit/src/components/utils/inputValueProviders.js.html +259 -0
  112. package/coverage/ui-kit/src/components/utils/textUtils.js.html +139 -0
  113. package/coverage/ui-kit/src/components/utils/uiUtils.js.html +127 -0
  114. package/coverage/ui-kit/src/components/utils/urlQueryUtils.js.html +346 -0
  115. package/coverage/ui-kit/src/constants/atoms/Close/close.jsx.html +100 -0
  116. package/coverage/ui-kit/src/constants/atoms/Close/index.html +116 -0
  117. package/coverage/ui-kit/src/constants/atoms/LinkButton/index.html +116 -0
  118. package/coverage/ui-kit/src/constants/atoms/LinkButton/linkButton.jsx.html +103 -0
  119. package/coverage/ui-kit/src/constants/atoms/Tooltip/index.html +116 -0
  120. package/coverage/ui-kit/src/constants/atoms/Tooltip/tooltip.jsx.html +109 -0
  121. package/coverage/ui-kit/src/constants/globalConstants.jsx.html +97 -0
  122. package/coverage/ui-kit/src/constants/index.html +116 -0
  123. package/coverage/ui-kit/src/constants/organisms/dialog/DialogStep/dialogStep.js.html +88 -0
  124. package/coverage/ui-kit/src/constants/organisms/dialog/DialogStep/index.html +116 -0
  125. package/coverage/ui-kit/src/constants/organisms/dialog/dialog.js.html +172 -0
  126. package/coverage/ui-kit/src/constants/organisms/dialog/index.html +116 -0
  127. package/coverage/ui-kit/src/index.html +116 -0
  128. package/coverage/ui-kit/src/index.js.html +367 -0
  129. package/coverage/ui-kit/src/robustExteranlApiCallerService/cacheAndConcurrentRequestsResolver.js.html +1762 -0
  130. package/coverage/ui-kit/src/robustExteranlApiCallerService/cachedRobustExternalApiCallerService.js.html +649 -0
  131. package/coverage/ui-kit/src/robustExteranlApiCallerService/cancelProcessing.js.html +172 -0
  132. package/coverage/ui-kit/src/robustExteranlApiCallerService/concurrentCalculationsMetadataHolder.js.html +394 -0
  133. package/coverage/ui-kit/src/robustExteranlApiCallerService/externalApiProvider.js.html +553 -0
  134. package/coverage/ui-kit/src/robustExteranlApiCallerService/externalServicesStatsCollector.js.html +331 -0
  135. package/coverage/ui-kit/src/robustExteranlApiCallerService/index.html +206 -0
  136. package/coverage/ui-kit/src/robustExteranlApiCallerService/robustExternalAPICallerService.js.html +1249 -0
  137. package/coverage/ui-kit/src/swaps-lib/external-apis/index.html +131 -0
  138. package/coverage/ui-kit/src/swaps-lib/external-apis/swapProvider.js.html +727 -0
  139. package/coverage/ui-kit/src/swaps-lib/external-apis/swapspaceSwapProvider.js.html +2899 -0
  140. package/coverage/ui-kit/src/swaps-lib/models/baseSwapCreationInfo.js.html +214 -0
  141. package/coverage/ui-kit/src/swaps-lib/models/existingSwap.js.html +304 -0
  142. package/coverage/ui-kit/src/swaps-lib/models/existingSwapWithFiatData.js.html +487 -0
  143. package/coverage/ui-kit/src/swaps-lib/models/index.html +146 -0
  144. package/coverage/ui-kit/src/swaps-lib/services/index.html +116 -0
  145. package/coverage/ui-kit/src/swaps-lib/services/publicSwapService.js.html +2191 -0
  146. package/coverage/ui-kit/src/swaps-lib/utils/index.html +116 -0
  147. package/coverage/ui-kit/src/swaps-lib/utils/swapUtils.js.html +742 -0
  148. package/coverage/ui-kit/stories/atoms/BackgroundTitle.stories.jsx.html +202 -0
  149. package/coverage/ui-kit/stories/atoms/LinesOfText.stories.jsx.html +283 -0
  150. package/coverage/ui-kit/stories/atoms/LoadingDots.stories.jsx.html +226 -0
  151. package/coverage/ui-kit/stories/atoms/QrCode.stories.jsx.html +175 -0
  152. package/coverage/ui-kit/stories/atoms/Validation.stories.jsx.html +178 -0
  153. package/coverage/ui-kit/stories/atoms/buttons/Button.stories.jsx.html +946 -0
  154. package/coverage/ui-kit/stories/atoms/buttons/Close.stories.jsx.html +214 -0
  155. package/coverage/ui-kit/stories/atoms/buttons/LinkButton.stories.jsx.html +295 -0
  156. package/coverage/ui-kit/stories/atoms/buttons/index.html +146 -0
  157. package/coverage/ui-kit/stories/atoms/index.html +176 -0
  158. package/coverage/ui-kit/stories/molecules/LineWithIconLink.stories.jsx.html +154 -0
  159. package/coverage/ui-kit/stories/molecules/TitledLineWithIconLink.stories.jsx.html +160 -0
  160. package/coverage/ui-kit/stories/molecules/index.html +131 -0
  161. package/coverage/ui-kit/stories/organisms/Dialog/Dialog.stories.jsx.html +589 -0
  162. package/coverage/ui-kit/stories/organisms/Dialog/DialogButtons/DialogButtons.stories.jsx.html +328 -0
  163. package/coverage/ui-kit/stories/organisms/Dialog/DialogButtons/index.html +116 -0
  164. package/coverage/ui-kit/stories/organisms/Dialog/DialogStep/DialogStep.stories.jsx.html +337 -0
  165. package/coverage/ui-kit/stories/organisms/Dialog/DialogStep/index.html +116 -0
  166. package/coverage/ui-kit/stories/organisms/Dialog/index.html +116 -0
  167. package/coverage/ui-kit/stories/stubs/exampleContent.jsx.html +145 -0
  168. package/coverage/ui-kit/stories/stubs/index.html +116 -0
  169. package/coverage/ui-kit/stories/templates/DeterminedErrorDialogStep.stories.jsx.html +193 -0
  170. package/coverage/ui-kit/stories/templates/index.html +116 -0
  171. package/dist/index.cjs +9920 -9
  172. package/dist/index.cjs.map +1 -1
  173. package/dist/index.css +68553 -1641
  174. package/dist/index.css.map +1 -1
  175. package/dist/index.modern.js +7635 -11
  176. package/dist/index.modern.js.map +1 -1
  177. package/dist/index.module.js +9840 -11
  178. package/dist/index.module.js.map +1 -1
  179. package/dist/index.umd.js +9911 -12
  180. package/dist/index.umd.js.map +1 -1
  181. package/index.js +1 -1
  182. package/package.json +27 -5
  183. package/src/assets/image/icons/arrow-tosca.svg +3 -0
  184. package/src/assets/wrappedImages/arrowIcon.jsx +19 -0
  185. package/src/assets/wrappedImages/arrowTosca.jsx +20 -0
  186. package/src/assets/wrappedImages/arrowWhite.jsx +20 -0
  187. package/src/assets/wrappedImages/darkRectangle.jsx +18 -0
  188. package/src/assets/wrappedImages/determinedError.jsx +129 -0
  189. package/src/assets/wrappedImages/failedValidationIcon.jsx +53 -0
  190. package/src/assets/wrappedImages/infoIcon.jsx +22 -0
  191. package/src/assets/wrappedImages/noticeQuestionIcon.jsx +60 -0
  192. package/src/assets/wrappedImages/successfulValidationIcon.jsx +40 -0
  193. package/src/assets/wrappedImages/walletIcon.jsx +38 -0
  194. package/src/common/adapters/axiosAdapter.js +35 -0
  195. package/src/common/adapters/qrUtils.js +18 -0
  196. package/src/common/amountUtils.js +436 -0
  197. package/src/common/errorUtils.js +42 -0
  198. package/src/common/external-apis/apiGroups.js +55 -0
  199. package/src/common/external-apis/ipAddressProviders.js +138 -0
  200. package/src/common/fiatCurrenciesService.js +161 -0
  201. package/src/common/models/blockchain.js +10 -0
  202. package/src/common/models/coin.js +157 -0
  203. package/src/common/models/protocol.js +5 -0
  204. package/src/common/tests/integration/external-apis/ipAddressProviders/getClientIpAddress.test.js +14 -0
  205. package/src/common/utils/cache.js +268 -0
  206. package/src/common/utils/emailAPI.js +18 -0
  207. package/src/common/utils/logging/logger.js +48 -0
  208. package/src/common/utils/logging/logsStorage.js +61 -0
  209. package/src/common/utils/postponeExecution.js +11 -0
  210. package/src/common/utils/safeStringify.js +50 -0
  211. package/src/components/atoms/AssetIcon/AssetIcon.jsx +64 -0
  212. package/src/components/atoms/AssetIcon/asset-icon.module.scss +42 -0
  213. package/src/components/atoms/AssetSelection/AssetSelection.jsx +75 -0
  214. package/src/components/atoms/AssetSelection/asset-selection.module.scss +55 -0
  215. package/src/components/atoms/BackgroundTitle/BackgroundTitle.jsx +44 -0
  216. package/src/components/atoms/BackgroundTitle/background-title.module.scss +52 -0
  217. package/src/components/atoms/InformationMessage/InformationMessage.jsx +60 -0
  218. package/src/components/atoms/InformationMessage/information-message.module.scss +36 -0
  219. package/src/components/atoms/Input/Input.jsx +198 -0
  220. package/src/components/atoms/Input/input.module.scss +107 -0
  221. package/{stories → src/components}/atoms/LoadingDots/LoadingDots.module.scss +1 -1
  222. package/src/components/atoms/NoticeIcon/NoticeIcon.jsx +71 -0
  223. package/src/components/atoms/NoticeIcon/notice-icon.module.scss +14 -0
  224. package/src/components/atoms/QrCode/QrCode.jsx +34 -0
  225. package/src/components/atoms/QrCode/qr-code.module.scss +9 -0
  226. package/src/components/atoms/SupportChat/SupportChat.jsx +48 -0
  227. package/src/components/atoms/Textarea/Textarea.jsx +158 -0
  228. package/src/components/atoms/Textarea/textarea.module.scss +71 -0
  229. package/src/components/atoms/TitleBox/TitleBox.jsx +164 -0
  230. package/src/components/atoms/TitleBox/title-box.module.scss +30 -0
  231. package/src/components/atoms/Tooltip/Tooltip.jsx +70 -0
  232. package/src/components/atoms/Tooltip/tooltip.module.scss +237 -0
  233. package/src/components/atoms/TwoLinesOfText/LinesOfText.jsx +80 -0
  234. package/src/components/atoms/TwoLinesOfText/lines-of-text.module.scss +64 -0
  235. package/src/components/atoms/Validation/Validation.jsx +39 -0
  236. package/src/components/atoms/Validation/validation.module.scss +15 -0
  237. package/{stories → src/components}/atoms/buttons/Button/Button.jsx +5 -1
  238. package/{stories → src/components}/atoms/buttons/Button/Button.module.scss +1 -1
  239. package/src/components/atoms/buttons/Close/Close.jsx +59 -0
  240. package/src/components/atoms/buttons/Close/close.module.scss +75 -0
  241. package/src/components/atoms/buttons/LinkButton/LinkButton.jsx +115 -0
  242. package/src/components/atoms/buttons/LinkButton/link-button.module.scss +49 -0
  243. package/src/components/atoms/buttons/RadioButtonWithText/RadioButtonWithText.jsx +128 -0
  244. package/src/components/atoms/buttons/RadioButtonWithText/radio-button-with-text.module.scss +86 -0
  245. package/src/components/hooks/useCallHandlingErrors.js +26 -0
  246. package/src/components/hooks/useReferredState.js +24 -0
  247. package/src/components/molecules/AmountInput/AmountInput.jsx +421 -0
  248. package/src/components/molecules/AmountInput/amount-input.module.scss +189 -0
  249. package/src/components/molecules/CoinPicker/CoinPicker.jsx +642 -0
  250. package/src/components/molecules/CoinPicker/coin-picker.module.scss +210 -0
  251. package/src/components/molecules/LineWithIconLink/LineWithIconLink.jsx +40 -0
  252. package/src/components/molecules/LineWithIconLink/line-with-icon-link.module.scss +25 -0
  253. package/src/components/molecules/TitledLineWithIconLink/TitledLineWithIconLink.jsx +30 -0
  254. package/src/components/organisms/CoinPickerDialogStep/CoinPickerDialogStep.jsx +66 -0
  255. package/src/components/organisms/Dialog/Dialog.jsx +515 -0
  256. package/src/components/organisms/Dialog/DialogButtons/DialogButtons.jsx +122 -0
  257. package/src/components/organisms/Dialog/DialogButtons/dialog-buttons.module.scss +25 -0
  258. package/src/components/organisms/Dialog/DialogStep/DialogStep.jsx +687 -0
  259. package/src/components/organisms/Dialog/DialogStep/dialog-step.module.scss +383 -0
  260. package/src/components/organisms/Dialog/dialog.module.scss +226 -0
  261. package/src/components/organisms/SwapForm/SwapForm.jsx +1244 -0
  262. package/src/components/organisms/SwapForm/swap-form.module.scss +128 -0
  263. package/src/components/templates/DeterminedErrorDialogStep/DeterminedErrorDialogStep.jsx +77 -0
  264. package/src/components/tests/utils/inputValueProviders/provideFormatOfFloatValueByInputString.test.js +139 -0
  265. package/src/components/tests/utils/urlQueryUtils/getQueryParameterValues.test.js +71 -0
  266. package/src/components/tests/utils/urlQueryUtils/saveQueryParameterAndValues.test.js +144 -0
  267. package/src/components/utils/inputValueProviders.js +58 -0
  268. package/src/components/utils/textUtils.js +18 -0
  269. package/src/components/utils/uiUtils.js +14 -0
  270. package/src/components/utils/urlQueryUtils.js +87 -0
  271. package/src/constants/atoms/Close/close.jsx +5 -0
  272. package/src/constants/atoms/LinkButton/linkButton.jsx +6 -0
  273. package/src/constants/atoms/Tooltip/tooltip.jsx +8 -0
  274. package/src/constants/globalConstants.jsx +4 -0
  275. package/src/constants/organisms/dialog/DialogStep/dialogStep.js +1 -0
  276. package/src/constants/organisms/dialog/dialog.js +29 -0
  277. package/src/index.js +94 -0
  278. package/src/robustExteranlApiCallerService/cacheAndConcurrentRequestsResolver.js +559 -0
  279. package/src/robustExteranlApiCallerService/cachedRobustExternalApiCallerService.js +188 -0
  280. package/src/robustExteranlApiCallerService/cancelProcessing.js +29 -0
  281. package/src/robustExteranlApiCallerService/concurrentCalculationsMetadataHolder.js +103 -0
  282. package/src/robustExteranlApiCallerService/externalApiProvider.js +156 -0
  283. package/src/robustExteranlApiCallerService/externalServicesStatsCollector.js +82 -0
  284. package/src/robustExteranlApiCallerService/robustExternalAPICallerService.js +388 -0
  285. package/src/robustExteranlApiCallerService/tests/robustExternalAPICallerService/robustExternalAPICallerService/callExternalAPI/_performCallAttempt.test.js +787 -0
  286. package/src/robustExteranlApiCallerService/tests/robustExternalAPICallerService/robustExternalAPICallerService/callExternalAPI/callExternalAPI.test.js +745 -0
  287. package/src/robustExteranlApiCallerService/tests/robustExternalAPICallerService/robustExternalAPICallerService/constructor.test.js +31 -0
  288. package/src/swaps-lib/external-apis/swapProvider.js +214 -0
  289. package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +938 -0
  290. package/src/swaps-lib/models/baseSwapCreationInfo.js +43 -0
  291. package/src/swaps-lib/models/existingSwap.js +73 -0
  292. package/src/swaps-lib/models/existingSwapWithFiatData.js +134 -0
  293. package/src/swaps-lib/services/publicSwapService.js +702 -0
  294. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +506 -0
  295. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/createSwap.test.js +1311 -0
  296. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getAllSupportedCurrencies.test.js +76 -0
  297. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getDepositCurrencies.test.js +82 -0
  298. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getSwapInfo.test.js +1892 -0
  299. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getWithdrawalCurrencies.test.js +111 -0
  300. package/src/swaps-lib/test/utils/swapUtils/safeHandleRequestsLimitExceeding.test.js +88 -0
  301. package/src/swaps-lib/utils/swapUtils.js +219 -0
  302. package/stories/stubs/exampleContent.jsx +20 -0
  303. package/styles/_placeholder.scss +1 -1
  304. package/styles/fonts/NunitoSans-Bold.ttf +0 -0
  305. package/styles/fonts/NunitoSans-ExtraBold.ttf +0 -0
  306. package/styles/fonts/NunitoSans-Light.ttf +0 -0
  307. package/styles/fonts/NunitoSans-Regular.ttf +0 -0
  308. package/styles/fonts/NunitoSans-SemiBold.ttf +0 -0
  309. package/styles/global-styles-index.scss +1 -1
  310. package/styles/index.scss +5 -3
  311. package/stories/index.js +0 -2
  312. /package/{stories → src/components}/atoms/LoadingDots/LoadingDots.jsx +0 -0
@@ -0,0 +1,702 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import EventBusInstance from "eventbusjs";
3
+
4
+ import { FiatCurrenciesService } from "../../common/fiatCurrenciesService.js";
5
+ import { improveAndRethrow } from "../../common/errorUtils.js";
6
+ import { safeStringify } from "../../common/utils/safeStringify.js";
7
+ import { Logger } from "../../common/utils/logging/logger.js";
8
+ import { Coin } from "../../common/models/coin.js";
9
+ import { AmountUtils } from "../../common/amountUtils.js";
10
+ import { BaseSwapCreationInfo } from "../models/baseSwapCreationInfo.js";
11
+ import { SwapUtils } from "../utils/swapUtils.js";
12
+ import { SwapspaceSwapProvider } from "../external-apis/swapspaceSwapProvider.js";
13
+ import { SwapProvider } from "../external-apis/swapProvider.js";
14
+
15
+ export class PublicSwapService {
16
+ static PUBLIC_SWAP_CREATED_EVENT = "publicSwapCreatedEvent";
17
+
18
+ static PUBLIC_SWAPS_COMMON_ERRORS = {
19
+ REQUESTS_LIMIT_EXCEEDED: "requestsLimitExceeded",
20
+ };
21
+
22
+ static PUBLIC_SWAP_DETAILS_FAIL_REASONS = {
23
+ AMOUNT_LESS_THAN_MIN_SWAPPABLE: "amountLessThanMinSwappable",
24
+ AMOUNT_HIGHER_THAN_MAX_SWAPPABLE: "amountHigherThanMaxSwappable",
25
+ PAIR_NOT_SUPPORTED: "pairNotSupported",
26
+ NO_FIXED_BUT_HAVE_FLOATING_PUBLIC_SWAP_OPTION:
27
+ "noFixedButHaveFloatingPublicSwapOption",
28
+ NO_FLOATING_BUT_HAVE_FIXED_PUBLIC_SWAP_OPTION:
29
+ "noFloatingButHaveFixedPublicSwapOption",
30
+ };
31
+
32
+ static _fiatDecimalsCount =
33
+ FiatCurrenciesService.getCurrencyDecimalCountByCode("USD");
34
+
35
+ constructor(apiKeysProxyUrl, cache) {
36
+ this._swapProvider = new SwapspaceSwapProvider(
37
+ apiKeysProxyUrl,
38
+ cache,
39
+ () => null,
40
+ false
41
+ );
42
+ }
43
+
44
+ async initialize() {
45
+ try {
46
+ await this._swapProvider.initialize();
47
+ } catch (e) {
48
+ Logger.logError(e, "PublicSwapService.initialize");
49
+ }
50
+ }
51
+
52
+ async getAllSupportedCurrenciesListForPublicSwap() {
53
+ const loggerSource = "getAllSupportedCurrenciesListForPublicSwap";
54
+ try {
55
+ const result = await this._swapProvider.getAllSupportedCurrencies();
56
+ if (
57
+ result.reason ===
58
+ SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
59
+ ) {
60
+ SwapUtils.safeHandleRequestsLimitExceeding();
61
+ return {
62
+ result: false,
63
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
64
+ .REQUESTS_LIMIT_EXCEEDED,
65
+ };
66
+ }
67
+ Logger.log(
68
+ `Retrieved ${result?.coins?.length} supported currencies for swap`,
69
+ loggerSource
70
+ );
71
+ return { result: true, coins: result.coins };
72
+ } catch (e) {
73
+ improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
74
+ }
75
+ }
76
+
77
+ async getDepositCurrenciesListForPublicSwap() {
78
+ try {
79
+ return await this._getCurrenciesListForPublicSwap(false);
80
+ } catch (e) {
81
+ improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
82
+ }
83
+ }
84
+
85
+ async getWithdrawCurrenciesListForPublicSwap() {
86
+ try {
87
+ return await this._getCurrenciesListForPublicSwap(true);
88
+ } catch (e) {
89
+ improveAndRethrow(e, "getWithdrawCurrenciesListForPublicSwap");
90
+ }
91
+ }
92
+
93
+ async _getCurrenciesListForPublicSwap(withdraw = false) {
94
+ const loggerSource = "getCurrenciesListForPublicSwap";
95
+ try {
96
+ const result = withdraw
97
+ ? await this._swapProvider.getWithdrawalCurrencies()
98
+ : await this._swapProvider.getDepositCurrencies();
99
+ if (
100
+ result.reason ===
101
+ SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
102
+ ) {
103
+ SwapUtils.safeHandleRequestsLimitExceeding();
104
+ return {
105
+ result: false,
106
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
107
+ .REQUESTS_LIMIT_EXCEEDED,
108
+ };
109
+ }
110
+ Logger.log(
111
+ `Retrieved ${result?.coins?.length} supported currencies for swap (withdraw=${withdraw})`,
112
+ loggerSource
113
+ );
114
+ return { result: true, coins: result.coins };
115
+ } catch (e) {
116
+ improveAndRethrow(e, loggerSource);
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Retrieves initial data for swapping two coins.
122
+ *
123
+ * @param fromCoin {Coin}
124
+ * @param toCoin {Coin}
125
+ * @return {Promise<{
126
+ * result: true,
127
+ * min: string,
128
+ * fiatMin: (number|null),
129
+ * max: string,
130
+ * fiatMax: (number|null),
131
+ * rate: (string|null)
132
+ * }|{
133
+ * result: false,
134
+ * reason: string
135
+ * }>}
136
+ */
137
+ async getInitialPublicSwapData(fromCoin, toCoin) {
138
+ try {
139
+ const result = await SwapUtils.getInitialSwapData(
140
+ this._swapProvider,
141
+ fromCoin,
142
+ toCoin
143
+ );
144
+ if (!result.result) {
145
+ if (
146
+ result.reason ===
147
+ SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
148
+ ) {
149
+ SwapUtils.safeHandleRequestsLimitExceeding();
150
+ return {
151
+ result: false,
152
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
153
+ .REQUESTS_LIMIT_EXCEEDED,
154
+ };
155
+ }
156
+ if (
157
+ result.reason ===
158
+ SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
159
+ ) {
160
+ return {
161
+ result: false,
162
+ reason: PublicSwapService
163
+ .PUBLIC_SWAP_DETAILS_FAIL_REASONS
164
+ .PAIR_NOT_SUPPORTED,
165
+ };
166
+ }
167
+ }
168
+ return result;
169
+ } catch (e) {
170
+ improveAndRethrow(e, "getInitialPublicSwapData");
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Retrieves swap details that can be used to create swap.
176
+ *
177
+ * @param fromCoin {Coin}
178
+ * @param toCoin {Coin}
179
+ * @param fromAmountCoins {string}
180
+ * @param [fixed=false] {boolean|null} null means fixed or float doesn't matter
181
+ * @param [withoutFiat=false] {boolean} pass true if you don't need the fiat equivalent - this will diminish requests count
182
+ * @return {Promise<{
183
+ * result: false,
184
+ * reason: string,
185
+ * min: (string|null),
186
+ * max: (string|null),
187
+ * rate: (string|undefined),
188
+ * fiatMin: (number|null),
189
+ * fiatMax: (number|null)
190
+ * }|{
191
+ * result: true,
192
+ * swapCreationInfo: BaseSwapCreationInfo
193
+ * }>}
194
+ */
195
+ async getPublicSwapDetails(
196
+ fromCoin,
197
+ toCoin,
198
+ fromAmountCoins,
199
+ fixed = false,
200
+ withoutFiat = false
201
+ ) {
202
+ const loggerSource = "getPublicSwapDetails";
203
+ try {
204
+ const coinUsdtRate = withoutFiat
205
+ ? null
206
+ : (await this._swapProvider.getCoinToUSDTRate(fromCoin))
207
+ ?.rate ?? null;
208
+ const details = await this._swapProvider.getSwapInfo(
209
+ fromCoin,
210
+ toCoin,
211
+ fromAmountCoins,
212
+ fixed,
213
+ coinUsdtRate
214
+ );
215
+ const min = details.smallestMin;
216
+ const max = details.greatestMax;
217
+ let fiatMin = null,
218
+ fiatMax = null;
219
+ if (coinUsdtRate != null) {
220
+ if (min != null) {
221
+ fiatMin = BigNumber(min)
222
+ .times(coinUsdtRate)
223
+ .toFixed(PublicSwapService._fiatDecimalsCount);
224
+ }
225
+ if (max != null) {
226
+ fiatMax = BigNumber(max)
227
+ .times(coinUsdtRate)
228
+ .toFixed(PublicSwapService._fiatDecimalsCount);
229
+ }
230
+ }
231
+
232
+ const composeFailResult = (reason) => ({
233
+ result: false,
234
+ reason: reason,
235
+ min: min ?? null,
236
+ fiatMin: fiatMin,
237
+ max: max ?? null,
238
+ fiatMax: fiatMax,
239
+ rate: details.rate ?? null,
240
+ });
241
+
242
+ if (!details.result) {
243
+ if (
244
+ details?.reason ===
245
+ SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
246
+ ) {
247
+ return composeFailResult(
248
+ PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS
249
+ .PAIR_NOT_SUPPORTED
250
+ );
251
+ } else if (
252
+ details?.reason ===
253
+ SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
254
+ ) {
255
+ SwapUtils.safeHandleRequestsLimitExceeding();
256
+ return composeFailResult(
257
+ PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
258
+ .REQUESTS_LIMIT_EXCEEDED
259
+ );
260
+ } else if (
261
+ details?.reason ===
262
+ SwapProvider.NO_SWAPS_REASONS.NO_FLOATING_BUT_HAVE_FIXED
263
+ ) {
264
+ return composeFailResult(
265
+ PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS
266
+ .NO_FLOATING_BUT_HAVE_FIXED_PUBLIC_SWAP_OPTION
267
+ );
268
+ } else if (
269
+ details?.reason ===
270
+ SwapProvider.NO_SWAPS_REASONS.NO_FIXED_BUT_HAVE_FLOATING
271
+ ) {
272
+ return composeFailResult(
273
+ PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS
274
+ .NO_FIXED_BUT_HAVE_FLOATING_PUBLIC_SWAP_OPTION
275
+ );
276
+ }
277
+ }
278
+
279
+ const fromAmountBigNumber = BigNumber(fromAmountCoins);
280
+ if (typeof min === "string" && fromAmountBigNumber.lt(min)) {
281
+ return composeFailResult(
282
+ PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS
283
+ .AMOUNT_LESS_THAN_MIN_SWAPPABLE
284
+ );
285
+ } else if (typeof max === "string" && fromAmountBigNumber.gt(max)) {
286
+ return composeFailResult(
287
+ PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS
288
+ .AMOUNT_HIGHER_THAN_MAX_SWAPPABLE
289
+ );
290
+ }
291
+
292
+ const toAmountCoins = AmountUtils.trim(
293
+ fromAmountBigNumber.times(details.rate),
294
+ fromCoin.digits
295
+ );
296
+ const result = {
297
+ result: true,
298
+ swapCreationInfo: new BaseSwapCreationInfo(
299
+ fromCoin,
300
+ toCoin,
301
+ fromAmountCoins,
302
+ toAmountCoins,
303
+ details.rate,
304
+ details.rawSwapData,
305
+ min,
306
+ fiatMin,
307
+ max,
308
+ fiatMax,
309
+ details.durationMinutesRange,
310
+ details.fixed
311
+ ),
312
+ };
313
+ Logger.log(
314
+ `Result: ${safeStringify({
315
+ result: result.result,
316
+ swapCreationInfo: {
317
+ ...result.swapCreationInfo,
318
+ fromCoin: result?.swapCreationInfo?.fromCoin?.ticker,
319
+ toCoin: result?.swapCreationInfo?.toCoin?.ticker,
320
+ },
321
+ })}`,
322
+ loggerSource
323
+ );
324
+
325
+ return result;
326
+ } catch (e) {
327
+ improveAndRethrow(e, loggerSource);
328
+ }
329
+ }
330
+
331
+ /**
332
+ * Creates swap by given params.
333
+ *
334
+ * @param fromCoin {Coin}
335
+ * @param toCoin {Coin}
336
+ * @param fromAmount {string}
337
+ * @param swapCreationInfo {BaseSwapCreationInfo}
338
+ * @param toAddress {string}
339
+ * @param refundAddress {string}
340
+ * @param clientIp {string}
341
+ * @param [toCurrencyExtraId] {string}
342
+ * @param [refundExtraId] {string}
343
+ * @return {Promise<{
344
+ * result: true,
345
+ * fiatCurrencyCode: string,
346
+ * toCoin: Coin,
347
+ * fromAmountFiat: (number|null),
348
+ * address: string,
349
+ * durationMinutesRange: string,
350
+ * fromAmount: string,
351
+ * toAmount: string,
352
+ * toAmountFiat: (number|null),
353
+ * fiatCurrencyDecimals: number,
354
+ * fromCoin: Coin,
355
+ * rate: string,
356
+ * swapId: string,
357
+ * fromCurrencyExtraId: string,
358
+ * fixed: boolean
359
+ * }|{
360
+ * result: false,
361
+ * reason: string
362
+ * }>}
363
+ */
364
+ async createPublicSwap(
365
+ fromCoin,
366
+ toCoin,
367
+ fromAmount,
368
+ swapCreationInfo,
369
+ toAddress,
370
+ refundAddress,
371
+ clientIp,
372
+ toCurrencyExtraId,
373
+ refundExtraId
374
+ ) {
375
+ const loggerSource = "createPublicSwap";
376
+ try {
377
+ if (
378
+ !(fromCoin instanceof Coin) ||
379
+ !(toCoin instanceof Coin) ||
380
+ typeof fromAmount !== "string" ||
381
+ typeof toAddress !== "string" ||
382
+ typeof refundAddress !== "string" ||
383
+ !(swapCreationInfo instanceof BaseSwapCreationInfo)
384
+ ) {
385
+ throw new Error(
386
+ `Wrong input: ${fromCoin.ticker} ${toCoin.ticker} ${fromAmount} ${swapCreationInfo}`
387
+ );
388
+ }
389
+ Logger.log(
390
+ `Start: ${fromAmount} ${fromCoin.ticker} -> ${
391
+ toCoin.ticker
392
+ }. Details: ${safeStringify({
393
+ ...swapCreationInfo,
394
+ fromCoin: swapCreationInfo?.fromCoin?.ticker,
395
+ toCoin: swapCreationInfo?.toCoin?.ticker,
396
+ })}`,
397
+ loggerSource
398
+ );
399
+
400
+ const result = await this._swapProvider.createSwap(
401
+ fromCoin,
402
+ toCoin,
403
+ fromAmount,
404
+ toAddress,
405
+ refundAddress,
406
+ swapCreationInfo.rawSwapData,
407
+ clientIp,
408
+ swapCreationInfo.fixed,
409
+ toCurrencyExtraId,
410
+ refundExtraId
411
+ );
412
+ Logger.log(
413
+ `Created:${safeStringify({
414
+ ...result,
415
+ fromCoin: fromCoin?.ticker,
416
+ toCoin: toCoin?.ticker,
417
+ })}`,
418
+ loggerSource
419
+ );
420
+ if (!result?.result) {
421
+ if (
422
+ result?.reason ===
423
+ SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
424
+ ) {
425
+ SwapUtils.safeHandleRequestsLimitExceeding();
426
+ return {
427
+ result: false,
428
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
429
+ .REQUESTS_LIMIT_EXCEEDED,
430
+ };
431
+ }
432
+ if (
433
+ result?.reason ===
434
+ SwapProvider.CREATION_FAIL_REASONS.RETRIABLE_FAIL
435
+ ) {
436
+ // TODO: [feature, high] implement retrying if one partner fail and we have another partners task_id=a07e367e488f4a4899613ac9056fa359
437
+ // return {
438
+ // result: false,
439
+ // reason: PublicSwapService.SWAP_CREATION_FAIL_REASONS.RETRIABLE_FAIL,
440
+ // };
441
+ }
442
+ }
443
+ if (result.result && result?.swapId) {
444
+ let fromAmountFiat = null,
445
+ toAmountFiat = null;
446
+ try {
447
+ const fromCoinUsdtRate =
448
+ (await this._swapProvider.getCoinToUSDTRate(fromCoin))
449
+ ?.rate ?? null;
450
+ const toCoinUsdtRate =
451
+ (await this._swapProvider.getCoinToUSDTRate(fromCoin))
452
+ ?.rate ?? null;
453
+ if (fromCoinUsdtRate != null && result.fromAmount != null) {
454
+ fromAmountFiat = BigNumber(result.fromAmount)
455
+ .times(fromCoinUsdtRate)
456
+ .toFixed(PublicSwapService._fiatDecimalsCount);
457
+ }
458
+ if (toCoinUsdtRate != null && result.toAmount != null) {
459
+ toAmountFiat = BigNumber(result.toAmount)
460
+ .times(toCoinUsdtRate)
461
+ .toFixed(PublicSwapService._fiatDecimalsCount);
462
+ }
463
+ } catch (e) {
464
+ Logger.logError(
465
+ e,
466
+ loggerSource,
467
+ "Failed to calculate fiat amounts for result"
468
+ );
469
+ }
470
+
471
+ // TODO: feature, cirtical] add GA event. task_id=tbd
472
+ EventBusInstance.dispatch(
473
+ PublicSwapService.PUBLIC_SWAP_CREATED_EVENT,
474
+ null,
475
+ fromCoin.ticker,
476
+ toCoin.ticker,
477
+ fromAmountFiat
478
+ );
479
+
480
+ const toReturn = {
481
+ result: true,
482
+ swapId: result.swapId,
483
+ fromCoin: fromCoin,
484
+ toCoin: toCoin,
485
+ fromAmount: result.fromAmount,
486
+ toAmount: result.toAmount,
487
+ fromAmountFiat: fromAmountFiat,
488
+ toAmountFiat: toAmountFiat,
489
+ fiatCurrencyCode: "USD",
490
+ fiatCurrencyDecimals: PublicSwapService._fiatDecimalsCount,
491
+ rate: result.rate,
492
+ durationMinutesRange: swapCreationInfo.durationMinutesRange,
493
+ address: result.fromAddress, // CRITICAL: this is the address to send coins to swaps provider
494
+ fromCurrencyExtraId: result.fromCurrencyExtraId ?? "", // CRITICAL: this is the extra ID for address to send coins to swaps provider
495
+ fixed: result.fixed,
496
+ };
497
+
498
+ this._savePublicSwapIdLocally(result.swapId);
499
+
500
+ Logger.log(
501
+ `Returning: ${safeStringify({
502
+ ...toReturn,
503
+ fromCoin: fromCoin?.ticker,
504
+ toCoin: toCoin?.ticker,
505
+ })}`,
506
+ loggerSource
507
+ );
508
+ return toReturn;
509
+ }
510
+
511
+ throw new Error(
512
+ `Unexpected result from provider ${safeStringify(result)}`
513
+ );
514
+ } catch (e) {
515
+ improveAndRethrow(e, loggerSource);
516
+ }
517
+ }
518
+
519
+ /**
520
+ * Retrieves swap details and status for existing swaps by their ids.
521
+ *
522
+ * @param swapIds {string[]}
523
+ * @return {Promise<{
524
+ * result: true,
525
+ * swaps: ExistingSwapWithFiatData[]
526
+ * }|{
527
+ * result: false,
528
+ * reason: string
529
+ * }>}
530
+ * error reason is one of PUBLIC_SWAPS_COMMON_ERRORS
531
+ */
532
+ async getPublicExistingSwapDetailsAndStatus(swapIds) {
533
+ const loggerSource = "getPublicExistingSwapDetailsAndStatus";
534
+ try {
535
+ const result =
536
+ await SwapUtils.getExistingSwapsDetailsWithFiatAmounts(
537
+ this._swapProvider,
538
+ swapIds
539
+ );
540
+ if (!result?.result) {
541
+ if (
542
+ result.reason ===
543
+ SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
544
+ ) {
545
+ SwapUtils.safeHandleRequestsLimitExceeding();
546
+ return {
547
+ result: false,
548
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
549
+ .REQUESTS_LIMIT_EXCEEDED,
550
+ };
551
+ }
552
+ throw new Error("Unknown reason: " + result?.reason);
553
+ }
554
+
555
+ return result;
556
+ } catch (e) {
557
+ improveAndRethrow(e, loggerSource);
558
+ }
559
+ }
560
+
561
+ /**
562
+ * Retrieves the whole available swaps history by ids saved locally.
563
+ *
564
+ * @return {Promise<{
565
+ * result: true,
566
+ * swaps: ExistingSwapWithFiatData[]
567
+ * }|{
568
+ * result: false,
569
+ * reason: string
570
+ * }>}
571
+ */
572
+ async getPublicSwapsHistory() {
573
+ try {
574
+ const swapIds = this._getPublicSwapIdsSavedLocally();
575
+ if (swapIds.length) {
576
+ return await this.getPublicExistingSwapDetailsAndStatus(
577
+ swapIds
578
+ );
579
+ }
580
+ return { result: true, swaps: [] };
581
+ } catch (e) {
582
+ improveAndRethrow(e, "getPublicSwapsHistory");
583
+ }
584
+ }
585
+
586
+ /**
587
+ * @param swapId {string}
588
+ * @private
589
+ */
590
+ _savePublicSwapIdLocally(swapId) {
591
+ if (typeof window !== "undefined") {
592
+ try {
593
+ const saved = localStorage.getItem("publicSwapIds");
594
+ const ids =
595
+ typeof saved === "string" && saved.length > 0
596
+ ? saved.split(",")
597
+ : [];
598
+ ids.push(swapId);
599
+ localStorage.setItem("publicSwapIds", ids.join(","));
600
+ } catch (e) {
601
+ improveAndRethrow(e, "_savePublicSwapIdLocally");
602
+ }
603
+ }
604
+ }
605
+
606
+ /**
607
+ * @private
608
+ * @return {string[]}
609
+ */
610
+ _getPublicSwapIdsSavedLocally() {
611
+ if (typeof window !== "undefined") {
612
+ try {
613
+ const saved = localStorage.getItem("publicSwapIds");
614
+ return typeof saved === "string" && saved.length > 0
615
+ ? saved.split(",")
616
+ : [];
617
+ } catch (e) {
618
+ improveAndRethrow(e, "_getPublicSwapIdsSavedLocally");
619
+ }
620
+ }
621
+ }
622
+
623
+ /**
624
+ * @param coinOrTicker {Coin|string}
625
+ * @return {string} icon URL (ready to use)
626
+ */
627
+ getAssetIconUrl(coinOrTicker) {
628
+ return this._swapProvider.getIconUrl(coinOrTicker);
629
+ }
630
+
631
+ /**
632
+ * @param ticker {string}
633
+ * @return {Coin|null}
634
+ */
635
+ getCoinByTickerIfPresent(ticker) {
636
+ return this._swapProvider.getCoinByTickerIfPresent(ticker);
637
+ }
638
+
639
+ /**
640
+ * TODO: [feature, moderate] add other fiat currencies support. task_id=5490e21b8b9c4f89a2247b28db3c9e0a
641
+ * @param asset {Coin}
642
+ * @return {Promise<string|null>}
643
+ */
644
+ async getAssetToUsdtRate(asset) {
645
+ try {
646
+ const result = await this._swapProvider.getCoinToUSDTRate(asset);
647
+ return result?.rate ?? null;
648
+ } catch (e) {
649
+ improveAndRethrow(e, "getAssetToUsdtRate");
650
+ }
651
+ }
652
+
653
+ /**
654
+ * @param asset {Coin}
655
+ * @param address {string}
656
+ * @return {boolean}
657
+ */
658
+ isAddressValidForAsset(asset, address) {
659
+ try {
660
+ return this._swapProvider.isAddressValidForAsset(asset, address);
661
+ } catch (e) {
662
+ improveAndRethrow(e, "isAddressValidForAsset");
663
+ }
664
+ }
665
+
666
+ /**
667
+ * Retrieves token by contract address.
668
+ *
669
+ * @param addressString {string}
670
+ * @return {Promise<Coin|null>}
671
+ */
672
+ async getTokenByContractAddress(addressString) {
673
+ try {
674
+ if (!addressString) return null;
675
+ const addressLowerCase = addressString.toLowerCase();
676
+ const allCoins =
677
+ await this._swapProvider.getAllSupportedCurrencies();
678
+ if (allCoins.result) {
679
+ return allCoins.coins.find(
680
+ (coin) =>
681
+ coin.tokenAddress &&
682
+ coin.tokenAddress.toLowerCase() === addressLowerCase
683
+ );
684
+ }
685
+ } catch (e) {
686
+ Logger.logError(e, "getTokenByContractAddress");
687
+ }
688
+ return null;
689
+ }
690
+
691
+ /**
692
+ * @param asset {Coin}
693
+ * @return {string|null}
694
+ */
695
+ getExtraIdNameIfPresentForAsset(asset) {
696
+ try {
697
+ return this._swapProvider.getExtraIdNameIfPresent(asset);
698
+ } catch (e) {
699
+ improveAndRethrow(e, "getExtraIdNameIfPresentForAsset");
700
+ }
701
+ }
702
+ }