@rabbitio/ui-kit 1.0.0-beta.10 → 1.0.0-beta.11
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/CHANGELOG.md +0 -0
- package/README.md +14 -14
- package/dist/index.cjs +859 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +726 -6
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +851 -7
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +859 -6
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/common/models/blockchain.js +10 -0
- package/src/common/models/coin.js +157 -0
- package/src/common/models/protocol.js +5 -0
- package/src/common/utils/cache.js +268 -0
- package/src/common/utils/logging/logger.js +48 -0
- package/src/common/utils/logging/logsStorage.js +61 -0
- package/src/common/utils/safeStringify.js +50 -0
- package/src/components/atoms/AssetIcon/AssetIcon.jsx +5 -5
- package/src/index.js +14 -1
- package/src/swaps-lib/external-apis/swapProvider.js +169 -0
- package/src/swaps-lib/models/existingSwap.js +58 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
export class SwapProvider {
|
|
2
|
+
static COMMON_ERRORS = {
|
|
3
|
+
REQUESTS_LIMIT_EXCEEDED: "requestsLimitExceeded",
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
static NO_SWAPS_REASONS = {
|
|
7
|
+
TOO_LOW: "tooLow",
|
|
8
|
+
TOO_HIGH: "tooHigh",
|
|
9
|
+
NOT_SUPPORTED: "notSupported",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
static CREATION_FAIL_REASONS = {
|
|
13
|
+
RETRIABLE_FAIL: "retriableFail",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
static SWAP_STATUSES = {
|
|
17
|
+
WAITING_FOR_PAYMENT: "waiting_for_payment", // public +
|
|
18
|
+
CONFIRMING: "confirming",
|
|
19
|
+
PAYMENT_RECEIVED: "payment_received", // public +
|
|
20
|
+
EXCHANGING: "exchanging", // session full // public +
|
|
21
|
+
COMPLETED: "completed", // session full // public +
|
|
22
|
+
REFUNDED: "refunded", // session full // public +
|
|
23
|
+
EXPIRED: "expired", // public +
|
|
24
|
+
FAILED: "failed", // public +
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @return {Promise<void>}
|
|
29
|
+
*/
|
|
30
|
+
async initialize() {
|
|
31
|
+
throw new Error("Not implemented in base");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @return {number} milliseconds TTL
|
|
36
|
+
*/
|
|
37
|
+
getSwapCreationInfoTtlMs() {
|
|
38
|
+
throw new Error("Not implemented in base");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves all deposit 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 getDepositCurrencies() {
|
|
48
|
+
throw new Error("Not implemented in base");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves all withdrawable currencies supported by this swap provider.
|
|
53
|
+
* Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
|
|
54
|
+
*
|
|
55
|
+
* @param [exceptCurrency=null] {Coin|null}
|
|
56
|
+
* @return {Promise<({ result: true, coins: Coin[] }|{ result: false, reason: string })>}
|
|
57
|
+
*/
|
|
58
|
+
async getWithdrawalCurrencies(exceptCurrency = null) {
|
|
59
|
+
throw new Error("Not implemented in base");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves URL for coin icon or fallback if not found.
|
|
64
|
+
*
|
|
65
|
+
* @param coin {Coin|string} coin or rabbit-format of coin ticker
|
|
66
|
+
* @return {string}
|
|
67
|
+
*/
|
|
68
|
+
getIconUrl(coin) {
|
|
69
|
+
throw new Error("Not implemented in base");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Retrieves coin to USDT rate.
|
|
74
|
+
*
|
|
75
|
+
* @param coin {Coin}
|
|
76
|
+
* @return {{result: true, rate: string}|{result: false}}
|
|
77
|
+
*/
|
|
78
|
+
async getCoinToUSDTRate(coin) {
|
|
79
|
+
throw new Error("Not implemented in base");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves estimation for swapping giving coins amount.
|
|
84
|
+
* null min or max signals there is no corresponding limitation. undefined means that the limits were not retrieved.
|
|
85
|
+
* For fail result on of SwapProvider.NO_SWAPS_REASONS or SwapProvider.COMMON_ERRORS reasons will be returned.
|
|
86
|
+
*
|
|
87
|
+
* @param fromCoin {Coin}
|
|
88
|
+
* @param toCoin {Coin}
|
|
89
|
+
* @param amountCoins {string}
|
|
90
|
+
* @param [fromCoinToUsdRate=null] pass if you want to increase the min amount returned
|
|
91
|
+
* by provider with some fixed "insurance" amount to cover min amount fluctuations.
|
|
92
|
+
* @return {Promise<({
|
|
93
|
+
* result: false,
|
|
94
|
+
* reason: string,
|
|
95
|
+
* smallestMin: (string|null|undefined),
|
|
96
|
+
* greatestMax: (string|null|undefined),
|
|
97
|
+
* }|{
|
|
98
|
+
* result: true,
|
|
99
|
+
* min: (string|null),
|
|
100
|
+
* max: (string|null),
|
|
101
|
+
* smallestMin: (string|null),
|
|
102
|
+
* greatestMax: (string|null),
|
|
103
|
+
* rate: (string|null),
|
|
104
|
+
* durationMinutesRange: string,
|
|
105
|
+
* [rawSwapData]: Object
|
|
106
|
+
* })>}
|
|
107
|
+
*/
|
|
108
|
+
async getSwapInfo(fromCoin, toCoin, amountCoins, fromCoinToUsdRate = null) {
|
|
109
|
+
throw new Error("Not implemented in base");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* For fail result we return one of SwapProvider.CREATION_FAIL_REASONS or SwapProvider.COMMON_ERRORS.
|
|
114
|
+
*
|
|
115
|
+
* @param fromCoin {Coin}
|
|
116
|
+
* @param toCoin {Coin}
|
|
117
|
+
* @param amount {string}
|
|
118
|
+
* @param toAddress {string}
|
|
119
|
+
* @param refundAddress {string}
|
|
120
|
+
* @param rawSwapData {Object|null}
|
|
121
|
+
* @param clientIpAddress {string}
|
|
122
|
+
* @return {Promise<({
|
|
123
|
+
* result: true,
|
|
124
|
+
* swapId: string,
|
|
125
|
+
* fromCoin: Coin,
|
|
126
|
+
* fromAmount: string,
|
|
127
|
+
* fromAddress: string,
|
|
128
|
+
* toCoin: Coin,
|
|
129
|
+
* toAmount: string,
|
|
130
|
+
* toAddress: string,
|
|
131
|
+
* rate: string
|
|
132
|
+
* }|{
|
|
133
|
+
* result: false,
|
|
134
|
+
* reason: string,
|
|
135
|
+
* partner: string
|
|
136
|
+
* })>}
|
|
137
|
+
*/
|
|
138
|
+
async createSwap(fromCoin, toCoin, amount, toAddress, refundAddress, rawSwapData = null, clientIpAddress) {
|
|
139
|
+
throw new Error("Not implemented in base");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves details and status for swaps by given ids.
|
|
144
|
+
* If some swap is not found by id then there is no item in return list.
|
|
145
|
+
*
|
|
146
|
+
* @param swapIds {string[]}
|
|
147
|
+
* @return {Promise<{result: false, reason: string}|{result:true, swaps: ExistingSwap[]}>}
|
|
148
|
+
*/
|
|
149
|
+
async getExistingSwapsDetailsAndStatus(swapIds) {
|
|
150
|
+
throw new Error("Not implemented in base");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @param ticker {string}
|
|
155
|
+
* @return {Coin|null}
|
|
156
|
+
*/
|
|
157
|
+
getCoinByTickerIfPresent(ticker) {
|
|
158
|
+
throw new Error("Not implemented in base");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param asset {Coin}
|
|
163
|
+
* @param address {string}
|
|
164
|
+
* @return {boolean}
|
|
165
|
+
*/
|
|
166
|
+
isAddressValidForAsset(asset, address) {
|
|
167
|
+
throw new Error("Not implemented in base");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export class ExistingSwap {
|
|
2
|
+
/**
|
|
3
|
+
* @param swapId {string}
|
|
4
|
+
* @param status {SwapProvider.SWAP_STATUSES}
|
|
5
|
+
* @param createdAt {number}
|
|
6
|
+
* @param expiresAt {number}
|
|
7
|
+
* @param confirmations {number}
|
|
8
|
+
* @param rate {string}
|
|
9
|
+
* @param refundAddress {string}
|
|
10
|
+
* @param fromCoin {Coin}
|
|
11
|
+
* @param fromAmount {string}
|
|
12
|
+
* @param fromTransactionId {string}
|
|
13
|
+
* @param toCoin {Coin}
|
|
14
|
+
* @param toAmount {string}
|
|
15
|
+
* @param toTransactionId {string|null}
|
|
16
|
+
* @param toAddress {string}
|
|
17
|
+
* @param partner {string}
|
|
18
|
+
*/
|
|
19
|
+
constructor(
|
|
20
|
+
swapId,
|
|
21
|
+
status,
|
|
22
|
+
createdAt,
|
|
23
|
+
expiresAt,
|
|
24
|
+
confirmations,
|
|
25
|
+
rate,
|
|
26
|
+
refundAddress,
|
|
27
|
+
payToAddress,
|
|
28
|
+
fromCoin,
|
|
29
|
+
fromAmount,
|
|
30
|
+
fromTransactionId,
|
|
31
|
+
fromTransactionLink,
|
|
32
|
+
toCoin,
|
|
33
|
+
toAmount,
|
|
34
|
+
toTransactionId,
|
|
35
|
+
toTransactionLink,
|
|
36
|
+
toAddress, // TODO: [refactoring, moderate] toAddress is not quite clear. How about recipientAddress? task_id=0815a111c99543b78d374217eadbde4f
|
|
37
|
+
partner
|
|
38
|
+
) {
|
|
39
|
+
this.swapId = swapId;
|
|
40
|
+
this.status = status;
|
|
41
|
+
this.createdAt = createdAt;
|
|
42
|
+
this.expiresAt = expiresAt;
|
|
43
|
+
this.confirmations = confirmations;
|
|
44
|
+
this.rate = rate;
|
|
45
|
+
this.refundAddress = refundAddress;
|
|
46
|
+
this.payToAddress = payToAddress;
|
|
47
|
+
this.fromCoin = fromCoin;
|
|
48
|
+
this.fromTransactionId = fromTransactionId;
|
|
49
|
+
this.fromAmount = fromAmount;
|
|
50
|
+
this.fromTransactionLink = fromTransactionLink;
|
|
51
|
+
this.toCoin = toCoin;
|
|
52
|
+
this.toTransactionId = toTransactionId;
|
|
53
|
+
this.toTransactionLink = toTransactionLink;
|
|
54
|
+
this.toAmount = toAmount;
|
|
55
|
+
this.toAddress = toAddress;
|
|
56
|
+
this.partner = partner;
|
|
57
|
+
}
|
|
58
|
+
}
|