@skip-go/widget 2.2.1-alpha.0 → 2.2.2

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.
@@ -1,7 +1,5 @@
1
1
  import { Chain, Asset, AssetList } from '@chain-registry/types';
2
2
  export declare const chains: Chain[];
3
3
  export declare const assets: AssetList[];
4
- export declare function getChain(chainId: string): Chain;
5
4
  export declare function chainIdToName(chainId: string): string;
6
5
  export declare function getAssets(chainId: string): Asset[];
7
- export declare function getChains(): Chain[];
package/build/index.es.js CHANGED
@@ -19,7 +19,6 @@ import { getWalletClient } from '@wagmi/core';
19
19
  import { createContext, useContext, useMemo, useCallback, useRef, useState, useEffect, forwardRef, Fragment as Fragment$1 } from 'react';
20
20
  import { create } from 'zustand';
21
21
  import { subscribeWithSelector, persist, createJSONStorage } from 'zustand/middleware';
22
- import { GasPrice, StargateClient } from '@cosmjs/stargate';
23
22
  import * as Dialog$1 from '@radix-ui/react-dialog';
24
23
  import { ArrowTopRightOnSquareIcon, ArrowLeftIcon as ArrowLeftIcon$1, ChevronDownIcon as ChevronDownIcon$1, PencilSquareIcon } from '@heroicons/react/16/solid';
25
24
  import { ArrowLeftIcon, FaceFrownIcon, ChevronDownIcon, BackspaceIcon, TrashIcon, CubeIcon, ArrowRightIcon, ArrowTopRightOnSquareIcon as ArrowTopRightOnSquareIcon$1, CheckCircleIcon, ArrowPathIcon, XCircleIcon, CheckIcon, ClipboardDocumentIcon, ChevronRightIcon, ExclamationTriangleIcon, InformationCircleIcon, PencilSquareIcon as PencilSquareIcon$1, FingerPrintIcon, ArrowsUpDownIcon } from '@heroicons/react/20/solid';
@@ -30,6 +29,7 @@ import { twMerge } from 'tailwind-merge';
30
29
  import { styled, useTheme, StyleSheetManager, ThemeProvider } from 'styled-components';
31
30
  import { matchSorter } from 'match-sorter';
32
31
  import * as Tooltip from '@radix-ui/react-tooltip';
32
+ import { StargateClient, GasPrice } from '@cosmjs/stargate';
33
33
  import { BigNumber } from 'bignumber.js';
34
34
  import { shallow } from 'zustand/shallow';
35
35
  import { createWithEqualityFn } from 'zustand/traditional';
@@ -493,8 +493,8 @@ function useChains(args = {}) {
493
493
  .map((chain) => {
494
494
  return {
495
495
  ...chain,
496
- chainName: chain.chainName || getChain(chain.chainID).chain_name,
497
- prettyName: chain.prettyName || getChain(chain.chainID).pretty_name,
496
+ chainName: chain.chainName,
497
+ prettyName: chain.prettyName,
498
498
  logoURI: chain.logoURI || 'https://api.dicebear.com/6.x/shapes/svg',
499
499
  };
500
500
  })
@@ -516,51 +516,6 @@ function useChainByID(chainID) {
516
516
  });
517
517
  }
518
518
 
