@rabbitio/ui-kit 1.0.0-beta.22 → 1.0.0-beta.23
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 +4 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +6 -0
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +4 -5
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +4 -5
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/swaps-lib/external-apis/swapProvider.js +20 -1
- package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +32 -0
- package/src/swaps-lib/services/publicSwapService.js +25 -5
package/package.json
CHANGED
|
@@ -38,6 +38,16 @@ export class SwapProvider {
|
|
|
38
38
|
throw new Error("Not implemented in base");
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves all currencies supported by this swap provider.
|
|
43
|
+
* Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
|
|
44
|
+
*
|
|
45
|
+
* @return {Promise<({ result: true, coins: Coin[] }|{ result: false, reason: string })>}
|
|
46
|
+
*/
|
|
47
|
+
async getAllSupportedCurrencies() {
|
|
48
|
+
throw new Error("Not implemented in base");
|
|
49
|
+
}
|
|
50
|
+
|
|
41
51
|
/**
|
|
42
52
|
* Retrieves all deposit currencies supported by this swap provider.
|
|
43
53
|
* Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
|
|
@@ -84,6 +94,7 @@ export class SwapProvider {
|
|
|
84
94
|
* null min or max signals there is no corresponding limitation. undefined means that the limits were not retrieved.
|
|
85
95
|
* For fail result on of SwapProvider.NO_SWAPS_REASONS or SwapProvider.COMMON_ERRORS reasons will be returned.
|
|
86
96
|
*
|
|
97
|
+
* WARNING: MUST return NOT_SUPPORTED error code for any case when pair is not available/supported (Should not throw random errors for this case)
|
|
87
98
|
* @param fromCoin {Coin}
|
|
88
99
|
* @param toCoin {Coin}
|
|
89
100
|
* @param amountCoins {string}
|
|
@@ -135,7 +146,15 @@ export class SwapProvider {
|
|
|
135
146
|
* partner: string
|
|
136
147
|
* })>}
|
|
137
148
|
*/
|
|
138
|
-
async createSwap(
|
|
149
|
+
async createSwap(
|
|
150
|
+
fromCoin,
|
|
151
|
+
toCoin,
|
|
152
|
+
amount,
|
|
153
|
+
toAddress,
|
|
154
|
+
refundAddress,
|
|
155
|
+
rawSwapData = null,
|
|
156
|
+
clientIpAddress
|
|
157
|
+
) {
|
|
139
158
|
throw new Error("Not implemented in base");
|
|
140
159
|
}
|
|
141
160
|
|
|
@@ -60,6 +60,29 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
async getAllSupportedCurrencies() {
|
|
64
|
+
const loggerSource = "getAllSupportedCurrencies";
|
|
65
|
+
try {
|
|
66
|
+
await this._fetchSupportedCurrenciesIfNeeded();
|
|
67
|
+
Logger.log(
|
|
68
|
+
`We have ${this._supportedCoins?.length} supported coins returning`,
|
|
69
|
+
loggerSource
|
|
70
|
+
);
|
|
71
|
+
return {
|
|
72
|
+
result: true,
|
|
73
|
+
coins: this._supportedCoins.map((item) => item.coin),
|
|
74
|
+
};
|
|
75
|
+
} catch (e) {
|
|
76
|
+
if (e?.response?.status === 429) {
|
|
77
|
+
return {
|
|
78
|
+
result: false,
|
|
79
|
+
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
improveAndRethrow(e, loggerSource);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
63
86
|
async getWithdrawalCurrencies(exceptCurrency = null) {
|
|
64
87
|
const loggerSource = "getWithdrawalCurrencies";
|
|
65
88
|
try {
|
|
@@ -302,6 +325,15 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
302
325
|
toCoin.ticker
|
|
303
326
|
);
|
|
304
327
|
}
|
|
328
|
+
if (
|
|
329
|
+
!fromCoinSwapspaceDetails.deposit ||
|
|
330
|
+
!toCoinSwapspaceDetails.withdrawal
|
|
331
|
+
) {
|
|
332
|
+
return {
|
|
333
|
+
result: false,
|
|
334
|
+
reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
305
337
|
/* Here we use not documented parameter 'estimated=false'. This parameter controls whether we want to use
|
|
306
338
|
* cached rate values stored in swapspace cache. Their support says they store at most for 30 sec.
|
|
307
339
|
* But we are better off using the most actual rates.
|
|
@@ -45,6 +45,31 @@ export class PublicSwapService {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
async getAllSupportedCurrenciesListForPublicSwap() {
|
|
49
|
+
const loggerSource = "getAllSupportedCurrenciesListForPublicSwap";
|
|
50
|
+
try {
|
|
51
|
+
const result = await this._swapProvider.getAllSupportedCurrencies();
|
|
52
|
+
if (
|
|
53
|
+
result.reason ===
|
|
54
|
+
SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
|
|
55
|
+
) {
|
|
56
|
+
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
57
|
+
return {
|
|
58
|
+
result: false,
|
|
59
|
+
reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS
|
|
60
|
+
.REQUESTS_LIMIT_EXCEEDED,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
Logger.log(
|
|
64
|
+
`Retrieved ${result?.coins?.length} supported currencies for swap`,
|
|
65
|
+
loggerSource
|
|
66
|
+
);
|
|
67
|
+
return { result: true, coins: result.coins };
|
|
68
|
+
} catch (e) {
|
|
69
|
+
improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
48
73
|
async getDepositCurrenciesListForPublicSwap() {
|
|
49
74
|
try {
|
|
50
75
|
return await this._getCurrenciesListForPublicSwap(false);
|
|
@@ -82,11 +107,6 @@ export class PublicSwapService {
|
|
|
82
107
|
`Retrieved ${result?.coins?.length} supported currencies for swap`,
|
|
83
108
|
loggerSource
|
|
84
109
|
);
|
|
85
|
-
if (result.coins.length > 1) {
|
|
86
|
-
let temp = result.coins[0];
|
|
87
|
-
result.coins[0] = result.coins[1];
|
|
88
|
-
result.coins[1] = temp;
|
|
89
|
-
}
|
|
90
110
|
return { result: true, coins: result.coins };
|
|
91
111
|
} catch (e) {
|
|
92
112
|
improveAndRethrow(e, loggerSource);
|