@rango-dev/queue-manager-rango-preset 0.5.1-next.7 → 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
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import mitt from 'mitt';
|
|
2
|
+
import {
|
|
3
|
+
MainEvents,
|
|
4
|
+
RemoveNameField,
|
|
5
|
+
Route,
|
|
6
|
+
RouteEvent,
|
|
7
|
+
RouteEventType,
|
|
8
|
+
RouteExecutionEvents,
|
|
9
|
+
EventSeverity,
|
|
10
|
+
Step,
|
|
11
|
+
StepEvent,
|
|
12
|
+
StepEventType,
|
|
13
|
+
StepExecutionEventStatus,
|
|
14
|
+
StepExecutionBlockedEventStatus,
|
|
15
|
+
} from '../types';
|
|
16
|
+
import { PendingSwap, PendingSwapStep } from 'rango-types/lib';
|
|
17
|
+
import { getCurrentBlockchainOfOrNull } from '../shared';
|
|
18
|
+
import {
|
|
19
|
+
getCurrentStepTx,
|
|
20
|
+
getFailedStep,
|
|
21
|
+
getLastSuccessfulStep,
|
|
22
|
+
isApprovalCurrentStepTx,
|
|
23
|
+
} from '../helpers';
|
|
24
|
+
|
|
25
|
+
type NotifierParams = {
|
|
26
|
+
swap: PendingSwap;
|
|
27
|
+
step: PendingSwapStep | null;
|
|
28
|
+
} & {
|
|
29
|
+
event: RemoveNameField<StepEvent, 'message' | 'messageSeverity'>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function createSteps(swapSteps: PendingSwapStep[]): Step[] {
|
|
33
|
+
return swapSteps.map((swapStep) => {
|
|
34
|
+
const {
|
|
35
|
+
diagnosisUrl,
|
|
36
|
+
estimatedTimeInSeconds,
|
|
37
|
+
explorerUrl,
|
|
38
|
+
feeInUsd,
|
|
39
|
+
executedTransactionId,
|
|
40
|
+
executedTransactionTime,
|
|
41
|
+
expectedOutputAmountHumanReadable,
|
|
42
|
+
fromBlockchain,
|
|
43
|
+
toBlockchain,
|
|
44
|
+
fromSymbol,
|
|
45
|
+
toSymbol,
|
|
46
|
+
fromSymbolAddress,
|
|
47
|
+
toSymbolAddress,
|
|
48
|
+
swapperType,
|
|
49
|
+
swapperId,
|
|
50
|
+
outputAmount,
|
|
51
|
+
fromAmountMaxValue,
|
|
52
|
+
fromAmountMinValue,
|
|
53
|
+
fromAmountPrecision,
|
|
54
|
+
fromAmountRestrictionType,
|
|
55
|
+
fromDecimals,
|
|
56
|
+
status: stepStatus,
|
|
57
|
+
} = swapStep;
|
|
58
|
+
|
|
59
|
+
const step: Step = {
|
|
60
|
+
diagnosisUrl,
|
|
61
|
+
estimatedTimeInSeconds,
|
|
62
|
+
explorerUrl,
|
|
63
|
+
feeInUsd,
|
|
64
|
+
executedTransactionId,
|
|
65
|
+
executedTransactionTime,
|
|
66
|
+
expectedOutputAmountHumanReadable,
|
|
67
|
+
fromBlockchain,
|
|
68
|
+
toBlockchain,
|
|
69
|
+
fromSymbol,
|
|
70
|
+
toSymbol,
|
|
71
|
+
fromSymbolAddress,
|
|
72
|
+
toSymbolAddress,
|
|
73
|
+
swapperName: swapperId,
|
|
74
|
+
swapperType,
|
|
75
|
+
outputAmount,
|
|
76
|
+
fromAmountMaxValue,
|
|
77
|
+
fromAmountMinValue,
|
|
78
|
+
fromAmountPrecision,
|
|
79
|
+
fromAmountRestrictionType,
|
|
80
|
+
fromDecimals,
|
|
81
|
+
status: stepStatus,
|
|
82
|
+
transaction: getCurrentStepTx(swapStep),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return step;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getEventPayload(
|
|
90
|
+
swap: PendingSwap,
|
|
91
|
+
type: StepEventType | RouteEventType,
|
|
92
|
+
swapStep?: PendingSwapStep
|
|
93
|
+
): { route: Route; step: Step } {
|
|
94
|
+
const {
|
|
95
|
+
creationTime,
|
|
96
|
+
finishTime,
|
|
97
|
+
requestId,
|
|
98
|
+
inputAmount,
|
|
99
|
+
status,
|
|
100
|
+
wallets,
|
|
101
|
+
steps,
|
|
102
|
+
settings,
|
|
103
|
+
} = swap;
|
|
104
|
+
|
|
105
|
+
const routeSteps = createSteps(steps);
|
|
106
|
+
const route: Route = {
|
|
107
|
+
creationTime,
|
|
108
|
+
finishTime,
|
|
109
|
+
requestId,
|
|
110
|
+
inputAmount,
|
|
111
|
+
status,
|
|
112
|
+
wallets,
|
|
113
|
+
steps: routeSteps,
|
|
114
|
+
slippage: settings.slippage,
|
|
115
|
+
infiniteApproval: settings.infiniteApprove,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const result: { route: Route; step: Step } = {
|
|
119
|
+
route,
|
|
120
|
+
step: routeSteps[routeSteps.length - 1],
|
|
121
|
+
};
|
|
122
|
+
if (swapStep) result.step = createSteps([swapStep])[0];
|
|
123
|
+
else {
|
|
124
|
+
if (type === 'failed') {
|
|
125
|
+
const failedStep = getFailedStep(routeSteps);
|
|
126
|
+
if (failedStep) result.step = failedStep;
|
|
127
|
+
} else {
|
|
128
|
+
const lastSuccessfulStep = getLastSuccessfulStep(routeSteps);
|
|
129
|
+
if (lastSuccessfulStep) result.step = lastSuccessfulStep;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const eventEmitter = mitt<RouteExecutionEvents>();
|
|
137
|
+
|
|
138
|
+
function emitRouteEvent(stepEvent: StepEvent, route: Route) {
|
|
139
|
+
let routeEvent: RouteEvent | undefined;
|
|
140
|
+
const { type } = stepEvent;
|
|
141
|
+
switch (type) {
|
|
142
|
+
case StepEventType.STARTED:
|
|
143
|
+
routeEvent = { ...stepEvent, type: RouteEventType.STARTED };
|
|
144
|
+
break;
|
|
145
|
+
case StepEventType.FAILED:
|
|
146
|
+
routeEvent = { ...stepEvent, type: RouteEventType.FAILED };
|
|
147
|
+
break;
|
|
148
|
+
case StepEventType.SUCCEEDED:
|
|
149
|
+
routeEvent = { ...stepEvent, type: RouteEventType.SUCCEEDED };
|
|
150
|
+
break;
|
|
151
|
+
default:
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
if (routeEvent)
|
|
155
|
+
eventEmitter.emit(MainEvents.RouteEvent, { event: routeEvent, route });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function emitStepEvent(stepEvent: StepEvent, route: Route, step: Step) {
|
|
159
|
+
eventEmitter.emit(MainEvents.StepEvent, { event: stepEvent, route, step });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function notifier(params: NotifierParams) {
|
|
163
|
+
console.log({ originalEvent: params.step });
|
|
164
|
+
const { event } = params;
|
|
165
|
+
const { type } = event;
|
|
166
|
+
const { route, step } = getEventPayload(
|
|
167
|
+
params.swap,
|
|
168
|
+
type,
|
|
169
|
+
params.step ?? undefined
|
|
170
|
+
);
|
|
171
|
+
const fromAsset = `${step.fromBlockchain}.${step.fromSymbol}`;
|
|
172
|
+
const toAsset = `${step.toBlockchain}.${step.toSymbol}`;
|
|
173
|
+
const outputAmount = step.outputAmount ?? '';
|
|
174
|
+
const currentFromBlockchain = !!params.step
|
|
175
|
+
? getCurrentBlockchainOfOrNull(params.swap, params.step)
|
|
176
|
+
: null;
|
|
177
|
+
let message = '';
|
|
178
|
+
let messageSeverity: StepEvent['messageSeverity'] = EventSeverity.INFO;
|
|
179
|
+
|
|
180
|
+
switch (type) {
|
|
181
|
+
case StepEventType.STARTED:
|
|
182
|
+
message = 'Swap process started';
|
|
183
|
+
messageSeverity = EventSeverity.SUCCESS;
|
|
184
|
+
break;
|
|
185
|
+
case StepEventType.SUCCEEDED:
|
|
186
|
+
message = `You received ${outputAmount} ${toAsset}, hooray!`;
|
|
187
|
+
messageSeverity = EventSeverity.SUCCESS;
|
|
188
|
+
break;
|
|
189
|
+
case StepEventType.FAILED:
|
|
190
|
+
message = `Swap failed: ${
|
|
191
|
+
params.swap?.extraMessage ?? 'Reason is unknown'
|
|
192
|
+
}`;
|
|
193
|
+
messageSeverity = EventSeverity.ERROR;
|
|
194
|
+
break;
|
|
195
|
+
case StepEventType.TX_EXECUTION:
|
|
196
|
+
if (event.status === StepExecutionEventStatus.CREATE_TX) {
|
|
197
|
+
message = 'Please wait while the transaction is created ...';
|
|
198
|
+
messageSeverity = EventSeverity.INFO;
|
|
199
|
+
} else if (event.status === StepExecutionEventStatus.SEND_TX) {
|
|
200
|
+
if (params.step && isApprovalCurrentStepTx(params.step))
|
|
201
|
+
message = `Please confirm '${step.swapperName}' smart contract access to ${fromAsset}`;
|
|
202
|
+
else message = 'Please confirm transaction request in your wallet';
|
|
203
|
+
messageSeverity = EventSeverity.WARNING;
|
|
204
|
+
} else if (event.status === StepExecutionEventStatus.TX_SENT) {
|
|
205
|
+
message = 'Transaction sent successfully';
|
|
206
|
+
messageSeverity = EventSeverity.INFO;
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
case StepEventType.CHECK_STATUS:
|
|
210
|
+
if (params.step && isApprovalCurrentStepTx(params.step))
|
|
211
|
+
message = 'Checking approve transacation status ...';
|
|
212
|
+
else message = 'Checking transacation status ...';
|
|
213
|
+
messageSeverity = EventSeverity.INFO;
|
|
214
|
+
break;
|
|
215
|
+
case StepEventType.APPROVAL_TX_SUCCEEDED:
|
|
216
|
+
message = 'Smart contract called successfully';
|
|
217
|
+
messageSeverity = EventSeverity.SUCCESS;
|
|
218
|
+
break;
|
|
219
|
+
case StepEventType.OUTPUT_REVEALED:
|
|
220
|
+
message = 'Transaction output amount revealed';
|
|
221
|
+
messageSeverity = EventSeverity.SUCCESS;
|
|
222
|
+
break;
|
|
223
|
+
|
|
224
|
+
case StepEventType.TX_EXECUTION_BLOCKED:
|
|
225
|
+
if (
|
|
226
|
+
event.status ===
|
|
227
|
+
StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT
|
|
228
|
+
) {
|
|
229
|
+
message = 'Please connect your wallet.';
|
|
230
|
+
messageSeverity = EventSeverity.WARNING;
|
|
231
|
+
} else if (
|
|
232
|
+
event.status === StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE
|
|
233
|
+
) {
|
|
234
|
+
message = 'Waiting for other swaps to complete';
|
|
235
|
+
messageSeverity = EventSeverity.WARNING;
|
|
236
|
+
} else if (
|
|
237
|
+
event.status ===
|
|
238
|
+
StepExecutionBlockedEventStatus.WAITING_FOR_CHANGE_WALLET_ACCOUNT
|
|
239
|
+
) {
|
|
240
|
+
message = 'Please change your wallet account.';
|
|
241
|
+
messageSeverity = EventSeverity.WARNING;
|
|
242
|
+
} else if (
|
|
243
|
+
event.status ===
|
|
244
|
+
StepExecutionBlockedEventStatus.WAITING_FOR_NETWORK_CHANGE
|
|
245
|
+
) {
|
|
246
|
+
message = `Please change your wallet network to ${currentFromBlockchain}.`;
|
|
247
|
+
messageSeverity = EventSeverity.WARNING;
|
|
248
|
+
}
|
|
249
|
+
break;
|
|
250
|
+
|
|
251
|
+
default:
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (params.step)
|
|
256
|
+
emitStepEvent({ ...event, message, messageSeverity }, route, step);
|
|
257
|
+
else emitRouteEvent({ ...event, message, messageSeverity }, route);
|
|
258
|
+
}
|
package/src/shared-errors.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isSignerErrorCode,
|
|
9
9
|
isAPIErrorCode,
|
|
10
10
|
} from 'rango-types';
|
|
11
|
+
import { DEFAULT_ERROR_CODE } from './constants';
|
|
11
12
|
|
|
12
13
|
export type ErrorDetail = {
|
|
13
14
|
extraMessage: string;
|
|
@@ -117,24 +118,23 @@ export class PrettyError extends Error {
|
|
|
117
118
|
export function mapAppErrorCodesToAPIErrorCode(
|
|
118
119
|
errorCode: string | null
|
|
119
120
|
): APIErrorCode {
|
|
120
|
-
const defaultErrorCode = 'CLIENT_UNEXPECTED_BEHAVIOUR';
|
|
121
121
|
try {
|
|
122
|
-
if (!errorCode) return
|
|
122
|
+
if (!errorCode) return DEFAULT_ERROR_CODE;
|
|
123
123
|
if (isAPIErrorCode(errorCode)) return errorCode;
|
|
124
124
|
if (isSignerErrorCode(errorCode)) {
|
|
125
125
|
const t: { [key in SignerErrorCodeType]: APIErrorCode } = {
|
|
126
126
|
[SignerErrorCode.REJECTED_BY_USER]: 'USER_REJECT',
|
|
127
127
|
[SignerErrorCode.SIGN_TX_ERROR]: 'CALL_WALLET_FAILED',
|
|
128
128
|
[SignerErrorCode.SEND_TX_ERROR]: 'SEND_TX_FAILED',
|
|
129
|
-
[SignerErrorCode.NOT_IMPLEMENTED]:
|
|
130
|
-
[SignerErrorCode.OPERATION_UNSUPPORTED]:
|
|
131
|
-
[SignerErrorCode.UNEXPECTED_BEHAVIOUR]:
|
|
129
|
+
[SignerErrorCode.NOT_IMPLEMENTED]: DEFAULT_ERROR_CODE,
|
|
130
|
+
[SignerErrorCode.OPERATION_UNSUPPORTED]: DEFAULT_ERROR_CODE,
|
|
131
|
+
[SignerErrorCode.UNEXPECTED_BEHAVIOUR]: DEFAULT_ERROR_CODE,
|
|
132
132
|
};
|
|
133
133
|
return t[errorCode];
|
|
134
134
|
}
|
|
135
|
-
return
|
|
135
|
+
return DEFAULT_ERROR_CODE;
|
|
136
136
|
} catch (err) {
|
|
137
|
-
return
|
|
137
|
+
return DEFAULT_ERROR_CODE;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
package/src/shared.ts
CHANGED
|
@@ -30,12 +30,6 @@ export interface PendingSwapWithQueueID {
|
|
|
30
30
|
swap: PendingSwap;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export type SwapProgressNotification = {
|
|
34
|
-
eventType: EventType;
|
|
35
|
-
swap: PendingSwap | null;
|
|
36
|
-
step: PendingSwapStep | null;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
33
|
export type WalletBalance = {
|
|
40
34
|
chain: Network;
|
|
41
35
|
symbol: string;
|
package/src/types.ts
CHANGED
|
@@ -7,8 +7,15 @@ import {
|
|
|
7
7
|
WalletState,
|
|
8
8
|
WalletType,
|
|
9
9
|
} from '@rango-dev/wallets-shared';
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
10
|
+
import { APIErrorCode, EvmBlockchainMeta, SignerFactory } from 'rango-types';
|
|
11
|
+
import { Transaction } from 'rango-sdk';
|
|
12
|
+
import { PendingSwap, PendingSwapStep, Wallet } from './shared';
|
|
13
|
+
|
|
14
|
+
export type RemoveNameField<T, U extends string> = {
|
|
15
|
+
[Property in keyof T as Exclude<Property, U>]: T[Property];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ArrayElement<A> = A extends readonly (infer T)[] ? T : never;
|
|
12
19
|
|
|
13
20
|
export type SwapQueueDef = QueueDef<
|
|
14
21
|
SwapStorage,
|
|
@@ -62,7 +69,6 @@ export interface SwapQueueContext extends QueueContext {
|
|
|
62
69
|
) => Promise<ConnectResult> | undefined;
|
|
63
70
|
state: (type: WalletType) => WalletState;
|
|
64
71
|
isMobileWallet: (type: WalletType) => boolean;
|
|
65
|
-
notifier: (data: SwapProgressNotification) => void;
|
|
66
72
|
|
|
67
73
|
// Dynamically will be added to context.
|
|
68
74
|
claimedBy?: string;
|
|
@@ -74,6 +80,146 @@ export interface UseQueueManagerParams {
|
|
|
74
80
|
disconnectedWallet: WalletType | undefined;
|
|
75
81
|
clearDisconnectedWallet: () => void;
|
|
76
82
|
evmChains: EvmBlockchainMeta[];
|
|
77
|
-
notifier: SwapQueueContext['notifier'];
|
|
78
83
|
canSwitchNetworkTo: (type: WalletType, network: Network) => boolean;
|
|
79
84
|
}
|
|
85
|
+
|
|
86
|
+
export enum MainEvents {
|
|
87
|
+
RouteEvent = 'routeEvent',
|
|
88
|
+
StepEvent = 'stepEvent',
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type Step = Pick<
|
|
92
|
+
PendingSwapStep,
|
|
93
|
+
| 'diagnosisUrl'
|
|
94
|
+
| 'estimatedTimeInSeconds'
|
|
95
|
+
| 'explorerUrl'
|
|
96
|
+
| 'feeInUsd'
|
|
97
|
+
| 'executedTransactionId'
|
|
98
|
+
| 'executedTransactionTime'
|
|
99
|
+
| 'expectedOutputAmountHumanReadable'
|
|
100
|
+
| 'fromBlockchain'
|
|
101
|
+
| 'toBlockchain'
|
|
102
|
+
| 'fromSymbol'
|
|
103
|
+
| 'toSymbol'
|
|
104
|
+
| 'toSymbolAddress'
|
|
105
|
+
| 'fromSymbolAddress'
|
|
106
|
+
| 'swapperType'
|
|
107
|
+
| 'outputAmount'
|
|
108
|
+
| 'fromAmountMaxValue'
|
|
109
|
+
| 'fromAmountMinValue'
|
|
110
|
+
| 'fromAmountPrecision'
|
|
111
|
+
| 'fromAmountRestrictionType'
|
|
112
|
+
| 'fromDecimals'
|
|
113
|
+
| 'status'
|
|
114
|
+
> & { swapperName: string; transaction: Transaction | null };
|
|
115
|
+
|
|
116
|
+
export type Route = Pick<
|
|
117
|
+
PendingSwap,
|
|
118
|
+
| 'creationTime'
|
|
119
|
+
| 'finishTime'
|
|
120
|
+
| 'requestId'
|
|
121
|
+
| 'inputAmount'
|
|
122
|
+
| 'status'
|
|
123
|
+
| 'wallets'
|
|
124
|
+
> & { steps: Step[]; slippage: string; infiniteApproval?: boolean };
|
|
125
|
+
|
|
126
|
+
export type SwapEvent = RouteEvent | StepEvent;
|
|
127
|
+
|
|
128
|
+
export enum RouteEventType {
|
|
129
|
+
STARTED = 'started',
|
|
130
|
+
FAILED = 'failed',
|
|
131
|
+
SUCCEEDED = 'succeeded',
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export enum StepExecutionEventStatus {
|
|
135
|
+
CREATE_TX = 'create_tx',
|
|
136
|
+
SEND_TX = 'send_tx',
|
|
137
|
+
TX_SENT = 'tx_sent',
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export enum StepExecutionBlockedEventStatus {
|
|
141
|
+
WAITING_FOR_QUEUE = 'waiting_for_queue',
|
|
142
|
+
WAITING_FOR_WALLET_CONNECT = 'waiting_for_wallet_connect',
|
|
143
|
+
WAITING_FOR_NETWORK_CHANGE = 'waiting_for_network_change',
|
|
144
|
+
WAITING_FOR_CHANGE_WALLET_ACCOUNT = 'waiting_for_change_wallet_account',
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export enum StepEventType {
|
|
148
|
+
STARTED = 'started',
|
|
149
|
+
FAILED = 'failed',
|
|
150
|
+
SUCCEEDED = 'succeeded',
|
|
151
|
+
TX_EXECUTION = 'tx_execution',
|
|
152
|
+
TX_EXECUTION_BLOCKED = 'tx_execution_blocked',
|
|
153
|
+
APPROVAL_TX_SUCCEEDED = 'approval_tx_succeeded',
|
|
154
|
+
CHECK_STATUS = 'check_status',
|
|
155
|
+
OUTPUT_REVEALED = 'output_revealed',
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export enum EventSeverity {
|
|
159
|
+
ERROR = 'error',
|
|
160
|
+
SUCCESS = 'success',
|
|
161
|
+
WARNING = 'warning',
|
|
162
|
+
INFO = 'info',
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export type Event<
|
|
166
|
+
T extends StepEventType | RouteEventType,
|
|
167
|
+
U extends Record<string, unknown> = Record<string, unknown>
|
|
168
|
+
> = {
|
|
169
|
+
type: T;
|
|
170
|
+
message: string;
|
|
171
|
+
messageSeverity: EventSeverity;
|
|
172
|
+
} & U;
|
|
173
|
+
|
|
174
|
+
export type FailedRouteEventPayload = {
|
|
175
|
+
reason?: string;
|
|
176
|
+
reasonCode: APIErrorCode;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export type SucceededRouteEventPayload = {
|
|
180
|
+
outputAmount: string;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export type StepExecutionEventPayload = {
|
|
184
|
+
status:
|
|
185
|
+
| StepExecutionEventStatus.CREATE_TX
|
|
186
|
+
| StepExecutionEventStatus.SEND_TX
|
|
187
|
+
| StepExecutionEventStatus.TX_SENT;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export type StepBlockedEventPayload =
|
|
191
|
+
| { status: StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE }
|
|
192
|
+
| {
|
|
193
|
+
status: StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT;
|
|
194
|
+
requiredWallet?: string;
|
|
195
|
+
requiredAccount?: string;
|
|
196
|
+
}
|
|
197
|
+
| {
|
|
198
|
+
status: StepExecutionBlockedEventStatus.WAITING_FOR_CHANGE_WALLET_ACCOUNT;
|
|
199
|
+
requiredAccount?: string;
|
|
200
|
+
}
|
|
201
|
+
| {
|
|
202
|
+
status: StepExecutionBlockedEventStatus.WAITING_FOR_NETWORK_CHANGE;
|
|
203
|
+
currentNetwork?: string;
|
|
204
|
+
requiredNetwork?: string;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export type StepEvent =
|
|
208
|
+
| Event<StepEventType.STARTED>
|
|
209
|
+
| Event<StepEventType.SUCCEEDED, { outputAmount: string }>
|
|
210
|
+
| Event<StepEventType.FAILED, FailedRouteEventPayload>
|
|
211
|
+
| Event<StepEventType.TX_EXECUTION, StepExecutionEventPayload>
|
|
212
|
+
| Event<StepEventType.TX_EXECUTION_BLOCKED, StepBlockedEventPayload>
|
|
213
|
+
| Event<StepEventType.CHECK_STATUS>
|
|
214
|
+
| Event<StepEventType.APPROVAL_TX_SUCCEEDED>
|
|
215
|
+
| Event<StepEventType.OUTPUT_REVEALED, { outputAmount: string }>;
|
|
216
|
+
|
|
217
|
+
export type RouteEvent =
|
|
218
|
+
| Event<RouteEventType.STARTED>
|
|
219
|
+
| Event<RouteEventType.FAILED, FailedRouteEventPayload>
|
|
220
|
+
| Event<RouteEventType.SUCCEEDED, SucceededRouteEventPayload>;
|
|
221
|
+
|
|
222
|
+
export type RouteExecutionEvents = {
|
|
223
|
+
[MainEvents.RouteEvent]: { route: Route; event: RouteEvent };
|
|
224
|
+
[MainEvents.StepEvent]: { route: Route; step: Step; event: StepEvent };
|
|
225
|
+
};
|