@orderly.network/wallet-connector-privy 2.4.2-alpha.0 → 2.5.0-alpha.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.
package/dist/index.mjs CHANGED
@@ -2,9 +2,9 @@ import React19, { createContext, useMemo, useContext, useState, useRef, useEffec
2
2
  import * as viemExport from 'viem';
3
3
  import { defineChain } from 'viem';
4
4
  import { mainnet, abstract, abstractTestnet } from 'viem/chains';
5
+ import { useWalletConnector, useAccount, useSWR, WalletConnectorContext, useTrack, useStorageLedgerAddress, useLocalStorage, useStorageChain } from '@orderly.network/hooks';
5
6
  import { SOLANA_TESTNET_CHAINID, SOLANA_MAINNET_CHAINID, ChainNamespace, ABSTRACT_CHAIN_ID_MAP, AccountStatusEnum, ABSTRACT_TESTNET_CHAINID, ABSTRACT_MAINNET_CHAINID, SolanaChains as SolanaChains$1, AbstractChains, AbstractTestnetChainInfo, ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo, TrackerEventName, ConnectorKey } from '@orderly.network/types';
6
7
  import { installExtension, ExtensionPositionEnum, useScreen, Button, Text, formatAddress, cn, TooltipProvider, CloseIcon, ScrollArea, ExclamationFillIcon, Tooltip, CopyIcon, Checkbox, toast, DropdownMenuRoot, DropdownMenuTrigger, DropdownMenuPortal, DropdownMenuContent, DropdownMenuItem, Flex, ChevronDownIcon, ChevronUpIcon, SimpleDialog, ChainIcon, Popover, modal } from '@orderly.network/ui';
7
- import { useWalletConnector, useAccount, WalletConnectorContext, useTrack, useStorageLedgerAddress, useLocalStorage, useStorageChain } from '@orderly.network/hooks';
8
8
  import { useTranslation, Trans } from '@orderly.network/i18n';
9
9
  import { AbstractWalletProvider as AbstractWalletProvider$1, useLoginWithAbstract, useAbstractClient, useGlobalWalletSignerAccount } from '@abstract-foundation/agw-react';
10
10
  import * as WagmiExport from 'wagmi';
@@ -2724,12 +2724,30 @@ function WagmiWallet(props) {
2724
2724
  }
2725
2725
 
2726
2726
  // src/provider.tsx
2727
- var fetchChainInfo = async (url) => {
2728
- const response = await fetch(url);
2729
- if (!response.ok) {
2730
- throw new Error(`Failed to fetch data from ${url}`);
2731
- }
2732
- return response.json();
2727
+ var commonSwrOpts = {
2728
+ revalidateIfStale: false,
2729
+ revalidateOnFocus: false,
2730
+ revalidateOnReconnect: false,
2731
+ // If false, undefined data gets cached against the key.
2732
+ revalidateOnMount: true,
2733
+ // don't duplicate a request with the same key for 1hr
2734
+ dedupingInterval: 36e5
2735
+ };
2736
+ var fetcher = (url) => fetch(url).then((res) => res.json());
2737
+ var formatSwapChainInfo = (data = {}) => {
2738
+ return Object.keys(data).map((key) => {
2739
+ const chain = data[key];
2740
+ const { network_infos, token_infos } = chain;
2741
+ const nativeToken = token_infos.find(
2742
+ (item) => item.symbol === network_infos.currency_symbol
2743
+ );
2744
+ if (nativeToken) {
2745
+ network_infos.currency_decimal = nativeToken.decimals;
2746
+ } else {
2747
+ network_infos.currency_decimal = 18;
2748
+ }
2749
+ return network_infos;
2750
+ });
2733
2751
  };
2734
2752
  var processChainInfo = (chainInfo) => chainInfo.map(
2735
2753
  (row) => defineChain({
@@ -2844,33 +2862,21 @@ function WalletConnectorPrivyProvider(props) {
2844
2862
  });
2845
2863
  return chainTypeObj;
2846
2864
  }, [initChains]);
2847
- const fetchAllChains = async () => {
2848
- let testChainsList = [];
2849
- let mainnetChainsList = [];
2850
- try {
2851
- const testChainInfoRes = await fetchChainInfo(
2852
- "https://testnet-api-evm.orderly.org/v1/public/chain_info"
2853
- );
2854
- testChainsList = testChainInfoRes.data.rows;
2855
- testChainsList.push(AbstractTestnetChainInfo);
2856
- } catch (error) {
2857
- testChainsList = [ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo];
2858
- }
2859
- try {
2860
- const mainnetChainInfoRes = await fetchChainInfo(
2861
- "https://api-evm.orderly.org/v1/public/chain_info"
2862
- );
2863
- mainnetChainsList = mainnetChainInfoRes.data.rows;
2864
- } catch (error) {
2865
- mainnetChainsList = [];
2866
- }
2867
- const testChains = processChainInfo(testChainsList);
2868
- const mainnetChains2 = processChainInfo(mainnetChainsList);
2869
- setTestnetChains(testChains);
2870
- setMainnetChains(mainnetChains2);
2871
- setInitChains([...testChains, ...mainnetChains2]);
2872
- initRef.current = true;
2873
- };
2865
+ const { data: mainnetChainInfoRes } = useSWR(
2866
+ !props.customChains ? "https://api.orderly.org/v1/public/chain_info" : null,
2867
+ fetcher,
2868
+ commonSwrOpts
2869
+ );
2870
+ const { data: testChainInfoRes } = useSWR(
2871
+ !props.customChains ? "https://testnet-api.orderly.org/v1/public/chain_info" : null,
2872
+ fetcher,
2873
+ commonSwrOpts
2874
+ );
2875
+ const { data: swapChainInfoRes } = useSWR(
2876
+ !props.customChains ? "https://fi-api.woo.org/swap_support" : null,
2877
+ fetcher,
2878
+ commonSwrOpts
2879
+ );
2874
2880
  const handleCustomerChains = () => {
2875
2881
  const testChains = processChainInfo(
2876
2882
  props.customChains.testnet?.map((item) => item.network_infos)
@@ -2953,11 +2959,45 @@ function WalletConnectorPrivyProvider(props) {
2953
2959
  ]
2954
2960
  );
2955
2961
  useEffect(() => {
2956
- if (!props.customChains) {
2957
- fetchAllChains();
2962
+ if (props.customChains) {
2958
2963
  return;
2959
2964
  }
2960
- handleCustomerChains();
2965
+ if (!mainnetChainInfoRes || !testChainInfoRes || !swapChainInfoRes) {
2966
+ return;
2967
+ }
2968
+ let testChainsList = [];
2969
+ let mainnetChainsList = [];
2970
+ try {
2971
+ testChainsList = testChainInfoRes?.data?.rows;
2972
+ testChainsList.push(AbstractTestnetChainInfo);
2973
+ mainnetChainsList = mainnetChainInfoRes?.data?.rows;
2974
+ const testChains = processChainInfo(testChainsList);
2975
+ const mainnetChains2 = processChainInfo(mainnetChainsList);
2976
+ const swapChains = processChainInfo(
2977
+ formatSwapChainInfo(swapChainInfoRes?.data)
2978
+ );
2979
+ const chains = [...testChains, ...mainnetChains2];
2980
+ const filterSwapChains = swapChains.filter(
2981
+ (item) => !chains.some((chain) => chain.id === item.id)
2982
+ );
2983
+ setTestnetChains(testChains);
2984
+ setMainnetChains(mainnetChains2);
2985
+ setInitChains([...chains, ...filterSwapChains]);
2986
+ } catch (error) {
2987
+ testChainsList = [ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo];
2988
+ mainnetChainsList = [];
2989
+ }
2990
+ initRef.current = true;
2991
+ }, [
2992
+ props.customChains,
2993
+ mainnetChainInfoRes,
2994
+ testChainInfoRes,
2995
+ swapChainInfoRes
2996
+ ]);
2997
+ useEffect(() => {
2998
+ if (props.customChains) {
2999
+ handleCustomerChains();
3000
+ }
2961
3001
  }, [props.customChains]);
2962
3002
  if (!initRef.current) {
2963
3003
  return null;