@rango-dev/queue-manager-rango-preset 0.22.1-next.0 → 0.22.1-next.10

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/src/shared.ts CHANGED
@@ -1,31 +1,32 @@
1
- import { Network, WalletType } from '@rango-dev/wallets-shared';
2
- import {
1
+ import type { Network, WalletType } from '@rango-dev/wallets-shared';
2
+ import type {
3
+ AmountRestrictionType,
4
+ BestRouteResponse,
5
+ BlockchainMeta,
3
6
  CosmosTransaction,
4
7
  EvmTransaction,
8
+ MetaResponse,
5
9
  SimulationResult,
6
10
  SolanaTransaction,
7
11
  StarknetTransaction,
8
- TronTransaction,
9
- Transfer as TransferTransaction,
10
- AmountRestrictionType,
11
- BestRouteResponse,
12
- MetaResponse,
13
- Token,
14
12
  SwapResult,
15
- BlockchainMeta,
13
+ Token,
14
+ Transfer as TransferTransaction,
15
+ TronTransaction,
16
16
  } from 'rango-sdk';
17
+ import type { TonTransaction } from 'rango-types';
17
18
 
18
- import { PrettyError } from './shared-errors';
19
19
  import BigNumber from 'bignumber.js';
20
- import { numberToString } from './numbers';
21
20
  import {
22
- TonTransaction,
23
21
  isCosmosBlockchain,
24
22
  isEvmBlockchain,
25
23
  isStarknetBlockchain,
26
24
  isTronBlockchain,
27
25
  } from 'rango-types';
28
26
 
27
+ import { numberToString } from './numbers';
28
+ import { PrettyError } from './shared-errors';
29
+
29
30
  export interface PendingSwapWithQueueID {
30
31
  id: string;
31
32
  swap: PendingSwap;
@@ -170,8 +171,10 @@ export type PendingSwapStep = {
170
171
  starknetTransaction: StarknetTransaction | null;
171
172
  tonTransaction: TonTransaction | null;
172
173
 
173
- // missing fields in older versions
174
- // keeping null for backward compatability
174
+ /*
175
+ * missing fields in older versions
176
+ * keeping null for backward compatability
177
+ */
175
178
  swapperLogo: string | null;
176
179
  swapperType: string | null;
177
180
  fromBlockchainLogo: string | null;
@@ -240,16 +243,22 @@ export const getCurrentBlockchainOf = (
240
243
  step.cosmosTransaction?.blockChain ||
241
244
  step.solanaTransaction?.blockChain ||
242
245
  step.tonTransaction?.blockChain;
243
- if (b1) return b1;
246
+ if (b1) {
247
+ return b1;
248
+ }
244
249
 
245
250
  const transferAddress = step.transferTransaction?.fromWalletAddress;
246
- if (!transferAddress) throw PrettyError.BlockchainMissing();
251
+ if (!transferAddress) {
252
+ throw PrettyError.BlockchainMissing();
253
+ }
247
254
 
248
255
  const blockchain =
249
256
  Object.keys(swap.wallets).find(
250
257
  (b) => swap.wallets[b]?.address === transferAddress
251
258
  ) || null;
252
- if (blockchain == null) throw PrettyError.BlockchainMissing();
259
+ if (blockchain == null) {
260
+ throw PrettyError.BlockchainMissing();
261
+ }
253
262
 
254
263
  return blockchain;
255
264
  };
@@ -257,14 +266,15 @@ export const getCurrentBlockchainOf = (
257
266
  const getBlockchainMetaExplorerBaseUrl = (
258
267
  blockchainMeta: BlockchainMeta
259
268
  ): string | undefined => {
260
- if (isCosmosBlockchain(blockchainMeta))
269
+ if (isCosmosBlockchain(blockchainMeta)) {
261
270
  return blockchainMeta.info?.explorerUrlToTx;
262
- else if (
271
+ } else if (
263
272
  isEvmBlockchain(blockchainMeta) ||
264
273
  isStarknetBlockchain(blockchainMeta) ||
265
274
  isTronBlockchain(blockchainMeta)
266
- )
275
+ ) {
267
276
  return blockchainMeta.info.transactionUrl;
277
+ }
268
278
  return;
269
279
  };
270
280
 
@@ -275,9 +285,12 @@ export const getScannerUrl = (
275
285
  ): string | undefined => {
276
286
  const blockchainMeta = blockchainMetaMap[network];
277
287
  const baseUrl = getBlockchainMetaExplorerBaseUrl(blockchainMeta);
278
- if (!baseUrl) return;
279
- if (baseUrl.indexOf('/{txHash}') !== -1)
288
+ if (!baseUrl) {
289
+ return;
290
+ }
291
+ if (baseUrl.indexOf('/{txHash}') !== -1) {
280
292
  return baseUrl.replace('{txHash}', txHash?.toLowerCase());
293
+ }
281
294
  return `${baseUrl}/${txHash?.toLowerCase()}`;
282
295
  };
283
296
 
@@ -316,7 +329,9 @@ export const getCurrentAddressOf = (
316
329
  ? { address: step.transferTransaction?.fromWalletAddress }
317
330
  : null) ||
318
331
  null;
319
- if (result == null) throw PrettyError.WalletMissing();
332
+ if (result == null) {
333
+ throw PrettyError.WalletMissing();
334
+ }
320
335
  return result.address;
321
336
  };
322
337
 
@@ -333,10 +348,11 @@ export function getRelatedWallet(
333
348
  const wallet = walletKV?.v || null;
334
349
 
335
350
  const walletType = wallet?.walletType;
336
- if (wallet === null)
351
+ if (wallet === null) {
337
352
  throw PrettyError.AssertionFailed(
338
353
  `Wallet for source ${blockchain} not passed: walletType: ${walletType}`
339
354
  );
355
+ }
340
356
  return wallet;
341
357
  }
342
358
 
@@ -373,7 +389,9 @@ export function getUsdFeeOfStep(
373
389
  let totalFeeInUsd = new BigNumber(0);
374
390
  for (let i = 0; i < step.fee.length; i++) {
375
391
  const fee = step.fee[i];
376
- if (fee.expenseType === 'DECREASE_FROM_OUTPUT') continue;
392
+ if (fee.expenseType === 'DECREASE_FROM_OUTPUT') {
393
+ continue;
394
+ }
377
395
 
378
396
  const unitPrice = getUsdPrice(
379
397
  fee.asset.blockchain,
@@ -395,10 +413,12 @@ export function calculatePendingSwap(
395
413
  wallets: { [p: string]: WalletTypeAndAddress },
396
414
  settings: SwapSavedSettings,
397
415
  validateBalanceOrFee: boolean,
398
- meta: MetaResponse | null
416
+ meta: Pick<MetaResponse, 'blockchains' | 'tokens'> | null
399
417
  ): PendingSwap {
400
418
  const simulationResult = bestRoute.result;
401
- if (!simulationResult) throw Error('Simulation result should not be null');
419
+ if (!simulationResult) {
420
+ throw Error('Simulation result should not be null');
421
+ }
402
422
 
403
423
  return {
404
424
  creationTime: new Date().getTime().toString(),
@@ -452,7 +472,8 @@ export function calculatePendingSwap(
452
472
  expectedOutputAmountHumanReadable: swap.toAmount,
453
473
  outputAmount: '',
454
474
  feeInUsd: meta
455
- ? numberToString(getUsdFeeOfStep(swap, meta?.tokens), null, 8)
475
+ ? // eslint-disable-next-line @typescript-eslint/no-magic-numbers
476
+ numberToString(getUsdFeeOfStep(swap, meta?.tokens), null, 8)
456
477
  : null,
457
478
  estimatedTimeInSeconds: swap.estimatedTimeInSeconds || null,
458
479
 
package/src/types.ts CHANGED
@@ -1,15 +1,23 @@
1
- import { QueueStorage, QueueDef } from '@rango-dev/queue-manager-core';
2
- import { QueueContext } from '@rango-dev/queue-manager-core/dist/queue';
3
- import { ConnectResult, Providers } from '@rango-dev/wallets-react';
4
- import {
1
+ import type { PendingSwap, PendingSwapStep, Wallet } from './shared';
2
+ import type {
3
+ QueueContext,
4
+ QueueDef,
5
+ QueueStorage,
6
+ } from '@rango-dev/queue-manager-core';
7
+ import type { ConnectResult } from '@rango-dev/wallets-core';
8
+ import type {
5
9
  Meta,
6
10
  Network,
11
+ Providers,
7
12
  WalletState,
8
13
  WalletType,
9
14
  } from '@rango-dev/wallets-shared';
10
- import { APIErrorCode, EvmBlockchainMeta, SignerFactory } from 'rango-types';
11
- import { Transaction } from 'rango-sdk';
12
- import { PendingSwap, PendingSwapStep, Wallet } from './shared';
15
+ import type { Transaction } from 'rango-sdk';
16
+ import type {
17
+ APIErrorCode,
18
+ EvmBlockchainMeta,
19
+ SignerFactory,
20
+ } from 'rango-types';
13
21
 
14
22
  export type RemoveNameField<T, U extends string> = {
15
23
  [Property in keyof T as Exclude<Property, U>]: T[Property];
@@ -61,7 +69,7 @@ export interface SwapQueueContext extends QueueContext {
61
69
  switchNetwork: (
62
70
  wallet: WalletType,
63
71
  network: Network
64
- ) => Promise<ConnectResult> | undefined;
72
+ ) => Promise<ConnectResult | undefined> | undefined;
65
73
  canSwitchNetworkTo: (type: WalletType, network: Network) => boolean;
66
74
  connect: (
67
75
  wallet: WalletType,