@rango-dev/queue-manager-rango-preset 0.24.0 → 0.24.1-next.0
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 -4
- package/dist/actions/checkStatus.d.ts +3 -2
- package/dist/actions/checkStatus.d.ts.map +1 -1
- package/dist/actions/executeTransaction.d.ts +2 -2
- package/dist/actions/executeTransaction.d.ts.map +1 -1
- package/dist/actions/scheduleNextStep.d.ts +3 -2
- package/dist/actions/scheduleNextStep.d.ts.map +1 -1
- package/dist/helpers.d.ts +10 -25
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/migration.d.ts.map +1 -1
- package/dist/services/eventEmitter.d.ts +2 -2
- package/dist/services/eventEmitter.d.ts.map +1 -1
- package/dist/shared-sentry.d.ts +2 -2
- package/dist/shared-sentry.d.ts.map +1 -1
- package/dist/shared.d.ts +5 -100
- package/dist/shared.d.ts.map +1 -1
- package/dist/types.d.ts +7 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/actions/checkStatus.ts +71 -53
- package/src/actions/executeTransaction.ts +23 -26
- package/src/actions/scheduleNextStep.ts +13 -10
- package/src/helpers.ts +149 -123
- package/src/index.ts +1 -9
- package/src/migration.ts +11 -11
- package/src/services/eventEmitter.ts +39 -22
- package/src/shared-sentry.ts +3 -2
- package/src/shared.ts +103 -182
- package/src/types.ts +18 -8
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
SwapQueueContext,
|
|
6
|
-
SwapStorage,
|
|
7
|
-
} from '../types';
|
|
1
|
+
import type { SwapQueueContext, SwapStorage } from '../types';
|
|
2
|
+
import type { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
3
|
+
import type { PendingSwapStep } from 'rango-types';
|
|
4
|
+
|
|
8
5
|
import {
|
|
9
6
|
getCurrentStep,
|
|
10
7
|
getLastSuccessfulStep,
|
|
11
8
|
isTxAlreadyCreated,
|
|
12
9
|
} from '../helpers';
|
|
13
10
|
import { notifier } from '../services/eventEmitter';
|
|
11
|
+
import { StepEventType, SwapActionTypes } from '../types';
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
*
|
|
@@ -30,7 +28,9 @@ export function scheduleNextStep({
|
|
|
30
28
|
}: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>): void {
|
|
31
29
|
const swap = getStorage().swapDetails;
|
|
32
30
|
const currentStep = getCurrentStep(swap);
|
|
33
|
-
const isFailed = swap.steps.find(
|
|
31
|
+
const isFailed = swap.steps.find(
|
|
32
|
+
(step: PendingSwapStep) => step.status === 'failed'
|
|
33
|
+
);
|
|
34
34
|
|
|
35
35
|
if (!!currentStep && !isFailed) {
|
|
36
36
|
if (isTxAlreadyCreated(swap, currentStep)) {
|
|
@@ -84,7 +84,10 @@ export function scheduleNextStep({
|
|
|
84
84
|
step: null,
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
if (isFailed)
|
|
88
|
-
|
|
87
|
+
if (isFailed) {
|
|
88
|
+
failed();
|
|
89
|
+
} else {
|
|
90
|
+
next();
|
|
91
|
+
}
|
|
89
92
|
}
|
|
90
93
|
}
|
package/src/helpers.ts
CHANGED
|
@@ -1,37 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from '@rango-dev/queue-manager-core';
|
|
7
|
-
import {
|
|
1
|
+
/* eslint-disable destructuring/in-params */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-floating-promises */
|
|
4
|
+
import type { SwapStatus, Wallet } from './shared';
|
|
5
|
+
import type {
|
|
8
6
|
ArrayElement,
|
|
9
|
-
|
|
10
|
-
StepEventType,
|
|
11
|
-
SwapActionTypes,
|
|
7
|
+
Step,
|
|
12
8
|
SwapQueueContext,
|
|
13
9
|
SwapQueueDef,
|
|
14
10
|
SwapStorage,
|
|
15
|
-
StepExecutionEventStatus,
|
|
16
|
-
StepExecutionBlockedEventStatus,
|
|
17
|
-
Step,
|
|
18
11
|
} from './types';
|
|
19
|
-
import {
|
|
20
|
-
|
|
12
|
+
import type {
|
|
13
|
+
ExecuterActions,
|
|
14
|
+
Manager,
|
|
15
|
+
QueueInfo,
|
|
16
|
+
QueueName,
|
|
17
|
+
QueueType,
|
|
18
|
+
} from '@rango-dev/queue-manager-core';
|
|
19
|
+
import type {
|
|
21
20
|
Meta,
|
|
22
21
|
Network,
|
|
23
|
-
|
|
22
|
+
Providers,
|
|
24
23
|
WalletState,
|
|
25
24
|
WalletType,
|
|
26
25
|
} from '@rango-dev/wallets-shared';
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
import {
|
|
30
|
-
Transaction,
|
|
31
|
-
TransactionType,
|
|
32
|
-
EvmBlockchainMeta,
|
|
26
|
+
import type {
|
|
33
27
|
CreateTransactionResponse,
|
|
28
|
+
EvmBlockchainMeta,
|
|
29
|
+
Transaction,
|
|
34
30
|
} from 'rango-sdk';
|
|
31
|
+
import type {
|
|
32
|
+
APIErrorCode,
|
|
33
|
+
PendingSwap,
|
|
34
|
+
PendingSwapStep,
|
|
35
|
+
SignerErrorCode,
|
|
36
|
+
StepStatus,
|
|
37
|
+
} from 'rango-types';
|
|
38
|
+
|
|
39
|
+
import { Status } from '@rango-dev/queue-manager-core';
|
|
40
|
+
import { readAccountAddress } from '@rango-dev/wallets-core';
|
|
41
|
+
import {
|
|
42
|
+
getBlockChainNameFromId,
|
|
43
|
+
getEvmProvider,
|
|
44
|
+
splitWalletNetwork,
|
|
45
|
+
} from '@rango-dev/wallets-shared';
|
|
46
|
+
import { TransactionType } from 'rango-sdk';
|
|
47
|
+
import { PendingSwapNetworkStatus } from 'rango-types';
|
|
35
48
|
|
|
36
49
|
import {
|
|
37
50
|
DEFAULT_ERROR_CODE,
|
|
@@ -39,32 +52,30 @@ import {
|
|
|
39
52
|
ERROR_MESSAGE_WAIT_FOR_WALLET,
|
|
40
53
|
ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION,
|
|
41
54
|
} from './constants';
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
55
|
+
import { httpService } from './services';
|
|
56
|
+
import { notifier } from './services/eventEmitter';
|
|
44
57
|
import {
|
|
58
|
+
getCurrentAddressOf,
|
|
45
59
|
getCurrentBlockchainOf,
|
|
46
60
|
getCurrentBlockchainOfOrNull,
|
|
47
|
-
|
|
61
|
+
getRelatedWallet,
|
|
48
62
|
getRelatedWalletOrNull,
|
|
63
|
+
getScannerUrl,
|
|
49
64
|
MessageSeverity,
|
|
50
|
-
PendingSwap,
|
|
51
|
-
PendingSwapNetworkStatus,
|
|
52
|
-
PendingSwapStep,
|
|
53
|
-
StepStatus,
|
|
54
|
-
SwapStatus,
|
|
55
|
-
Wallet,
|
|
56
|
-
getRelatedWallet,
|
|
57
|
-
getCurrentAddressOf,
|
|
58
65
|
} from './shared';
|
|
59
|
-
import { logRPCError } from './shared-sentry';
|
|
60
66
|
import {
|
|
61
|
-
PrettyError,
|
|
62
67
|
mapAppErrorCodesToAPIErrorCode,
|
|
63
68
|
prettifyErrorMessage,
|
|
69
|
+
PrettyError,
|
|
64
70
|
} from './shared-errors';
|
|
65
|
-
import {
|
|
66
|
-
import {
|
|
67
|
-
|
|
71
|
+
import { logRPCError } from './shared-sentry';
|
|
72
|
+
import {
|
|
73
|
+
BlockReason,
|
|
74
|
+
StepEventType,
|
|
75
|
+
StepExecutionBlockedEventStatus,
|
|
76
|
+
StepExecutionEventStatus,
|
|
77
|
+
SwapActionTypes,
|
|
78
|
+
} from './types';
|
|
68
79
|
|
|
69
80
|
type WhenTaskBlocked = Parameters<NonNullable<SwapQueueDef['whenTaskBlocked']>>;
|
|
70
81
|
type WhenTaskBlockedEvent = WhenTaskBlocked[0];
|
|
@@ -108,7 +119,9 @@ export function inMemoryTransactionsData() {
|
|
|
108
119
|
swapTransactionToDataMap[hash] || {},
|
|
109
120
|
setTransactionDataByHash: (hash: string, data: TransactionData) => {
|
|
110
121
|
const r = swapTransactionToDataMap[hash];
|
|
111
|
-
if (!r)
|
|
122
|
+
if (!r) {
|
|
123
|
+
swapTransactionToDataMap[hash] = {};
|
|
124
|
+
}
|
|
112
125
|
swapTransactionToDataMap[hash].response =
|
|
113
126
|
data.response || swapTransactionToDataMap[hash].response;
|
|
114
127
|
swapTransactionToDataMap[hash].receiptReceived =
|
|
@@ -119,29 +132,6 @@ export function inMemoryTransactionsData() {
|
|
|
119
132
|
};
|
|
120
133
|
}
|
|
121
134
|
|
|
122
|
-
/**
|
|
123
|
-
* Sample inputs are:
|
|
124
|
-
* - "metamask-ETH"
|
|
125
|
-
* - "metamask-BSC-BSC:0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
126
|
-
* - "token-pocket-BSC-BSC:0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
127
|
-
* Returns "wallet and network" separately, even if the wallet is dashed inside.
|
|
128
|
-
*
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
export function splitWalletNetwork(input: string): string[] {
|
|
132
|
-
const removedAddressInput = input?.split(':')[0] || '';
|
|
133
|
-
const splittedInput = removedAddressInput.split('-');
|
|
134
|
-
const network = splittedInput[splittedInput.length - 1];
|
|
135
|
-
const walletNetwork = splittedInput.slice(0, -1);
|
|
136
|
-
|
|
137
|
-
if (walletNetwork[walletNetwork.length - 1] === network) {
|
|
138
|
-
walletNetwork.pop();
|
|
139
|
-
}
|
|
140
|
-
const wallet = walletNetwork.join('-');
|
|
141
|
-
|
|
142
|
-
return [wallet, network];
|
|
143
|
-
}
|
|
144
|
-
|
|
145
135
|
/**
|
|
146
136
|
*
|
|
147
137
|
* Returns `steps`, if it's a `running` swap.
|
|
@@ -213,19 +203,25 @@ export const setCurrentStepTx = (
|
|
|
213
203
|
const txType = transaction.type;
|
|
214
204
|
switch (txType) {
|
|
215
205
|
case TransactionType.EVM:
|
|
216
|
-
if (transaction.isApprovalTx)
|
|
206
|
+
if (transaction.isApprovalTx) {
|
|
217
207
|
currentStep.evmApprovalTransaction = transaction;
|
|
218
|
-
else
|
|
208
|
+
} else {
|
|
209
|
+
currentStep.evmTransaction = transaction;
|
|
210
|
+
}
|
|
219
211
|
break;
|
|
220
212
|
case TransactionType.TRON:
|
|
221
|
-
if (transaction.isApprovalTx)
|
|
213
|
+
if (transaction.isApprovalTx) {
|
|
222
214
|
currentStep.tronApprovalTransaction = transaction;
|
|
223
|
-
else
|
|
215
|
+
} else {
|
|
216
|
+
currentStep.tronTransaction = transaction;
|
|
217
|
+
}
|
|
224
218
|
break;
|
|
225
219
|
case TransactionType.STARKNET:
|
|
226
|
-
if (transaction.isApprovalTx)
|
|
220
|
+
if (transaction.isApprovalTx) {
|
|
227
221
|
currentStep.starknetApprovalTransaction = transaction;
|
|
228
|
-
else
|
|
222
|
+
} else {
|
|
223
|
+
currentStep.starknetTransaction = transaction;
|
|
224
|
+
}
|
|
229
225
|
break;
|
|
230
226
|
case TransactionType.COSMOS:
|
|
231
227
|
currentStep.cosmosTransaction = transaction;
|
|
@@ -323,12 +319,17 @@ export function updateSwapStatus({
|
|
|
323
319
|
swap,
|
|
324
320
|
step: currentStep,
|
|
325
321
|
};
|
|
326
|
-
if (!!nextStepStatus && !!currentStep)
|
|
322
|
+
if (!!nextStepStatus && !!currentStep) {
|
|
323
|
+
currentStep.status = nextStepStatus;
|
|
324
|
+
}
|
|
327
325
|
|
|
328
|
-
if (nextStatus)
|
|
326
|
+
if (nextStatus) {
|
|
327
|
+
swap.status = nextStatus;
|
|
328
|
+
}
|
|
329
329
|
swap.hasAlreadyProceededToSign = hasAlreadyProceededToSign;
|
|
330
|
-
if (!!nextStatus && ['failed', 'success'].includes(nextStatus))
|
|
330
|
+
if (!!nextStatus && ['failed', 'success'].includes(nextStatus)) {
|
|
331
331
|
swap.finishTime = new Date().getTime().toString();
|
|
332
|
+
}
|
|
332
333
|
|
|
333
334
|
if (!!message || !!details) {
|
|
334
335
|
swap.extraMessage = message || '';
|
|
@@ -341,7 +342,7 @@ export function updateSwapStatus({
|
|
|
341
342
|
details && details.includes('Warning')
|
|
342
343
|
? 'Swap canceled by user.'
|
|
343
344
|
: details;
|
|
344
|
-
const walletType = getRelatedWalletOrNull(swap, currentStep
|
|
345
|
+
const walletType = getRelatedWalletOrNull(swap, currentStep)?.walletType;
|
|
345
346
|
swap.extraMessageSeverity = MessageSeverity.error;
|
|
346
347
|
|
|
347
348
|
const failureType = mapAppErrorCodesToAPIErrorCode(errorCode);
|
|
@@ -361,15 +362,23 @@ export function updateSwapStatus({
|
|
|
361
362
|
})
|
|
362
363
|
.then()
|
|
363
364
|
.catch();
|
|
364
|
-
} else if (!!nextStepStatus && ['running'].includes(nextStepStatus))
|
|
365
|
+
} else if (!!nextStepStatus && ['running'].includes(nextStepStatus)) {
|
|
365
366
|
swap.extraMessageSeverity = MessageSeverity.info;
|
|
366
|
-
else if (
|
|
367
|
+
} else if (
|
|
368
|
+
!!nextStepStatus &&
|
|
369
|
+
['success', 'approved'].includes(nextStepStatus)
|
|
370
|
+
) {
|
|
367
371
|
swap.extraMessageSeverity = MessageSeverity.success;
|
|
368
|
-
else if (
|
|
372
|
+
} else if (
|
|
373
|
+
nextStepStatus &&
|
|
374
|
+
['waitingForApproval'].includes(nextStepStatus)
|
|
375
|
+
) {
|
|
369
376
|
swap.extraMessageSeverity = MessageSeverity.warning;
|
|
377
|
+
}
|
|
370
378
|
|
|
371
|
-
if (nextStepStatus === 'running' && currentStep)
|
|
379
|
+
if (nextStepStatus === 'running' && currentStep) {
|
|
372
380
|
currentStep.startTransactionTime = new Date().getTime();
|
|
381
|
+
}
|
|
373
382
|
|
|
374
383
|
setStorage({
|
|
375
384
|
...getStorage(),
|
|
@@ -395,7 +404,7 @@ export function setStepTransactionIds(
|
|
|
395
404
|
const currentStep = getCurrentStep(swap)!;
|
|
396
405
|
currentStep.executedTransactionId = txId;
|
|
397
406
|
currentStep.executedTransactionTime = new Date().getTime().toString();
|
|
398
|
-
if (explorerUrl?.url)
|
|
407
|
+
if (explorerUrl?.url) {
|
|
399
408
|
currentStep.explorerUrl = [
|
|
400
409
|
...(currentStep.explorerUrl || []),
|
|
401
410
|
{
|
|
@@ -403,11 +412,15 @@ export function setStepTransactionIds(
|
|
|
403
412
|
description: explorerUrl.description || null,
|
|
404
413
|
},
|
|
405
414
|
];
|
|
415
|
+
}
|
|
406
416
|
|
|
407
417
|
const isApproval = isApprovalCurrentStepTx(currentStep);
|
|
408
418
|
|
|
409
|
-
if (isApproval)
|
|
410
|
-
|
|
419
|
+
if (isApproval) {
|
|
420
|
+
swap.extraMessage = 'Checking approve transaction status ...';
|
|
421
|
+
} else {
|
|
422
|
+
swap.extraMessage = 'Checking transaction status ...';
|
|
423
|
+
}
|
|
411
424
|
|
|
412
425
|
swap.extraMessageDetail = '';
|
|
413
426
|
swap.extraMessageSeverity = MessageSeverity.info;
|
|
@@ -447,7 +460,9 @@ export function markRunningSwapAsWaitingForConnectingWallet(
|
|
|
447
460
|
): void {
|
|
448
461
|
const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
|
|
449
462
|
const currentStep = getCurrentStep(swap);
|
|
450
|
-
if (!currentStep)
|
|
463
|
+
if (!currentStep) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
451
466
|
const currentTime = new Date();
|
|
452
467
|
swap.lastNotificationTime = currentTime.getTime().toString();
|
|
453
468
|
|
|
@@ -488,7 +503,9 @@ export function markRunningSwapAsSwitchingNetwork({
|
|
|
488
503
|
const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
|
|
489
504
|
|
|
490
505
|
const currentStep = getCurrentStep(swap);
|
|
491
|
-
if (!currentStep)
|
|
506
|
+
if (!currentStep) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
492
509
|
|
|
493
510
|
// Generate message
|
|
494
511
|
const { type } = getRequiredWallet(swap);
|
|
@@ -529,7 +546,9 @@ export function markRunningSwapAsDependsOnOtherQueues({
|
|
|
529
546
|
| undefined {
|
|
530
547
|
const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
|
|
531
548
|
const currentStep = getCurrentStep(swap);
|
|
532
|
-
if (!currentStep)
|
|
549
|
+
if (!currentStep) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
533
552
|
|
|
534
553
|
swap.networkStatusExtraMessage = '';
|
|
535
554
|
swap.networkStatusExtraMessageDetail = '';
|
|
@@ -555,7 +574,7 @@ export function markRunningSwapAsDependsOnOtherQueues({
|
|
|
555
574
|
};
|
|
556
575
|
}
|
|
557
576
|
|
|
558
|
-
export function delay(ms: number): Promise<unknown> {
|
|
577
|
+
export async function delay(ms: number): Promise<unknown> {
|
|
559
578
|
return new Promise((res) => setTimeout(res, ms));
|
|
560
579
|
}
|
|
561
580
|
|
|
@@ -586,23 +605,6 @@ export function isWalletNull(wallet: Wallet | null): boolean {
|
|
|
586
605
|
);
|
|
587
606
|
}
|
|
588
607
|
|
|
589
|
-
/**
|
|
590
|
-
* On our implementation for `wallets` package, We keep the instance in 2 ways
|
|
591
|
-
* If it's a single chain wallet, it returns the instance directly,
|
|
592
|
-
* If it's a multichain wallet, it returns a `Map` of instances.
|
|
593
|
-
* This function will get the `ETHEREUM` instance in both types.
|
|
594
|
-
*/
|
|
595
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
596
|
-
export function getEvmProvider(providers: Providers, type: WalletType): any {
|
|
597
|
-
if (type && providers[type]) {
|
|
598
|
-
// we need this because provider can return an instance or a map of instances, so what you are doing here is try to detect that.
|
|
599
|
-
if (providers[type].size) return providers[type].get(Networks.ETHEREUM);
|
|
600
|
-
|
|
601
|
-
return providers[type];
|
|
602
|
-
}
|
|
603
|
-
return null;
|
|
604
|
-
}
|
|
605
|
-
|
|
606
608
|
/**
|
|
607
609
|
* In a `PendingSwap`, each step needs a wallet to proceed,
|
|
608
610
|
* By using this function we can access what wallet exactly we need to run current step.
|
|
@@ -663,7 +665,9 @@ export async function isNetworkMatchedForTransaction(
|
|
|
663
665
|
return false;
|
|
664
666
|
}
|
|
665
667
|
const fromBlockChain = getCurrentBlockchainOfOrNull(swap, step);
|
|
666
|
-
if (!fromBlockChain)
|
|
668
|
+
if (!fromBlockChain) {
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
667
671
|
|
|
668
672
|
if (
|
|
669
673
|
meta.evmBasedChains.find(
|
|
@@ -685,13 +689,15 @@ export async function isNetworkMatchedForTransaction(
|
|
|
685
689
|
if (
|
|
686
690
|
blockChain &&
|
|
687
691
|
blockChain.toLowerCase() === fromBlockChain.toLowerCase()
|
|
688
|
-
)
|
|
692
|
+
) {
|
|
689
693
|
return true;
|
|
694
|
+
}
|
|
690
695
|
if (
|
|
691
696
|
blockChain &&
|
|
692
697
|
blockChain.toLowerCase() !== fromBlockChain.toLowerCase()
|
|
693
|
-
)
|
|
698
|
+
) {
|
|
694
699
|
return false;
|
|
700
|
+
}
|
|
695
701
|
}
|
|
696
702
|
}
|
|
697
703
|
} catch (e) {
|
|
@@ -831,7 +837,9 @@ export function onBlockForChangeNetwork(
|
|
|
831
837
|
const swap = queue.getStorage().swapDetails as SwapStorage['swapDetails'];
|
|
832
838
|
const currentStep = getCurrentStep(swap);
|
|
833
839
|
|
|
834
|
-
if (!currentStep || swap.status !== 'running')
|
|
840
|
+
if (!currentStep || swap.status !== 'running') {
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
835
843
|
|
|
836
844
|
const result = markRunningSwapAsSwitchingNetwork({
|
|
837
845
|
getStorage: queue.getStorage.bind(queue),
|
|
@@ -904,7 +912,9 @@ export function onDependsOnOtherQueues(
|
|
|
904
912
|
const claimerId = claimedBy();
|
|
905
913
|
const isClaimedByAnyQueue = !!claimerId;
|
|
906
914
|
|
|
907
|
-
if (claimerId === queue.id)
|
|
915
|
+
if (claimerId === queue.id) {
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
908
918
|
|
|
909
919
|
// Check if any queue `claimed` before, if yes, we don't should do anything.
|
|
910
920
|
if (isClaimedByAnyQueue) {
|
|
@@ -960,7 +970,9 @@ export function isRequiredWalletConnected(
|
|
|
960
970
|
const walletState = getState(type);
|
|
961
971
|
const { accounts, connected } = walletState;
|
|
962
972
|
const connectedAccounts = accounts || [];
|
|
963
|
-
if (!connected)
|
|
973
|
+
if (!connected) {
|
|
974
|
+
return { ok: false, reason: 'not_connected' };
|
|
975
|
+
}
|
|
964
976
|
|
|
965
977
|
const matched = connectedAccounts.some((account) => {
|
|
966
978
|
const { address: accountAddress } = readAccountAddress(account);
|
|
@@ -969,7 +981,7 @@ export function isRequiredWalletConnected(
|
|
|
969
981
|
return { ok: matched, reason: 'account_miss_match' };
|
|
970
982
|
}
|
|
971
983
|
|
|
972
|
-
export function
|
|
984
|
+
export function signTransaction(
|
|
973
985
|
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
974
986
|
): void {
|
|
975
987
|
const { setTransactionDataByHash } = inMemoryTransactionsData();
|
|
@@ -1075,11 +1087,12 @@ export function singTransaction(
|
|
|
1075
1087
|
},
|
|
1076
1088
|
...updateResult,
|
|
1077
1089
|
});
|
|
1078
|
-
} else
|
|
1090
|
+
} else {
|
|
1079
1091
|
notifier({
|
|
1080
1092
|
event: { type: eventType, status: StepExecutionEventStatus.SEND_TX },
|
|
1081
1093
|
...updateResult,
|
|
1082
1094
|
});
|
|
1095
|
+
}
|
|
1083
1096
|
|
|
1084
1097
|
if (hasAlreadyProceededToSign) {
|
|
1085
1098
|
failed();
|
|
@@ -1109,7 +1122,9 @@ export function singTransaction(
|
|
|
1109
1122
|
onFinish();
|
|
1110
1123
|
},
|
|
1111
1124
|
(error) => {
|
|
1112
|
-
if (swap.status === 'failed')
|
|
1125
|
+
if (swap.status === 'failed') {
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1113
1128
|
|
|
1114
1129
|
const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
|
|
1115
1130
|
prettifyErrorMessage(error);
|
|
@@ -1153,7 +1168,9 @@ export function checkWaitingForConnectWalletChange(params: {
|
|
|
1153
1168
|
const { wallet_network, evmChains, manager } = params;
|
|
1154
1169
|
const [wallet, network] = splitWalletNetwork(wallet_network);
|
|
1155
1170
|
// We only need change network for EVM chains.
|
|
1156
|
-
if (!evmChains.some((chain) => chain.name == network))
|
|
1171
|
+
if (!evmChains.some((chain) => chain.name == network)) {
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1157
1174
|
|
|
1158
1175
|
manager?.getAll().forEach((q) => {
|
|
1159
1176
|
const queueStorage = q.list.getStorage() as SwapStorage | undefined;
|
|
@@ -1267,7 +1284,9 @@ export function getRunningSwaps(manager: Manager): PendingSwap[] {
|
|
|
1267
1284
|
// retry only on affected queues
|
|
1268
1285
|
const queueStorage = q.list.getStorage() as SwapStorage | undefined;
|
|
1269
1286
|
const swap = queueStorage?.swapDetails;
|
|
1270
|
-
if (!swap || swap.status !== 'running')
|
|
1287
|
+
if (!swap || swap.status !== 'running') {
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1271
1290
|
result.push(swap);
|
|
1272
1291
|
});
|
|
1273
1292
|
return result;
|
|
@@ -1290,9 +1309,11 @@ export function resetRunningSwapNotifsOnPageLoad(runningSwaps: PendingSwap[]) {
|
|
|
1290
1309
|
| StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE
|
|
1291
1310
|
| StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT
|
|
1292
1311
|
| undefined;
|
|
1293
|
-
if (
|
|
1312
|
+
if (
|
|
1313
|
+
currentStep?.networkStatus === PendingSwapNetworkStatus.WaitingForQueue
|
|
1314
|
+
) {
|
|
1294
1315
|
eventSubtype = StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE;
|
|
1295
|
-
else if (swap?.status === 'running') {
|
|
1316
|
+
} else if (swap?.status === 'running') {
|
|
1296
1317
|
eventSubtype = StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT;
|
|
1297
1318
|
}
|
|
1298
1319
|
if (!!eventType && !!notifier) {
|
|
@@ -1377,22 +1398,25 @@ export function retryOn(
|
|
|
1377
1398
|
finalQueueToBeRun = onlyWalletMatched[0];
|
|
1378
1399
|
}
|
|
1379
1400
|
|
|
1380
|
-
if (!canSwitchNetworkTo?.(wallet, network))
|
|
1381
|
-
|
|
1401
|
+
if (!canSwitchNetworkTo?.(wallet, network)) {
|
|
1402
|
+
finalQueueToBeRun?.unblock();
|
|
1403
|
+
} else {
|
|
1404
|
+
finalQueueToBeRun?.checkBlock();
|
|
1405
|
+
}
|
|
1382
1406
|
}
|
|
1383
1407
|
|
|
1384
|
-
/*
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1408
|
+
/*
|
|
1409
|
+
*For avoiding conflict by making too many requests to wallet, we need to make sure
|
|
1410
|
+
*We only run one request at a time (In parallel mode).
|
|
1411
|
+
*/
|
|
1388
1412
|
export function isNeedBlockQueueForParallel(step: PendingSwapStep): boolean {
|
|
1389
1413
|
return !!step.evmTransaction || !!step.evmApprovalTransaction;
|
|
1390
1414
|
}
|
|
1391
1415
|
|
|
1392
1416
|
/*
|
|
1393
|
-
Create transaction endpoint doesn't return error code on http status code,
|
|
1394
|
-
For backward compatibilty with server and sdk, we use this wrapper to reject the promise.
|
|
1395
|
-
*/
|
|
1417
|
+
*Create transaction endpoint doesn't return error code on http status code,
|
|
1418
|
+
*For backward compatibilty with server and sdk, we use this wrapper to reject the promise.
|
|
1419
|
+
*/
|
|
1396
1420
|
export async function throwOnOK(
|
|
1397
1421
|
rawResponse: Promise<CreateTransactionResponse>
|
|
1398
1422
|
): Promise<CreateTransactionResponse> {
|
|
@@ -1438,7 +1462,9 @@ export function cancelSwap(
|
|
|
1438
1462
|
});
|
|
1439
1463
|
|
|
1440
1464
|
reset();
|
|
1441
|
-
if (manager)
|
|
1465
|
+
if (manager) {
|
|
1466
|
+
manager?.retry();
|
|
1467
|
+
}
|
|
1442
1468
|
|
|
1443
1469
|
return updateResult;
|
|
1444
1470
|
}
|
package/src/index.ts
CHANGED
|
@@ -33,29 +33,21 @@ export {
|
|
|
33
33
|
StepExecutionEventStatus,
|
|
34
34
|
StepExecutionBlockedEventStatus,
|
|
35
35
|
} from './types';
|
|
36
|
-
export type {
|
|
37
|
-
PendingSwapWithQueueID,
|
|
38
|
-
PendingSwapStep,
|
|
39
|
-
PendingSwap,
|
|
40
|
-
EventType,
|
|
41
|
-
} from './shared';
|
|
36
|
+
export type { PendingSwapWithQueueID, EventType } from './shared';
|
|
42
37
|
export {
|
|
43
38
|
getCurrentBlockchainOfOrNull,
|
|
44
39
|
getRelatedWalletOrNull,
|
|
45
40
|
getRelatedWallet,
|
|
46
41
|
MessageSeverity,
|
|
47
|
-
PendingSwapNetworkStatus,
|
|
48
42
|
calculatePendingSwap,
|
|
49
43
|
} from './shared';
|
|
50
44
|
export {
|
|
51
45
|
updateSwapStatus,
|
|
52
46
|
checkWaitingForNetworkChange,
|
|
53
47
|
getCurrentStep,
|
|
54
|
-
getEvmProvider,
|
|
55
48
|
cancelSwap,
|
|
56
49
|
getRequiredWallet,
|
|
57
50
|
getRunningSwaps,
|
|
58
|
-
splitWalletNetwork,
|
|
59
51
|
resetRunningSwapNotifsOnPageLoad,
|
|
60
52
|
isApprovalTX,
|
|
61
53
|
getLastSuccessfulStep,
|
package/src/migration.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
DB_NAME,
|
|
6
|
-
} from '@rango-dev/queue-manager-core';
|
|
1
|
+
import type { PersistedQueue } from '@rango-dev/queue-manager-core';
|
|
2
|
+
import type { PendingSwap } from 'rango-types';
|
|
3
|
+
|
|
4
|
+
import { DB_NAME, Persistor, Status } from '@rango-dev/queue-manager-core';
|
|
7
5
|
import { v4 as uuid } from 'uuid';
|
|
8
|
-
|
|
6
|
+
|
|
9
7
|
import { SwapActionTypes } from './types';
|
|
10
8
|
|
|
11
9
|
const MIGRATED_KEY = 'migratedToQueueManager';
|
|
@@ -49,9 +47,9 @@ async function migration(): Promise<boolean> {
|
|
|
49
47
|
const convertedSwaps: PersistedQueue[] = [];
|
|
50
48
|
|
|
51
49
|
swaps.forEach((swap) => {
|
|
52
|
-
/*
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
/*
|
|
51
|
+
*For running task we need to add some more work
|
|
52
|
+
*We need to create a queue task to be run and resume the running task from queue manager.
|
|
55
53
|
*/
|
|
56
54
|
if (swap.status === 'running') {
|
|
57
55
|
const taskId = uuid();
|
|
@@ -112,7 +110,9 @@ async function migration(): Promise<boolean> {
|
|
|
112
110
|
// Getting an instance from persistor, so we can directly put our data inside it.
|
|
113
111
|
const persistor = new Persistor();
|
|
114
112
|
|
|
115
|
-
const promises = convertedSwaps.map((queue) =>
|
|
113
|
+
const promises = convertedSwaps.map(async (queue) =>
|
|
114
|
+
persistor.insertQueue(queue)
|
|
115
|
+
);
|
|
116
116
|
await Promise.all(promises);
|
|
117
117
|
|
|
118
118
|
// Mark as the data has been successfully migrated.
|