@rango-dev/queue-manager-rango-preset 0.1.13-next.0 → 0.1.13-next.2

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/queue-manager-rango-preset",
3
- "version": "0.1.13-next.0",
3
+ "version": "0.1.13-next.2",
4
4
  "license": "MIT",
5
5
  "module": "dist/queue-manager-rango-preset.esm.js",
6
6
  "main": "dist/index.js",
@@ -1,5 +1,6 @@
1
1
  import { ExecuterActions } from '@rango-dev/queue-manager-core';
2
2
  import {
3
+ ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES,
3
4
  ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK,
4
5
  ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION,
5
6
  ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION_WRONG_WALLET,
@@ -14,6 +15,7 @@ import {
14
15
  resetNetworkStatus,
15
16
  getRequiredWallet,
16
17
  isNeedBlockQueueForParallel,
18
+ claimQueue,
17
19
  } from '../helpers';
18
20
  import { getCurrentBlockchainOf, PendingSwapNetworkStatus } from '../shared';
19
21
  import {
@@ -37,6 +39,7 @@ export async function executeTransaction(
37
39
  ): Promise<void> {
38
40
  const { getStorage, context } = actions;
39
41
  const { meta, wallets, providers } = context;
42
+ const { claimedBy } = claimQueue();
40
43
 
41
44
  const isClaimed = context.claimedBy === context._queue?.id;
42
45
  const requestBlock: typeof actions.block = (blockedFor) => {
@@ -73,22 +76,6 @@ export async function executeTransaction(
73
76
  return;
74
77
  }
75
78
 
76
- /*
77
- For avoiding conflict by making too many requests to wallet, we need to make sure
78
- We only run one request at a time (In parallel mode).
79
- */
80
- const needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
81
-
82
- if (needsToBlockQueue && !isClaimed) {
83
- const blockedFor = {
84
- reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
85
- description: 'Waiting for other swaps to complete',
86
- details: {},
87
- };
88
- requestBlock(blockedFor);
89
- return;
90
- }
91
-
92
79
  /* Wallet should be on correct network */
93
80
  const networkMatched = await isNetworkMatchedForTransaction(
94
81
  swap,
@@ -97,7 +84,18 @@ export async function executeTransaction(
97
84
  meta,
98
85
  providers
99
86
  );
100
- if (!networkMatched) {
87
+ const claimerId = claimedBy();
88
+ const isClaimedByAnyQueue = !!claimerId && !isClaimed;
89
+ if (isClaimedByAnyQueue && !networkMatched) {
90
+ const details = ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES;
91
+
92
+ const blockedFor = {
93
+ reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
94
+ details: details,
95
+ };
96
+ requestBlock(blockedFor);
97
+ return;
98
+ } else if (!networkMatched) {
101
99
  const fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
102
100
  const details = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(fromBlockchain);
103
101
 
@@ -116,6 +114,22 @@ export async function executeTransaction(
116
114
  });
117
115
  }
118
116
 
117
+ /*
118
+ For avoiding conflict by making too many requests to wallet, we need to make sure
119
+ We only run one request at a time (In parallel mode).
120
+ */
121
+ const needsToBlockQueue = isNeedBlockQueueForParallel(currentStep);
122
+
123
+ if (needsToBlockQueue && !isClaimed) {
124
+ const blockedFor = {
125
+ reason: BlockReason.DEPENDS_ON_OTHER_QUEUES,
126
+ description: ERROR_MESSAGE_DEPENDS_ON_OTHER_QUEUES,
127
+ details: {},
128
+ };
129
+ requestBlock(blockedFor);
130
+ return;
131
+ }
132
+
119
133
  // All the conditions are met. We can safely send the tx to wallet for sign.
120
134
  singTransaction(actions);
121
135
  }
package/src/helpers.ts CHANGED
@@ -79,7 +79,7 @@ let swapClaimedBy: { id: string } | null = null;
79
79
  * We simply use module-level variable to keep track of which queue has claimed the execution of parallel runnings.
80
80
  *
81
81
  */
82
- function claimQueue() {
82
+ export function claimQueue() {
83
83
  return {
84
84
  claimedBy: () => swapClaimedBy?.id,
85
85
  setClaimer: (queue_id: string) => {
@@ -543,6 +543,7 @@ export async function isNetworkMatchedForTransaction(
543
543
  WalletType.BRAVE,
544
544
  WalletType.FRONTIER,
545
545
  WalletType.KUCOIN,
546
+ WalletType.ENKRYPT,
546
547
  ].includes(sourceWallet.walletType)
547
548
  ) {
548
549
  const provider = getEvmProvider(providers, sourceWallet.walletType);