519
- /**
520
- * - deprio denoms start with 'ibc/' and 'factory/'
521
- * - prio denoms start with 'u' or 'uu'
522
- */
523
- function sortFeeAssets(a, b) {
524
- const aIsDeprio = a.denom.startsWith('ibc/') || a.denom.startsWith('factory/');
525
- const bIsDeprio = b.denom.startsWith('ibc/') || b.denom.startsWith('factory/');
526
- const aIsPrio = a.denom.startsWith('u') || a.denom.startsWith('uu');
527
- const bIsPrio = b.denom.startsWith('u') || b.denom.startsWith('uu');
528
- if (aIsDeprio && !bIsDeprio)
529
- return 1;
530
- if (!aIsDeprio && bIsDeprio)
531
- return -1;
532
- if (aIsPrio && !bIsPrio)
533
- return -1;
534
- if (!aIsPrio && bIsPrio)
535
- return 1;
536
- return 0;
537
- }
538
- const getChainFeeAssets = (chainID) => {
539
- var _a;
540
- const { fees } = getChain(chainID);
541
- const feeAssets = (_a = fees === null || fees === void 0 ? void 0 : fees.fee_tokens.map((ft) => {
542
- var _a, _b, _c;
543
- return ({
544
- denom: ft.denom,
545
- gasPrice: {
546
- low: ((_a = ft.low_gas_price) !== null && _a !== void 0 ? _a : 0.01).toString(),
547
- average: ((_b = ft.average_gas_price) !== null && _b !== void 0 ? _b : 0.025).toString(),
548
- high: ((_c = ft.high_gas_price) !== null && _c !== void 0 ? _c : 0.04).toString(),
549
- },
550
- });
551
- })) !== null && _a !== void 0 ? _a : [];
552
- return feeAssets;
553
- };
554
- const getChainGasPrice = (chainID) => {
555
- var _a;
556
- const { fees } = getChain(chainID);
557
- const ft = (_a = fees === null || fees === void 0 ? void 0 : fees.fee_tokens) === null || _a === void 0 ? void 0 : _a[0];
558
- if (!(ft && ft.average_gas_price && ft.denom))
559
- return null;
560
- const gas = `${ft.average_gas_price}${ft.denom}`;
561
- return GasPrice.fromString(gas);
562
- };
563
-
564
519
  const AssetsContext = createContext({
565
520
  assets: {},
566
521
  assetsByChainID: () => [],
@@ -587,28 +542,21 @@ const AssetsProvider = ({ children }) => {
587
542
  return asset;
588
543
  }, [assets]);
589
544
  const getFeeAsset = useCallback(async (chainID) => {
590
- const cached = feeAssetCache[chainID];
591
- if (cached)
592
- return cached;
593
- let feeAsset;
594
- if (!feeAsset) {
595
- const chain = (chains !== null && chains !== void 0 ? chains : []).find((chain) => chain.chainID === chainID);
596
- if (!chain)
597
- return;
598
- else if (chainID === 'carbon-1') {
599
- feeAsset = chain.feeAssets.find((v) => v.denom == 'swth');
600
- }
601
- else {
602
- [feeAsset] = chain.feeAssets.sort(sortFeeAssets);
545
+ const chain = (chains !== null && chains !== void 0 ? chains : []).find((chain) => chain.chainID === chainID);
546
+ if (!chain)
547
+ return;
548
+ const feeAsset = (() => {
549
+ var _a;
550
+ if (chainID === 'carbon-1') {
551
+ return chain.feeAssets.find((v) => v.denom == 'swth');
603
552
  }
604
- }
605
- if (!feeAsset) {
553
+ return (_a = chain.feeAssets) === null || _a === void 0 ? void 0 : _a[0];
554
+ })();
555
+ if (!feeAsset)
606
556
  return;
607
- }
608
557
  const asset = getAsset(feeAsset.denom, chainID);
609
558
  if (!asset)
610
559
  return;
611
- feeAssetCache[chainID] = asset;
612
560
  return asset;
613
561
  }, [chains, getAsset]);
614
562
  const getNativeAssets = useCallback(() => {
@@ -649,7 +597,6 @@ const AssetsProvider = ({ children }) => {
649
597
  function useAssets() {
650
598
  return useContext(AssetsContext);
651
599
  }
652
- const feeAssetCache = {};
653
600
 
654
601
  const DialogContext = createContext({
655
602
  open: false,
@@ -1261,7 +1208,7 @@ function useAccount(chainID) {
1261
1208
  const cosmosWallet = useMemo(() => {
1262
1209
  if ((chain === null || chain === void 0 ? void 0 : chain.chainType) !== 'cosmos')
1263
1210
  return;
1264
- const { wallets } = getWalletRepo(chain.chainName);
1211
+ const { wallets } = getWalletRepo(chainIdToName(chain.chainID));
1265
1212
  return wallets.find((w) => w.walletName === (trackedWallet === null || trackedWallet === void 0 ? void 0 : trackedWallet.walletName));
1266
1213
  }, [
1267
1214
  chain === null || chain === void 0 ? void 0 : chain.chainName,
@@ -2367,15 +2314,16 @@ function useSwapWidget(persistSwapWidgetState = true) {
2367
2314
  */
2368
2315
  useEffect(() => {
2369
2316
  return useSwapWidgetStore.subscribe((state) => [state.sourceChain, state.sourceAsset, state.sourceFeeAsset], async ([srcChain, srcAsset, srcFeeAsset]) => {
2370
- var _a;
2317
+ var _a, _b, _c;
2371
2318
  if (!((srcChain === null || srcChain === void 0 ? void 0 : srcChain.chainType) === 'cosmos' && srcAsset))
2372
2319
  return;
2373
- let srcGasPrice = getChainGasPrice(srcChain.chainID);
2320
+ const feeAsset = (_a = srcChain.feeAssets) === null || _a === void 0 ? void 0 : _a[0];
2321
+ const gas = `${(_b = feeAsset === null || feeAsset === void 0 ? void 0 : feeAsset.gasPrice) === null || _b === void 0 ? void 0 : _b.average}${feeAsset.denom}`;
2322
+ const gasPrice = GasPrice.fromString(gas);
2323
+ let srcGasPrice = (feeAsset === null || feeAsset === void 0 ? void 0 : feeAsset.gasPrice) && gasPrice;
2374
2324
  if (!srcFeeAsset || srcFeeAsset.chainID !== srcChain.chainID) {
2375
2325
  if (srcGasPrice) {
2376
- srcFeeAsset = assetsByChainID(srcChain.chainID).find(({ denom }) => {
2377
- return denom === srcGasPrice.denom;
2378
- });
2326
+ srcFeeAsset = getAsset(srcGasPrice.denom, srcChain.chainID);
2379
2327
  }
2380
2328
  else {
2381
2329
  srcFeeAsset = await getFeeAsset(srcChain.chainID);
@@ -2385,7 +2333,7 @@ function useSwapWidget(persistSwapWidgetState = true) {
2385
2333
  toast.error(`Unable to find gas asset for ${srcChain.chainName}`);
2386
2334
  return;
2387
2335
  }
2388
- const decimals = (_a = srcFeeAsset.decimals) !== null && _a !== void 0 ? _a : 6;
2336
+ const decimals = (_c = srcFeeAsset.decimals) !== null && _c !== void 0 ? _c : 6;
2389
2337
  let selectedGasPrice;
2390
2338
  const actualGasAmount = isChainIdEvmos(srcChain.chainID)
2391
2339
  ? EVMOS_GAS_AMOUNT
@@ -2397,9 +2345,6 @@ function useSwapWidget(persistSwapWidgetState = true) {
2397
2345
  let feeDenomPrices = srcChain.feeAssets.find(({ denom }) => {
2398
2346
  return denom === (srcFeeAsset === null || srcFeeAsset === void 0 ? void 0 : srcFeeAsset.denom);
2399
2347
  });
2400
- feeDenomPrices !== null && feeDenomPrices !== void 0 ? feeDenomPrices : (feeDenomPrices = (await getChainFeeAssets(srcChain.chainID)).find(({ denom }) => {
2401
- return denom === (srcFeeAsset === null || srcFeeAsset === void 0 ? void 0 : srcFeeAsset.denom);
2402
- }));
2403
2348
  if (!feeDenomPrices || !feeDenomPrices.gasPrice) {
2404
2349
  toast.error(`Unable to find gas prices for ${srcFeeAsset.denom} on ${srcChain.chainName}`);
2405
2350
  return;
@@ -2464,7 +2409,7 @@ function useSwapWidget(persistSwapWidgetState = true) {
2464
2409
  return useSwapWidgetStore.subscribe((state) => state.sourceChain, async (srcChain) => {
2465
2410
  const { cosmos, svm } = trackWallet.get();
2466
2411
  if (srcChain && srcChain.chainType === 'cosmos') {
2467
- const { wallets } = getWalletRepo(srcChain.chainName);
2412
+ const { wallets } = getWalletRepo(chainIdToName(srcChain.chainID));
2468
2413
  let wallet;
2469
2414
  if ((cosmos === null || cosmos === void 0 ? void 0 : cosmos.chainType) === 'cosmos') {
2470
2415
  wallet = wallets.find((w) => {
@@ -4649,45 +4594,6 @@ const makeChainIDsWithAction = ({ route, actions, }) => {
4649
4594
  });
4650
4595
  };
4651
4596
 
4652
- function getExplorerUrl(chainId) {
4653
- var _a, _b, _c;
4654
- let baseUrl;
4655
- const parsedIntId = parseInt(chainId);
4656
- const isEvmChain = typeof parsedIntId === 'number' && !isNaN(parsedIntId);
4657
- const isSvmChain = chainId === 'solana-devnet' || chainId === 'solana';
4658
- if (isSvmChain) {
4659
- baseUrl =
4660
- chainId === 'solana-devnet'
4661
- ? 'https://solscan.io/tx/${txHash}?cluster=devnet'
4662
- : 'https://solscan.io/tx/${txHash}';
4663
- }
4664
- if (isEvmChain) {
4665
- const chain = EVM_CHAINS.find((chain) => chain.id === parseInt(chainId));
4666
- if ((_a = chain === null || chain === void 0 ? void 0 : chain.blockExplorers) === null || _a === void 0 ? void 0 : _a.default.url) {
4667
- baseUrl = chain.blockExplorers.default.url;
4668
- }
4669
- }
4670
- else {
4671
- const explorers = getChain(chainId).explorers || [];
4672
- baseUrl || (baseUrl = (_b = explorers.find((explorer) => explorer.kind === 'mintscan')) === null || _b === void 0 ? void 0 : _b.tx_page);
4673
- baseUrl || (baseUrl = (_c = explorers[0]) === null || _c === void 0 ? void 0 : _c.tx_page);
4674
- }
4675
- if (!baseUrl) {
4676
- return null;
4677
- }
4678
- const payload = {
4679
- evm: isEvmChain,
4680
- explorer: baseUrl,
4681
- };
4682
- const { evm, explorer } = payload;
4683
- if (evm) {
4684
- return (txHash) => `${explorer}/tx/${txHash}`;
4685
- }
4686
- else {
4687
- return (txHash) => `${explorer.replace('${txHash}', txHash)}`;
4688
- }
4689
- }
4690
-
4691
4597
  function isUserRejectedRequestError(input) {
4692
4598
  if (input instanceof Error) {
4693
4599
  if (
@@ -4840,12 +4746,10 @@ const PreviewRoute = ({ route, disclosure, isAmountError, }) => {
4840
4746
  },
4841
4747
  slippageTolerancePercent: useSettingsStore.getState().slippage,
4842
4748
  onTransactionTracked: async (txStatus) => {
4843
- const makeExplorerUrl = getExplorerUrl(txStatus.chainID);
4844
- const explorerLink = makeExplorerUrl === null || makeExplorerUrl === void 0 ? void 0 : makeExplorerUrl(txStatus.txHash);
4845
4749
  txHistory.addStatus(historyId, route, {
4846
4750
  chainId: txStatus.chainID,
4847
4751
  txHash: txStatus.txHash,
4848
- explorerLink: explorerLink || '#',
4752
+ explorerLink: txStatus.explorerLink,
4849
4753
  });
4850
4754
  setBroadcastedTxs((v) => {
4851
4755
  const txs = [
@@ -4853,7 +4757,7 @@ const PreviewRoute = ({ route, disclosure, isAmountError, }) => {
4853
4757
  {
4854
4758
  chainID: txStatus.chainID,
4855
4759
  txHash: txStatus.txHash,
4856
- explorerLink: explorerLink || '#',
4760
+ explorerLink: txStatus.explorerLink,
4857
4761
  },
4858
4762
  ];
4859
4763
  if (route.txsRequired === txs.length) {