@rabbitio/ui-kit 1.0.0-beta.87 → 1.0.0-beta.89

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 (222) hide show
  1. package/coverage/clover.xml +1882 -1481
  2. package/coverage/coverage-final.json +32 -31
  3. package/coverage/index.html +90 -75
  4. package/coverage/rabbit-ui-kit/index.html +1 -1
  5. package/coverage/rabbit-ui-kit/index.js.html +1 -1
  6. package/coverage/rabbit-ui-kit/src/common-apis/adapters/analyticsAdapters/googleAnalyticsAdapter.js.html +1 -1
  7. package/coverage/rabbit-ui-kit/src/common-apis/adapters/analyticsAdapters/index.html +1 -1
  8. package/coverage/rabbit-ui-kit/src/common-apis/adapters/analyticsAdapters/metrikaAdapter.js.html +1 -1
  9. package/coverage/rabbit-ui-kit/src/common-apis/adapters/analyticsAdapters/mixpanelAdapter.js.html +1 -1
  10. package/coverage/rabbit-ui-kit/src/common-apis/adapters/axiosAdapter.js.html +1 -1
  11. package/coverage/rabbit-ui-kit/src/common-apis/adapters/index.html +1 -1
  12. package/coverage/rabbit-ui-kit/src/common-apis/adapters/qrUtils.js.html +2 -2
  13. package/coverage/rabbit-ui-kit/src/common-apis/external-apis/apiGroups.js.html +1 -1
  14. package/coverage/rabbit-ui-kit/src/common-apis/{utils → external-apis}/emailAPI.js.html +4 -4
  15. package/coverage/rabbit-ui-kit/src/common-apis/external-apis/index.html +24 -9
  16. package/coverage/rabbit-ui-kit/src/common-apis/external-apis/ipAddressProviders.js.html +2 -2
  17. package/coverage/rabbit-ui-kit/src/common-apis/globalConstants.jsx.html +1 -1
  18. package/coverage/rabbit-ui-kit/src/common-apis/index.html +10 -55
  19. package/coverage/rabbit-ui-kit/src/common-apis/models/blockchain.js.html +1 -1
  20. package/coverage/rabbit-ui-kit/src/common-apis/models/coin.js.html +381 -96
  21. package/coverage/rabbit-ui-kit/src/common-apis/models/index.html +17 -17
  22. package/coverage/rabbit-ui-kit/src/common-apis/models/protocol.js.html +1 -1
  23. package/coverage/rabbit-ui-kit/src/common-apis/{fiatCurrenciesService.js.html → services/fiatCurrenciesService.js.html} +10 -10
  24. package/coverage/rabbit-ui-kit/src/common-apis/services/index.html +116 -0
  25. package/coverage/rabbit-ui-kit/src/common-apis/{amountUtils.js.html → utils/amountUtils.js.html} +11 -11
  26. package/coverage/rabbit-ui-kit/src/common-apis/utils/cache.js.html +2 -2
  27. package/coverage/rabbit-ui-kit/src/common-apis/{errorUtils.js.html → utils/errorUtils.js.html} +12 -12
  28. package/coverage/rabbit-ui-kit/src/common-apis/utils/index.html +49 -19
  29. package/coverage/rabbit-ui-kit/src/common-apis/utils/logging/index.html +1 -1
  30. package/coverage/rabbit-ui-kit/src/common-apis/utils/logging/logger.js.html +1 -1
  31. package/coverage/rabbit-ui-kit/src/common-apis/utils/logging/logsStorage.js.html +1 -1
  32. package/coverage/rabbit-ui-kit/src/common-apis/utils/postponeExecution.js.html +1 -1
  33. package/coverage/rabbit-ui-kit/src/common-apis/utils/rabbitTicker.js.html +157 -0
  34. package/coverage/rabbit-ui-kit/src/common-apis/utils/safeStringify.js.html +1 -1
  35. package/coverage/rabbit-ui-kit/src/index.html +5 -5
  36. package/coverage/rabbit-ui-kit/src/index.js.html +21 -9
  37. package/coverage/rabbit-ui-kit/src/robust-api-caller/cacheAndConcurrentRequestsResolver.js.html +2 -2
  38. package/coverage/rabbit-ui-kit/src/robust-api-caller/cachedRobustExternalApiCallerService.js.html +2 -2
  39. package/coverage/rabbit-ui-kit/src/robust-api-caller/cancelProcessing.js.html +1 -1
  40. package/coverage/rabbit-ui-kit/src/robust-api-caller/concurrentCalculationsMetadataHolder.js.html +1 -1
  41. package/coverage/rabbit-ui-kit/src/robust-api-caller/externalApiProvider.js.html +1 -1
  42. package/coverage/rabbit-ui-kit/src/robust-api-caller/externalServicesStatsCollector.js.html +2 -2
  43. package/coverage/rabbit-ui-kit/src/robust-api-caller/index.html +1 -1
  44. package/coverage/rabbit-ui-kit/src/robust-api-caller/robustExternalAPICallerService.js.html +2 -2
  45. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/index.html +28 -28
  46. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/letsExchangeSwapProvider.js.html +100 -31
  47. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapProvider.js.html +418 -208
  48. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapspaceSwapProvider.js.html +127 -40
  49. package/coverage/rabbit-ui-kit/src/swaps-lib/models/baseSwapCreationInfo.js.html +85 -4
  50. package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwap.js.html +1 -1
  51. package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwapWithFiatData.js.html +1 -1
  52. package/coverage/rabbit-ui-kit/src/swaps-lib/models/index.html +25 -25
  53. package/coverage/rabbit-ui-kit/src/swaps-lib/models/partner.js.html +76 -13
  54. package/coverage/rabbit-ui-kit/src/swaps-lib/models/swapProviderCoinInfo.js.html +147 -9
  55. package/coverage/rabbit-ui-kit/src/swaps-lib/services/index.html +5 -5
  56. package/coverage/rabbit-ui-kit/src/swaps-lib/services/publicSwapService.js.html +158 -23
  57. package/coverage/rabbit-ui-kit/src/swaps-lib/utils/index.html +1 -1
  58. package/coverage/rabbit-ui-kit/src/swaps-lib/utils/swapUtils.js.html +5 -5
  59. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/arrowIcon.jsx.html +1 -1
  60. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/arrowTosca.jsx.html +1 -1
  61. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/arrowWhite.jsx.html +1 -1
  62. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/darkRectangle.jsx.html +1 -1
  63. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/determinedError.jsx.html +1 -1
  64. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/failedValidationIcon.jsx.html +1 -1
  65. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/index.html +1 -1
  66. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/infoIcon.jsx.html +1 -1
  67. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/messageIcon.jsx.html +1 -1
  68. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/noticeQuestionIcon.jsx.html +1 -1
  69. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/successfulValidationIcon.jsx.html +1 -1
  70. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/supportDialogImage.jsx.html +1 -1
  71. package/coverage/rabbit-ui-kit/src/ui-kit/assets/wrappedImages/walletIcon.jsx.html +1 -1
  72. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetIcon/AssetIcon.jsx.html +1 -1
  73. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetIcon/index.html +1 -1
  74. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetSelection/AssetSelection.jsx.html +1 -1
  75. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/AssetSelection/index.html +1 -1
  76. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/BackgroundTitle/BackgroundTitle.jsx.html +1 -1
  77. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/BackgroundTitle/index.html +1 -1
  78. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/InformationMessage/InformationMessage.jsx.html +1 -1
  79. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/InformationMessage/index.html +1 -1
  80. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Input/Input.jsx.html +2 -2
  81. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Input/index.html +1 -1
  82. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/LoadingDots/LoadingDots.jsx.html +1 -1
  83. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/LoadingDots/index.html +1 -1
  84. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/NoticeIcon/NoticeIcon.jsx.html +1 -1
  85. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/NoticeIcon/index.html +1 -1
  86. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/QrCode/QrCode.jsx.html +2 -2
  87. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/QrCode/index.html +1 -1
  88. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/RateSelector/RateSelector.jsx.html +1 -1
  89. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/RateSelector/index.html +1 -1
  90. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/SupportChat/SupportChat.jsx.html +1 -1
  91. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/SupportChat/index.html +1 -1
  92. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Textarea/Textarea.jsx.html +1 -1
  93. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Textarea/index.html +1 -1
  94. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TitleBox/TitleBox.jsx.html +1 -1
  95. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TitleBox/index.html +1 -1
  96. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Tooltip/Tooltip.jsx.html +1 -1
  97. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Tooltip/index.html +1 -1
  98. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TwoLinesOfText/LinesOfText.jsx.html +1 -1
  99. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/TwoLinesOfText/index.html +1 -1
  100. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Validation/Validation.jsx.html +1 -1
  101. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/Validation/index.html +1 -1
  102. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Button/Button.jsx.html +1 -1
  103. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Button/index.html +1 -1
  104. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Close/Close.jsx.html +1 -1
  105. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/Close/index.html +1 -1
  106. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/LinkButton/LinkButton.jsx.html +1 -1
  107. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/LinkButton/index.html +1 -1
  108. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/RadioButtonWithText/RadioButtonWithText.jsx.html +1 -1
  109. package/coverage/rabbit-ui-kit/src/ui-kit/components/atoms/buttons/RadioButtonWithText/index.html +1 -1
  110. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/AmountInput/AmountInput.jsx.html +3 -3
  111. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/AmountInput/index.html +1 -1
  112. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/CoinPicker/CoinPicker.jsx.html +3 -3
  113. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/CoinPicker/index.html +1 -1
  114. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/ColoredNotice/ColoredNotice.jsx.html +1 -1
  115. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/ColoredNotice/index.html +1 -1
  116. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LineWithIconLink/LineWithIconLink.jsx.html +1 -1
  117. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LineWithIconLink/index.html +1 -1
  118. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LogoCarousel/LogoCarousel.jsx.html +1 -1
  119. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/LogoCarousel/index.html +1 -1
  120. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/SearchableCoinsList/SearchableCoinsList.jsx.html +6 -6
  121. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/SearchableCoinsList/index.html +1 -1
  122. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/TitledLineWithIconLink/TitledLineWithIconLink.jsx.html +1 -1
  123. package/coverage/rabbit-ui-kit/src/ui-kit/components/molecules/TitledLineWithIconLink/index.html +1 -1
  124. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/CoinPickerDialogStep/CoinPickerDialogStep.jsx.html +1 -1
  125. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/CoinPickerDialogStep/index.html +1 -1
  126. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/Dialog.jsx.html +2 -2
  127. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogButtons/DialogButtons.jsx.html +1 -1
  128. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogButtons/index.html +1 -1
  129. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogStep/DialogStep.jsx.html +2 -2
  130. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/DialogStep/index.html +1 -1
  131. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/Dialog/index.html +1 -1
  132. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/SwapForm/SwapForm.jsx.html +40 -7
  133. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/SwapForm/index.html +5 -5
  134. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/WaitlistSubscription/WaitlistSubscription.jsx.html +2 -2
  135. package/coverage/rabbit-ui-kit/src/ui-kit/components/organisms/WaitlistSubscription/index.html +1 -1
  136. package/coverage/rabbit-ui-kit/src/ui-kit/components/templates/DeterminedErrorDialogStep/DeterminedErrorDialogStep.jsx.html +1 -1
  137. package/coverage/rabbit-ui-kit/src/ui-kit/components/templates/DeterminedErrorDialogStep/index.html +1 -1
  138. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/index.html +1 -1
  139. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/useCallHandlingErrors.js.html +1 -1
  140. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/useIsHydrated.js.html +1 -1
  141. package/coverage/rabbit-ui-kit/src/ui-kit/hooks/useReferredState.js.html +1 -1
  142. package/coverage/rabbit-ui-kit/src/ui-kit/utils/index.html +1 -1
  143. package/coverage/rabbit-ui-kit/src/ui-kit/utils/inputValueProviders.js.html +1 -1
  144. package/coverage/rabbit-ui-kit/src/ui-kit/utils/textUtils.js.html +2 -2
  145. package/coverage/rabbit-ui-kit/src/ui-kit/utils/uiUtils.js.html +1 -1
  146. package/coverage/rabbit-ui-kit/src/ui-kit/utils/urlQueryUtils.js.html +1 -1
  147. package/coverage/rabbit-ui-kit/stories/atoms/BackgroundTitle.stories.jsx.html +1 -1
  148. package/coverage/rabbit-ui-kit/stories/atoms/LinesOfText.stories.jsx.html +1 -1
  149. package/coverage/rabbit-ui-kit/stories/atoms/LoadingDots.stories.jsx.html +1 -1
  150. package/coverage/rabbit-ui-kit/stories/atoms/QrCode.stories.jsx.html +1 -1
  151. package/coverage/rabbit-ui-kit/stories/atoms/RateSelector.stories.jsx.html +1 -1
  152. package/coverage/rabbit-ui-kit/stories/atoms/Validation.stories.jsx.html +1 -1
  153. package/coverage/rabbit-ui-kit/stories/atoms/buttons/Button.stories.jsx.html +1 -1
  154. package/coverage/rabbit-ui-kit/stories/atoms/buttons/Close.stories.jsx.html +1 -1
  155. package/coverage/rabbit-ui-kit/stories/atoms/buttons/LinkButton.stories.jsx.html +1 -1
  156. package/coverage/rabbit-ui-kit/stories/atoms/buttons/index.html +1 -1
  157. package/coverage/rabbit-ui-kit/stories/atoms/index.html +1 -1
  158. package/coverage/rabbit-ui-kit/stories/molecules/AmountInput.stories.jsx.html +1 -1
  159. package/coverage/rabbit-ui-kit/stories/molecules/CoinPicker.stories.jsx.html +1 -1
  160. package/coverage/rabbit-ui-kit/stories/molecules/ColoredNotice.stories.jsx.html +1 -1
  161. package/coverage/rabbit-ui-kit/stories/molecules/LineWithIconLink.stories.jsx.html +1 -1
  162. package/coverage/rabbit-ui-kit/stories/molecules/LogoCarousel.stories.jsx.html +1 -1
  163. package/coverage/rabbit-ui-kit/stories/molecules/TitledLineWithIconLink.stories.jsx.html +1 -1
  164. package/coverage/rabbit-ui-kit/stories/molecules/index.html +1 -1
  165. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/Dialog.stories.jsx.html +1 -1
  166. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/DialogButtons.stories.jsx.html +1 -1
  167. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/index.html +1 -1
  168. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/DialogStep.stories.jsx.html +1 -1
  169. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/index.html +1 -1
  170. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/index.html +1 -1
  171. package/coverage/rabbit-ui-kit/stories/organisms/WaitlistSubscription.stories.jsx.html +1 -1
  172. package/coverage/rabbit-ui-kit/stories/organisms/index.html +1 -1
  173. package/coverage/rabbit-ui-kit/stories/stubs/coins.jsx.html +1 -1
  174. package/coverage/rabbit-ui-kit/stories/stubs/exampleContent.jsx.html +1 -1
  175. package/coverage/rabbit-ui-kit/stories/stubs/index.html +1 -1
  176. package/coverage/rabbit-ui-kit/stories/templates/DeterminedErrorDialogStep.stories.jsx.html +1 -1
  177. package/coverage/rabbit-ui-kit/stories/templates/index.html +1 -1
  178. package/dist/index.cjs +1547 -1178
  179. package/dist/index.cjs.map +1 -1
  180. package/dist/index.modern.js +751 -421
  181. package/dist/index.modern.js.map +1 -1
  182. package/dist/index.module.js +1543 -1179
  183. package/dist/index.module.js.map +1 -1
  184. package/dist/index.umd.js +1547 -1178
  185. package/dist/index.umd.js.map +1 -1
  186. package/package.json +1 -1
  187. package/src/common-apis/adapters/qrUtils.js +1 -1
  188. package/src/common-apis/{utils → external-apis}/emailAPI.js +1 -1
  189. package/src/common-apis/external-apis/ipAddressProviders.js +1 -1
  190. package/src/common-apis/models/coin.js +96 -1
  191. package/src/common-apis/tests/{amountUtils → units/utils/amountUtils}/composeRateText.test.js +1 -1
  192. package/src/common-apis/{amountUtils.js → utils/amountUtils.js} +1 -1
  193. package/src/common-apis/utils/cache.js +1 -1
  194. package/src/common-apis/{errorUtils.js → utils/errorUtils.js} +2 -2
  195. package/src/common-apis/utils/rabbitTicker.js +24 -0
  196. package/src/index.js +9 -5
  197. package/src/robust-api-caller/cacheAndConcurrentRequestsResolver.js +1 -1
  198. package/src/robust-api-caller/cachedRobustExternalApiCallerService.js +1 -1
  199. package/src/robust-api-caller/externalServicesStatsCollector.js +1 -1
  200. package/src/robust-api-caller/robustExternalAPICallerService.js +1 -1
  201. package/src/swaps-lib/external-apis/letsExchangeSwapProvider.js +50 -27
  202. package/src/swaps-lib/external-apis/swapProvider.js +84 -14
  203. package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +54 -25
  204. package/src/swaps-lib/models/baseSwapCreationInfo.js +27 -0
  205. package/src/swaps-lib/models/partner.js +22 -1
  206. package/src/swaps-lib/models/swapProviderCoinInfo.js +46 -0
  207. package/src/swaps-lib/services/publicSwapService.js +64 -19
  208. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +0 -3
  209. package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getSwapInfo.test.js +9 -2
  210. package/src/swaps-lib/test/utils/swapUtils/safeHandleRequestsLimitExceeding.test.js +1 -1
  211. package/src/swaps-lib/utils/swapUtils.js +4 -4
  212. package/src/ui-kit/components/atoms/Input/Input.jsx +1 -1
  213. package/src/ui-kit/components/atoms/QrCode/QrCode.jsx +1 -1
  214. package/src/ui-kit/components/molecules/AmountInput/AmountInput.jsx +2 -2
  215. package/src/ui-kit/components/molecules/CoinPicker/CoinPicker.jsx +2 -2
  216. package/src/ui-kit/components/molecules/SearchableCoinsList/SearchableCoinsList.jsx +5 -5
  217. package/src/ui-kit/components/organisms/Dialog/Dialog.jsx +1 -1
  218. package/src/ui-kit/components/organisms/Dialog/DialogStep/DialogStep.jsx +1 -1
  219. package/src/ui-kit/components/organisms/SwapForm/SwapForm.jsx +14 -3
  220. package/src/ui-kit/components/organisms/WaitlistSubscription/WaitlistSubscription.jsx +1 -1
  221. package/src/ui-kit/utils/textUtils.js +1 -1
  222. /package/src/common-apis/{fiatCurrenciesService.js → services/fiatCurrenciesService.js} +0 -0
package/dist/index.cjs CHANGED
@@ -4800,6 +4800,7 @@ function useIsHydrated() {
4800
4800
  * @param {string} ticker - Ticker symbol of the asset.
4801
4801
  * @param {string} address - Address to be validated
4802
4802
  * @param {boolean} isFixed - Is swap rate mode = fixed
4803
+ * @param {function} setValidationContent - Function setting validation message text
4803
4804
  * @return {Promise<boolean>}
4804
4805
  */
4805
4806
 
@@ -5452,7 +5453,7 @@ var SwapForm = function SwapForm(_ref) {
5452
5453
  };
5453
5454
  if (!receivingAssetTicker) return;
5454
5455
  var _temp = recipientAddress.current === "";
5455
- return _temp ? _temp2(false) : Promise.resolve(validateAddressByTicker(receivingAssetTicker, recipientAddress.current, isFixedRate.current)).then(_temp2);
5456
+ return _temp ? _temp2(false) : Promise.resolve(validateAddressByTicker(receivingAssetTicker, recipientAddress.current, isFixedRate.current, setValidationContent)).then(_temp2);
5456
5457
  } catch (e) {
5457
5458
  Promise.reject(e);
5458
5459
  }
@@ -5467,7 +5468,7 @@ var SwapForm = function SwapForm(_ref) {
5467
5468
  };
5468
5469
  if (!sendingAssetTicker || !isRefundAddressRequired) return;
5469
5470
  var _temp3 = refundAddress.current === "";
5470
- return _temp3 ? _temp4(false) : Promise.resolve(validateAddressByTicker(sendingAssetTicker, refundAddress.current, isFixedRate.current)).then(_temp4);
5471
+ return _temp3 ? _temp4(false) : Promise.resolve(validateAddressByTicker(sendingAssetTicker, refundAddress.current, isFixedRate.current, setValidationContent)).then(_temp4);
5471
5472
  } catch (e) {
5472
5473
  Promise.reject(e);
5473
5474
  }
