@orderly.network/wallet-connector-privy 2.8.12 → 2.8.13-alpha.0
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.js +37 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import * as WagmiConnectorsExport from 'wagmi/connectors';
|
|
|
6
6
|
import React19, { createContext, useState, useEffect, useMemo, useContext, useRef, useCallback } from 'react';
|
|
7
7
|
import { mainnet, abstract, abstractTestnet } from 'viem/chains';
|
|
8
8
|
import { useWalletConnector, useAccount, useMainnetChainsStore, useTestnetChainsStore, useSwapSupportStore, WalletConnectorContext, useTrack, useStorageLedgerAddress, useLocalStorage, useStorageChain } from '@orderly.network/hooks';
|
|
9
|
-
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';
|
|
9
|
+
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, defaultMainnetChains, defaultTestnetChains, TrackerEventName, ConnectorKey } from '@orderly.network/types';
|
|
10
10
|
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';
|
|
11
11
|
import { useTranslation, Trans } from '@orderly.network/i18n';
|
|
12
12
|
import { AbstractWalletProvider as AbstractWalletProvider$1, useLoginWithAbstract, useAbstractClient, useGlobalWalletSignerAccount } from '@abstract-foundation/agw-react';
|
|
@@ -984,7 +984,7 @@ var getChainType = (chainId) => {
|
|
|
984
984
|
// src/hooks/useWallet.tsx
|
|
985
985
|
function useWallet2() {
|
|
986
986
|
const { track } = useTrack();
|
|
987
|
-
const { walletChainTypeConfig } = useWalletConnectorPrivy();
|
|
987
|
+
const { walletChainTypeConfig, initChains, network } = useWalletConnectorPrivy();
|
|
988
988
|
const [connectorKey, setConnectorKey] = useLocalStorage(ConnectorKey, "");
|
|
989
989
|
const {
|
|
990
990
|
disconnect: disconnectEVM,
|
|
@@ -1021,6 +1021,23 @@ function useWallet2() {
|
|
|
1021
1021
|
const [walletType, setWalletType] = useState(null);
|
|
1022
1022
|
const { storageChain, setStorageChain } = useStorageChain();
|
|
1023
1023
|
const { setOpenConnectDrawer, targetWalletType, setTargetWalletType } = useWalletConnectorPrivy();
|
|
1024
|
+
const supportedEvmChainIds = useMemo(() => {
|
|
1025
|
+
const ids = initChains?.map((c) => c.id).filter((id) => !SolanaChains$1.has(id) && !AbstractChains.has(id));
|
|
1026
|
+
return new Set(ids ?? []);
|
|
1027
|
+
}, [initChains]);
|
|
1028
|
+
const preferredEvmChainId = useMemo(() => {
|
|
1029
|
+
const preferredOrder = network === "mainnet" ? defaultMainnetChains : defaultTestnetChains;
|
|
1030
|
+
return preferredOrder.map((c) => c.id).find((id) => supportedEvmChainIds.has(id));
|
|
1031
|
+
}, [network, supportedEvmChainIds]);
|
|
1032
|
+
const defaultEvmChainId = useMemo(() => {
|
|
1033
|
+
for (const chain of initChains ?? []) {
|
|
1034
|
+
if (!SolanaChains$1.has(chain.id) && !AbstractChains.has(chain.id)) {
|
|
1035
|
+
return chain.id;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
return void 0;
|
|
1039
|
+
}, [initChains]);
|
|
1040
|
+
const fallbackEvmChainId = preferredEvmChainId ?? defaultEvmChainId;
|
|
1024
1041
|
const isManual = useRef(false);
|
|
1025
1042
|
const connect = (params) => {
|
|
1026
1043
|
setTargetWalletType(void 0);
|
|
@@ -1133,7 +1150,11 @@ function useWallet2() {
|
|
|
1133
1150
|
switch (walletType2) {
|
|
1134
1151
|
case "EVM" /* EVM */:
|
|
1135
1152
|
if (privyWalletEVM) {
|
|
1136
|
-
|
|
1153
|
+
const desired = privyWalletEVM.chain.id;
|
|
1154
|
+
const nextChainId = supportedEvmChainIds.has(desired) ? desired : fallbackEvmChainId;
|
|
1155
|
+
if (typeof nextChainId === "number") {
|
|
1156
|
+
setStorageChain(nextChainId);
|
|
1157
|
+
}
|
|
1137
1158
|
toWallet = privyWalletEVM.accounts[0].address;
|
|
1138
1159
|
}
|
|
1139
1160
|
break;
|
|
@@ -1229,6 +1250,11 @@ function useWallet2() {
|
|
|
1229
1250
|
}
|
|
1230
1251
|
}
|
|
1231
1252
|
}, [connectorKey, privyWalletEVM, privyWalletSOL, storageChain]);
|
|
1253
|
+
useEffect(() => {
|
|
1254
|
+
if (connectorKey === "privy" /* PRIVY */ && isConnectedPrivy && AbstractChains.has(storageChain.chainId)) {
|
|
1255
|
+
setOpenConnectDrawer(true);
|
|
1256
|
+
}
|
|
1257
|
+
}, [connectorKey, isConnectedPrivy, storageChain]);
|
|
1232
1258
|
useEffect(() => {
|
|
1233
1259
|
if (connectorKey === "privy" /* PRIVY */) {
|
|
1234
1260
|
return;
|
|
@@ -3034,8 +3060,15 @@ function InitPrivyProvider({
|
|
|
3034
3060
|
if (!privyConfig) {
|
|
3035
3061
|
return children;
|
|
3036
3062
|
}
|
|
3063
|
+
const { network } = useWalletConnectorPrivy();
|
|
3037
3064
|
const config = useMemo(() => {
|
|
3038
3065
|
const chains = initChains;
|
|
3066
|
+
const preferredDefaultChainIds = (network === "mainnet" ? defaultMainnetChains : defaultTestnetChains).map((c) => c.id);
|
|
3067
|
+
const preferredDefaultChain = preferredDefaultChainIds.map((id) => chains.find((c) => c.id === id)).find((c) => !!c);
|
|
3068
|
+
const firstEvmChain = chains.find(
|
|
3069
|
+
(chain) => !SolanaChains$1.has(chain.id) && !AbstractChains.has(chain.id)
|
|
3070
|
+
);
|
|
3071
|
+
const defaultEvmChain = preferredDefaultChain ?? firstEvmChain ?? chains[0];
|
|
3039
3072
|
return {
|
|
3040
3073
|
loginMethods: privyConfig.config?.loginMethods || [
|
|
3041
3074
|
"email",
|
|
@@ -3059,10 +3092,10 @@ function InitPrivyProvider({
|
|
|
3059
3092
|
enabled: false
|
|
3060
3093
|
}
|
|
3061
3094
|
},
|
|
3062
|
-
defaultChain:
|
|
3095
|
+
defaultChain: defaultEvmChain,
|
|
3063
3096
|
supportedChains: chains
|
|
3064
3097
|
};
|
|
3065
|
-
}, [initChains, privyConfig]);
|
|
3098
|
+
}, [initChains, privyConfig, network]);
|
|
3066
3099
|
if (!initChains.length) {
|
|
3067
3100
|
return;
|
|
3068
3101
|
}
|