@rango-dev/queue-manager-rango-preset 0.1.15-next.3 → 0.1.15-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/src/shared.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Network, WalletType } from '@rango-dev/wallets-shared';
2
2
  import {
3
3
  CosmosTransaction,
4
- EvmBlockchainMeta,
5
4
  EvmTransaction,
6
5
  SimulationResult,
7
6
  SolanaTransaction,
@@ -13,11 +12,18 @@ import {
13
12
  MetaResponse,
14
13
  Token,
15
14
  SwapResult,
15
+ BlockchainMeta,
16
16
  } from 'rango-sdk';
17
17
 
18
18
  import { PrettyError } from './shared-errors';
19
19
  import BigNumber from 'bignumber.js';
20
20
  import { numberToString } from './numbers';
21
+ import {
22
+ isCosmosBlockchain,
23
+ isEvmBlockchain,
24
+ isStarknetBlockchain,
25
+ isTronBlockchain,
26
+ } from 'rango-types';
21
27
 
22
28
  export interface PendingSwapWithQueueID {
23
29
  id: string;
@@ -78,6 +84,7 @@ export type EventType =
78
84
  | 'waiting_for_change_wallet_account'
79
85
  | 'network_changed'
80
86
  | 'not_enough_balance'
87
+ | 'not_enough_approval'
81
88
  | 'waiting_for_queue'
82
89
  | 'check_fee_failed'
83
90
  | 'route_failed_to_find'
@@ -251,40 +258,31 @@ export const getCurrentBlockchainOf = (
251
258
  return blockchain as Network;
252
259
  };
253
260
 
254
- export const getEvmApproveUrl = (
255
- tx: string,
256
- network: Network,
257
- evmBasedBlockchains: EvmBlockchainMeta[]
258
- ): string => {
259
- const evmBlochain = evmBasedBlockchains.find(
260
- (blockchain) => blockchain.name === network
261
- );
262
-
263
- if (!evmBlochain) {
264
- throw Error(`unsupported network: ${network} for getting approve url.`);
265
- }
266
-
267
- if (evmBlochain.info.transactionUrl)
268
- return evmBlochain.info.transactionUrl.replace(
269
- '{txHash}',
270
- tx.toLowerCase()
271
- );
272
-
273
- throw Error(`Explorer url for ${network} is not implemented`);
274
- };
275
-
276
- export const getStarknetApproveUrl = (tx: string): string => {
277
- return 'https://starkscan.co/tx/{txHash}'.replace(
278
- '{txHash}',
279
- tx.toLowerCase()
280
- );
261
+ const getBlockchainMetaExplorerBaseUrl = (
262
+ blockchainMeta: BlockchainMeta
263
+ ): string | undefined => {
264
+ if (isCosmosBlockchain(blockchainMeta))
265
+ return blockchainMeta.info?.explorerUrlToTx;
266
+ else if (
267
+ isEvmBlockchain(blockchainMeta) ||
268
+ isStarknetBlockchain(blockchainMeta) ||
269
+ isTronBlockchain(blockchainMeta)
270
+ )
271
+ return blockchainMeta.info.transactionUrl;
272
+ return;
281
273
  };
282
274
 
283
- export const getTronApproveUrl = (tx: string): string => {
284
- return 'https://tronscan.org/#/transaction/{txHash}'.replace(
285
- '{txHash}',
286
- tx.toLowerCase()
287
- );
275
+ export const getScannerUrl = (
276
+ txHash: string,
277
+ network: Network,
278
+ blockchainMetaMap: { [key: string]: BlockchainMeta }
279
+ ): string | undefined => {
280
+ const blockchainMeta = blockchainMetaMap[network];
281
+ const baseUrl = getBlockchainMetaExplorerBaseUrl(blockchainMeta);
282
+ if (!baseUrl) return;
283
+ if (baseUrl.indexOf('/{txHash}') !== -1)
284
+ return baseUrl.replace('{txHash}', txHash?.toLowerCase());
285
+ return `${baseUrl}/${txHash?.toLowerCase()}`;
288
286
  };
289
287
 
290
288
  export function getNextStep(