@rango-dev/queue-manager-rango-preset 0.53.0 → 0.53.1-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/CHANGELOG.md +9 -0
- package/dist/actions/common/checkEnvironmentBeforeExecuteTransaction.d.ts +8 -0
- package/dist/actions/common/checkEnvironmentBeforeExecuteTransaction.d.ts.map +1 -0
- package/dist/actions/common/produceNextStateForTransaction.d.ts +17 -0
- package/dist/actions/common/produceNextStateForTransaction.d.ts.map +1 -0
- package/dist/actions/common/utils.d.ts +5 -0
- package/dist/actions/common/utils.d.ts.map +1 -0
- package/dist/actions/{executeTransaction.d.ts → executeTransaction/executeTransaction.d.ts} +2 -1
- package/dist/actions/executeTransaction/executeTransaction.d.ts.map +1 -0
- package/dist/actions/executeTransaction/index.d.ts +2 -0
- package/dist/actions/executeTransaction/index.d.ts.map +1 -0
- package/dist/helpers.d.ts +7 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/queue-manager-rango-preset.build.json +1 -1
- package/package.json +2 -1
- package/src/actions/{executeTransaction.ts → common/checkEnvironmentBeforeExecuteTransaction.ts} +83 -64
- package/src/actions/common/produceNextStateForTransaction.ts +167 -0
- package/src/actions/common/utils.ts +25 -0
- package/src/actions/executeTransaction/executeTransaction.ts +107 -0
- package/src/actions/executeTransaction/index.ts +1 -0
- package/src/helpers.ts +43 -158
- package/dist/actions/executeTransaction.d.ts.map +0 -1
package/src/helpers.ts
CHANGED
|
@@ -37,7 +37,6 @@ import type {
|
|
|
37
37
|
PendingSwap,
|
|
38
38
|
PendingSwapStep,
|
|
39
39
|
SignerErrorCode,
|
|
40
|
-
SignerFactory,
|
|
41
40
|
StepStatus,
|
|
42
41
|
} from 'rango-types';
|
|
43
42
|
|
|
@@ -64,7 +63,6 @@ import {
|
|
|
64
63
|
import { httpService } from './services';
|
|
65
64
|
import { notifier } from './services/eventEmitter';
|
|
66
65
|
import {
|
|
67
|
-
getCurrentAddressOf,
|
|
68
66
|
getCurrentNamespaceOf,
|
|
69
67
|
getCurrentNamespaceOfOrNull,
|
|
70
68
|
getRelatedWallet,
|
|
@@ -1032,129 +1030,55 @@ export function isRequiredWalletConnected(
|
|
|
1032
1030
|
return { ok: matched, reason: 'account_miss_match' };
|
|
1033
1031
|
}
|
|
1034
1032
|
|
|
1035
|
-
export
|
|
1036
|
-
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1033
|
+
export function handleSuccessfulSign(
|
|
1034
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>,
|
|
1035
|
+
data: { isApproval: boolean }
|
|
1036
|
+
) {
|
|
1037
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1038
|
+
return ({ hash, response }: { hash: string; response?: any }) => {
|
|
1039
|
+
const { setTransactionDataByHash } = inMemoryTransactionsData();
|
|
1040
|
+
const { getStorage, next, schedule, context } = actions;
|
|
1041
|
+
const { meta } = context;
|
|
1042
|
+
const swap = getStorage().swapDetails;
|
|
1044
1043
|
|
|
1045
|
-
|
|
1046
|
-
const mobileWallet = isMobileWallet(sourceWallet?.walletType);
|
|
1047
|
-
const walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
1048
|
-
const currentStepNamespace = getCurrentNamespaceOf(swap, currentStep);
|
|
1044
|
+
const currentStep = getCurrentStep(swap)!;
|
|
1049
1045
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1046
|
+
const currentStepNamespace = getCurrentNamespaceOf(swap, currentStep);
|
|
1047
|
+
const explorerUrl = getScannerUrl(
|
|
1048
|
+
hash,
|
|
1049
|
+
currentStepNamespace.network,
|
|
1050
|
+
meta.blockchains
|
|
1051
|
+
);
|
|
1052
|
+
setStepTransactionIds(
|
|
1053
|
+
actions,
|
|
1054
|
+
hash,
|
|
1055
|
+
explorerUrl && (!response || (response && !response.hashRequiringUpdate))
|
|
1056
|
+
? {
|
|
1057
|
+
url: explorerUrl,
|
|
1058
|
+
description: data.isApproval ? 'Approve' : 'Swap',
|
|
1059
|
+
}
|
|
1060
|
+
: undefined
|
|
1061
|
+
);
|
|
1062
|
+
// response used for evm transactions to get receipt and track replaced
|
|
1063
|
+
if (response) {
|
|
1064
|
+
setTransactionDataByHash(hash, { response });
|
|
1054
1065
|
}
|
|
1066
|
+
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1067
|
+
next();
|
|
1055
1068
|
};
|
|
1069
|
+
}
|
|
1056
1070
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
const
|
|
1063
|
-
const
|
|
1064
|
-
getStorage,
|
|
1065
|
-
setStorage,
|
|
1066
|
-
nextStatus: 'failed',
|
|
1067
|
-
nextStepStatus: 'failed',
|
|
1068
|
-
message: extraMessage,
|
|
1069
|
-
details: undefined,
|
|
1070
|
-
errorCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
1071
|
-
});
|
|
1072
|
-
notifier({
|
|
1073
|
-
event: {
|
|
1074
|
-
type: StepEventType.FAILED,
|
|
1075
|
-
reason: extraMessage,
|
|
1076
|
-
reasonCode: 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
1077
|
-
inputAmount: getLastFinishedStepInput(swap),
|
|
1078
|
-
inputAmountUsd: getLastFinishedStepInputUsd(swap),
|
|
1079
|
-
},
|
|
1080
|
-
...updateResult,
|
|
1081
|
-
});
|
|
1082
|
-
failed();
|
|
1083
|
-
return onFinish();
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
const chainId = meta.blockchains?.[tx.blockChain]?.chainId;
|
|
1087
|
-
|
|
1088
|
-
const hasAlreadyProceededToSign =
|
|
1089
|
-
typeof swap.hasAlreadyProceededToSign === 'boolean';
|
|
1090
|
-
|
|
1091
|
-
let nextStatus: SwapStatus | undefined,
|
|
1092
|
-
nextStepStatus: StepStatus,
|
|
1093
|
-
message: string,
|
|
1094
|
-
details: string,
|
|
1095
|
-
eventType: StepEventType;
|
|
1096
|
-
|
|
1097
|
-
if (isApproval) {
|
|
1098
|
-
message = `Waiting for approval of ${currentStep?.fromSymbol} coin ${
|
|
1099
|
-
mobileWallet ? 'on your mobile phone!' : ''
|
|
1100
|
-
}`;
|
|
1101
|
-
details =
|
|
1102
|
-
'Waiting for approve transaction to be mined and confirmed successfully';
|
|
1103
|
-
nextStepStatus = 'waitingForApproval';
|
|
1104
|
-
nextStatus = undefined;
|
|
1105
|
-
eventType = StepEventType.TX_EXECUTION;
|
|
1106
|
-
} else if (hasAlreadyProceededToSign) {
|
|
1107
|
-
message = 'Transaction is expired. Please try again.';
|
|
1108
|
-
nextStepStatus = 'failed';
|
|
1109
|
-
nextStatus = 'failed';
|
|
1110
|
-
details = '';
|
|
1111
|
-
eventType = StepEventType.FAILED;
|
|
1112
|
-
} else {
|
|
1113
|
-
message = 'Executing transaction ...';
|
|
1114
|
-
nextStepStatus = 'running';
|
|
1115
|
-
nextStatus = 'running';
|
|
1116
|
-
details = `${mobileWallet ? 'Check your mobile phone!' : ''}`;
|
|
1117
|
-
eventType = StepEventType.TX_EXECUTION;
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
const updateResult = updateSwapStatus({
|
|
1121
|
-
getStorage,
|
|
1122
|
-
setStorage,
|
|
1123
|
-
nextStepStatus,
|
|
1124
|
-
nextStatus,
|
|
1125
|
-
message: message,
|
|
1126
|
-
details: details,
|
|
1127
|
-
hasAlreadyProceededToSign: isApproval
|
|
1128
|
-
? undefined
|
|
1129
|
-
: hasAlreadyProceededToSign,
|
|
1130
|
-
errorCode: hasAlreadyProceededToSign ? 'TX_EXPIRED' : undefined,
|
|
1131
|
-
});
|
|
1132
|
-
|
|
1133
|
-
if (eventType === StepEventType.FAILED) {
|
|
1134
|
-
notifier({
|
|
1135
|
-
event: {
|
|
1136
|
-
type: eventType,
|
|
1137
|
-
reason: message,
|
|
1138
|
-
reasonCode: updateResult.failureType ?? DEFAULT_ERROR_CODE,
|
|
1139
|
-
inputAmount: getLastFinishedStepInput(swap),
|
|
1140
|
-
inputAmountUsd: getLastFinishedStepInputUsd(swap),
|
|
1141
|
-
},
|
|
1142
|
-
...updateResult,
|
|
1143
|
-
});
|
|
1144
|
-
} else {
|
|
1145
|
-
notifier({
|
|
1146
|
-
event: { type: eventType, status: StepExecutionEventStatus.SEND_TX },
|
|
1147
|
-
...updateResult,
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1071
|
+
export function handleRejectedSign(
|
|
1072
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
1073
|
+
) {
|
|
1074
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1075
|
+
return (error: any) => {
|
|
1076
|
+
const { getStorage, setStorage, failed } = actions;
|
|
1077
|
+
const swap = getStorage().swapDetails;
|
|
1150
1078
|
|
|
1151
|
-
|
|
1152
|
-
failed();
|
|
1153
|
-
onFinish();
|
|
1154
|
-
return;
|
|
1155
|
-
}
|
|
1079
|
+
const currentStep = getCurrentStep(swap)!;
|
|
1156
1080
|
|
|
1157
|
-
|
|
1081
|
+
const sourceWallet = getRelatedWallet(swap, currentStep);
|
|
1158
1082
|
if (swap.status === 'failed') {
|
|
1159
1083
|
return;
|
|
1160
1084
|
}
|
|
@@ -1180,7 +1104,7 @@ export async function signTransaction(
|
|
|
1180
1104
|
message: extraMessage,
|
|
1181
1105
|
details: extraMessageDetail,
|
|
1182
1106
|
errorCode: extraMessageErrorCode,
|
|
1183
|
-
trace: error?.cause
|
|
1107
|
+
trace: error?.cause,
|
|
1184
1108
|
});
|
|
1185
1109
|
|
|
1186
1110
|
notifier({
|
|
@@ -1194,46 +1118,7 @@ export async function signTransaction(
|
|
|
1194
1118
|
...updateResult,
|
|
1195
1119
|
});
|
|
1196
1120
|
failed();
|
|
1197
|
-
onFinish();
|
|
1198
1121
|
};
|
|
1199
|
-
|
|
1200
|
-
let walletSigners: SignerFactory;
|
|
1201
|
-
|
|
1202
|
-
try {
|
|
1203
|
-
walletSigners = await getSigners(sourceWallet.walletType);
|
|
1204
|
-
} catch (error) {
|
|
1205
|
-
handleSignError(error as Error);
|
|
1206
|
-
return;
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
const signer = walletSigners.getSigner(txType);
|
|
1210
|
-
signer
|
|
1211
|
-
.signAndSendTx(tx, walletAddress, chainId)
|
|
1212
|
-
.then(({ hash, response }) => {
|
|
1213
|
-
const explorerUrl = getScannerUrl(
|
|
1214
|
-
hash,
|
|
1215
|
-
currentStepNamespace.network,
|
|
1216
|
-
meta.blockchains
|
|
1217
|
-
);
|
|
1218
|
-
setStepTransactionIds(
|
|
1219
|
-
actions,
|
|
1220
|
-
hash,
|
|
1221
|
-
explorerUrl &&
|
|
1222
|
-
(!response || (response && !response.hashRequiringUpdate))
|
|
1223
|
-
? {
|
|
1224
|
-
url: explorerUrl,
|
|
1225
|
-
description: isApproval ? 'Approve' : 'Swap',
|
|
1226
|
-
}
|
|
1227
|
-
: undefined
|
|
1228
|
-
);
|
|
1229
|
-
// response used for evm transactions to get receipt and track replaced
|
|
1230
|
-
if (response) {
|
|
1231
|
-
setTransactionDataByHash(hash, { response });
|
|
1232
|
-
}
|
|
1233
|
-
schedule(SwapActionTypes.CHECK_TRANSACTION_STATUS);
|
|
1234
|
-
next();
|
|
1235
|
-
onFinish();
|
|
1236
|
-
}, handleSignError);
|
|
1237
1122
|
}
|
|
1238
1123
|
|
|
1239
1124
|
export function checkWaitingForConnectWalletChange(params: {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"executeTransaction.d.ts","sourceRoot":"","sources":["../../src/actions/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAyBrE;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,eAAe,CAAC,WAAW,EAAE,eAAe,EAAE,gBAAgB,CAAC,GACvE,OAAO,CAAC,IAAI,CAAC,CAmGf"}
|