@rango-dev/queue-manager-rango-preset 0.1.15-next.7 → 0.1.15-next.9
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/dist/actions/checkStatus.d.ts +11 -11
- package/dist/actions/checkStatus.d.ts.map +1 -1
- package/dist/actions/createTransaction.d.ts +10 -10
- package/dist/actions/createTransaction.d.ts.map +1 -1
- package/dist/actions/executeTransaction.d.ts +12 -12
- package/dist/actions/executeTransaction.d.ts.map +1 -1
- package/dist/actions/scheduleNextStep.d.ts +12 -12
- package/dist/actions/scheduleNextStep.d.ts.map +1 -1
- package/dist/actions/start.d.ts +3 -3
- package/dist/actions/start.d.ts.map +1 -1
- package/dist/configs.d.ts +7 -7
- package/dist/configs.d.ts.map +1 -1
- package/dist/constants.d.ts +5 -5
- package/dist/constants.d.ts.map +1 -1
- package/dist/helpers.d.ts +242 -232
- package/dist/helpers.d.ts.map +1 -1
- package/dist/hooks.d.ts +18 -18
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -8
- package/dist/index.js.map +7 -0
- package/dist/migration.d.ts +14 -14
- package/dist/migration.d.ts.map +1 -1
- package/dist/numbers.d.ts +2 -2
- package/dist/numbers.d.ts.map +1 -1
- package/dist/queueDef.d.ts +9 -9
- package/dist/queueDef.d.ts.map +1 -1
- package/dist/services/httpService.d.ts +2 -2
- package/dist/services/httpService.d.ts.map +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/shared-errors.d.ts +24 -24
- package/dist/shared-errors.d.ts.map +1 -1
- package/dist/shared-sentry.d.ts +3 -3
- package/dist/shared-sentry.d.ts.map +1 -1
- package/dist/shared.d.ts +158 -158
- package/dist/shared.d.ts.map +1 -1
- package/dist/types.d.ts +50 -50
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -5
- package/src/actions/checkStatus.ts +69 -34
- package/src/helpers.ts +20 -9
- package/src/index.ts +8 -6
- package/dist/queue-manager-rango-preset.cjs.development.js +0 -2779
- package/dist/queue-manager-rango-preset.cjs.development.js.map +0 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js +0 -2
- package/dist/queue-manager-rango-preset.cjs.production.min.js.map +0 -1
- package/dist/queue-manager-rango-preset.esm.js +0 -2758
- package/dist/queue-manager-rango-preset.esm.js.map +0 -1
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
resetNetworkStatus,
|
|
7
7
|
setCurrentStepTx,
|
|
8
8
|
updateSwapStatus,
|
|
9
|
-
|
|
9
|
+
useTransactionsData,
|
|
10
10
|
} from '../helpers';
|
|
11
11
|
import { SwapActionTypes, SwapQueueContext, SwapStorage } from '../types';
|
|
12
12
|
import {
|
|
@@ -35,17 +35,24 @@ async function checkTransactionStatus({
|
|
|
35
35
|
retry,
|
|
36
36
|
failed,
|
|
37
37
|
context,
|
|
38
|
-
}: ExecuterActions<
|
|
38
|
+
}: ExecuterActions<
|
|
39
|
+
SwapStorage,
|
|
40
|
+
SwapActionTypes,
|
|
41
|
+
SwapQueueContext
|
|
42
|
+
>): Promise<void> {
|
|
39
43
|
const swap = getStorage().swapDetails;
|
|
40
44
|
const { meta } = context;
|
|
41
45
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
42
46
|
const currentStep = getCurrentStep(swap)!;
|
|
47
|
+
|
|
48
|
+
if (!currentStep?.executedTransactionId) return;
|
|
43
49
|
let txId = currentStep.executedTransactionId;
|
|
44
50
|
|
|
45
51
|
let getTxReceiptFailed = false;
|
|
46
52
|
let status: TransactionStatusResponse | null = null;
|
|
47
53
|
let signer: GenericSigner<Transaction> | null = null;
|
|
48
|
-
const {
|
|
54
|
+
const { getTransactionDataByHash, setTransactionDataByHash } =
|
|
55
|
+
useTransactionsData();
|
|
49
56
|
|
|
50
57
|
try {
|
|
51
58
|
const txType = getCurrentStepTxType(currentStep);
|
|
@@ -59,19 +66,19 @@ async function checkTransactionStatus({
|
|
|
59
66
|
|
|
60
67
|
try {
|
|
61
68
|
// if wallet is connected, try to get transaction reciept
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
txResponse
|
|
67
|
-
);
|
|
69
|
+
const { response: txResponse, receiptReceived } =
|
|
70
|
+
getTransactionDataByHash(txId);
|
|
71
|
+
if (signer?.wait && !receiptReceived) {
|
|
72
|
+
const { hash: updatedTxHash, response: updatedTxResponse } =
|
|
73
|
+
await signer.wait(txId, txResponse);
|
|
68
74
|
if (updatedTxHash !== txId) {
|
|
69
|
-
currentStep.executedTransactionId =
|
|
75
|
+
currentStep.executedTransactionId =
|
|
76
|
+
updatedTxHash || currentStep.executedTransactionId;
|
|
70
77
|
const currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
|
|
71
78
|
const explorerUrl = getScannerUrl(
|
|
72
|
-
currentStep.executedTransactionId
|
|
79
|
+
currentStep.executedTransactionId,
|
|
73
80
|
currentStepBlockchain,
|
|
74
|
-
meta.blockchains
|
|
81
|
+
meta.blockchains
|
|
75
82
|
);
|
|
76
83
|
if (explorerUrl) {
|
|
77
84
|
if (currentStep.explorerUrl && currentStep.explorerUrl?.length >= 1) {
|
|
@@ -83,11 +90,18 @@ async function checkTransactionStatus({
|
|
|
83
90
|
}
|
|
84
91
|
txId = currentStep.executedTransactionId;
|
|
85
92
|
if (updatedTxHash && updatedTxResponse)
|
|
86
|
-
|
|
93
|
+
setTransactionDataByHash(updatedTxHash, {
|
|
94
|
+
response: updatedTxResponse,
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
setTransactionDataByHash(updatedTxHash, {
|
|
98
|
+
receiptReceived: true,
|
|
99
|
+
});
|
|
87
100
|
}
|
|
88
101
|
}
|
|
89
102
|
} catch (error) {
|
|
90
|
-
const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
|
|
103
|
+
const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
|
|
104
|
+
prettifyErrorMessage(error);
|
|
91
105
|
const updateResult = updateSwapStatus({
|
|
92
106
|
getStorage,
|
|
93
107
|
setStorage,
|
|
@@ -110,7 +124,7 @@ async function checkTransactionStatus({
|
|
|
110
124
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
111
125
|
status = await httpService().checkStatus({
|
|
112
126
|
requestId: swap.requestId,
|
|
113
|
-
txId
|
|
127
|
+
txId,
|
|
114
128
|
step: currentStep.id,
|
|
115
129
|
});
|
|
116
130
|
} catch (e) {
|
|
@@ -126,14 +140,16 @@ async function checkTransactionStatus({
|
|
|
126
140
|
if (currentStep?.status === 'failed') return;
|
|
127
141
|
|
|
128
142
|
const outputAmount: string | null =
|
|
129
|
-
status?.outputAmount ||
|
|
143
|
+
status?.outputAmount ||
|
|
144
|
+
(currentStep.outputAmount ? currentStep.outputAmount : null);
|
|
130
145
|
const prevOutputAmount = currentStep.outputAmount || null;
|
|
131
146
|
swap.extraMessage = status?.extraMessage || swap.extraMessage;
|
|
132
147
|
swap.extraMessageSeverity = MessageSeverity.info;
|
|
133
148
|
swap.extraMessageDetail = '';
|
|
134
149
|
|
|
135
150
|
currentStep.status = status?.status || currentStep.status;
|
|
136
|
-
currentStep.diagnosisUrl =
|
|
151
|
+
currentStep.diagnosisUrl =
|
|
152
|
+
status?.diagnosisUrl || currentStep.diagnosisUrl || null;
|
|
137
153
|
currentStep.outputAmount = outputAmount || currentStep.outputAmount;
|
|
138
154
|
currentStep.explorerUrl = status?.explorerUrl || currentStep.explorerUrl;
|
|
139
155
|
currentStep.internalSteps = status?.steps || null;
|
|
@@ -181,7 +197,10 @@ async function checkTransactionStatus({
|
|
|
181
197
|
|
|
182
198
|
if (status?.status === 'failed') {
|
|
183
199
|
failed();
|
|
184
|
-
} else if (
|
|
200
|
+
} else if (
|
|
201
|
+
status?.status === 'success' ||
|
|
202
|
+
(status?.status === 'running' && !!status.newTx)
|
|
203
|
+
) {
|
|
185
204
|
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
186
205
|
next();
|
|
187
206
|
} else {
|
|
@@ -202,10 +221,15 @@ async function checkApprovalStatus({
|
|
|
202
221
|
retry,
|
|
203
222
|
failed,
|
|
204
223
|
context,
|
|
205
|
-
}: ExecuterActions<
|
|
224
|
+
}: ExecuterActions<
|
|
225
|
+
SwapStorage,
|
|
226
|
+
SwapActionTypes,
|
|
227
|
+
SwapQueueContext
|
|
228
|
+
>): Promise<void> {
|
|
206
229
|
const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
|
|
207
230
|
const { meta } = context;
|
|
208
|
-
const {
|
|
231
|
+
const { getTransactionDataByHash, setTransactionDataByHash } =
|
|
232
|
+
useTransactionsData();
|
|
209
233
|
|
|
210
234
|
const currentStep = getCurrentStep(swap);
|
|
211
235
|
if (!currentStep) {
|
|
@@ -213,6 +237,7 @@ async function checkApprovalStatus({
|
|
|
213
237
|
return;
|
|
214
238
|
}
|
|
215
239
|
|
|
240
|
+
if (!currentStep?.executedTransactionId) return;
|
|
216
241
|
let txId = currentStep.executedTransactionId;
|
|
217
242
|
|
|
218
243
|
let signer: GenericSigner<Transaction> | null = null;
|
|
@@ -227,20 +252,20 @@ async function checkApprovalStatus({
|
|
|
227
252
|
}
|
|
228
253
|
|
|
229
254
|
try {
|
|
255
|
+
const { response: txResponse, receiptReceived } =
|
|
256
|
+
getTransactionDataByHash(txId);
|
|
230
257
|
// if wallet is connected, try to get transaction reciept
|
|
231
|
-
if (signer?.wait) {
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
txId!,
|
|
235
|
-
txResponse,
|
|
236
|
-
);
|
|
258
|
+
if (signer?.wait && !receiptReceived) {
|
|
259
|
+
const { hash: updatedTxHash, response: updatedTxResponse } =
|
|
260
|
+
await signer.wait(txId, txResponse);
|
|
237
261
|
if (updatedTxHash !== txId) {
|
|
238
|
-
currentStep.executedTransactionId =
|
|
262
|
+
currentStep.executedTransactionId =
|
|
263
|
+
updatedTxHash || currentStep.executedTransactionId;
|
|
239
264
|
const currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
|
|
240
265
|
const explorerUrl = getScannerUrl(
|
|
241
|
-
currentStep.executedTransactionId
|
|
266
|
+
currentStep.executedTransactionId,
|
|
242
267
|
currentStepBlockchain,
|
|
243
|
-
meta.blockchains
|
|
268
|
+
meta.blockchains
|
|
244
269
|
);
|
|
245
270
|
if (explorerUrl) {
|
|
246
271
|
if (currentStep.explorerUrl && currentStep.explorerUrl?.length >= 1) {
|
|
@@ -252,11 +277,18 @@ async function checkApprovalStatus({
|
|
|
252
277
|
}
|
|
253
278
|
txId = currentStep.executedTransactionId;
|
|
254
279
|
if (updatedTxHash && updatedTxResponse)
|
|
255
|
-
|
|
280
|
+
setTransactionDataByHash(updatedTxHash, {
|
|
281
|
+
response: updatedTxResponse,
|
|
282
|
+
});
|
|
283
|
+
} else {
|
|
284
|
+
setTransactionDataByHash(updatedTxHash, {
|
|
285
|
+
receiptReceived: true,
|
|
286
|
+
});
|
|
256
287
|
}
|
|
257
288
|
}
|
|
258
289
|
} catch (error) {
|
|
259
|
-
const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
|
|
290
|
+
const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
|
|
291
|
+
prettifyErrorMessage(error);
|
|
260
292
|
const updateResult = updateSwapStatus({
|
|
261
293
|
getStorage,
|
|
262
294
|
setStorage,
|
|
@@ -277,13 +309,16 @@ async function checkApprovalStatus({
|
|
|
277
309
|
try {
|
|
278
310
|
const response = await httpService().checkApproval(
|
|
279
311
|
swap.requestId,
|
|
280
|
-
currentStep.executedTransactionId
|
|
312
|
+
currentStep.executedTransactionId
|
|
281
313
|
);
|
|
282
314
|
// If user cancel swap during check status api call, we should ignore check approval response
|
|
283
315
|
if (currentStep?.status === 'failed') return;
|
|
284
316
|
|
|
285
317
|
isApproved = response.isApproved;
|
|
286
|
-
if (
|
|
318
|
+
if (
|
|
319
|
+
!isApproved &&
|
|
320
|
+
(response.txStatus === 'failed' || response.txStatus === 'success')
|
|
321
|
+
) {
|
|
287
322
|
let message, details;
|
|
288
323
|
if (response.txStatus === 'failed') {
|
|
289
324
|
message = 'Approve transaction failed';
|
|
@@ -360,7 +395,7 @@ async function checkApprovalStatus({
|
|
|
360
395
|
*
|
|
361
396
|
*/
|
|
362
397
|
export async function checkStatus(
|
|
363
|
-
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext
|
|
398
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
364
399
|
): Promise<void> {
|
|
365
400
|
const swap = actions.getStorage().swapDetails;
|
|
366
401
|
const currentStep = getCurrentStep(swap);
|
package/src/helpers.ts
CHANGED
|
@@ -93,16 +93,27 @@ export function claimQueue() {
|
|
|
93
93
|
/**
|
|
94
94
|
*
|
|
95
95
|
* We use module-level variable to keep track of
|
|
96
|
-
* map of transactions hash to the TransactionResponse
|
|
96
|
+
* map of transactions hash to the TransactionResponse and ...
|
|
97
97
|
*
|
|
98
98
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
type TransactionData = {
|
|
100
|
+
response?: any; // e.g. TransactionResponse in case of EVM transactions
|
|
101
|
+
receiptReceived?: boolean; // e.g. is TransactionReceipt ready in case of EVM transactions
|
|
102
|
+
};
|
|
103
|
+
const swapTransactionToDataMap: { [id: string]: TransactionData } = {};
|
|
104
|
+
export function useTransactionsData() {
|
|
101
105
|
return {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
getTransactionDataByHash: (hash: string) =>
|
|
107
|
+
swapTransactionToDataMap[hash] || {},
|
|
108
|
+
setTransactionDataByHash: (hash: string, data: TransactionData) => {
|
|
109
|
+
const r = swapTransactionToDataMap[hash];
|
|
110
|
+
if (!r) swapTransactionToDataMap[hash] = {};
|
|
111
|
+
swapTransactionToDataMap[hash].response =
|
|
112
|
+
data.response || swapTransactionToDataMap[hash].response;
|
|
113
|
+
swapTransactionToDataMap[hash].receiptReceived =
|
|
114
|
+
data.receiptReceived ||
|
|
115
|
+
swapTransactionToDataMap[hash].receiptReceived ||
|
|
116
|
+
false;
|
|
106
117
|
},
|
|
107
118
|
};
|
|
108
119
|
}
|
|
@@ -895,7 +906,7 @@ export function isRequiredWalletConnected(
|
|
|
895
906
|
export function singTransaction(
|
|
896
907
|
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
897
908
|
): void {
|
|
898
|
-
const {
|
|
909
|
+
const { setTransactionDataByHash } = useTransactionsData();
|
|
899
910
|
const { getStorage, setStorage, failed, next, schedule, context } = actions;
|
|
900
911
|
const { meta, getSigners, notifier, isMobileWallet } = context;
|
|
901
912
|
const swap = getStorage().swapDetails;
|
|
@@ -998,7 +1009,7 @@ export function singTransaction(
|
|
|
998
1009
|
: undefined
|
|
999
1010
|
);
|
|
1000
1011
|
// response used for evm transactions to get receipt and track replaced
|
|
1001
|
-
response &&
|
|
1012
|
+
response && setTransactionDataByHash(hash, { response });
|
|
1002
1013
|
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1003
1014
|
next();
|
|
1004
1015
|
onFinish();
|
package/src/index.ts
CHANGED
|
@@ -3,18 +3,20 @@ import { SwapQueueDef } from './types';
|
|
|
3
3
|
import { swapQueueDef } from './queueDef';
|
|
4
4
|
|
|
5
5
|
export { PrettyError, prettifyErrorMessage } from './shared-errors';
|
|
6
|
-
export { SwapQueueContext, SwapStorage } from './types';
|
|
7
|
-
export {
|
|
6
|
+
export type { SwapQueueContext, SwapStorage } from './types';
|
|
7
|
+
export type {
|
|
8
8
|
PendingSwapWithQueueID,
|
|
9
|
+
PendingSwapStep,
|
|
10
|
+
PendingSwap,
|
|
11
|
+
EventType,
|
|
12
|
+
SwapProgressNotification,
|
|
13
|
+
} from './shared';
|
|
14
|
+
export {
|
|
9
15
|
getCurrentBlockchainOfOrNull,
|
|
10
16
|
getRelatedWalletOrNull,
|
|
11
17
|
getRelatedWallet,
|
|
12
18
|
MessageSeverity,
|
|
13
|
-
PendingSwapStep,
|
|
14
19
|
PendingSwapNetworkStatus,
|
|
15
|
-
PendingSwap,
|
|
16
|
-
EventType,
|
|
17
|
-
SwapProgressNotification,
|
|
18
20
|
calculatePendingSwap,
|
|
19
21
|
} from './shared';
|
|
20
22
|
export {
|