@rango-dev/queue-manager-rango-preset 0.22.1-next.4 → 0.22.1-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/queue-manager-rango-preset",
3
- "version": "0.22.1-next.4",
3
+ "version": "0.22.1-next.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
package/src/helpers.ts CHANGED
@@ -1,37 +1,45 @@
1
- import {
2
- ExecuterActions,
3
- QueueInfo,
4
- QueueName,
5
- QueueType,
6
- } from '@rango-dev/queue-manager-core';
7
- import {
1
+ /* eslint-disable destructuring/in-params */
2
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
3
+ /* eslint-disable @typescript-eslint/no-floating-promises */
4
+ import type {
5
+ PendingSwap,
6
+ PendingSwapStep,
7
+ StepStatus,
8
+ SwapStatus,
9
+ Wallet,
10
+ } from './shared';
11
+ import type {
8
12
  ArrayElement,
9
- BlockReason,
10
- StepEventType,
11
- SwapActionTypes,
13
+ Step,
12
14
  SwapQueueContext,
13
15
  SwapQueueDef,
14
16
  SwapStorage,
15
- StepExecutionEventStatus,
16
- StepExecutionBlockedEventStatus,
17
- Step,
18
17
  } from './types';
19
- import {
20
- getBlockChainNameFromId,
18
+ import type {
19
+ ExecuterActions,
20
+ Manager,
21
+ QueueInfo,
22
+ QueueName,
23
+ QueueType,
24
+ } from '@rango-dev/queue-manager-core';
25
+ import type { Providers } from '@rango-dev/wallets-react';
26
+ import type {
21
27
  Meta,
22
28
  Network,
23
- Networks,
24
29
  WalletState,
25
30
  WalletType,
26
31
  } from '@rango-dev/wallets-shared';
27
- import { Providers, readAccountAddress } from '@rango-dev/wallets-react';
28
-
29
- import {
30
- Transaction,
31
- TransactionType,
32
- EvmBlockchainMeta,
32
+ import type {
33
33
  CreateTransactionResponse,
34
+ EvmBlockchainMeta,
35
+ Transaction,
34
36
  } from 'rango-sdk';
37
+ import type { APIErrorCode, SignerErrorCode } from 'rango-types/lib';
38
+
39
+ import { Status } from '@rango-dev/queue-manager-core';
40
+ import { readAccountAddress } from '@rango-dev/wallets-react';
41
+ import { getBlockChainNameFromId, Networks } from '@rango-dev/wallets-shared';
42
+ import { TransactionType } from 'rango-sdk';
35
43
 
36
44
  import {
37
45
  DEFAULT_ERROR_CODE,
@@ -39,32 +47,31 @@ import {
39
47
  ERROR_MESSAGE_WAIT_FOR_WALLET,
40
48
  ERROR_MESSAGE_WAIT_FOR_WALLET_DESCRIPTION,
41
49
  } from './constants';
42
- import { Manager } from '@rango-dev/queue-manager-core';
43
- import { Status } from '@rango-dev/queue-manager-core';
50
+ import { httpService } from './services';
51
+ import { notifier } from './services/eventEmitter';
44
52
  import {
53
+ getCurrentAddressOf,
45
54
  getCurrentBlockchainOf,
46
55
  getCurrentBlockchainOfOrNull,
47
- getScannerUrl,
56
+ getRelatedWallet,
48
57
  getRelatedWalletOrNull,
58
+ getScannerUrl,
49
59
  MessageSeverity,
50
- PendingSwap,
51
60
  PendingSwapNetworkStatus,
52
- PendingSwapStep,
53
- StepStatus,
54
- SwapStatus,
55
- Wallet,
56
- getRelatedWallet,
57
- getCurrentAddressOf,
58
61
  } from './shared';
59
- import { logRPCError } from './shared-sentry';
60
62
  import {
61
- PrettyError,
62
63
  mapAppErrorCodesToAPIErrorCode,
63
64
  prettifyErrorMessage,
65
+ PrettyError,
64
66
  } from './shared-errors';
65
- import { httpService } from './services';
66
- import { APIErrorCode, SignerErrorCode } from 'rango-types/lib';
67
- import { notifier } from './services/eventEmitter';
67
+ import { logRPCError } from './shared-sentry';
68
+ import {
69
+ BlockReason,
70
+ StepEventType,
71
+ StepExecutionBlockedEventStatus,
72
+ StepExecutionEventStatus,
73
+ SwapActionTypes,
74
+ } from './types';
68
75
 
69
76
  type WhenTaskBlocked = Parameters<NonNullable<SwapQueueDef['whenTaskBlocked']>>;
70
77
  type WhenTaskBlockedEvent = WhenTaskBlocked[0];
@@ -108,7 +115,9 @@ export function inMemoryTransactionsData() {
108
115
  swapTransactionToDataMap[hash] || {},
109
116
  setTransactionDataByHash: (hash: string, data: TransactionData) => {
110
117
  const r = swapTransactionToDataMap[hash];
111
- if (!r) swapTransactionToDataMap[hash] = {};
118
+ if (!r) {
119
+ swapTransactionToDataMap[hash] = {};
120
+ }
112
121
  swapTransactionToDataMap[hash].response =
113
122
  data.response || swapTransactionToDataMap[hash].response;
114
123
  swapTransactionToDataMap[hash].receiptReceived =
@@ -213,19 +222,25 @@ export const setCurrentStepTx = (
213
222
  const txType = transaction.type;
214
223
  switch (txType) {
215
224
  case TransactionType.EVM:
216
- if (transaction.isApprovalTx)
225
+ if (transaction.isApprovalTx) {
217
226
  currentStep.evmApprovalTransaction = transaction;
218
- else currentStep.evmTransaction = transaction;
227
+ } else {
228
+ currentStep.evmTransaction = transaction;
229
+ }
219
230
  break;
220
231
  case TransactionType.TRON:
221
- if (transaction.isApprovalTx)
232
+ if (transaction.isApprovalTx) {
222
233
  currentStep.tronApprovalTransaction = transaction;
223
- else currentStep.tronTransaction = transaction;
234
+ } else {
235
+ currentStep.tronTransaction = transaction;
236
+ }
224
237
  break;
225
238
  case TransactionType.STARKNET:
226
- if (transaction.isApprovalTx)
239
+ if (transaction.isApprovalTx) {
227
240
  currentStep.starknetApprovalTransaction = transaction;
228
- else currentStep.starknetTransaction = transaction;
241
+ } else {
242
+ currentStep.starknetTransaction = transaction;
243
+ }
229
244
  break;
230
245
  case TransactionType.COSMOS:
231
246
  currentStep.cosmosTransaction = transaction;
@@ -323,12 +338,17 @@ export function updateSwapStatus({
323
338
  swap,
324
339
  step: currentStep,
325
340
  };
326
- if (!!nextStepStatus && !!currentStep) currentStep.status = nextStepStatus;
341
+ if (!!nextStepStatus && !!currentStep) {
342
+ currentStep.status = nextStepStatus;
343
+ }
327
344
 
328
- if (nextStatus) swap.status = nextStatus;
345
+ if (nextStatus) {
346
+ swap.status = nextStatus;
347
+ }
329
348
  swap.hasAlreadyProceededToSign = hasAlreadyProceededToSign;
330
- if (!!nextStatus && ['failed', 'success'].includes(nextStatus))
349
+ if (!!nextStatus && ['failed', 'success'].includes(nextStatus)) {
331
350
  swap.finishTime = new Date().getTime().toString();
351
+ }
332
352
 
333
353
  if (!!message || !!details) {
334
354
  swap.extraMessage = message || '';
@@ -361,15 +381,23 @@ export function updateSwapStatus({
361
381
  })
362
382
  .then()
363
383
  .catch();
364
- } else if (!!nextStepStatus && ['running'].includes(nextStepStatus))
384
+ } else if (!!nextStepStatus && ['running'].includes(nextStepStatus)) {
365
385
  swap.extraMessageSeverity = MessageSeverity.info;
366
- else if (!!nextStepStatus && ['success', 'approved'].includes(nextStepStatus))
386
+ } else if (
387
+ !!nextStepStatus &&
388
+ ['success', 'approved'].includes(nextStepStatus)
389
+ ) {
367
390
  swap.extraMessageSeverity = MessageSeverity.success;
368
- else if (nextStepStatus && ['waitingForApproval'].includes(nextStepStatus))
391
+ } else if (
392
+ nextStepStatus &&
393
+ ['waitingForApproval'].includes(nextStepStatus)
394
+ ) {
369
395
  swap.extraMessageSeverity = MessageSeverity.warning;
396
+ }
370
397
 
371
- if (nextStepStatus === 'running' && currentStep)
398
+ if (nextStepStatus === 'running' && currentStep) {
372
399
  currentStep.startTransactionTime = new Date().getTime();
400
+ }
373
401
 
374
402
  setStorage({
375
403
  ...getStorage(),
@@ -395,7 +423,7 @@ export function setStepTransactionIds(
395
423
  const currentStep = getCurrentStep(swap)!;
396
424
  currentStep.executedTransactionId = txId;
397
425
  currentStep.executedTransactionTime = new Date().getTime().toString();
398
- if (explorerUrl?.url)
426
+ if (explorerUrl?.url) {
399
427
  currentStep.explorerUrl = [
400
428
  ...(currentStep.explorerUrl || []),
401
429
  {
@@ -403,11 +431,15 @@ export function setStepTransactionIds(
403
431
  description: explorerUrl.description || null,
404
432
  },
405
433
  ];
434
+ }
406
435
 
407
436
  const isApproval = isApprovalCurrentStepTx(currentStep);
408
437
 
409
- if (isApproval) swap.extraMessage = 'Checking approve transaction status ...';
410
- else swap.extraMessage = 'Checking transaction status ...';
438
+ if (isApproval) {
439
+ swap.extraMessage = 'Checking approve transaction status ...';
440
+ } else {
441
+ swap.extraMessage = 'Checking transaction status ...';
442
+ }
411
443
 
412
444
  swap.extraMessageDetail = '';
413
445
  swap.extraMessageSeverity = MessageSeverity.info;
@@ -447,7 +479,9 @@ export function markRunningSwapAsWaitingForConnectingWallet(
447
479
  ): void {
448
480
  const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
449
481
  const currentStep = getCurrentStep(swap);
450
- if (!currentStep) return;
482
+ if (!currentStep) {
483
+ return;
484
+ }
451
485
  const currentTime = new Date();
452
486
  swap.lastNotificationTime = currentTime.getTime().toString();
453
487
 
@@ -488,7 +522,9 @@ export function markRunningSwapAsSwitchingNetwork({
488
522
  const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
489
523
 
490
524
  const currentStep = getCurrentStep(swap);
491
- if (!currentStep) return;
525
+ if (!currentStep) {
526
+ return;
527
+ }
492
528
 
493
529
  // Generate message
494
530
  const { type } = getRequiredWallet(swap);
@@ -529,7 +565,9 @@ export function markRunningSwapAsDependsOnOtherQueues({
529
565
  | undefined {
530
566
  const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
531
567
  const currentStep = getCurrentStep(swap);
532
- if (!currentStep) return;
568
+ if (!currentStep) {
569
+ return;
570
+ }
533
571
 
534
572
  swap.networkStatusExtraMessage = '';
535
573
  swap.networkStatusExtraMessageDetail = '';
@@ -555,7 +593,7 @@ export function markRunningSwapAsDependsOnOtherQueues({
555
593
  };
556
594
  }
557
595
 
558
- export function delay(ms: number): Promise<unknown> {
596
+ export async function delay(ms: number): Promise<unknown> {
559
597
  return new Promise((res) => setTimeout(res, ms));
560
598
  }
561
599
 
@@ -596,7 +634,9 @@ export function isWalletNull(wallet: Wallet | null): boolean {
596
634
  export function getEvmProvider(providers: Providers, type: WalletType): any {
597
635
  if (type && providers[type]) {
598
636
  // we need this because provider can return an instance or a map of instances, so what you are doing here is try to detect that.
599
- if (providers[type].size) return providers[type].get(Networks.ETHEREUM);
637
+ if (providers[type].size) {
638
+ return providers[type].get(Networks.ETHEREUM);
639
+ }
600
640
 
601
641
  return providers[type];
602
642
  }
@@ -663,7 +703,9 @@ export async function isNetworkMatchedForTransaction(
663
703
  return false;
664
704
  }
665
705
  const fromBlockChain = getCurrentBlockchainOfOrNull(swap, step);
666
- if (!fromBlockChain) return false;
706
+ if (!fromBlockChain) {
707
+ return false;
708
+ }
667
709
 
668
710
  if (
669
711
  meta.evmBasedChains.find(
@@ -685,13 +727,15 @@ export async function isNetworkMatchedForTransaction(
685
727
  if (
686
728
  blockChain &&
687
729
  blockChain.toLowerCase() === fromBlockChain.toLowerCase()
688
- )
730
+ ) {
689
731
  return true;
732
+ }
690
733
  if (
691
734
  blockChain &&
692
735
  blockChain.toLowerCase() !== fromBlockChain.toLowerCase()
693
- )
736
+ ) {
694
737
  return false;
738
+ }
695
739
  }
696
740
  }
697
741
  } catch (e) {
@@ -831,7 +875,9 @@ export function onBlockForChangeNetwork(
831
875
  const swap = queue.getStorage().swapDetails as SwapStorage['swapDetails'];
832
876
  const currentStep = getCurrentStep(swap);
833
877
 
834
- if (!currentStep || swap.status !== 'running') return;
878
+ if (!currentStep || swap.status !== 'running') {
879
+ return;
880
+ }
835
881
 
836
882
  const result = markRunningSwapAsSwitchingNetwork({
837
883
  getStorage: queue.getStorage.bind(queue),
@@ -904,7 +950,9 @@ export function onDependsOnOtherQueues(
904
950
  const claimerId = claimedBy();
905
951
  const isClaimedByAnyQueue = !!claimerId;
906
952
 
907
- if (claimerId === queue.id) return;
953
+ if (claimerId === queue.id) {
954
+ return;
955
+ }
908
956
 
909
957
  // Check if any queue `claimed` before, if yes, we don't should do anything.
910
958
  if (isClaimedByAnyQueue) {
@@ -960,7 +1008,9 @@ export function isRequiredWalletConnected(
960
1008
  const walletState = getState(type);
961
1009
  const { accounts, connected } = walletState;
962
1010
  const connectedAccounts = accounts || [];
963
- if (!connected) return { ok: false, reason: 'not_connected' };
1011
+ if (!connected) {
1012
+ return { ok: false, reason: 'not_connected' };
1013
+ }
964
1014
 
965
1015
  const matched = connectedAccounts.some((account) => {
966
1016
  const { address: accountAddress } = readAccountAddress(account);
@@ -1075,11 +1125,12 @@ export function singTransaction(
1075
1125
  },
1076
1126
  ...updateResult,
1077
1127
  });
1078
- } else
1128
+ } else {
1079
1129
  notifier({
1080
1130
  event: { type: eventType, status: StepExecutionEventStatus.SEND_TX },
1081
1131
  ...updateResult,
1082
1132
  });
1133
+ }
1083
1134
 
1084
1135
  if (hasAlreadyProceededToSign) {
1085
1136
  failed();
@@ -1109,7 +1160,9 @@ export function singTransaction(
1109
1160
  onFinish();
1110
1161
  },
1111
1162
  (error) => {
1112
- if (swap.status === 'failed') return;
1163
+ if (swap.status === 'failed') {
1164
+ return;
1165
+ }
1113
1166
 
1114
1167
  const { extraMessage, extraMessageDetail, extraMessageErrorCode } =
1115
1168
  prettifyErrorMessage(error);
@@ -1153,7 +1206,9 @@ export function checkWaitingForConnectWalletChange(params: {
1153
1206
  const { wallet_network, evmChains, manager } = params;
1154
1207
  const [wallet, network] = splitWalletNetwork(wallet_network);
1155
1208
  // We only need change network for EVM chains.
1156
- if (!evmChains.some((chain) => chain.name == network)) return;
1209
+ if (!evmChains.some((chain) => chain.name == network)) {
1210
+ return;
1211
+ }
1157
1212
 
1158
1213
  manager?.getAll().forEach((q) => {
1159
1214
  const queueStorage = q.list.getStorage() as SwapStorage | undefined;
@@ -1267,7 +1322,9 @@ export function getRunningSwaps(manager: Manager): PendingSwap[] {
1267
1322
  // retry only on affected queues
1268
1323
  const queueStorage = q.list.getStorage() as SwapStorage | undefined;
1269
1324
  const swap = queueStorage?.swapDetails;
1270
- if (!swap || swap.status !== 'running') return;
1325
+ if (!swap || swap.status !== 'running') {
1326
+ return;
1327
+ }
1271
1328
  result.push(swap);
1272
1329
  });
1273
1330
  return result;
@@ -1290,9 +1347,11 @@ export function resetRunningSwapNotifsOnPageLoad(runningSwaps: PendingSwap[]) {
1290
1347
  | StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE
1291
1348
  | StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT
1292
1349
  | undefined;
1293
- if (currentStep?.networkStatus === PendingSwapNetworkStatus.WaitingForQueue)
1350
+ if (
1351
+ currentStep?.networkStatus === PendingSwapNetworkStatus.WaitingForQueue
1352
+ ) {
1294
1353
  eventSubtype = StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE;
1295
- else if (swap?.status === 'running') {
1354
+ } else if (swap?.status === 'running') {
1296
1355
  eventSubtype = StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT;
1297
1356
  }
1298
1357
  if (!!eventType && !!notifier) {
@@ -1377,22 +1436,25 @@ export function retryOn(
1377
1436
  finalQueueToBeRun = onlyWalletMatched[0];
1378
1437
  }
1379
1438
 
1380
- if (!canSwitchNetworkTo?.(wallet, network)) finalQueueToBeRun?.unblock();
1381
- else finalQueueToBeRun?.checkBlock();
1439
+ if (!canSwitchNetworkTo?.(wallet, network)) {
1440
+ finalQueueToBeRun?.unblock();
1441
+ } else {
1442
+ finalQueueToBeRun?.checkBlock();
1443
+ }
1382
1444
  }
1383
1445
 
1384
- /*
1385
- For avoiding conflict by making too many requests to wallet, we need to make sure
1386
- We only run one request at a time (In parallel mode).
1387
- */
1446
+ /*
1447
+ *For avoiding conflict by making too many requests to wallet, we need to make sure
1448
+ *We only run one request at a time (In parallel mode).
1449
+ */
1388
1450
  export function isNeedBlockQueueForParallel(step: PendingSwapStep): boolean {
1389
1451
  return !!step.evmTransaction || !!step.evmApprovalTransaction;
1390
1452
  }
1391
1453
 
1392
1454
  /*
1393
- Create transaction endpoint doesn't return error code on http status code,
1394
- For backward compatibilty with server and sdk, we use this wrapper to reject the promise.
1395
- */
1455
+ *Create transaction endpoint doesn't return error code on http status code,
1456
+ *For backward compatibilty with server and sdk, we use this wrapper to reject the promise.
1457
+ */
1396
1458
  export async function throwOnOK(
1397
1459
  rawResponse: Promise<CreateTransactionResponse>
1398
1460
  ): Promise<CreateTransactionResponse> {
@@ -1438,7 +1500,9 @@ export function cancelSwap(
1438
1500
  });
1439
1501
 
1440
1502
  reset();
1441
- if (manager) manager?.retry();
1503
+ if (manager) {
1504
+ manager?.retry();
1505
+ }
1442
1506
 
1443
1507
  return updateResult;
1444
1508
  }