@orderly.network/wallet-connector-privy 2.8.1 → 2.8.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,8 +2,8 @@ import React19, { createContext, useState, useEffect, useMemo, useContext, useRe
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, fetcher, WalletConnectorContext, useTrack, useStorageLedgerAddress, useLocalStorage, useStorageChain } from '@orderly.network/hooks';
6
- import { SOLANA_TESTNET_CHAINID, SOLANA_MAINNET_CHAINID, ChainNamespace, TesntTokenFallback, ArbitrumSepoliaTokenInfo, SolanaDevnetTokenInfo, ABSTRACT_CHAIN_ID_MAP, AccountStatusEnum, ABSTRACT_TESTNET_CHAINID, ABSTRACT_MAINNET_CHAINID, SolanaChains as SolanaChains$1, AbstractChains, ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo, EMPTY_OBJECT, TrackerEventName, ConnectorKey } from '@orderly.network/types';
5
+ import { useWalletConnector, useAccount, useMainnetChainsStore, useTestnetChainsStore, useSwapSupportStore, WalletConnectorContext, useTrack, useStorageLedgerAddress, useLocalStorage, useStorageChain } from '@orderly.network/hooks';
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, ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo, EMPTY_OBJECT, TrackerEventName, ConnectorKey } from '@orderly.network/types';
7
7
  import { modal, useModal, SimpleSheet, SheetHeader, Text, Flex, Divider, cn, installExtension, ExtensionPositionEnum, useScreen, formatAddress, Button, SimpleDialog, TooltipProvider, CloseSquareFillIcon, ScrollArea, ExclamationFillIcon, Tooltip, CopyIcon, Checkbox, toast, DropdownMenuRoot, DropdownMenuTrigger, DropdownMenuPortal, DropdownMenuContent, DropdownMenuItem, ChevronDownIcon, ChevronUpIcon, Grid, ChainIcon, Popover } from '@orderly.network/ui';
8
8
  import { useTranslation, Trans } from '@orderly.network/i18n';
9
9
  import { AbstractWalletProvider as AbstractWalletProvider$1, useLoginWithAbstract, useAbstractClient, useGlobalWalletSignerAccount } from '@abstract-foundation/agw-react';
@@ -25,11 +25,11 @@ var Network = /* @__PURE__ */ ((Network3) => {
25
25
  Network3["testnet"] = "testnet";
26
26
  return Network3;
27
27
  })(Network || {});
