@rabbitio/ui-kit 1.0.0-beta.16 → 1.0.0-beta.17
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/dist/index.cjs +24 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +22 -21
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +23 -23
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +27 -27
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/common/utils/logging/logger.js +1 -1
- package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +8 -6
- package/src/swaps-lib/services/publicSwapService.js +21 -17
- package/src/swaps-lib/utils/swapUtils.js +4 -3
package/package.json
CHANGED
|
@@ -39,7 +39,7 @@ export class Logger {
|
|
|
39
39
|
|
|
40
40
|
const finalErrorText = message + ". " + safeStringify(e);
|
|
41
41
|
// eslint-disable-next-line no-console
|
|
42
|
-
console.error(finalErrorText);
|
|
42
|
+
console.error(finalErrorText, e);
|
|
43
43
|
|
|
44
44
|
if (!onlyToConsole) {
|
|
45
45
|
this.log(finalErrorText, "logError");
|
|
@@ -597,9 +597,10 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
597
597
|
Logger.log(errorMessage, loggerSource);
|
|
598
598
|
throw new Error(errorMessage);
|
|
599
599
|
} catch (e) {
|
|
600
|
-
Logger.
|
|
601
|
-
|
|
602
|
-
loggerSource
|
|
600
|
+
Logger.logError(
|
|
601
|
+
e,
|
|
602
|
+
loggerSource,
|
|
603
|
+
`Failed to create swap. Error is: ${safeStringify(e)}`
|
|
603
604
|
);
|
|
604
605
|
const composeFailResult = (reason) => ({
|
|
605
606
|
result: false,
|
|
@@ -752,9 +753,10 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
752
753
|
);
|
|
753
754
|
return { result: true, swaps: swaps };
|
|
754
755
|
} catch (e) {
|
|
755
|
-
Logger.
|
|
756
|
-
|
|
757
|
-
loggerSource
|
|
756
|
+
Logger.logError(
|
|
757
|
+
e,
|
|
758
|
+
loggerSource,
|
|
759
|
+
`Failed to get swap details. Error is: ${safeStringify(e)}`
|
|
758
760
|
);
|
|
759
761
|
const composeFailResult = (reason) => ({
|
|
760
762
|
result: false,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import EventBusInstance from "eventbusjs";
|
|
2
3
|
|
|
3
4
|
import { FiatCurrenciesService } from "../../common/fiatCurrenciesService.js";
|
|
4
5
|
import { improveAndRethrow } from "../../common/errorUtils.js";
|
|
@@ -39,7 +40,6 @@ export class PublicSwapService {
|
|
|
39
40
|
async initialize() {
|
|
40
41
|
try {
|
|
41
42
|
await this._swapProvider.initialize();
|
|
42
|
-
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
43
43
|
} catch (e) {
|
|
44
44
|
Logger.logError(e, "PublicSwapService.initialize");
|
|
45
45
|
}
|
|
@@ -61,7 +61,7 @@ export class PublicSwapService {
|
|
|
61
61
|
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
62
62
|
return {
|
|
63
63
|
result: false,
|
|
64
|
-
reason:
|
|
64
|
+
reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
|
|
65
65
|
.REQUESTS_LIMIT_EXCEEDED,
|
|
66
66
|
};
|
|
67
67
|
}
|
|
@@ -115,7 +115,7 @@ export class PublicSwapService {
|
|
|
115
115
|
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
116
116
|
return {
|
|
117
117
|
result: false,
|
|
118
|
-
reason:
|
|
118
|
+
reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
|
|
119
119
|
.REQUESTS_LIMIT_EXCEEDED,
|
|
120
120
|
};
|
|
121
121
|
}
|
|
@@ -125,7 +125,8 @@ export class PublicSwapService {
|
|
|
125
125
|
) {
|
|
126
126
|
return {
|
|
127
127
|
result: false,
|
|
128
|
-
reason:
|
|
128
|
+
reason: PublicSwapService
|
|
129
|
+
.PUBLIC_SWAP_DETAILS_FAIL_REASONS
|
|
129
130
|
.PAIR_NOT_SUPPORTED,
|
|
130
131
|
};
|
|
131
132
|
}
|
|
@@ -175,12 +176,12 @@ export class PublicSwapService {
|
|
|
175
176
|
if (min != null) {
|
|
176
177
|
fiatMin = BigNumber(min)
|
|
177
178
|
.times(coinUsdtRate)
|
|
178
|
-
.toFixed(
|
|
179
|
+
.toFixed(PublicSwapService._fiatDecimalsCount);
|
|
179
180
|
}
|
|
180
181
|
if (max != null) {
|
|
181
182
|
fiatMax = BigNumber(max)
|
|
182
183
|
.times(coinUsdtRate)
|
|
183
|
-
.toFixed(
|
|
184
|
+
.toFixed(PublicSwapService._fiatDecimalsCount);
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
|
|
@@ -200,7 +201,8 @@ export class PublicSwapService {
|
|
|
200
201
|
SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
|
|
201
202
|
)
|
|
202
203
|
return composeFailResult(
|
|
203
|
-
|
|
204
|
+
PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS
|
|
205
|
+
.PAIR_NOT_SUPPORTED
|
|
204
206
|
);
|
|
205
207
|
else if (
|
|
206
208
|
details?.reason ===
|
|
@@ -208,7 +210,8 @@ export class PublicSwapService {
|
|
|
208
210
|
) {
|
|
209
211
|
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
210
212
|
return composeFailResult(
|
|
211
|
-
|
|
213
|
+
PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
|
|
214
|
+
.REQUESTS_LIMIT_EXCEEDED
|
|
212
215
|
);
|
|
213
216
|
}
|
|
214
217
|
}
|
|
@@ -216,12 +219,12 @@ export class PublicSwapService {
|
|
|
216
219
|
const fromAmountBigNumber = BigNumber(fromAmountCoins);
|
|
217
220
|
if (typeof min === "string" && fromAmountBigNumber.lt(min)) {
|
|
218
221
|
return composeFailResult(
|
|
219
|
-
|
|
222
|
+
PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS
|
|
220
223
|
.AMOUNT_LESS_THAN_MIN_SWAPPABLE
|
|
221
224
|
);
|
|
222
225
|
} else if (typeof max === "string" && fromAmountBigNumber.gt(max)) {
|
|
223
226
|
return composeFailResult(
|
|
224
|
-
|
|
227
|
+
PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS
|
|
225
228
|
.AMOUNT_HIGHER_THAN_MAX_SWAPPABLE
|
|
226
229
|
);
|
|
227
230
|
}
|
|
@@ -273,6 +276,7 @@ export class PublicSwapService {
|
|
|
273
276
|
* @param swapCreationInfo {BaseSwapCreationInfo}
|
|
274
277
|
* @param toAddress {string}
|
|
275
278
|
* @param refundAddress {string}
|
|
279
|
+
* @param clientIp {string}
|
|
276
280
|
* @return {Promise<{
|
|
277
281
|
* result: true,
|
|
278
282
|
* fiatCurrencyCode: string,
|
|
@@ -351,7 +355,7 @@ export class PublicSwapService {
|
|
|
351
355
|
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
352
356
|
return {
|
|
353
357
|
result: false,
|
|
354
|
-
reason:
|
|
358
|
+
reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
|
|
355
359
|
.REQUESTS_LIMIT_EXCEEDED,
|
|
356
360
|
};
|
|
357
361
|
}
|
|
@@ -362,7 +366,7 @@ export class PublicSwapService {
|
|
|
362
366
|
// TODO: [feature, high] implement retrying if one partner fail and we have another partners task_id=a07e367e488f4a4899613ac9056fa359
|
|
363
367
|
// return {
|
|
364
368
|
// result: false,
|
|
365
|
-
// reason:
|
|
369
|
+
// reason: PublicSwapService.SWAP_CREATION_FAIL_REASONS.RETRIABLE_FAIL,
|
|
366
370
|
// };
|
|
367
371
|
}
|
|
368
372
|
}
|
|
@@ -379,12 +383,12 @@ export class PublicSwapService {
|
|
|
379
383
|
if (fromCoinUsdtRate != null && result.fromAmount != null) {
|
|
380
384
|
fromAmountFiat = BigNumber(result.fromAmount)
|
|
381
385
|
.times(fromCoinUsdtRate)
|
|
382
|
-
.toFixed(
|
|
386
|
+
.toFixed(PublicSwapService._fiatDecimalsCount);
|
|
383
387
|
}
|
|
384
388
|
if (toCoinUsdtRate != null && result.toAmount != null) {
|
|
385
389
|
toAmountFiat = BigNumber(result.toAmount)
|
|
386
390
|
.times(toCoinUsdtRate)
|
|
387
|
-
.toFixed(
|
|
391
|
+
.toFixed(PublicSwapService._fiatDecimalsCount);
|
|
388
392
|
}
|
|
389
393
|
} catch (e) {
|
|
390
394
|
Logger.logError(
|
|
@@ -395,7 +399,7 @@ export class PublicSwapService {
|
|
|
395
399
|
}
|
|
396
400
|
|
|
397
401
|
EventBusInstance.dispatch(
|
|
398
|
-
|
|
402
|
+
PublicSwapService.PUBLIC_SWAP_CREATED_EVENT,
|
|
399
403
|
null,
|
|
400
404
|
fromCoin.ticker,
|
|
401
405
|
toCoin.ticker,
|
|
@@ -412,7 +416,7 @@ export class PublicSwapService {
|
|
|
412
416
|
fromAmountFiat: fromAmountFiat,
|
|
413
417
|
toAmountFiat: toAmountFiat,
|
|
414
418
|
fiatCurrencyCode: "USD",
|
|
415
|
-
fiatCurrencyDecimals:
|
|
419
|
+
fiatCurrencyDecimals: PublicSwapService._fiatDecimalsCount,
|
|
416
420
|
rate: result.rate,
|
|
417
421
|
durationMinutesRange: swapCreationInfo.durationMinutesRange,
|
|
418
422
|
address: result.fromAddress, // CRITICAL: this is the address to send coins to swaps provider
|
|
@@ -468,7 +472,7 @@ export class PublicSwapService {
|
|
|
468
472
|
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
469
473
|
return {
|
|
470
474
|
result: false,
|
|
471
|
-
reason:
|
|
475
|
+
reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
|
|
472
476
|
.REQUESTS_LIMIT_EXCEEDED,
|
|
473
477
|
};
|
|
474
478
|
}
|
|
@@ -103,9 +103,10 @@ export class SwapUtils {
|
|
|
103
103
|
Logger.log(`Returning: ${safeStringify(result)}`, loggerSource);
|
|
104
104
|
return result;
|
|
105
105
|
} catch (e) {
|
|
106
|
-
Logger.
|
|
107
|
-
|
|
108
|
-
loggerSource
|
|
106
|
+
Logger.logError(
|
|
107
|
+
e,
|
|
108
|
+
loggerSource,
|
|
109
|
+
`Failed to init swap: ${safeStringify(e)}`
|
|
109
110
|
);
|
|
110
111
|
improveAndRethrow(e, loggerSource);
|
|
111
112
|
}
|