@rango-dev/queue-manager-rango-preset 0.1.15-next.6 → 0.1.15-next.8
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/helpers.d.ts +14 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.development.js +136 -115
- 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 +136 -115
- package/dist/queue-manager-rango-preset.esm.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/actions/checkStatus.ts +69 -34
- package/src/helpers.ts +53 -36
- package/src/hooks.ts +6 -1
- package/src/types.ts +2 -0
package/dist/types.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface SwapQueueContext extends QueueContext {
|
|
|
32
32
|
providers: Providers;
|
|
33
33
|
getSigners: (type: WalletType) => SignerFactory;
|
|
34
34
|
switchNetwork: (wallet: WalletType, network: Network) => Promise<ConnectResult> | undefined;
|
|
35
|
+
canSwitchNetworkTo: (type: WalletType, network: Network) => boolean;
|
|
35
36
|
connect: (wallet: WalletType, network: Network) => Promise<ConnectResult> | undefined;
|
|
36
37
|
state: (type: WalletType) => WalletState;
|
|
37
38
|
isMobileWallet: (type: WalletType) => boolean;
|
|
@@ -45,5 +46,6 @@ export interface UseQueueManagerParams {
|
|
|
45
46
|
clearDisconnectedWallet: () => void;
|
|
46
47
|
evmChains: EvmBlockchainMeta[];
|
|
47
48
|
notifier: SwapQueueContext['notifier'];
|
|
49
|
+
canSwitchNetworkTo: (type: WalletType, network: Network) => boolean;
|
|
48
50
|
}
|
|
49
51
|
//# sourceMappingURL=types.d.ts.map
|
package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;IACxC,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,WAAW,CAAC;IACzC,cAAc,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC;IAC9C,QAAQ,EAAE,CAAC,IAAI,EAAE,wBAAwB,KAAK,IAAI,CAAC;IAGnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,UAAU,GAAG,SAAS,CAAC;IAC3C,uBAAuB,EAAE,MAAM,IAAI,CAAC;IACpC,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAC/B,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACvC,kBAAkB,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;CACrE"}
|
package/package.json
CHANGED
|
@@ -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
|
}
|
|
@@ -286,7 +297,7 @@ export function updateSwapStatus({
|
|
|
286
297
|
const currentStep = getCurrentStep(swap);
|
|
287
298
|
if (!!nextStepStatus && !!currentStep) currentStep.status = nextStepStatus;
|
|
288
299
|
|
|
289
|
-
if (
|
|
300
|
+
if (nextStatus) swap.status = nextStatus;
|
|
290
301
|
swap.hasAlreadyProceededToSign = hasAlreadyProceededToSign;
|
|
291
302
|
if (!!nextStatus && ['failed', 'success'].includes(nextStatus))
|
|
292
303
|
swap.finishTime = new Date().getTime().toString();
|
|
@@ -354,7 +365,7 @@ export function setStepTransactionIds(
|
|
|
354
365
|
const currentStep = getCurrentStep(swap)!;
|
|
355
366
|
currentStep.executedTransactionId = txId;
|
|
356
367
|
currentStep.executedTransactionTime = new Date().getTime().toString();
|
|
357
|
-
if (
|
|
368
|
+
if (explorerUrl?.url)
|
|
358
369
|
currentStep.explorerUrl = [
|
|
359
370
|
...(currentStep.explorerUrl || []),
|
|
360
371
|
{
|
|
@@ -376,7 +387,7 @@ export function setStepTransactionIds(
|
|
|
376
387
|
...getStorage(),
|
|
377
388
|
swapDetails: swap,
|
|
378
389
|
});
|
|
379
|
-
if (
|
|
390
|
+
if (eventType)
|
|
380
391
|
notifier({ eventType: eventType, swap: swap, step: currentStep });
|
|
381
392
|
}
|
|
382
393
|
|
|
@@ -613,7 +624,7 @@ export async function isNetworkMatchedForTransaction(
|
|
|
613
624
|
if (!fromBlockChain) return false;
|
|
614
625
|
|
|
615
626
|
if (
|
|
616
|
-
|
|
627
|
+
meta.evmBasedChains.find(
|
|
617
628
|
(evmBlochain) => evmBlochain.name === fromBlockChain
|
|
618
629
|
)
|
|
619
630
|
) {
|
|
@@ -783,16 +794,18 @@ export function onBlockForChangeNetwork(
|
|
|
783
794
|
// Try to auto switch
|
|
784
795
|
const { type, network } = getRequiredWallet(swap);
|
|
785
796
|
if (!!type && !!network) {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
result
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
797
|
+
if (context.canSwitchNetworkTo(type, network)) {
|
|
798
|
+
const result = context.switchNetwork(type, network);
|
|
799
|
+
if (result) {
|
|
800
|
+
result
|
|
801
|
+
.then(() => {
|
|
802
|
+
queue.unblock();
|
|
803
|
+
})
|
|
804
|
+
.catch((error) => {
|
|
805
|
+
// ignore switch network errors
|
|
806
|
+
console.log({ error });
|
|
807
|
+
});
|
|
808
|
+
}
|
|
796
809
|
}
|
|
797
810
|
}
|
|
798
811
|
}
|
|
@@ -860,7 +873,12 @@ export function onDependsOnOtherQueues(
|
|
|
860
873
|
resetClaimedBy: () => {
|
|
861
874
|
reset();
|
|
862
875
|
// TODO: Use key generator
|
|
863
|
-
retryOn(
|
|
876
|
+
retryOn(
|
|
877
|
+
`${type}-${network}:${address}`,
|
|
878
|
+
context.notifier,
|
|
879
|
+
manager,
|
|
880
|
+
context.canSwitchNetworkTo
|
|
881
|
+
);
|
|
864
882
|
},
|
|
865
883
|
});
|
|
866
884
|
}
|
|
@@ -888,7 +906,7 @@ export function isRequiredWalletConnected(
|
|
|
888
906
|
export function singTransaction(
|
|
889
907
|
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
890
908
|
): void {
|
|
891
|
-
const {
|
|
909
|
+
const { setTransactionDataByHash } = useTransactionsData();
|
|
892
910
|
const { getStorage, setStorage, failed, next, schedule, context } = actions;
|
|
893
911
|
const { meta, getSigners, notifier, isMobileWallet } = context;
|
|
894
912
|
const swap = getStorage().swapDetails;
|
|
@@ -991,7 +1009,7 @@ export function singTransaction(
|
|
|
991
1009
|
: undefined
|
|
992
1010
|
);
|
|
993
1011
|
// response used for evm transactions to get receipt and track replaced
|
|
994
|
-
response &&
|
|
1012
|
+
response && setTransactionDataByHash(hash, { response });
|
|
995
1013
|
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
996
1014
|
next();
|
|
997
1015
|
onFinish();
|
|
@@ -1147,7 +1165,7 @@ export function checkWaitingForNetworkChange(manager?: Manager): void {
|
|
|
1147
1165
|
*/
|
|
1148
1166
|
export function getRunningSwaps(manager: Manager): PendingSwap[] {
|
|
1149
1167
|
const queues = manager?.getAll() || new Map<QueueName, QueueInfo>();
|
|
1150
|
-
|
|
1168
|
+
const result: PendingSwap[] = [];
|
|
1151
1169
|
queues.forEach((q) => {
|
|
1152
1170
|
// retry only on affected queues
|
|
1153
1171
|
const queueStorage = q.list.getStorage() as SwapStorage | undefined;
|
|
@@ -1204,6 +1222,7 @@ export function retryOn(
|
|
|
1204
1222
|
wallet_network: string,
|
|
1205
1223
|
notifier: SwapQueueContext['notifier'],
|
|
1206
1224
|
manager?: Manager,
|
|
1225
|
+
canSwitchNetworkTo?: (type: WalletType, network: Network) => boolean,
|
|
1207
1226
|
options = { fallbackToOnlyWallet: true }
|
|
1208
1227
|
): void {
|
|
1209
1228
|
const [wallet, network] = splitWalletNetwork(wallet_network);
|
|
@@ -1258,7 +1277,9 @@ export function retryOn(
|
|
|
1258
1277
|
finalQueueToBeRun = onlyWalletMatched[0];
|
|
1259
1278
|
}
|
|
1260
1279
|
|
|
1261
|
-
|
|
1280
|
+
if (!canSwitchNetworkTo?.(wallet, network as Network))
|
|
1281
|
+
finalQueueToBeRun?.unblock();
|
|
1282
|
+
else finalQueueToBeRun?.checkBlock();
|
|
1262
1283
|
}
|
|
1263
1284
|
|
|
1264
1285
|
/*
|
|
@@ -1276,17 +1297,13 @@ For backward compatibilty with server and sdk, we use this wrapper to reject the
|
|
|
1276
1297
|
export async function throwOnOK(
|
|
1277
1298
|
rawResponse: Promise<CreateTransactionResponse>
|
|
1278
1299
|
): Promise<CreateTransactionResponse> {
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
);
|
|
1285
|
-
}
|
|
1286
|
-
return responseBody;
|
|
1287
|
-
} catch (e) {
|
|
1288
|
-
throw e;
|
|
1300
|
+
const responseBody = await rawResponse;
|
|
1301
|
+
if (!responseBody.ok || !responseBody.transaction) {
|
|
1302
|
+
throw PrettyError.CreateTransaction(
|
|
1303
|
+
responseBody.error || 'bad response from create tx endpoint'
|
|
1304
|
+
);
|
|
1289
1305
|
}
|
|
1306
|
+
return responseBody;
|
|
1290
1307
|
}
|
|
1291
1308
|
|
|
1292
1309
|
export function cancelSwap(
|
package/src/hooks.ts
CHANGED
|
@@ -56,7 +56,12 @@ function useQueueManager(params: UseQueueManagerParams): void {
|
|
|
56
56
|
manager,
|
|
57
57
|
notifier: params.notifier,
|
|
58
58
|
});
|
|
59
|
-
retryOn(
|
|
59
|
+
retryOn(
|
|
60
|
+
params.lastConnectedWallet,
|
|
61
|
+
params.notifier,
|
|
62
|
+
manager,
|
|
63
|
+
params.canSwitchNetworkTo
|
|
64
|
+
);
|
|
60
65
|
}
|
|
61
66
|
}, [params.lastConnectedWallet]);
|
|
62
67
|
|
package/src/types.ts
CHANGED
|
@@ -55,6 +55,7 @@ export interface SwapQueueContext extends QueueContext {
|
|
|
55
55
|
wallet: WalletType,
|
|
56
56
|
network: Network
|
|
57
57
|
) => Promise<ConnectResult> | undefined;
|
|
58
|
+
canSwitchNetworkTo: (type: WalletType, network: Network) => boolean;
|
|
58
59
|
connect: (
|
|
59
60
|
wallet: WalletType,
|
|
60
61
|
network: Network
|
|
@@ -74,4 +75,5 @@ export interface UseQueueManagerParams {
|
|
|
74
75
|
clearDisconnectedWallet: () => void;
|
|
75
76
|
evmChains: EvmBlockchainMeta[];
|
|
76
77
|
notifier: SwapQueueContext['notifier'];
|
|
78
|
+
canSwitchNetworkTo: (type: WalletType, network: Network) => boolean;
|
|
77
79
|
}
|