@@ -6582,160 +6583,12 @@ var s$2 = {"coin-picker":"_mvuzQ","loading":"_18kIX","item":"_fSxCX","link":"_rO
6582
6583
  var FALLBACK_ASSET_ICON_URL = "https://rabbit.io/asset-icons/fallback.svg";
6583
6584
  var DEFAULT_CRYPTO_DECIMAL_COUNT = 8;
6584
6585
 
6585
- /**
6586
- * The model for cryptocurrency coins.
6587
- *
6588
- * WARNING: this class should not be instantiated directly. Use only predefined singleton Coin (or descendants) instances.
6589
- */
6590
- var Coin = /*#__PURE__*/function () {
6591
- /**
6592
- * Creates new coin
6593
- *
6594
- * @param latinName {string} the coin name in latin symbols like "Bitcoin"
6595
- * @param ticker {string} the coin symbol/ticker/code like 'BTC'. Always upper case. A unique coin identifier
6596
- * @param tickerPrintable {string} ticker but in printable format. Useful for tokens based on external blockchains
6597
- * like ERC20 or TRC20. It is not friendly to display USDTERC20 or BUSDTRC20 - more neat options are just
6598
- * USDT and BUSD. Note that you should always care about user's understanding of what coin he/she is working
6599
- * with as printable ticker for USDTERC20 and USDTTRC20 are the same.
6600
- * @param digitsCountAfterComma {number} count of digits after the comma. E.g. 8 for bitcoin
6601
- * @param maxValue {number|null} max possible value for cryptocurrency. Null means that the currency has no max possible value
6602
- * @param atomName {string} name of the coin's atomic value. Like 'satoshi' for bitcoin
6603
- * @param mainnet {Network} main network for this coin
6604
- * @param testnet {Network} test network for this coin
6605
- * @param minConfirmations {number} min confirmations count to treat the coin's transaction confirmed
6606
- * @param payableEntityStringForFeeRate {string|null} the payable fee entity like byte for bitcoin or gas for ether if present
6607
- * @param feeOptionsTimeStringsSortedDesc {string[]} array of 4 strings for fee options when sending coins. Should be sorted from the highest time to the smallest
6608
- * @param feeRatesExpirationTimeMs {number} number of milliseconds to treat the fee rates as expired
6609
- * @param blockchain {Blockchain} blockchain object
6610
- * @param [protocol] {Protocol|null} token/coin protocol if relevant
6611
- * @param [tokenAddress] {string|null} address of contract of this token (if the coin is token)
6612
- * @param [doesUseLowerCaseAddresses] {boolean} flag to clarify whether we can use lower case addresses to ensure more robust comparisons
6613
- * @param [doesUseOutputs=false] {boolean} true if this coin uses inputs/outputs concept and false if it uses just balances
6614
- */
6615
- function Coin(latinName, ticker, tickerPrintable, digitsCountAfterComma, maxValue, atomName, mainnet, testnet, minConfirmations, payableEntityStringForFeeRate, feeOptionsTimeStringsSortedDesc, feeRatesExpirationTimeMs, blockchain, protocol, tokenAddress, doesUseLowerCaseAddresses, doesUseOutputs) {
6616
- if (protocol === void 0) {
6617
- protocol = null;
6618
- }
6619
- if (tokenAddress === void 0) {
6620
- tokenAddress = null;
6621
- }
6622
- if (doesUseLowerCaseAddresses === void 0) {
6623
- doesUseLowerCaseAddresses = true;
6624
- }
6625
- if (doesUseOutputs === void 0) {
6626
- doesUseOutputs = false;
6627
- }
6628
- this.latinName = latinName;
6629
- this.ticker = ticker;
6630
- this.tickerPrintable = tickerPrintable;
6631
- this.digits = digitsCountAfterComma;
6632
- this.maxValue = maxValue;
6633
- this.atomName = atomName;
6634
- this.mainnet = mainnet;
6635
- this.testnet = testnet;
6636
- this.minConfirmations = minConfirmations;
6637
- this.payableEntityStringForFeeRate = payableEntityStringForFeeRate;
6638
- this.feeOptionsTimeStringsSortedDesc = feeOptionsTimeStringsSortedDesc;
6639
- this.feeRatesExpirationTimeMs = feeRatesExpirationTimeMs;
6640
- this.protocol = protocol;
6641
- this.blockchain = blockchain;
6642
- // TODO: [bug, critical] use testnet property for testnet contract address as it blocks the app work in testnets
6643
- this.tokenAddress = tokenAddress;
6644
- this.feeCoin = this;
6645
- this._significantDigits = 8;
6646
- this.doesUseLowerCaseAddresses = doesUseLowerCaseAddresses;
6647
- this.doesUseOutputs = doesUseOutputs;
6648
- }
6649
-
6650
- /**
6651
- * Sets fee coin
6652
- *
6653
- * @param feeCoin {Coin} some tokens use another coin to charge transaction fee as they work on top of some external
6654
- * blockchain. So pass here the coin the token uses for fee charging. Like for ERC20 token the fee coin is ETH.
6655
- * By default, the creating coin will be set as a value for this field.
6656
- */
6657
- var _proto = Coin.prototype;
6658
- _proto.setFeeCoin = function setFeeCoin(feeCoin) {
6659
- this.feeCoin = feeCoin;
6660
- }
6661
-
6662
- /**
6663
- * Checks whether this coin uses another coin (blockchain) to charge fee for transactions (means works on base of
6664
- * some external blockchain).
6665
- *
6666
- * @return {boolean} true if this coin uses external blockchain to perform transactions and charge fee
6667
- */;
6668
- _proto.doesUseDifferentCoinFee = function doesUseDifferentCoinFee() {
6669
- return this.feeCoin !== this;
6670
- }
6671
-
6672
- /**
6673
- * Converts the given atoms string/number to string representing the same amount in coin itself - floating point number
6674
- *
6675
- * @param atoms {string} atoms positive integer amount
6676
- * @return {string} coin amount floating point number as a string
6677
- */;
6678
- _proto.atomsToCoinAmount = function atomsToCoinAmount(atoms) {
6679
- throw new Error("Not implemented in base Coin");
6680
- }
6681
-
6682
- /**
6683
- * Converts the given coins amount string/number to string representing the same amount in coin atoms - integer number
6684
- *
6685
- * @param coinsAmount {string} coins positive floating point amount
6686
- * @return {string} coin atoms amount integer number as a string
6687
- */;
6688
- _proto.coinAmountToAtoms = function coinAmountToAtoms(coinsAmount) {
6689
- throw new Error("Not implemented in base Coin");
6690
- }
6691
-
6692
- /**
6693
- * Composes URL to view the tx with given id in the external blockchain explorer
6694
- *
6695
- * @param txId {string} id of transaction
6696
- * @return {string} URL string
6697
- */;
6698
- _proto.composeUrlToTransactionExplorer = function composeUrlToTransactionExplorer(txId) {
6699
- throw new Error("Not implemented in base Coin");
6700
- }
6701
-
6702
- /**
6703
- * Most of the cryptocurrencies has specific fee rate or fee price metric. This value usually has specific measure
6704
- * like satoshi/byte or gWei/gas. This function adds the described denomination string to the given amount
6705
- * as a suffix and returns the result string ready to be show to a user.
6706
- *
6707
- * @param coinAtomsString {string} coin atoms positive integer amount
6708
- * @return {string} string of coin amount and fee rate units
6709
- */;
6710
- _proto.coinAtomsFeeRateToCommonlyUsedAmountFormatWithDenominationString = function coinAtomsFeeRateToCommonlyUsedAmountFormatWithDenominationString(coinAtomsString) {
6711
- throw new Error("Not implemented in base Coin");
6712
- }
6713
-
6714
- /**
6715
- * Check whether this coin support transaction prioritisation during the sending process.
6716
- *
6717
- * @return {boolean} true if support transaction prioritisation and false otherwise
6718
- */;
6719
- _proto.doesSupportTransactionPrioritisation = function doesSupportTransactionPrioritisation() {
6720
- return Array.isArray(this.feeOptionsTimeStringsSortedDesc);
6721
- };
6722
- _proto.tickerAndProtocol = function tickerAndProtocol() {
6723
- try {
6724
- var _ref;
6725
- return "" + this.tickerPrintable + (this.protocol ? (_ref = " " + this.protocol.protocol) != null ? _ref : "" : "");
6726
- } catch (e) {
6727
- improveAndRethrow(e, "tickerAndProtocol");
6728
- }
6729
- };
6730
- return Coin;
6731
- }();
6732
-
6733
6586
  /**
6734
6587
  * A component that displays a list of coins that can be searched and filtered.
6735
6588
  *
6736
6589
  * @param {Object} props - The properties object.
6737
- * @param {Coin[]} props.coinsList - The list of all available coins.
6738
- * @param {Array<{coin: Coin, component: React.Component}>} props.coinsBundle - The bundle of coin components to be displayed.
6590
+ * @param {{ ticker:string, tickerPrintable: string, latinName: string }[]} props.coinsList - The list of all available coins.
6591
+ * @param {Array<{ ticker: string, component: React.Component }>} props.coinsBundle - The bundle of coin components to be displayed.
6739
6592
  * @param {string} props.searchQuery - The search query to filter coins.
6740
6593
  * @param {boolean} props.partialLoadingEnabled - Determines if partial loading is enabled.
6741
6594
  * @param {number} props.partialLoadingIncrement - The increment of coins to load when loading more.
@@ -6835,7 +6688,7 @@ var SearchableCoinsList = function SearchableCoinsList(_ref) {
6835
6688
  }, [coinsList, searchQuery]);
6836
6689
  return displayedCoins.map(function (coin) {
6837
6690
  return coinsBundle.find(function (bundleItem) {
6838
- return bundleItem.coin.ticker === coin.ticker;
6691
+ return bundleItem.ticker === coin.ticker;
6839
6692
  }).component;
6840
6693
  }).map(function (Item) {
6841
6694
  return /*#__PURE__*/React__default["default"].createElement(Item, null);
@@ -7170,7 +7023,7 @@ var CoinPicker = function CoinPicker(_ref) {
7170
7023
  coinsList: coins,
7171
7024
  coinsBundle: coins == null ? void 0 : coins.map(function (coin, index) {
7172
7025
  return {
7173
- coin: coin,
7026
+ ticker: coin.ticker,
7174
7027
  component: function component() {
7175
7028
  var _coinsContent$find$su, _coinsContent$find;
7176
7029
  var _coinToIconPaths = coinToIconPaths(coin),
@@ -7387,115 +7240,247 @@ ColoredNotice.defaultProps = {
7387
7240
  onButtonClick: function onButtonClick() {}
7388
7241
  };
7389
7242
 
7390
- var messageIcon = (function () {
7391
- return /*#__PURE__*/React__default["default"].createElement("svg", {
7392
- width: "130",
7393
- height: "130",
7394
- viewBox: "0 0 130 130",
7395
- fill: "none",
7396
- xmlns: "http://www.w3.org/2000/svg"
7397
- }, /*#__PURE__*/React__default["default"].createElement("path", {
7398
- "fill-rule": "evenodd",
7399
- "clip-rule": "evenodd",
7400
- d: "M65 130C100.899 130 130 100.899 130 65C130 29.1015 100.899 0 65 0C29.1015 0 0 29.1015 0 65C0 100.899 29.1015 130 65 130Z",
7401
- fill: "#2294F0"
7402
- }), /*#__PURE__*/React__default["default"].createElement("mask", {
7403
- id: "mask0",
7404
- style: {
7405
- maskType: "alpha"
7406
- },
7407
- maskUnits: "userSpaceOnUse",
7408
- x: "0",
7409
- y: "0",
7410
- width: "130",
7411
- height: "130"
7412
- }, /*#__PURE__*/React__default["default"].createElement("path", {
7413
- "fill-rule": "evenodd",
7414
- "clip-rule": "evenodd",
7415
- d: "M65 130C100.899 130 130 100.899 130 65C130 29.1015 100.899 0 65 0C29.1015 0 0 29.1015 0 65C0 100.899 29.1015 130 65 130Z",
7416
- fill: "white"
7417
- })), /*#__PURE__*/React__default["default"].createElement("g", {
7418
- mask: "url(#mask0)"
7419
- }, /*#__PURE__*/React__default["default"].createElement("rect", {
7420
- opacity: "0.3",
7421
- x: "3.25",
7422
- y: "150.776",
7423
- width: "227.136",
7424
- height: "25.2373",
7425
- transform: "rotate(-45 3.25 150.776)",
7426
- fill: "white"
7427
- }), /*#__PURE__*/React__default["default"].createElement("rect", {
7428
- opacity: "0.3",
7429
- x: "-48.4546",
7430
- y: "126.52",
7431
- width: "227.136",
7432
- height: "25.2373",
7433
- transform: "rotate(-45 -48.4546 126.52)",
7434
- fill: "white"
7435
- }), /*#__PURE__*/React__default["default"].createElement("rect", {
7436
- x: "27.75",
7437
- y: "29.5",
7438
- width: "74.5",
7439
- height: "81.5",
7440
- rx: "12",
7441
- fill: "white"
7442
- }), /*#__PURE__*/React__default["default"].createElement("path", {
7443
- d: "M27.75 41.5C27.75 34.8726 33.1226 29.5 39.75 29.5H90.25C96.8774 29.5 102.25 34.8726 102.25 41.5V118C102.25 124.627 96.8774 130 90.25 130H39.75C33.1226 130 27.75 124.627 27.75 118V41.5Z",
7444
- fill: "white"
7445
- }), /*#__PURE__*/React__default["default"].createElement("path", {
7446
- "fill-rule": "evenodd",
7447
- "clip-rule": "evenodd",
7448
- d: "M51.5 63.5C58.1274 63.5 63.5 58.1274 63.5 51.5C63.5 44.8726 58.1274 39.5 51.5 39.5C44.8726 39.5 39.5 44.8726 39.5 51.5C39.5 58.1274 44.8726 63.5 51.5 63.5Z",
7449
- fill: "#2294F0"
7450
- }), /*#__PURE__*/React__default["default"].createElement("path", {
7451
- d: "M50.072 49.088H52.03V54.5H50.072V49.088ZM52.074 46.382V48.153H50.028V46.382H52.074Z",
7452
- fill: "white"
7453
- }), /*#__PURE__*/React__default["default"].createElement("path", {
7454
- opacity: "0.2",
7455
- d: "M41 74.5H63",
7456
- stroke: "#2294F0",
7457
- "stroke-width": "4",
7458
- "stroke-linecap": "round",
7459
- "stroke-linejoin": "round"
7460
- }), /*#__PURE__*/React__default["default"].createElement("path", {
7461
- opacity: "0.2",
7462
- d: "M41 84.6157H84.1426",
7463
- stroke: "#2294F0",
7464
- "stroke-width": "4",
7465
- "stroke-linecap": "round",
7466
- "stroke-linejoin": "round"
7467
- }), /*#__PURE__*/React__default["default"].createElement("path", {
7468
- opacity: "0.2",
7469
- d: "M41 94.7314H84.1426",
7470
- stroke: "#2294F0",
7471
- "stroke-width": "4",
7472
- "stroke-linecap": "round",
7473
- "stroke-linejoin": "round"
7474
- }), /*#__PURE__*/React__default["default"].createElement("path", {
7475
- opacity: "0.2",
7476
- d: "M41 104.731H84.1426",
7477
- stroke: "#2294F0",
7478
- "stroke-width": "4",
7479
- "stroke-linecap": "round",
7480
- "stroke-linejoin": "round"
7481
- })));
7482
- });
7243
+ /**
7244
+ * The model for cryptocurrency coins.
7245
+ *
7246
+ * WARNING: this class should not be instantiated directly. Use only predefined singleton Coin (or descendants) instances.
7247
+ */
7248
+ var Coin = /*#__PURE__*/function () {
7249
+ /**
7250
+ * @type {string}
7251
+ */
7483
7252
 
7484
- var supportDialogImage = (function () {
7485
- return /*#__PURE__*/React__default["default"].createElement("svg", {
7486
- width: "130",
7487
- height: "130",
7488
- viewBox: "0 0 130 130",
7489
- fill: "none",
7490
- xmlns: "http://www.w3.org/2000/svg"
7253
+ /**
7254
+ * @type {string}
7255
+ */
7256
+
7257
+ /**
7258
+ * @type {string}
7259
+ */
7260
+
7261
+ /**
7262
+ * @type {number}
7263
+ */
7264
+
7265
+ /**
7266
+ * @type {number|null}
7267
+ */
7268
+
7269
+ /**
7270
+ * @type {string}
7271
+ */
7272
+
7273
+ /**
7274
+ * @type {Network}
7275
+ */
7276
+
7277
+ /**
7278
+ * @type {Network}
7279
+ */
7280
+
7281
+ /**
7282
+ * @type {number}
7283
+ */
7284
+
7285
+ /**
7286
+ * @type {string|null}
7287
+ */
7288
+
7289
+ /**
7290
+ * @type {string[]}
7291
+ */
7292
+
7293
+ /**
7294
+ * @type {number}
7295
+ */
7296
+
7297
+ /**
7298
+ * @type {Blockchain}
7299
+ */
7300
+
7301
+ /**
7302
+ * @type {Protocol|null}
7303
+ */
7304
+
7305
+ /**
7306
+ * @type {string|null}
7307
+ */
7308
+
7309
+ /**
7310
+ * @type {boolean}
7311
+ */
7312
+
7313
+ /**
7314
+ * @type {boolean}
7315
+ */
7316
+
7317
+ /**
7318
+ * @type {Coin}
7319
+ */
7320
+
7321
+ /**
7322
+ * @type {number}
7323
+ */
7324
+
7325
+ /**
7326
+ * Creates new coin
7327
+ *
7328
+ * @param latinName {string} the coin name in latin symbols like "Bitcoin"
7329
+ * @param ticker {string} the coin symbol/ticker/code like 'BTC'. Always upper case. A unique coin identifier
7330
+ * @param tickerPrintable {string} ticker but in printable format. Useful for tokens based on external blockchains
7331
+ * like ERC20 or TRC20. It is not friendly to display USDTERC20 or BUSDTRC20 - more neat options are just
7332
+ * USDT and BUSD. Note that you should always care about user's understanding of what coin he/she is working
7333
+ * with as printable ticker for USDTERC20 and USDTTRC20 are the same.
7334
+ * @param digitsCountAfterComma {number} count of digits after the comma. E.g. 8 for bitcoin
7335
+ * @param maxValue {number|null} max possible value for cryptocurrency. Null means that the currency has no max possible value
7336
+ * @param atomName {string} name of the coin's atomic value. Like 'satoshi' for bitcoin
7337
+ * @param mainnet {Network} main network for this coin
7338
+ * @param testnet {Network} test network for this coin
7339
+ * @param minConfirmations {number} min confirmations count to treat the coin's transaction confirmed
7340
+ * @param payableEntityStringForFeeRate {string|null} the payable fee entity like byte for bitcoin or gas for ether if present
7341
+ * @param feeOptionsTimeStringsSortedDesc {string[]} array of 4 strings for fee options when sending coins. Should be sorted from the highest time to the smallest
7342
+ * @param feeRatesExpirationTimeMs {number} number of milliseconds to treat the fee rates as expired
7343
+ * @param blockchain {Blockchain} blockchain object
7344
+ * @param [protocol] {Protocol|null} token/coin protocol if relevant
7345
+ * @param [tokenAddress] {string|null} address of contract of this token (if the coin is token)
7346
+ * @param [doesUseLowerCaseAddresses] {boolean} flag to clarify whether we can use lower case addresses to ensure more robust comparisons
7347
+ * @param [doesUseOutputs=false] {boolean} true if this coin uses inputs/outputs concept and false if it uses just balances
7348
+ */
7349
+ function Coin(latinName, ticker, tickerPrintable, digitsCountAfterComma, maxValue, atomName, mainnet, testnet, minConfirmations, payableEntityStringForFeeRate, feeOptionsTimeStringsSortedDesc, feeRatesExpirationTimeMs, blockchain, protocol, tokenAddress, doesUseLowerCaseAddresses, doesUseOutputs) {
7350
+ if (protocol === void 0) {
7351
+ protocol = null;
7352
+ }
7353
+ if (tokenAddress === void 0) {
7354
+ tokenAddress = null;
7355
+ }
7356
+ if (doesUseLowerCaseAddresses === void 0) {
7357
+ doesUseLowerCaseAddresses = true;
7358
+ }
7359
+ if (doesUseOutputs === void 0) {
7360
+ doesUseOutputs = false;
7361
+ }
7362
+ this.latinName = latinName;
7363
+ this.ticker = ticker;
7364
+ this.tickerPrintable = tickerPrintable;
7365
+ this.digits = digitsCountAfterComma;
7366
+ this.maxValue = maxValue;
7367
+ this.atomName = atomName;
7368
+ this.mainnet = mainnet;
7369
+ this.testnet = testnet;
7370
+ this.minConfirmations = minConfirmations;
7371
+ this.payableEntityStringForFeeRate = payableEntityStringForFeeRate;
7372
+ this.feeOptionsTimeStringsSortedDesc = feeOptionsTimeStringsSortedDesc;
7373
+ this.feeRatesExpirationTimeMs = feeRatesExpirationTimeMs;
7374
+ this.protocol = protocol;
7375
+ this.blockchain = blockchain;
7376
+ // TODO: [bug, critical] use testnet property for testnet contract address as it blocks the app work in testnets
7377
+ this.tokenAddress = tokenAddress;
7378
+ this.feeCoin = this;
7379
+ this._significantDigits = 8;
7380
+ this.doesUseLowerCaseAddresses = doesUseLowerCaseAddresses;
7381
+ this.doesUseOutputs = doesUseOutputs;
7382
+ }
7383
+
7384
+ /**
7385
+ * Sets fee coin
7386
+ *
7387
+ * @param feeCoin {Coin} some tokens use another coin to charge transaction fee as they work on top of some external
7388
+ * blockchain. So pass here the coin the token uses for fee charging. Like for ERC20 token the fee coin is ETH.
7389
+ * By default, the creating coin will be set as a value for this field.
7390
+ */
7391
+ var _proto = Coin.prototype;
7392
+ _proto.setFeeCoin = function setFeeCoin(feeCoin) {
7393
+ this.feeCoin = feeCoin;
7394
+ }
7395
+
7396
+ /**
7397
+ * Checks whether this coin uses another coin (blockchain) to charge fee for transactions (means works on base of
7398
+ * some external blockchain).
7399
+ *
7400
+ * @return {boolean} true if this coin uses external blockchain to perform transactions and charge fee
7401
+ */;
7402
+ _proto.doesUseDifferentCoinFee = function doesUseDifferentCoinFee() {
7403
+ return this.feeCoin !== this;
7404
+ }
7405
+
7406
+ /**
7407
+ * Converts the given atoms string/number to string representing the same amount in coin itself - floating point number
7408
+ *
7409
+ * @param atoms {string} atoms positive integer amount
7410
+ * @return {string} coin amount floating point number as a string
7411
+ */;
7412
+ _proto.atomsToCoinAmount = function atomsToCoinAmount(atoms) {
7413
+ throw new Error("Not implemented in base Coin");
7414
+ }
7415
+
7416
+ /**
7417
+ * Converts the given coins amount string/number to string representing the same amount in coin atoms - integer number
7418
+ *
7419
+ * @param coinsAmount {string} coins positive floating point amount
7420
+ * @return {string} coin atoms amount integer number as a string
7421
+ */;
7422
+ _proto.coinAmountToAtoms = function coinAmountToAtoms(coinsAmount) {
7423
+ throw new Error("Not implemented in base Coin");
7424
+ }
7425
+
7426
+ /**
7427
+ * Composes URL to view the tx with given id in the external blockchain explorer
7428
+ *
7429
+ * @param txId {string} id of transaction
7430
+ * @return {string} URL string
7431
+ */;
7432
+ _proto.composeUrlToTransactionExplorer = function composeUrlToTransactionExplorer(txId) {
7433
+ throw new Error("Not implemented in base Coin");
7434
+ }
7435
+
7436
+ /**
7437
+ * Most of the cryptocurrencies has specific fee rate or fee price metric. This value usually has specific measure
7438
+ * like satoshi/byte or gWei/gas. This function adds the described denomination string to the given amount
7439
+ * as a suffix and returns the result string ready to be show to a user.
7440
+ *
7441
+ * @param coinAtomsString {string} coin atoms positive integer amount
7442
+ * @return {string} string of coin amount and fee rate units
7443
+ */;
7444
+ _proto.coinAtomsFeeRateToCommonlyUsedAmountFormatWithDenominationString = function coinAtomsFeeRateToCommonlyUsedAmountFormatWithDenominationString(coinAtomsString) {
7445
+ throw new Error("Not implemented in base Coin");
7446
+ }
7447
+
7448
+ /**
7449
+ * Check whether this coin support transaction prioritisation during the sending process.
7450
+ *
7451
+ * @return {boolean} true if support transaction prioritisation and false otherwise
7452
+ */;
7453
+ _proto.doesSupportTransactionPrioritisation = function doesSupportTransactionPrioritisation() {
7454
+ return Array.isArray(this.feeOptionsTimeStringsSortedDesc);
7455
+ };
7456
+ _proto.tickerAndProtocol = function tickerAndProtocol() {
7457
+ try {
7458
+ var _ref;
7459
+ return "" + this.tickerPrintable + (this.protocol ? (_ref = " " + this.protocol.protocol) != null ? _ref : "" : "");
7460
+ } catch (e) {
7461
+ improveAndRethrow(e, "tickerAndProtocol");
7462
+ }
7463
+ };
7464
+ return Coin;
7465
+ }();
7466
+
7467
+ var messageIcon = (function () {
7468
+ return /*#__PURE__*/React__default["default"].createElement("svg", {
7469
+ width: "130",
7470
+ height: "130",
7471
+ viewBox: "0 0 130 130",
7472
+ fill: "none",
7473
+ xmlns: "http://www.w3.org/2000/svg"
7491
7474
  }, /*#__PURE__*/React__default["default"].createElement("path", {
7492
7475
  "fill-rule": "evenodd",
7493
7476
  "clip-rule": "evenodd",
7494
7477
  d: "M65 130C100.899 130 130 100.899 130 65C130 29.1015 100.899 0 65 0C29.1015 0 0 29.1015 0 65C0 100.899 29.1015 130 65 130Z",
7495
- fill: "#AFEBC3"
7478
+ fill: "#2294F0"
7496
7479
  }), /*#__PURE__*/React__default["default"].createElement("mask", {
7497
7480
  id: "mask0",
7498
- "mask-type": "alpha",
7481
+ style: {
7482
+ maskType: "alpha"
7483
+ },
7499
7484
  maskUnits: "userSpaceOnUse",
7500
7485
  x: "0",
7501
7486
  y: "0",
@@ -7518,38 +7503,130 @@ var supportDialogImage = (function () {
7518
7503
  fill: "white"
7519
7504
  }), /*#__PURE__*/React__default["default"].createElement("rect", {
7520
7505
  opacity: "0.3",
7521
- x: "-48.4545",
7506
+ x: "-48.4546",
7522
7507
  y: "126.52",
7523
7508
  width: "227.136",
7524
7509
  height: "25.2373",
7525
- transform: "rotate(-45 -48.4545 126.52)",
7510
+ transform: "rotate(-45 -48.4546 126.52)",
7511
+ fill: "white"
7512
+ }), /*#__PURE__*/React__default["default"].createElement("rect", {
7513
+ x: "27.75",
7514
+ y: "29.5",
7515
+ width: "74.5",
7516
+ height: "81.5",
7517
+ rx: "12",
7526
7518
  fill: "white"
7527
7519
  }), /*#__PURE__*/React__default["default"].createElement("path", {
7528
- d: "M9.69092 69.153C9.69092 66.0864 11.2523 63.2309 13.8339 61.576L55.8257 34.6583C61.4168 31.0742 68.5832 31.0742 74.1743 34.6583L116.166 61.576C118.748 63.2309 120.309 66.0864 120.309 69.153V126.495C120.309 131.466 116.28 135.495 111.309 135.495H18.6909C13.7204 135.495 9.69092 131.466 9.69092 126.495V69.153Z",
7529
- fill: "#14A957"
7520
+ d: "M27.75 41.5C27.75 34.8726 33.1226 29.5 39.75 29.5H90.25C96.8774 29.5 102.25 34.8726 102.25 41.5V118C102.25 124.627 96.8774 130 90.25 130H39.75C33.1226 130 27.75 124.627 27.75 118V41.5Z",
7521
+ fill: "white"
7530
7522
  }), /*#__PURE__*/React__default["default"].createElement("path", {
7531
- d: "M30.9045 51.8818H97.9136V117.118H30.9045V51.8818Z",
7523
+ "fill-rule": "evenodd",
7524
+ "clip-rule": "evenodd",
7525
+ d: "M51.5 63.5C58.1274 63.5 63.5 58.1274 63.5 51.5C63.5 44.8726 58.1274 39.5 51.5 39.5C44.8726 39.5 39.5 44.8726 39.5 51.5C39.5 58.1274 44.8726 63.5 51.5 63.5Z",
7526
+ fill: "#2294F0"
7527
+ }), /*#__PURE__*/React__default["default"].createElement("path", {
7528
+ d: "M50.072 49.088H52.03V54.5H50.072V49.088ZM52.074 46.382V48.153H50.028V46.382H52.074Z",
7532
7529
  fill: "white"
7533
7530
  }), /*#__PURE__*/React__default["default"].createElement("path", {
7534
- opacity: "0.1",
7535
- d: "M63.8182 107.167C76.8722 107.167 87.4545 96.5849 87.4545 83.5308C87.4545 70.4768 76.8722 59.8945 63.8182 59.8945C50.7642 59.8945 40.1818 70.4768 40.1818 83.5308C40.1818 96.5849 50.7642 107.167 63.8182 107.167Z",
7536
- fill: "#24BE6A"
7531
+ opacity: "0.2",
7532
+ d: "M41 74.5H63",
7533
+ stroke: "#2294F0",
7534
+ "stroke-width": "4",
7535
+ "stroke-linecap": "round",
7536
+ "stroke-linejoin": "round"
7537
7537
  }), /*#__PURE__*/React__default["default"].createElement("path", {
7538
- d: "M58.2093 83.4849L63.0246 88.3002L71.3036 79.047",
7539
- stroke: "#24BE6A",
7540
- "stroke-width": "3.76358",
7538
+ opacity: "0.2",
7539
+ d: "M41 84.6157H84.1426",
7540
+ stroke: "#2294F0",
7541
+ "stroke-width": "4",
7541
7542
  "stroke-linecap": "round",
7542
7543
  "stroke-linejoin": "round"
7543
7544
  }), /*#__PURE__*/React__default["default"].createElement("path", {
7544
- d: "M9.69092 70.2531C9.69092 68.672 11.4391 67.7161 12.7703 68.5694L65 102.05L117.23 68.5694C118.561 67.7161 120.309 68.672 120.309 70.2531V128.859C120.309 133.83 116.28 137.859 111.309 137.859H18.6909C13.7204 137.859 9.69092 133.83 9.69092 128.859V70.2531Z",
7545
- fill: "#24BE6A"
7546
- })));
7547
- });
7548
-
7549
- /**
7550
- * Saves a user's subscription to receive notifications about a specific coin.
7551
- * This function sends an email to subscribe the user to notifications for the specified coin.
7552
- *
7545
+ opacity: "0.2",
7546
+ d: "M41 94.7314H84.1426",
7547
+ stroke: "#2294F0",
7548
+ "stroke-width": "4",
7549
+ "stroke-linecap": "round",
7550
+ "stroke-linejoin": "round"
7551
+ }), /*#__PURE__*/React__default["default"].createElement("path", {
7552
+ opacity: "0.2",
7553
+ d: "M41 104.731H84.1426",
7554
+ stroke: "#2294F0",
7555
+ "stroke-width": "4",
7556
+ "stroke-linecap": "round",
7557
+ "stroke-linejoin": "round"
7558
+ })));
7559
+ });
7560
+
7561
+ var supportDialogImage = (function () {
7562
+ return /*#__PURE__*/React__default["default"].createElement("svg", {
7563
+ width: "130",
7564
+ height: "130",
7565
+ viewBox: "0 0 130 130",
7566
+ fill: "none",
7567
+ xmlns: "http://www.w3.org/2000/svg"
7568
+ }, /*#__PURE__*/React__default["default"].createElement("path", {
7569
+ "fill-rule": "evenodd",
7570
+ "clip-rule": "evenodd",
7571
+ d: "M65 130C100.899 130 130 100.899 130 65C130 29.1015 100.899 0 65 0C29.1015 0 0 29.1015 0 65C0 100.899 29.1015 130 65 130Z",
7572
+ fill: "#AFEBC3"
7573
+ }), /*#__PURE__*/React__default["default"].createElement("mask", {
7574
+ id: "mask0",
7575
+ "mask-type": "alpha",
7576
+ maskUnits: "userSpaceOnUse",
7577
+ x: "0",
7578
+ y: "0",
7579
+ width: "130",
7580
+ height: "130"
7581
+ }, /*#__PURE__*/React__default["default"].createElement("path", {
7582
+ "fill-rule": "evenodd",
7583
+ "clip-rule": "evenodd",
7584
+ d: "M65 130C100.899 130 130 100.899 130 65C130 29.1015 100.899 0 65 0C29.1015 0 0 29.1015 0 65C0 100.899 29.1015 130 65 130Z",
7585
+ fill: "white"
7586
+ })), /*#__PURE__*/React__default["default"].createElement("g", {
7587
+ mask: "url(#mask0)"
7588
+ }, /*#__PURE__*/React__default["default"].createElement("rect", {
7589
+ opacity: "0.3",
7590
+ x: "3.25",
7591
+ y: "150.776",
7592
+ width: "227.136",
7593
+ height: "25.2373",
7594
+ transform: "rotate(-45 3.25 150.776)",
7595
+ fill: "white"
7596
+ }), /*#__PURE__*/React__default["default"].createElement("rect", {
7597
+ opacity: "0.3",
7598
+ x: "-48.4545",
7599
+ y: "126.52",
7600
+ width: "227.136",
7601
+ height: "25.2373",
7602
+ transform: "rotate(-45 -48.4545 126.52)",
7603
+ fill: "white"
7604
+ }), /*#__PURE__*/React__default["default"].createElement("path", {
7605
+ d: "M9.69092 69.153C9.69092 66.0864 11.2523 63.2309 13.8339 61.576L55.8257 34.6583C61.4168 31.0742 68.5832 31.0742 74.1743 34.6583L116.166 61.576C118.748 63.2309 120.309 66.0864 120.309 69.153V126.495C120.309 131.466 116.28 135.495 111.309 135.495H18.6909C13.7204 135.495 9.69092 131.466 9.69092 126.495V69.153Z",
7606
+ fill: "#14A957"
7607
+ }), /*#__PURE__*/React__default["default"].createElement("path", {
7608
+ d: "M30.9045 51.8818H97.9136V117.118H30.9045V51.8818Z",
7609
+ fill: "white"
7610
+ }), /*#__PURE__*/React__default["default"].createElement("path", {
7611
+ opacity: "0.1",
7612
+ d: "M63.8182 107.167C76.8722 107.167 87.4545 96.5849 87.4545 83.5308C87.4545 70.4768 76.8722 59.8945 63.8182 59.8945C50.7642 59.8945 40.1818 70.4768 40.1818 83.5308C40.1818 96.5849 50.7642 107.167 63.8182 107.167Z",
7613
+ fill: "#24BE6A"
7614
+ }), /*#__PURE__*/React__default["default"].createElement("path", {
7615
+ d: "M58.2093 83.4849L63.0246 88.3002L71.3036 79.047",
7616
+ stroke: "#24BE6A",
7617
+ "stroke-width": "3.76358",
7618
+ "stroke-linecap": "round",
7619
+ "stroke-linejoin": "round"
7620
+ }), /*#__PURE__*/React__default["default"].createElement("path", {
7621
+ d: "M9.69092 70.2531C9.69092 68.672 11.4391 67.7161 12.7703 68.5694L65 102.05L117.23 68.5694C118.561 67.7161 120.309 68.672 120.309 70.2531V128.859C120.309 133.83 116.28 137.859 111.309 137.859H18.6909C13.7204 137.859 9.69092 133.83 9.69092 128.859V70.2531Z",
7622
+ fill: "#24BE6A"
7623
+ })));
7624
+ });
7625
+
7626
+ /**
7627
+ * Saves a user's subscription to receive notifications about a specific coin.
7628
+ * This function sends an email to subscribe the user to notifications for the specified coin.
7629
+ *
7553
7630
  * @function
7554
7631
  * @name saveSubscription
7555
7632
  * @param {Coin} coin - The coin object containing information about the coin, including its ticker symbol.
@@ -7858,6 +7935,27 @@ function getQueryParameterSingleValue(name) {
7858
7935
  return (getQueryParameterValues(name) || [])[0];
7859
7936
  }
7860
7937
 
7938
+ /**
7939
+ * Major point of rabbit ticker format definition.
7940
+ * Our asset ticker format is just stick standard (printable) ticker with protocol code.
7941
+ * If protocol code is the same as asset ticker than it is not added.
7942
+ * Examples:
7943
+ * SHIBERC20 - shiba inu on ethereum,
7944
+ * TON - Ton coin on ton blockchain,
7945
+ * BTC - Bitcoin in BTC mainnet,
7946
+ * NOTTON - Notcoin in Ton blockchain
7947
+ *
7948
+ * @param standardPrintableTicker {string}
7949
+ * @param protocolOrNetworkCode {string}
7950
+ * @return {string}
7951
+ */
7952
+ function toRabbitTicker(standardPrintableTicker, protocolOrNetworkCode) {
7953
+ if (typeof standardPrintableTicker !== "string" || typeof protocolOrNetworkCode !== "string" && protocolOrNetworkCode != null) throw new Error("Wrong ticker/protocol passed: " + standardPrintableTicker + ", " + protocolOrNetworkCode);
7954
+ var upperTicker = standardPrintableTicker.toUpperCase();
7955
+ var upperCode = (protocolOrNetworkCode != null ? protocolOrNetworkCode : "").toUpperCase();
7956
+ return "" + upperTicker + (upperCode === upperTicker ? "" : upperCode);
7957
+ }
7958
+
7861
7959
  var Blockchain =
7862
7960
  /**
7863
7961
  * @param name {string} latin printable name of blockchain
@@ -10465,7 +10563,32 @@ var ExistingSwapWithFiatData = /*#__PURE__*/function (_ExistingSwap) {
10465
10563
  return ExistingSwapWithFiatData;
10466
10564
  }(ExistingSwap);
10467
10565
 
10468
- var BaseSwapCreationInfo =
10566
+ var BaseSwapCreationInfo = /** @type {Coin} */
10567
+
10568
+ /** @type {Coin} */
10569
+
10570
+ /** @type {string} */
10571
+
10572
+ /** @type {string} */
10573
+
10574
+ /** @type {string} */
10575
+
10576
+ /** @type {Object} */
10577
+
10578
+ /** @type {string} */
10579
+
10580
+ /** @type {number} */
10581
+
10582
+ /** @type {string} */
10583
+
10584
+ /** @type {number} */
10585
+
10586
+ /** @type {string} */
10587
+
10588
+ /** @type {boolean} */
10589
+
10590
+ /** @type {boolean} */
10591
+
10469
10592
  /**
10470
10593
  * @param fromCoin {Coin}
10471
10594
  * @param toCoin {Coin}
@@ -10507,7 +10630,42 @@ function BaseSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins,
10507
10630
  * 3. protocol should be null for coins major for their blockchains like BTC, ETH
10508
10631
  * 4. isPopular should be a number - the higher -> the more popular
10509
10632
  */
10510
- var SwapProviderCoinInfo = function SwapProviderCoinInfo(coin, code, network, hasExtraId, extraIdName, popularity, iconURL, deposit, withdrawal, validationRegexp, isAvailable) {
10633
+ var SwapProviderCoinInfo = /** @type {Coin} */
10634
+
10635
+ /** @type {string} */
10636
+
10637
+ /** @type {string} */
10638
+
10639
+ /** @type {boolean} */
10640
+
10641
+ /** @type {string|null} */
10642
+
10643
+ /** @type {number} */
10644
+
10645
+ /** @type {string} */
10646
+
10647
+ /** @type {boolean} */
10648
+
10649
+ /** @type {boolean} */
10650
+
10651
+ /** @type {string|null} */
10652
+
10653
+ /** @type {boolean} */
10654
+
10655
+ /**
10656
+ * @param {string} coin - The name of the coin.
10657
+ * @param {string} code - The ticker code for the coin, e.g., USDTERC20.
10658
+ * @param {string} network - The network on which the coin operates.
10659
+ * @param {boolean} hasExtraId - Whether the coin requires an extra ID for transactions.
10660
+ * @param {string|null} extraIdName - The name of the extra ID, if applicable.
10661
+ * @param {number} popularity - A number indicating the popularity of the coin.
10662
+ * @param {string} [iconURL=FALLBACK_ASSET_ICON_URL] - The URL of the coin's icon. Falls back to a default value if not provided.
10663
+ * @param {boolean} [deposit=false] - Indicates whether deposits are supported. Defaults to `false`.
10664
+ * @param {boolean} [withdrawal=false] - Indicates whether withdrawals are supported. Defaults to `false`.
10665
+ * @param {string|null} [validationRegexp=null] - A regular expression for validating addresses, if applicable.
10666
+ * @param {boolean} [isAvailable=true] - Whether the coin is available for transactions. Defaults to `true`.
10667
+ */
10668
+ function SwapProviderCoinInfo(coin, code, network, hasExtraId, extraIdName, popularity, iconURL, deposit, withdrawal, validationRegexp, isAvailable) {
10511
10669
  this.coin = coin;
10512
10670
  this.code = code;
10513
10671
  this.network = network;
@@ -10536,7 +10694,23 @@ var PRE_LISTED_COINS = [new SwapProviderCoinInfo(new Coin("Hamster Kombat", "HMS
10536
10694
  // "https://hamsterkombat.io/images/icons/hamster-coin.png"
10537
10695
  true, true, "^(EQ|UQ)[A-Za-z0-9-_]{46}$", false)];
10538
10696
  var SwapProvider = /*#__PURE__*/function () {
10539
- function SwapProvider(cache, customCoinBuilder, useRestrictedCoinsSet) {
10697
+ /** @type {string} */
10698
+
10699
+ /** @type {SwapProviderCoinInfo[]} */
10700
+
10701
+ /** @type {number} */
10702
+
10703
+ /** @type {number} */
10704
+
10705
+ /** @type {boolean} */
10706
+
10707
+ /** @type {function} */
10708
+
10709
+ /** @type {Cache} */
10710
+
10711
+ /** @type {boolean} */
10712
+
10713
+ function SwapProvider(id, cache, customCoinBuilder, useRestrictedCoinsSet) {
10540
10714
  if (customCoinBuilder === void 0) {
10541
10715
  customCoinBuilder = function customCoinBuilder(coin, network) {
10542
10716
  return null;
@@ -10545,7 +10719,9 @@ var SwapProvider = /*#__PURE__*/function () {
10545
10719
  if (useRestrictedCoinsSet === void 0) {
10546
10720
  useRestrictedCoinsSet = true;
10547
10721
  }
10722
+ this.id = id;
10548
10723
  this._supportedCoins = [];
10724
+ this._supportedCoinsLastUpdateTimestamp = 0;
10549
10725
  this._maxRateDigits = 20;
10550
10726
  this.useRestrictedCoinsSet = useRestrictedCoinsSet;
10551
10727
  this._customCoinBuilder = customCoinBuilder;
@@ -10554,8 +10730,24 @@ var SwapProvider = /*#__PURE__*/function () {
10554
10730
  }
10555
10731
  var _proto = SwapProvider.prototype;
10556
10732
  /**
10557
- * @return {Promise<void>}
10733
+ * Returns provider-specific identifiers exactly the way they defined in the provider API.
10734
+ * Usually providers have 2 identifiers - ticker/code/coin id and network/protocol.
10735
+ * So by default we return this set based in the coin info instance.
10736
+ * Should be redefined for dedicated providers if their ids logic differ.
10737
+ *
10738
+ * @param info {SwapProviderCoinInfo}
10739
+ * @return {{code: string, network: string|null}} null network means the coin is the major for its network like BTC and ETH
10558
10740
  */
10741
+ _proto.getIdsByCoinInfo = function getIdsByCoinInfo(info) {
10742
+ return {
10743
+ code: info.code,
10744
+ network: info.network
10745
+ };
10746
+ }
10747
+
10748
+ /**
10749
+ * @return {Promise<void>}
10750
+ */;
10559
10751
  _proto.initialize = function initialize() {
10560
10752
  try {
10561
10753
  var _this = this;
@@ -10602,6 +10794,10 @@ var SwapProvider = /*#__PURE__*/function () {
10602
10794
  // By default, sort by the coin ticker
10603
10795
  return i1.coin.ticker.localeCompare(i2.coin.ticker);
10604
10796
  });
10797
+ };
10798
+ _proto._shouldCoinsListBeLoaded = function _shouldCoinsListBeLoaded() {
10799
+ var _this$_supportedCoins;
10800
+ return !((_this$_supportedCoins = this._supportedCoins) != null && _this$_supportedCoins.length) || !this._supportedCoinsLastUpdateTimestamp || this._supportedCoinsLastUpdateTimestamp + SwapProvider.COINS_EXPIRATION_TIME_MS < Date.now();
10605
10801
  }
10606
10802
 
10607
10803
  /**
@@ -10663,6 +10859,40 @@ var SwapProvider = /*#__PURE__*/function () {
10663
10859
  return Promise.reject(e);
10664
10860
  }
10665
10861
  }
10862
+ /**
10863
+ * Retrieves all currencies supported by this swap provider with raw details.
10864
+ * Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
10865
+ *
10866
+ * @return {Promise<({ result: true, coinsInfo: SwapProviderCoinInfo[] }|{ result: false, reason: string })>}
10867
+ */
10868
+ ;
10869
+ _proto.getAllSupportedCurrenciesWithRawDetails = function getAllSupportedCurrenciesWithRawDetails() {
10870
+ try {
10871
+ var _this4 = this;
10872
+ var loggerSource = "getAllSupportedCurrenciesWithRawDetails";
10873
+ return Promise.resolve(_catch$4(function () {
10874
+ return Promise.resolve(_this4._fetchSupportedCurrenciesIfNeeded()).then(function () {
10875
+ var _this4$_supportedCoin;
10876
+ Logger.log("We have " + ((_this4$_supportedCoin = _this4._supportedCoins) == null ? void 0 : _this4$_supportedCoin.length) + " supported coins returning", loggerSource);
10877
+ return {
10878
+ result: true,
10879
+ coinsInfo: [].concat(_this4._supportedCoins)
10880
+ };
10881
+ });
10882
+ }, function (e) {
10883
+ var _e$response2;
10884
+ if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
10885
+ return {
10886
+ result: false,
10887
+ reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
10888
+ };
10889
+ }
10890
+ improveAndRethrow(e, loggerSource);
10891
+ }));
10892
+ } catch (e) {
10893
+ return Promise.reject(e);
10894
+ }
10895
+ }
10666
10896
  /**
10667
10897
  * Retrieves all deposit currencies supported by this swap provider.
10668
10898
  * Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
@@ -10672,15 +10902,15 @@ var SwapProvider = /*#__PURE__*/function () {
10672
10902
  ;
10673
10903
  _proto.getDepositCurrencies = function getDepositCurrencies() {
10674
10904
  try {
10675
- var _this4 = this;
10905
+ var _this5 = this;
10676
10906
  var loggerSource = "getDepositCurrencies";
10677
10907
  return Promise.resolve(_catch$4(function () {
10678
- return Promise.resolve(_this4._fetchSupportedCurrenciesIfNeeded()).then(function () {
10679
- var _this4$_supportedCoin;
10680
- Logger.log("We have " + ((_this4$_supportedCoin = _this4._supportedCoins) == null ? void 0 : _this4$_supportedCoin.length) + " supported coins, getting depositable", loggerSource);
10908
+ return Promise.resolve(_this5._fetchSupportedCurrenciesIfNeeded()).then(function () {
10909
+ var _this5$_supportedCoin;
10910
+ Logger.log("We have " + ((_this5$_supportedCoin = _this5._supportedCoins) == null ? void 0 : _this5$_supportedCoin.length) + " supported coins, getting depositable", loggerSource);
10681
10911
  return {
10682
10912
  result: true,
10683
- coins: _this4._supportedCoins.filter(function (item) {
10913
+ coins: _this5._supportedCoins.filter(function (item) {
10684
10914
  return item.deposit;
10685
10915
  }).map(function (item) {
10686
10916
  return item.coin;
@@ -10688,8 +10918,8 @@ var SwapProvider = /*#__PURE__*/function () {
10688
10918
  };
10689
10919
  });
10690
10920
  }, function (e) {
10691
- var _e$response2;
10692
- if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
10921
+ var _e$response3;
10922
+ if ((e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status) === 429) {
10693
10923
  return {
10694
10924
  result: false,
10695
10925
  reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
@@ -10714,15 +10944,15 @@ var SwapProvider = /*#__PURE__*/function () {
10714
10944
  exceptCurrency = null;
10715
10945
  }
10716
10946
  try {
10717
- var _this5 = this;
10947
+ var _this6 = this;
10718
10948
  var loggerSource = "getWithdrawalCurrencies";
10719
10949
  return Promise.resolve(_catch$4(function () {
10720
- return Promise.resolve(_this5._fetchSupportedCurrenciesIfNeeded()).then(function () {
10721
- var _this5$_supportedCoin;
10722
- Logger.log("We have " + ((_this5$_supportedCoin = _this5._supportedCoins) == null ? void 0 : _this5$_supportedCoin.length) + " supported coins, getting withdrawable", loggerSource);
10950
+ return Promise.resolve(_this6._fetchSupportedCurrenciesIfNeeded()).then(function () {
10951
+ var _this6$_supportedCoin;
10952
+ Logger.log("We have " + ((_this6$_supportedCoin = _this6._supportedCoins) == null ? void 0 : _this6$_supportedCoin.length) + " supported coins, getting withdrawable", loggerSource);
10723
10953
  return {
10724
10954
  result: true,
10725
- coins: _this5._supportedCoins.filter(function (item) {
10955
+ coins: _this6._supportedCoins.filter(function (item) {
10726
10956
  var _item$coin, _exceptCurrency;
10727
10957
  return item.withdrawal && (!exceptCurrency || ((_item$coin = item.coin) == null ? void 0 : _item$coin.ticker) !== ((_exceptCurrency = exceptCurrency) == null ? void 0 : _exceptCurrency.ticker));
10728
10958
  }).map(function (item) {
@@ -10731,8 +10961,8 @@ var SwapProvider = /*#__PURE__*/function () {
10731
10961
  };
10732
10962
  });
10733
10963
  }, function (e) {
10734
- var _e$response3;
10735
- if ((e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status) === 429) {
10964
+ var _e$response4;
10965
+ if ((e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.status) === 429) {
10736
10966
  return {
10737
10967
  result: false,
10738
10968
  reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
@@ -10754,18 +10984,18 @@ var SwapProvider = /*#__PURE__*/function () {
10754
10984
  _proto.getIconUrl = function getIconUrl(coinOrTicker) {
10755
10985
  var loggerSource = "getIconUrl";
10756
10986
  try {
10757
- var _this$_supportedCoins2, _this$_supportedCoins3;
10987
+ var _this$_supportedCoins3, _this$_supportedCoins4;
10758
10988
  var coin = coinOrTicker;
10759
10989
  if (!(coinOrTicker instanceof Coin)) {
10760
- var _this$_supportedCoins;
10761
- coin = (_this$_supportedCoins = this._supportedCoins.find(function (i) {
10990
+ var _this$_supportedCoins2;
10991
+ coin = (_this$_supportedCoins2 = this._supportedCoins.find(function (i) {
10762
10992
  return i.coin.ticker === coinOrTicker;
10763
- })) == null ? void 0 : _this$_supportedCoins.coin;
10993
+ })) == null ? void 0 : _this$_supportedCoins2.coin;
10764
10994
  }
10765
- return (_this$_supportedCoins2 = (_this$_supportedCoins3 = this._supportedCoins.find(function (item) {
10995
+ return (_this$_supportedCoins3 = (_this$_supportedCoins4 = this._supportedCoins.find(function (item) {
10766
10996
  var _item$coin2, _coin;
10767
10997
  return ((_item$coin2 = item.coin) == null ? void 0 : _item$coin2.ticker) === ((_coin = coin) == null ? void 0 : _coin.ticker);
10768
- })) == null ? void 0 : _this$_supportedCoins3.iconURL) != null ? _this$_supportedCoins2 : FALLBACK_ASSET_ICON_URL;
10998
+ })) == null ? void 0 : _this$_supportedCoins4.iconURL) != null ? _this$_supportedCoins3 : FALLBACK_ASSET_ICON_URL;
10769
10999
  } catch (e) {
10770
11000
  improveAndRethrow(e, loggerSource);
10771
11001
  }
@@ -10774,43 +11004,44 @@ var SwapProvider = /*#__PURE__*/function () {
10774
11004
  /**
10775
11005
  * Retrieves coin to USDT rate.
10776
11006
  *
10777
- * @param coin {Coin}
11007
+ * @param coinOrTicker {Coin|string}
10778
11008
  * @return {{result: true, rate: string}|null}
10779
11009
  */;
10780
- _proto.getCoinToUSDTRate = function getCoinToUSDTRate(coin) {
11010
+ _proto.getCoinToUSDTRate = function getCoinToUSDTRate(coinOrTicker) {
10781
11011
  try {
10782
- var _this6 = this;
11012
+ var _this7 = this;
10783
11013
  var loggerSource = "getCoinToUSDTRate";
10784
11014
  return Promise.resolve(_catch$4(function () {
10785
- return coin ? Promise.resolve(_this6._fetchSupportedCurrenciesIfNeeded()).then(function () {
10786
- var _this6$_supportedCoin;
10787
- var isCoinAvailableForThisProvider = !!_this6.getCoinByTickerIfPresent(coin.ticker);
10788
- if (!isCoinAvailableForThisProvider) return null;
11015
+ return coinOrTicker ? Promise.resolve(_this7._fetchSupportedCurrenciesIfNeeded()).then(function () {
11016
+ var _this7$_supportedCoin;
11017
+ var ticker = coinOrTicker instanceof Coin ? coinOrTicker.ticker : coinOrTicker;
11018
+ var coin = _this7.getCoinByTickerIfPresent(ticker);
11019
+ if (!coin) return null;
10789
11020
 
10790
11021
  // Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
10791
11022
  // This calculation is not precise as we cannot recognize the actual fee and network fee. Just approximate.
10792
- // fee is usually 0.4%
10793
- var usdtTrc20 = (_this6$_supportedCoin = _this6._supportedCoins.find(function (i) {
11023
+ // standard market fee is about 0.4% usually
11024
+ var usdtTrc20 = (_this7$_supportedCoin = _this7._supportedCoins.find(function (i) {
10794
11025
  return i.coin.ticker === "USDTTRC20";
10795
- })) == null ? void 0 : _this6$_supportedCoin.coin;
11026
+ })) == null ? void 0 : _this7$_supportedCoin.coin;
10796
11027
  if (!usdtTrc20) {
10797
11028
  return null;
10798
11029
  }
10799
- var cached = _this6._cache.get("swapspace_usdt_rate_" + coin.ticker);
11030
+ var cached = _this7._cache.get("swapspace_usdt_rate_" + ticker);
10800
11031
  if (cached != null) {
10801
11032
  return {
10802
11033
  result: true,
10803
11034
  rate: cached
10804
11035
  };
10805
11036
  }
10806
- Logger.log("Loading USDT->coin rate as not found in cache:", coin == null ? void 0 : coin.ticker);
10807
- return Promise.resolve(_this6.getSwapInfo(usdtTrc20, coin, "5000", false)).then(function (result) {
11037
+ Logger.log("Loading USDT->coin rate as not found in cache:", ticker);
11038
+ return Promise.resolve(_this7.getSwapInfo(usdtTrc20, coin, "5000", false)).then(function (result) {
10808
11039
  if (!result.result) {
10809
11040
  return null;
10810
11041
  }
10811
11042
  var standardSwapspaceFeeMultiplier = 1.004;
10812
11043
  var rate = bignumber_js.BigNumber(1).div(bignumber_js.BigNumber(result.rate).times(standardSwapspaceFeeMultiplier)).toString();
10813
- _this6._cache.put("swap_usdt_rate_" + coin.ticker, rate, 15 * 60000 // 15 minutes
11044
+ _this7._cache.put("swap_usdt_rate_" + ticker, rate, 10 * 60000 // 15 minutes
10814
11045
  );
10815
11046
  return {
10816
11047
  result: true,
@@ -10838,6 +11069,7 @@ var SwapProvider = /*#__PURE__*/function () {
10838
11069
  * @param [fromCoinToUsdRate=null] pass if you want to increase the min amount returned
10839
11070
  * by provider with some fixed "insurance" amount to cover min amount fluctuations.
10840
11071
  * @param [amountIsToReceive=false] {boolean} whether the given amount is receiving amount. False means the amount is the sending amount.
11072
+ * @param [bannedPartners=[]] {string[]} list of ids of banned partners to be excluded from list, suitable only for swap aggregators
10841
11073
  * @return {Promise<({
10842
11074
  * result: false,
10843
11075
  * reason: string,
@@ -10857,7 +11089,7 @@ var SwapProvider = /*#__PURE__*/function () {
10857
11089
  * })>}
10858
11090
  */
10859
11091
  ;
10860
- _proto.getSwapInfo = function getSwapInfo(fromCoin, toCoin, amountCoins, fixed, fromCoinToUsdRate, amountIsToReceive) {
11092
+ _proto.getSwapInfo = function getSwapInfo(fromCoin, toCoin, amountCoins, fixed, fromCoinToUsdRate, amountIsToReceive, bannedPartners) {
10861
11093
  try {
10862
11094
  throw new Error("Not implemented in base");
10863
11095
  } catch (e) {
@@ -11016,6 +11248,7 @@ var SwapProvider = /*#__PURE__*/function () {
11016
11248
  };
11017
11249
  return SwapProvider;
11018
11250
  }();
11251
+ SwapProvider.COINS_EXPIRATION_TIME_MS = 5 * 60 * 1000;
11019
11252
  SwapProvider.COMMON_ERRORS = {
11020
11253
  REQUESTS_LIMIT_EXCEEDED: "requestsLimitExceeded"
11021
11254
  };
@@ -11041,9 +11274,36 @@ SwapProvider.SWAP_STATUSES = {
11041
11274
  FAILED: "failed"
11042
11275
  };
11043
11276
 
11044
- var Partner = function Partner(name, logoUrl) {
11277
+ var Partner =
11278
+ /**
11279
+ * Rabbit id for partner.
11280
+ *
11281
+ * @type {string}
11282
+ * */
11283
+
11284
+ /** @type {string} */
11285
+
11286
+ /** @type {string|undefined|null} */
11287
+
11288
+ /** @type {string|null} */
11289
+
11290
+ function Partner(id, name, logoUrl, kycLevel) {
11291
+ var _Object$values$find;
11292
+ if (kycLevel === void 0) {
11293
+ kycLevel = null;
11294
+ }
11295
+ this.id = id;
11045
11296
  this.name = name;
11046
11297
  this.logoUrl = logoUrl;
11298
+ this.kycLevel = (_Object$values$find = Object.values(KYC_LEVELS).find(function (level) {
11299
+ var _kycLevel;
11300
+ return level === ((_kycLevel = kycLevel) != null ? _kycLevel : "").toLowerCase();
11301
+ })) != null ? _Object$values$find : null;
11302
+ };
11303
+ var KYC_LEVELS = {
11304
+ LOW: "low",
11305
+ MEDIUM: "medium",
11306
+ HIGH: "high"
11047
11307
  };
11048
11308
 
11049
11309
  function _catch$3(body, recover) {
@@ -11057,10 +11317,18 @@ function _catch$3(body, recover) {
11057
11317
  }
11058
11318
  return result;
11059
11319
  }
11060
- var BANNED_PARTNERS = ["stealthex", "changee", "coincraddle", "easybit"];
11061
11320
  var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11062
11321
  _inheritsLoose(SwapspaceSwapProvider, _SwapProvider);
11063
- function SwapspaceSwapProvider(apiKeysProxyUrl, cache, customCoinBuilder, useRestrictedCoinsSet) {
11322
+ /**
11323
+ * You should pass either proxy URL or the API key
11324
+ *
11325
+ * @param apiKeysProxyUrl {string|null}
11326
+ * @param cache {Cache}
11327
+ * @param [customCoinBuilder] {function}
11328
+ * @param [useRestrictedCoinsSet=true] {boolean}
11329
+ * @param [apiKey] {string|null}
11330
+ */
11331
+ function SwapspaceSwapProvider(apiKeysProxyUrl, cache, customCoinBuilder, useRestrictedCoinsSet, apiKey) {
11064
11332
  var _this;
11065
11333
  if (customCoinBuilder === void 0) {
11066
11334
  customCoinBuilder = function customCoinBuilder(coin, network) {
@@ -11070,9 +11338,15 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11070
11338
  if (useRestrictedCoinsSet === void 0) {
11071
11339
  useRestrictedCoinsSet = true;
11072
11340
  }
11073
- _this = _SwapProvider.call(this, cache, customCoinBuilder, useRestrictedCoinsSet) || this;
11341
+ if (apiKey === void 0) {
11342
+ apiKey = null;
11343
+ }
11344
+ _this = _SwapProvider.call(this, "swapspace", cache, customCoinBuilder, useRestrictedCoinsSet) || this;
11074
11345
  _this._partners = [];
11075
- _this._URL = apiKeysProxyUrl + "/swapspace";
11346
+ _this._URL = apiKey ? "https://api.swapspace.co" : apiKeysProxyUrl + "/" + _this.id;
11347
+ _this._headers = apiKey ? {
11348
+ Authorization: apiKey
11349
+ } : {};
11076
11350
  _this.isAggregator = true;
11077
11351
  return _this;
11078
11352
  }
@@ -11087,15 +11361,17 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11087
11361
  var _this2 = this;
11088
11362
  var loggerSource = "_fetchSupportedCurrenciesIfNeeded";
11089
11363
  return Promise.resolve(_catch$3(function () {
11090
- var _temp = function (_this2$_supportedCoin) {
11091
- if (!((_this2$_supportedCoin = _this2._supportedCoins) != null && _this2$_supportedCoin.length)) {
11092
- return Promise.resolve(axios__default["default"].get(_this2._URL + "/api/v2/currencies")).then(function (rawResponse) {
11364
+ var _temp = function () {
11365
+ if (_this2._shouldCoinsListBeLoaded()) {
11366
+ return Promise.resolve(axios__default["default"].get(_this2._URL + "/api/v2/currencies", {
11367
+ headers: _this2._headers
11368
+ })).then(function (rawResponse) {
11093
11369
  var _rawResponse$data, _rawResponse$data2;
11094
11370
  Logger.log("Retrieved " + (rawResponse == null || (_rawResponse$data = rawResponse.data) == null ? void 0 : _rawResponse$data.length), loggerSource);
11095
11371
  var allowedCoins = (_rawResponse$data2 = rawResponse == null ? void 0 : rawResponse.data) != null ? _rawResponse$data2 : [];
11096
11372
  Logger.log("Allowed cnt " + allowedCoins.length, loggerSource);
11097
11373
  _this2._supportedCoins = allowedCoins.map(function (item) {
11098
- var coin = _this2._customCoinBuilder(item.code, item.network);
11374
+ var coin = _this2._customCoinBuilder != null ? _this2._customCoinBuilder(item.code, item.network) : null;
11099
11375
  if (!coin && !_this2.useRestrictedCoinsSet) {
11100
11376
  /** Building coin object for coin that isn't supported OOB in Rabbit.
11101
11377
  * We are doing this way to be able to use extended coins set for swaps.
@@ -11111,7 +11387,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11111
11387
  * from coin object rather than counting on having it in the coin name itself.
11112
11388
  * This processing is needed due to poor quality of swapspace coins names. */
11113
11389
  var name = _this2.removeProtocolNameFromCoinName(item.name, code, network);
11114
- var ticker = "" + code + (code === network ? "" : network);
11390
+ var ticker = toRabbitTicker(code, network);
11115
11391
  var defaultDecimalPlacesForCoinNotSupportedOOB = 8;
11116
11392
  var defaultMinConfirmationsForCoinNotSupportedOOB = 1;
11117
11393
  coin = new Coin(name, ticker, code, defaultDecimalPlacesForCoinNotSupportedOOB, null, "", null, null, defaultMinConfirmationsForCoinNotSupportedOOB, null, [], 60000, null,
@@ -11124,6 +11400,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11124
11400
  }
11125
11401
  return [];
11126
11402
  }).flat();
11403
+ _this2._supportedCoinsLastUpdateTimestamp = Date.now();
11127
11404
  _this2._putPopularCoinsFirst();
11128
11405
  return Promise.resolve(_SwapProvider.prototype._fetchSupportedCurrenciesIfNeeded.call(_this2)).then(function () {});
11129
11406
  });
@@ -11144,7 +11421,9 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11144
11421
  return Promise.resolve(_catch$3(function () {
11145
11422
  var _temp2 = function (_this3$_partners) {
11146
11423
  if (((_this3$_partners = _this3._partners) == null ? void 0 : _this3$_partners.length) === 0) {
11147
- return Promise.resolve(axios__default["default"].get(_this3._URL + "/api/v2/partners")).then(function (rawResponse) {
11424
+ return Promise.resolve(axios__default["default"].get(_this3._URL + "/api/v2/partners", {
11425
+ headers: _this3._headers
11426
+ })).then(function (rawResponse) {
11148
11427
  var _rawResponse$data3;
11149
11428
  Logger.log("Retrieved " + (rawResponse == null || (_rawResponse$data3 = rawResponse.data) == null ? void 0 : _rawResponse$data3.length) + " partners", loggerSource);
11150
11429
  _this3._partners = Array.isArray(rawResponse == null ? void 0 : rawResponse.data) ? rawResponse == null ? void 0 : rawResponse.data : [];
@@ -11159,7 +11438,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11159
11438
  return Promise.reject(e);
11160
11439
  }
11161
11440
  };
11162
- _proto.getSwapInfo = function getSwapInfo(fromCoin, toCoin, amountCoins, fixed, fromCoinToUsdRate, amountIsToReceive) {
11441
+ _proto.getSwapInfo = function getSwapInfo(fromCoin, toCoin, amountCoins, fixed, fromCoinToUsdRate, amountIsToReceive, bannedPartners) {
11163
11442
  if (fixed === void 0) {
11164
11443
  fixed = false;
11165
11444
  }
@@ -11169,6 +11448,9 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11169
11448
  if (amountIsToReceive === void 0) {
11170
11449
  amountIsToReceive = false;
11171
11450
  }
11451
+ if (bannedPartners === void 0) {
11452
+ bannedPartners = [];
11453
+ }
11172
11454
  try {
11173
11455
  var _this4 = this;
11174
11456
  var loggerSource = "getSwapInfo";
@@ -11177,148 +11459,156 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11177
11459
  if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amountCoins !== "string" || bignumber_js.BigNumber(amountCoins).lt("0") || fixed !== null && typeof fixed !== "boolean") {
11178
11460
  throw new Error("Wrong input params: " + amountCoins + " " + fromCoin.ticker + " -> " + toCoin.ticker + ", " + (fromCoin instanceof Coin) + ", " + (toCoin instanceof Coin) + ", " + typeof fixed + " " + fixed);
11179
11461
  }
11180
- var fromCoinSwapspaceDetails = _this4._supportedCoins.find(function (i) {
11181
- var _i$coin;
11182
- return ((_i$coin = i.coin) == null ? void 0 : _i$coin.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
11183
- });
11184
- var toCoinSwapspaceDetails = _this4._supportedCoins.find(function (i) {
11185
- var _i$coin2;
11186
- return ((_i$coin2 = i.coin) == null ? void 0 : _i$coin2.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
11187
- });
11188
- return !fromCoinSwapspaceDetails || !toCoinSwapspaceDetails || !fromCoinSwapspaceDetails.deposit || !toCoinSwapspaceDetails.withdrawal || !fromCoinSwapspaceDetails.isAvailable || !toCoinSwapspaceDetails.isAvailable ? {
11189
- result: false,
11190
- reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
11191
- } : Promise.resolve(axios__default["default"].get(_this4._URL + "/api/v2/amounts?fromCurrency=" + fromCoinSwapspaceDetails.code + "&fromNetwork=" + fromCoinSwapspaceDetails.network + "&toNetwork=" + toCoinSwapspaceDetails.network + "&toCurrency=" + toCoinSwapspaceDetails.code + "&amount=" + amountCoins + "&estimated=false")).then(function (response) {
11192
- var _response$data, _exchangesSupportingT;
11193
- var _exit;
11194
- function _temp4(_result2) {
11195
- if (_exit) return _result2;
11196
- var result = {
11197
- result: false,
11198
- reason: smallestMin && bignumber_js.BigNumber(amountCoins).lt(smallestMin) ? SwapProvider.NO_SWAPS_REASONS.TOO_LOW : greatestMax && bignumber_js.BigNumber(amountCoins).gt(greatestMax) ? SwapProvider.NO_SWAPS_REASONS.TOO_HIGH : SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED,
11199
- smallestMin: smallestMin,
11200
- greatestMax: greatestMax
11201
- };
11202
- Logger.log("Returning result " + safeStringify(result), loggerSource);
11203
- return result;
11204
- }
11205
- Logger.log("Retrieved " + (response == null || (_response$data = response.data) == null ? void 0 : _response$data.length) + " options", loggerSource);
11206
- var options = Array.isArray(response.data) ? response.data : [];
11207
- // TODO: [feature, high] remove if possible over-engineering about toAmount = 0 options treating as supported but not available. task_id=404ae30d9a7743238af3cc0d3bae9239
11208
- var exchangesSupportingThePairDespiteFixedOrFloating = options.filter(function (exchange) {
11209
- return (exchange == null ? void 0 : exchange.exists) && !BANNED_PARTNERS.find(function (bannedPartner) {
11210
- return bannedPartner === (exchange == null ? void 0 : exchange.partner);
11211
- }) && ((exchange == null ? void 0 : exchange.fixed) === false || (exchange == null ? void 0 : exchange.fixed) === true) && typeof exchange.toAmount === "number" && (typeof exchange.min === "number" && typeof exchange.max === "number" || exchange.toAmount > 0) && (exchange.min === 0 || exchange.max === 0 || exchange.max > exchange.min);
11462
+ return Promise.resolve(_this4._fetchSupportedCurrenciesIfNeeded()).then(function () {
11463
+ var fromCoinSwapspaceDetails = _this4._supportedCoins.find(function (i) {
11464
+ var _i$coin;
11465
+ return ((_i$coin = i.coin) == null ? void 0 : _i$coin.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
11466
+ });
11467
+ var toCoinSwapspaceDetails = _this4._supportedCoins.find(function (i) {
11468
+ var _i$coin2;
11469
+ return ((_i$coin2 = i.coin) == null ? void 0 : _i$coin2.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
11212
11470
  });
11213
- var exchangesSupportingThePair = exchangesSupportingThePairDespiteFixedOrFloating;
11214
- if (fixed != null) {
11215
- exchangesSupportingThePair = exchangesSupportingThePairDespiteFixedOrFloating.filter(function (option) {
11216
- return option.fixed === fixed;
11471
+ return !fromCoinSwapspaceDetails || !toCoinSwapspaceDetails || !fromCoinSwapspaceDetails.deposit || !toCoinSwapspaceDetails.withdrawal || !fromCoinSwapspaceDetails.isAvailable || !toCoinSwapspaceDetails.isAvailable ? {
11472
+ result: false,
11473
+ reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
11474
+ } : Promise.resolve(axios__default["default"].get(_this4._URL + "/api/v2/amounts?fromCurrency=" + fromCoinSwapspaceDetails.code + "&fromNetwork=" + fromCoinSwapspaceDetails.network + "&toNetwork=" + toCoinSwapspaceDetails.network + "&toCurrency=" + toCoinSwapspaceDetails.code + "&amount=" + amountCoins + "&estimated=false", {
11475
+ headers: _this4._headers
11476
+ })).then(function (response) {
11477
+ var _response$data, _exchangesSupportingT;
11478
+ var _exit;
11479
+ function _temp4(_result) {
11480
+ if (_exit) return _result;
11481
+ var result = {
11482
+ result: false,
11483
+ reason: smallestMin && bignumber_js.BigNumber(amountCoins).lt(smallestMin) ? SwapProvider.NO_SWAPS_REASONS.TOO_LOW : greatestMax && bignumber_js.BigNumber(amountCoins).gt(greatestMax) ? SwapProvider.NO_SWAPS_REASONS.TOO_HIGH : SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED,
11484
+ smallestMin: smallestMin,
11485
+ greatestMax: greatestMax
11486
+ };
11487
+ Logger.log("Returning result " + safeStringify(result), loggerSource);
11488
+ return result;
11489
+ }
11490
+ Logger.log("Retrieved " + (response == null || (_response$data = response.data) == null ? void 0 : _response$data.length) + " options", loggerSource);
11491
+ var options = Array.isArray(response.data) ? response.data : [];
11492
+ // TODO: [feature, high] remove if possible over-engineering about toAmount = 0 options treating as supported but not available. task_id=404ae30d9a7743238af3cc0d3bae9239
11493
+ var exchangesSupportingThePairDespiteFixedOrFloating = options.filter(function (exchange) {
11494
+ return (exchange == null ? void 0 : exchange.exists) && !bannedPartners.find(function (bannedPartner) {
11495
+ return bannedPartner === (exchange == null ? void 0 : exchange.partner);
11496
+ }) && ((exchange == null ? void 0 : exchange.fixed) === false || (exchange == null ? void 0 : exchange.fixed) === true) && typeof exchange.toAmount === "number" && (typeof exchange.min === "number" && typeof exchange.max === "number" || exchange.toAmount > 0) && (exchange.min === 0 || exchange.max === 0 || exchange.max > exchange.min);
11217
11497
  });
11218
- }
11219
- Logger.log(((_exchangesSupportingT = exchangesSupportingThePair) == null ? void 0 : _exchangesSupportingT.length) + " of them have exist=true", loggerSource);
11220
- if (exchangesSupportingThePair.length === 0) {
11221
- if (exchangesSupportingThePairDespiteFixedOrFloating.length > 0 && fixed !== null) {
11498
+ var exchangesSupportingThePair = exchangesSupportingThePairDespiteFixedOrFloating;
11499
+ if (fixed != null) {
11500
+ exchangesSupportingThePair = exchangesSupportingThePairDespiteFixedOrFloating.filter(function (option) {
11501
+ return option.fixed === fixed;
11502
+ });
11503
+ }
11504
+ Logger.log(((_exchangesSupportingT = exchangesSupportingThePair) == null ? void 0 : _exchangesSupportingT.length) + " of them have exist=true", loggerSource);
11505
+ if (exchangesSupportingThePair.length === 0) {
11506
+ if (exchangesSupportingThePairDespiteFixedOrFloating.length > 0 && fixed !== null) {
11507
+ return {
11508
+ result: false,
11509
+ reason: fixed ? SwapProvider.NO_SWAPS_REASONS.NO_FIXED_BUT_HAVE_FLOATING : SwapProvider.NO_SWAPS_REASONS.NO_FLOATING_BUT_HAVE_FIXED
11510
+ };
11511
+ }
11222
11512
  return {
11223
11513
  result: false,
11224
- reason: fixed ? SwapProvider.NO_SWAPS_REASONS.NO_FIXED_BUT_HAVE_FLOATING : SwapProvider.NO_SWAPS_REASONS.NO_FLOATING_BUT_HAVE_FIXED
11514
+ reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
11225
11515
  };
11226
11516
  }
11227
- return {
11228
- result: false,
11229
- reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
11230
- };
11231
- }
11232
- var availableExchanges = exchangesSupportingThePair.filter(function (exchange) {
11233
- return typeof (exchange == null ? void 0 : exchange.toAmount) === "number" && exchange.toAmount > 0;
11234
- });
11235
- Logger.log("Available (having amountTo): " + safeStringify(availableExchanges), loggerSource);
11236
- // min=0 or max=0 means there is no limit for the partner
11237
- var smallestMin = null;
11238
- if (exchangesSupportingThePair.find(function (ex) {
11239
- return bignumber_js.BigNumber(ex.min).isZero();
11240
- }) == null) {
11241
- smallestMin = exchangesSupportingThePair.reduce(function (prev, cur) {
11242
- if (typeof cur.min === "number" && (prev === null || bignumber_js.BigNumber(cur.min).lt(prev))) return bignumber_js.BigNumber(cur.min);
11243
- return prev;
11244
- }, null);
11245
- }
11246
- var greatestMax = null;
11247
- if (exchangesSupportingThePair.find(function (ex) {
11248
- return bignumber_js.BigNumber(ex.max).isZero();
11249
- }) == null) {
11250
- greatestMax = exchangesSupportingThePair.reduce(function (prev, cur) {
11251
- if (typeof cur.max === "number" && (prev === null || bignumber_js.BigNumber(cur.max).gt(prev))) return bignumber_js.BigNumber(cur.max);
11252
- return prev;
11253
- }, null);
11254
- }
11255
- var extraCoinsToFitMinMax = "0";
11256
- if (typeof fromCoinToUsdRate === "string" && bignumber_js.BigNumber(fromCoinToUsdRate).gt("0")) {
11257
- var extraUsdToFitMinMax = bignumber_js.BigNumber("1"); // We correct the limits as the exact limit can fluctuate and cause failed swap creation
11258
- extraCoinsToFitMinMax = AmountUtils.trim(extraUsdToFitMinMax.div(fromCoinToUsdRate), fromCoin.digits);
11259
- }
11260
- if (smallestMin instanceof bignumber_js.BigNumber) {
11261
- smallestMin = AmountUtils.trim(smallestMin.plus(extraCoinsToFitMinMax), fromCoin.digits);
11262
- }
11263
- if (greatestMax instanceof bignumber_js.BigNumber) {
11264
- if (greatestMax > extraCoinsToFitMinMax) {
11265
- greatestMax = AmountUtils.trim(greatestMax.minus(extraCoinsToFitMinMax), fromCoin.digits);
11266
- } else {
11267
- greatestMax = "0";
11517
+ var availableExchanges = exchangesSupportingThePair.filter(function (exchange) {
11518
+ return typeof (exchange == null ? void 0 : exchange.toAmount) === "number" && exchange.toAmount > 0;
11519
+ });
11520
+ Logger.log("Available (having amountTo): " + safeStringify(availableExchanges), loggerSource);
11521
+ // min=0 or max=0 means there is no limit for the partner
11522
+ var smallestMin = null;
11523
+ if (exchangesSupportingThePair.find(function (ex) {
11524
+ return bignumber_js.BigNumber(ex.min).isZero();
11525
+ }) == null) {
11526
+ smallestMin = exchangesSupportingThePair.reduce(function (prev, cur) {
11527
+ if (typeof cur.min === "number" && (prev === null || bignumber_js.BigNumber(cur.min).lt(prev))) return bignumber_js.BigNumber(cur.min);
11528
+ return prev;
11529
+ }, null);
11268
11530
  }
11269
- }
11270
- var _temp3 = function () {
11271
- if (availableExchanges.length) {
11272
- var sorted = availableExchanges.sort(function (op1, op2) {
11273
- return op2.toAmount - op1.toAmount;
11274
- });
11275
- var bestOpt = sorted[0];
11276
- Logger.log("Returning first option after sorting: " + safeStringify(bestOpt), loggerSource);
11277
- var max = null;
11278
- var min = null;
11279
- if (extraCoinsToFitMinMax != null) {
11280
- if (typeof bestOpt.max === "number" && bestOpt.max !== 0) {
11281
- max = bignumber_js.BigNumber(bestOpt.max).minus(extraCoinsToFitMinMax);
11282
- max = AmountUtils.trim(max.lt(0) ? "0" : max, fromCoin.digits);
11283
- }
11284
- if (typeof bestOpt.min === "number" && bestOpt.min !== 0) {
11285
- min = AmountUtils.trim(bignumber_js.BigNumber(bestOpt.min).plus(extraCoinsToFitMinMax), fromCoin.digits);
11286
- }
11531
+ var greatestMax = null;
11532
+ if (exchangesSupportingThePair.find(function (ex) {
11533
+ return bignumber_js.BigNumber(ex.max).isZero();
11534
+ }) == null) {
11535
+ greatestMax = exchangesSupportingThePair.reduce(function (prev, cur) {
11536
+ if (typeof cur.max === "number" && (prev === null || bignumber_js.BigNumber(cur.max).gt(prev))) return bignumber_js.BigNumber(cur.max);
11537
+ return prev;
11538
+ }, null);
11539
+ }
11540
+ var extraCoinsToFitMinMax = "0";
11541
+ if (typeof fromCoinToUsdRate === "string" && bignumber_js.BigNumber(fromCoinToUsdRate).gt("0")) {
11542
+ var extraUsdToFitMinMax = bignumber_js.BigNumber("1"); // We correct the limits as the exact limit can fluctuate and cause failed swap creation
11543
+ extraCoinsToFitMinMax = AmountUtils.trim(extraUsdToFitMinMax.div(fromCoinToUsdRate), fromCoin.digits);
11544
+ }
11545
+ if (smallestMin instanceof bignumber_js.BigNumber) {
11546
+ smallestMin = AmountUtils.trim(smallestMin.plus(extraCoinsToFitMinMax), fromCoin.digits);
11547
+ }
11548
+ if (greatestMax instanceof bignumber_js.BigNumber) {
11549
+ if (greatestMax > extraCoinsToFitMinMax) {
11550
+ greatestMax = AmountUtils.trim(greatestMax.minus(extraCoinsToFitMinMax), fromCoin.digits);
11551
+ } else {
11552
+ greatestMax = "0";
11287
11553
  }
11288
- var rate = bestOpt.toAmount && bestOpt.fromAmount ? bignumber_js.BigNumber(bestOpt.toAmount).div(bestOpt.fromAmount) : null;
11289
- return Promise.resolve(_this4._fetchPartnersListIfNeeded()).then(function () {
11290
- var _bestOpt$duration;
11291
- var partner = _this4._partners.find(function (p) {
11292
- var _bestOpt$partner;
11293
- return (bestOpt == null || (_bestOpt$partner = bestOpt.partner) == null ? void 0 : _bestOpt$partner.toLowerCase()) === p.path.toLowerCase();
11294
- });
11295
- var isRefundAddressRequired = partner == null ? true : bestOpt.fixed ? partner.reqFixedRefund : partner.reqFloatRefund;
11296
- var _result$min$max$small = {
11297
- result: true,
11298
- min: min,
11299
- max: max,
11300
- smallestMin: smallestMin,
11301
- greatestMax: greatestMax,
11302
- rate: rate != null ? AmountUtils.trim(rate, _this4._maxRateDigits) : null,
11303
- durationMinutesRange: (_bestOpt$duration = bestOpt.duration) != null ? _bestOpt$duration : null,
11304
- fixed: bestOpt.fixed,
11305
- rawSwapData: bestOpt,
11306
- isRefundAddressRequired: !!isRefundAddressRequired
11307
- };
11308
- _exit = 1;
11309
- return _result$min$max$small;
11310
- });
11311
11554
  }
11312
- }();
11313
- return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
11314
- });
11315
- }, function (e) {
11316
- var _e$response;
11317
- if ((e == null || (_e$response = e.response) == null ? void 0 : _e$response.status) === 429) {
11318
- return {
11319
- result: false,
11320
- reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
11321
- };
11555
+ var _temp3 = function () {
11556
+ if (availableExchanges.length) {
11557
+ var sorted = availableExchanges.sort(function (op1, op2) {
11558
+ return op2.toAmount - op1.toAmount;
11559
+ });
11560
+ var bestOpt = sorted[0];
11561
+ Logger.log("Returning first option after sorting: " + safeStringify(bestOpt), loggerSource);
11562
+ var max = null;
11563
+ var min = null;
11564
+ if (extraCoinsToFitMinMax != null) {
11565
+ if (typeof bestOpt.max === "number" && bestOpt.max !== 0) {
11566
+ max = bignumber_js.BigNumber(bestOpt.max).minus(extraCoinsToFitMinMax);
11567
+ max = AmountUtils.trim(max.lt(0) ? "0" : max, fromCoin.digits);
11568
+ }
11569
+ if (typeof bestOpt.min === "number" && bestOpt.min !== 0) {
11570
+ min = AmountUtils.trim(bignumber_js.BigNumber(bestOpt.min).plus(extraCoinsToFitMinMax), fromCoin.digits);
11571
+ }
11572
+ }
11573
+ var rate = bestOpt.toAmount && bestOpt.fromAmount ? bignumber_js.BigNumber(bestOpt.toAmount).div(bestOpt.fromAmount) : null;
11574
+ return Promise.resolve(_this4._fetchPartnersListIfNeeded()).then(function () {
11575
+ var _bestOpt$duration;
11576
+ var partner = _this4._partners.find(function (p) {
11577
+ var _bestOpt$partner;
11578
+ return (bestOpt == null || (_bestOpt$partner = bestOpt.partner) == null ? void 0 : _bestOpt$partner.toLowerCase()) === p.path.toLowerCase();
11579
+ });
11580
+ var isRefundAddressRequired = partner == null ? true : bestOpt.fixed ? partner.reqFixedRefund : partner.reqFloatRefund;
11581
+ var _result$min$max$small = {
11582
+ result: true,
11583
+ min: min,
11584
+ max: max,
11585
+ smallestMin: smallestMin,
11586
+ greatestMax: greatestMax,
11587
+ rate: rate != null ? AmountUtils.trim(rate, _this4._maxRateDigits) : null,
11588
+ durationMinutesRange: (_bestOpt$duration = bestOpt.duration) != null ? _bestOpt$duration : null,
11589
+ fixed: bestOpt.fixed,
11590
+ rawSwapData: bestOpt,
11591
+ isRefundAddressRequired: !!isRefundAddressRequired
11592
+ };
11593
+ _exit = 1;
11594
+ return _result$min$max$small;
11595
+ });
11596
+ }
11597
+ }();
11598
+ return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
11599
+ });
11600
+ });
11601
+ /* Here we use not documented parameter 'estimated=false'. This parameter controls whether we want to use
11602
+ * cached rate values stored in swapspace cache. Their support says they store at most for 30 sec.
11603
+ * But we are better off using the most actual rates.
11604
+ */
11605
+ }, function (e) {
11606
+ var _e$response;
11607
+ if ((e == null || (_e$response = e.response) == null ? void 0 : _e$response.status) === 429) {
11608
+ return {
11609
+ result: false,
11610
+ reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
11611
+ };
11322
11612
  }
11323
11613
  Logger.log("Internal swapspace/rabbit error when getting swap options " + safeStringify(e), loggerSource);
11324
11614
  improveAndRethrow(e, loggerSource);
@@ -11350,13 +11640,13 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11350
11640
  ) {
11351
11641
  throw new Error("Invalid raw swap data: " + safeStringify(rawSwapData));
11352
11642
  }
11353
- var _this5$_supportedCoin = _this5._supportedCoins.reduce(function (prev, coinData) {
11354
- return [coinData.coin.ticker === fromCoin.ticker ? coinData.hasExtraId : prev[0], coinData.coin.ticker === toCoin.ticker ? coinData.hasExtraId : prev[1]];
11355
- }, [false, false]),
11356
- fromCurrencyHasExtraId = _this5$_supportedCoin[0],
11357
- toCurrencyHasExtraId = _this5$_supportedCoin[1];
11358
11643
  return Promise.resolve(_this5._fetchSupportedCurrenciesIfNeeded()).then(function () {
11359
11644
  var _toCurrencyExtraId, _refundExtraId;
11645
+ var _this5$_supportedCoin = _this5._supportedCoins.reduce(function (prev, coinData) {
11646
+ return [coinData.coin.ticker === fromCoin.ticker ? coinData.hasExtraId : prev[0], coinData.coin.ticker === toCoin.ticker ? coinData.hasExtraId : prev[1]];
11647
+ }, [false, false]),
11648
+ fromCurrencyHasExtraId = _this5$_supportedCoin[0],
11649
+ toCurrencyHasExtraId = _this5$_supportedCoin[1];
11360
11650
  var requestData = {
11361
11651
  partner: partner,
11362
11652
  fromCurrency: rawSwapData == null ? void 0 : rawSwapData.fromCurrency,
@@ -11374,7 +11664,9 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11374
11664
  refund: refundAddress
11375
11665
  };
11376
11666
  Logger.log("Sending create request: " + safeStringify(requestData), loggerSource);
11377
- return Promise.resolve(axios__default["default"].post(_this5._URL + "/api/v2/exchange", requestData)).then(function (response) {
11667
+ return Promise.resolve(axios__default["default"].post(_this5._URL + "/api/v2/exchange", requestData, {
11668
+ headers: _this5._headers
11669
+ })).then(function (response) {
11378
11670
  var result = response.data;
11379
11671
  Logger.log("Creation result " + safeStringify(result), loggerSource);
11380
11672
  if (result != null && result.id) {
@@ -11479,7 +11771,9 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11479
11771
  var getNotFailingOn404 = function getNotFailingOn404(swapId) {
11480
11772
  try {
11481
11773
  return Promise.resolve(_catch$3(function () {
11482
- return Promise.resolve(axios__default["default"].get(_this6._URL + "/api/v2/exchange/" + swapId));
11774
+ return Promise.resolve(axios__default["default"].get(_this6._URL + "/api/v2/exchange/" + swapId, {
11775
+ headers: _this6._headers
11776
+ }));
11483
11777
  }, function (error) {
11484
11778
  var _error$response;
11485
11779
  if ((error == null || (_error$response = error.response) == null ? void 0 : _error$response.status) === 404) return [];
@@ -11552,15 +11846,11 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11552
11846
  var _this7 = this;
11553
11847
  return Promise.resolve(_catch$3(function () {
11554
11848
  return Promise.resolve(_this7._fetchPartnersListIfNeeded()).then(function () {
11555
- var swapspacePartners = _this7._partners.filter(function (p) {
11556
- return !BANNED_PARTNERS.find(function (banned) {
11557
- return banned === p.path;
11558
- });
11559
- }).map(function (p) {
11849
+ var swapspacePartners = _this7._partners.map(function (p) {
11560
11850
  var _p$image;
11561
- return new Partner(p.name, p != null && (_p$image = p.image) != null && _p$image["default"] ? "https://storage.swapspace.co" + p.image["default"] : null);
11851
+ return new Partner(p.path, p.name, p != null && (_p$image = p.image) != null && _p$image["default"] ? "https://storage.swapspace.co" + p.image["default"] : null, p.kycLevel);
11562
11852
  });
11563
- var swapspaceItself = new Partner("Swapspace", "https://storage.swapspace.co/static/logo-vertical-black.svg");
11853
+ var swapspaceItself = new Partner("swapspace", "Swapspace", "https://storage.swapspace.co/static/logo-vertical-black.svg", KYC_LEVELS.LOW);
11564
11854
  return [swapspaceItself].concat(swapspacePartners);
11565
11855
  });
11566
11856
  }, function (e) {
@@ -11584,354 +11874,440 @@ function _catch$2(body, recover) {
11584
11874
  }
11585
11875
  return result;
11586
11876
  }
11587
- var _iteratorSymbol = typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator";
11588
- function _settle(pact, state, value) {
11589
- if (!pact.s) {
11590
- if (value instanceof _Pact) {
11591
- if (value.s) {
11592
- if (state & 1) {
11593
- state = value.s;
11594
- }
11595
- value = value.v;
11596
- } else {
11597
- value.o = _settle.bind(null, pact, state);
11598
- return;
11599
- }
11877
+ var LetsExchangeSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11878
+ _inheritsLoose(LetsExchangeSwapProvider, _SwapProvider);
11879
+ function LetsExchangeSwapProvider(apiKeysProxyUrl, cache, customCoinBuilder, useRestrictedCoinsSet, apiKey) {
11880
+ var _this;
11881
+ if (customCoinBuilder === void 0) {
11882
+ customCoinBuilder = function customCoinBuilder(coin, network) {
11883
+ return null;
11884
+ };
11600
11885
  }
11601
- if (value && value.then) {
11602
- value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
11603
- return;
11886
+ if (useRestrictedCoinsSet === void 0) {
11887
+ useRestrictedCoinsSet = true;
11604
11888
  }
11605
- pact.s = state;
11606
- pact.v = value;
11607
- var observer = pact.o;
11608
- if (observer) {
11609
- observer(pact);
11889
+ if (apiKey === void 0) {
11890
+ apiKey = null;
11610
11891
  }
11892
+ _this = _SwapProvider.call(this, "letsexchange", cache, customCoinBuilder, useRestrictedCoinsSet) || this;
11893
+ _this._partners = [];
11894
+ _this._URL = apiKey ? "https://api.letsexchange.io/api" : apiKeysProxyUrl + "/" + _this.id;
11895
+ _this.isAggregator = false;
11896
+ _this._headers = apiKey ? {
11897
+ Authorization: "Bearer " + apiKey,
11898
+ "Content-Type": "application/json",
11899
+ Accept: "application/json"
11900
+ } : {};
11901
+ return _this;
11611
11902
  }
11612
- }
11613
- var _Pact = /*#__PURE__*/function () {
11614
- function _Pact() {}
11615
- _Pact.prototype.then = function (onFulfilled, onRejected) {
11616
- var result = new _Pact();
11617
- var state = this.s;
11618
- if (state) {
11619
- var callback = state & 1 ? onFulfilled : onRejected;
11620
- if (callback) {
11621
- try {
11622
- _settle(result, 1, callback(this.v));
11623
- } catch (e) {
11624
- _settle(result, 2, e);
11625
- }
11626
- return result;
11627
- } else {
11628
- return this;
11629
- }
11630
- }
11631
- this.o = function (_this) {
11632
- try {
11633
- var value = _this.v;
11634
- if (_this.s & 1) {
11635
- _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
11636
- } else if (onRejected) {
11637
- _settle(result, 1, onRejected(value));
11638
- } else {
11639
- _settle(result, 2, value);
11640
- }
11641
- } catch (e) {
11642
- _settle(result, 2, e);
11643
- }
11644
- };
11645
- return result;
11903
+ var _proto = LetsExchangeSwapProvider.prototype;
11904
+ _proto.getSwapCreationInfoTtlMs = function getSwapCreationInfoTtlMs() {
11905
+ return 110000;
11646
11906
  };
11647
- return _Pact;
11648
- }();
11649
- function _isSettledPact(thenable) {
11650
- return thenable instanceof _Pact && thenable.s & 1;
11651
- }
11652
- function _forTo(array, body, check) {
11653
- var i = -1,
11654
- pact,
11655
- reject;
11656
- function _cycle(result) {
11907
+ _proto._fetchSupportedCurrenciesIfNeeded = function _fetchSupportedCurrenciesIfNeeded() {
11657
11908
  try {
11658
- while (++i < array.length && (!check || !check())) {
11659
- result = body(i);
11660
- if (result && result.then) {
11661
- if (_isSettledPact(result)) {
11662
- result = result.v;
11663
- } else {
11664
- result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
11665
- return;
11909
+ var _this2 = this;
11910
+ var loggerSource = "_fetchSupportedCurrenciesIfNeeded";
11911
+ return Promise.resolve(_catch$2(function () {
11912
+ var _temp = function () {
11913
+ if (_this2._shouldCoinsListBeLoaded()) {
11914
+ return Promise.resolve(axios__default["default"].get(_this2._URL + "/v2/coins", {
11915
+ headers: _this2._headers
11916
+ })).then(function (rawResponse) {
11917
+ var _rawResponse$data, _rawResponse$data2;
11918
+ Logger.log("Retrieved " + (rawResponse == null || (_rawResponse$data = rawResponse.data) == null ? void 0 : _rawResponse$data.length), loggerSource);
11919
+ var allowedCoins = (_rawResponse$data2 = rawResponse == null ? void 0 : rawResponse.data) != null ? _rawResponse$data2 : [];
11920
+ Logger.log("Allowed cnt " + allowedCoins.length, loggerSource);
11921
+ _this2._supportedCoins = allowedCoins.map(function (item) {
11922
+ var code = item.code.toUpperCase();
11923
+ if (!Array.isArray(item.networks)) return [];
11924
+ return item.networks.map(function (networkDetails) {
11925
+ var network = networkDetails.code.toUpperCase();
11926
+ var coin = _this2._customCoinBuilder != null ? _this2._customCoinBuilder(code, network) : null;
11927
+ if (!coin && !_this2.useRestrictedCoinsSet) {
11928
+ var name = _this2.removeProtocolNameFromCoinName(item.name, code, network);
11929
+ var ticker = toRabbitTicker(code, network);
11930
+ var defaultDecimalPlacesForCoinNotSupportedOOB = DEFAULT_CRYPTO_DECIMAL_COUNT;
11931
+ var defaultMinConfirmationsForCoinNotSupportedOOB = 1;
11932
+ coin = new Coin(name, ticker, code, defaultDecimalPlacesForCoinNotSupportedOOB, null, "", null, null, defaultMinConfirmationsForCoinNotSupportedOOB, null, [], 60000, null, code !== network ? new Protocol(network) : null, item.contract_address || null, false);
11933
+ }
11934
+ if (coin) {
11935
+ var _networkDetails$extra, _networkDetails$valid;
11936
+ return new SwapProviderCoinInfo(coin, item.code, networkDetails.code, !!networkDetails.has_extra, (_networkDetails$extra = networkDetails.extra_name) != null ? _networkDetails$extra : null, item.rating || 0, item.icon ? item.icon : FALLBACK_ASSET_ICON_URL, true,
11937
+ // Letsexchange provide no such details
11938
+ true, // Letsexchange provide no such details
11939
+ (_networkDetails$valid = networkDetails.validation_address_regex) != null ? _networkDetails$valid : null, (typeof item.is_active !== "number" || item.is_active === 1) && (typeof item.disabled !== "number" || item.disabled === 0) && (typeof networkDetails.is_active !== "number" || networkDetails.is_active === 1));
11940
+ }
11941
+ return [];
11942
+ });
11943
+ }).flat();
11944
+ _this2._supportedCoinsLastUpdateTimestamp = Date.now();
11945
+ _this2._putPopularCoinsFirst();
11946
+ return Promise.resolve(_SwapProvider.prototype._fetchSupportedCurrenciesIfNeeded.call(_this2)).then(function () {});
11947
+ });
11666
11948
  }
11667
- }
11668
- }
11669
- if (pact) {
11670
- _settle(pact, 1, result);
11671
- } else {
11672
- pact = result;
11673
- }
11949
+ }();
11950
+ if (_temp && _temp.then) return _temp.then(function () {});
11951
+ }, function (e) {
11952
+ improveAndRethrow(e, loggerSource);
11953
+ }));
11674
11954
  } catch (e) {
11675
- _settle(pact || (pact = new _Pact()), 2, e);
11955
+ return Promise.reject(e);
11676
11956
  }
11677
- }
11678
- _cycle();
11679
- return pact;
11680
- }
11681
- function _forOf(target, body, check) {
11682
- if (typeof target[_iteratorSymbol] === "function") {
11683
- var _cycle = function _cycle(result) {
11684
- try {
11685
- while (!(step = iterator.next()).done && (!check || !check())) {
11686
- result = body(step.value);
11687
- if (result && result.then) {
11688
- if (_isSettledPact(result)) {
11689
- result = result.v;
11690
- } else {
11691
- result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
11692
- return;
11693
- }
11694
- }
11695
- }
11696
- if (pact) {
11697
- _settle(pact, 1, result);
11698
- } else {
11699
- pact = result;
11957
+ };
11958
+ _proto.getSwapInfo = function getSwapInfo(fromCoin, toCoin, amountCoins, fixed, fromCoinToUsdRate, amountIsToReceive) {
11959
+ if (fixed === void 0) {
11960
+ fixed = false;
11961
+ }
11962
+ if (amountIsToReceive === void 0) {
11963
+ amountIsToReceive = false;
11964
+ }
11965
+ try {
11966
+ var _this3 = this;
11967
+ var loggerSource = "getSwapInfo";
11968
+ var min = null;
11969
+ var max = null;
11970
+ return Promise.resolve(_catch$2(function () {
11971
+ if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amountCoins !== "string" || bignumber_js.BigNumber(amountCoins).lt("0") || fixed !== null && typeof fixed !== "boolean" || amountIsToReceive && !fixed) {
11972
+ throw new Error("Wrong input params: " + amountCoins + " " + fromCoin.ticker + " -> " + toCoin.ticker + ", " + (fromCoin instanceof Coin) + ", " + (toCoin instanceof Coin) + ", " + typeof fixed + " " + fixed + ", " + amountIsToReceive);
11700
11973
  }
11701
- } catch (e) {
11702
- _settle(pact || (pact = new _Pact()), 2, e);
11703
- }
11704
- };
11705
- var iterator = target[_iteratorSymbol](),
11706
- step,
11707
- pact,
11708
- reject;
11709
- _cycle();
11710
- if (iterator["return"]) {
11711
- var _fixup = function _fixup(value) {
11712
- try {
11713
- if (!step.done) {
11714
- iterator["return"]();
11974
+ return Promise.resolve(_this3._fetchSupportedCurrenciesIfNeeded()).then(function () {
11975
+ var fromCoinDetails = _this3._supportedCoins.find(function (i) {
11976
+ var _i$coin;
11977
+ return ((_i$coin = i.coin) == null ? void 0 : _i$coin.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
11978
+ });
11979
+ var toCoinDetails = _this3._supportedCoins.find(function (i) {
11980
+ var _i$coin2;
11981
+ return ((_i$coin2 = i.coin) == null ? void 0 : _i$coin2.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
11982
+ });
11983
+ if (!fromCoinDetails || !toCoinDetails || !fromCoinDetails.deposit || !fromCoinDetails.isAvailable || !toCoinDetails.withdrawal || !toCoinDetails.isAvailable) {
11984
+ return {
11985
+ result: false,
11986
+ reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
11987
+ };
11715
11988
  }
11716
- } catch (e) {}
11717
- return value;
11718
- };
11719
- if (pact && pact.then) {
11720
- return pact.then(_fixup, function (e) {
11721
- throw _fixup(e);
11989
+ var pathAndQuery = "/v1/info" + (amountIsToReceive ? "-revert" : "?float=" + !fixed);
11990
+ return Promise.resolve(axios__default["default"].post("" + _this3._URL + pathAndQuery, {
11991
+ from: fromCoinDetails.code,
11992
+ to: toCoinDetails.code,
11993
+ network_from: fromCoinDetails.network,
11994
+ network_to: toCoinDetails.network,
11995
+ amount: amountCoins,
11996
+ affiliate_id: LetsExchangeSwapProvider.AFFILIATE_ID
11997
+ }, {
11998
+ headers: _this3._headers
11999
+ })).then(function (response) {
12000
+ Logger.log("Retrieved " + (response == null ? void 0 : response.data), loggerSource);
12001
+ var data = response.data;
12002
+
12003
+ // TODO: [dev] add SwapProvider.NO_SWAPS_REASONS.NO_FIXED_BUT_HAVE_FLOATING - request alternative rate. task_id=
12004
+
12005
+ // TODO: [feature, low] implement extra coins to fit min/max if there are frequent errors due to min/max exceeding
12006
+ // let extraCoinsToFitMinMax = "0";
12007
+ // if (typeof fromCoinToUsdRate === "string" && BigNumber(fromCoinToUsdRate).gt("0")) {
12008
+ // const extraUsdToFitMinMax = BigNumber("1"); // We correct the limits as the exact limit can fluctuate and cause failed swap creation
12009
+ // extraCoinsToFitMinMax = AmountUtils.trim(extraUsdToFitMinMax.div(fromCoinToUsdRate), fromCoin.digits);
12010
+ // }
12011
+ if (data != null && data.min_amount) {
12012
+ min = AmountUtils.trim(data == null ? void 0 : data.min_amount, amountIsToReceive ? toCoin.digits : fromCoin.digits);
12013
+ }
12014
+ if (data != null && data.max_amount) {
12015
+ max = AmountUtils.trim(data == null ? void 0 : data.max_amount, amountIsToReceive ? toCoin.digits : fromCoin.digits);
12016
+ }
12017
+ if (data.success === false && data.error) {
12018
+ // TODO: [dev] waiting for response from letsexchange about their not-documented responses
12019
+ // {
12020
+ // "success": false,
12021
+ // "error": "Internal error"
12022
+ // }
12023
+ throw new Error("Failed to estimate swap letsexchange");
12024
+ }
12025
+ if (bignumber_js.BigNumber(data.rate).eq("0") || bignumber_js.BigNumber(data.amount).eq("0")) {
12026
+ // TODO actualize according to letsexchage clarification - decide, can we count on min/max abcense? task_id=76512110797f4eab8b37f1bb789825cb
12027
+ // amount: "0", rate: "0", rate_id: ""
12028
+ var reason = SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED;
12029
+ if (min && bignumber_js.BigNumber(amountCoins).lt(min)) {
12030
+ reason = SwapProvider.NO_SWAPS_REASONS.TOO_LOW;
12031
+ } else if (max && bignumber_js.BigNumber(amountCoins).gt(max)) {
12032
+ reason = SwapProvider.NO_SWAPS_REASONS.TOO_HIGH;
12033
+ } else if (!amountIsToReceive) {
12034
+ // If we are not requesting receiving amount (it cannot be floating-rate)
12035
+ // todo [feature, moderate] request alternative rate. task_id=31884db5392f49738c20a86115c90e1f
12036
+ // const alternativeRate = 1;
12037
+ // const alternativeRateAvailable = alternativeRate;
12038
+ // if (alternativeRateAvailable) {
12039
+ // reason = fixed
12040
+ // ? SwapProvider.NO_SWAPS_REASONS.NO_FIXED_BUT_HAVE_FLOATING
12041
+ // : SwapProvider.NO_SWAPS_REASONS.NO_FLOATING_BUT_HAVE_FIXED;
12042
+ // }
12043
+ }
12044
+ return {
12045
+ result: false,
12046
+ reason: reason,
12047
+ smallestMin: min,
12048
+ greatestMax: max
12049
+ };
12050
+ }
12051
+ var rate = amountIsToReceive ? bignumber_js.BigNumber(amountCoins).div(data.amount) : bignumber_js.BigNumber(data.amount).div(amountCoins);
12052
+ return {
12053
+ result: true,
12054
+ min: min,
12055
+ max: max,
12056
+ smallestMin: min,
12057
+ greatestMax: max,
12058
+ rate: AmountUtils.trim(rate, _this3._maxRateDigits),
12059
+ durationMinutesRange: null,
12060
+ fixed: fixed,
12061
+ rawSwapData: data,
12062
+ isRefundAddressRequired: false
12063
+ };
12064
+ });
11722
12065
  });
11723
- }
11724
- _fixup();
11725
- }
11726
- return pact;
11727
- }
11728
- // No support for Symbol.iterator
11729
- if (!("length" in target)) {
11730
- throw new TypeError("Object is not iterable");
11731
- }
11732
- // Handle live collections properly
11733
- var values = [];
11734
- for (var i = 0; i < target.length; i++) {
11735
- values.push(target[i]);
11736
- }
11737
- return _forTo(values, function (i) {
11738
- return body(values[i]);
11739
- }, check);
11740
- }
11741
- var SwapUtils = /*#__PURE__*/function () {
11742
- function SwapUtils() {}
11743
- /**
11744
- * Retrieves min and max limits for swapping giving currencies.
11745
- * Returns also conversion rate if possible with predefined amount logic.
11746
- * Rate is how many "to" coins does 1 "from" coin contain.
11747
- *
11748
- * In case of errors returns one of reasons
11749
- * - SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
11750
- * - one of SwapProvider.COMMON_ERRORS.*
11751
- *
11752
- * @param swapProvider {SwapProvider}
11753
- * @param fromCoin {Coin} enabled coin (to swap amount from)
11754
- * @param toCoin {Coin}
11755
- * @param coinToCurrentFiatRate {string|null}
11756
- * @param fiatCurrencyDecimals {number|null}
11757
- * @return {Promise<{
11758
- * result: true,
11759
- * min: string,
11760
- * fiatMin: (number|null),
11761
- * max: string,
11762
- * fiatMax: (number|null),
11763
- * rate: (string|null),
11764
- * }|{
11765
- * result: false,
11766
- * reason: string
11767
- * }>}
11768
- */
11769
- SwapUtils.getInitialSwapData = function getInitialSwapData(swapProvider, fromCoin, toCoin, coinToCurrentFiatRate, fiatCurrencyDecimals) {
11770
- if (coinToCurrentFiatRate === void 0) {
11771
- coinToCurrentFiatRate = null;
12066
+ }, function (e) {
12067
+ var _e$response, _e$response2;
12068
+ if ((e == null || (_e$response = e.response) == null ? void 0 : _e$response.status) === 404) {
12069
+ return {
12070
+ result: false,
12071
+ reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED,
12072
+ smallestMin: min,
12073
+ greatestMax: max
12074
+ };
12075
+ }
12076
+ if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
12077
+ return {
12078
+ result: false,
12079
+ reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
12080
+ };
12081
+ }
12082
+ Logger.log("Internal error when getting swap options " + safeStringify(e), loggerSource);
12083
+ improveAndRethrow(e, loggerSource);
12084
+ }));
12085
+ } catch (e) {
12086
+ return Promise.reject(e);
11772
12087
  }
11773
- if (fiatCurrencyDecimals === void 0) {
11774
- fiatCurrencyDecimals = null;
12088
+ };
12089
+ _proto.createSwap = function createSwap(fromCoin, toCoin, amount, toAddress, refundAddress, rawSwapData, clientIpAddress, fixed, toCurrencyExtraId, refundExtraId, amountIsToReceive) {
12090
+ if (toCurrencyExtraId === void 0) {
12091
+ toCurrencyExtraId = "";
12092
+ }
12093
+ if (refundExtraId === void 0) {
12094
+ refundExtraId = "";
12095
+ }
12096
+ if (amountIsToReceive === void 0) {
12097
+ amountIsToReceive = false;
11775
12098
  }
11776
12099
  try {
11777
- var loggerSource = "getInitialSwapData";
12100
+ var _this4 = this;
12101
+ var loggerSource = "createSwap";
11778
12102
  return Promise.resolve(_catch$2(function () {
11779
- /* We use some amount here that should fit at least some of the limits of the swap providers.
11780
- * So we are going to get some rate to be used as the default for the on-flight calculations before we get
11781
- * the exact rate (that should be retrieved by getSwapCreationInfo method) for a specific amount.
11782
- */
11783
- var defaultAmountUsd = bignumber_js.BigNumber("300");
11784
- return Promise.resolve(swapProvider.getCoinToUSDTRate(fromCoin)).then(function (coinUsdRate) {
11785
- var coinAmountForDefaultUsdAmount = AmountUtils.trim(coinUsdRate != null && coinUsdRate.result ? defaultAmountUsd.div(coinUsdRate == null ? void 0 : coinUsdRate.rate) : defaultAmountUsd, fromCoin.digits);
11786
- Logger.log("Init: " + coinAmountForDefaultUsdAmount + " " + fromCoin.ticker + "->" + toCoin.ticker, loggerSource);
11787
- return Promise.resolve(swapProvider.getSwapInfo(fromCoin, toCoin, coinAmountForDefaultUsdAmount)).then(function (details) {
11788
- var _coinToCurrentFiatRat, _fiatCurrencyDecimals;
11789
- if (!details) {
11790
- throw new Error("The details are empty: " + safeStringify(details));
11791
- }
11792
- if (!details.result) {
11793
- Logger.log("Failed with reason: " + details.reason + ". " + fromCoin.ticker + "->" + toCoin.ticker, loggerSource);
11794
- if ((details == null ? void 0 : details.reason) === SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED || (details == null ? void 0 : details.reason) === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
11795
- return {
11796
- result: false,
11797
- reason: details.reason
11798
- };
11799
- } else {
11800
- throw new Error("Unhandled error case: " + (details == null ? void 0 : details.reason));
11801
- }
11802
- }
11803
- var fiatMin = null;
11804
- var fiatMax = null;
11805
- var fiatRate = (_coinToCurrentFiatRat = coinToCurrentFiatRate) != null ? _coinToCurrentFiatRat : coinUsdRate == null ? void 0 : coinUsdRate.rate;
11806
- var fiatDecimals = (_fiatCurrencyDecimals = fiatCurrencyDecimals) != null ? _fiatCurrencyDecimals : FiatCurrenciesService.getCurrencyDecimalCountByCode("USD");
11807
- if (fiatRate != null) {
11808
- fiatMin = bignumber_js.BigNumber(details == null ? void 0 : details.smallestMin).times(fiatRate).toFixed(fiatDecimals);
11809
- fiatMax = bignumber_js.BigNumber(details == null ? void 0 : details.greatestMax).times(fiatRate).toFixed(fiatDecimals);
12103
+ if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string" || typeof clientIpAddress != "string" || typeof fixed != "boolean") {
12104
+ throw new Error("Invalid input: " + fromCoin + " " + toCoin + " " + amount + " " + toAddress + " " + refundAddress + " " + fixed);
12105
+ }
12106
+ if (typeof rawSwapData !== "object" || fixed && !rawSwapData.rate_id) {
12107
+ throw new Error("Invalid raw swap data: " + safeStringify(rawSwapData));
12108
+ }
12109
+ return Promise.resolve(_this4._fetchSupportedCurrenciesIfNeeded()).then(function () {
12110
+ var fromCoinDetails = _this4._supportedCoins.find(function (i) {
12111
+ var _i$coin3;
12112
+ return ((_i$coin3 = i.coin) == null ? void 0 : _i$coin3.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
12113
+ });
12114
+ var toCoinDetails = _this4._supportedCoins.find(function (i) {
12115
+ var _i$coin4;
12116
+ return ((_i$coin4 = i.coin) == null ? void 0 : _i$coin4.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
12117
+ });
12118
+ if (!fromCoinDetails || !toCoinDetails) {
12119
+ throw new Error("Failed to find coin details for: " + fromCoin.ticker + " -> " + toCoin.ticker);
12120
+ }
12121
+ var requestBody = {
12122
+ coin_from: fromCoinDetails.code,
12123
+ network_from: fromCoinDetails.network,
12124
+ coin_to: toCoinDetails.code,
12125
+ network_to: toCoinDetails.network,
12126
+ withdrawal: toAddress,
12127
+ withdrawal_extra_id: toCurrencyExtraId,
12128
+ "return": refundAddress,
12129
+ return_extra_id: refundExtraId,
12130
+ affiliate_id: LetsExchangeSwapProvider.AFFILIATE_ID
12131
+ };
12132
+ if (amountIsToReceive) {
12133
+ requestBody.withdrawal_amount = amount;
12134
+ } else {
12135
+ requestBody.deposit_amount = amount;
12136
+ }
12137
+ if (fixed) {
12138
+ requestBody.rate_id = rawSwapData.rate_id;
12139
+ }
12140
+ return Promise.resolve(axios__default["default"].post(_this4._URL + "/v1/transaction" + (amountIsToReceive ? "-revert" : "?float=" + !fixed), requestBody, {
12141
+ headers: _this4._headers
12142
+ })).then(function (response) {
12143
+ var result = response.data;
12144
+ Logger.log("Creation result " + safeStringify(result), loggerSource);
12145
+ if (result != null && result.transaction_id) {
12146
+ var _result$rate, _result$deposit_extra;
12147
+ var rate = bignumber_js.BigNumber((_result$rate = result.rate) != null ? _result$rate : 0).isZero() ? bignumber_js.BigNumber(result.withdrawal_amount).div(result.deposit_amount) : bignumber_js.BigNumber(result.rate);
12148
+ return {
12149
+ result: true,
12150
+ swapId: result.transaction_id,
12151
+ fromCoin: fromCoin,
12152
+ fromAmount: AmountUtils.trim(result.deposit_amount, fromCoin.digits),
12153
+ fromAddress: result.deposit,
12154
+ toCoin: toCoin,
12155
+ toAmount: AmountUtils.trim(result.withdrawal_amount, toCoin.digits),
12156
+ toAddress: result.withdrawal,
12157
+ fromCurrencyExtraId: (_result$deposit_extra = result.deposit_extra_id) != null ? _result$deposit_extra : "",
12158
+ rate: AmountUtils.trim(rate, _this4._maxRateDigits),
12159
+ fixed: !result.is_float
12160
+ };
11810
12161
  }
11811
- var result = {
11812
- result: true,
11813
- min: details == null ? void 0 : details.smallestMin,
11814
- fiatMin: fiatMin,
11815
- max: details == null ? void 0 : details.greatestMax,
11816
- fiatMax: fiatMax,
11817
- rate: AmountUtils.trim(details.rate, 30)
11818
- };
11819
- Logger.log("Returning: " + safeStringify(result), loggerSource);
11820
- return result;
12162
+ var errorMessage = "Swap creation succeeded but the response is wrong: " + safeStringify(response);
12163
+ Logger.log(errorMessage, loggerSource);
12164
+ throw new Error(errorMessage);
11821
12165
  });
11822
12166
  });
11823
12167
  }, function (e) {
11824
- Logger.logError(e, loggerSource, "Failed to init swap: " + safeStringify(e));
12168
+ var _e$response3, _e$response4;
12169
+ Logger.logError(e, loggerSource, "Failed to create swap. Error is: " + safeStringify(e));
12170
+ var composeFailResult = function composeFailResult(reason) {
12171
+ return {
12172
+ result: false,
12173
+ reason: reason
12174
+ };
12175
+ };
12176
+ var status = e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status;
12177
+ var data = e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.data;
12178
+ if (status === 429) {
12179
+ Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
12180
+ return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
12181
+ }
12182
+ // TODO: [feature, low] add custom errors handling - waiting for response from letsexchange. task_id=00d2e435f6df4fb99af912135bd9ee27
12183
+ // 422 - missing params
12184
+ Logger.log("Internal error for swap: " + safeStringify(e), loggerSource);
11825
12185
  improveAndRethrow(e, loggerSource);
11826
12186
  }));
11827
12187
  } catch (e) {
11828
12188
  return Promise.reject(e);
11829
12189
  }
11830
12190
  };
11831
- SwapUtils.safeHandleRequestsLimitExceeding = function safeHandleRequestsLimitExceeding() {
11832
- (function () {
11833
- try {
11834
- var _temp = _catch$2(function () {
11835
- return Promise.resolve(EmailsApi.sendEmail("AUTOMATIC EMAIL - SWAPSPACE REQUESTS LIMIT EXCEEDED", "Requests limit exceeded. Urgently ask swaps provider support for limit increasing")).then(function () {});
11836
- }, function (e) {
11837
- Logger.log("Failed to handle limit exceeding " + safeStringify(e), "_safeHandleRequestsLimitExceeding");
11838
- });
11839
- return _temp && _temp.then ? _temp.then(function () {}) : void 0;
11840
- } catch (e) {
11841
- Promise.reject(e);
11842
- }
11843
- })();
11844
- }
11845
-
11846
- /**
11847
- * If some swap is not found by id then there is no item in return list.
11848
- *
11849
- * @param swapProviders {SwapProvider[]} - Array of swap providers
11850
- * @param swapIds {string[]} - Array of swap IDs
11851
- * @return {Promise<{
11852
- * result: true,
11853
- * swaps: ExistingSwapWithFiatData[]
11854
- * }|{
11855
- * result: false,
11856
- * reason: string
11857
- * }>}
11858
- */;
11859
- SwapUtils.getExistingSwapsDetailsWithFiatAmounts = function getExistingSwapsDetailsWithFiatAmounts(swapProviders, swapIds) {
12191
+ _proto.getExistingSwapsDetailsAndStatus = function getExistingSwapsDetailsAndStatus(swapIds) {
11860
12192
  try {
12193
+ var _this5 = this;
12194
+ var loggerSource = "getExistingSwapsDetailsAndStatus";
11861
12195
  return Promise.resolve(_catch$2(function () {
11862
- var _interrupt;
11863
- function _temp8() {
11864
- if (swapIds.length > 0 && allSwaps.length === 0 && failResults.length > 0) {
11865
- var failReasons = failResults.map(function (r) {
11866
- return r.reason;
11867
- });
11868
- return {
11869
- result: false,
11870
- reason: failReasons.find(function (r) {
11871
- return r !== SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED;
11872
- }) ? failReasons.join("\n") : SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
12196
+ if (swapIds.find(function (id) {
12197
+ return typeof id !== "string";
12198
+ })) {
12199
+ throw new Error("Swap id is not string: " + safeStringify(swapIds));
12200
+ }
12201
+ return Promise.resolve(axios__default["default"].get(_this5._URL + "/v1/transactions-list?ids[]=" + swapIds.join("&ids[]="), {
12202
+ headers: _this5._headers
12203
+ })).then(function (response) {
12204
+ Logger.log("All swaps RAW: " + safeStringify(response.data), loggerSource);
12205
+ var swaps = response.data.map(function (swap, index) {
12206
+ var _this5$_supportedCoin, _this5$_supportedCoin2, _swap$deposit_extra_i, _swap$withdrawal_extr, _swap$return_extra_id;
12207
+ var fromCoin = (_this5$_supportedCoin = _this5._supportedCoins.find(function (i) {
12208
+ return i.code === swap.coin_from && i.network === swap.coin_from_network;
12209
+ })) == null ? void 0 : _this5$_supportedCoin.coin;
12210
+ var toCoin = (_this5$_supportedCoin2 = _this5._supportedCoins.find(function (i) {
12211
+ return i.code === swap.coin_to && i.network === swap.coin_to_network;
12212
+ })) == null ? void 0 : _this5$_supportedCoin2.coin;
12213
+ if (!fromCoin || !toCoin) {
12214
+ return []; // We skip swaps with not supported coins for now
12215
+ }
12216
+ var toUtcTimestamp = function toUtcTimestamp(timeStr) {
12217
+ return Date.parse(timeStr.match(/.+[Zz]$/) ? timeStr : timeStr + "Z");
11873
12218
  };
11874
- }
12219
+ var expiresAt = swap.expired_at ? swap.expired_at * 1000 : null;
12220
+ var createdAt = swap.created_at ? toUtcTimestamp("" + swap.created_at) : null;
12221
+ var isExpiredByTime = expiresAt && expiresAt < Date.now();
12222
+ var status = _this5._mapLetsExchangeStatusToRabbitStatus(swap.status, isExpiredByTime);
12223
+ var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
12224
+ var deposit = swap.real_deposit_amount && swap.real_deposit_amount !== "" ? swap.real_deposit_amount : swap.deposit_amount;
12225
+ var withdrawal = swap.real_withdrawal_amount && swap.real_withdrawal_amount !== "" ? swap.real_withdrawal_amount : swap.withdrawal_amount;
12226
+ var rate = bignumber_js.BigNumber(withdrawal).div(deposit).toFixed(_this5._maxRateDigits); // We don't use their rate as it excludes their fee
12227
+ return new ExistingSwap(swapIds[index], status, createdAt, expiresAt, swap.confirmations, rate, swap.is_float != null ? !swap.is_float : false, swap["return"], swap.deposit, fromCoin, AmountUtils.trim(deposit, fromCoin.digits), swap.hash_in, swap.hash_in ? "" + swap.coin_from_explorer_url + swap.hash_in : null, toCoin, AmountUtils.trim(withdrawal, toDigits), swap.hash_out, swap.hash_out ? "" + swap.coin_to_explorer_url + swap.hash_out : null, swap.withdrawal, "letsexchange", (_swap$deposit_extra_i = swap.deposit_extra_id) != null ? _swap$deposit_extra_i : null, (_swap$withdrawal_extr = swap.withdrawal_extra_id) != null ? _swap$withdrawal_extr : null, (_swap$return_extra_id = swap.return_extra_id) != null ? _swap$return_extra_id : null);
12228
+ }).flat();
12229
+ Logger.log("Swap details result " + safeStringify(swaps), loggerSource);
11875
12230
  return {
11876
12231
  result: true,
11877
- swaps: allSwaps
12232
+ swaps: swaps
12233
+ };
12234
+ });
12235
+ }, function (e) {
12236
+ var _e$response5, _e$response6;
12237
+ Logger.logError(e, loggerSource, "Failed to get swap details. Error is: " + safeStringify(e));
12238
+ var composeFailResult = function composeFailResult(reason) {
12239
+ return {
12240
+ result: false,
12241
+ reason: reason
11878
12242
  };
12243
+ };
12244
+ var status = e == null || (_e$response5 = e.response) == null ? void 0 : _e$response5.status;
12245
+ var data = e == null || (_e$response6 = e.response) == null ? void 0 : _e$response6.data;
12246
+ if (status === 429) {
12247
+ Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
12248
+ return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
11879
12249
  }
11880
- var allSwaps = [];
11881
- var remainingSwapIds = new Set(swapIds);
11882
- var failResults = [];
11883
- var _temp7 = _forOf(swapProviders, function (provider) {
11884
- return Promise.resolve(provider.getExistingSwapsDetailsAndStatus([].concat(remainingSwapIds))).then(function (result) {
11885
- var _temp6 = function () {
11886
- if (result.result) {
11887
- var _temp5 = function _temp5() {
11888
- allSwaps = allSwaps.concat(_extendedSwaps);
11889
-
11890
- // Stop if we have retrieved all swaps
11891
- if (allSwaps.length >= swapIds.length) {
11892
- _interrupt = 1;
11893
- }
11894
- };
11895
- var _extendedSwaps = [];
11896
- var _temp4 = _forOf(result.swaps, function (swap) {
11897
- function _temp3() {
11898
- remainingSwapIds["delete"](swap.id);
11899
- }
11900
- var _temp2 = function () {
11901
- if (swap.status === SwapProvider.SWAP_STATUSES.REFUNDED) {
11902
- return Promise.resolve(provider.getCoinToUSDTRate(swap.fromCoin)).then(function (rate) {
11903
- _extendedSwaps.push(ExistingSwapWithFiatData.fromExistingSwap(swap, (rate == null ? void 0 : rate.rate) != null ? bignumber_js.BigNumber(swap.fromAmount).times(rate.rate).toNumber() : null, (rate == null ? void 0 : rate.rate) != null ? bignumber_js.BigNumber(swap.toAmount).times(rate.rate).toNumber() : null, "USD", FiatCurrenciesService.getCurrencyDecimalCountByCode("USD")));
11904
- });
11905
- } else {
11906
- return Promise.resolve(Promise.all([provider.getCoinToUSDTRate(swap.fromCoin), provider.getCoinToUSDTRate(swap.toCoin)])).then(function (_ref) {
11907
- var fromCoinFiatRate = _ref[0],
11908
- toCoinFiatRate = _ref[1];
11909
- _extendedSwaps.push(ExistingSwapWithFiatData.fromExistingSwap(swap, (fromCoinFiatRate == null ? void 0 : fromCoinFiatRate.rate) != null ? bignumber_js.BigNumber(swap.fromAmount).times(fromCoinFiatRate.rate).toNumber() : null, (toCoinFiatRate == null ? void 0 : toCoinFiatRate.rate) != null ? bignumber_js.BigNumber(swap.toAmount).times(toCoinFiatRate.rate).toNumber() : null, "USD", FiatCurrenciesService.getCurrencyDecimalCountByCode("USD")));
11910
- });
11911
- }
11912
- }();
11913
- return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2);
11914
- });
11915
- return _temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4);
11916
- } else {
11917
- failResults.push(result);
11918
- }
11919
- }();
11920
- if (_temp6 && _temp6.then) return _temp6.then(function () {});
11921
- });
11922
- }, function () {
11923
- return _interrupt;
11924
- });
11925
- return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7);
11926
- }, function (e) {
11927
- improveAndRethrow(e, "getExistingSwapsDetailsWithFiatAmounts");
12250
+ improveAndRethrow(e, loggerSource);
11928
12251
  }));
11929
12252
  } catch (e) {
11930
12253
  return Promise.reject(e);
11931
12254
  }
11932
12255
  };
11933
- return SwapUtils;
11934
- }();
12256
+ _proto._mapLetsExchangeStatusToRabbitStatus = function _mapLetsExchangeStatusToRabbitStatus(status, isExpiredByTime) {
12257
+ /**
12258
+ * Lets exchange statuses description
12259
+ * wait - The exchange has just been created and it’s waiting for coins to reach the deposit wallet
12260
+ * confirmation - The transaction appears in mempool and now it is waiting for necessary network confirmations to start.
12261
+ * confirmed - The user’s payment is confirmed, the exchange process is about to start.
12262
+ * exchanging - The exchange process is running.
12263
+ * sending - Funds are being sent to the recipient`s address.
12264
+ * sending_confirmation - The outgoing transaction is waiting for network confirmations.
12265
+ * success - The exchange is completed and the funds are successfully sent to the recipient’s address.
12266
+ * aml_check_failed - The deposit was marked as risky by AML check service.
12267
+ * overdue - The deposit receiving time for this transaction has expired.
12268
+ * error - The transaction has failed. In most cases, the amount that was sent differs from the amount that was specified when creating the transaction.
12269
+ * refund - The exchange failed and the coins were refunded to the user's wallet.
12270
+ */
12271
+ switch (status) {
12272
+ case "wait":
12273
+ if (isExpiredByTime) {
12274
+ return SwapProvider.SWAP_STATUSES.EXPIRED;
12275
+ }
12276
+ return SwapProvider.SWAP_STATUSES.WAITING_FOR_PAYMENT;
12277
+ case "confirmation":
12278
+ return SwapProvider.SWAP_STATUSES.CONFIRMING;
12279
+ case "confirmed":
12280
+ return SwapProvider.SWAP_STATUSES.PAYMENT_RECEIVED;
12281
+ case "exchanging":
12282
+ return SwapProvider.SWAP_STATUSES.EXCHANGING;
12283
+ case "sending":
12284
+ return SwapProvider.SWAP_STATUSES.EXCHANGING;
12285
+ case "sending_confirmation":
12286
+ return SwapProvider.SWAP_STATUSES.EXCHANGING;
12287
+ case "success":
12288
+ return SwapProvider.SWAP_STATUSES.COMPLETED;
12289
+ case "refund":
12290
+ return SwapProvider.SWAP_STATUSES.REFUNDED;
12291
+ case "overdue":
12292
+ return SwapProvider.SWAP_STATUSES.EXPIRED;
12293
+ case "aml_check_failed":
12294
+ return SwapProvider.SWAP_STATUSES.EXCHANGING;
12295
+ case "error":
12296
+ return SwapProvider.SWAP_STATUSES.FAILED;
12297
+ default:
12298
+ throw new Error("Unknown LetsExchange status: " + status);
12299
+ }
12300
+ };
12301
+ _proto.getPartnersList = function getPartnersList() {
12302
+ try {
12303
+ return Promise.resolve([new Partner("letsexchange", "LetsExchange", "https://letsexchange.notion.site/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F02e45813-b375-49d8-b2b0-092ce1847fff%2F55ebbc3c-4ee6-4fa7-847b-f673e82594f3%2Flets-logo-basic__on-light.svg?table=block&id=bec5952a-2f9c-47fb-8cc0-86e1391a7f60&spaceId=02e45813-b375-49d8-b2b0-092ce1847fff&userId=&cache=v2", null)]);
12304
+ } catch (e) {
12305
+ return Promise.reject(e);
12306
+ }
12307
+ };
12308
+ return LetsExchangeSwapProvider;
12309
+ }(SwapProvider);
12310
+ LetsExchangeSwapProvider.AFFILIATE_ID = "0zbj9hf7xg7jgdgv";
11935
12311
 
11936
12312
  function _catch$1(body, recover) {
11937
12313
  try {
@@ -11944,422 +12320,354 @@ function _catch$1(body, recover) {
11944
12320
  }
11945
12321
  return result;
11946
12322
  }
11947
- var LetsExchangeSwapProvider = /*#__PURE__*/function (_SwapProvider) {
11948
- _inheritsLoose(LetsExchangeSwapProvider, _SwapProvider);
11949
- function LetsExchangeSwapProvider(apiKeysProxyUrl, cache, customCoinBuilder, useRestrictedCoinsSet) {
11950
- var _this;
11951
- if (customCoinBuilder === void 0) {
11952
- customCoinBuilder = function customCoinBuilder(coin, network) {
11953
- return null;
11954
- };
12323
+ var _iteratorSymbol = typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator";
12324
+ function _settle(pact, state, value) {
12325
+ if (!pact.s) {
12326
+ if (value instanceof _Pact) {
12327
+ if (value.s) {
12328
+ if (state & 1) {
12329
+ state = value.s;
12330
+ }
12331
+ value = value.v;
12332
+ } else {
12333
+ value.o = _settle.bind(null, pact, state);
12334
+ return;
12335
+ }
11955
12336
  }
11956
- if (useRestrictedCoinsSet === void 0) {
11957
- useRestrictedCoinsSet = true;
12337
+ if (value && value.then) {
12338
+ value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
12339
+ return;
12340
+ }
12341
+ pact.s = state;
12342
+ pact.v = value;
12343
+ var observer = pact.o;
12344
+ if (observer) {
12345
+ observer(pact);
11958
12346
  }
11959
- _this = _SwapProvider.call(this, cache, customCoinBuilder, useRestrictedCoinsSet) || this;
11960
- _this._partners = [];
11961
- _this._URL = apiKeysProxyUrl + "/letsexchange";
11962
- _this.isAggregator = false;
11963
- _this.COINS_EXPIRATION_TIME_MS = 5 * 60 * 1000;
11964
- _this.coinsLastUpdateTimestamp = null;
11965
- return _this;
11966
12347
  }
11967
- var _proto = LetsExchangeSwapProvider.prototype;
11968
- _proto.getSwapCreationInfoTtlMs = function getSwapCreationInfoTtlMs() {
11969
- return 110000;
12348
+ }
12349
+ var _Pact = /*#__PURE__*/function () {
12350
+ function _Pact() {}
12351
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
12352
+ var result = new _Pact();
12353
+ var state = this.s;
12354
+ if (state) {
12355
+ var callback = state & 1 ? onFulfilled : onRejected;
12356
+ if (callback) {
12357
+ try {
12358
+ _settle(result, 1, callback(this.v));
12359
+ } catch (e) {
12360
+ _settle(result, 2, e);
12361
+ }
12362
+ return result;
12363
+ } else {
12364
+ return this;
12365
+ }
12366
+ }
12367
+ this.o = function (_this) {
12368
+ try {
12369
+ var value = _this.v;
12370
+ if (_this.s & 1) {
12371
+ _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
12372
+ } else if (onRejected) {
12373
+ _settle(result, 1, onRejected(value));
12374
+ } else {
12375
+ _settle(result, 2, value);
12376
+ }
12377
+ } catch (e) {
12378
+ _settle(result, 2, e);
12379
+ }
12380
+ };
12381
+ return result;
11970
12382
  };
11971
- _proto._fetchSupportedCurrenciesIfNeeded = function _fetchSupportedCurrenciesIfNeeded() {
12383
+ return _Pact;
12384
+ }();
12385
+ function _isSettledPact(thenable) {
12386
+ return thenable instanceof _Pact && thenable.s & 1;
12387
+ }
12388
+ function _forTo(array, body, check) {
12389
+ var i = -1,
12390
+ pact,
12391
+ reject;
12392
+ function _cycle(result) {
11972
12393
  try {
11973
- var _this2 = this;
11974
- var loggerSource = "_fetchSupportedCurrenciesIfNeeded";
11975
- return Promise.resolve(_catch$1(function () {
11976
- var _temp = function (_this2$_supportedCoin) {
11977
- if (!((_this2$_supportedCoin = _this2._supportedCoins) != null && _this2$_supportedCoin.length) || !_this2.coinsLastUpdateTimestamp || _this2.coinsLastUpdateTimestamp + _this2.COINS_EXPIRATION_TIME_MS < Date.now()) {
11978
- return Promise.resolve(axios__default["default"].get(_this2._URL + "/v2/coins")).then(function (rawResponse) {
11979
- var _rawResponse$data, _rawResponse$data2;
11980
- Logger.log("Retrieved " + (rawResponse == null || (_rawResponse$data = rawResponse.data) == null ? void 0 : _rawResponse$data.length), loggerSource);
11981
- var allowedCoins = (_rawResponse$data2 = rawResponse == null ? void 0 : rawResponse.data) != null ? _rawResponse$data2 : [];
11982
- Logger.log("Allowed cnt " + allowedCoins.length, loggerSource);
11983
- _this2._supportedCoins = allowedCoins.map(function (item) {
11984
- var code = item.code.toUpperCase();
11985
- if (!Array.isArray(item.networks)) return [];
11986
- return item.networks.map(function (networkDetails) {
11987
- var network = networkDetails.code.toUpperCase();
11988
- var coin = _this2._customCoinBuilder(code, network);
11989
- if (!coin && !_this2.useRestrictedCoinsSet) {
11990
- var name = _this2.removeProtocolNameFromCoinName(item.name, code, network);
11991
- var ticker = "" + code + (code === network ? "" : network);
11992
- var defaultDecimalPlacesForCoinNotSupportedOOB = DEFAULT_CRYPTO_DECIMAL_COUNT;
11993
- var defaultMinConfirmationsForCoinNotSupportedOOB = 1;
11994
- coin = new Coin(name, ticker, code, defaultDecimalPlacesForCoinNotSupportedOOB, null, "", null, null, defaultMinConfirmationsForCoinNotSupportedOOB, null, [], 60000, null, code !== network ? new Protocol(network) : null, item.contract_address || null, false);
11995
- }
11996
- if (coin) {
11997
- var _networkDetails$extra, _networkDetails$valid;
11998
- return new SwapProviderCoinInfo(coin, item.code, networkDetails.code, !!networkDetails.has_extra, (_networkDetails$extra = networkDetails.extra_name) != null ? _networkDetails$extra : null, item.rating || 0, item.icon ? item.icon : FALLBACK_ASSET_ICON_URL, true,
11999
- // Letsexchange provide no such details
12000
- true, // Letsexchange provide no such details
12001
- (_networkDetails$valid = networkDetails.validation_address_regex) != null ? _networkDetails$valid : null, (typeof item.is_active !== "number" || item.is_active === 1) && (typeof item.disabled !== "number" || item.disabled === 0) && (typeof networkDetails.is_active !== "number" || networkDetails.is_active === 1));
12002
- }
12003
- return [];
12004
- });
12005
- }).flat();
12006
- _this2.coinsLastUpdateTimestamp = Date.now();
12007
- _this2._putPopularCoinsFirst();
12008
- return Promise.resolve(_SwapProvider.prototype._fetchSupportedCurrenciesIfNeeded.call(_this2)).then(function () {});
12009
- });
12394
+ while (++i < array.length && (!check || !check())) {
12395
+ result = body(i);
12396
+ if (result && result.then) {
12397
+ if (_isSettledPact(result)) {
12398
+ result = result.v;
12399
+ } else {
12400
+ result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
12401
+ return;
12010
12402
  }
12011
- }();
12012
- if (_temp && _temp.then) return _temp.then(function () {});
12013
- }, function (e) {
12014
- improveAndRethrow(e, loggerSource);
12015
- }));
12403
+ }
12404
+ }
12405
+ if (pact) {
12406
+ _settle(pact, 1, result);
12407
+ } else {
12408
+ pact = result;
12409
+ }
12016
12410
  } catch (e) {
12017
- return Promise.reject(e);
12018
- }
12019
- };
12020
- _proto.getSwapInfo = function getSwapInfo(fromCoin, toCoin, amountCoins, fixed, fromCoinToUsdRate, amountIsToReceive) {
12021
- if (fixed === void 0) {
12022
- fixed = false;
12023
- }
12024
- if (amountIsToReceive === void 0) {
12025
- amountIsToReceive = false;
12411
+ _settle(pact || (pact = new _Pact()), 2, e);
12026
12412
  }
12027
- try {
12028
- var _this3 = this;
12029
- var loggerSource = "getSwapInfo";
12030
- var min = null;
12031
- var max = null;
12032
- return Promise.resolve(_catch$1(function () {
12033
- if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amountCoins !== "string" || bignumber_js.BigNumber(amountCoins).lt("0") || fixed !== null && typeof fixed !== "boolean" || amountIsToReceive && !fixed) {
12034
- throw new Error("Wrong input params: " + amountCoins + " " + fromCoin.ticker + " -> " + toCoin.ticker + ", " + (fromCoin instanceof Coin) + ", " + (toCoin instanceof Coin) + ", " + typeof fixed + " " + fixed + ", " + amountIsToReceive);
12035
- }
12036
- var fromCoinDetails = _this3._supportedCoins.find(function (i) {
12037
- var _i$coin;
12038
- return ((_i$coin = i.coin) == null ? void 0 : _i$coin.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
12039
- });
12040
- var toCoinDetails = _this3._supportedCoins.find(function (i) {
12041
- var _i$coin2;
12042
- return ((_i$coin2 = i.coin) == null ? void 0 : _i$coin2.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
12043
- });
12044
- if (!fromCoinDetails || !toCoinDetails || !fromCoinDetails.deposit || !fromCoinDetails.isAvailable || !toCoinDetails.withdrawal || !toCoinDetails.isAvailable) {
12045
- return {
12046
- result: false,
12047
- reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
12048
- };
12049
- }
12050
- var pathAndQuery = "/v1/info" + (amountIsToReceive ? "-revert" : "?float=" + !fixed);
12051
- return Promise.resolve(axios__default["default"].post("" + _this3._URL + pathAndQuery, {
12052
- from: fromCoinDetails.code,
12053
- to: toCoinDetails.code,
12054
- network_from: fromCoinDetails.network,
12055
- network_to: toCoinDetails.network,
12056
- amount: amountCoins,
12057
- affiliate_id: LetsExchangeSwapProvider.AFFILIATE_ID
12058
- })).then(function (response) {
12059
- Logger.log("Retrieved " + (response == null ? void 0 : response.data), loggerSource);
12060
- var data = response.data;
12061
-
12062
- // TODO: [dev] add SwapProvider.NO_SWAPS_REASONS.NO_FIXED_BUT_HAVE_FLOATING - request alternative rate. task_id=
12063
-
12064
- // TODO: [feature, low] implement extra coins to fit min/max if there are frequent errors due to min/max exceeding
12065
- // let extraCoinsToFitMinMax = "0";
12066
- // if (typeof fromCoinToUsdRate === "string" && BigNumber(fromCoinToUsdRate).gt("0")) {
12067
- // const extraUsdToFitMinMax = BigNumber("1"); // We correct the limits as the exact limit can fluctuate and cause failed swap creation
12068
- // extraCoinsToFitMinMax = AmountUtils.trim(extraUsdToFitMinMax.div(fromCoinToUsdRate), fromCoin.digits);
12069
- // }
12070
- if (data != null && data.min_amount) {
12071
- min = AmountUtils.trim(data == null ? void 0 : data.min_amount, amountIsToReceive ? toCoin.digits : fromCoin.digits);
12072
- }
12073
- if (data != null && data.max_amount) {
12074
- max = AmountUtils.trim(data == null ? void 0 : data.max_amount, amountIsToReceive ? toCoin.digits : fromCoin.digits);
12075
- }
12076
- if (data.success === false && data.error) {
12077
- // TODO: [dev] waiting for response from letsexchange about their not-documented responses
12078
- // {
12079
- // "success": false,
12080
- // "error": "Internal error"
12081
- // }
12082
- throw new Error("Failed to estimate swap letsexchange");
12083
- }
12084
- if (bignumber_js.BigNumber(data.rate).eq("0") || bignumber_js.BigNumber(data.amount).eq("0")) {
12085
- // TODO actualize according to letsexchage clarification - decide, can we count on min/max abcense? task_id=76512110797f4eab8b37f1bb789825cb
12086
- // amount: "0", rate: "0", rate_id: ""
12087
- var reason = SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED;
12088
- if (min && bignumber_js.BigNumber(amountCoins).lt(min)) {
12089
- reason = SwapProvider.NO_SWAPS_REASONS.TOO_LOW;
12090
- } else if (max && bignumber_js.BigNumber(amountCoins).gt(max)) {
12091
- reason = SwapProvider.NO_SWAPS_REASONS.TOO_HIGH;
12092
- } else if (!amountIsToReceive) {
12093
- // If we are not requesting receiving amount (it cannot be floating-rate)
12094
- // todo [feature, moderate] request alternative rate. task_id=31884db5392f49738c20a86115c90e1f
12095
- // const alternativeRate = 1;
12096
- // const alternativeRateAvailable = alternativeRate;
12097
- // if (alternativeRateAvailable) {
12098
- // reason = fixed
12099
- // ? SwapProvider.NO_SWAPS_REASONS.NO_FIXED_BUT_HAVE_FLOATING
12100
- // : SwapProvider.NO_SWAPS_REASONS.NO_FLOATING_BUT_HAVE_FIXED;
12101
- // }
12413
+ }
12414
+ _cycle();
12415
+ return pact;
12416
+ }
12417
+ function _forOf(target, body, check) {
12418
+ if (typeof target[_iteratorSymbol] === "function") {
12419
+ var _cycle = function _cycle(result) {
12420
+ try {
12421
+ while (!(step = iterator.next()).done && (!check || !check())) {
12422
+ result = body(step.value);
12423
+ if (result && result.then) {
12424
+ if (_isSettledPact(result)) {
12425
+ result = result.v;
12426
+ } else {
12427
+ result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
12428
+ return;
12102
12429
  }
12103
- return {
12104
- result: false,
12105
- reason: reason,
12106
- smallestMin: min,
12107
- greatestMax: max
12108
- };
12109
12430
  }
12110
- var rate = amountIsToReceive ? bignumber_js.BigNumber(amountCoins).div(data.amount) : bignumber_js.BigNumber(data.amount).div(amountCoins);
12111
- return {
12112
- result: true,
12113
- min: min,
12114
- max: max,
12115
- smallestMin: min,
12116
- greatestMax: max,
12117
- rate: AmountUtils.trim(rate, _this3._maxRateDigits),
12118
- durationMinutesRange: null,
12119
- fixed: fixed,
12120
- rawSwapData: data,
12121
- isRefundAddressRequired: false
12122
- };
12123
- });
12124
- }, function (e) {
12125
- var _e$response, _e$response2;
12126
- if ((e == null || (_e$response = e.response) == null ? void 0 : _e$response.status) === 404) {
12127
- return {
12128
- result: false,
12129
- reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED,
12130
- smallestMin: min,
12131
- greatestMax: max
12132
- };
12133
12431
  }
12134
- if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
12135
- return {
12136
- result: false,
12137
- reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
12138
- };
12432
+ if (pact) {
12433
+ _settle(pact, 1, result);
12434
+ } else {
12435
+ pact = result;
12139
12436
  }
12140
- Logger.log("Internal error when getting swap options " + safeStringify(e), loggerSource);
12141
- improveAndRethrow(e, loggerSource);
12142
- }));
12143
- } catch (e) {
12144
- return Promise.reject(e);
12145
- }
12146
- };
12147
- _proto.createSwap = function createSwap(fromCoin, toCoin, amount, toAddress, refundAddress, rawSwapData, clientIpAddress, fixed, toCurrencyExtraId, refundExtraId, amountIsToReceive) {
12148
- if (toCurrencyExtraId === void 0) {
12149
- toCurrencyExtraId = "";
12437
+ } catch (e) {
12438
+ _settle(pact || (pact = new _Pact()), 2, e);
12439
+ }
12440
+ };
12441
+ var iterator = target[_iteratorSymbol](),
12442
+ step,
12443
+ pact,
12444
+ reject;
12445
+ _cycle();
12446
+ if (iterator["return"]) {
12447
+ var _fixup = function _fixup(value) {
12448
+ try {
12449
+ if (!step.done) {
12450
+ iterator["return"]();
12451
+ }
12452
+ } catch (e) {}
12453
+ return value;
12454
+ };
12455
+ if (pact && pact.then) {
12456
+ return pact.then(_fixup, function (e) {
12457
+ throw _fixup(e);
12458
+ });
12459
+ }
12460
+ _fixup();
12150
12461
  }
12151
- if (refundExtraId === void 0) {
12152
- refundExtraId = "";
12462
+ return pact;
12463
+ }
12464
+ // No support for Symbol.iterator
12465
+ if (!("length" in target)) {
12466
+ throw new TypeError("Object is not iterable");
12467
+ }
12468
+ // Handle live collections properly
12469
+ var values = [];
12470
+ for (var i = 0; i < target.length; i++) {
12471
+ values.push(target[i]);
12472
+ }
12473
+ return _forTo(values, function (i) {
12474
+ return body(values[i]);
12475
+ }, check);
12476
+ }
12477
+ var SwapUtils = /*#__PURE__*/function () {
12478
+ function SwapUtils() {}
12479
+ /**
12480
+ * Retrieves min and max limits for swapping giving currencies.
12481
+ * Returns also conversion rate if possible with predefined amount logic.
12482
+ * Rate is how many "to" coins does 1 "from" coin contain.
12483
+ *
12484
+ * In case of errors returns one of reasons
12485
+ * - SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
12486
+ * - one of SwapProvider.COMMON_ERRORS.*
12487
+ *
12488
+ * @param swapProvider {SwapProvider}
12489
+ * @param fromCoin {Coin} enabled coin (to swap amount from)
12490
+ * @param toCoin {Coin}
12491
+ * @param coinToCurrentFiatRate {string|null}
12492
+ * @param fiatCurrencyDecimals {number|null}
12493
+ * @return {Promise<{
12494
+ * result: true,
12495
+ * min: string,
12496
+ * fiatMin: (number|null),
12497
+ * max: string,
12498
+ * fiatMax: (number|null),
12499
+ * rate: (string|null),
12500
+ * }|{
12501
+ * result: false,
12502
+ * reason: string
12503
+ * }>}
12504
+ */
12505
+ SwapUtils.getInitialSwapData = function getInitialSwapData(swapProvider, fromCoin, toCoin, coinToCurrentFiatRate, fiatCurrencyDecimals) {
12506
+ if (coinToCurrentFiatRate === void 0) {
12507
+ coinToCurrentFiatRate = null;
12153
12508
  }
12154
- if (amountIsToReceive === void 0) {
12155
- amountIsToReceive = false;
12509
+ if (fiatCurrencyDecimals === void 0) {
12510
+ fiatCurrencyDecimals = null;
12156
12511
  }
12157
12512
  try {
12158
- var _this4 = this;
12159
- var loggerSource = "createSwap";
12513
+ var loggerSource = "getInitialSwapData";
12160
12514
  return Promise.resolve(_catch$1(function () {
12161
- if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string" || typeof clientIpAddress != "string" || typeof fixed != "boolean") {
12162
- throw new Error("Invalid input: " + fromCoin + " " + toCoin + " " + amount + " " + toAddress + " " + refundAddress + " " + fixed);
12163
- }
12164
- if (typeof rawSwapData !== "object" || fixed && !rawSwapData.rate_id) {
12165
- throw new Error("Invalid raw swap data: " + safeStringify(rawSwapData));
12166
- }
12167
- var fromCoinDetails = _this4._supportedCoins.find(function (i) {
12168
- var _i$coin3;
12169
- return ((_i$coin3 = i.coin) == null ? void 0 : _i$coin3.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
12170
- });
12171
- var toCoinDetails = _this4._supportedCoins.find(function (i) {
12172
- var _i$coin4;
12173
- return ((_i$coin4 = i.coin) == null ? void 0 : _i$coin4.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
12174
- });
12175
- if (!fromCoinDetails || !toCoinDetails) {
12176
- throw new Error("Failed to find coin details for: " + fromCoin.ticker + " -> " + toCoin.ticker);
12177
- }
12178
- var requestBody = {
12179
- coin_from: fromCoinDetails.code,
12180
- network_from: fromCoinDetails.network,
12181
- coin_to: toCoinDetails.code,
12182
- network_to: toCoinDetails.network,
12183
- withdrawal: toAddress,
12184
- withdrawal_extra_id: toCurrencyExtraId,
12185
- "return": refundAddress,
12186
- return_extra_id: refundExtraId,
12187
- affiliate_id: LetsExchangeSwapProvider.AFFILIATE_ID
12188
- };
12189
- if (amountIsToReceive) {
12190
- requestBody.withdrawal_amount = amount;
12191
- } else {
12192
- requestBody.deposit_amount = amount;
12193
- }
12194
- if (fixed) {
12195
- requestBody.rate_id = rawSwapData.rate_id;
12196
- }
12197
- return Promise.resolve(axios__default["default"].post(_this4._URL + "/v1/transaction" + (amountIsToReceive ? "-revert" : "?float=" + !fixed), requestBody)).then(function (response) {
12198
- var result = response.data;
12199
- Logger.log("Creation result " + safeStringify(result), loggerSource);
12200
- if (result != null && result.transaction_id) {
12201
- var _result$rate, _result$deposit_extra;
12202
- var rate = bignumber_js.BigNumber((_result$rate = result.rate) != null ? _result$rate : 0).isZero() ? bignumber_js.BigNumber(result.withdrawal_amount).div(result.deposit_amount) : bignumber_js.BigNumber(result.rate);
12203
- return {
12515
+ /* We use some amount here that should fit at least some of the limits of the swap providers.
12516
+ * So we are going to get some rate to be used as the default for the on-flight calculations before we get
12517
+ * the exact rate (that should be retrieved by getSwapCreationInfo method) for a specific amount.
12518
+ */
12519
+ var defaultAmountUsd = bignumber_js.BigNumber("300");
12520
+ return Promise.resolve(swapProvider.getCoinToUSDTRate(fromCoin)).then(function (coinUsdRate) {
12521
+ var coinAmountForDefaultUsdAmount = AmountUtils.trim(coinUsdRate != null && coinUsdRate.result ? defaultAmountUsd.div(coinUsdRate == null ? void 0 : coinUsdRate.rate) : defaultAmountUsd, fromCoin.digits);
12522
+ Logger.log("Init: " + coinAmountForDefaultUsdAmount + " " + fromCoin.ticker + "->" + toCoin.ticker, loggerSource);
12523
+ return Promise.resolve(swapProvider.getSwapInfo(fromCoin, toCoin, coinAmountForDefaultUsdAmount)).then(function (details) {
12524
+ var _coinToCurrentFiatRat, _fiatCurrencyDecimals;
12525
+ if (!details) {
12526
+ throw new Error("The details are empty: " + safeStringify(details));
12527
+ }
12528
+ if (!details.result) {
12529
+ Logger.log("Failed with reason: " + details.reason + ". " + fromCoin.ticker + "->" + toCoin.ticker, loggerSource);
12530
+ if ((details == null ? void 0 : details.reason) === SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED || (details == null ? void 0 : details.reason) === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
12531
+ return {
12532
+ result: false,
12533
+ reason: details.reason
12534
+ };
12535
+ } else {
12536
+ throw new Error("Unhandled error case: " + (details == null ? void 0 : details.reason));
12537
+ }
12538
+ }
12539
+ var fiatMin = null;
12540
+ var fiatMax = null;
12541
+ var fiatRate = (_coinToCurrentFiatRat = coinToCurrentFiatRate) != null ? _coinToCurrentFiatRat : coinUsdRate == null ? void 0 : coinUsdRate.rate;
12542
+ var fiatDecimals = (_fiatCurrencyDecimals = fiatCurrencyDecimals) != null ? _fiatCurrencyDecimals : FiatCurrenciesService.getCurrencyDecimalCountByCode("USD");
12543
+ if (fiatRate != null) {
12544
+ fiatMin = bignumber_js.BigNumber(details == null ? void 0 : details.smallestMin).times(fiatRate).toFixed(fiatDecimals);
12545
+ fiatMax = bignumber_js.BigNumber(details == null ? void 0 : details.greatestMax).times(fiatRate).toFixed(fiatDecimals);
12546
+ }
12547
+ var result = {
12204
12548
  result: true,
12205
- swapId: result.transaction_id,
12206
- fromCoin: fromCoin,
12207
- fromAmount: AmountUtils.trim(result.deposit_amount, fromCoin.digits),
12208
- fromAddress: result.deposit,
12209
- toCoin: toCoin,
12210
- toAmount: AmountUtils.trim(result.withdrawal_amount, toCoin.digits),
12211
- toAddress: result.withdrawal,
12212
- fromCurrencyExtraId: (_result$deposit_extra = result.deposit_extra_id) != null ? _result$deposit_extra : "",
12213
- rate: AmountUtils.trim(rate, _this4._maxRateDigits),
12214
- fixed: !result.is_float
12549
+ min: details == null ? void 0 : details.smallestMin,
12550
+ fiatMin: fiatMin,
12551
+ max: details == null ? void 0 : details.greatestMax,
12552
+ fiatMax: fiatMax,
12553
+ rate: AmountUtils.trim(details.rate, 30)
12215
12554
  };
12216
- }
12217
- var errorMessage = "Swap creation succeeded but the response is wrong: " + safeStringify(response);
12218
- Logger.log(errorMessage, loggerSource);
12219
- throw new Error(errorMessage);
12555
+ Logger.log("Returning: " + safeStringify(result), loggerSource);
12556
+ return result;
12557
+ });
12220
12558
  });
12221
12559
  }, function (e) {
12222
- var _e$response3, _e$response4;
12223
- Logger.logError(e, loggerSource, "Failed to create swap. Error is: " + safeStringify(e));
12224
- var composeFailResult = function composeFailResult(reason) {
12225
- return {
12226
- result: false,
12227
- reason: reason
12228
- };
12229
- };
12230
- var status = e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status;
12231
- var data = e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.data;
12232
- if (status === 429) {
12233
- Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
12234
- return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
12235
- }
12236
- // TODO: [feature, low] add custom errors handling - waiting for response from letsexchange. task_id=00d2e435f6df4fb99af912135bd9ee27
12237
- // 422 - missing params
12238
- Logger.log("Internal error for swap: " + safeStringify(e), loggerSource);
12560
+ Logger.logError(e, loggerSource, "Failed to init swap: " + safeStringify(e));
12239
12561
  improveAndRethrow(e, loggerSource);
12240
12562
  }));
12241
12563
  } catch (e) {
12242
12564
  return Promise.reject(e);
12243
12565
  }
12244
12566
  };
12245
- _proto.getExistingSwapsDetailsAndStatus = function getExistingSwapsDetailsAndStatus(swapIds) {
12567
+ SwapUtils.safeHandleRequestsLimitExceeding = function safeHandleRequestsLimitExceeding() {
12568
+ (function () {
12569
+ try {
12570
+ var _temp = _catch$1(function () {
12571
+ return Promise.resolve(EmailsApi.sendEmail("AUTOMATIC EMAIL - SWAPSPACE REQUESTS LIMIT EXCEEDED", "Requests limit exceeded. Urgently ask swaps provider support for limit increasing")).then(function () {});
12572
+ }, function (e) {
12573
+ Logger.log("Failed to handle limit exceeding " + safeStringify(e), "_safeHandleRequestsLimitExceeding");
12574
+ });
12575
+ return _temp && _temp.then ? _temp.then(function () {}) : void 0;
12576
+ } catch (e) {
12577
+ Promise.reject(e);
12578
+ }
12579
+ })();
12580
+ }
12581
+
12582
+ /**
12583
+ * If some swap is not found by id then there is no item in return list.
12584
+ *
12585
+ * @param swapProviders {SwapProvider[]} - Array of swap providers
12586
+ * @param swapIds {string[]} - Array of swap IDs
12587
+ * @return {Promise<{
12588
+ * result: true,
12589
+ * swaps: ExistingSwapWithFiatData[]
12590
+ * }|{
12591
+ * result: false,
12592
+ * reason: string
12593
+ * }>}
12594
+ */;
12595
+ SwapUtils.getExistingSwapsDetailsWithFiatAmounts = function getExistingSwapsDetailsWithFiatAmounts(swapProviders, swapIds) {
12246
12596
  try {
12247
- var _this5 = this;
12248
- var loggerSource = "getExistingSwapsDetailsAndStatus";
12249
12597
  return Promise.resolve(_catch$1(function () {
12250
- if (swapIds.find(function (id) {
12251
- return typeof id !== "string";
12252
- })) {
12253
- throw new Error("Swap id is not string: " + safeStringify(swapIds));
12254
- }
12255
- return Promise.resolve(axios__default["default"].get(_this5._URL + "/v1/transactions-list?ids[]=" + swapIds.join("&ids[]="))).then(function (response) {
12256
- Logger.log("All swaps RAW: " + safeStringify(response.data), loggerSource);
12257
- var swaps = response.data.map(function (swap, index) {
12258
- var _this5$_supportedCoin, _this5$_supportedCoin2, _swap$deposit_extra_i, _swap$withdrawal_extr, _swap$return_extra_id;
12259
- var fromCoin = (_this5$_supportedCoin = _this5._supportedCoins.find(function (i) {
12260
- return i.code === swap.coin_from && i.network === swap.coin_from_network;
12261
- })) == null ? void 0 : _this5$_supportedCoin.coin;
12262
- var toCoin = (_this5$_supportedCoin2 = _this5._supportedCoins.find(function (i) {
12263
- return i.code === swap.coin_to && i.network === swap.coin_to_network;
12264
- })) == null ? void 0 : _this5$_supportedCoin2.coin;
12265
- if (!fromCoin || !toCoin) {
12266
- return []; // We skip swaps with not supported coins for now
12267
- }
12268
- var toUtcTimestamp = function toUtcTimestamp(timeStr) {
12269
- return Date.parse(timeStr.match(/.+[Zz]$/) ? timeStr : timeStr + "Z");
12598
+ var _interrupt;
12599
+ function _temp8() {
12600
+ if (swapIds.length > 0 && allSwaps.length === 0 && failResults.length > 0) {
12601
+ var failReasons = failResults.map(function (r) {
12602
+ return r.reason;
12603
+ });
12604
+ return {
12605
+ result: false,
12606
+ reason: failReasons.find(function (r) {
12607
+ return r !== SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED;
12608
+ }) ? failReasons.join("\n") : SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
12270
12609
  };
12271
- var expiresAt = swap.expired_at ? swap.expired_at * 1000 : null;
12272
- var createdAt = swap.created_at ? toUtcTimestamp("" + swap.created_at) : null;
12273
- var isExpiredByTime = expiresAt && expiresAt < Date.now();
12274
- var status = _this5._mapLetsExchangeStatusToRabbitStatus(swap.status, isExpiredByTime);
12275
- var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
12276
- var deposit = swap.real_deposit_amount && swap.real_deposit_amount !== "" ? swap.real_deposit_amount : swap.deposit_amount;
12277
- var withdrawal = swap.real_withdrawal_amount && swap.real_withdrawal_amount !== "" ? swap.real_withdrawal_amount : swap.withdrawal_amount;
12278
- var rate = bignumber_js.BigNumber(withdrawal).div(deposit).toFixed(_this5._maxRateDigits); // We don't use their rate as it excludes their fee
12279
- return new ExistingSwap(swapIds[index], status, createdAt, expiresAt, swap.confirmations, rate, swap.is_float != null ? !swap.is_float : false, swap["return"], swap.deposit, fromCoin, AmountUtils.trim(deposit, fromCoin.digits), swap.hash_in, swap.hash_in ? "" + swap.coin_from_explorer_url + swap.hash_in : null, toCoin, AmountUtils.trim(withdrawal, toDigits), swap.hash_out, swap.hash_out ? "" + swap.coin_to_explorer_url + swap.hash_out : null, swap.withdrawal, "letsexchange", (_swap$deposit_extra_i = swap.deposit_extra_id) != null ? _swap$deposit_extra_i : null, (_swap$withdrawal_extr = swap.withdrawal_extra_id) != null ? _swap$withdrawal_extr : null, (_swap$return_extra_id = swap.return_extra_id) != null ? _swap$return_extra_id : null);
12280
- }).flat();
12281
- Logger.log("Swap details result " + safeStringify(swaps), loggerSource);
12610
+ }
12282
12611
  return {
12283
12612
  result: true,
12284
- swaps: swaps
12613
+ swaps: allSwaps
12285
12614
  };
12615
+ }
12616
+ var allSwaps = [];
12617
+ var remainingSwapIds = new Set(swapIds);
12618
+ var failResults = [];
12619
+ var _temp7 = _forOf(swapProviders, function (provider) {
12620
+ return Promise.resolve(provider.getExistingSwapsDetailsAndStatus([].concat(remainingSwapIds))).then(function (result) {
12621
+ var _temp6 = function () {
12622
+ if (result.result) {
12623
+ var _temp5 = function _temp5() {
12624
+ allSwaps = allSwaps.concat(_extendedSwaps);
12625
+
12626
+ // Stop if we have retrieved all swaps
12627
+ if (allSwaps.length >= swapIds.length) {
12628
+ _interrupt = 1;
12629
+ }
12630
+ };
12631
+ var _extendedSwaps = [];
12632
+ var _temp4 = _forOf(result.swaps, function (swap) {
12633
+ function _temp3() {
12634
+ remainingSwapIds["delete"](swap.id);
12635
+ }
12636
+ var _temp2 = function () {
12637
+ if (swap.status === SwapProvider.SWAP_STATUSES.REFUNDED) {
12638
+ return Promise.resolve(provider.getCoinToUSDTRate(swap.fromCoin)).then(function (rate) {
12639
+ _extendedSwaps.push(ExistingSwapWithFiatData.fromExistingSwap(swap, (rate == null ? void 0 : rate.rate) != null ? bignumber_js.BigNumber(swap.fromAmount).times(rate.rate).toNumber() : null, (rate == null ? void 0 : rate.rate) != null ? bignumber_js.BigNumber(swap.toAmount).times(rate.rate).toNumber() : null, "USD", FiatCurrenciesService.getCurrencyDecimalCountByCode("USD")));
12640
+ });
12641
+ } else {
12642
+ return Promise.resolve(Promise.all([provider.getCoinToUSDTRate(swap.fromCoin), provider.getCoinToUSDTRate(swap.toCoin)])).then(function (_ref) {
12643
+ var fromCoinFiatRate = _ref[0],
12644
+ toCoinFiatRate = _ref[1];
12645
+ _extendedSwaps.push(ExistingSwapWithFiatData.fromExistingSwap(swap, (fromCoinFiatRate == null ? void 0 : fromCoinFiatRate.rate) != null ? bignumber_js.BigNumber(swap.fromAmount).times(fromCoinFiatRate.rate).toNumber() : null, (toCoinFiatRate == null ? void 0 : toCoinFiatRate.rate) != null ? bignumber_js.BigNumber(swap.toAmount).times(toCoinFiatRate.rate).toNumber() : null, "USD", FiatCurrenciesService.getCurrencyDecimalCountByCode("USD")));
12646
+ });
12647
+ }
12648
+ }();
12649
+ return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2);
12650
+ });
12651
+ return _temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4);
12652
+ } else {
12653
+ failResults.push(result);
12654
+ }
12655
+ }();
12656
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
12657
+ });
12658
+ }, function () {
12659
+ return _interrupt;
12286
12660
  });
12661
+ return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7);
12287
12662
  }, function (e) {
12288
- var _e$response5, _e$response6;
12289
- Logger.logError(e, loggerSource, "Failed to get swap details. Error is: " + safeStringify(e));
12290
- var composeFailResult = function composeFailResult(reason) {
12291
- return {
12292
- result: false,
12293
- reason: reason
12294
- };
12295
- };
12296
- var status = e == null || (_e$response5 = e.response) == null ? void 0 : _e$response5.status;
12297
- var data = e == null || (_e$response6 = e.response) == null ? void 0 : _e$response6.data;
12298
- if (status === 429) {
12299
- Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
12300
- return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
12301
- }
12302
- improveAndRethrow(e, loggerSource);
12663
+ improveAndRethrow(e, "getExistingSwapsDetailsWithFiatAmounts");
12303
12664
  }));
12304
12665
  } catch (e) {
12305
12666
  return Promise.reject(e);
12306
12667
  }
12307
12668
  };
12308
- _proto._mapLetsExchangeStatusToRabbitStatus = function _mapLetsExchangeStatusToRabbitStatus(status, isExpiredByTime) {
12309
- /**
12310
- * Lets exchange statuses description
12311
- * wait - The exchange has just been created and it’s waiting for coins to reach the deposit wallet
12312
- * confirmation - The transaction appears in mempool and now it is waiting for necessary network confirmations to start.
12313
- * confirmed - The user’s payment is confirmed, the exchange process is about to start.
12314
- * exchanging - The exchange process is running.
12315
- * sending - Funds are being sent to the recipient`s address.
12316
- * sending_confirmation - The outgoing transaction is waiting for network confirmations.
12317
- * success - The exchange is completed and the funds are successfully sent to the recipient’s address.
12318
- * aml_check_failed - The deposit was marked as risky by AML check service.
12319
- * overdue - The deposit receiving time for this transaction has expired.
12320
- * error - The transaction has failed. In most cases, the amount that was sent differs from the amount that was specified when creating the transaction.
12321
- * refund - The exchange failed and the coins were refunded to the user's wallet.
12322
- */
12323
- switch (status) {
12324
- case "wait":
12325
- if (isExpiredByTime) {
12326
- return SwapProvider.SWAP_STATUSES.EXPIRED;
12327
- }
12328
- return SwapProvider.SWAP_STATUSES.WAITING_FOR_PAYMENT;
12329
- case "confirmation":
12330
- return SwapProvider.SWAP_STATUSES.CONFIRMING;
12331
- case "confirmed":
12332
- return SwapProvider.SWAP_STATUSES.PAYMENT_RECEIVED;
12333
- case "exchanging":
12334
- return SwapProvider.SWAP_STATUSES.EXCHANGING;
12335
- case "sending":
12336
- return SwapProvider.SWAP_STATUSES.EXCHANGING;
12337
- case "sending_confirmation":
12338
- return SwapProvider.SWAP_STATUSES.EXCHANGING;
12339
- case "success":
12340
- return SwapProvider.SWAP_STATUSES.COMPLETED;
12341
- case "refund":
12342
- return SwapProvider.SWAP_STATUSES.REFUNDED;
12343
- case "overdue":
12344
- return SwapProvider.SWAP_STATUSES.EXPIRED;
12345
- case "aml_check_failed":
12346
- return SwapProvider.SWAP_STATUSES.EXCHANGING;
12347
- case "error":
12348
- return SwapProvider.SWAP_STATUSES.FAILED;
12349
- default:
12350
- throw new Error("Unknown LetsExchange status: " + status);
12351
- }
12352
- };
12353
- _proto.getPartnersList = function getPartnersList() {
12354
- try {
12355
- return Promise.resolve([new Partner("LetsExchange", "https://letsexchange.notion.site/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F02e45813-b375-49d8-b2b0-092ce1847fff%2F55ebbc3c-4ee6-4fa7-847b-f673e82594f3%2Flets-logo-basic__on-light.svg?table=block&id=bec5952a-2f9c-47fb-8cc0-86e1391a7f60&spaceId=02e45813-b375-49d8-b2b0-092ce1847fff&userId=&cache=v2")]);
12356
- } catch (e) {
12357
- return Promise.reject(e);
12358
- }
12359
- };
12360
- return LetsExchangeSwapProvider;
12361
- }(SwapProvider);
12362
- LetsExchangeSwapProvider.AFFILIATE_ID = "0zbj9hf7xg7jgdgv";
12669
+ return SwapUtils;
12670
+ }();
12363
12671
 
12364
12672
  function _catch(body, recover) {
12365
12673
  try {
@@ -12373,13 +12681,33 @@ function _catch(body, recover) {
12373
12681
  return result;
12374
12682
  }
12375
12683
  var PublicSwapService = /*#__PURE__*/function () {
12376
- function PublicSwapService(apiKeysProxyUrl, cache) {
12377
- this._swapProvider = new SwapspaceSwapProvider(apiKeysProxyUrl, cache, function () {
12378
- return null;
12379
- }, false);
12380
- this._fixedSwapProvider = new LetsExchangeSwapProvider(apiKeysProxyUrl, cache, function () {
12381
- return null;
12382
- }, false);
12684
+ /**
12685
+ * TODO: [feature, critical] implement more adequate providers list&initiation logic. task_id=6a6b0fbbee8a413690c49b1e4ee289cb
12686
+ *
12687
+ * @param apiKeysProxyUrl {string|null}
12688
+ * @param cache {Cache}
12689
+ * @param providers {SwapProvider[]|null}
12690
+ */
12691
+ function PublicSwapService(apiKeysProxyUrl, cache, providers) {
12692
+ var _providers;
12693
+ if (providers === void 0) {
12694
+ providers = null;
12695
+ }
12696
+ if (apiKeysProxyUrl) {
12697
+ this._swapProvider = new SwapspaceSwapProvider(apiKeysProxyUrl, cache, function () {
12698
+ return null;
12699
+ }, false);
12700
+ this._fixedSwapProvider = new LetsExchangeSwapProvider(apiKeysProxyUrl, cache, function () {
12701
+ return null;
12702
+ }, false);
12703
+ } else if ((_providers = providers) != null && _providers.length) {
12704
+ this._swapProvider = providers.find(function (p) {
12705
+ return p.id === "swapspace";
12706
+ });
12707
+ this._fixedSwapProvider = providers.find(function (p) {
12708
+ return p.id === "letsexchange";
12709
+ });
12710
+ }
12383
12711
  }
12384
12712
  var _proto = PublicSwapService.prototype;
12385
12713
  _proto.initialize = function initialize() {
@@ -12558,13 +12886,14 @@ var PublicSwapService = /*#__PURE__*/function () {
12558
12886
  /**
12559
12887
  * Retrieves swap details that can be used to create swap.
12560
12888
  *
12561
- * @param fromCoin {Coin}
12562
- * @param toCoin {Coin}
12889
+ * @param fromCoinOrTicker {Coin|string}
12890
+ * @param toCoinOrTicker {Coin|string}
12563
12891
  * @param amountCoins {string}
12564
12892
  * @param [fixed=false] {boolean|null} null means fixed or float doesn't matter
12565
12893
  * @param [withoutFiat=false] {boolean} pass true if you don't need the fiat equivalent - this will diminish requests count
12566
12894
  * @param [amountIsToReceive=false] {boolean} whether the given amount is receiving amount.
12567
12895
  * False means the amount is the sending amount.
12896
+ * @param bannedPartners {string[]} array of banned swap partners (providers) ids
12568
12897
  * @return {Promise<{
12569
12898
  * result: false,
12570
12899
  * reason: string,
@@ -12579,7 +12908,7 @@ var PublicSwapService = /*#__PURE__*/function () {
12579
12908
  * }>}
12580
12909
  */
12581
12910
  ;
12582
- _proto.getPublicSwapDetails = function getPublicSwapDetails(fromCoin, toCoin, amountCoins, fixed, withoutFiat, amountIsToReceive) {
12911
+ _proto.getPublicSwapDetails = function getPublicSwapDetails(fromCoinOrTicker, toCoinOrTicker, amountCoins, fixed, withoutFiat, amountIsToReceive, bannedPartners) {
12583
12912
  if (fixed === void 0) {
12584
12913
  fixed = false;
12585
12914
  }
@@ -12589,14 +12918,18 @@ var PublicSwapService = /*#__PURE__*/function () {
12589
12918
  if (amountIsToReceive === void 0) {
12590
12919
  amountIsToReceive = false;
12591
12920
  }
12921
+ if (bannedPartners === void 0) {
12922
+ bannedPartners = [];
12923
+ }
12592
12924
  try {
12593
12925
  var _this7 = this;
12594
12926
  var loggerSource = "getPublicSwapDetails";
12595
12927
  return Promise.resolve(_catch(function () {
12596
- function _temp2(_getCoinToUSDTRate) {
12597
- var _getCoinToUSDTRate$ra;
12598
- var coinUsdtRate = withoutFiat ? _getCoinToUSDTRate : (_getCoinToUSDTRate$ra = _getCoinToUSDTRate == null ? void 0 : _getCoinToUSDTRate.rate) != null ? _getCoinToUSDTRate$ra : null;
12599
- return Promise.resolve((fixed ? _this7._fixedSwapProvider : _this7._swapProvider).getSwapInfo(fromCoin, toCoin, amountCoins, fixed, coinUsdtRate, amountIsToReceive)).then(function (details) {
12928
+ function _temp2(_operatingPartner$get) {
12929
+ var _operatingPartner$get2;
12930
+ var coinUsdtRate = withoutFiat ? _operatingPartner$get : (_operatingPartner$get2 = _operatingPartner$get == null ? void 0 : _operatingPartner$get.rate) != null ? _operatingPartner$get2 : null;
12931
+ // TODO: [feature, high] implement base logic for provider selection based on the list of allowed providers - call estimation for all allowed and select the best option. task_id=6a6b0fbbee8a413690c49b1e4ee289cb
12932
+ return Promise.resolve(operatingPartner.getSwapInfo(fromCoin, toCoin, amountCoins, fixed, coinUsdtRate, amountIsToReceive, bannedPartners)).then(function (details) {
12600
12933
  var _result$swapCreationI, _result$swapCreationI2;
12601
12934
  // eslint-disable-next-line no-console
12602
12935
  console.log("getSwapInfo result: ", details);
@@ -12661,7 +12994,27 @@ var PublicSwapService = /*#__PURE__*/function () {
12661
12994
  if (amountIsToReceive && !fixed) {
12662
12995
  throw new Error("Estimating allowed only for fixed rate.");
12663
12996
  }
12664
- return withoutFiat ? _temp2(null) : Promise.resolve((fixed ? _this7._fixedSwapProvider : _this7._swapProvider).getCoinToUSDTRate(amountIsToReceive ? toCoin : fromCoin)).then(_temp2);
12997
+ var fromCoin = fromCoinOrTicker;
12998
+ if (typeof fromCoin === "string") {
12999
+ fromCoin = _this7.getCoinByTickerIfPresent(fromCoin);
13000
+ }
13001
+ var toCoin = toCoinOrTicker;
13002
+ if (typeof toCoin === "string") {
13003
+ toCoin = _this7.getCoinByTickerIfPresent(toCoin);
13004
+ }
13005
+ var operatingPartner = fixed ? _this7._fixedSwapProvider : _this7._swapProvider;
13006
+ var isPartnerBanned = !!bannedPartners.find(function (banned) {
13007
+ return banned === operatingPartner.id;
13008
+ });
13009
+ return !fromCoin || !toCoin || isPartnerBanned ? {
13010
+ result: false,
13011
+ reason: PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED,
13012
+ min: null,
13013
+ max: null,
13014
+ fiatMin: null,
13015
+ fiatMax: null,
13016
+ rate: undefined
13017
+ } : withoutFiat ? _temp2(null) : Promise.resolve(operatingPartner.getCoinToUSDTRate(amountIsToReceive ? toCoin : fromCoin)).then(_temp2);
12665
13018
  }, function (e) {
12666
13019
  improveAndRethrow(e, loggerSource);
12667
13020
  }));
@@ -13061,7 +13414,12 @@ var PublicSwapService = /*#__PURE__*/function () {
13061
13414
  } catch (e) {
13062
13415
  improveAndRethrow(e, "getExtraIdNameIfPresentForAsset");
13063
13416
  }
13064
- };
13417
+ }
13418
+
13419
+ /**
13420
+ * Retrieves flat partners list across all supported providers (including aggregators)
13421
+ * @return {Promise<Partner[]>}
13422
+ */;
13065
13423
  _proto.getPartnersList = function getPartnersList() {
13066
13424
  try {
13067
13425
  var _temp17 = function _temp17(_result15) {
@@ -13077,10 +13435,16 @@ var PublicSwapService = /*#__PURE__*/function () {
13077
13435
  allPartners = _Promise$all;
13078
13436
  allPartners = allPartners.flat().flat();
13079
13437
  var _allPartners$reduce = allPartners.reduce(function (prev, cur) {
13080
- if (!prev.find(function (partner) {
13438
+ var alreadyAdded = prev.find(function (partner) {
13081
13439
  return partner.name.toLowerCase() === cur.name.toLowerCase();
13082
- })) {
13440
+ });
13441
+ if (!alreadyAdded) {
13083
13442
  prev.push(cur);
13443
+ } else {
13444
+ var _cur$logoUrl, _cur$kycLevel;
13445
+ // Attempting to fill missing data if there are the same partner from different providers
13446
+ alreadyAdded.logoUrl = (_cur$logoUrl = cur.logoUrl) != null ? _cur$logoUrl : alreadyAdded.logoUrl;
13447
+ alreadyAdded.kycLevel = (_cur$kycLevel = cur.kycLevel) != null ? _cur$kycLevel : alreadyAdded.kycLevel;
13084
13448
  }
13085
13449
  return prev;
13086
13450
  }, []);
@@ -13154,6 +13518,8 @@ exports.InformationMessage = InformationMessage;
13154
13518
  exports.Input = Input;
13155
13519
  exports.InputValuesProviders = InputValuesProviders;
13156
13520
  exports.IpAddressProvider = IpAddressProvider;
13521
+ exports.KYC_LEVELS = KYC_LEVELS;
13522
+ exports.LetsExchangeSwapProvider = LetsExchangeSwapProvider;
13157
13523
  exports.LineWithIconLink = LineWithIconLink;
13158
13524
  exports.LinesOfText = LinesOfText;
13159
13525
  exports.LinkButton = LinkButton;
@@ -13164,6 +13530,7 @@ exports.LogsStorage = LogsStorage;
13164
13530
  exports.MetrikaAdapter = MetrikaAdapter;
13165
13531
  exports.MixpanelAdapter = MixpanelAdapter;
13166
13532
  exports.NoticeIcon = NoticeIcon;
13533
+ exports.Partner = Partner;
13167
13534
  exports.Protocol = Protocol;
13168
13535
  exports.PublicSwapService = PublicSwapService;
13169
13536
  exports.QrCode = QrCode;
@@ -13173,6 +13540,7 @@ exports.SearchableCoinsList = SearchableCoinsList;
13173
13540
  exports.SupportChat = SupportChat;
13174
13541
  exports.SwapForm = SwapForm;
13175
13542
  exports.SwapProvider = SwapProvider;
13543
+ exports.SwapProviderCoinInfo = SwapProviderCoinInfo;
13176
13544
  exports.SwapUtils = SwapUtils;
13177
13545
  exports.SwapspaceSwapProvider = SwapspaceSwapProvider;
13178
13546
  exports.TOOLTIP_POSITIONS = TOOLTIP_POSITIONS;
@@ -13192,6 +13560,7 @@ exports.postponeExecution = postponeExecution;
13192
13560
  exports.removeQueryParameterAndValues = removeQueryParameterAndValues;
13193
13561
  exports.safeStringify = safeStringify;
13194
13562
  exports.saveQueryParameterAndValues = saveQueryParameterAndValues;
13563
+ exports.toRabbitTicker = toRabbitTicker;
13195
13564
  exports.useCallHandlingErrors = useCallHandlingErrors;
13196
13565
  exports.useIsHydrated = useIsHydrated;
13197
13566
  exports.useReferredState = useReferredState;