28
- var WalletType = /* @__PURE__ */ ((WalletType5) => {
29
- WalletType5["EVM"] = "EVM";
30
- WalletType5["SOL"] = "SOL";
31
- WalletType5["ABSTRACT"] = "Abstract";
32
- return WalletType5;
28
+ var WalletType = /* @__PURE__ */ ((WalletType4) => {
29
+ WalletType4["EVM"] = "EVM";
30
+ WalletType4["SOL"] = "SOL";
31
+ WalletType4["ABSTRACT"] = "Abstract";
32
+ return WalletType4;
33
33
  })(WalletType || {});
34
34
  var WalletConnectType = /* @__PURE__ */ ((WalletConnectType2) => {
35
35
  WalletConnectType2["EVM"] = "EVM";
@@ -1622,7 +1622,24 @@ function EVMConnectArea({
1622
1622
  // src/components/renderConnector/index.tsx
1623
1623
  function RenderConnector() {
1624
1624
  const { connect } = useWallet2();
1625
- const { setOpenConnectDrawer, connectorWalletType, walletChainTypeConfig } = useWalletConnectorPrivy();
1625
+ const {
1626
+ setOpenConnectDrawer,
1627
+ connectorWalletType,
1628
+ walletChainTypeConfig,
1629
+ targetWalletType
1630
+ } = useWalletConnectorPrivy();
1631
+ const { storageChain } = useStorageChain();
1632
+ const selectedWalletType = (() => {
1633
+ if (targetWalletType)
1634
+ return targetWalletType;
1635
+ if (!storageChain?.chainId)
1636
+ return void 0;
1637
+ try {
1638
+ return getChainType(parseInt(storageChain.chainId));
1639
+ } catch {
1640
+ return void 0;
1641
+ }
1642
+ })();
1626
1643
  const handleConnect = (params) => {
1627
1644
  connect(params);
1628
1645
  if (params.walletType === "privy" /* PRIVY */) {
@@ -1691,7 +1708,30 @@ function RenderConnector() {
1691
1708
  }
1692
1709
  );
1693
1710
  };
1694
- return /* @__PURE__ */ React19.createElement(ScrollArea, { className: "oui-flex oui-grow oui-shrik oui-basis-auto oui-custom-scrollbar" }, /* @__PURE__ */ React19.createElement("div", { className: cn("oui-flex oui-flex-col oui-gap-4", "md:oui-gap-5") }, renderPrivyConnectArea(), renderWagmiConnectArea(), renderSolanaConnectArea(), renderAbstractConnectArea()));
1711
+ const walletOrder = ["evm", "sol", "abstract"];
1712
+ const typeToKey = {
1713
+ ["EVM" /* EVM */]: "evm",
1714
+ ["SOL" /* SOL */]: "sol",
1715
+ ["Abstract" /* ABSTRACT */]: "abstract"
1716
+ };
1717
+ const prioritizedKey = selectedWalletType ? typeToKey[selectedWalletType] : void 0;
1718
+ const orderedWalletKeys = prioritizedKey ? [
1719
+ prioritizedKey,
1720
+ ...walletOrder.filter((k) => k !== prioritizedKey)
1721
+ ] : walletOrder;
1722
+ const renderByKey = (key) => {
1723
+ switch (key) {
1724
+ case "evm":
1725
+ return renderWagmiConnectArea();
1726
+ case "sol":
1727
+ return renderSolanaConnectArea();
1728
+ case "abstract":
1729
+ return renderAbstractConnectArea();
1730
+ default:
1731
+ return null;
1732
+ }
1733
+ };
1734
+ return /* @__PURE__ */ React19.createElement(ScrollArea, { className: "oui-flex oui-grow oui-shrik oui-basis-auto oui-custom-scrollbar" }, /* @__PURE__ */ React19.createElement("div", { className: cn("oui-flex oui-flex-col oui-gap-4", "md:oui-gap-5") }, renderPrivyConnectArea(), orderedWalletKeys.map((key) => /* @__PURE__ */ React19.createElement(React19.Fragment, { key }, renderByKey(key)))));
1695
1735
  }
1696
1736
  function SwitchNetworkTips({
1697
1737
  tipsContent
@@ -3123,19 +3163,6 @@ var WagmiWallet = (props) => {
3123
3163
  };
3124
3164
 
3125
3165
  // src/provider.tsx
3126
- var commonSwrOpts = {
3127
- revalidateIfStale: false,
3128
- revalidateOnFocus: false,
3129
- revalidateOnReconnect: false,
3130
- // If false, undefined data gets cached against the key.
3131
- revalidateOnMount: true,
3132
- // don't duplicate a request with the same key for 1hr
3133
- dedupingInterval: 36e5
3134
- };
3135
- TesntTokenFallback([
3136
- ArbitrumSepoliaTokenInfo,
3137
- SolanaDevnetTokenInfo
3138
- ]);
3139
3166
  var testnetChainFallback = [ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo];
3140
3167
  var formatSwapChainInfo = (data = {}) => {
3141
3168
  return Object.keys(data).map((key) => {
@@ -3220,7 +3247,18 @@ function WalletConnectorPrivyProvider(props) {
3220
3247
  const [initChains, setInitChains] = useState([]);
3221
3248
  const [mainnetChains, setMainnetChains] = useState([]);
3222
3249
  const [testnetChains, setTestnetChains] = useState([]);
3223
- const initRef = useRef(false);
3250
+ const [mainnetChainInfos, setMainnetChainInfos] = useState(null);
3251
+ const [testChainInfos, setTestChainInfos] = useState(
3252
+ null
3253
+ );
3254
+ const fetchMainChains = useMainnetChainsStore((state) => state.fetchData);
3255
+ const fetchTestChains = useTestnetChainsStore((state) => state.fetchData);
3256
+ const mainnetChainInfosFromStore = useMainnetChainsStore(
3257
+ (state) => state.data
3258
+ );
3259
+ const testChainInfosFromStore = useTestnetChainsStore((state) => state.data);
3260
+ const hasCustomChains = Array.isArray(props.customChains) && props.customChains.length > 0;
3261
+ const initRef = useRef(hasCustomChains);
3224
3262
  const [openConnectDrawer, setOpenConnectDrawer] = useState(false);
3225
3263
  const [targetWalletType, setTargetWalletType] = useState();
3226
3264
  const [privyConfig, setPrivyConfig] = useState({
@@ -3265,24 +3303,24 @@ function WalletConnectorPrivyProvider(props) {
3265
3303
  });
3266
3304
  return chainTypeObj;
3267
3305
  }, [initChains]);
3268
- const { data: swapChainInfoRes, isLoading: swapLoading } = useSWR(
3269
- !props.customChains && props.enableSwapDeposit ? "https://fi-api.woo.org/swap_support" : null,
3270
- (url) => fetch(url).then((res) => res.json()),
3271
- commonSwrOpts
3272
- );
3273
- const { data: mainnetChainInfos } = useSWR(
3274
- !props.customChains ? "https://api.orderly.org/v1/public/chain_info" : null,
3275
- fetcher,
3276
- commonSwrOpts
3277
- );
3278
- const { data: testChainInfos } = useSWR(
3279
- !props.customChains ? "https://testnet-api.orderly.org/v1/public/chain_info" : null,
3280
- fetcher,
3281
- {
3282
- ...commonSwrOpts,
3283
- fallbackData: testnetChainFallback
3284
- }
3285
- );
3306
+ const {
3307
+ data: swapChainInfoRes,
3308
+ // loading: swapLoading,
3309
+ fetchData: fetchSwapData
3310
+ } = useSwapSupportStore();
3311
+ useEffect(() => {
3312
+ if (!props.enableSwapDeposit || !!props.customChains)
3313
+ return;
3314
+ fetchSwapData();
3315
+ }, [props.enableSwapDeposit, props.customChains]);
3316
+ useEffect(() => {
3317
+ fetchMainChains().then((data) => {
3318
+ setMainnetChainInfos(data);
3319
+ });
3320
+ fetchTestChains().then((data) => {
3321
+ setTestChainInfos(data);
3322
+ });
3323
+ }, []);
3286
3324
  const handleCustomerChains = () => {
3287
3325
  const testChains = processChainInfo(
3288
3326
  props.customChains.testnet?.map((item) => item.network_infos)
@@ -3365,21 +3403,33 @@ function WalletConnectorPrivyProvider(props) {
3365
3403
  ]
3366
3404
  );
3367
3405
  useEffect(() => {
3368
- if (props.customChains) {
3406
+ if (initRef.current)
3407
+ return;
3408
+ if (hasCustomChains) {
3369
3409
  return;
3370
3410
  }
3371
- if (!mainnetChainInfos || !testChainInfos || swapLoading) {
3411
+ const hasStoreData = mainnetChainInfosFromStore && testChainInfosFromStore;
3412
+ const hasApiData = mainnetChainInfos && testChainInfos;
3413
+ if (!hasStoreData && !hasApiData) {
3414
+ return;
3415
+ }
3416
+ if (!swapChainInfoRes) {
3372
3417
  return;
3373
3418
  }
3374
3419
  let testChainsList = [];
3375
3420
  let mainnetChainsList = [];
3376
3421
  try {
3377
- testChainsList = testChainInfos;
3378
- mainnetChainsList = mainnetChainInfos;
3422
+ if (hasStoreData) {
3423
+ testChainsList = testChainInfosFromStore;
3424
+ mainnetChainsList = mainnetChainInfosFromStore;
3425
+ } else {
3426
+ testChainsList = testChainInfos || testnetChainFallback;
3427
+ mainnetChainsList = mainnetChainInfos || [];
3428
+ }
3379
3429
  const testChains = processChainInfo(testChainsList);
3380
3430
  const mainnetChains2 = processChainInfo(mainnetChainsList);
3381
3431
  const swapChains = processChainInfo(
3382
- formatSwapChainInfo(swapChainInfoRes?.data || {})
3432
+ formatSwapChainInfo(swapChainInfoRes || {})
3383
3433
  );
3384
3434
  const chains = [...testChains, ...mainnetChains2];
3385
3435
  const filterSwapChains = swapChains.filter(
@@ -3397,8 +3447,10 @@ function WalletConnectorPrivyProvider(props) {
3397
3447
  props.customChains,
3398
3448
  mainnetChainInfos,
3399
3449
  testChainInfos,
3400
- swapChainInfoRes,
3401
- swapLoading
3450
+ mainnetChainInfosFromStore,
3451
+ testChainInfosFromStore,
3452
+ swapChainInfoRes
3453
+ // swapLoading,
3402
3454
  ]);
3403
3455
  useEffect(() => {
3404
3456
  if (props.customChains) {