@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.js
CHANGED
|
@@ -1009,7 +1009,7 @@ var getChainType = (chainId) => {
|
|
|
1009
1009
|
// src/hooks/useWallet.tsx
|
|
1010
1010
|
function useWallet2() {
|
|
1011
1011
|
const { track } = hooks.useTrack();
|
|
1012
|
-
const { walletChainTypeConfig } = useWalletConnectorPrivy();
|
|
1012
|
+
const { walletChainTypeConfig, initChains, network } = useWalletConnectorPrivy();
|
|
1013
1013
|
const [connectorKey, setConnectorKey] = hooks.useLocalStorage(types.ConnectorKey, "");
|
|
1014
1014
|
const {
|
|
1015
1015
|
disconnect: disconnectEVM,
|
|
@@ -1046,6 +1046,23 @@ function useWallet2() {
|
|
|
1046
1046
|
const [walletType, setWalletType] = React19.useState(null);
|
|
1047
1047
|
const { storageChain, setStorageChain } = hooks.useStorageChain();
|
|
1048
1048
|
const { setOpenConnectDrawer, targetWalletType, setTargetWalletType } = useWalletConnectorPrivy();
|
|
1049
|
+
const supportedEvmChainIds = React19.useMemo(() => {
|
|
1050
|
+
const ids = initChains?.map((c) => c.id).filter((id) => !types.SolanaChains.has(id) && !types.AbstractChains.has(id));
|
|
1051
|
+
return new Set(ids ?? []);
|
|
1052
|
+
}, [initChains]);
|
|
1053
|
+
const preferredEvmChainId = React19.useMemo(() => {
|
|
1054
|
+
const preferredOrder = network === "mainnet" ? types.defaultMainnetChains : types.defaultTestnetChains;
|
|
1055
|
+
return preferredOrder.map((c) => c.id).find((id) => supportedEvmChainIds.has(id));
|
|
1056
|
+
}, [network, supportedEvmChainIds]);
|
|
1057
|
+
const defaultEvmChainId = React19.useMemo(() => {
|
|
1058
|
+
for (const chain of initChains ?? []) {
|
|
1059
|
+
if (!types.SolanaChains.has(chain.id) && !types.AbstractChains.has(chain.id)) {
|
|
1060
|
+
return chain.id;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
return void 0;
|
|
1064
|
+
}, [initChains]);
|
|
1065
|
+
const fallbackEvmChainId = preferredEvmChainId ?? defaultEvmChainId;
|
|
1049
1066
|
const isManual = React19.useRef(false);
|
|
1050
1067
|
const connect = (params) => {
|
|
1051
1068
|
setTargetWalletType(void 0);
|
|
@@ -1158,7 +1175,11 @@ function useWallet2() {
|
|
|
1158
1175
|
switch (walletType2) {
|
|
1159
1176
|
case "EVM" /* EVM */:
|
|
1160
1177
|
if (privyWalletEVM) {
|
|
1161
|
-
|
|
1178
|
+
const desired = privyWalletEVM.chain.id;
|
|
1179
|
+
const nextChainId = supportedEvmChainIds.has(desired) ? desired : fallbackEvmChainId;
|
|
1180
|
+
if (typeof nextChainId === "number") {
|
|
1181
|
+
setStorageChain(nextChainId);
|
|
1182
|
+
}
|
|
1162
1183
|
toWallet = privyWalletEVM.accounts[0].address;
|
|
1163
1184
|
}
|
|
1164
1185
|
break;
|
|
@@ -1254,6 +1275,11 @@ function useWallet2() {
|
|
|
1254
1275
|
}
|
|
1255
1276
|
}
|
|
1256
1277
|
}, [connectorKey, privyWalletEVM, privyWalletSOL, storageChain]);
|
|
1278
|
+
React19.useEffect(() => {
|
|
1279
|
+
if (connectorKey === "privy" /* PRIVY */ && isConnectedPrivy && types.AbstractChains.has(storageChain.chainId)) {
|
|
1280
|
+
setOpenConnectDrawer(true);
|
|
1281
|
+
}
|
|
1282
|
+
}, [connectorKey, isConnectedPrivy, storageChain]);
|
|
1257
1283
|
React19.useEffect(() => {
|
|
1258
1284
|
if (connectorKey === "privy" /* PRIVY */) {
|
|
1259
1285
|
return;
|
|
@@ -3059,8 +3085,15 @@ function InitPrivyProvider({
|
|
|
3059
3085
|
if (!privyConfig) {
|
|
3060
3086
|
return children;
|
|
3061
3087
|
}
|
|
3088
|
+
const { network } = useWalletConnectorPrivy();
|
|
3062
3089
|
const config = React19.useMemo(() => {
|
|
3063
3090
|
const chains = initChains;
|
|
3091
|
+
const preferredDefaultChainIds = (network === "mainnet" ? types.defaultMainnetChains : types.defaultTestnetChains).map((c) => c.id);
|
|
3092
|
+
const preferredDefaultChain = preferredDefaultChainIds.map((id) => chains.find((c) => c.id === id)).find((c) => !!c);
|
|
3093
|
+
const firstEvmChain = chains.find(
|
|
3094
|
+
(chain) => !types.SolanaChains.has(chain.id) && !types.AbstractChains.has(chain.id)
|
|
3095
|
+
);
|
|
3096
|
+
const defaultEvmChain = preferredDefaultChain ?? firstEvmChain ?? chains[0];
|
|
3064
3097
|
return {
|
|
3065
3098
|
loginMethods: privyConfig.config?.loginMethods || [
|
|
3066
3099
|
"email",
|
|
@@ -3084,10 +3117,10 @@ function InitPrivyProvider({
|
|
|
3084
3117
|
enabled: false
|
|
3085
3118
|
}
|
|
3086
3119
|
},
|
|
3087
|
-
defaultChain:
|
|
3120
|
+
defaultChain: defaultEvmChain,
|
|
3088
3121
|
supportedChains: chains
|
|
3089
3122
|
};
|
|
3090
|
-
}, [initChains, privyConfig]);
|
|
3123
|
+
}, [initChains, privyConfig, network]);
|
|
3091
3124
|
if (!initChains.length) {
|
|
3092
3125
|
return;
|
|
3093
3126
|
}
|