@rango-dev/queue-manager-rango-preset 0.1.15-next.3 → 0.1.15-next.5
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.map +1 -1
- package/dist/actions/createTransaction.d.ts.map +1 -1
- package/dist/helpers.d.ts +39 -13
- package/dist/helpers.d.ts.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.development.js +396 -580
- package/dist/queue-manager-rango-preset.cjs.development.js.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js.map +1 -1
- package/dist/queue-manager-rango-preset.esm.js +398 -582
- package/dist/queue-manager-rango-preset.esm.js.map +1 -1
- package/dist/shared.d.ts +5 -5
- package/dist/shared.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/actions/checkStatus.ts +171 -73
- package/src/actions/createTransaction.ts +5 -50
- package/src/helpers.ts +256 -672
- package/src/shared.ts +31 -33
package/dist/shared.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
2
|
-
import { CosmosTransaction,
|
|
2
|
+
import { CosmosTransaction, EvmTransaction, SimulationResult, SolanaTransaction, StarknetTransaction, TronTransaction, Transfer as TransferTransaction, AmountRestrictionType, BestRouteResponse, MetaResponse, Token, SwapResult, BlockchainMeta } from 'rango-sdk';
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
export interface PendingSwapWithQueueID {
|
|
5
5
|
id: string;
|
|
@@ -37,7 +37,7 @@ export declare type Blockchain = {
|
|
|
37
37
|
export declare type Wallet = {
|
|
38
38
|
blockchains: Blockchain[];
|
|
39
39
|
};
|
|
40
|
-
export declare type EventType = 'swap_started' | 'confirm_contract' | 'confirm_transfer' | 'task_failed' | 'task_completed' | 'task_canceled' | 'task_paused' | 'contract_confirmed' | 'confirm_approve_contract' | 'contract_rejected' | 'check_tx_status' | 'check_approve_tx_status' | 'transfer_rejected' | 'transfer_failed' | 'calling_smart_contract' | 'smart_contract_called' | 'smart_contract_call_failed' | 'step_completed_with_output' | 'waiting_for_network_change' | 'waiting_for_connecting_wallet' | 'waiting_for_change_wallet_account' | 'network_changed' | 'not_enough_balance' | 'waiting_for_queue' | 'check_fee_failed' | 'route_failed_to_find' | 'transaction_expired';
|
|
40
|
+
export declare type EventType = 'swap_started' | 'confirm_contract' | 'confirm_transfer' | 'task_failed' | 'task_completed' | 'task_canceled' | 'task_paused' | 'contract_confirmed' | 'confirm_approve_contract' | 'contract_rejected' | 'check_tx_status' | 'check_approve_tx_status' | 'transfer_rejected' | 'transfer_failed' | 'calling_smart_contract' | 'smart_contract_called' | 'smart_contract_call_failed' | 'step_completed_with_output' | 'waiting_for_network_change' | 'waiting_for_connecting_wallet' | 'waiting_for_change_wallet_account' | 'network_changed' | 'not_enough_balance' | 'not_enough_approval' | 'waiting_for_queue' | 'check_fee_failed' | 'route_failed_to_find' | 'transaction_expired';
|
|
41
41
|
export declare type SwapSavedSettings = {
|
|
42
42
|
slippage: string;
|
|
43
43
|
disabledSwappersIds?: string[];
|
|
@@ -140,9 +140,9 @@ export declare type PendingSwap = {
|
|
|
140
140
|
};
|
|
141
141
|
export declare const getCurrentBlockchainOfOrNull: (swap: PendingSwap, step: PendingSwapStep) => Network | null;
|
|
142
142
|
export declare const getCurrentBlockchainOf: (swap: PendingSwap, step: PendingSwapStep) => Network;
|
|
143
|
-
export declare const
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
export declare const getScannerUrl: (txHash: string, network: Network, blockchainMetaMap: {
|
|
144
|
+
[key: string]: BlockchainMeta;
|
|
145
|
+
}) => string | undefined;
|
|
146
146
|
export declare function getNextStep(swap: PendingSwap, currentStep: PendingSwapStep): PendingSwapStep | null;
|
|
147
147
|
/**
|
|
148
148
|
* Returns the wallet address, based on the current step of `PendingSwap`.
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EACL,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,QAAQ,IAAI,mBAAmB,EAC/B,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,KAAK,EACL,UAAU,EACV,cAAc,EACf,MAAM,WAAW,CAAC;AAGnB,OAAO,SAAS,MAAM,cAAc,CAAC;AASrC,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,oBAAY,wBAAwB,GAAG;IACrC,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,oBAAY,aAAa,GAAG;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,oBAAY,OAAO,GAAG;IACpB,QAAQ,EAAE,aAAa,EAAE,GAAG,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B,WAAW,EAAE,eAAe,GAC3B,oBAAoB,GAAG,IAAI,CAM7B;AAED,eAAO,MAAM,WAAW,eACV,MAAM,UACV,MAAM,WACL,MAAM,GAAG,IAAI,aACX,KAAK,EAAE,KACjB,MAAM,GAAG,IAQX,CAAC;AAEF,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,KAAK,EAAE,GACjB,SAAS,CAkBX;AAED,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAAA;CAAE,EAC9C,QAAQ,EAAE,iBAAiB,EAC3B,oBAAoB,EAAE,OAAO,EAC7B,IAAI,EAAE,YAAY,GAAG,IAAI,GACxB,WAAW,CAwFb"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/queue-manager-rango-preset",
|
|
3
|
-
"version": "0.1.15-next.
|
|
3
|
+
"version": "0.1.15-next.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"module": "dist/queue-manager-rango-preset.esm.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"typings": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"files": [
|
|
9
10
|
"dist",
|
|
10
11
|
"src"
|
|
11
12
|
],
|
|
12
13
|
"scripts": {
|
|
13
|
-
"dev": "tsdx watch",
|
|
14
|
+
"dev": "tsdx watch --tsconfig ./tsconfig.json",
|
|
14
15
|
"build": "tsdx build --tsconfig ./tsconfig.json",
|
|
15
16
|
"analyze": "size-limit --why",
|
|
16
17
|
"clean": "rimraf dist",
|
|
@@ -2,21 +2,26 @@ import { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
|
2
2
|
import {
|
|
3
3
|
delay,
|
|
4
4
|
getCurrentStep,
|
|
5
|
-
|
|
6
|
-
isEvmTransaction,
|
|
7
|
-
isSolanaTransaction,
|
|
8
|
-
isStarknetTransaction,
|
|
9
|
-
isTrasnferTransaction,
|
|
10
|
-
isTronTransaction,
|
|
5
|
+
getCurrentStepTxType,
|
|
11
6
|
resetNetworkStatus,
|
|
7
|
+
setCurrentStepTx,
|
|
12
8
|
updateSwapStatus,
|
|
9
|
+
useTransactionsResponse,
|
|
13
10
|
} from '../helpers';
|
|
14
11
|
import { SwapActionTypes, SwapQueueContext, SwapStorage } from '../types';
|
|
15
|
-
import {
|
|
16
|
-
|
|
12
|
+
import {
|
|
13
|
+
getCurrentBlockchainOf,
|
|
14
|
+
getNextStep,
|
|
15
|
+
getRelatedWallet,
|
|
16
|
+
getScannerUrl,
|
|
17
|
+
MessageSeverity,
|
|
18
|
+
} from '../shared';
|
|
19
|
+
import { Transaction, TransactionStatusResponse } from 'rango-sdk';
|
|
17
20
|
import { httpService } from '../services';
|
|
21
|
+
import { GenericSigner } from 'rango-types';
|
|
22
|
+
import { prettifyErrorMessage } from '../shared-errors';
|
|
18
23
|
|
|
19
|
-
const INTERVAL_FOR_CHECK =
|
|
24
|
+
const INTERVAL_FOR_CHECK = 5_000;
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
27
|
* Subscribe to status of swap transaction by checking from server periodically.
|
|
@@ -30,17 +35,77 @@ async function checkTransactionStatus({
|
|
|
30
35
|
retry,
|
|
31
36
|
failed,
|
|
32
37
|
context,
|
|
33
|
-
}: ExecuterActions<
|
|
34
|
-
SwapStorage,
|
|
35
|
-
SwapActionTypes,
|
|
36
|
-
SwapQueueContext
|
|
37
|
-
>): Promise<void> {
|
|
38
|
+
}: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>): Promise<void> {
|
|
38
39
|
const swap = getStorage().swapDetails;
|
|
40
|
+
const { meta } = context;
|
|
39
41
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
40
42
|
const currentStep = getCurrentStep(swap)!;
|
|
41
|
-
|
|
43
|
+
let txId = currentStep.executedTransactionId;
|
|
42
44
|
|
|
45
|
+
let getTxReceiptFailed = false;
|
|
43
46
|
let status: TransactionStatusResponse | null = null;
|
|
47
|
+
let signer: GenericSigner<Transaction> | null = null;
|
|
48
|
+
const { getTransactionResponseByHash, setTransactionResponseByHash } = useTransactionsResponse();
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const txType = getCurrentStepTxType(currentStep);
|
|
52
|
+
const sourceWallet = getRelatedWallet(swap, currentStep);
|
|
53
|
+
if (txType && sourceWallet)
|
|
54
|
+
signer = context.getSigners(sourceWallet.walletType).getSigner(txType);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
// wallet is not connected yet
|
|
57
|
+
// no need to do anything
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
// if wallet is connected, try to get transaction reciept
|
|
62
|
+
if (signer?.wait) {
|
|
63
|
+
const txResponse = getTransactionResponseByHash(txId!);
|
|
64
|
+
const { hash: updatedTxHash, response: updatedTxResponse } = await signer.wait(
|
|
65
|
+
txId!,
|
|
66
|
+
txResponse,
|
|
67
|
+
);
|
|
68
|
+
if (updatedTxHash !== txId) {
|
|
69
|
+
currentStep.executedTransactionId = updatedTxHash || currentStep.executedTransactionId;
|
|
70
|
+
const currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
|
|
71
|
+
const explorerUrl = getScannerUrl(
|
|
72
|
+
currentStep.executedTransactionId!,
|
|
73
|
+
currentStepBlockchain,
|
|
74
|
+
meta.blockchains,
|
|
75
|
+
);
|
|
76
|
+
if (explorerUrl) {
|
|
77
|
+
if (currentStep.explorerUrl && currentStep.explorerUrl?.length >= 1) {
|
|
78
|
+
currentStep.explorerUrl[currentStep.explorerUrl.length - 1] = {
|
|
79
|
+
url: explorerUrl,
|
|
80
|
+
description: 'Replaced Swap',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
txId = currentStep.executedTransactionId;
|
|
85
|
+
if (updatedTxHash && updatedTxResponse)
|
|
86
|
+
setTransactionResponseByHash(updatedTxHash, updatedTxResponse);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const { extraMessage, extraMessageDetail, extraMessageErrorCode } = prettifyErrorMessage(error);
|
|
91
|
+
const updateResult = updateSwapStatus({
|
|
92
|
+
getStorage,
|
|
93
|
+
setStorage,
|
|
94
|
+
nextStatus: 'failed',
|
|
95
|
+
nextStepStatus: 'failed',
|
|
96
|
+
message: extraMessage,
|
|
97
|
+
details: extraMessageDetail,
|
|
98
|
+
errorCode: extraMessageErrorCode,
|
|
99
|
+
});
|
|
100
|
+
context?.notifier({
|
|
101
|
+
eventType: 'task_failed',
|
|
102
|
+
...updateResult,
|
|
103
|
+
});
|
|
104
|
+
getTxReceiptFailed = true;
|
|
105
|
+
// We shouldn't return here, because we need to trigger check status job in backend.
|
|
106
|
+
// This is not a ui requirement but the backend one.
|
|
107
|
+
}
|
|
108
|
+
|
|
44
109
|
try {
|
|
45
110
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
46
111
|
status = await httpService().checkStatus({
|
|
@@ -54,59 +119,32 @@ async function checkTransactionStatus({
|
|
|
54
119
|
return;
|
|
55
120
|
}
|
|
56
121
|
|
|
57
|
-
// If user cancel swap during check status api call,
|
|
122
|
+
// If user cancel swap during check status api call,
|
|
123
|
+
// or getting transaction receipt failed,
|
|
124
|
+
// we should ignore check status response and return
|
|
125
|
+
if (getTxReceiptFailed) return failed();
|
|
58
126
|
if (currentStep?.status === 'failed') return;
|
|
59
127
|
|
|
60
128
|
const outputAmount: string | null =
|
|
61
|
-
status?.outputAmount ||
|
|
62
|
-
(!!currentStep.outputAmount ? currentStep.outputAmount : null);
|
|
129
|
+
status?.outputAmount || (currentStep.outputAmount ? currentStep.outputAmount : null);
|
|
63
130
|
const prevOutputAmount = currentStep.outputAmount || null;
|
|
64
131
|
swap.extraMessage = status?.extraMessage || swap.extraMessage;
|
|
65
132
|
swap.extraMessageSeverity = MessageSeverity.info;
|
|
66
133
|
swap.extraMessageDetail = '';
|
|
67
134
|
|
|
68
135
|
currentStep.status = status?.status || currentStep.status;
|
|
69
|
-
currentStep.diagnosisUrl =
|
|
70
|
-
status?.diagnosisUrl || currentStep.diagnosisUrl || null;
|
|
136
|
+
currentStep.diagnosisUrl = status?.diagnosisUrl || currentStep.diagnosisUrl || null;
|
|
71
137
|
currentStep.outputAmount = outputAmount || currentStep.outputAmount;
|
|
72
138
|
currentStep.explorerUrl = status?.explorerUrl || currentStep.explorerUrl;
|
|
73
139
|
currentStep.internalSteps = status?.steps || null;
|
|
74
140
|
|
|
75
141
|
const newTransaction = status?.newTx;
|
|
76
142
|
|
|
77
|
-
if (
|
|
143
|
+
if (newTransaction) {
|
|
78
144
|
currentStep.status = 'created';
|
|
79
145
|
currentStep.executedTransactionId = null;
|
|
80
146
|
currentStep.executedTransactionTime = null;
|
|
81
|
-
currentStep
|
|
82
|
-
currentStep.cosmosTransaction = null;
|
|
83
|
-
currentStep.evmTransaction = null;
|
|
84
|
-
currentStep.solanaTransaction = null;
|
|
85
|
-
currentStep.evmApprovalTransaction = null;
|
|
86
|
-
currentStep.starknetApprovalTransaction = null;
|
|
87
|
-
currentStep.starknetTransaction = null;
|
|
88
|
-
currentStep.tronApprovalTransaction = null;
|
|
89
|
-
currentStep.tronTransaction = null;
|
|
90
|
-
|
|
91
|
-
if (isEvmTransaction(newTransaction)) {
|
|
92
|
-
if (newTransaction.isApprovalTx)
|
|
93
|
-
currentStep.evmApprovalTransaction = newTransaction;
|
|
94
|
-
else currentStep.evmTransaction = newTransaction;
|
|
95
|
-
} else if (isCosmosTransaction(newTransaction)) {
|
|
96
|
-
currentStep.cosmosTransaction = newTransaction;
|
|
97
|
-
} else if (isSolanaTransaction(newTransaction)) {
|
|
98
|
-
currentStep.solanaTransaction = newTransaction;
|
|
99
|
-
} else if (isTrasnferTransaction(newTransaction)) {
|
|
100
|
-
currentStep.transferTransaction = newTransaction;
|
|
101
|
-
} else if (isStarknetTransaction(newTransaction)) {
|
|
102
|
-
if (newTransaction.isApprovalTx)
|
|
103
|
-
currentStep.starknetApprovalTransaction = newTransaction;
|
|
104
|
-
else currentStep.starknetTransaction = newTransaction;
|
|
105
|
-
} else if (isTronTransaction(newTransaction)) {
|
|
106
|
-
if (newTransaction.isApprovalTx)
|
|
107
|
-
currentStep.tronApprovalTransaction = newTransaction;
|
|
108
|
-
else currentStep.tronTransaction = newTransaction;
|
|
109
|
-
}
|
|
147
|
+
setCurrentStepTx(currentStep, newTransaction);
|
|
110
148
|
}
|
|
111
149
|
|
|
112
150
|
if (prevOutputAmount === null && outputAmount !== null)
|
|
@@ -127,7 +165,7 @@ async function checkTransactionStatus({
|
|
|
127
165
|
if (currentStep.status === 'success') {
|
|
128
166
|
const nextStep = getNextStep(swap, currentStep);
|
|
129
167
|
swap.extraMessageDetail = '';
|
|
130
|
-
swap.extraMessage =
|
|
168
|
+
swap.extraMessage = nextStep
|
|
131
169
|
? `starting next step: ${nextStep.swapperId}: ${nextStep.fromBlockchain} -> ${nextStep.toBlockchain}`
|
|
132
170
|
: '';
|
|
133
171
|
} else if (currentStep.status === 'failed') {
|
|
@@ -143,10 +181,7 @@ async function checkTransactionStatus({
|
|
|
143
181
|
|
|
144
182
|
if (status?.status === 'failed') {
|
|
145
183
|
failed();
|
|
146
|
-
} else if (
|
|
147
|
-
status?.status === 'success' ||
|
|
148
|
-
(status?.status === 'running' && !!status.newTx)
|
|
149
|
-
) {
|
|
184
|
+
} else if (status?.status === 'success' || (status?.status === 'running' && !!status.newTx)) {
|
|
150
185
|
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
151
186
|
next();
|
|
152
187
|
} else {
|
|
@@ -167,32 +202,92 @@ async function checkApprovalStatus({
|
|
|
167
202
|
retry,
|
|
168
203
|
failed,
|
|
169
204
|
context,
|
|
170
|
-
}: ExecuterActions<
|
|
171
|
-
SwapStorage,
|
|
172
|
-
SwapActionTypes,
|
|
173
|
-
SwapQueueContext
|
|
174
|
-
>): Promise<void> {
|
|
205
|
+
}: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>): Promise<void> {
|
|
175
206
|
const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
|
|
176
|
-
|
|
177
|
-
const
|
|
207
|
+
const { meta } = context;
|
|
208
|
+
const { getTransactionResponseByHash, setTransactionResponseByHash } = useTransactionsResponse();
|
|
209
|
+
|
|
210
|
+
const currentStep = getCurrentStep(swap);
|
|
211
|
+
if (!currentStep) {
|
|
212
|
+
console.log('ignore check status, current step is null');
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let txId = currentStep.executedTransactionId;
|
|
217
|
+
|
|
218
|
+
let signer: GenericSigner<Transaction> | null = null;
|
|
219
|
+
try {
|
|
220
|
+
const txType = getCurrentStepTxType(currentStep);
|
|
221
|
+
const sourceWallet = getRelatedWallet(swap, currentStep);
|
|
222
|
+
if (txType && sourceWallet)
|
|
223
|
+
signer = context.getSigners(sourceWallet.walletType).getSigner(txType);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
// wallet is not connected yet
|
|
226
|
+
// no need to do anything
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
// if wallet is connected, try to get transaction reciept
|
|
231
|
+
if (signer?.wait) {
|
|
232
|
+
const txResponse = getTransactionResponseByHash(txId!);
|
|
233
|
+
const { hash: updatedTxHash, response: updatedTxResponse } = await signer.wait(
|
|
234
|
+
txId!,
|
|
235
|
+
txResponse,
|
|
236
|
+
);
|
|
237
|
+
if (updatedTxHash !== txId) {
|
|
238
|
+
currentStep.executedTransactionId = updatedTxHash || currentStep.executedTransactionId;
|
|
239
|
+
const currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
|
|
240
|
+
const explorerUrl = getScannerUrl(
|
|
241
|
+
currentStep.executedTransactionId!,
|
|
242
|
+
currentStepBlockchain,
|
|
243
|
+
meta.blockchains,
|
|
244
|
+
);
|
|
245
|
+
if (explorerUrl) {
|
|
246
|
+
if (currentStep.explorerUrl && currentStep.explorerUrl?.length >= 1) {
|
|
247
|
+
currentStep.explorerUrl[currentStep.explorerUrl.length - 1] = {
|
|
248
|
+
url: explorerUrl,
|
|
249
|
+
description: 'Replaced Approve',
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
txId = currentStep.executedTransactionId;
|
|
254
|
+
if (updatedTxHash && updatedTxResponse)
|
|
255
|
+
setTransactionResponseByHash(updatedTxHash, updatedTxResponse);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
} catch (error) {
|
|
259
|
+
const { extraMessage, extraMessageDetail, extraMessageErrorCode } = prettifyErrorMessage(error);
|
|
260
|
+
const updateResult = updateSwapStatus({
|
|
261
|
+
getStorage,
|
|
262
|
+
setStorage,
|
|
263
|
+
nextStatus: 'failed',
|
|
264
|
+
nextStepStatus: 'failed',
|
|
265
|
+
message: extraMessage,
|
|
266
|
+
details: extraMessageDetail,
|
|
267
|
+
errorCode: extraMessageErrorCode,
|
|
268
|
+
});
|
|
269
|
+
context?.notifier({
|
|
270
|
+
eventType: 'task_failed',
|
|
271
|
+
...updateResult,
|
|
272
|
+
});
|
|
273
|
+
return failed();
|
|
274
|
+
}
|
|
275
|
+
|
|
178
276
|
let isApproved = false;
|
|
179
277
|
try {
|
|
180
278
|
const response = await httpService().checkApproval(
|
|
181
279
|
swap.requestId,
|
|
182
|
-
currentStep.executedTransactionId || ''
|
|
280
|
+
currentStep.executedTransactionId || '',
|
|
183
281
|
);
|
|
184
282
|
// If user cancel swap during check status api call, we should ignore check approval response
|
|
185
283
|
if (currentStep?.status === 'failed') return;
|
|
186
284
|
|
|
187
285
|
isApproved = response.isApproved;
|
|
188
|
-
if (
|
|
189
|
-
!isApproved &&
|
|
190
|
-
(response.txStatus === 'failed' || response.txStatus === 'success')
|
|
191
|
-
) {
|
|
286
|
+
if (!isApproved && (response.txStatus === 'failed' || response.txStatus === 'success')) {
|
|
192
287
|
let message, details;
|
|
193
288
|
if (response.txStatus === 'failed') {
|
|
194
289
|
message = 'Approve transaction failed';
|
|
195
|
-
details = 'Smart contract approval failed in blockchain.';
|
|
290
|
+
details = 'Smart contract approval tx failed in blockchain.';
|
|
196
291
|
} else {
|
|
197
292
|
message = 'Not enough approval';
|
|
198
293
|
if (response.requiredApprovedAmount && response.currentApprovedAmount)
|
|
@@ -206,12 +301,12 @@ async function checkApprovalStatus({
|
|
|
206
301
|
setStorage,
|
|
207
302
|
nextStatus: 'failed',
|
|
208
303
|
nextStepStatus: 'failed',
|
|
209
|
-
errorCode: '
|
|
304
|
+
errorCode: 'INSUFFICIENT_APPROVE',
|
|
210
305
|
message: message,
|
|
211
306
|
details: details,
|
|
212
307
|
});
|
|
213
308
|
context.notifier({
|
|
214
|
-
eventType: '
|
|
309
|
+
eventType: 'not_enough_approval',
|
|
215
310
|
...updateResult,
|
|
216
311
|
});
|
|
217
312
|
failed();
|
|
@@ -265,11 +360,14 @@ async function checkApprovalStatus({
|
|
|
265
360
|
*
|
|
266
361
|
*/
|
|
267
362
|
export async function checkStatus(
|
|
268
|
-
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext
|
|
363
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>,
|
|
269
364
|
): Promise<void> {
|
|
270
365
|
const swap = actions.getStorage().swapDetails;
|
|
271
|
-
|
|
272
|
-
|
|
366
|
+
const currentStep = getCurrentStep(swap);
|
|
367
|
+
if (!currentStep) {
|
|
368
|
+
console.log('ignore check status, current step is null', swap.requestId);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
273
371
|
|
|
274
372
|
// Reset network status
|
|
275
373
|
// Because when check status is on `loading` or `failed` status, it shows previous message that isn't related to current state.
|
|
@@ -2,14 +2,10 @@ import { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
|
2
2
|
import { SwapActionTypes, SwapQueueContext, SwapStorage } from '../types';
|
|
3
3
|
import {
|
|
4
4
|
getCurrentStep,
|
|
5
|
-
isCosmosTransaction,
|
|
6
|
-
isEvmTransaction,
|
|
7
|
-
isSolanaTransaction,
|
|
8
|
-
isTrasnferTransaction,
|
|
9
|
-
isStarknetTransaction,
|
|
10
|
-
isTronTransaction,
|
|
11
5
|
updateSwapStatus,
|
|
12
6
|
throwOnOK,
|
|
7
|
+
getCurrentStepTx,
|
|
8
|
+
setCurrentStepTx,
|
|
13
9
|
} from '../helpers';
|
|
14
10
|
import { prettifyErrorMessage } from '../shared-errors';
|
|
15
11
|
import { CreateTransactionRequest } from 'rango-sdk';
|
|
@@ -29,30 +25,9 @@ export async function createTransaction(
|
|
|
29
25
|
const swap = getStorage().swapDetails;
|
|
30
26
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
31
27
|
const currentStep = getCurrentStep(swap)!;
|
|
28
|
+
const transaction = getCurrentStepTx(currentStep);
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
evmTransaction,
|
|
35
|
-
cosmosTransaction,
|
|
36
|
-
transferTransaction,
|
|
37
|
-
evmApprovalTransaction,
|
|
38
|
-
solanaTransaction,
|
|
39
|
-
tronTransaction,
|
|
40
|
-
tronApprovalTransaction,
|
|
41
|
-
starknetTransaction,
|
|
42
|
-
starknetApprovalTransaction,
|
|
43
|
-
} = currentStep;
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
!evmTransaction &&
|
|
47
|
-
!evmApprovalTransaction &&
|
|
48
|
-
!tronTransaction &&
|
|
49
|
-
!tronApprovalTransaction &&
|
|
50
|
-
!starknetTransaction &&
|
|
51
|
-
!starknetApprovalTransaction &&
|
|
52
|
-
!cosmosTransaction &&
|
|
53
|
-
!transferTransaction &&
|
|
54
|
-
!solanaTransaction
|
|
55
|
-
) {
|
|
30
|
+
if (!transaction) {
|
|
56
31
|
const request: CreateTransactionRequest = {
|
|
57
32
|
requestId: swap.requestId,
|
|
58
33
|
step: currentStep.id,
|
|
@@ -72,27 +47,7 @@ export async function createTransaction(
|
|
|
72
47
|
httpService().createTransaction(request)
|
|
73
48
|
);
|
|
74
49
|
|
|
75
|
-
if (transaction)
|
|
76
|
-
if (isEvmTransaction(transaction)) {
|
|
77
|
-
if (transaction.isApprovalTx)
|
|
78
|
-
currentStep.evmApprovalTransaction = transaction;
|
|
79
|
-
else currentStep.evmTransaction = transaction;
|
|
80
|
-
} else if (isCosmosTransaction(transaction)) {
|
|
81
|
-
currentStep.cosmosTransaction = transaction;
|
|
82
|
-
} else if (isSolanaTransaction(transaction)) {
|
|
83
|
-
currentStep.solanaTransaction = transaction;
|
|
84
|
-
} else if (isTrasnferTransaction(transaction)) {
|
|
85
|
-
currentStep.transferTransaction = transaction;
|
|
86
|
-
} else if (isStarknetTransaction(transaction)) {
|
|
87
|
-
if (transaction.isApprovalTx)
|
|
88
|
-
currentStep.starknetApprovalTransaction = transaction;
|
|
89
|
-
else currentStep.starknetTransaction = transaction;
|
|
90
|
-
} else if (isTronTransaction(transaction)) {
|
|
91
|
-
if (transaction.isApprovalTx)
|
|
92
|
-
currentStep.tronApprovalTransaction = transaction;
|
|
93
|
-
else currentStep.tronTransaction = transaction;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
50
|
+
if (transaction) setCurrentStepTx(currentStep, transaction);
|
|
96
51
|
|
|
97
52
|
setStorage({ ...getStorage(), swapDetails: swap });
|
|
98
53
|
schedule(SwapActionTypes.EXECUTE_TRANSACTION);
|