@rabbitio/ui-kit 1.0.0-beta.32 → 1.0.0-beta.34
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 +106 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +80 -27
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +106 -44
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +106 -44
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/swaps-lib/external-apis/swapProvider.js +15 -2
- package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +23 -12
- package/src/swaps-lib/models/existingSwap.js +13 -1
- package/src/swaps-lib/models/existingSwapWithFiatData.js +16 -1
- package/src/swaps-lib/services/publicSwapService.js +34 -7
package/package.json
CHANGED
|
@@ -130,6 +130,8 @@ export class SwapProvider {
|
|
|
130
130
|
* @param refundAddress {string}
|
|
131
131
|
* @param rawSwapData {Object|null}
|
|
132
132
|
* @param clientIpAddress {string}
|
|
133
|
+
* @param [toCurrencyExtraId=""] {string} optional extra ID
|
|
134
|
+
* @param [refundExtraId=""] {string} optional extra ID for refund address
|
|
133
135
|
* @return {Promise<({
|
|
134
136
|
* result: true,
|
|
135
137
|
* swapId: string,
|
|
@@ -139,7 +141,8 @@ export class SwapProvider {
|
|
|
139
141
|
* toCoin: Coin,
|
|
140
142
|
* toAmount: string,
|
|
141
143
|
* toAddress: string,
|
|
142
|
-
* rate: string
|
|
144
|
+
* rate: string,
|
|
145
|
+
* fromCurrencyExtraId: string|undefined
|
|
143
146
|
* }|{
|
|
144
147
|
* result: false,
|
|
145
148
|
* reason: string,
|
|
@@ -153,7 +156,9 @@ export class SwapProvider {
|
|
|
153
156
|
toAddress,
|
|
154
157
|
refundAddress,
|
|
155
158
|
rawSwapData = null,
|
|
156
|
-
clientIpAddress
|
|
159
|
+
clientIpAddress,
|
|
160
|
+
toCurrencyExtraId = "",
|
|
161
|
+
refundExtraId = ""
|
|
157
162
|
) {
|
|
158
163
|
throw new Error("Not implemented in base");
|
|
159
164
|
}
|
|
@@ -185,4 +190,12 @@ export class SwapProvider {
|
|
|
185
190
|
isAddressValidForAsset(asset, address) {
|
|
186
191
|
throw new Error("Not implemented in base");
|
|
187
192
|
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @param asset {Coin}
|
|
196
|
+
* @return {string|null}
|
|
197
|
+
*/
|
|
198
|
+
getExtraIdNameIfPresent(asset) {
|
|
199
|
+
throw new Error("Not implemented in base");
|
|
200
|
+
}
|
|
188
201
|
}
|
|
@@ -22,7 +22,7 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
22
22
|
) {
|
|
23
23
|
super();
|
|
24
24
|
this._supportedCoins = [];
|
|
25
|
-
this._URL = `${apiKeysProxyUrl}`;
|
|
25
|
+
this._URL = `${apiKeysProxyUrl}/swapspace`;
|
|
26
26
|
this._maxRateDigits = 20;
|
|
27
27
|
this.useRestrictedCoinsSet = useRestrictedCoinsSet;
|
|
28
28
|
this._customCoinBuilder = customCoinBuilder;
|
|
@@ -148,10 +148,6 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
148
148
|
loggerSource
|
|
149
149
|
);
|
|
150
150
|
let allowedCoins = rawResponse?.data ?? [];
|
|
151
|
-
// TODO: [feature, critical] add support for extra ID. task_id=7219d65d41c242a292dfa47479b8d63f
|
|
152
|
-
allowedCoins = allowedCoins.filter(
|
|
153
|
-
(c) => c.hasExtraId !== true && c.hasExtraId !== "true"
|
|
154
|
-
);
|
|
155
151
|
Logger.log(`Allowed cnt ${allowedCoins.length}`, loggerSource);
|
|
156
152
|
|
|
157
153
|
this._supportedCoins = allowedCoins
|
|
@@ -201,7 +197,8 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
201
197
|
coin: coin,
|
|
202
198
|
code: item.code,
|
|
203
199
|
network: item.network,
|
|
204
|
-
|
|
200
|
+
hasExtraId: item.hasExtraId,
|
|
201
|
+
extraIdName: item.extraIdName,
|
|
205
202
|
isPopular: !!item?.popular,
|
|
206
203
|
iconURL: item.icon
|
|
207
204
|
? `https://storage.swapspace.co${item.icon}`
|
|
@@ -537,7 +534,9 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
537
534
|
toAddress,
|
|
538
535
|
refundAddress,
|
|
539
536
|
rawSwapData,
|
|
540
|
-
clientIpAddress
|
|
537
|
+
clientIpAddress,
|
|
538
|
+
toCurrencyExtraId = "",
|
|
539
|
+
refundExtraId = ""
|
|
541
540
|
) {
|
|
542
541
|
const loggerSource = "createSwap";
|
|
543
542
|
const partner = rawSwapData?.partner;
|
|
@@ -567,10 +566,6 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
567
566
|
}
|
|
568
567
|
|
|
569
568
|
await this._fetchSupportedCurrenciesIfNeeded();
|
|
570
|
-
const toCurrencyExtraId =
|
|
571
|
-
this._supportedCoins.find(
|
|
572
|
-
(item) => item.coin?.ticker === toCoin?.ticker
|
|
573
|
-
)?.extraId ?? "";
|
|
574
569
|
const requestData = {
|
|
575
570
|
partner: partner,
|
|
576
571
|
fromCurrency: rawSwapData?.fromCurrency,
|
|
@@ -581,6 +576,7 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
581
576
|
amount: amount,
|
|
582
577
|
fixed: false,
|
|
583
578
|
extraId: toCurrencyExtraId ?? "",
|
|
579
|
+
refundExtraId: refundExtraId ?? "", // This param is not documented. But the refund is usually manual so this is not critical.
|
|
584
580
|
rateId: rawSwapData?.id,
|
|
585
581
|
userIp: clientIpAddress,
|
|
586
582
|
refund: refundAddress,
|
|
@@ -634,6 +630,7 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
634
630
|
toCoin.digits
|
|
635
631
|
),
|
|
636
632
|
toAddress: result?.to?.address,
|
|
633
|
+
fromCurrencyExtraId: result?.from?.extraId ?? "",
|
|
637
634
|
rate: AmountUtils.trim(rate, this._maxRateDigits),
|
|
638
635
|
};
|
|
639
636
|
}
|
|
@@ -799,7 +796,10 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
799
796
|
swap.to.transactionHash,
|
|
800
797
|
swap.blockExplorerTransactionUrl.to,
|
|
801
798
|
swap.to.address,
|
|
802
|
-
swap.partner
|
|
799
|
+
swap.partner,
|
|
800
|
+
swap.from.extraId ?? null,
|
|
801
|
+
swap.to.extraId ?? null,
|
|
802
|
+
swap.refundExtraId ?? null
|
|
803
803
|
);
|
|
804
804
|
})
|
|
805
805
|
.flat();
|
|
@@ -853,4 +853,15 @@ export class SwapspaceSwapProvider extends SwapProvider {
|
|
|
853
853
|
}
|
|
854
854
|
return false;
|
|
855
855
|
}
|
|
856
|
+
|
|
857
|
+
getExtraIdNameIfPresent(asset) {
|
|
858
|
+
try {
|
|
859
|
+
const assetData = this._supportedCoins.find(
|
|
860
|
+
(i) => i.coin?.ticker === asset?.ticker
|
|
861
|
+
);
|
|
862
|
+
return assetData?.hasExtraId ? assetData?.extraIdName : null;
|
|
863
|
+
} catch (e) {
|
|
864
|
+
improveAndRethrow(e, "getExtraIdNameIfPresent");
|
|
865
|
+
}
|
|
866
|
+
}
|
|
856
867
|
}
|
|
@@ -7,14 +7,20 @@ export class ExistingSwap {
|
|
|
7
7
|
* @param confirmations {number}
|
|
8
8
|
* @param rate {string}
|
|
9
9
|
* @param refundAddress {string}
|
|
10
|
+
* @param payToAddress {string}
|
|
10
11
|
* @param fromCoin {Coin}
|
|
11
12
|
* @param fromAmount {string}
|
|
12
13
|
* @param fromTransactionId {string}
|
|
14
|
+
* @param fromTransactionLink {string}
|
|
13
15
|
* @param toCoin {Coin}
|
|
14
16
|
* @param toAmount {string}
|
|
15
17
|
* @param toTransactionId {string|null}
|
|
18
|
+
* @param toTransactionLink {string}
|
|
16
19
|
* @param toAddress {string}
|
|
17
20
|
* @param partner {string}
|
|
21
|
+
* @param fromExtraId {string}
|
|
22
|
+
* @param toExtraId {string}
|
|
23
|
+
* @param refundExtraId {string}
|
|
18
24
|
*/
|
|
19
25
|
constructor(
|
|
20
26
|
swapId,
|
|
@@ -34,7 +40,10 @@ export class ExistingSwap {
|
|
|
34
40
|
toTransactionId,
|
|
35
41
|
toTransactionLink,
|
|
36
42
|
toAddress, // TODO: [refactoring, moderate] toAddress is not quite clear. How about recipientAddress? task_id=0815a111c99543b78d374217eadbde4f
|
|
37
|
-
partner
|
|
43
|
+
partner,
|
|
44
|
+
fromExtraId,
|
|
45
|
+
toExtraId,
|
|
46
|
+
refundExtraId
|
|
38
47
|
) {
|
|
39
48
|
this.swapId = swapId;
|
|
40
49
|
this.status = status;
|
|
@@ -54,5 +63,8 @@ export class ExistingSwap {
|
|
|
54
63
|
this.toAmount = toAmount;
|
|
55
64
|
this.toAddress = toAddress;
|
|
56
65
|
this.partner = partner;
|
|
66
|
+
this.fromExtraId = fromExtraId;
|
|
67
|
+
this.toExtraId = toExtraId;
|
|
68
|
+
this.refundExtraId = refundExtraId;
|
|
57
69
|
}
|
|
58
70
|
}
|
|
@@ -9,14 +9,20 @@ export class ExistingSwapWithFiatData extends ExistingSwap {
|
|
|
9
9
|
* @param confirmations {number}
|
|
10
10
|
* @param rate {string}
|
|
11
11
|
* @param refundAddress {string}
|
|
12
|
+
* @param payToAddress {string}
|
|
12
13
|
* @param fromCoin {Coin}
|
|
13
14
|
* @param fromAmount {string}
|
|
14
15
|
* @param fromTransactionId {string}
|
|
16
|
+
* @param fromTransactionLink {string}
|
|
15
17
|
* @param toCoin {Coin}
|
|
16
18
|
* @param toAmount {string}
|
|
17
19
|
* @param toTransactionId {string|null}
|
|
20
|
+
* @param toTransactionLink
|
|
18
21
|
* @param toAddress {string}
|
|
19
22
|
* @param partner {string}
|
|
23
|
+
* @param fromExtraId {string}
|
|
24
|
+
* @param toExtraId {string}
|
|
25
|
+
* @param refundExtraId {string}
|
|
20
26
|
* @param fromAmountFiat {number}
|
|
21
27
|
* @param toAmountFiat {number}
|
|
22
28
|
* @param fiatCurrencyCode {string}
|
|
@@ -41,6 +47,9 @@ export class ExistingSwapWithFiatData extends ExistingSwap {
|
|
|
41
47
|
toTransactionLink,
|
|
42
48
|
toAddress,
|
|
43
49
|
partner,
|
|
50
|
+
fromExtraId,
|
|
51
|
+
toExtraId,
|
|
52
|
+
refundExtraId,
|
|
44
53
|
fromAmountFiat,
|
|
45
54
|
toAmountFiat,
|
|
46
55
|
fiatCurrencyCode,
|
|
@@ -64,7 +73,10 @@ export class ExistingSwapWithFiatData extends ExistingSwap {
|
|
|
64
73
|
toTransactionId,
|
|
65
74
|
toTransactionLink,
|
|
66
75
|
toAddress,
|
|
67
|
-
partner
|
|
76
|
+
partner,
|
|
77
|
+
fromExtraId,
|
|
78
|
+
toExtraId,
|
|
79
|
+
refundExtraId
|
|
68
80
|
);
|
|
69
81
|
this.fromAmountFiat = fromAmountFiat;
|
|
70
82
|
this.toAmountFiat = toAmountFiat;
|
|
@@ -106,6 +118,9 @@ export class ExistingSwapWithFiatData extends ExistingSwap {
|
|
|
106
118
|
existingSwap.toTransactionLink,
|
|
107
119
|
existingSwap.toAddress,
|
|
108
120
|
existingSwap.partner,
|
|
121
|
+
existingSwap.fromExtraId,
|
|
122
|
+
existingSwap.toExtraId,
|
|
123
|
+
existingSwap.refundExtraId,
|
|
109
124
|
fromAmountFiat,
|
|
110
125
|
toAmountFiat,
|
|
111
126
|
fiatCurrencyCode,
|
|
@@ -173,6 +173,7 @@ export class PublicSwapService {
|
|
|
173
173
|
* @param fromCoin {Coin}
|
|
174
174
|
* @param toCoin {Coin}
|
|
175
175
|
* @param fromAmountCoins {string}
|
|
176
|
+
* @param [withoutFiat=false] {boolean} pass true if you don't need the fiat equivalent - this will diminish requests count
|
|
176
177
|
* @return {Promise<{
|
|
177
178
|
* result: false,
|
|
178
179
|
* reason: string,
|
|
@@ -186,12 +187,18 @@ export class PublicSwapService {
|
|
|
186
187
|
* swapCreationInfo: BaseSwapCreationInfo
|
|
187
188
|
* }>}
|
|
188
189
|
*/
|
|
189
|
-
async getPublicSwapDetails(
|
|
190
|
+
async getPublicSwapDetails(
|
|
191
|
+
fromCoin,
|
|
192
|
+
toCoin,
|
|
193
|
+
fromAmountCoins,
|
|
194
|
+
withoutFiat = false
|
|
195
|
+
) {
|
|
190
196
|
const loggerSource = "getPublicSwapDetails";
|
|
191
197
|
try {
|
|
192
|
-
const coinUsdtRate =
|
|
193
|
-
|
|
194
|
-
|
|
198
|
+
const coinUsdtRate = withoutFiat
|
|
199
|
+
? null
|
|
200
|
+
: (await this._swapProvider.getCoinToUSDTRate(fromCoin))
|
|
201
|
+
?.rate ?? null;
|
|
195
202
|
const details = await this._swapProvider.getSwapInfo(
|
|
196
203
|
fromCoin,
|
|
197
204
|
toCoin,
|
|
@@ -307,6 +314,8 @@ export class PublicSwapService {
|
|
|
307
314
|
* @param toAddress {string}
|
|
308
315
|
* @param refundAddress {string}
|
|
309
316
|
* @param clientIp {string}
|
|
317
|
+
* @param [toCurrencyExtraId] {string}
|
|
318
|
+
* @param [refundExtraId] {string}
|
|
310
319
|
* @return {Promise<{
|
|
311
320
|
* result: true,
|
|
312
321
|
* fiatCurrencyCode: string,
|
|
@@ -320,7 +329,8 @@ export class PublicSwapService {
|
|
|
320
329
|
* fiatCurrencyDecimals: number,
|
|
321
330
|
* fromCoin: Coin,
|
|
322
331
|
* rate: string,
|
|
323
|
-
* swapId: string
|
|
332
|
+
* swapId: string,
|
|
333
|
+
* fromCurrencyExtraId: string
|
|
324
334
|
* }|{
|
|
325
335
|
* result: false,
|
|
326
336
|
* reason: string
|
|
@@ -333,7 +343,9 @@ export class PublicSwapService {
|
|
|
333
343
|
swapCreationInfo,
|
|
334
344
|
toAddress,
|
|
335
345
|
refundAddress,
|
|
336
|
-
clientIp
|
|
346
|
+
clientIp,
|
|
347
|
+
toCurrencyExtraId,
|
|
348
|
+
refundExtraId
|
|
337
349
|
) {
|
|
338
350
|
const loggerSource = "createPublicSwap";
|
|
339
351
|
try {
|
|
@@ -367,7 +379,9 @@ export class PublicSwapService {
|
|
|
367
379
|
toAddress,
|
|
368
380
|
refundAddress,
|
|
369
381
|
swapCreationInfo.rawSwapData,
|
|
370
|
-
clientIp
|
|
382
|
+
clientIp,
|
|
383
|
+
toCurrencyExtraId,
|
|
384
|
+
refundExtraId
|
|
371
385
|
);
|
|
372
386
|
Logger.log(
|
|
373
387
|
`Created:${safeStringify({
|
|
@@ -450,6 +464,7 @@ export class PublicSwapService {
|
|
|
450
464
|
rate: result.rate,
|
|
451
465
|
durationMinutesRange: swapCreationInfo.durationMinutesRange,
|
|
452
466
|
address: result.fromAddress, // CRITICAL: this is the address to send coins to swaps provider
|
|
467
|
+
fromCurrencyExtraId: result.fromCurrencyExtraId ?? "", // CRITICAL: this is the extra ID for address to send coins to swaps provider
|
|
453
468
|
};
|
|
454
469
|
|
|
455
470
|
this._savePublicSwapIdLocally(result.swapId);
|
|
@@ -644,4 +659,16 @@ export class PublicSwapService {
|
|
|
644
659
|
}
|
|
645
660
|
return null;
|
|
646
661
|
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* @param asset {Coin}
|
|
665
|
+
* @return {string|null}
|
|
666
|
+
*/
|
|
667
|
+
getExtraIdNameIfPresentForAsset(asset) {
|
|
668
|
+
try {
|
|
669
|
+
return this._swapProvider.getExtraIdNameIfPresent(asset);
|
|
670
|
+
} catch (e) {
|
|
671
|
+
improveAndRethrow(e, "getExtraIdNameIfPresentForAsset");
|
|
672
|
+
}
|
|
673
|
+
}
|
|
647
674
|
}
|