@rabbitio/ui-kit 1.0.0-beta.12 → 1.0.0-beta.121

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 (402) hide show
  1. package/.env.example +1 -0
  2. package/.gitlab-ci.yml +29 -0
  3. package/.husky/commit-msg +19 -0
  4. package/.husky/pre-push +1 -0
  5. package/README.md +14 -4
  6. package/coverage/base.css +224 -0
  7. package/coverage/block-navigation.js +87 -0
  8. package/coverage/clover.xml +19749 -0
  9. package/coverage/coverage-final.json +122 -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 +151 -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 +172 -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 +253 -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 +391 -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 +1234 -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 +211 -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 +388 -0
  47. package/coverage/rabbit-ui-kit/src/robust-api-caller/cacheAndConcurrentRequestsResolver.js.html +1660 -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/changeHeroSwapProvider.js.html +2800 -0
  56. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/changeNowSwapProvider.js.html +2644 -0
  57. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/exolixSwapProvider.js.html +1942 -0
  58. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/goexmeSwapProvider.js.html +2389 -0
  59. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/index.html +236 -0
  60. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/letsExchangeSwapProvider.js.html +1666 -0
  61. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/retriableErrorsUtils.js.html +274 -0
  62. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapProvider.js.html +1888 -0
  63. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapspaceSwapProvider.js.html +1981 -0
  64. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/utils.js.html +163 -0
  65. package/coverage/rabbit-ui-kit/src/swaps-lib/models/baseSwapCreationInfo.js.html +319 -0
  66. package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwap.js.html +514 -0
  67. package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwapWithFiatData.js.html +529 -0
  68. package/coverage/rabbit-ui-kit/src/swaps-lib/models/index.html +176 -0
  69. package/coverage/rabbit-ui-kit/src/swaps-lib/models/partner.js.html +166 -0
  70. package/coverage/rabbit-ui-kit/src/swaps-lib/models/swapProviderCoinInfo.js.html +337 -0
  71. package/coverage/rabbit-ui-kit/src/swaps-lib/services/index.html +116 -0
  72. package/coverage/rabbit-ui-kit/src/swaps-lib/services/publicSwapService.js.html +1654 -0
  73. package/coverage/rabbit-ui-kit/src/swaps-lib/utils/index.html +116 -0
  74. package/coverage/rabbit-ui-kit/src/swaps-lib/utils/swapUtils.js.html +706 -0
  75. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/arrowIcon.jsx.html +124 -0
  76. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/arrowTosca.jsx.html +127 -0
  77. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/arrowWhite.jsx.html +127 -0
  78. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/darkRectangle.jsx.html +106 -0
  79. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/determinedError.jsx.html +439 -0
  80. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/failedValidationIcon.jsx.html +202 -0
  81. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/index.html +281 -0
  82. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/infoIcon.jsx.html +133 -0
  83. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/messageIcon.jsx.html +346 -0
  84. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/noticeQuestionIcon.jsx.html +247 -0
  85. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/successfulValidationIcon.jsx.html +163 -0
  86. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/supportDialogImage.jsx.html +268 -0
  87. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/walletIcon.jsx.html +151 -0
  88. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetIcon/AssetIcon.jsx.html +256 -0
  89. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetIcon/index.html +116 -0
  90. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetSelection/AssetSelection.jsx.html +289 -0
  91. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetSelection/index.html +116 -0
  92. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/BackgroundTitle/BackgroundTitle.jsx.html +187 -0
  93. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/BackgroundTitle/index.html +116 -0
  94. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/InformationMessage/InformationMessage.jsx.html +238 -0
  95. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/InformationMessage/index.html +116 -0
  96. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Input/Input.jsx.html +634 -0
  97. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Input/index.html +116 -0
  98. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/LoadingDots/LoadingDots.jsx.html +196 -0
  99. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/LoadingDots/index.html +116 -0
  100. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/NoticeIcon/NoticeIcon.jsx.html +277 -0
  101. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/NoticeIcon/index.html +116 -0
  102. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/QrCode/QrCode.jsx.html +199 -0
  103. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/QrCode/index.html +116 -0
  104. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/RateSelector/RateSelector.jsx.html +175 -0
  105. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/RateSelector/index.html +116 -0
  106. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/SupportChat/SupportChat.jsx.html +217 -0
  107. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/SupportChat/index.html +116 -0
  108. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Textarea/Textarea.jsx.html +529 -0
  109. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Textarea/index.html +116 -0
  110. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TitleBox/TitleBox.jsx.html +508 -0
  111. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TitleBox/index.html +116 -0
  112. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Tooltip/Tooltip.jsx.html +316 -0
  113. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Tooltip/index.html +116 -0
  114. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TwoLinesOfText/LinesOfText.jsx.html +313 -0
  115. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TwoLinesOfText/index.html +116 -0
  116. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Validation/Validation.jsx.html +202 -0
  117. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Validation/index.html +116 -0
  118. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Button/Button.jsx.html +733 -0
  119. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Button/index.html +116 -0
  120. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Close/Close.jsx.html +259 -0
  121. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Close/index.html +116 -0
  122. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/LinkButton/LinkButton.jsx.html +433 -0
  123. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/LinkButton/index.html +116 -0
  124. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/RadioButtonWithText/RadioButtonWithText.jsx.html +415 -0
  125. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/RadioButtonWithText/index.html +116 -0
  126. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/AmountInput/AmountInput.jsx.html +1429 -0
  127. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/AmountInput/index.html +116 -0
  128. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/CoinPicker/CoinPicker.jsx.html +1474 -0
  129. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/CoinPicker/index.html +116 -0
  130. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/ColoredNotice/ColoredNotice.jsx.html +241 -0
  131. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/ColoredNotice/index.html +116 -0
  132. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LineWithIconLink/LineWithIconLink.jsx.html +190 -0
  133. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LineWithIconLink/index.html +116 -0
  134. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LogoCarousel/LogoCarousel.jsx.html +307 -0
  135. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LogoCarousel/index.html +116 -0
  136. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/SearchableCoinsList/SearchableCoinsList.jsx.html +427 -0
  137. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/SearchableCoinsList/index.html +116 -0
  138. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/TitledLineWithIconLink/TitledLineWithIconLink.jsx.html +181 -0
  139. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/TitledLineWithIconLink/index.html +116 -0
  140. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/CoinPickerDialogStep/CoinPickerDialogStep.jsx.html +283 -0
  141. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/CoinPickerDialogStep/index.html +116 -0
  142. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/Dialog.jsx.html +1567 -0
  143. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogButtons/DialogButtons.jsx.html +481 -0
  144. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogButtons/index.html +116 -0
  145. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogStep/DialogStep.jsx.html +1747 -0
  146. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogStep/index.html +116 -0
  147. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/index.html +116 -0
  148. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/SwapForm/SwapForm.jsx.html +4375 -0
  149. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/SwapForm/index.html +116 -0
  150. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/WaitlistSubscription/WaitlistSubscription.jsx.html +559 -0
  151. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/WaitlistSubscription/index.html +116 -0
  152. package/coverage/rabbit-ui-kit/src/ui-kit/components/templates/DeterminedErrorDialogStep/DeterminedErrorDialogStep.jsx.html +316 -0
  153. package/coverage/rabbit-ui-kit/src/ui-kit/components/templates/DeterminedErrorDialogStep/index.html +116 -0
  154. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/index.html +146 -0
  155. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/useCallHandlingErrors.js.html +166 -0
  156. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/useIsHydrated.js.html +121 -0
  157. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/useReferredState.js.html +157 -0
  158. package/coverage/rabbit-ui-kit/src/ui-kit/utils/index.html +176 -0
  159. package/coverage/rabbit-ui-kit/src/ui-kit/utils/inputValueProviders.js.html +235 -0
  160. package/coverage/rabbit-ui-kit/src/ui-kit/utils/searchCoins.js.html +259 -0
  161. package/coverage/rabbit-ui-kit/src/ui-kit/utils/textUtils.js.html +139 -0
  162. package/coverage/rabbit-ui-kit/src/ui-kit/utils/uiUtils.js.html +121 -0
  163. package/coverage/rabbit-ui-kit/src/ui-kit/utils/urlQueryUtils.js.html +271 -0
  164. package/coverage/rabbit-ui-kit/stories/atoms/BackgroundTitle.stories.jsx.html +202 -0
  165. package/coverage/rabbit-ui-kit/stories/atoms/LinesOfText.stories.jsx.html +283 -0
  166. package/coverage/rabbit-ui-kit/stories/atoms/LoadingDots.stories.jsx.html +226 -0
  167. package/coverage/rabbit-ui-kit/stories/atoms/QrCode.stories.jsx.html +175 -0
  168. package/coverage/rabbit-ui-kit/stories/atoms/RateSelector.stories.jsx.html +136 -0
  169. package/coverage/rabbit-ui-kit/stories/atoms/Validation.stories.jsx.html +178 -0
  170. package/coverage/rabbit-ui-kit/stories/atoms/buttons/Button.stories.jsx.html +883 -0
  171. package/coverage/rabbit-ui-kit/stories/atoms/buttons/Close.stories.jsx.html +211 -0
  172. package/coverage/rabbit-ui-kit/stories/atoms/buttons/LinkButton.stories.jsx.html +301 -0
  173. package/coverage/rabbit-ui-kit/stories/atoms/buttons/index.html +146 -0
  174. package/coverage/rabbit-ui-kit/stories/atoms/index.html +191 -0
  175. package/coverage/rabbit-ui-kit/stories/molecules/AmountInput.stories.jsx.html +289 -0
  176. package/coverage/rabbit-ui-kit/stories/molecules/CoinPicker.stories.jsx.html +322 -0
  177. package/coverage/rabbit-ui-kit/stories/molecules/ColoredNotice.stories.jsx.html +178 -0
  178. package/coverage/rabbit-ui-kit/stories/molecules/LineWithIconLink.stories.jsx.html +154 -0
  179. package/coverage/rabbit-ui-kit/stories/molecules/LogoCarousel.stories.jsx.html +235 -0
  180. package/coverage/rabbit-ui-kit/stories/molecules/TitledLineWithIconLink.stories.jsx.html +160 -0
  181. package/coverage/rabbit-ui-kit/stories/molecules/index.html +191 -0
  182. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/Dialog.stories.jsx.html +523 -0
  183. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/DialogButtons.stories.jsx.html +328 -0
  184. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/index.html +116 -0
  185. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/DialogStep.stories.jsx.html +337 -0
  186. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/index.html +116 -0
  187. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/index.html +116 -0
  188. package/coverage/rabbit-ui-kit/stories/organisms/WaitlistSubscription.stories.jsx.html +151 -0
  189. package/coverage/rabbit-ui-kit/stories/organisms/index.html +116 -0
  190. package/coverage/rabbit-ui-kit/stories/stubs/coins.jsx.html +6880 -0
  191. package/coverage/rabbit-ui-kit/stories/stubs/exampleContent.jsx.html +145 -0
  192. package/coverage/rabbit-ui-kit/stories/stubs/index.html +131 -0
  193. package/coverage/rabbit-ui-kit/stories/templates/DeterminedErrorDialogStep.stories.jsx.html +190 -0
  194. package/coverage/rabbit-ui-kit/stories/templates/index.html +116 -0
  195. package/coverage/sort-arrow-sprite.png +0 -0
  196. package/coverage/sorter.js +196 -0
  197. package/dist/global.css +197 -0
  198. package/dist/global.css.map +1 -0
  199. package/dist/index.cjs +15089 -1593
  200. package/dist/index.cjs.map +1 -1
  201. package/dist/index.css +2352 -8493
  202. package/dist/index.css.map +1 -1
  203. package/dist/index.modern.js +11801 -1298
  204. package/dist/index.modern.js.map +1 -1
  205. package/dist/index.module.js +15003 -1594
  206. package/dist/index.module.js.map +1 -1
  207. package/dist/index.umd.js +15081 -1596
  208. package/dist/index.umd.js.map +1 -1
  209. package/package.json +35 -9
  210. package/raw +1000 -0
  211. package/src/common-apis/adapters/analyticsAdapters/googleAnalyticsAdapter.js +22 -0
  212. package/src/common-apis/adapters/analyticsAdapters/metrikaAdapter.js +29 -0
  213. package/src/common-apis/adapters/analyticsAdapters/mixpanelAdapter.js +38 -0
  214. package/src/common-apis/adapters/axiosAdapter.js +35 -0
  215. package/src/common-apis/adapters/qrUtils.js +18 -0
  216. package/src/common-apis/external-apis/apiGroups.js +56 -0
  217. package/src/common-apis/external-apis/emailAPI.js +16 -0
  218. package/src/common-apis/external-apis/ipAddressProviders.js +102 -0
  219. package/src/common-apis/globalConstants.jsx +3 -0
  220. package/src/{common → common-apis}/models/coin.js +98 -7
  221. package/src/{common → common-apis/services}/fiatCurrenciesService.js +4 -12
  222. package/src/common-apis/tests/integration/external-apis/ipAddressProviders/getClientIpAddress.test.js +18 -0
  223. package/src/common-apis/tests/units/utils/amountUtils/composeRateText.test.js +152 -0
  224. package/src/{common → common-apis/utils}/amountUtils.js +100 -140
  225. package/src/{common → common-apis}/utils/cache.js +15 -41
  226. package/src/{common → common-apis/utils}/errorUtils.js +15 -0
  227. package/src/{common → common-apis}/utils/logging/logger.js +7 -13
  228. package/src/common-apis/utils/postponeExecution.js +11 -0
  229. package/src/common-apis/utils/rabbitTicker.js +24 -0
  230. package/src/index.js +91 -14
  231. package/src/robust-api-caller/cacheAndConcurrentRequestsResolver.js +525 -0
  232. package/src/robust-api-caller/cachedRobustExternalApiCallerService.js +147 -0
  233. package/src/robust-api-caller/cancelProcessing.js +29 -0
  234. package/src/robust-api-caller/concurrentCalculationsMetadataHolder.js +75 -0
  235. package/src/robust-api-caller/externalApiProvider.js +156 -0
  236. package/src/robust-api-caller/externalServicesStatsCollector.js +78 -0
  237. package/src/robust-api-caller/robustExternalAPICallerService.js +304 -0
  238. package/src/robust-api-caller/tests/robustExternalAPICallerService/robustExternalAPICallerService/callExternalAPI/_performCallAttempt.test.js +533 -0
  239. package/src/robust-api-caller/tests/robustExternalAPICallerService/robustExternalAPICallerService/callExternalAPI/callExternalAPI.test.js +532 -0
  240. package/src/robust-api-caller/tests/robustExternalAPICallerService/robustExternalAPICallerService/constructor.test.js +19 -0
  241. package/src/swaps-lib/external-apis/changeHeroSwapProvider.js +905 -0
  242. package/src/swaps-lib/external-apis/changeNowSwapProvider.js +853 -0
  243. package/src/swaps-lib/external-apis/exolixSwapProvider.js +619 -0
  244. package/src/swaps-lib/external-apis/goexmeSwapProvider.js +768 -0
  245. package/src/swaps-lib/external-apis/letsExchangeSwapProvider.js +527 -0
  246. package/src/swaps-lib/external-apis/retriableErrorsUtils.js +63 -0
  247. package/src/swaps-lib/external-apis/swapProvider.js +457 -25
  248. package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +320 -486
  249. package/src/swaps-lib/external-apis/utils.js +26 -0
  250. package/src/swaps-lib/models/baseSwapCreationInfo.js +78 -0
  251. package/src/swaps-lib/models/existingSwap.js +101 -16
  252. package/src/swaps-lib/models/existingSwapWithFiatData.js +148 -0
  253. package/src/swaps-lib/models/partner.js +27 -0
  254. package/src/swaps-lib/models/swapProviderCoinInfo.js +84 -0
  255. package/src/swaps-lib/services/publicSwapService.js +523 -0
  256. package/src/swaps-lib/test/external-apis/changeHeroSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +155 -0
  257. package/src/swaps-lib/test/external-apis/changeHeroSwapProvider/createSwap.test.js +702 -0
  258. package/src/swaps-lib/test/external-apis/changeHeroSwapProvider/getExistingSwapsDetailsAndStatus.test.js +501 -0
  259. package/src/swaps-lib/test/external-apis/changeHeroSwapProvider/getSwapInfo.test.js +425 -0
  260. package/src/swaps-lib/test/external-apis/changeNowSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +83 -0
  261. package/src/swaps-lib/test/external-apis/changeNowSwapProvider/_providerHelpers.test.js +54 -0
  262. package/src/swaps-lib/test/external-apis/changeNowSwapProvider/_validateAddressWithProvider.test.js +49 -0
  263. package/src/swaps-lib/test/external-apis/changeNowSwapProvider/createSwap.test.js +938 -0
  264. package/src/swaps-lib/test/external-apis/changeNowSwapProvider/getExistingSwapsDetailsAndStatus.test.js +353 -0
  265. package/src/swaps-lib/test/external-apis/changeNowSwapProvider/getSwapInfo.test.js +342 -0
  266. package/src/swaps-lib/test/external-apis/exolixSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +34 -0
  267. package/src/swaps-lib/test/external-apis/exolixSwapProvider/createSwap.test.js +1081 -0
  268. package/src/swaps-lib/test/external-apis/exolixSwapProvider/getSwapInfo.test.js +611 -0
  269. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/_convertCurrencyMeta.test.js +95 -0
  270. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +75 -0
  271. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/createSwap.test.js +225 -0
  272. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/getExistingSwapsDetailsAndStatus.test.js +175 -0
  273. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/getSwapInfo.test.js +177 -0
  274. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/helpers.test.js +26 -0
  275. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/integration/PairSupport.int.test.js +69 -0
  276. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/integration/_fetchSupportedCurrenciesIfNeeded.int.test.js +307 -0
  277. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/integration/createSwap.int.test.js +335 -0
  278. package/src/swaps-lib/test/external-apis/goexmeSwapProvider/integration/getSwapInfo.int.test.js +154 -0
  279. package/src/swaps-lib/test/external-apis/swapProvider/getAllSupportedCurrencies.test.js +63 -0
  280. package/src/swaps-lib/test/external-apis/swapProvider/getDepositCurrencies.test.js +73 -0
  281. package/src/swaps-lib/test/external-apis/swapProvider/getWithdrawalCurrencies.test.js +102 -0
  282. package/src/swaps-lib/test/external-apis/swapProvider/removeProtocolNameFromCoinName.test.js +152 -0
  283. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +536 -0
  284. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/createSwap.test.js +1359 -0
  285. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getExistingSwapsDetailsAndStatus.test.js +136 -0
  286. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getSwapInfo.test.js +1743 -0
  287. package/src/swaps-lib/test/utils/swapUtils/isIpBannedProviderError.test.js +150 -0
  288. package/src/swaps-lib/test/utils/swapUtils/safeHandleRequestsLimitExceeding.test.js +80 -0
  289. package/src/swaps-lib/utils/swapUtils.js +207 -0
  290. package/{styles → src/ui-kit/assets/styles}/_functions.scss +5 -0
  291. package/{styles → src/ui-kit/assets/styles}/_mixins.scss +2 -2
  292. package/{styles → src/ui-kit/assets/styles}/_placeholder.scss +3 -3
  293. package/{styles → src/ui-kit/assets/styles}/_variables.scss +17 -15
  294. package/src/ui-kit/assets/styles/fonts/NunitoSans-Bold.ttf +0 -0
  295. package/src/ui-kit/assets/styles/fonts/NunitoSans-ExtraBold.ttf +0 -0
  296. package/src/ui-kit/assets/styles/fonts/NunitoSans-Light.ttf +0 -0
  297. package/src/ui-kit/assets/styles/fonts/NunitoSans-Regular.ttf +0 -0
  298. package/src/ui-kit/assets/styles/fonts/NunitoSans-SemiBold.ttf +0 -0
  299. package/src/ui-kit/assets/styles/global.scss +171 -0
  300. package/src/ui-kit/assets/styles/index.scss +10 -0
  301. package/src/ui-kit/assets/wrappedImages/arrowIcon.jsx +13 -0
  302. package/src/ui-kit/assets/wrappedImages/arrowTosca.jsx +14 -0
  303. package/src/ui-kit/assets/wrappedImages/arrowWhite.jsx +14 -0
  304. package/src/ui-kit/assets/wrappedImages/darkRectangle.jsx +7 -0
  305. package/src/ui-kit/assets/wrappedImages/determinedError.jsx +118 -0
  306. package/src/ui-kit/assets/wrappedImages/failedValidationIcon.jsx +39 -0
  307. package/src/ui-kit/assets/wrappedImages/infoIcon.jsx +16 -0
  308. package/src/ui-kit/assets/wrappedImages/messageIcon.jsx +87 -0
  309. package/src/ui-kit/assets/wrappedImages/noticeQuestionIcon.jsx +54 -0
  310. package/src/ui-kit/assets/wrappedImages/successfulValidationIcon.jsx +26 -0
  311. package/src/ui-kit/assets/wrappedImages/supportDialogImage.jsx +61 -0
  312. package/src/ui-kit/assets/wrappedImages/walletIcon.jsx +22 -0
  313. package/src/{components → ui-kit/components}/atoms/AssetIcon/AssetIcon.jsx +16 -14
  314. package/src/{components → ui-kit/components}/atoms/AssetIcon/asset-icon.module.scss +1 -1
  315. package/src/ui-kit/components/atoms/AssetSelection/AssetSelection.jsx +68 -0
  316. package/src/ui-kit/components/atoms/AssetSelection/asset-selection.module.scss +56 -0
  317. package/src/ui-kit/components/atoms/BackgroundTitle/BackgroundTitle.jsx +34 -0
  318. package/src/ui-kit/components/atoms/BackgroundTitle/background-title.module.scss +52 -0
  319. package/src/ui-kit/components/atoms/InformationMessage/InformationMessage.jsx +51 -0
  320. package/src/ui-kit/components/atoms/InformationMessage/information-message.module.scss +38 -0
  321. package/src/ui-kit/components/atoms/Input/Input.jsx +183 -0
  322. package/src/ui-kit/components/atoms/Input/input.module.scss +107 -0
  323. package/src/{components → ui-kit/components}/atoms/LoadingDots/LoadingDots.jsx +8 -28
  324. package/src/{components → ui-kit/components}/atoms/LoadingDots/LoadingDots.module.scss +3 -2
  325. package/src/ui-kit/components/atoms/NoticeIcon/NoticeIcon.jsx +64 -0
  326. package/src/ui-kit/components/atoms/NoticeIcon/notice-icon.module.scss +14 -0
  327. package/src/ui-kit/components/atoms/QrCode/QrCode.jsx +38 -0
  328. package/src/ui-kit/components/atoms/QrCode/qr-code.module.scss +8 -0
  329. package/src/ui-kit/components/atoms/RateSelector/RateSelector.jsx +30 -0
  330. package/src/ui-kit/components/atoms/RateSelector/rate-selector.module.scss +47 -0
  331. package/src/{components → ui-kit/components}/atoms/SupportChat/SupportChat.jsx +5 -1
  332. package/src/ui-kit/components/atoms/Textarea/Textarea.jsx +148 -0
  333. package/src/ui-kit/components/atoms/Textarea/textarea.module.scss +71 -0
  334. package/src/ui-kit/components/atoms/TitleBox/TitleBox.jsx +141 -0
  335. package/src/ui-kit/components/atoms/TitleBox/title-box.module.scss +32 -0
  336. package/src/ui-kit/components/atoms/Tooltip/Tooltip.jsx +77 -0
  337. package/src/ui-kit/components/atoms/Tooltip/tooltip.module.scss +237 -0
  338. package/src/ui-kit/components/atoms/TwoLinesOfText/LinesOfText.jsx +76 -0
  339. package/src/ui-kit/components/atoms/TwoLinesOfText/lines-of-text.module.scss +65 -0
  340. package/src/ui-kit/components/atoms/Validation/Validation.jsx +39 -0
  341. package/src/ui-kit/components/atoms/Validation/validation.module.scss +19 -0
  342. package/src/{components → ui-kit/components}/atoms/buttons/Button/Button.jsx +26 -45
  343. package/src/{components → ui-kit/components}/atoms/buttons/Button/Button.module.scss +1 -1
  344. package/src/ui-kit/components/atoms/buttons/Close/Close.jsx +58 -0
  345. package/src/ui-kit/components/atoms/buttons/Close/close.module.scss +75 -0
  346. package/src/ui-kit/components/atoms/buttons/LinkButton/LinkButton.jsx +116 -0
  347. package/src/ui-kit/components/atoms/buttons/LinkButton/link-button.module.scss +53 -0
  348. package/src/ui-kit/components/atoms/buttons/RadioButtonWithText/RadioButtonWithText.jsx +110 -0
  349. package/src/ui-kit/components/atoms/buttons/RadioButtonWithText/radio-button-with-text.module.scss +86 -0
  350. package/src/ui-kit/components/molecules/AmountInput/AmountInput.jsx +448 -0
  351. package/src/ui-kit/components/molecules/AmountInput/amount-input.module.scss +233 -0
  352. package/src/ui-kit/components/molecules/CoinPicker/CoinPicker.jsx +463 -0
  353. package/src/ui-kit/components/molecules/CoinPicker/coin-picker.module.scss +207 -0
  354. package/src/ui-kit/components/molecules/ColoredNotice/ColoredNotice.jsx +52 -0
  355. package/src/ui-kit/components/molecules/ColoredNotice/colored-notice.module.scss +36 -0
  356. package/src/ui-kit/components/molecules/LineWithIconLink/LineWithIconLink.jsx +35 -0
  357. package/src/ui-kit/components/molecules/LineWithIconLink/line-with-icon-link.module.scss +25 -0
  358. package/src/ui-kit/components/molecules/LogoCarousel/LogoCarousel.jsx +74 -0
  359. package/src/ui-kit/components/molecules/LogoCarousel/logo-carousel.module.scss +106 -0
  360. package/src/ui-kit/components/molecules/SearchableCoinsList/SearchableCoinsList.jsx +114 -0
  361. package/src/ui-kit/components/molecules/TitledLineWithIconLink/TitledLineWithIconLink.jsx +32 -0
  362. package/src/ui-kit/components/organisms/CoinPickerDialogStep/CoinPickerDialogStep.jsx +66 -0
  363. package/src/ui-kit/components/organisms/Dialog/Dialog.jsx +494 -0
  364. package/src/ui-kit/components/organisms/Dialog/DialogButtons/DialogButtons.jsx +132 -0
  365. package/src/ui-kit/components/organisms/Dialog/DialogButtons/dialog-buttons.module.scss +25 -0
  366. package/src/ui-kit/components/organisms/Dialog/DialogStep/DialogStep.jsx +554 -0
  367. package/src/ui-kit/components/organisms/Dialog/DialogStep/dialog-step.module.scss +382 -0
  368. package/src/ui-kit/components/organisms/Dialog/dialog.module.scss +226 -0
  369. package/src/ui-kit/components/organisms/SwapForm/SwapForm.jsx +1430 -0
  370. package/src/ui-kit/components/organisms/SwapForm/swap-form.module.scss +134 -0
  371. package/src/ui-kit/components/organisms/WaitlistSubscription/WaitlistSubscription.jsx +158 -0
  372. package/src/ui-kit/components/templates/DeterminedErrorDialogStep/DeterminedErrorDialogStep.jsx +77 -0
  373. package/src/ui-kit/hooks/useCallHandlingErrors.js +27 -0
  374. package/src/ui-kit/hooks/useIsHydrated.js +12 -0
  375. package/src/ui-kit/hooks/useReferredState.js +24 -0
  376. package/src/ui-kit/tests/utils/inputValueProviders/provideFormatOfFloatValueByInputString.test.js +146 -0
  377. package/src/ui-kit/tests/utils/urlQueryUtils/getQueryParameterValues.test.js +65 -0
  378. package/src/ui-kit/tests/utils/urlQueryUtils/saveQueryParameterAndValues.test.js +104 -0
  379. package/src/ui-kit/utils/inputValueProviders.js +50 -0
  380. package/src/ui-kit/utils/searchCoins.js +58 -0
  381. package/src/ui-kit/utils/textUtils.js +18 -0
  382. package/src/ui-kit/utils/uiUtils.js +12 -0
  383. package/src/ui-kit/utils/urlQueryUtils.js +62 -0
  384. package/stories/font.scss +40 -0
  385. package/stories/stubs/coins.jsx +2266 -0
  386. package/stories/stubs/exampleContent.jsx +20 -0
  387. package/styles/_global-classes.scss +0 -433
  388. package/styles/fonts/NunitoSans-Bold.ttf +0 -0
  389. package/styles/fonts/NunitoSans-ExtraBold.ttf +0 -0
  390. package/styles/fonts/NunitoSans-Light.ttf +0 -0
  391. package/styles/fonts/NunitoSans-Regular.ttf +0 -0
  392. package/styles/fonts/NunitoSans-SemiBold.ttf +0 -0
  393. package/styles/global-styles-index.scss +0 -74
  394. package/styles/index.scss +0 -33
  395. /package/src/{common → common-apis}/models/blockchain.js +0 -0
  396. /package/src/{common → common-apis}/models/protocol.js +0 -0
  397. /package/src/{common → common-apis}/utils/logging/logsStorage.js +0 -0
  398. /package/src/{common → common-apis}/utils/safeStringify.js +0 -0
  399. /package/{styles → src/ui-kit/assets/styles}/colors/_light-colors.scss +0 -0
  400. /package/{styles → src/ui-kit/assets/styles}/colors/_solid-colors.scss +0 -0
  401. /package/{styles → src/ui-kit/assets/styles}/size/_margin-size.scss +0 -0
  402. /package/{styles → src/ui-kit/assets/styles}/size/_padding-size.scss +0 -0
