@rango-dev/queue-manager-rango-preset 0.5.1-next.8 → 0.5.1-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.map +1 -1
- package/dist/actions/createTransaction.d.ts.map +1 -1
- package/dist/actions/scheduleNextStep.d.ts +1 -1
- package/dist/actions/scheduleNextStep.d.ts.map +1 -1
- package/dist/actions/start.d.ts +1 -1
- package/dist/actions/start.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/helpers.d.ts +14 -9
- package/dist/helpers.d.ts.map +1 -1
- package/dist/hooks.d.ts +2 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/services/eventEmitter.d.ts +12 -0
- package/dist/services/eventEmitter.d.ts.map +1 -0
- package/dist/shared-errors.d.ts.map +1 -1
- package/dist/shared.d.ts +0 -5
- package/dist/shared.d.ts.map +1 -1
- package/dist/types.d.ts +99 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/actions/checkStatus.ts +47 -16
- package/src/actions/createTransaction.ts +25 -4
- package/src/actions/scheduleNextStep.ts +34 -5
- package/src/actions/start.ts +7 -1
- package/src/constants.ts +2 -0
- package/src/helpers.ts +174 -81
- package/src/hooks.ts +7 -8
- package/src/index.ts +19 -3
- package/src/services/eventEmitter.ts +258 -0
- package/src/shared-errors.ts +7 -7
- package/src/shared.ts +0 -6
- package/src/types.ts +150 -4
package/src/helpers.ts
CHANGED
|
@@ -5,11 +5,16 @@ import {
|
|
|
5
5
|
QueueType,
|
|
6
6
|
} from '@rango-dev/queue-manager-core';
|
|
7
7
|
import {
|
|
8
|
+
ArrayElement,
|
|
8
9
|
BlockReason,
|
|
10
|
+
StepEventType,
|
|
9
11
|
SwapActionTypes,
|
|
10
12
|
SwapQueueContext,
|
|
11
13
|
SwapQueueDef,
|
|
12
14
|
SwapStorage,
|
|
15
|
+
StepExecutionEventStatus,
|
|
16
|
+
StepExecutionBlockedEventStatus,
|
|
17
|
+
Step,
|
|
13
18
|
} from './types';
|
|
14
19
|
import {
|
|
15
20
|
getBlockChainNameFromId,
|
|
@@ -29,6 +34,7 @@ import {
|
|
|
29
34
|
} from 'rango-sdk';
|
|
30
35
|
|
|
31
36
|
import {
|
|
37
|
+
DEFAULT_ERROR_CODE,
|
|
32
38
|
ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK,
|
|
33
39
|
ERROR_MESSAGE_WAIT_FOR_WALLET,
|
|
34
40
|
ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION,
|
|
@@ -36,7 +42,6 @@ import {
|
|
|
36
42
|
import { Manager } from '@rango-dev/queue-manager-core';
|
|
37
43
|
import { Status } from '@rango-dev/queue-manager-core';
|
|
38
44
|
import {
|
|
39
|
-
EventType,
|
|
40
45
|
getCurrentBlockchainOf,
|
|
41
46
|
getCurrentBlockchainOfOrNull,
|
|
42
47
|
getScannerUrl,
|
|
@@ -59,6 +64,7 @@ import {
|
|
|
59
64
|
} from './shared-errors';
|
|
60
65
|
import { httpService } from './services';
|
|
61
66
|
import { APIErrorCode, SignerErrorCode } from 'rango-types/lib';
|
|
67
|
+
import { notifier } from './services/eventEmitter';
|
|
62
68
|
|
|
63
69
|
type WhenTaskBlocked = Parameters<NonNullable<SwapQueueDef['whenTaskBlocked']>>;
|
|
64
70
|
type WhenTaskBlockedEvent = WhenTaskBlocked[0];
|
|
@@ -299,9 +305,18 @@ export function updateSwapStatus({
|
|
|
299
305
|
}): {
|
|
300
306
|
swap: PendingSwap;
|
|
301
307
|
step: PendingSwapStep | null;
|
|
308
|
+
failureType?: APIErrorCode;
|
|
302
309
|
} {
|
|
303
310
|
const swap = getStorage().swapDetails;
|
|
304
311
|
const currentStep = getCurrentStep(swap);
|
|
312
|
+
const updatedResult: {
|
|
313
|
+
swap: PendingSwap;
|
|
314
|
+
step: PendingSwapStep | null;
|
|
315
|
+
failureType?: APIErrorCode;
|
|
316
|
+
} = {
|
|
317
|
+
swap,
|
|
318
|
+
step: currentStep,
|
|
319
|
+
};
|
|
305
320
|
if (!!nextStepStatus && !!currentStep) currentStep.status = nextStepStatus;
|
|
306
321
|
|
|
307
322
|
if (nextStatus) swap.status = nextStatus;
|
|
@@ -323,11 +338,14 @@ export function updateSwapStatus({
|
|
|
323
338
|
const walletType = getRelatedWalletOrNull(swap, currentStep!)?.walletType;
|
|
324
339
|
swap.extraMessageSeverity = MessageSeverity.error;
|
|
325
340
|
|
|
341
|
+
const failureType = mapAppErrorCodesToAPIErrorCode(errorCode);
|
|
342
|
+
updatedResult.failureType = failureType;
|
|
343
|
+
|
|
326
344
|
httpService()
|
|
327
345
|
.reportFailure({
|
|
328
346
|
requestId: swap.requestId,
|
|
329
347
|
step: currentStep?.id || 1,
|
|
330
|
-
eventType:
|
|
348
|
+
eventType: failureType,
|
|
331
349
|
reason: errorReason || '',
|
|
332
350
|
data: walletType ? { wallet: walletType } : undefined,
|
|
333
351
|
})
|
|
@@ -348,10 +366,7 @@ export function updateSwapStatus({
|
|
|
348
366
|
swapDetails: swap,
|
|
349
367
|
});
|
|
350
368
|
|
|
351
|
-
return
|
|
352
|
-
swap,
|
|
353
|
-
step: currentStep,
|
|
354
|
-
};
|
|
369
|
+
return updatedResult;
|
|
355
370
|
}
|
|
356
371
|
|
|
357
372
|
/**
|
|
@@ -362,8 +377,6 @@ export function updateSwapStatus({
|
|
|
362
377
|
export function setStepTransactionIds(
|
|
363
378
|
{ getStorage, setStorage }: ExecuterActions<SwapStorage, SwapActionTypes>,
|
|
364
379
|
txId: string | null,
|
|
365
|
-
notifier: SwapQueueContext['notifier'],
|
|
366
|
-
eventType?: EventType,
|
|
367
380
|
explorerUrl?: { url?: string; description?: string }
|
|
368
381
|
): void {
|
|
369
382
|
const swap = getStorage().swapDetails;
|
|
@@ -380,22 +393,29 @@ export function setStepTransactionIds(
|
|
|
380
393
|
description: explorerUrl.description || null,
|
|
381
394
|
},
|
|
382
395
|
];
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
swap.extraMessageSeverity = MessageSeverity.info;
|
|
387
|
-
} else if (eventType === 'check_approve_tx_status') {
|
|
388
|
-
swap.extraMessage = 'Checking approve transaction status ...';
|
|
389
|
-
swap.extraMessageDetail = '';
|
|
390
|
-
swap.extraMessageSeverity = MessageSeverity.info;
|
|
391
|
-
}
|
|
396
|
+
swap.extraMessage = 'Transaction sent ...';
|
|
397
|
+
swap.extraMessageDetail = '';
|
|
398
|
+
swap.extraMessageSeverity = MessageSeverity.info;
|
|
392
399
|
|
|
393
400
|
setStorage({
|
|
394
401
|
...getStorage(),
|
|
395
402
|
swapDetails: swap,
|
|
396
403
|
});
|
|
397
|
-
|
|
398
|
-
|
|
404
|
+
|
|
405
|
+
notifier({
|
|
406
|
+
event: {
|
|
407
|
+
type: StepEventType.TX_EXECUTION,
|
|
408
|
+
status: StepExecutionEventStatus.TX_SENT,
|
|
409
|
+
},
|
|
410
|
+
swap: swap,
|
|
411
|
+
step: currentStep,
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
notifier({
|
|
415
|
+
event: { type: StepEventType.CHECK_STATUS },
|
|
416
|
+
swap: swap,
|
|
417
|
+
step: currentStep,
|
|
418
|
+
});
|
|
399
419
|
}
|
|
400
420
|
|
|
401
421
|
/**
|
|
@@ -486,10 +506,7 @@ export function markRunningSwapAsSwitchingNetwork({
|
|
|
486
506
|
export function markRunningSwapAsDependsOnOtherQueues({
|
|
487
507
|
getStorage,
|
|
488
508
|
setStorage,
|
|
489
|
-
|
|
490
|
-
}: Pick<ExecuterActions, 'getStorage' | 'setStorage'> & {
|
|
491
|
-
notifier: SwapQueueContext['notifier'];
|
|
492
|
-
}):
|
|
509
|
+
}: Pick<ExecuterActions, 'getStorage' | 'setStorage'>):
|
|
493
510
|
| {
|
|
494
511
|
swap: PendingSwap;
|
|
495
512
|
step: PendingSwapStep;
|
|
@@ -504,7 +521,10 @@ export function markRunningSwapAsDependsOnOtherQueues({
|
|
|
504
521
|
currentStep.networkStatus = PendingSwapNetworkStatus.WaitingForQueue;
|
|
505
522
|
|
|
506
523
|
notifier({
|
|
507
|
-
|
|
524
|
+
event: {
|
|
525
|
+
type: StepEventType.TX_EXECUTION_BLOCKED,
|
|
526
|
+
status: StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE,
|
|
527
|
+
},
|
|
508
528
|
swap,
|
|
509
529
|
step: currentStep,
|
|
510
530
|
});
|
|
@@ -743,11 +763,23 @@ export function onBlockForConnectWallet(
|
|
|
743
763
|
if (!ok) {
|
|
744
764
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
745
765
|
const currentStep = getCurrentStep(swap)!;
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
766
|
+
const { type: walletType, address } = getRequiredWallet(swap);
|
|
767
|
+
notifier({
|
|
768
|
+
event: {
|
|
769
|
+
type: StepEventType.TX_EXECUTION_BLOCKED,
|
|
770
|
+
...(reason === 'account_miss_match'
|
|
771
|
+
? {
|
|
772
|
+
status:
|
|
773
|
+
StepExecutionBlockedEventStatus.WAITING_FOR_CHANGE_WALLET_ACCOUNT,
|
|
774
|
+
requiredAccount: address ?? undefined,
|
|
775
|
+
}
|
|
776
|
+
: {
|
|
777
|
+
status:
|
|
778
|
+
StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT,
|
|
779
|
+
requiredWallet: walletType ?? undefined,
|
|
780
|
+
requiredAccount: address ?? undefined,
|
|
781
|
+
}),
|
|
782
|
+
},
|
|
751
783
|
swap: swap,
|
|
752
784
|
step: currentStep,
|
|
753
785
|
});
|
|
@@ -790,9 +822,22 @@ export function onBlockForChangeNetwork(
|
|
|
790
822
|
setStorage: queue.setStorage.bind(queue),
|
|
791
823
|
});
|
|
792
824
|
|
|
825
|
+
const requiredNetwork = getCurrentBlockchainOfOrNull(swap, currentStep);
|
|
826
|
+
|
|
827
|
+
const requiredWallet = getRequiredWallet(swap).type;
|
|
828
|
+
|
|
829
|
+
const currentNetwork = requiredWallet
|
|
830
|
+
? context.state(requiredWallet).network
|
|
831
|
+
: undefined;
|
|
832
|
+
|
|
793
833
|
if (result) {
|
|
794
|
-
|
|
795
|
-
|
|
834
|
+
notifier({
|
|
835
|
+
event: {
|
|
836
|
+
type: StepEventType.TX_EXECUTION_BLOCKED,
|
|
837
|
+
status: StepExecutionBlockedEventStatus.WAITING_FOR_NETWORK_CHANGE,
|
|
838
|
+
requiredNetwork: requiredNetwork ?? undefined,
|
|
839
|
+
currentNetwork: currentNetwork ?? undefined,
|
|
840
|
+
},
|
|
796
841
|
swap: result.swap,
|
|
797
842
|
step: result.step,
|
|
798
843
|
});
|
|
@@ -851,7 +896,6 @@ export function onDependsOnOtherQueues(
|
|
|
851
896
|
markRunningSwapAsDependsOnOtherQueues({
|
|
852
897
|
getStorage: queue.getStorage.bind(queue),
|
|
853
898
|
setStorage: queue.setStorage.bind(queue),
|
|
854
|
-
notifier: context.notifier,
|
|
855
899
|
});
|
|
856
900
|
return;
|
|
857
901
|
}
|
|
@@ -882,7 +926,6 @@ export function onDependsOnOtherQueues(
|
|
|
882
926
|
// TODO: Use key generator
|
|
883
927
|
retryOn(
|
|
884
928
|
`${type}-${network}:${address}`,
|
|
885
|
-
context.notifier,
|
|
886
929
|
manager,
|
|
887
930
|
context.canSwitchNetworkTo
|
|
888
931
|
);
|
|
@@ -915,7 +958,7 @@ export function singTransaction(
|
|
|
915
958
|
): void {
|
|
916
959
|
const { setTransactionDataByHash } = inMemoryTransactionsData();
|
|
917
960
|
const { getStorage, setStorage, failed, next, schedule, context } = actions;
|
|
918
|
-
const { meta, getSigners,
|
|
961
|
+
const { meta, getSigners, isMobileWallet } = context;
|
|
919
962
|
const swap = getStorage().swapDetails;
|
|
920
963
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
921
964
|
const currentStep = getCurrentStep(swap)!;
|
|
@@ -936,11 +979,6 @@ export function singTransaction(
|
|
|
936
979
|
const tx = getCurrentStepTx(currentStep);
|
|
937
980
|
const txType = tx?.type;
|
|
938
981
|
const isApproval = isApprovalCurrentStepTx(currentStep);
|
|
939
|
-
const isSmartContractCall = [
|
|
940
|
-
TransactionType.EVM,
|
|
941
|
-
TransactionType.STARKNET,
|
|
942
|
-
TransactionType.TRON,
|
|
943
|
-
].includes(txType!);
|
|
944
982
|
|
|
945
983
|
if (!tx || !txType) {
|
|
946
984
|
const extraMessage = 'Unexpected Error: tx is null!';
|
|
@@ -954,7 +992,11 @@ export function singTransaction(
|
|
|
954
992
|
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
955
993
|
});
|
|
956
994
|
notifier({
|
|
957
|
-
|
|
995
|
+
event: {
|
|
996
|
+
type: StepEventType.FAILED,
|
|
997
|
+
reason: extraMessage,
|
|
998
|
+
reasonCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
999
|
+
},
|
|
958
1000
|
...updateResult,
|
|
959
1001
|
});
|
|
960
1002
|
failed();
|
|
@@ -968,9 +1010,9 @@ export function singTransaction(
|
|
|
968
1010
|
|
|
969
1011
|
let nextStatus: SwapStatus | undefined,
|
|
970
1012
|
nextStepStatus: StepStatus,
|
|
971
|
-
eventType: EventType,
|
|
972
1013
|
message: string,
|
|
973
|
-
details: string
|
|
1014
|
+
details: string,
|
|
1015
|
+
eventType: StepEventType;
|
|
974
1016
|
|
|
975
1017
|
if (isApproval) {
|
|
976
1018
|
message = `Waiting for approval of ${currentStep?.fromSymbol} coin ${
|
|
@@ -980,21 +1022,19 @@ export function singTransaction(
|
|
|
980
1022
|
'Waiting for approve transaction to be mined and confirmed successfully';
|
|
981
1023
|
nextStepStatus = 'waitingForApproval';
|
|
982
1024
|
nextStatus = undefined;
|
|
983
|
-
eventType =
|
|
1025
|
+
eventType = StepEventType.TX_EXECUTION;
|
|
984
1026
|
} else if (hasAlreadyProceededToSign) {
|
|
985
1027
|
message = 'Transaction is expired. Please try again.';
|
|
986
1028
|
nextStepStatus = 'failed';
|
|
987
1029
|
nextStatus = 'failed';
|
|
988
1030
|
details = '';
|
|
989
|
-
eventType =
|
|
1031
|
+
eventType = StepEventType.FAILED;
|
|
990
1032
|
} else {
|
|
991
1033
|
message = 'Executing transaction ...';
|
|
992
1034
|
nextStepStatus = 'running';
|
|
993
1035
|
nextStatus = 'running';
|
|
994
1036
|
details = `${mobileWallet ? 'Check your mobile phone!' : ''}`;
|
|
995
|
-
eventType =
|
|
996
|
-
? 'calling_smart_contract'
|
|
997
|
-
: 'confirm_transfer';
|
|
1037
|
+
eventType = StepEventType.TX_EXECUTION;
|
|
998
1038
|
}
|
|
999
1039
|
|
|
1000
1040
|
const updateResult = updateSwapStatus({
|
|
@@ -1009,10 +1049,21 @@ export function singTransaction(
|
|
|
1009
1049
|
: hasAlreadyProceededToSign,
|
|
1010
1050
|
errorCode: hasAlreadyProceededToSign ? 'TX_EXPIRED' : undefined,
|
|
1011
1051
|
});
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1052
|
+
|
|
1053
|
+
if (eventType === StepEventType.FAILED) {
|
|
1054
|
+
notifier({
|
|
1055
|
+
event: {
|
|
1056
|
+
type: eventType,
|
|
1057
|
+
reason: message,
|
|
1058
|
+
reasonCode: updateResult.failureType ?? DEFAULT_ERROR_CODE,
|
|
1059
|
+
},
|
|
1060
|
+
...updateResult,
|
|
1061
|
+
});
|
|
1062
|
+
} else
|
|
1063
|
+
notifier({
|
|
1064
|
+
event: { type: eventType, status: StepExecutionEventStatus.SEND_TX },
|
|
1065
|
+
...updateResult,
|
|
1066
|
+
});
|
|
1016
1067
|
|
|
1017
1068
|
if (hasAlreadyProceededToSign) {
|
|
1018
1069
|
failed();
|
|
@@ -1030,8 +1081,6 @@ export function singTransaction(
|
|
|
1030
1081
|
setStepTransactionIds(
|
|
1031
1082
|
actions,
|
|
1032
1083
|
hash,
|
|
1033
|
-
notifier,
|
|
1034
|
-
isApproval ? 'check_approve_tx_status' : 'check_tx_status',
|
|
1035
1084
|
explorerUrl
|
|
1036
1085
|
? { url: explorerUrl, description: isApproval ? 'Approve' : 'Swap' }
|
|
1037
1086
|
: undefined
|
|
@@ -1049,13 +1098,7 @@ export function singTransaction(
|
|
|
1049
1098
|
prettifyErrorMessage(error);
|
|
1050
1099
|
|
|
1051
1100
|
// if it is an rpc error with details, send the log to sentry
|
|
1052
|
-
if (
|
|
1053
|
-
error &&
|
|
1054
|
-
error?.root &&
|
|
1055
|
-
error?.root?.message &&
|
|
1056
|
-
error?.root?.code &&
|
|
1057
|
-
error?.root?.reason
|
|
1058
|
-
)
|
|
1101
|
+
if (error?.root?.message && error?.root?.code && error?.root?.reason)
|
|
1059
1102
|
logRPCError(error.root, swap, currentStep, sourceWallet?.walletType);
|
|
1060
1103
|
|
|
1061
1104
|
const updateResult = updateSwapStatus({
|
|
@@ -1067,14 +1110,13 @@ export function singTransaction(
|
|
|
1067
1110
|
details: extraMessageDetail,
|
|
1068
1111
|
errorCode: extraMessageErrorCode,
|
|
1069
1112
|
});
|
|
1070
|
-
|
|
1071
|
-
extraMessageErrorCode === 'REJECTED_BY_USER'
|
|
1072
|
-
? 'contract_rejected'
|
|
1073
|
-
: isSmartContractCall
|
|
1074
|
-
? 'smart_contract_call_failed'
|
|
1075
|
-
: 'transfer_failed';
|
|
1113
|
+
|
|
1076
1114
|
notifier({
|
|
1077
|
-
|
|
1115
|
+
event: {
|
|
1116
|
+
type: StepEventType.FAILED,
|
|
1117
|
+
reason: extraMessage,
|
|
1118
|
+
reasonCode: updateResult.failureType ?? DEFAULT_ERROR_CODE,
|
|
1119
|
+
},
|
|
1078
1120
|
...updateResult,
|
|
1079
1121
|
});
|
|
1080
1122
|
failed();
|
|
@@ -1087,7 +1129,6 @@ export function checkWaitingForConnectWalletChange(params: {
|
|
|
1087
1129
|
wallet_network: string;
|
|
1088
1130
|
manager?: Manager;
|
|
1089
1131
|
evmChains: EvmBlockchainMeta[];
|
|
1090
|
-
notifier: SwapQueueContext['notifier'];
|
|
1091
1132
|
}): void {
|
|
1092
1133
|
const { wallet_network, evmChains, manager } = params;
|
|
1093
1134
|
const [wallet, network] = splitWalletNetwork(wallet_network);
|
|
@@ -1116,10 +1157,12 @@ export function checkWaitingForConnectWalletChange(params: {
|
|
|
1116
1157
|
}
|
|
1117
1158
|
);
|
|
1118
1159
|
|
|
1160
|
+
const requiredNetwork = getCurrentBlockchainOfOrNull(swap, currentStep);
|
|
1161
|
+
|
|
1119
1162
|
if (
|
|
1120
1163
|
currentStepRequiredWallet === wallet &&
|
|
1121
1164
|
hasWaitingForConnect &&
|
|
1122
|
-
|
|
1165
|
+
requiredNetwork != network
|
|
1123
1166
|
) {
|
|
1124
1167
|
const queueInstance = q.list;
|
|
1125
1168
|
const { type } = getRequiredWallet(swap);
|
|
@@ -1139,8 +1182,14 @@ export function checkWaitingForConnectWalletChange(params: {
|
|
|
1139
1182
|
});
|
|
1140
1183
|
|
|
1141
1184
|
if (result) {
|
|
1142
|
-
|
|
1143
|
-
|
|
1185
|
+
notifier({
|
|
1186
|
+
event: {
|
|
1187
|
+
type: StepEventType.TX_EXECUTION_BLOCKED,
|
|
1188
|
+
status:
|
|
1189
|
+
StepExecutionBlockedEventStatus.WAITING_FOR_NETWORK_CHANGE,
|
|
1190
|
+
currentNetwork: network,
|
|
1191
|
+
requiredNetwork: requiredNetwork ?? undefined,
|
|
1192
|
+
},
|
|
1144
1193
|
swap: result.swap,
|
|
1145
1194
|
step: result.step,
|
|
1146
1195
|
});
|
|
@@ -1213,21 +1262,26 @@ export function getRunningSwaps(manager: Manager): PendingSwap[] {
|
|
|
1213
1262
|
* @param notifier
|
|
1214
1263
|
* @returns
|
|
1215
1264
|
*/
|
|
1216
|
-
export function resetRunningSwapNotifsOnPageLoad(
|
|
1217
|
-
runningSwaps: PendingSwap[],
|
|
1218
|
-
notifier: SwapQueueContext['notifier']
|
|
1219
|
-
) {
|
|
1265
|
+
export function resetRunningSwapNotifsOnPageLoad(runningSwaps: PendingSwap[]) {
|
|
1220
1266
|
runningSwaps.forEach((swap) => {
|
|
1221
1267
|
const currentStep = getCurrentStep(swap);
|
|
1222
|
-
|
|
1268
|
+
const eventType = StepEventType.TX_EXECUTION_BLOCKED;
|
|
1269
|
+
let eventSubtype:
|
|
1270
|
+
| StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE
|
|
1271
|
+
| StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT
|
|
1272
|
+
| undefined;
|
|
1223
1273
|
if (currentStep?.networkStatus === PendingSwapNetworkStatus.WaitingForQueue)
|
|
1224
|
-
|
|
1274
|
+
eventSubtype = StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE;
|
|
1225
1275
|
else if (swap?.status === 'running') {
|
|
1226
|
-
|
|
1276
|
+
eventSubtype = StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT;
|
|
1227
1277
|
}
|
|
1228
1278
|
if (!!eventType && !!notifier) {
|
|
1229
1279
|
notifier({
|
|
1230
|
-
|
|
1280
|
+
event: {
|
|
1281
|
+
type: eventType,
|
|
1282
|
+
status:
|
|
1283
|
+
eventSubtype ?? StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE,
|
|
1284
|
+
},
|
|
1231
1285
|
swap: swap,
|
|
1232
1286
|
step: currentStep,
|
|
1233
1287
|
});
|
|
@@ -1248,7 +1302,6 @@ export function resetRunningSwapNotifsOnPageLoad(
|
|
|
1248
1302
|
*/
|
|
1249
1303
|
export function retryOn(
|
|
1250
1304
|
wallet_network: string,
|
|
1251
|
-
notifier: SwapQueueContext['notifier'],
|
|
1252
1305
|
manager?: Manager,
|
|
1253
1306
|
canSwitchNetworkTo?: (type: WalletType, network: Network) => boolean,
|
|
1254
1307
|
options = { fallbackToOnlyWallet: true }
|
|
@@ -1297,7 +1350,6 @@ export function retryOn(
|
|
|
1297
1350
|
markRunningSwapAsDependsOnOtherQueues({
|
|
1298
1351
|
getStorage: currentQueue.getStorage.bind(currentQueue),
|
|
1299
1352
|
setStorage: currentQueue.setStorage.bind(currentQueue),
|
|
1300
|
-
notifier: notifier,
|
|
1301
1353
|
});
|
|
1302
1354
|
}
|
|
1303
1355
|
}
|
|
@@ -1353,8 +1405,49 @@ export function cancelSwap(
|
|
|
1353
1405
|
nextStepStatus: 'failed',
|
|
1354
1406
|
errorCode: 'USER_CANCEL',
|
|
1355
1407
|
});
|
|
1408
|
+
|
|
1409
|
+
notifier({
|
|
1410
|
+
event: {
|
|
1411
|
+
type: StepEventType.FAILED,
|
|
1412
|
+
reasonCode: 'USER_CANCEL',
|
|
1413
|
+
reason: updateResult.swap.extraMessage ?? undefined,
|
|
1414
|
+
},
|
|
1415
|
+
|
|
1416
|
+
swap: updateResult.swap,
|
|
1417
|
+
step: updateResult.step,
|
|
1418
|
+
});
|
|
1419
|
+
|
|
1356
1420
|
reset();
|
|
1357
1421
|
if (manager) manager?.retry();
|
|
1358
1422
|
|
|
1359
1423
|
return updateResult;
|
|
1360
1424
|
}
|
|
1425
|
+
|
|
1426
|
+
export function getLastSuccessfulStep<T extends { status: StepStatus }[]>(
|
|
1427
|
+
steps: T
|
|
1428
|
+
): ArrayElement<T> | undefined {
|
|
1429
|
+
return steps
|
|
1430
|
+
.slice()
|
|
1431
|
+
.reverse()
|
|
1432
|
+
.find((step) => step.status === 'success') as ArrayElement<T> | undefined;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
export function getFailedStep<T extends { status: StepStatus }[]>(
|
|
1436
|
+
steps: T
|
|
1437
|
+
): ArrayElement<T> | undefined {
|
|
1438
|
+
return steps
|
|
1439
|
+
.slice()
|
|
1440
|
+
.reverse()
|
|
1441
|
+
.find((step) => step.status === 'failed') as ArrayElement<T> | undefined;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
export function isApprovalTX(step: Step): boolean {
|
|
1445
|
+
const { transaction } = step;
|
|
1446
|
+
const approvalTx =
|
|
1447
|
+
(transaction?.type === TransactionType.EVM && transaction.isApprovalTx) ||
|
|
1448
|
+
(transaction?.type === TransactionType.STARKNET &&
|
|
1449
|
+
transaction.isApprovalTx) ||
|
|
1450
|
+
(transaction?.type === TransactionType.TRON && transaction.isApprovalTx);
|
|
1451
|
+
|
|
1452
|
+
return approvalTx;
|
|
1453
|
+
}
|
package/src/hooks.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from './helpers';
|
|
8
8
|
import { migrated, migration } from './migration';
|
|
9
9
|
import { UseQueueManagerParams } from './types';
|
|
10
|
+
import { eventEmitter } from './services/eventEmitter';
|
|
10
11
|
|
|
11
12
|
let isCalled = 0;
|
|
12
13
|
|
|
@@ -54,14 +55,8 @@ function useQueueManager(params: UseQueueManagerParams): void {
|
|
|
54
55
|
evmChains: params.evmChains,
|
|
55
56
|
wallet_network: params.lastConnectedWallet,
|
|
56
57
|
manager,
|
|
57
|
-
notifier: params.notifier,
|
|
58
58
|
});
|
|
59
|
-
retryOn(
|
|
60
|
-
params.lastConnectedWallet,
|
|
61
|
-
params.notifier,
|
|
62
|
-
manager,
|
|
63
|
-
params.canSwitchNetworkTo
|
|
64
|
-
);
|
|
59
|
+
retryOn(params.lastConnectedWallet, manager, params.canSwitchNetworkTo);
|
|
65
60
|
}
|
|
66
61
|
}, [params.lastConnectedWallet]);
|
|
67
62
|
|
|
@@ -78,4 +73,8 @@ function useQueueManager(params: UseQueueManagerParams): void {
|
|
|
78
73
|
}, [params.disconnectedWallet]);
|
|
79
74
|
}
|
|
80
75
|
|
|
81
|
-
|
|
76
|
+
function useEvents() {
|
|
77
|
+
return eventEmitter;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { useQueueManager, useMigration, useEvents };
|
package/src/index.ts
CHANGED
|
@@ -3,13 +3,28 @@ import { SwapQueueDef } from './types';
|
|
|
3
3
|
import { swapQueueDef } from './queueDef';
|
|
4
4
|
|
|
5
5
|
export { PrettyError, prettifyErrorMessage } from './shared-errors';
|
|
6
|
-
export type {
|
|
6
|
+
export type {
|
|
7
|
+
SwapQueueContext,
|
|
8
|
+
SwapStorage,
|
|
9
|
+
RouteExecutionEvents,
|
|
10
|
+
Route,
|
|
11
|
+
Step,
|
|
12
|
+
RouteEvent,
|
|
13
|
+
StepEvent,
|
|
14
|
+
EventSeverity,
|
|
15
|
+
} from './types';
|
|
16
|
+
export {
|
|
17
|
+
MainEvents,
|
|
18
|
+
StepEventType,
|
|
19
|
+
RouteEventType,
|
|
20
|
+
StepExecutionEventStatus,
|
|
21
|
+
StepExecutionBlockedEventStatus,
|
|
22
|
+
} from './types';
|
|
7
23
|
export type {
|
|
8
24
|
PendingSwapWithQueueID,
|
|
9
25
|
PendingSwapStep,
|
|
10
26
|
PendingSwap,
|
|
11
27
|
EventType,
|
|
12
|
-
SwapProgressNotification,
|
|
13
28
|
} from './shared';
|
|
14
29
|
export {
|
|
15
30
|
getCurrentBlockchainOfOrNull,
|
|
@@ -29,8 +44,9 @@ export {
|
|
|
29
44
|
getRunningSwaps,
|
|
30
45
|
splitWalletNetwork,
|
|
31
46
|
resetRunningSwapNotifsOnPageLoad,
|
|
47
|
+
isApprovalTX,
|
|
32
48
|
} from './helpers';
|
|
33
|
-
export { useMigration, useQueueManager } from './hooks';
|
|
49
|
+
export { useMigration, useQueueManager, useEvents } from './hooks';
|
|
34
50
|
|
|
35
51
|
export function makeQueueDefinition(configs: Configs): SwapQueueDef {
|
|
36
52
|
initConfig(configs);
|