@rango-dev/widget-embedded 0.1.10-next.76 → 0.1.10-next.77

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.
@@ -8,7 +8,7 @@ import BigNumber, { BigNumber as BigNumber$1 } from 'bignumber.js';
8
8
  import { RangoClient, TransactionType } from 'rango-sdk';
9
9
  import { readAccountAddress, useWallets, Provider, Events } from '@rango-dev/wallets-core';
10
10
  import { allProviders } from '@rango-dev/provider-all';
11
- import { Network, isEvmAddress, WalletType, isEvmBlockchain } from '@rango-dev/wallets-shared';
11
+ import { Network, isEvmAddress, KEPLR_COMPATIBLE_WALLETS, WalletType, getCosmosExperimentalChainInfo, isCosmosBlockchain, isEvmBlockchain } from '@rango-dev/wallets-shared';
12
12
  import { persist } from 'zustand/middleware';
13
13
  import { styled as styled$1 } from '@rango-dev/ui/src/theme';
14
14
 
@@ -375,10 +375,11 @@ function getSelectableWallets(accounts, selectedWallets, getWalletInfo, required
375
375
  name: getWalletInfo(account.walletType).name,
376
376
  selected: !!selectedWallets.find(wallet => wallet.chain === account.chain && wallet.walletType === account.walletType)
377
377
  }));
378
- return requiredChains ? connectedWallets.filter(wallet => requiredChains.includes(wallet.chain)) : removeDuplicateWallets(connectedWallets, 'walletType');
378
+ return requiredChains ? connectedWallets.filter((wallet, index, array) => requiredChains.includes(wallet.chain) && array.findIndex(w => w.address === wallet.address) === index) : removeDuplicateWallets(connectedWallets, 'walletType');
379
379
  }
380
380
  const removeDuplicateWallets = (arr, key) => {
381
- return [...new Map(arr.map(item => [item[key], item])).values()];
381
+ const map = new Map(arr.map(item => [item[key], item]));
382
+ return Array.from(map.values());
382
383
  };
383
384
  function getBalanceFromWallet(balances, chain, symbol, address) {
384
385
  if (balances.length === 0) return null;
@@ -442,8 +443,6 @@ const calculateWalletUsdValue = balance => {
442
443
  return modifiedWalletBlockchain;
443
444
  });
444
445
  const total = numberToString(modifiedWalletBlockchains?.flatMap(b => b.accounts)?.flatMap(a => a?.balances)?.map(b => new BigNumber(b?.amount || ZERO).multipliedBy(b?.usdPrice || 0))?.reduce((a, b) => a.plus(b), ZERO) || ZERO).toString();
445
- console.log('total');
446
- console.log(total);
447
446
  return numberWithThousandSeperator(total);
448
447
  };
449
448
  function numberWithThousandSeperator(number) {
@@ -468,6 +467,17 @@ const getUsdPrice = (blockchain, symbol, address, allTokens) => {
468
467
  const token = allTokens?.find(t => t.blockchain === blockchain && t.symbol?.toUpperCase() === symbol?.toUpperCase() && t.address === address);
469
468
  return token?.usdPrice || null;
470
469
  };
470
+ const isExperimentalChain = (blockchains, wallet) => {
471
+ const cosmosExperimentalChainInfo = getCosmosExperimentalChainInfo(Object.entries(blockchains).map(_ref => {
472
+ let [, blockchainMeta] = _ref;
473
+ return blockchainMeta;
474
+ }).filter(isCosmosBlockchain));
475
+ return cosmosExperimentalChainInfo && !!cosmosExperimentalChainInfo[wallet];
476
+ };
477
+ const getKeplrCompatibleConnectedWallets = selectableWallets => {
478
+ const connectedWalletTypes = new Set(selectableWallets.map(a => a.walletType.toString()));
479
+ return KEPLR_COMPATIBLE_WALLETS.filter(compatibleWallet => connectedWalletTypes.has(compatibleWallet));
480
+ };
471
481
 
472
482
  const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()(set => ({
473
483
  accounts: [],
@@ -2200,25 +2210,36 @@ function WalletsPage() {
2200
2210
  function ConfirmWalletsPage() {
2201
2211
  const navigate = useNavigate();
2202
2212
  const bestRoute = useBestRouteStore.use.bestRoute();
2213
+ const {
2214
+ blockchains
2215
+ } = useMetaStore.use.meta();
2203
2216
  const accounts = useWalletsStore.use.accounts();
2204
2217
  const selectedWallets = useWalletsStore.use.selectedWallets();
2205
2218
  const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
2206
2219
  const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
2207
2220
  const {
2208
- getWalletInfo
2221
+ getWalletInfo,
2222
+ connect
2209
2223
  } = useWallets();
2210
2224
  const confirmDisabled = !requiredWallets(bestRoute).every(chain => selectedWallets.map(wallet => wallet.chain).includes(chain));
2211
2225
  useEffect(() => {
2212
2226
  initSelectedWallets();
2213
2227
  }, []);
2228
+ const selectableWallets = getSelectableWallets(accounts, selectedWallets, getWalletInfo, getRequiredChains(bestRoute));
2229
+ const handleConnectChain = wallet => {
2230
+ const network = wallet;
2231
+ getKeplrCompatibleConnectedWallets(selectableWallets).forEach(compatibleWallet => connect?.(compatibleWallet, network));
2232
+ };
2214
2233
  return React.createElement(ConfirmWallets, {
2215
2234
  requiredWallets: getRequiredChains(bestRoute),
2216
- selectableWallets: getSelectableWallets(accounts, selectedWallets, getWalletInfo, getRequiredChains(bestRoute)),
2235
+ selectableWallets: selectableWallets,
2217
2236
  onBack: () => navigate(-1),
2218
2237
  swap: bestRoute,
2219
2238
  onConfirm: () => navigate(navigationRoutes.confirmSwap),
2220
2239
  onChange: wallet => setSelectedWallet(wallet),
2221
- confirmDisabled: confirmDisabled
2240
+ confirmDisabled: confirmDisabled,
2241
+ handleConnectChain: wallet => handleConnectChain(wallet),
2242
+ isExperimentalChain: wallet => getKeplrCompatibleConnectedWallets(selectableWallets).length > 0 ? isExperimentalChain(blockchains, wallet) : false
2222
2243
  });
2223
2244
  }
2224
2245