@@ -0,0 +1,938 @@
1
+ import sinon from "sinon";
2
+ import axios from "axios";
3
+ import should from "should";
4
+ import { describe, it, beforeEach, afterEach } from "vitest";
5
+
6
+ import { ChangeNowSwapProvider } from "../../../external-apis/changeNowSwapProvider.js";
7
+ import { Cache } from "../../../../common-apis/utils/cache.js";
8
+ import { Coin } from "../../../../common-apis/models/coin.js";
9
+ import { SwapProvider } from "../../../external-apis/swapProvider.js";
10
+
11
+ describe("src/swaps-lib/external-apis/changeNowSwapProvider.js", function () {
12
+ describe("createSwap", function () {
13
+ let provider;
14
+ let axiosPostStub;
15
+ let fetchCoinsStub;
16
+ let validateStub;
17
+ let fromCoin;
18
+ let toCoin;
19
+
20
+ function buildCoin(ticker, digits = 8) {
21
+ return new Coin(
22
+ ticker,
23
+ ticker,
24
+ ticker,
25
+ digits,
26
+ null,
27
+ "",
28
+ null,
29
+ null,
30
+ 1,
31
+ null,
32
+ [],
33
+ 60000,
34
+ null,
35
+ null,
36
+ null,
37
+ false
38
+ );
39
+ }
40
+
41
+ beforeEach(function () {
42
+ provider = new ChangeNowSwapProvider(null, new Cache());
43
+ axiosPostStub = sinon.stub(axios, "post");
44
+ fetchCoinsStub = sinon.stub(provider, "_fetchSupportedCurrenciesIfNeeded").resolves();
45
+ validateStub = sinon.stub(provider, "_validateAddressWithProvider");
46
+ fromCoin = buildCoin("BTC");
47
+ toCoin = buildCoin("ETH");
48
+ });
49
+
50
+ afterEach(function () {
51
+ sinon.restore();
52
+ });
53
+
54
+ it("Should return retriable fail on invalid input parameters", async function () {
55
+ let thrown1;
56
+ try {
57
+ await provider.createSwap({}, toCoin, "1", "addr", null, {}, null, false);
58
+ } catch (e) {
59
+ thrown1 = e;
60
+ }
61
+ should.exist(thrown1);
62
+ (thrown1.message || "").toLowerCase().includes("invalid swap parameters").should.be.true();
63
+
64
+ let thrown2;
65
+ try {
66
+ await provider.createSwap(fromCoin, toCoin, "-1", "addr", null, {}, null, false);
67
+ } catch (e) {
68
+ thrown2 = e;
69
+ }
70
+ should.exist(thrown2);
71
+ (thrown2.message || "").toLowerCase().includes("invalid swap parameters").should.be.true();
72
+ });
73
+
74
+ it("Should return retriable fail when toAddress is empty", async function () {
75
+ let thrown;
76
+ try {
77
+ await provider.createSwap(fromCoin, toCoin, "1", " ", null, {}, null, false);
78
+ } catch (e) {
79
+ thrown = e;
80
+ }
81
+ should.exist(thrown);
82
+ (thrown.message || "").toLowerCase().includes("invalid destination address").should.be.true();
83
+ });
84
+
85
+ it("Should throw when supported coin info for fromCoin is missing (internal inconsistency)", async function () {
86
+ provider._supportedCoins = [
87
+ { coin: toCoin, code: "ETH", network: null, deposit: true, withdrawal: true, isAvailable: true },
88
+ ];
89
+ validateStub.resolves(true);
90
+
91
+ let thrown;
92
+ try {
93
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
94
+ } catch (e) {
95
+ thrown = e;
96
+ }
97
+ should.exist(thrown);
98
+ (thrown.message || "").toLowerCase().includes("internal inconsistency").should.be.true();
99
+ });
100
+
101
+ it("Should throw when supported coin info for toCoin is missing (internal inconsistency)", async function () {
102
+ provider._supportedCoins = [
103
+ { coin: fromCoin, code: "BTC", network: null, deposit: true, withdrawal: true, isAvailable: true },
104
+ ];
105
+ validateStub.resolves(true);
106
+
107
+ let thrown;
108
+ try {
109
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
110
+ } catch (e) {
111
+ thrown = e;
112
+ }
113
+ should.exist(thrown);
114
+ (thrown.message || "").toLowerCase().includes("internal inconsistency").should.be.true();
115
+ });
116
+
117
+ it("Should return retriable fail when payout address validation fails", async function () {
118
+ provider._supportedCoins = [
119
+ { coin: fromCoin, code: "BTC", network: null, deposit: true, withdrawal: true, isAvailable: true },
120
+ { coin: toCoin, code: "ETH", network: null, deposit: true, withdrawal: true, isAvailable: true },
121
+ ];
122
+ validateStub.resolves(false);
123
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "invalidAddr", null, {}, null, false);
124
+ res.result.should.be.false();
125
+ res.reason.should.equal(provider.constructor.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
126
+ });
127
+
128
+ it("Should return retriable fail when refund address validation fails", async function () {
129
+ provider._supportedCoins = [
130
+ { coin: fromCoin, code: "BTC", network: null, deposit: true, withdrawal: true, isAvailable: true },
131
+ { coin: toCoin, code: "ETH", network: null, deposit: true, withdrawal: true, isAvailable: true },
132
+ ];
133
+ validateStub.onCall(0).resolves(true);
134
+ validateStub.onCall(1).resolves(false);
135
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "valid", "badRefund", {}, null, false);
136
+ res.result.should.be.false();
137
+ res.reason.should.equal(provider.constructor.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
138
+ });
139
+
140
+ it("Should construct payload and return swap details on success", async function () {
141
+ provider._supportedCoins = [
142
+ { coin: fromCoin, code: "BTC", network: null, deposit: true, withdrawal: true, isAvailable: true },
143
+ { coin: toCoin, code: "ETH", network: null, deposit: true, withdrawal: true, isAvailable: true },
144
+ ];
145
+ validateStub.resolves(true);
146
+ axiosPostStub.resolves({
147
+ status: 200,
148
+ data: { id: "swapId", payinAddress: "fromAddr", payinExtraId: "memo", fromAmount: "5", toAmount: "10" },
149
+ });
150
+ const estimationData = { rate: "2", rateId: "rid123" };
151
+ const res = await provider.createSwap(
152
+ fromCoin,
153
+ toCoin,
154
+ "5",
155
+ "userToAddr",
156
+ "refundAddr",
157
+ estimationData,
158
+ null,
159
+ true,
160
+ "destTag",
161
+ "refundTag",
162
+ false
163
+ );
164
+ axiosPostStub.calledOnce.should.be.true();
165
+ const callArgs = axiosPostStub.firstCall.args;
166
+ callArgs[0].should.match(/\/exchange$/);
167
+ const payload = callArgs[1];
168
+ payload.fromCurrency.should.equal("BTC");
169
+ payload.toCurrency.should.equal("ETH");
170
+ payload.address.should.equal("userToAddr");
171
+ payload.fromAmount.should.equal("5");
172
+ payload.flow.should.equal("fixed-rate");
173
+ payload.rateId.should.equal("rid123");
174
+ payload.extraId.should.equal("destTag");
175
+ payload.refundAddress.should.equal("refundAddr");
176
+ payload.refundExtraId.should.equal("refundTag");
177
+ res.result.should.be.true();
178
+ res.swapId.should.equal("swapId");
179
+ res.fromAmount.should.equal("5");
180
+ res.toAmount.should.equal("10");
181
+ res.rate.should.equal("2");
182
+ res.fromCurrencyExtraId.should.equal("memo");
183
+ res.fixed.should.be.true();
184
+ });
185
+
186
+ it("Should map provider error messages to retriable fail reason per adapter behavior", async function () {
187
+ provider._supportedCoins = [
188
+ { coin: fromCoin, code: "BTC", network: null, deposit: true, withdrawal: true, isAvailable: true },
189
+ { coin: toCoin, code: "ETH", network: null, deposit: true, withdrawal: true, isAvailable: true },
190
+ ];
191
+ validateStub.resolves(true);
192
+
193
+ axiosPostStub.resolves({ status: 400, data: { error: "Minimum amount is 10" } });
194
+ let res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
195
+ res.result.should.be.false();
196
+ res.reason.should.equal(provider.constructor.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
197
+
198
+ axiosPostStub.resolves({ status: 400, data: { error: "Not supported" } });
199
+ res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
200
+ res.result.should.be.false();
201
+ res.reason.should.equal(provider.constructor.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
202
+
203
+ axiosPostStub.resolves({ status: 400, data: { error: "Invalid address" } });
204
+ res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
205
+ res.result.should.be.false();
206
+ res.reason.should.equal(provider.constructor.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
207
+
208
+ axiosPostStub.resolves({ status: 400, data: { error: "Something else" } });
209
+ res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
210
+ res.result.should.be.false();
211
+ res.reason.should.equal(provider.constructor.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
212
+ });
213
+
214
+ it("Should return retriable fail when a network error is thrown", async function () {
215
+ provider._supportedCoins = [
216
+ { coin: fromCoin, code: "BTC", network: null, deposit: true, withdrawal: true, isAvailable: true },
217
+ { coin: toCoin, code: "ETH", network: null, deposit: true, withdrawal: true, isAvailable: true },
218
+ ];
219
+ validateStub.resolves(true);
220
+ axiosPostStub.rejects(new Error("network down"));
221
+
222
+ let thrown;
223
+ try {
224
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
225
+ } catch (e) {
226
+ thrown = e;
227
+ }
228
+ should.exist(thrown);
229
+ });
230
+
231
+ it("Should throw error when fromCoin is not a Coin instance", async function () {
232
+ let thrown;
233
+ try {
234
+ await provider.createSwap({}, toCoin, "1", "addr", null, {}, null, false);
235
+ } catch (e) {
236
+ thrown = e;
237
+ }
238
+ should.exist(thrown);
239
+ (thrown.message || "").toLowerCase().includes("invalid swap parameters").should.be.true();
240
+ });
241
+
242
+ it("Should throw error when toCoin is not a Coin instance", async function () {
243
+ let thrown;
244
+ try {
245
+ await provider.createSwap(fromCoin, {}, "1", "addr", null, {}, null, false);
246
+ } catch (e) {
247
+ thrown = e;
248
+ }
249
+ should.exist(thrown);
250
+ (thrown.message || "").toLowerCase().includes("invalid swap parameters").should.be.true();
251
+ });
252
+
253
+ it("Should throw error when amount is not a positive string", async function () {
254
+ let thrown1;
255
+ try {
256
+ await provider.createSwap(fromCoin, toCoin, 1, "addr", null, {}, null, false);
257
+ } catch (e) {
258
+ thrown1 = e;
259
+ }
260
+ should.exist(thrown1);
261
+ (thrown1.message || "").toLowerCase().includes("invalid swap parameters").should.be.true();
262
+
263
+ let thrown2;
264
+ try {
265
+ await provider.createSwap(fromCoin, toCoin, "0", "addr", null, {}, null, false);
266
+ } catch (e) {
267
+ thrown2 = e;
268
+ }
269
+ should.exist(thrown2);
270
+ (thrown2.message || "").toLowerCase().includes("invalid swap parameters").should.be.true();
271
+ });
272
+
273
+ it("Should not call axios when payout address validation fails", async function () {
274
+ provider._supportedCoins = [
275
+ {
276
+ coin: fromCoin,
277
+ code: fromCoin.ticker,
278
+ network: "btc",
279
+ deposit: true,
280
+ withdrawal: true,
281
+ isAvailable: true,
282
+ },
283
+ {
284
+ coin: toCoin,
285
+ code: toCoin.ticker,
286
+ network: "eth",
287
+ deposit: true,
288
+ withdrawal: true,
289
+ isAvailable: true,
290
+ },
291
+ ];
292
+ validateStub.resolves(false);
293
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "bad", null, {}, null, false);
294
+ res.result.should.be.false();
295
+ axiosPostStub.called.should.be.false();
296
+ });
297
+
298
+ it("Should not call axios when refund address validation fails", async function () {
299
+ provider._supportedCoins = [
300
+ {
301
+ coin: fromCoin,
302
+ code: fromCoin.ticker,
303
+ network: "btc",
304
+ deposit: true,
305
+ withdrawal: true,
306
+ isAvailable: true,
307
+ },
308
+ {
309
+ coin: toCoin,
310
+ code: toCoin.ticker,
311
+ network: "eth",
312
+ deposit: true,
313
+ withdrawal: true,
314
+ isAvailable: true,
315
+ },
316
+ ];
317
+ validateStub.onCall(0).resolves(true);
318
+ validateStub.onCall(1).resolves(false);
319
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "good", "bad", {}, null, false);
320
+ res.result.should.be.false();
321
+ axiosPostStub.called.should.be.false();
322
+ });
323
+
324
+ it("Should include network parameters in the payload when networks are specified", async function () {
325
+ provider._supportedCoins = [
326
+ {
327
+ coin: fromCoin,
328
+ code: fromCoin.ticker,
329
+ network: "btc",
330
+ deposit: true,
331
+ withdrawal: true,
332
+ isAvailable: true,
333
+ },
334
+ {
335
+ coin: toCoin,
336
+ code: toCoin.ticker,
337
+ network: "eth",
338
+ deposit: true,
339
+ withdrawal: true,
340
+ isAvailable: true,
341
+ },
342
+ ];
343
+ validateStub.resolves(true);
344
+ axiosPostStub.resolves({
345
+ status: 200,
346
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
347
+ });
348
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
349
+ const payload = axiosPostStub.firstCall.args[1];
350
+ payload.fromNetwork.should.equal("btc");
351
+ payload.toNetwork.should.equal("eth");
352
+ });
353
+
354
+ it("Should send toAmount instead of fromAmount when amountIsToReceive is true", async function () {
355
+ provider._supportedCoins = [
356
+ {
357
+ coin: fromCoin,
358
+ code: fromCoin.ticker,
359
+ network: null,
360
+ deposit: true,
361
+ withdrawal: true,
362
+ isAvailable: true,
363
+ },
364
+ {
365
+ coin: toCoin,
366
+ code: toCoin.ticker,
367
+ network: null,
368
+ deposit: true,
369
+ withdrawal: true,
370
+ isAvailable: true,
371
+ },
372
+ ];
373
+ validateStub.resolves(true);
374
+ axiosPostStub.resolves({
375
+ status: 200,
376
+ data: { id: "id", payinAddress: "in", fromAmount: "3", toAmount: "5" },
377
+ });
378
+ await provider.createSwap(fromCoin, toCoin, "7", "addr", null, {}, null, false, "", "", true);
379
+ const payload = axiosPostStub.firstCall.args[1];
380
+ should(payload.fromAmount).be.undefined();
381
+ payload.toAmount.should.equal("7");
382
+ });
383
+
384
+ it("Should not include extraId when none is provided", async function () {
385
+ provider._supportedCoins = [
386
+ {
387
+ coin: fromCoin,
388
+ code: fromCoin.ticker,
389
+ network: null,
390
+ deposit: true,
391
+ withdrawal: true,
392
+ isAvailable: true,
393
+ },
394
+ {
395
+ coin: toCoin,
396
+ code: toCoin.ticker,
397
+ network: null,
398
+ deposit: true,
399
+ withdrawal: true,
400
+ isAvailable: true,
401
+ },
402
+ ];
403
+ validateStub.resolves(true);
404
+ axiosPostStub.resolves({
405
+ status: 200,
406
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
407
+ });
408
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false, "");
409
+ const payload = axiosPostStub.firstCall.args[1];
410
+ should(payload.extraId).be.undefined();
411
+ });
412
+
413
+ it("Should not include refundAddress and refundExtraId when not provided", async function () {
414
+ provider._supportedCoins = [
415
+ {
416
+ coin: fromCoin,
417
+ code: fromCoin.ticker,
418
+ network: null,
419
+ deposit: true,
420
+ withdrawal: true,
421
+ isAvailable: true,
422
+ },
423
+ {
424
+ coin: toCoin,
425
+ code: toCoin.ticker,
426
+ network: null,
427
+ deposit: true,
428
+ withdrawal: true,
429
+ isAvailable: true,
430
+ },
431
+ ];
432
+ validateStub.resolves(true);
433
+ axiosPostStub.resolves({
434
+ status: 200,
435
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
436
+ });
437
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", "", {}, null, false);
438
+ const payload = axiosPostStub.firstCall.args[1];
439
+ should(payload.refundAddress).be.undefined();
440
+ should(payload.refundExtraId).be.undefined();
441
+ });
442
+
443
+ it("Should include refundExtraId when provided", async function () {
444
+ provider._supportedCoins = [
445
+ {
446
+ coin: fromCoin,
447
+ code: fromCoin.ticker,
448
+ network: null,
449
+ deposit: true,
450
+ withdrawal: true,
451
+ isAvailable: true,
452
+ },
453
+ {
454
+ coin: toCoin,
455
+ code: toCoin.ticker,
456
+ network: null,
457
+ deposit: true,
458
+ withdrawal: true,
459
+ isAvailable: true,
460
+ },
461
+ ];
462
+ validateStub.resolves(true);
463
+ axiosPostStub.resolves({
464
+ status: 200,
465
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
466
+ });
467
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", "refund", {}, null, false, "", "refundTag");
468
+ const payload = axiosPostStub.firstCall.args[1];
469
+ payload.refundExtraId.should.equal("refundTag");
470
+ });
471
+
472
+ it("Should include rateId from rawSwapData when provided in estimationData", async function () {
473
+ provider._supportedCoins = [
474
+ {
475
+ coin: fromCoin,
476
+ code: fromCoin.ticker,
477
+ network: null,
478
+ deposit: true,
479
+ withdrawal: true,
480
+ isAvailable: true,
481
+ },
482
+ {
483
+ coin: toCoin,
484
+ code: toCoin.ticker,
485
+ network: null,
486
+ deposit: true,
487
+ withdrawal: true,
488
+ isAvailable: true,
489
+ },
490
+ ];
491
+ validateStub.resolves(true);
492
+ axiosPostStub.resolves({
493
+ status: 200,
494
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
495
+ });
496
+
497
+ const estimationData = { rate: "1", rateId: "abc" };
498
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", null, estimationData, null, true);
499
+ const payload = axiosPostStub.firstCall.args[1];
500
+ payload.rateId.should.equal("abc");
501
+ });
502
+
503
+ it("Should compute rate from returned amounts when estimationData.rate is not provided", async function () {
504
+ provider._supportedCoins = [
505
+ {
506
+ coin: fromCoin,
507
+ code: fromCoin.ticker,
508
+ network: null,
509
+ deposit: true,
510
+ withdrawal: true,
511
+ isAvailable: true,
512
+ },
513
+ {
514
+ coin: toCoin,
515
+ code: toCoin.ticker,
516
+ network: null,
517
+ deposit: true,
518
+ withdrawal: true,
519
+ isAvailable: true,
520
+ },
521
+ ];
522
+ validateStub.resolves(true);
523
+ axiosPostStub.resolves({
524
+ status: 200,
525
+ data: { id: "id", payinAddress: "in", fromAmount: "2", toAmount: "6" },
526
+ });
527
+ const res = await provider.createSwap(fromCoin, toCoin, "2", "addr", null, {}, null, false);
528
+ res.rate.should.equal("3");
529
+ });
530
+
531
+ it("Should return null rate when no amounts and no rate provided", async function () {
532
+ provider._supportedCoins = [
533
+ {
534
+ coin: fromCoin,
535
+ code: fromCoin.ticker,
536
+ network: null,
537
+ deposit: true,
538
+ withdrawal: true,
539
+ isAvailable: true,
540
+ },
541
+ {
542
+ coin: toCoin,
543
+ code: toCoin.ticker,
544
+ network: null,
545
+ deposit: true,
546
+ withdrawal: true,
547
+ isAvailable: true,
548
+ },
549
+ ];
550
+ validateStub.resolves(true);
551
+ axiosPostStub.resolves({ status: 200, data: { id: "id", payinAddress: "in" } });
552
+ const res = await provider.createSwap(fromCoin, toCoin, "5", "addr", null, {}, null, false);
553
+ should(res.rate).be.null();
554
+ });
555
+
556
+ it("Should handle 201 status as success and compute rate", async function () {
557
+ provider._supportedCoins = [
558
+ {
559
+ coin: fromCoin,
560
+ code: fromCoin.ticker,
561
+ network: null,
562
+ deposit: true,
563
+ withdrawal: true,
564
+ isAvailable: true,
565
+ },
566
+ {
567
+ coin: toCoin,
568
+ code: toCoin.ticker,
569
+ network: null,
570
+ deposit: true,
571
+ withdrawal: true,
572
+ isAvailable: true,
573
+ },
574
+ ];
575
+ validateStub.resolves(true);
576
+ axiosPostStub.resolves({
577
+ status: 201,
578
+ data: { id: "id", payinAddress: "in", fromAmount: "3", toAmount: "9" },
579
+ });
580
+ const res = await provider.createSwap(fromCoin, toCoin, "3", "addr", null, {}, null, false);
581
+ res.result.should.be.true();
582
+ res.rate.should.equal("3");
583
+ });
584
+
585
+ it("Should set swapId to null when exchangeId returned instead of id", async function () {
586
+ provider._supportedCoins = [
587
+ {
588
+ coin: fromCoin,
589
+ code: fromCoin.ticker,
590
+ network: null,
591
+ deposit: true,
592
+ withdrawal: true,
593
+ isAvailable: true,
594
+ },
595
+ {
596
+ coin: toCoin,
597
+ code: toCoin.ticker,
598
+ network: null,
599
+ deposit: true,
600
+ withdrawal: true,
601
+ isAvailable: true,
602
+ },
603
+ ];
604
+ validateStub.resolves(true);
605
+ axiosPostStub.resolves({
606
+ status: 200,
607
+ data: { exchangeId: "ex123", payinAddress: "in", fromAmount: "1", toAmount: "2" },
608
+ });
609
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
610
+ should(res.swapId).be.null();
611
+ });
612
+
613
+ it("Should set swapId to null when requestId returned instead of id", async function () {
614
+ provider._supportedCoins = [
615
+ {
616
+ coin: fromCoin,
617
+ code: fromCoin.ticker,
618
+ network: null,
619
+ deposit: true,
620
+ withdrawal: true,
621
+ isAvailable: true,
622
+ },
623
+ {
624
+ coin: toCoin,
625
+ code: toCoin.ticker,
626
+ network: null,
627
+ deposit: true,
628
+ withdrawal: true,
629
+ isAvailable: true,
630
+ },
631
+ ];
632
+ validateStub.resolves(true);
633
+ axiosPostStub.resolves({
634
+ status: 200,
635
+ data: { requestId: "req456", payinAddress: "in", fromAmount: "1", toAmount: "2" },
636
+ });
637
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
638
+ should(res.swapId).be.null();
639
+ });
640
+
641
+ it("Should leave fromAddress null when payinAddress missing", async function () {
642
+ provider._supportedCoins = [
643
+ {
644
+ coin: fromCoin,
645
+ code: fromCoin.ticker,
646
+ network: null,
647
+ deposit: true,
648
+ withdrawal: true,
649
+ isAvailable: true,
650
+ },
651
+ {
652
+ coin: toCoin,
653
+ code: toCoin.ticker,
654
+ network: null,
655
+ deposit: true,
656
+ withdrawal: true,
657
+ isAvailable: true,
658
+ },
659
+ ];
660
+ validateStub.resolves(true);
661
+ axiosPostStub.resolves({
662
+ status: 200,
663
+ data: { id: "id", fromAddress: "fa", fromAmount: "1", toAmount: "2" },
664
+ });
665
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
666
+ should(res.fromAddress).be.null();
667
+ });
668
+
669
+ it("Should leave fromAddress null when only address field is returned", async function () {
670
+ provider._supportedCoins = [
671
+ {
672
+ coin: fromCoin,
673
+ code: fromCoin.ticker,
674
+ network: null,
675
+ deposit: true,
676
+ withdrawal: true,
677
+ isAvailable: true,
678
+ },
679
+ {
680
+ coin: toCoin,
681
+ code: toCoin.ticker,
682
+ network: null,
683
+ deposit: true,
684
+ withdrawal: true,
685
+ isAvailable: true,
686
+ },
687
+ ];
688
+ validateStub.resolves(true);
689
+ axiosPostStub.resolves({
690
+ status: 200,
691
+ data: { id: "id", address: "fallback", fromAmount: "1", toAmount: "2" },
692
+ });
693
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
694
+ should(res.fromAddress).be.null();
695
+ });
696
+
697
+ it("Should set fromCurrencyExtraId null when payinExtraId is missing", async function () {
698
+ provider._supportedCoins = [
699
+ {
700
+ coin: fromCoin,
701
+ code: fromCoin.ticker,
702
+ network: null,
703
+ deposit: true,
704
+ withdrawal: true,
705
+ isAvailable: true,
706
+ },
707
+ {
708
+ coin: toCoin,
709
+ code: toCoin.ticker,
710
+ network: null,
711
+ deposit: true,
712
+ withdrawal: true,
713
+ isAvailable: true,
714
+ },
715
+ ];
716
+ validateStub.resolves(true);
717
+ axiosPostStub.resolves({
718
+ status: 200,
719
+ data: { id: "id", payinAddress: "in", fromCurrencyExtraId: "fcx", fromAmount: "1", toAmount: "2" },
720
+ });
721
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
722
+ should(res.fromCurrencyExtraId).be.null();
723
+ });
724
+
725
+ it("Should set fixed to false and omit flow when fixed parameter is false", async function () {
726
+ provider._supportedCoins = [
727
+ {
728
+ coin: fromCoin,
729
+ code: fromCoin.ticker,
730
+ network: null,
731
+ deposit: true,
732
+ withdrawal: true,
733
+ isAvailable: true,
734
+ },
735
+ {
736
+ coin: toCoin,
737
+ code: toCoin.ticker,
738
+ network: null,
739
+ deposit: true,
740
+ withdrawal: true,
741
+ isAvailable: true,
742
+ },
743
+ ];
744
+ validateStub.resolves(true);
745
+ axiosPostStub.resolves({
746
+ status: 200,
747
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
748
+ });
749
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
750
+ const payload = axiosPostStub.firstCall.args[1];
751
+ should(payload.flow).be.undefined();
752
+ should(payload.rateId).be.undefined();
753
+ res.fixed.should.be.false();
754
+ });
755
+
756
+ it("Should validate only payout address when refundAddress is not provided", async function () {
757
+ provider._supportedCoins = [
758
+ {
759
+ coin: fromCoin,
760
+ code: fromCoin.ticker,
761
+ network: null,
762
+ deposit: true,
763
+ withdrawal: true,
764
+ isAvailable: true,
765
+ },
766
+ {
767
+ coin: toCoin,
768
+ code: toCoin.ticker,
769
+ network: null,
770
+ deposit: true,
771
+ withdrawal: true,
772
+ isAvailable: true,
773
+ },
774
+ ];
775
+ validateStub.resolves(true);
776
+ axiosPostStub.resolves({
777
+ status: 200,
778
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
779
+ });
780
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
781
+ validateStub.callCount.should.equal(1);
782
+ });
783
+
784
+ it("Should validate both payout and refund addresses when refundAddress is provided", async function () {
785
+ provider._supportedCoins = [
786
+ {
787
+ coin: fromCoin,
788
+ code: fromCoin.ticker,
789
+ network: null,
790
+ deposit: true,
791
+ withdrawal: true,
792
+ isAvailable: true,
793
+ },
794
+ {
795
+ coin: toCoin,
796
+ code: toCoin.ticker,
797
+ network: null,
798
+ deposit: true,
799
+ withdrawal: true,
800
+ isAvailable: true,
801
+ },
802
+ ];
803
+ validateStub.onCall(0).resolves(true);
804
+ validateStub.onCall(1).resolves(true);
805
+ axiosPostStub.resolves({
806
+ status: 200,
807
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
808
+ });
809
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", "refund", {}, null, false);
810
+ validateStub.callCount.should.equal(2);
811
+ });
812
+
813
+ it("Should call address validation with correct parameters", async function () {
814
+ provider._supportedCoins = [
815
+ { coin: fromCoin, code: "BTC", network: "btc", deposit: true, withdrawal: true, isAvailable: true },
816
+ { coin: toCoin, code: "ETH", network: "eth", deposit: true, withdrawal: true, isAvailable: true },
817
+ ];
818
+ validateStub.onCall(0).resolves(true);
819
+ validateStub.onCall(1).resolves(true);
820
+ axiosPostStub.resolves({
821
+ status: 200,
822
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
823
+ });
824
+ await provider.createSwap(fromCoin, toCoin, "1", "toAddr", "refAddr", {}, null, false);
825
+ const firstCallArgs = validateStub.getCall(0).args;
826
+ firstCallArgs[0].should.equal("eth");
827
+ firstCallArgs[1].should.equal("ETH");
828
+ firstCallArgs[2].should.equal("toAddr");
829
+ const secondCallArgs = validateStub.getCall(1).args;
830
+ secondCallArgs[0].should.equal("btc");
831
+ secondCallArgs[1].should.equal("BTC");
832
+ secondCallArgs[2].should.equal("refAddr");
833
+ });
834
+
835
+ it("Should call fetchSupportedCurrenciesIfNeeded once per swap", async function () {
836
+ provider._supportedCoins = [
837
+ {
838
+ coin: fromCoin,
839
+ code: fromCoin.ticker,
840
+ network: null,
841
+ deposit: true,
842
+ withdrawal: true,
843
+ isAvailable: true,
844
+ },
845
+ {
846
+ coin: toCoin,
847
+ code: toCoin.ticker,
848
+ network: null,
849
+ deposit: true,
850
+ withdrawal: true,
851
+ isAvailable: true,
852
+ },
853
+ ];
854
+ validateStub.resolves(true);
855
+ axiosPostStub.resolves({
856
+ status: 200,
857
+ data: { id: "id", payinAddress: "in", fromAmount: "1", toAmount: "2" },
858
+ });
859
+ await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
860
+ fetchCoinsStub.calledOnce.should.be.true();
861
+ });
862
+
863
+ it("Should return retriable fail for 404 response with 'Amount out of range'", async function () {
864
+ provider._supportedCoins = [
865
+ { coin: fromCoin, code: "BTC", network: null, deposit: true, withdrawal: true, isAvailable: true },
866
+ { coin: toCoin, code: "ETH", network: null, deposit: true, withdrawal: true, isAvailable: true },
867
+ ];
868
+ validateStub.resolves(true);
869
+ axiosPostStub.resolves({ status: 404, data: { error: "Amount out of range" } });
870
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
871
+ res.result.should.be.false();
872
+ res.reason.should.equal(provider.constructor.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
873
+ });
874
+
875
+ it("Should return retriable fail for 404 response with unknown error", async function () {
876
+ provider._supportedCoins = [
877
+ { coin: fromCoin, code: "BTC", network: null, deposit: true, withdrawal: true, isAvailable: true },
878
+ { coin: toCoin, code: "ETH", network: null, deposit: true, withdrawal: true, isAvailable: true },
879
+ ];
880
+ validateStub.resolves(true);
881
+ axiosPostStub.resolves({ status: 404, data: { error: "Some unexpected issue" } });
882
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", null, {}, null, false);
883
+ res.result.should.be.false();
884
+ res.reason.should.equal(provider.constructor.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
885
+ });
886
+ it("Should map rejected 403 with Cloudflare header to RETRIABLE_FAIL + IP_BANNED", async function () {
887
+ provider._supportedCoins = [
888
+ { coin: fromCoin, code: "btc", network: "btc", deposit: true, withdrawal: true, isAvailable: true },
889
+ { coin: toCoin, code: "eth", network: "eth", deposit: true, withdrawal: true, isAvailable: true },
890
+ ];
891
+
892
+ validateStub.resolves(true);
893
+
894
+ axiosPostStub.rejects({
895
+ response: {
896
+ status: 403,
897
+ headers: { "cf-ray": "ray-id" },
898
+ data: "Forbidden",
899
+ },
900
+ });
901
+
902
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", "", {}, null, false);
903
+
904
+ res.should.match({
905
+ result: false,
906
+ reason: SwapProvider.CREATION_FAIL_REASONS.RETRIABLE_FAIL,
907
+ errorCode: SwapProvider.RETRIABLE_SWAP_CREATION_ERRORS.IP_BANNED,
908
+ partner: provider.id,
909
+ });
910
+ });
911
+
912
+ it("Should map rejected 4xx containing 'ip' + 'blocked' to RETRIABLE_FAIL + IP_BANNED", async function () {
913
+ provider._supportedCoins = [
914
+ { coin: fromCoin, code: "btc", network: "btc", deposit: true, withdrawal: true, isAvailable: true },
915
+ { coin: toCoin, code: "eth", network: "eth", deposit: true, withdrawal: true, isAvailable: true },
916
+ ];
917
+
918
+ validateStub.resolves(true);
919
+
920
+ axiosPostStub.rejects({
921
+ response: {
922
+ status: 401,
923
+ headers: {},
924
+ data: "your ip is blocked",
925
+ },
926
+ });
927
+
928
+ const res = await provider.createSwap(fromCoin, toCoin, "1", "addr", "", {}, null, false);
929
+
930
+ res.should.match({
931
+ result: false,
932
+ reason: SwapProvider.CREATION_FAIL_REASONS.RETRIABLE_FAIL,
933
+ errorCode: SwapProvider.RETRIABLE_SWAP_CREATION_ERRORS.IP_BANNED,
934
+ partner: provider.id,
935
+ });
936
+ });
937
+ });
938
+ });