@rango-dev/queue-manager-rango-preset 0.22.1-next.10 → 0.22.1-next.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/package.json
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SwapQueueContext, SwapStorage } from '../types';
|
|
2
|
+
import type { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
3
|
+
import type { Transaction, TransactionStatusResponse } from 'rango-sdk';
|
|
4
|
+
import type { GenericSigner } from 'rango-types';
|
|
5
|
+
|
|
6
|
+
import { DEFAULT_ERROR_CODE } from '../constants';
|
|
2
7
|
import {
|
|
3
8
|
delay,
|
|
4
9
|
getCurrentStep,
|
|
5
10
|
getCurrentStepTx,
|
|
6
11
|
getCurrentStepTxType,
|
|
12
|
+
inMemoryTransactionsData,
|
|
7
13
|
resetNetworkStatus,
|
|
8
14
|
setCurrentStepTx,
|
|
9
15
|
updateSwapStatus,
|
|
10
|
-
inMemoryTransactionsData,
|
|
11
16
|
} from '../helpers';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
SwapActionTypes,
|
|
15
|
-
SwapQueueContext,
|
|
16
|
-
SwapStorage,
|
|
17
|
-
} from '../types';
|
|
17
|
+
import { httpService } from '../services';
|
|
18
|
+
import { notifier } from '../services/eventEmitter';
|
|
18
19
|
import {
|
|
19
20
|
getCurrentBlockchainOf,
|
|
20
21
|
getNextStep,
|
|
@@ -22,14 +23,11 @@ import {
|
|
|
22
23
|
getScannerUrl,
|
|
23
24
|
MessageSeverity,
|
|
24
25
|
} from '../shared';
|
|
25
|
-
import { Transaction, TransactionStatusResponse } from 'rango-sdk';
|
|
26
|
-
import { httpService } from '../services';
|
|
27
|
-
import type { GenericSigner } from 'rango-types';
|
|
28
26
|
import { prettifyErrorMessage } from '../shared-errors';
|
|
29
|
-
import {
|
|
30
|
-
import { DEFAULT_ERROR_CODE } from '../constants';
|
|
27
|
+
import { StepEventType, SwapActionTypes } from '../types';
|
|
31
28
|
|
|
32
|
-
const
|
|
29
|
+
const INTERVAL_FOR_CHECK_STATUS = 5_000;
|
|
30
|
+
const INTERVAL_FOR_CHECK_APPROVAL = 2_000;
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
33
|
* Subscribe to status of swap transaction by checking from server periodically.
|
|
@@ -53,10 +51,11 @@ async function checkTransactionStatus({
|
|
|
53
51
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
54
52
|
const currentStep = getCurrentStep(swap)!;
|
|
55
53
|
|
|
56
|
-
if (!currentStep?.executedTransactionId)
|
|
54
|
+
if (!currentStep?.executedTransactionId) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
57
|
const tx = getCurrentStepTx(currentStep);
|
|
58
58
|
let txId = currentStep.executedTransactionId;
|
|
59
|
-
let explorerUrlToUpdate = false;
|
|
60
59
|
let getTxReceiptFailed = false;
|
|
61
60
|
let status: TransactionStatusResponse | null = null;
|
|
62
61
|
let signer: GenericSigner<Transaction> | null = null;
|
|
@@ -66,11 +65,14 @@ async function checkTransactionStatus({
|
|
|
66
65
|
try {
|
|
67
66
|
const txType = getCurrentStepTxType(currentStep);
|
|
68
67
|
const sourceWallet = getRelatedWallet(swap, currentStep);
|
|
69
|
-
if (txType && sourceWallet)
|
|
68
|
+
if (txType && sourceWallet) {
|
|
70
69
|
signer = context.getSigners(sourceWallet.walletType).getSigner(txType);
|
|
70
|
+
}
|
|
71
71
|
} catch (error) {
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
/*
|
|
73
|
+
* wallet is not connected yet
|
|
74
|
+
* no need to do anything
|
|
75
|
+
*/
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
try {
|
|
@@ -83,9 +85,6 @@ async function checkTransactionStatus({
|
|
|
83
85
|
undefined;
|
|
84
86
|
const { hash: updatedTxHash, response: updatedTxResponse } =
|
|
85
87
|
await signer.wait(txId, chainId, txResponse);
|
|
86
|
-
if (updatedTxResponse?.isMultiSig) {
|
|
87
|
-
explorerUrlToUpdate = !updatedTxResponse.hashWasUpdated;
|
|
88
|
-
}
|
|
89
88
|
if (updatedTxHash !== txId) {
|
|
90
89
|
currentStep.executedTransactionId =
|
|
91
90
|
updatedTxHash || currentStep.executedTransactionId;
|
|
@@ -108,17 +107,16 @@ async function checkTransactionStatus({
|
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
txId = currentStep.executedTransactionId;
|
|
111
|
-
if (updatedTxHash && updatedTxResponse)
|
|
110
|
+
if (updatedTxHash && updatedTxResponse) {
|
|
112
111
|
setTransactionDataByHash(updatedTxHash, {
|
|
113
112
|
response: updatedTxResponse,
|
|
114
113
|
});
|
|
114
|
+
}
|
|
115
115
|
} else {
|
|
116
116
|
setTransactionDataByHash(updatedTxHash, {
|
|
117
117
|
receiptReceived: true,
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
-
} else if (!signer) {
|
|
121
|
-
explorerUrlToUpdate = true;
|
|
122
120
|
}
|
|
123
121
|
} catch (error) {
|
|
124
122
|
const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
|
|
@@ -143,8 +141,10 @@ async function checkTransactionStatus({
|
|
|
143
141
|
});
|
|
144
142
|
|
|
145
143
|
getTxReceiptFailed = true;
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
/*
|
|
145
|
+
* We shouldn't return here, because we need to trigger check status job in backend.
|
|
146
|
+
* This is not a ui requirement but the backend one.
|
|
147
|
+
*/
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
try {
|
|
@@ -155,16 +155,22 @@ async function checkTransactionStatus({
|
|
|
155
155
|
step: currentStep.id,
|
|
156
156
|
});
|
|
157
157
|
} catch (e) {
|
|
158
|
-
await delay(
|
|
158
|
+
await delay(INTERVAL_FOR_CHECK_STATUS);
|
|
159
159
|
retry();
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
/*
|
|
164
|
+
* If user cancel swap during check status api call,
|
|
165
|
+
* or getting transaction receipt failed,
|
|
166
|
+
* we should ignore check status response and return
|
|
167
|
+
*/
|
|
168
|
+
if (getTxReceiptFailed) {
|
|
169
|
+
return failed();
|
|
170
|
+
}
|
|
171
|
+
if (currentStep?.status === 'failed') {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
168
174
|
|
|
169
175
|
const outputAmount: string | null =
|
|
170
176
|
status?.outputAmount ||
|
|
@@ -178,9 +184,7 @@ async function checkTransactionStatus({
|
|
|
178
184
|
currentStep.diagnosisUrl =
|
|
179
185
|
status?.diagnosisUrl || currentStep.diagnosisUrl || null;
|
|
180
186
|
currentStep.outputAmount = outputAmount || currentStep.outputAmount;
|
|
181
|
-
currentStep.explorerUrl =
|
|
182
|
-
? status?.explorerUrl || currentStep.explorerUrl
|
|
183
|
-
: null;
|
|
187
|
+
currentStep.explorerUrl = status?.explorerUrl || currentStep.explorerUrl;
|
|
184
188
|
currentStep.internalSteps = status?.steps || null;
|
|
185
189
|
|
|
186
190
|
const newTransaction = status?.newTx;
|
|
@@ -192,13 +196,13 @@ async function checkTransactionStatus({
|
|
|
192
196
|
setCurrentStepTx(currentStep, newTransaction);
|
|
193
197
|
}
|
|
194
198
|
|
|
195
|
-
if (prevOutputAmount === null && outputAmount !== null)
|
|
199
|
+
if (prevOutputAmount === null && outputAmount !== null) {
|
|
196
200
|
notifier({
|
|
197
201
|
event: { type: StepEventType.OUTPUT_REVEALED, outputAmount },
|
|
198
202
|
swap: swap,
|
|
199
203
|
step: currentStep,
|
|
200
204
|
});
|
|
201
|
-
else if (prevOutputAmount === null && outputAmount === null) {
|
|
205
|
+
} else if (prevOutputAmount === null && outputAmount === null) {
|
|
202
206
|
// it is needed to set notification after reloading the page
|
|
203
207
|
notifier({
|
|
204
208
|
event: { type: StepEventType.CHECK_STATUS },
|
|
@@ -241,7 +245,7 @@ async function checkTransactionStatus({
|
|
|
241
245
|
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
242
246
|
next();
|
|
243
247
|
} else {
|
|
244
|
-
await delay(
|
|
248
|
+
await delay(INTERVAL_FOR_CHECK_STATUS);
|
|
245
249
|
retry();
|
|
246
250
|
}
|
|
247
251
|
}
|
|
@@ -263,7 +267,7 @@ async function checkApprovalStatus({
|
|
|
263
267
|
SwapActionTypes,
|
|
264
268
|
SwapQueueContext
|
|
265
269
|
>): Promise<void> {
|
|
266
|
-
const swap = getStorage().swapDetails
|
|
270
|
+
const swap = getStorage().swapDetails;
|
|
267
271
|
const { meta } = context;
|
|
268
272
|
const { getTransactionDataByHash, setTransactionDataByHash } =
|
|
269
273
|
inMemoryTransactionsData();
|
|
@@ -275,18 +279,23 @@ async function checkApprovalStatus({
|
|
|
275
279
|
}
|
|
276
280
|
const tx = getCurrentStepTx(currentStep);
|
|
277
281
|
|
|
278
|
-
if (!currentStep?.executedTransactionId)
|
|
282
|
+
if (!currentStep?.executedTransactionId) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
279
285
|
let txId = currentStep.executedTransactionId;
|
|
280
286
|
|
|
281
287
|
let signer: GenericSigner<Transaction> | null = null;
|
|
282
288
|
try {
|
|
283
289
|
const txType = getCurrentStepTxType(currentStep);
|
|
284
290
|
const sourceWallet = getRelatedWallet(swap, currentStep);
|
|
285
|
-
if (txType && sourceWallet)
|
|
291
|
+
if (txType && sourceWallet) {
|
|
286
292
|
signer = context.getSigners(sourceWallet.walletType).getSigner(txType);
|
|
293
|
+
}
|
|
287
294
|
} catch (error) {
|
|
288
|
-
|
|
289
|
-
|
|
295
|
+
/*
|
|
296
|
+
* wallet is not connected yet
|
|
297
|
+
* no need to do anything
|
|
298
|
+
*/
|
|
290
299
|
}
|
|
291
300
|
|
|
292
301
|
try {
|
|
@@ -321,10 +330,11 @@ async function checkApprovalStatus({
|
|
|
321
330
|
}
|
|
322
331
|
}
|
|
323
332
|
txId = currentStep.executedTransactionId;
|
|
324
|
-
if (updatedTxHash && updatedTxResponse)
|
|
333
|
+
if (updatedTxHash && updatedTxResponse) {
|
|
325
334
|
setTransactionDataByHash(updatedTxHash, {
|
|
326
335
|
response: updatedTxResponse,
|
|
327
336
|
});
|
|
337
|
+
}
|
|
328
338
|
} else {
|
|
329
339
|
setTransactionDataByHash(updatedTxHash, {
|
|
330
340
|
receiptReceived: true,
|
|
@@ -361,7 +371,9 @@ async function checkApprovalStatus({
|
|
|
361
371
|
currentStep.executedTransactionId
|
|
362
372
|
);
|
|
363
373
|
// If user cancel swap during check status api call, we should ignore check approval response
|
|
364
|
-
if (currentStep?.status === 'failed')
|
|
374
|
+
if (currentStep?.status === 'failed') {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
365
377
|
|
|
366
378
|
isApproved = response.isApproved;
|
|
367
379
|
if (
|
|
@@ -374,12 +386,16 @@ async function checkApprovalStatus({
|
|
|
374
386
|
details = 'Smart contract approval tx failed in blockchain.';
|
|
375
387
|
} else {
|
|
376
388
|
message = 'Not enough approval';
|
|
377
|
-
if (response.requiredApprovedAmount && response.currentApprovedAmount)
|
|
389
|
+
if (response.requiredApprovedAmount && response.currentApprovedAmount) {
|
|
378
390
|
details = `Required approval: ${response.requiredApprovedAmount}, current approval: ${response.currentApprovedAmount}`;
|
|
379
|
-
else
|
|
391
|
+
} else {
|
|
392
|
+
details = `You still don't have enough approval for this swap.`;
|
|
393
|
+
}
|
|
380
394
|
}
|
|
381
|
-
|
|
382
|
-
|
|
395
|
+
/*
|
|
396
|
+
* approve transaction failed on
|
|
397
|
+
* we should fail the whole swap
|
|
398
|
+
*/
|
|
383
399
|
const updateResult = updateSwapStatus({
|
|
384
400
|
getStorage,
|
|
385
401
|
setStorage,
|
|
@@ -436,7 +452,7 @@ async function checkApprovalStatus({
|
|
|
436
452
|
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
437
453
|
next();
|
|
438
454
|
} else {
|
|
439
|
-
await delay(
|
|
455
|
+
await delay(INTERVAL_FOR_CHECK_APPROVAL);
|
|
440
456
|
retry();
|
|
441
457
|
}
|
|
442
458
|
}
|
|
@@ -459,8 +475,10 @@ export async function checkStatus(
|
|
|
459
475
|
return;
|
|
460
476
|
}
|
|
461
477
|
|
|
462
|
-
|
|
463
|
-
|
|
478
|
+
/*
|
|
479
|
+
* Reset network status
|
|
480
|
+
* Because when check status is on `loading` or `failed` status, it shows previous message that isn't related to current state.
|
|
481
|
+
*/
|
|
464
482
|
resetNetworkStatus(actions);
|
|
465
483
|
|
|
466
484
|
if (currentStep.status === 'running') {
|