@rabbitio/ui-kit 1.0.0-beta.7 → 1.0.0-beta.70
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.
- package/.gitlab-ci.yml +29 -0
- package/.husky/commit-msg +14 -0
- package/.husky/pre-push +1 -0
- package/CHANGELOG.md +0 -0
- package/README.md +27 -18
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +11536 -0
- package/coverage/coverage-final.json +100 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +986 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/rabbit-ui-kit/index.html +116 -0
- package/coverage/rabbit-ui-kit/index.js.html +88 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/arrowIcon.jsx.html +124 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/arrowTosca.jsx.html +127 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/arrowWhite.jsx.html +127 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/darkRectangle.jsx.html +106 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/determinedError.jsx.html +439 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/failedValidationIcon.jsx.html +202 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/index.html +251 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/infoIcon.jsx.html +133 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/noticeQuestionIcon.jsx.html +247 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/successfulValidationIcon.jsx.html +163 -0
- package/coverage/rabbit-ui-kit/src/assets/wrappedImages/walletIcon.jsx.html +151 -0
- package/coverage/rabbit-ui-kit/src/common/adapters/axiosAdapter.js.html +190 -0
- package/coverage/rabbit-ui-kit/src/common/adapters/index.html +131 -0
- package/coverage/rabbit-ui-kit/src/common/adapters/qrUtils.js.html +139 -0
- package/coverage/rabbit-ui-kit/src/common/amountUtils.js.html +1162 -0
- package/coverage/rabbit-ui-kit/src/common/errorUtils.js.html +211 -0
- package/coverage/rabbit-ui-kit/src/common/external-apis/apiGroups.js.html +250 -0
- package/coverage/rabbit-ui-kit/src/common/external-apis/index.html +131 -0
- package/coverage/rabbit-ui-kit/src/common/external-apis/ipAddressProviders.js.html +352 -0
- package/coverage/rabbit-ui-kit/src/common/fiatCurrenciesService.js.html +544 -0
- package/coverage/rabbit-ui-kit/src/common/index.html +146 -0
- package/coverage/rabbit-ui-kit/src/common/models/blockchain.js.html +115 -0
- package/coverage/rabbit-ui-kit/src/common/models/coin.js.html +544 -0
- package/coverage/rabbit-ui-kit/src/common/models/index.html +146 -0
- package/coverage/rabbit-ui-kit/src/common/models/protocol.js.html +100 -0
- package/coverage/rabbit-ui-kit/src/common/utils/cache.js.html +811 -0
- package/coverage/rabbit-ui-kit/src/common/utils/emailAPI.js.html +133 -0
- package/coverage/rabbit-ui-kit/src/common/utils/index.html +161 -0
- package/coverage/rabbit-ui-kit/src/common/utils/logging/index.html +131 -0
- package/coverage/rabbit-ui-kit/src/common/utils/logging/logger.js.html +208 -0
- package/coverage/rabbit-ui-kit/src/common/utils/logging/logsStorage.js.html +268 -0
- package/coverage/rabbit-ui-kit/src/common/utils/postponeExecution.js.html +118 -0
- package/coverage/rabbit-ui-kit/src/common/utils/safeStringify.js.html +235 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/AssetIcon/AssetIcon.jsx.html +247 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/AssetIcon/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/AssetSelection/AssetSelection.jsx.html +286 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/AssetSelection/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/BackgroundTitle/BackgroundTitle.jsx.html +187 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/BackgroundTitle/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/InformationMessage/InformationMessage.jsx.html +235 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/InformationMessage/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/Input/Input.jsx.html +631 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/Input/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/LoadingDots/LoadingDots.jsx.html +196 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/LoadingDots/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/NoticeIcon/NoticeIcon.jsx.html +277 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/NoticeIcon/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/QrCode/QrCode.jsx.html +187 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/QrCode/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/RateSelector/RateSelector.jsx.html +172 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/RateSelector/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/SupportChat/SupportChat.jsx.html +214 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/SupportChat/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/Textarea/Textarea.jsx.html +523 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/Textarea/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/TitleBox/TitleBox.jsx.html +508 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/TitleBox/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/Tooltip/Tooltip.jsx.html +289 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/Tooltip/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/TwoLinesOfText/LinesOfText.jsx.html +307 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/TwoLinesOfText/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/Validation/Validation.jsx.html +208 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/Validation/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/buttons/Button/Button.jsx.html +712 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/buttons/Button/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/buttons/Close/Close.jsx.html +244 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/buttons/Close/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/buttons/LinkButton/LinkButton.jsx.html +403 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/buttons/LinkButton/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/buttons/RadioButtonWithText/RadioButtonWithText.jsx.html +415 -0
- package/coverage/rabbit-ui-kit/src/components/atoms/buttons/RadioButtonWithText/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/hooks/index.html +131 -0
- package/coverage/rabbit-ui-kit/src/components/hooks/useCallHandlingErrors.js.html +151 -0
- package/coverage/rabbit-ui-kit/src/components/hooks/useReferredState.js.html +157 -0
- package/coverage/rabbit-ui-kit/src/components/molecules/AmountInput/AmountInput.jsx.html +997 -0
- package/coverage/rabbit-ui-kit/src/components/molecules/AmountInput/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/molecules/CoinPicker/CoinPicker.jsx.html +1612 -0
- package/coverage/rabbit-ui-kit/src/components/molecules/CoinPicker/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/molecules/LineWithIconLink/LineWithIconLink.jsx.html +190 -0
- package/coverage/rabbit-ui-kit/src/components/molecules/LineWithIconLink/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/molecules/TitledLineWithIconLink/TitledLineWithIconLink.jsx.html +175 -0
- package/coverage/rabbit-ui-kit/src/components/molecules/TitledLineWithIconLink/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/CoinPickerDialogStep/CoinPickerDialogStep.jsx.html +277 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/CoinPickerDialogStep/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/Dialog.jsx.html +1480 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/DialogButtons/DialogButtons.jsx.html +451 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/DialogButtons/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/DialogStep/DialogStep.jsx.html +1684 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/DialogStep/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/SwapForm/SwapForm.jsx.html +3400 -0
- package/coverage/rabbit-ui-kit/src/components/organisms/SwapForm/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/templates/DeterminedErrorDialogStep/DeterminedErrorDialogStep.jsx.html +316 -0
- package/coverage/rabbit-ui-kit/src/components/templates/DeterminedErrorDialogStep/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/components/utils/index.html +161 -0
- package/coverage/rabbit-ui-kit/src/components/utils/inputValueProviders.js.html +235 -0
- package/coverage/rabbit-ui-kit/src/components/utils/textUtils.js.html +139 -0
- package/coverage/rabbit-ui-kit/src/components/utils/uiUtils.js.html +121 -0
- package/coverage/rabbit-ui-kit/src/components/utils/urlQueryUtils.js.html +271 -0
- package/coverage/rabbit-ui-kit/src/constants/atoms/Close/close.jsx.html +100 -0
- package/coverage/rabbit-ui-kit/src/constants/atoms/Close/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/constants/atoms/LinkButton/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/constants/atoms/LinkButton/linkButton.jsx.html +103 -0
- package/coverage/rabbit-ui-kit/src/constants/atoms/Tooltip/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/constants/atoms/Tooltip/tooltip.jsx.html +109 -0
- package/coverage/rabbit-ui-kit/src/constants/globalConstants.jsx.html +94 -0
- package/coverage/rabbit-ui-kit/src/constants/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/constants/organisms/dialog/DialogStep/dialogStep.js.html +88 -0
- package/coverage/rabbit-ui-kit/src/constants/organisms/dialog/DialogStep/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/constants/organisms/dialog/dialog.js.html +172 -0
- package/coverage/rabbit-ui-kit/src/constants/organisms/dialog/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/index.js.html +349 -0
- package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/cacheAndConcurrentRequestsResolver.js.html +1570 -0
- package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/cachedRobustExternalApiCallerService.js.html +526 -0
- package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/cancelProcessing.js.html +172 -0
- package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/concurrentCalculationsMetadataHolder.js.html +310 -0
- package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/externalApiProvider.js.html +553 -0
- package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/externalServicesStatsCollector.js.html +319 -0
- package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/index.html +206 -0
- package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/robustExternalAPICallerService.js.html +997 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/index.html +131 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapProvider.js.html +709 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapspaceSwapProvider.js.html +2197 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/models/baseSwapCreationInfo.js.html +214 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwap.js.html +304 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwapWithFiatData.js.html +469 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/models/index.html +146 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/services/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/services/publicSwapService.js.html +1888 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/utils/index.html +116 -0
- package/coverage/rabbit-ui-kit/src/swaps-lib/utils/swapUtils.js.html +595 -0
- package/coverage/rabbit-ui-kit/stories/atoms/BackgroundTitle.stories.jsx.html +202 -0
- package/coverage/rabbit-ui-kit/stories/atoms/LinesOfText.stories.jsx.html +283 -0
- package/coverage/rabbit-ui-kit/stories/atoms/LoadingDots.stories.jsx.html +226 -0
- package/coverage/rabbit-ui-kit/stories/atoms/QrCode.stories.jsx.html +175 -0
- package/coverage/rabbit-ui-kit/stories/atoms/RateSelector.stories.jsx.html +136 -0
- package/coverage/rabbit-ui-kit/stories/atoms/Validation.stories.jsx.html +178 -0
- package/coverage/rabbit-ui-kit/stories/atoms/buttons/Button.stories.jsx.html +946 -0
- package/coverage/rabbit-ui-kit/stories/atoms/buttons/Close.stories.jsx.html +214 -0
- package/coverage/rabbit-ui-kit/stories/atoms/buttons/LinkButton.stories.jsx.html +295 -0
- package/coverage/rabbit-ui-kit/stories/atoms/buttons/index.html +146 -0
- package/coverage/rabbit-ui-kit/stories/atoms/index.html +191 -0
- package/coverage/rabbit-ui-kit/stories/molecules/LineWithIconLink.stories.jsx.html +154 -0
- package/coverage/rabbit-ui-kit/stories/molecules/TitledLineWithIconLink.stories.jsx.html +160 -0
- package/coverage/rabbit-ui-kit/stories/molecules/index.html +131 -0
- package/coverage/rabbit-ui-kit/stories/organisms/Dialog/Dialog.stories.jsx.html +589 -0
- package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/DialogButtons.stories.jsx.html +328 -0
- package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/index.html +116 -0
- package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/DialogStep.stories.jsx.html +337 -0
- package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/index.html +116 -0
- package/coverage/rabbit-ui-kit/stories/organisms/Dialog/index.html +116 -0
- package/coverage/rabbit-ui-kit/stories/stubs/exampleContent.jsx.html +145 -0
- package/coverage/rabbit-ui-kit/stories/stubs/index.html +116 -0
- package/coverage/rabbit-ui-kit/stories/templates/DeterminedErrorDialogStep.stories.jsx.html +193 -0
- package/coverage/rabbit-ui-kit/stories/templates/index.html +116 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/dist/index.cjs +10019 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +71418 -1641
- package/dist/index.css.map +1 -1
- package/dist/index.modern.js +7716 -11
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +9939 -11
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +10010 -12
- package/dist/index.umd.js.map +1 -1
- package/index.js +1 -1
- package/package.json +29 -5
- package/src/assets/image/icons/arrow-tosca.svg +3 -0
- package/src/assets/wrappedImages/arrowIcon.jsx +13 -0
- package/src/assets/wrappedImages/arrowTosca.jsx +14 -0
- package/src/assets/wrappedImages/arrowWhite.jsx +14 -0
- package/src/assets/wrappedImages/darkRectangle.jsx +7 -0
- package/src/assets/wrappedImages/determinedError.jsx +118 -0
- package/src/assets/wrappedImages/failedValidationIcon.jsx +39 -0
- package/src/assets/wrappedImages/infoIcon.jsx +16 -0
- package/src/assets/wrappedImages/noticeQuestionIcon.jsx +54 -0
- package/src/assets/wrappedImages/successfulValidationIcon.jsx +26 -0
- package/src/assets/wrappedImages/walletIcon.jsx +22 -0
- package/src/common/adapters/axiosAdapter.js +35 -0
- package/src/common/adapters/qrUtils.js +18 -0
- package/src/common/amountUtils.js +359 -0
- package/src/common/errorUtils.js +42 -0
- package/src/common/external-apis/apiGroups.js +55 -0
- package/src/common/external-apis/ipAddressProviders.js +89 -0
- package/src/common/fiatCurrenciesService.js +153 -0
- package/src/common/models/blockchain.js +10 -0
- package/src/common/models/coin.js +153 -0
- package/src/common/models/protocol.js +5 -0
- package/src/common/tests/amountUtils/composeRateText.test.js +152 -0
- package/src/common/tests/integration/external-apis/ipAddressProviders/getClientIpAddress.test.js +12 -0
- package/src/common/utils/cache.js +242 -0
- package/src/common/utils/emailAPI.js +16 -0
- package/src/common/utils/logging/logger.js +41 -0
- package/src/common/utils/logging/logsStorage.js +61 -0
- package/src/common/utils/postponeExecution.js +11 -0
- package/src/common/utils/safeStringify.js +50 -0
- package/src/components/atoms/AssetIcon/AssetIcon.jsx +54 -0
- package/{stories → src/components}/atoms/AssetIcon/asset-icon.module.scss +1 -1
- package/src/components/atoms/AssetSelection/AssetSelection.jsx +67 -0
- package/src/components/atoms/AssetSelection/asset-selection.module.scss +56 -0
- package/src/components/atoms/BackgroundTitle/BackgroundTitle.jsx +34 -0
- package/src/components/atoms/BackgroundTitle/background-title.module.scss +52 -0
- package/src/components/atoms/InformationMessage/InformationMessage.jsx +50 -0
- package/src/components/atoms/InformationMessage/information-message.module.scss +38 -0
- package/src/components/atoms/Input/Input.jsx +182 -0
- package/src/components/atoms/Input/input.module.scss +107 -0
- package/{stories → src/components}/atoms/LoadingDots/LoadingDots.jsx +8 -28
- package/{stories → src/components}/atoms/LoadingDots/LoadingDots.module.scss +1 -1
- package/src/components/atoms/NoticeIcon/NoticeIcon.jsx +64 -0
- package/src/components/atoms/NoticeIcon/notice-icon.module.scss +14 -0
- package/src/components/atoms/QrCode/QrCode.jsx +34 -0
- package/src/components/atoms/QrCode/qr-code.module.scss +15 -0
- package/src/components/atoms/RateSelector/RateSelector.jsx +29 -0
- package/src/components/atoms/RateSelector/rate-selector.module.scss +47 -0
- package/{stories/atoms/SupportChat/SupportChat.js → src/components/atoms/SupportChat/SupportChat.jsx} +4 -1
- package/src/components/atoms/Textarea/Textarea.jsx +146 -0
- package/src/components/atoms/Textarea/textarea.module.scss +71 -0
- package/src/components/atoms/TitleBox/TitleBox.jsx +141 -0
- package/src/components/atoms/TitleBox/title-box.module.scss +32 -0
- package/src/components/atoms/Tooltip/Tooltip.jsx +68 -0
- package/src/components/atoms/Tooltip/tooltip.module.scss +237 -0
- package/src/components/atoms/TwoLinesOfText/LinesOfText.jsx +74 -0
- package/src/components/atoms/TwoLinesOfText/lines-of-text.module.scss +65 -0
- package/src/components/atoms/Validation/Validation.jsx +41 -0
- package/src/components/atoms/Validation/validation.module.scss +15 -0
- package/{stories → src/components}/atoms/buttons/Button/Button.jsx +22 -48
- package/{stories → src/components}/atoms/buttons/Button/Button.module.scss +1 -1
- package/src/components/atoms/buttons/Close/Close.jsx +53 -0
- package/src/components/atoms/buttons/Close/close.module.scss +75 -0
- package/src/components/atoms/buttons/LinkButton/LinkButton.jsx +106 -0
- package/src/components/atoms/buttons/LinkButton/link-button.module.scss +49 -0
- package/src/components/atoms/buttons/RadioButtonWithText/RadioButtonWithText.jsx +110 -0
- package/src/components/atoms/buttons/RadioButtonWithText/radio-button-with-text.module.scss +86 -0
- package/src/components/hooks/useCallHandlingErrors.js +22 -0
- package/src/components/hooks/useReferredState.js +24 -0
- package/src/components/molecules/AmountInput/AmountInput.jsx +304 -0
- package/src/components/molecules/AmountInput/amount-input.module.scss +189 -0
- package/src/components/molecules/CoinPicker/CoinPicker.jsx +509 -0
- package/src/components/molecules/CoinPicker/coin-picker.module.scss +207 -0
- package/src/components/molecules/LineWithIconLink/LineWithIconLink.jsx +35 -0
- package/src/components/molecules/LineWithIconLink/line-with-icon-link.module.scss +25 -0
- package/src/components/molecules/TitledLineWithIconLink/TitledLineWithIconLink.jsx +30 -0
- package/src/components/organisms/CoinPickerDialogStep/CoinPickerDialogStep.jsx +64 -0
- package/src/components/organisms/Dialog/Dialog.jsx +465 -0
- package/src/components/organisms/Dialog/DialogButtons/DialogButtons.jsx +122 -0
- package/src/components/organisms/Dialog/DialogButtons/dialog-buttons.module.scss +25 -0
- package/src/components/organisms/Dialog/DialogStep/DialogStep.jsx +533 -0
- package/src/components/organisms/Dialog/DialogStep/dialog-step.module.scss +381 -0
- package/src/components/organisms/Dialog/dialog.module.scss +226 -0
- package/src/components/organisms/SwapForm/SwapForm.jsx +1105 -0
- package/src/components/organisms/SwapForm/swap-form.module.scss +134 -0
- package/src/components/templates/DeterminedErrorDialogStep/DeterminedErrorDialogStep.jsx +77 -0
- package/src/components/tests/utils/inputValueProviders/provideFormatOfFloatValueByInputString.test.js +132 -0
- package/src/components/tests/utils/urlQueryUtils/getQueryParameterValues.test.js +65 -0
- package/src/components/tests/utils/urlQueryUtils/saveQueryParameterAndValues.test.js +104 -0
- package/src/components/utils/inputValueProviders.js +50 -0
- package/src/components/utils/textUtils.js +18 -0
- package/src/components/utils/uiUtils.js +12 -0
- package/src/components/utils/urlQueryUtils.js +62 -0
- package/src/constants/atoms/Close/close.jsx +5 -0
- package/src/constants/atoms/LinkButton/linkButton.jsx +6 -0
- package/src/constants/atoms/Tooltip/tooltip.jsx +8 -0
- package/src/constants/globalConstants.jsx +3 -0
- package/src/constants/organisms/dialog/DialogStep/dialogStep.js +1 -0
- package/src/constants/organisms/dialog/dialog.js +29 -0
- package/src/index.js +88 -0
- package/src/robustExteranlApiCallerService/cacheAndConcurrentRequestsResolver.js +495 -0
- package/src/robustExteranlApiCallerService/cachedRobustExternalApiCallerService.js +147 -0
- package/src/robustExteranlApiCallerService/cancelProcessing.js +29 -0
- package/src/robustExteranlApiCallerService/concurrentCalculationsMetadataHolder.js +75 -0
- package/src/robustExteranlApiCallerService/externalApiProvider.js +156 -0
- package/src/robustExteranlApiCallerService/externalServicesStatsCollector.js +78 -0
- package/src/robustExteranlApiCallerService/robustExternalAPICallerService.js +304 -0
- package/src/robustExteranlApiCallerService/tests/robustExternalAPICallerService/robustExternalAPICallerService/callExternalAPI/_performCallAttempt.test.js +533 -0
- package/src/robustExteranlApiCallerService/tests/robustExternalAPICallerService/robustExternalAPICallerService/callExternalAPI/callExternalAPI.test.js +532 -0
- package/src/robustExteranlApiCallerService/tests/robustExternalAPICallerService/robustExternalAPICallerService/constructor.test.js +19 -0
- package/src/swaps-lib/external-apis/swapProvider.js +208 -0
- package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +704 -0
- package/src/swaps-lib/models/baseSwapCreationInfo.js +43 -0
- package/src/swaps-lib/models/existingSwap.js +73 -0
- package/src/swaps-lib/models/existingSwapWithFiatData.js +128 -0
- package/src/swaps-lib/services/publicSwapService.js +601 -0
- package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/_fetchSupportedCurrenciesIfNeeded.test.js +538 -0
- package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/createSwap.test.js +1249 -0
- package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getAllSupportedCurrencies.test.js +66 -0
- package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getDepositCurrencies.test.js +76 -0
- package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getSwapInfo.test.js +1580 -0
- package/src/swaps-lib/test/external-apis/swapspaceSwapProvider/getWithdrawalCurrencies.test.js +105 -0
- package/src/swaps-lib/test/utils/swapUtils/safeHandleRequestsLimitExceeding.test.js +80 -0
- package/src/swaps-lib/utils/swapUtils.js +170 -0
- package/stories/stubs/exampleContent.jsx +20 -0
- package/styles/_placeholder.scss +1 -1
- package/styles/fonts/NunitoSans-Bold.ttf +0 -0
- package/styles/fonts/NunitoSans-ExtraBold.ttf +0 -0
- package/styles/fonts/NunitoSans-Light.ttf +0 -0
- package/styles/fonts/NunitoSans-Regular.ttf +0 -0
- package/styles/fonts/NunitoSans-SemiBold.ttf +0 -0
- package/styles/global-styles-index.scss +1 -1
- package/styles/index.scss +5 -3
- package/stories/atoms/AssetIcon/AssetIcon.js +0 -55
- package/stories/index.js +0 -4
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
import { AmountUtils } from "../../common/amountUtils.js";
|
|
5
|
+
import { improveAndRethrow } from "../../common/errorUtils.js";
|
|
6
|
+
import { SwapProvider } from "./swapProvider.js";
|
|
7
|
+
import { ExistingSwap } from "../models/existingSwap.js";
|
|
8
|
+
import { Coin } from "../../common/models/coin.js";
|
|
9
|
+
import { Protocol } from "../../common/models/protocol.js";
|
|
10
|
+
import { safeStringify } from "../../common/utils/safeStringify.js";
|
|
11
|
+
import { Logger } from "../../common/utils/logging/logger.js";
|
|
12
|
+
import { FALLBACK_ASSET_ICON_URL } from "../../constants/globalConstants.jsx";
|
|
13
|
+
|
|
14
|
+
export const BANNED_PARTNERS = ["stealthex", "changee", "coincraddle"];
|
|
15
|
+
|
|
16
|
+
export class SwapspaceSwapProvider extends SwapProvider {
|
|
17
|
+
constructor(apiKeysProxyUrl, cache, customCoinBuilder = (coin, network) => null, useRestrictedCoinsSet = true) {
|
|
18
|
+
super();
|
|
19
|
+
this._supportedCoins = [];
|
|
20
|
+
this._URL = `${apiKeysProxyUrl}`;
|
|
21
|
+
this._maxRateDigits = 20;
|
|
22
|
+
this.useRestrictedCoinsSet = useRestrictedCoinsSet;
|
|
23
|
+
this._customCoinBuilder = customCoinBuilder;
|
|
24
|
+
this._cache = cache;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getSwapCreationInfoTtlMs() {
|
|
28
|
+
/* Actually 2 minutes and only relevant for some partners, but we use it
|
|
29
|
+
* (and even a bit smaller value) for better consistency */
|
|
30
|
+
return 110000;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getDepositCurrencies() {
|
|
34
|
+
const loggerSource = "getDepositCurrencies";
|
|
35
|
+
try {
|
|
36
|
+
await this._fetchSupportedCurrenciesIfNeeded();
|
|
37
|
+
Logger.log(`We have ${this._supportedCoins?.length} supported coins, getting depositable`, loggerSource);
|
|
38
|
+
return {
|
|
39
|
+
result: true,
|
|
40
|
+
coins: this._supportedCoins.filter(item => item.deposit).map(item => item.coin),
|
|
41
|
+
};
|
|
42
|
+
} catch (e) {
|
|
43
|
+
if (e?.response?.status === 429) {
|
|
44
|
+
return {
|
|
45
|
+
result: false,
|
|
46
|
+
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
improveAndRethrow(e, loggerSource);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async getAllSupportedCurrencies() {
|
|
54
|
+
const loggerSource = "getAllSupportedCurrencies";
|
|
55
|
+
try {
|
|
56
|
+
await this._fetchSupportedCurrenciesIfNeeded();
|
|
57
|
+
Logger.log(`We have ${this._supportedCoins?.length} supported coins returning`, loggerSource);
|
|
58
|
+
return {
|
|
59
|
+
result: true,
|
|
60
|
+
coins: this._supportedCoins.map(item => item.coin),
|
|
61
|
+
};
|
|
62
|
+
} catch (e) {
|
|
63
|
+
if (e?.response?.status === 429) {
|
|
64
|
+
return {
|
|
65
|
+
result: false,
|
|
66
|
+
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
improveAndRethrow(e, loggerSource);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async getWithdrawalCurrencies(exceptCurrency = null) {
|
|
74
|
+
const loggerSource = "getWithdrawalCurrencies";
|
|
75
|
+
try {
|
|
76
|
+
await this._fetchSupportedCurrenciesIfNeeded();
|
|
77
|
+
Logger.log(`We have ${this._supportedCoins?.length} supported coins, getting withdrawable`, loggerSource);
|
|
78
|
+
return {
|
|
79
|
+
result: true,
|
|
80
|
+
coins: this._supportedCoins
|
|
81
|
+
.filter(
|
|
82
|
+
item => item.withdrawal && (!exceptCurrency || item.coin?.ticker !== exceptCurrency?.ticker)
|
|
83
|
+
)
|
|
84
|
+
.map(item => item.coin),
|
|
85
|
+
};
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (e?.response?.status === 429) {
|
|
88
|
+
return {
|
|
89
|
+
result: false,
|
|
90
|
+
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
improveAndRethrow(e, loggerSource);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async initialize() {
|
|
98
|
+
await this._fetchSupportedCurrenciesIfNeeded();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getIconUrl(coinOrTicker) {
|
|
102
|
+
const loggerSource = "getIconUrl";
|
|
103
|
+
try {
|
|
104
|
+
let coin = coinOrTicker;
|
|
105
|
+
if (!(coinOrTicker instanceof Coin)) {
|
|
106
|
+
coin = this._supportedCoins.find(i => i.coin.ticker === coinOrTicker)?.coin;
|
|
107
|
+
}
|
|
108
|
+
return (
|
|
109
|
+
this._supportedCoins.find(item => item.coin?.ticker === coin?.ticker)?.iconURL ??
|
|
110
|
+
FALLBACK_ASSET_ICON_URL
|
|
111
|
+
);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
improveAndRethrow(e, loggerSource);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async _fetchSupportedCurrenciesIfNeeded() {
|
|
118
|
+
const loggerSource = "_fetchSupportedCurrenciesIfNeeded";
|
|
119
|
+
try {
|
|
120
|
+
if (!this._supportedCoins?.length) {
|
|
121
|
+
const rawResponse = await axios.get(`${this._URL}/api/v2/currencies`);
|
|
122
|
+
Logger.log(`Retrieved ${rawResponse?.data?.length}`, loggerSource);
|
|
123
|
+
let allowedCoins = rawResponse?.data ?? [];
|
|
124
|
+
Logger.log(`Allowed cnt ${allowedCoins.length}`, loggerSource);
|
|
125
|
+
|
|
126
|
+
this._supportedCoins = allowedCoins
|
|
127
|
+
.map(item => {
|
|
128
|
+
let coin = this._customCoinBuilder(item.code, item.network);
|
|
129
|
+
if (!coin && !this.useRestrictedCoinsSet) {
|
|
130
|
+
/** Building coin object for coin that isn't supported OOB in Rabbit.
|
|
131
|
+
* We are doing this way to be able to use extended coins set for swaps.
|
|
132
|
+
* These temporary built coins are only for in-swap use, and we omit some usual
|
|
133
|
+
* coin details here.
|
|
134
|
+
* Ideally we should add some new abstractions e.g. BaseCoin:
|
|
135
|
+
* Coin will extend BaseCoin, SwapCoin will extend BaseCoin etc.
|
|
136
|
+
* But for now it is reasonable to use this simpler approach.
|
|
137
|
+
*/
|
|
138
|
+
const code = item.code.toUpperCase();
|
|
139
|
+
const network = item.network.toUpperCase();
|
|
140
|
+
/** Removing ticker and protocol name from coin name as we usually use them explicitly
|
|
141
|
+
* from coin object rather than counting on having it in the coin name itself.
|
|
142
|
+
* This processing is needed due to poor quality of swapspace coins names. */
|
|
143
|
+
let name = (item.name ?? "")
|
|
144
|
+
.replaceAll(`(${code})`, "")
|
|
145
|
+
.replaceAll(`(${network})`, "")
|
|
146
|
+
.replaceAll(/ +/g, " ")
|
|
147
|
+
.trim();
|
|
148
|
+
if (name === "") {
|
|
149
|
+
// Rolling back to original name if our processing leads in empty name
|
|
150
|
+
name = item.name;
|
|
151
|
+
}
|
|
152
|
+
const ticker = `${code}${code === network ? "" : network}`;
|
|
153
|
+
const defaultDecimalPlacesForCoinNotSupportedOOB = 8;
|
|
154
|
+
const defaultMinConfirmationsForCoinNotSupportedOOB = 1;
|
|
155
|
+
coin = new Coin(
|
|
156
|
+
name,
|
|
157
|
+
ticker,
|
|
158
|
+
code,
|
|
159
|
+
defaultDecimalPlacesForCoinNotSupportedOOB,
|
|
160
|
+
null,
|
|
161
|
+
"",
|
|
162
|
+
null,
|
|
163
|
+
null,
|
|
164
|
+
defaultMinConfirmationsForCoinNotSupportedOOB,
|
|
165
|
+
null,
|
|
166
|
+
[],
|
|
167
|
+
60000,
|
|
168
|
+
null, // We cannot recognize blockchain from swapspace data
|
|
169
|
+
code !== network ? new Protocol(network) : null,
|
|
170
|
+
item.contractAddress || null,
|
|
171
|
+
false
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
if (coin) {
|
|
175
|
+
return {
|
|
176
|
+
coin: coin,
|
|
177
|
+
code: item.code,
|
|
178
|
+
network: item.network,
|
|
179
|
+
hasExtraId: item.hasExtraId,
|
|
180
|
+
extraIdName: item.extraIdName,
|
|
181
|
+
isPopular: !!item.popular,
|
|
182
|
+
iconURL: item.icon
|
|
183
|
+
? `https://storage.swapspace.co${item.icon}`
|
|
184
|
+
: FALLBACK_ASSET_ICON_URL,
|
|
185
|
+
deposit: item.deposit ?? false,
|
|
186
|
+
withdrawal: item.withdrawal ?? false,
|
|
187
|
+
validationRegexp: item.validationRegexp ?? null,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return [];
|
|
192
|
+
})
|
|
193
|
+
.flat();
|
|
194
|
+
this._putPopularCoinsFirst();
|
|
195
|
+
}
|
|
196
|
+
} catch (e) {
|
|
197
|
+
improveAndRethrow(e, loggerSource);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* This method sort internal list putting popular (as swapspace thinks) coins to the top.
|
|
203
|
+
* This is just for users of this API if they don't care about the sorting - we just improve a list a bit this way.
|
|
204
|
+
* @private
|
|
205
|
+
*/
|
|
206
|
+
_putPopularCoinsFirst() {
|
|
207
|
+
this._supportedCoins.sort((i1, i2) => {
|
|
208
|
+
if (i1.isPopular && !i2.isPopular) return -1;
|
|
209
|
+
if (i2.isPopular && !i1.isPopular) return 1;
|
|
210
|
+
return i1.coin.ticker > i2.coin.ticker ? 1 : i1.coin.ticker < i2.coin.ticker ? -1 : 0;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async getCoinToUSDTRate(coin) {
|
|
215
|
+
const loggerSource = "getCoinToUSDTRate";
|
|
216
|
+
try {
|
|
217
|
+
if (!coin) return null;
|
|
218
|
+
|
|
219
|
+
await this._fetchSupportedCurrenciesIfNeeded();
|
|
220
|
+
|
|
221
|
+
// Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
|
|
222
|
+
const usdtTrc20 = this._supportedCoins.find(i => i.coin.ticker === "USDTTRC20")?.coin;
|
|
223
|
+
if (!usdtTrc20) {
|
|
224
|
+
return { result: false };
|
|
225
|
+
}
|
|
226
|
+
const cached = this._cache.get("swapspace_usdt_rate_" + coin.ticker);
|
|
227
|
+
if (cached != null) {
|
|
228
|
+
return {
|
|
229
|
+
result: true,
|
|
230
|
+
rate: cached,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
Logger.log("Loading USDT->coin rate as not found in cache:", coin?.ticker);
|
|
235
|
+
const result = await this.getSwapInfo(usdtTrc20, coin, "5000", false);
|
|
236
|
+
if (!result.result) {
|
|
237
|
+
return { result: false };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// This calculation is not precise as we cannot recognize the actual fee and network fee. Just approximate.
|
|
241
|
+
const standardSwapspaceFeeMultiplier = 1.004; // fee is usually 0.4%
|
|
242
|
+
const rate = BigNumber(1).div(BigNumber(result.rate).times(standardSwapspaceFeeMultiplier)).toString();
|
|
243
|
+
this._cache.put(
|
|
244
|
+
"swapspace_usdt_rate_" + coin.ticker,
|
|
245
|
+
rate,
|
|
246
|
+
15 * 60000 // 15 minutes
|
|
247
|
+
);
|
|
248
|
+
return {
|
|
249
|
+
result: true,
|
|
250
|
+
rate: rate,
|
|
251
|
+
};
|
|
252
|
+
} catch (e) {
|
|
253
|
+
improveAndRethrow(e, loggerSource);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
getCoinByTickerIfPresent(ticker) {
|
|
258
|
+
try {
|
|
259
|
+
const item = this._supportedCoins.find(i => i.coin.ticker === ticker);
|
|
260
|
+
return item?.coin ?? null;
|
|
261
|
+
} catch (e) {
|
|
262
|
+
improveAndRethrow(e, "getCoinByTickerIfPresent");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async getSwapInfo(fromCoin, toCoin, amountCoins, fixed = false, fromCoinToUsdRate = null) {
|
|
267
|
+
const loggerSource = "getSwapInfo";
|
|
268
|
+
try {
|
|
269
|
+
if (
|
|
270
|
+
!(fromCoin instanceof Coin) ||
|
|
271
|
+
!(toCoin instanceof Coin) ||
|
|
272
|
+
typeof amountCoins !== "string" ||
|
|
273
|
+
BigNumber(amountCoins).lt("0") ||
|
|
274
|
+
(fixed !== null && typeof fixed !== "boolean")
|
|
275
|
+
) {
|
|
276
|
+
throw new Error(
|
|
277
|
+
`Wrong input params: ${amountCoins} ${fromCoin.ticker} -> ${toCoin.ticker}, ${
|
|
278
|
+
fromCoin instanceof Coin
|
|
279
|
+
}, ${toCoin instanceof Coin}, ${typeof fixed} ${fixed}`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
const fromCoinSwapspaceDetails = this._supportedCoins.find(i => i.coin?.ticker === fromCoin?.ticker);
|
|
283
|
+
const toCoinSwapspaceDetails = this._supportedCoins.find(i => i.coin?.ticker === toCoin?.ticker);
|
|
284
|
+
if (!fromCoinSwapspaceDetails || !toCoinSwapspaceDetails) {
|
|
285
|
+
throw new Error(
|
|
286
|
+
"Failed to find swapspace coin details for: " + fromCoin.ticker + " -> " + toCoin.ticker
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
if (!fromCoinSwapspaceDetails.deposit || !toCoinSwapspaceDetails.withdrawal) {
|
|
290
|
+
return {
|
|
291
|
+
result: false,
|
|
292
|
+
reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/* Here we use not documented parameter 'estimated=false'. This parameter controls whether we want to use
|
|
296
|
+
* cached rate values stored in swapspace cache. Their support says they store at most for 30 sec.
|
|
297
|
+
* But we are better off using the most actual rates.
|
|
298
|
+
*/
|
|
299
|
+
const response = await axios.get(
|
|
300
|
+
`${this._URL}/api/v2/amounts?fromCurrency=${fromCoinSwapspaceDetails.code}&fromNetwork=${fromCoinSwapspaceDetails.network}&toNetwork=${toCoinSwapspaceDetails.network}&toCurrency=${toCoinSwapspaceDetails.code}&amount=${amountCoins}&estimated=false`
|
|
301
|
+
);
|
|
302
|
+
Logger.log(`Retrieved ${response?.data?.length} options`, loggerSource);
|
|
303
|
+
const options = Array.isArray(response.data) ? response.data : [];
|
|
304
|
+
// TODO: [feature, high] remove if possible over-engineering about toAmount = 0 options treating as supported but not available. task_id=404ae30d9a7743238af3cc0d3bae9239
|
|
305
|
+
let exchangesSupportingThePairDespiteFixedOrFloating = options.filter(
|
|
306
|
+
exchange =>
|
|
307
|
+
exchange?.exists &&
|
|
308
|
+
!BANNED_PARTNERS.find(bannedPartner => bannedPartner === exchange?.partner) &&
|
|
309
|
+
(exchange?.fixed === false || exchange?.fixed === true) &&
|
|
310
|
+
typeof exchange.toAmount === "number" &&
|
|
311
|
+
((typeof exchange.min === "number" && typeof exchange.max === "number") || exchange.toAmount > 0) &&
|
|
312
|
+
(exchange.min === 0 || exchange.max === 0 || exchange.max > exchange.min)
|
|
313
|
+
);
|
|
314
|
+
let exchangesSupportingThePair = exchangesSupportingThePairDespiteFixedOrFloating;
|
|
315
|
+
if (fixed != null) {
|
|
316
|
+
exchangesSupportingThePair = exchangesSupportingThePairDespiteFixedOrFloating.filter(
|
|
317
|
+
option => option.fixed === fixed
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
Logger.log(`${exchangesSupportingThePair?.length} of them have exist=true`, loggerSource);
|
|
321
|
+
if (exchangesSupportingThePair.length === 0) {
|
|
322
|
+
if (exchangesSupportingThePairDespiteFixedOrFloating.length > 0 && fixed !== null) {
|
|
323
|
+
return {
|
|
324
|
+
result: false,
|
|
325
|
+
reason: fixed
|
|
326
|
+
? SwapProvider.NO_SWAPS_REASONS.NO_FIXED_BUT_HAVE_FLOATING
|
|
327
|
+
: SwapProvider.NO_SWAPS_REASONS.NO_FLOATING_BUT_HAVE_FIXED,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
result: false,
|
|
332
|
+
reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
const availableExchanges = exchangesSupportingThePair.filter(
|
|
336
|
+
exchange => typeof exchange?.toAmount === "number" && exchange.toAmount > 0
|
|
337
|
+
);
|
|
338
|
+
Logger.log(`Available (having amountTo): ${safeStringify(availableExchanges)}`, loggerSource);
|
|
339
|
+
// min=0 or max=0 means there is no limit for the partner
|
|
340
|
+
let smallestMin = null;
|
|
341
|
+
if (exchangesSupportingThePair.find(ex => BigNumber(ex.min).isZero()) == null) {
|
|
342
|
+
smallestMin = exchangesSupportingThePair.reduce((prev, cur) => {
|
|
343
|
+
if (typeof cur.min === "number" && (prev === null || BigNumber(cur.min).lt(prev)))
|
|
344
|
+
return BigNumber(cur.min);
|
|
345
|
+
return prev;
|
|
346
|
+
}, null);
|
|
347
|
+
}
|
|
348
|
+
let greatestMax = null;
|
|
349
|
+
if (exchangesSupportingThePair.find(ex => BigNumber(ex.max).isZero()) == null) {
|
|
350
|
+
greatestMax = exchangesSupportingThePair.reduce((prev, cur) => {
|
|
351
|
+
if (typeof cur.max === "number" && (prev === null || BigNumber(cur.max).gt(prev)))
|
|
352
|
+
return BigNumber(cur.max);
|
|
353
|
+
return prev;
|
|
354
|
+
}, null);
|
|
355
|
+
}
|
|
356
|
+
let extraCoinsToFitMinMax = "0";
|
|
357
|
+
if (typeof fromCoinToUsdRate === "string" && BigNumber(fromCoinToUsdRate).gt("0")) {
|
|
358
|
+
const extraUsdToFitMinMax = BigNumber("1"); // We correct the limits as the exact limit can fluctuate and cause failed swap creation
|
|
359
|
+
extraCoinsToFitMinMax = AmountUtils.trim(extraUsdToFitMinMax.div(fromCoinToUsdRate), fromCoin.digits);
|
|
360
|
+
}
|
|
361
|
+
if (smallestMin instanceof BigNumber) {
|
|
362
|
+
smallestMin = AmountUtils.trim(smallestMin.plus(extraCoinsToFitMinMax), fromCoin.digits);
|
|
363
|
+
}
|
|
364
|
+
if (greatestMax instanceof BigNumber) {
|
|
365
|
+
if (greatestMax > extraCoinsToFitMinMax) {
|
|
366
|
+
greatestMax = AmountUtils.trim(greatestMax.minus(extraCoinsToFitMinMax), fromCoin.digits);
|
|
367
|
+
} else {
|
|
368
|
+
greatestMax = "0";
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (availableExchanges.length) {
|
|
373
|
+
const sorted = availableExchanges.sort((op1, op2) => op2.toAmount - op1.toAmount);
|
|
374
|
+
const bestOpt = sorted[0];
|
|
375
|
+
Logger.log(`Returning first option after sorting: ${safeStringify(bestOpt)}`, loggerSource);
|
|
376
|
+
let max = null;
|
|
377
|
+
let min = null;
|
|
378
|
+
if (extraCoinsToFitMinMax != null) {
|
|
379
|
+
if (typeof bestOpt.max === "number" && bestOpt.max !== 0) {
|
|
380
|
+
max = BigNumber(bestOpt.max).minus(extraCoinsToFitMinMax);
|
|
381
|
+
max = AmountUtils.trim(max.lt(0) ? "0" : max, fromCoin.digits);
|
|
382
|
+
}
|
|
383
|
+
if (typeof bestOpt.min === "number" && bestOpt.min !== 0) {
|
|
384
|
+
min = AmountUtils.trim(BigNumber(bestOpt.min).plus(extraCoinsToFitMinMax), fromCoin.digits);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const rate =
|
|
389
|
+
bestOpt.toAmount && bestOpt.fromAmount ? BigNumber(bestOpt.toAmount).div(bestOpt.fromAmount) : null;
|
|
390
|
+
return {
|
|
391
|
+
result: true,
|
|
392
|
+
min: min,
|
|
393
|
+
max: max,
|
|
394
|
+
smallestMin: smallestMin,
|
|
395
|
+
greatestMax: greatestMax,
|
|
396
|
+
rate: rate != null ? AmountUtils.trim(rate, this._maxRateDigits) : null,
|
|
397
|
+
durationMinutesRange: bestOpt.duration ?? null,
|
|
398
|
+
fixed: bestOpt.fixed,
|
|
399
|
+
rawSwapData: bestOpt,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
const result = {
|
|
403
|
+
result: false,
|
|
404
|
+
reason:
|
|
405
|
+
smallestMin && BigNumber(amountCoins).lt(smallestMin)
|
|
406
|
+
? SwapProvider.NO_SWAPS_REASONS.TOO_LOW
|
|
407
|
+
: greatestMax && BigNumber(amountCoins).gt(greatestMax)
|
|
408
|
+
? SwapProvider.NO_SWAPS_REASONS.TOO_HIGH
|
|
409
|
+
: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED,
|
|
410
|
+
smallestMin: smallestMin,
|
|
411
|
+
greatestMax: greatestMax,
|
|
412
|
+
};
|
|
413
|
+
Logger.log(`Returning result ${safeStringify(result)}`, loggerSource);
|
|
414
|
+
return result;
|
|
415
|
+
} catch (e) {
|
|
416
|
+
if (e?.response?.status === 429) {
|
|
417
|
+
return {
|
|
418
|
+
result: false,
|
|
419
|
+
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
Logger.log(`Internal swapspace/rabbit error when getting swap options ${safeStringify(e)}`, loggerSource);
|
|
423
|
+
improveAndRethrow(e, loggerSource);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
async createSwap(
|
|
428
|
+
fromCoin,
|
|
429
|
+
toCoin,
|
|
430
|
+
amount,
|
|
431
|
+
toAddress,
|
|
432
|
+
refundAddress,
|
|
433
|
+
rawSwapData,
|
|
434
|
+
clientIpAddress,
|
|
435
|
+
fixed,
|
|
436
|
+
toCurrencyExtraId = "",
|
|
437
|
+
refundExtraId = ""
|
|
438
|
+
) {
|
|
439
|
+
const loggerSource = "createSwap";
|
|
440
|
+
const partner = rawSwapData?.partner;
|
|
441
|
+
try {
|
|
442
|
+
if (
|
|
443
|
+
!(fromCoin instanceof Coin) ||
|
|
444
|
+
!(toCoin instanceof Coin) ||
|
|
445
|
+
typeof amount !== "string" ||
|
|
446
|
+
typeof toAddress !== "string" ||
|
|
447
|
+
typeof refundAddress !== "string" ||
|
|
448
|
+
typeof clientIpAddress != "string" ||
|
|
449
|
+
typeof fixed != "boolean" ||
|
|
450
|
+
clientIpAddress.length === 0
|
|
451
|
+
) {
|
|
452
|
+
throw new Error(
|
|
453
|
+
`Invalid input: ${fromCoin} ${toCoin} ${amount} ${toAddress} ${refundAddress} ${clientIpAddress?.length} ${fixed}`
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
if (
|
|
457
|
+
typeof partner !== "string" ||
|
|
458
|
+
typeof rawSwapData?.fromCurrency !== "string" ||
|
|
459
|
+
typeof rawSwapData?.fromNetwork !== "string" ||
|
|
460
|
+
typeof rawSwapData?.toCurrency !== "string" ||
|
|
461
|
+
typeof rawSwapData?.toNetwork !== "string" ||
|
|
462
|
+
typeof rawSwapData?.id !== "string" // can be just empty
|
|
463
|
+
) {
|
|
464
|
+
throw new Error(`Invalid raw swap data: ${safeStringify(rawSwapData)}`);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const [fromCurrencyHasExtraId, toCurrencyHasExtraId] = this._supportedCoins.reduce(
|
|
468
|
+
(prev, coinData) => [
|
|
469
|
+
coinData.coin.ticker === fromCoin.ticker ? coinData.hasExtraId : prev[0],
|
|
470
|
+
coinData.coin.ticker === toCoin.ticker ? coinData.hasExtraId : prev[1],
|
|
471
|
+
],
|
|
472
|
+
[false, false]
|
|
473
|
+
);
|
|
474
|
+
await this._fetchSupportedCurrenciesIfNeeded();
|
|
475
|
+
const requestData = {
|
|
476
|
+
partner: partner,
|
|
477
|
+
fromCurrency: rawSwapData?.fromCurrency,
|
|
478
|
+
fromNetwork: rawSwapData?.fromNetwork,
|
|
479
|
+
toCurrency: rawSwapData?.toCurrency,
|
|
480
|
+
toNetwork: rawSwapData?.toNetwork,
|
|
481
|
+
address: toAddress,
|
|
482
|
+
amount: amount,
|
|
483
|
+
fixed: fixed,
|
|
484
|
+
extraId: toCurrencyHasExtraId ? toCurrencyExtraId ?? "" : "",
|
|
485
|
+
// This param is not documented. But the refund is usually manual so this is not critical.
|
|
486
|
+
refundExtraId: fromCurrencyHasExtraId ? refundExtraId ?? "" : "",
|
|
487
|
+
rateId: rawSwapData?.id,
|
|
488
|
+
userIp: clientIpAddress,
|
|
489
|
+
refund: refundAddress,
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
Logger.log(`Sending create request: ${safeStringify(requestData)}`, loggerSource);
|
|
493
|
+
const response = await axios.post(`${this._URL}/api/v2/exchange`, requestData);
|
|
494
|
+
const result = response.data;
|
|
495
|
+
Logger.log(`Creation result ${safeStringify(result)}`, loggerSource);
|
|
496
|
+
|
|
497
|
+
if (result?.id) {
|
|
498
|
+
if (
|
|
499
|
+
typeof result?.from?.amount !== "number" ||
|
|
500
|
+
typeof result?.from?.address !== "string" ||
|
|
501
|
+
typeof result?.fixed !== "boolean" ||
|
|
502
|
+
typeof result?.to?.amount !== "number" ||
|
|
503
|
+
typeof result?.to?.address !== "string"
|
|
504
|
+
)
|
|
505
|
+
throw new Error(`Wrong swap creation result ${result}`);
|
|
506
|
+
/* We use the returned rate preferably but if the retrieved
|
|
507
|
+
* rate 0/null/undefined we calculate it manually */
|
|
508
|
+
let rate = result.rate;
|
|
509
|
+
if (typeof rate !== "number" || BigNumber(rate).isZero()) {
|
|
510
|
+
rate = BigNumber(result?.to?.amount).div(result?.from?.amount);
|
|
511
|
+
} else {
|
|
512
|
+
rate = BigNumber(rate);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
return {
|
|
516
|
+
result: true,
|
|
517
|
+
swapId: result?.id,
|
|
518
|
+
fromCoin: fromCoin,
|
|
519
|
+
fromAmount: AmountUtils.trim(result?.from?.amount, fromCoin.digits),
|
|
520
|
+
fromAddress: result?.from?.address,
|
|
521
|
+
toCoin: toCoin,
|
|
522
|
+
toAmount: AmountUtils.trim(result?.to?.amount, toCoin.digits),
|
|
523
|
+
toAddress: result?.to?.address,
|
|
524
|
+
fromCurrencyExtraId: result?.from?.extraId ?? "",
|
|
525
|
+
rate: AmountUtils.trim(rate, this._maxRateDigits),
|
|
526
|
+
fixed: result.fixed,
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
const errorMessage = `Swap creation succeeded but the response is wrong: ${safeStringify(response)}`;
|
|
530
|
+
Logger.log(errorMessage, loggerSource);
|
|
531
|
+
throw new Error(errorMessage);
|
|
532
|
+
} catch (e) {
|
|
533
|
+
Logger.logError(e, loggerSource, `Failed to create swap. Error is: ${safeStringify(e)}`);
|
|
534
|
+
const composeFailResult = reason => ({
|
|
535
|
+
result: false,
|
|
536
|
+
reason: reason,
|
|
537
|
+
partner: partner,
|
|
538
|
+
});
|
|
539
|
+
const status = e?.response?.status;
|
|
540
|
+
const data = e?.response?.data;
|
|
541
|
+
if (status === 429) {
|
|
542
|
+
Logger.log(`Returning fail - RPS limit exceeded ${data}`, loggerSource);
|
|
543
|
+
return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
|
|
544
|
+
}
|
|
545
|
+
const texts422 = [
|
|
546
|
+
"Pair cannot be processed by",
|
|
547
|
+
"Currency not found",
|
|
548
|
+
"Amount maximum is",
|
|
549
|
+
"Amount minimum is",
|
|
550
|
+
];
|
|
551
|
+
const text403 = "IP address is forbidden";
|
|
552
|
+
if (
|
|
553
|
+
typeof data === "string" &&
|
|
554
|
+
((status === 403 && data.includes(text403)) ||
|
|
555
|
+
(status === 422 && texts422.find(text => data.includes(text))))
|
|
556
|
+
) {
|
|
557
|
+
Logger.log(`Returning retriable fail: ${status} - ${data}, ${partner}`, loggerSource);
|
|
558
|
+
return composeFailResult(SwapProvider.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
|
|
559
|
+
}
|
|
560
|
+
Logger.log(`Internal swapspace/rabbit error for ${partner}: ${safeStringify(e)}`, loggerSource);
|
|
561
|
+
improveAndRethrow(e, loggerSource);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
_mapSwapspaceStatusToRabbitStatus(status, isExpiredByTime) {
|
|
566
|
+
switch (status) {
|
|
567
|
+
case "waiting":
|
|
568
|
+
if (isExpiredByTime) {
|
|
569
|
+
return SwapProvider.SWAP_STATUSES.EXPIRED;
|
|
570
|
+
}
|
|
571
|
+
return SwapProvider.SWAP_STATUSES.WAITING_FOR_PAYMENT;
|
|
572
|
+
case "confirming":
|
|
573
|
+
return SwapProvider.SWAP_STATUSES.CONFIRMING;
|
|
574
|
+
case "exchanging":
|
|
575
|
+
return SwapProvider.SWAP_STATUSES.EXCHANGING;
|
|
576
|
+
case "sending":
|
|
577
|
+
return SwapProvider.SWAP_STATUSES.PAYMENT_RECEIVED;
|
|
578
|
+
case "finished":
|
|
579
|
+
return SwapProvider.SWAP_STATUSES.COMPLETED;
|
|
580
|
+
case "verifying":
|
|
581
|
+
return SwapProvider.SWAP_STATUSES.EXCHANGING;
|
|
582
|
+
case "refunded":
|
|
583
|
+
return SwapProvider.SWAP_STATUSES.REFUNDED;
|
|
584
|
+
case "expired":
|
|
585
|
+
return SwapProvider.SWAP_STATUSES.EXPIRED;
|
|
586
|
+
case "failed":
|
|
587
|
+
return SwapProvider.SWAP_STATUSES.FAILED;
|
|
588
|
+
default:
|
|
589
|
+
throw new Error(`Unknown swapspace status: ${status}`);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
async getExistingSwapsDetailsAndStatus(swapIds) {
|
|
594
|
+
const loggerSource = "getExistingSwapsDetailsAndStatus";
|
|
595
|
+
try {
|
|
596
|
+
if (swapIds.find(id => typeof id !== "string")) {
|
|
597
|
+
throw new Error("Swap id is not string: " + safeStringify(swapIds));
|
|
598
|
+
}
|
|
599
|
+
const getNotFailingOn404 = async swapId => {
|
|
600
|
+
try {
|
|
601
|
+
return await axios.get(`${this._URL}/api/v2/exchange/${swapId}`);
|
|
602
|
+
} catch (error) {
|
|
603
|
+
if (error?.response?.status === 404) return [];
|
|
604
|
+
throw error;
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
const responses = await Promise.all(swapIds.map(swapId => getNotFailingOn404(swapId)));
|
|
608
|
+
const wo404 = responses.flat();
|
|
609
|
+
Logger.log("All swaps RAW: " + JSON.stringify(wo404.map(r => r.data)), loggerSource);
|
|
610
|
+
const swaps = wo404
|
|
611
|
+
.map(r => r.data)
|
|
612
|
+
.map((swap, index) => {
|
|
613
|
+
const fromCoin = this._supportedCoins.find(
|
|
614
|
+
i => i.code === swap.from.code && i.network === swap.from.network
|
|
615
|
+
)?.coin;
|
|
616
|
+
const toCoin = this._supportedCoins.find(
|
|
617
|
+
i => i.code === swap.to.code && i.network === swap.to.network
|
|
618
|
+
)?.coin;
|
|
619
|
+
if (!fromCoin || !toCoin) {
|
|
620
|
+
return []; // We skip swaps with not supported coins for now
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const toUtcTimestamp = timeStr => Date.parse(timeStr.match(/.+[Zz]$/) ? timeStr : `${timeStr}Z`);
|
|
624
|
+
const expiresAt = toUtcTimestamp(swap.timestamps.expiresAt);
|
|
625
|
+
const isExpiredByTime = expiresAt < Date.now();
|
|
626
|
+
const status = this._mapSwapspaceStatusToRabbitStatus(swap.status, isExpiredByTime);
|
|
627
|
+
const toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
|
|
628
|
+
const addressToSendCoinsToSwapspace = swap.from.address;
|
|
629
|
+
return new ExistingSwap(
|
|
630
|
+
swapIds[index],
|
|
631
|
+
status,
|
|
632
|
+
toUtcTimestamp(swap.timestamps.createdAt),
|
|
633
|
+
expiresAt,
|
|
634
|
+
swap.confirmations,
|
|
635
|
+
AmountUtils.trim(swap.rate, this._maxRateDigits),
|
|
636
|
+
swap.fixed,
|
|
637
|
+
swap.refundAddress,
|
|
638
|
+
addressToSendCoinsToSwapspace,
|
|
639
|
+
fromCoin,
|
|
640
|
+
AmountUtils.trim(swap.from.amount, fromCoin.digits),
|
|
641
|
+
swap.from.transactionHash,
|
|
642
|
+
swap.blockExplorerTransactionUrl.from,
|
|
643
|
+
toCoin,
|
|
644
|
+
AmountUtils.trim(swap.to.amount, toDigits),
|
|
645
|
+
swap.to.transactionHash,
|
|
646
|
+
swap.blockExplorerTransactionUrl.to,
|
|
647
|
+
swap.to.address,
|
|
648
|
+
swap.partner,
|
|
649
|
+
swap.from.extraId ?? null,
|
|
650
|
+
swap.to.extraId ?? null,
|
|
651
|
+
swap.refundExtraId ?? null
|
|
652
|
+
);
|
|
653
|
+
})
|
|
654
|
+
.flat();
|
|
655
|
+
Logger.log(`Swap details result ${safeStringify(swaps)}`, loggerSource);
|
|
656
|
+
return { result: true, swaps: swaps };
|
|
657
|
+
} catch (e) {
|
|
658
|
+
Logger.logError(e, loggerSource, `Failed to get swap details. Error is: ${safeStringify(e)}`);
|
|
659
|
+
const composeFailResult = reason => ({
|
|
660
|
+
result: false,
|
|
661
|
+
reason: reason,
|
|
662
|
+
});
|
|
663
|
+
const status = e?.response?.status;
|
|
664
|
+
const data = e?.response?.data;
|
|
665
|
+
if (status === 429) {
|
|
666
|
+
Logger.log(`Returning fail - RPS limit exceeded ${data}`, loggerSource);
|
|
667
|
+
return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
|
|
668
|
+
}
|
|
669
|
+
improveAndRethrow(e, loggerSource);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
isAddressValidForAsset(asset, address) {
|
|
674
|
+
try {
|
|
675
|
+
const assetData = this._supportedCoins.find(i => i.coin?.ticker === asset?.ticker);
|
|
676
|
+
if (assetData) {
|
|
677
|
+
let corrected = assetData.validationRegexp.trim();
|
|
678
|
+
corrected = corrected[0] === "/" ? corrected.slice(1) : corrected;
|
|
679
|
+
corrected =
|
|
680
|
+
corrected[corrected.length - 1] === "/" ? corrected.slice(0, corrected.length - 1) : corrected;
|
|
681
|
+
return address.match(corrected) != null;
|
|
682
|
+
}
|
|
683
|
+
} catch (e) {
|
|
684
|
+
Logger.logError(e, "isAddressValidForAsset");
|
|
685
|
+
}
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
getExtraIdNameIfPresent(asset) {
|
|
690
|
+
try {
|
|
691
|
+
const assetData = this._supportedCoins.find(i => i.coin?.ticker === asset?.ticker);
|
|
692
|
+
if (assetData?.hasExtraId) {
|
|
693
|
+
if (assetData?.extraIdName == null || assetData?.extraIdName === "") {
|
|
694
|
+
// We return some default name if the extraIdName is empty
|
|
695
|
+
return "ID";
|
|
696
|
+
}
|
|
697
|
+
return assetData?.extraIdName;
|
|
698
|
+
}
|
|
699
|
+
return null;
|
|
700
|
+
} catch (e) {
|
|
701
|
+
improveAndRethrow(e, "getExtraIdNameIfPresent");
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|