@rango-dev/queue-manager-rango-preset 0.1.12 → 0.1.13-next.1

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.12",
3
+ "version": "0.1.13-next.1",
4
4
  "license": "MIT",
5
5
  "module": "dist/queue-manager-rango-preset.esm.js",
6
6
  "main": "dist/index.js",
@@ -53,6 +53,9 @@ async function checkTransactionStatus({
53
53
  return;
54
54
  }
55
55
 
56
+ // If user cancel swap during check status api call, we should ignore check status response
57
+ if (currentStep?.status === 'failed') return;
58
+
56
59
  const outputAmount: string | null =
57
60
  status?.outputAmount ||
58
61
  (!!currentStep.outputAmount ? currentStep.outputAmount : null);
@@ -166,13 +169,6 @@ async function checkApprovalStatus({
166
169
  SwapQueueContext
167
170
  >): Promise<void> {
168
171
  const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
169
- // double check it after fixing parallel
170
- // const onFinish = () => {
171
- // // TODO resetClaimedBy is undefined here
172
- // if (context.resetClaimedBy) {
173
- // context.resetClaimedBy();
174
- // }
175
- // };
176
172
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
177
173
  const currentStep = getCurrentStep(swap)!;
178
174
  let isApproved = false;
@@ -181,6 +177,9 @@ async function checkApprovalStatus({
181
177
  swap.requestId,
182
178
  currentStep.executedTransactionId || ''
183
179
  );
180
+ // If user cancel swap during check status api call, we should ignore check approval response
181
+ if (currentStep?.status === 'failed') return;
182
+
184
183
  isApproved = response.isApproved;
185
184
  if (!isApproved && response.txStatus === 'failed') {
186
185
  // approve transaction failed on
@@ -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) => {
@@ -1733,11 +1733,7 @@ export function retryOn(
1733
1733
  We only run one request at a time (In parallel mode).
1734
1734
  */
1735
1735
  export function isNeedBlockQueueForParallel(step: PendingSwapStep): boolean {
1736
- return (
1737
- !!step.evmTransaction ||
1738
- !!step.evmApprovalTransaction ||
1739
- !!step.cosmosTransaction
1740
- );
1736
+ return !!step.evmTransaction || !!step.evmApprovalTransaction;
1741
1737
  }
1742
1738
 
1743
1739
  /*