@cometh/connect-react-hooks 0.0.11-dev.2 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +10 -10
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -2185,9 +2185,7 @@ function useCancelRecoveryRequest() {
|
|
2185
2185
|
|
2186
2186
|
// src/hooks/useSwitchChain.ts
|
2187
2187
|
|
2188
|
-
|
2189
2188
|
var useSwitchChain = () => {
|
2190
|
-
const { address } = _wagmi.useAccount.call(void 0, );
|
2191
2189
|
const context = _react.useContext.call(void 0, ConnectContext);
|
2192
2190
|
if (context === void 0) {
|
2193
2191
|
throw new Error("useSwitchChain must be used within a ConnectProvider");
|
@@ -2202,16 +2200,20 @@ var useSwitchChain = () => {
|
|
2202
2200
|
const [error, setError] = _react.useState.call(void 0, null);
|
2203
2201
|
const switchChainInternal = _react.useCallback.call(void 0,
|
2204
2202
|
async (params) => {
|
2205
|
-
const {
|
2206
|
-
if (!networksConfig)
|
2203
|
+
const { chainId } = params;
|
2204
|
+
if (!networksConfig)
|
2205
|
+
throw new Error("No current configuration found");
|
2206
|
+
const selectedNetwork = _optionalChain([networksConfig, 'optionalAccess', _90 => _90.find, 'call', _91 => _91(
|
2207
|
+
(network) => _optionalChain([network, 'access', _92 => _92.chain, 'optionalAccess', _93 => _93.id]) === chainId
|
2208
|
+
)]);
|
2209
|
+
if (!selectedNetwork)
|
2207
2210
|
throw new Error("No current configuration found");
|
2208
|
-
}
|
2209
2211
|
try {
|
2210
2212
|
await updateSmartAccountClient({
|
2211
|
-
address: _optionalChain([smartAccountClient, 'optionalAccess',
|
2212
|
-
chain
|
2213
|
+
address: _optionalChain([smartAccountClient, 'optionalAccess', _94 => _94.account, 'access', _95 => _95.address]),
|
2214
|
+
chain: selectedNetwork.chain
|
2213
2215
|
});
|
2214
|
-
_optionalChain([queryClient, 'optionalAccess',
|
2216
|
+
_optionalChain([queryClient, 'optionalAccess', _96 => _96.invalidateQueries, 'call', _97 => _97({
|
2215
2217
|
queryKey: ["switchChain"]
|
2216
2218
|
})]);
|
2217
2219
|
} catch (e) {
|
@@ -2227,7 +2229,6 @@ var useSwitchChain = () => {
|
|
2227
2229
|
);
|
2228
2230
|
const switchChain = _react.useCallback.call(void 0,
|
2229
2231
|
(params) => {
|
2230
|
-
if (!address) throw new Error("Wallet is not connected");
|
2231
2232
|
setIsPending(true);
|
2232
2233
|
setError(null);
|
2233
2234
|
switchChainInternal(params).catch((e) => {
|
@@ -2243,7 +2244,6 @@ var useSwitchChain = () => {
|
|
2243
2244
|
);
|
2244
2245
|
const switchChainAsync = _react.useCallback.call(void 0,
|
2245
2246
|
async (params) => {
|
2246
|
-
if (!address) throw new Error("Wallet is not connected");
|
2247
2247
|
setIsPending(true);
|
2248
2248
|
setError(null);
|
2249
2249
|
try {
|
package/dist/index.d.cts
CHANGED
@@ -939,10 +939,10 @@ declare function useCancelRecoveryRequest(): UseCancelRecoveryRequestReturn;
|
|
939
939
|
|
940
940
|
declare const useSwitchChain: () => {
|
941
941
|
switchChain: (params: {
|
942
|
-
|
942
|
+
chainId: number;
|
943
943
|
}) => void;
|
944
944
|
switchChainAsync: (params: {
|
945
|
-
|
945
|
+
chainId: number;
|
946
946
|
}) => Promise<void>;
|
947
947
|
isPending: boolean;
|
948
948
|
error: Error | null;
|
package/dist/index.d.ts
CHANGED
@@ -939,10 +939,10 @@ declare function useCancelRecoveryRequest(): UseCancelRecoveryRequestReturn;
|
|
939
939
|
|
940
940
|
declare const useSwitchChain: () => {
|
941
941
|
switchChain: (params: {
|
942
|
-
|
942
|
+
chainId: number;
|
943
943
|
}) => void;
|
944
944
|
switchChainAsync: (params: {
|
945
|
-
|
945
|
+
chainId: number;
|
946
946
|
}) => Promise<void>;
|
947
947
|
isPending: boolean;
|
948
948
|
error: Error | null;
|
package/dist/index.js
CHANGED
@@ -2185,9 +2185,7 @@ function useCancelRecoveryRequest() {
|
|
2185
2185
|
|
2186
2186
|
// src/hooks/useSwitchChain.ts
|
2187
2187
|
import { useCallback as useCallback8, useContext as useContext8, useState as useState9 } from "react";
|
2188
|
-
import { useAccount as useAccount2 } from "wagmi";
|
2189
2188
|
var useSwitchChain = () => {
|
2190
|
-
const { address } = useAccount2();
|
2191
2189
|
const context = useContext8(ConnectContext);
|
2192
2190
|
if (context === void 0) {
|
2193
2191
|
throw new Error("useSwitchChain must be used within a ConnectProvider");
|
@@ -2202,14 +2200,18 @@ var useSwitchChain = () => {
|
|
2202
2200
|
const [error, setError] = useState9(null);
|
2203
2201
|
const switchChainInternal = useCallback8(
|
2204
2202
|
async (params) => {
|
2205
|
-
const {
|
2206
|
-
if (!networksConfig)
|
2203
|
+
const { chainId } = params;
|
2204
|
+
if (!networksConfig)
|
2205
|
+
throw new Error("No current configuration found");
|
2206
|
+
const selectedNetwork = networksConfig?.find(
|
2207
|
+
(network) => network.chain?.id === chainId
|
2208
|
+
);
|
2209
|
+
if (!selectedNetwork)
|
2207
2210
|
throw new Error("No current configuration found");
|
2208
|
-
}
|
2209
2211
|
try {
|
2210
2212
|
await updateSmartAccountClient({
|
2211
2213
|
address: smartAccountClient?.account.address,
|
2212
|
-
chain
|
2214
|
+
chain: selectedNetwork.chain
|
2213
2215
|
});
|
2214
2216
|
queryClient?.invalidateQueries({
|
2215
2217
|
queryKey: ["switchChain"]
|
@@ -2227,7 +2229,6 @@ var useSwitchChain = () => {
|
|
2227
2229
|
);
|
2228
2230
|
const switchChain = useCallback8(
|
2229
2231
|
(params) => {
|
2230
|
-
if (!address) throw new Error("Wallet is not connected");
|
2231
2232
|
setIsPending(true);
|
2232
2233
|
setError(null);
|
2233
2234
|
switchChainInternal(params).catch((e) => {
|
@@ -2243,7 +2244,6 @@ var useSwitchChain = () => {
|
|
2243
2244
|
);
|
2244
2245
|
const switchChainAsync = useCallback8(
|
2245
2246
|
async (params) => {
|
2246
|
-
if (!address) throw new Error("Wallet is not connected");
|
2247
2247
|
setIsPending(true);
|
2248
2248
|
setError(null);
|
2249
2249
|
try {
|