Closed lxiiiixi closed 6 months ago
Okay, I now understand the reason. I should attempt to establish a connection by activating the network.
import { Connector } from "@web3-react/types";
import { ConnectionType } from "./types";
import { useEffect } from "react";
import { useRecentConnection } from "./useRecentConnection";
import { getConnection } from ".";
async function connect(connector: Connector, type: ConnectionType) {
console.log("Tring to connect by", type, "......");
try {
if (connector.connectEagerly) {
await connector.connectEagerly();
} else {
await connector.activate();
}
return true;
} catch (error) {
console.debug(`web3-react eager connection error: ${error}`);
return false;
}
}
export const useEagerlyConnect = () => {
const { getRecentConnectionMeta } = useRecentConnection();
const connectionMeta = getRecentConnectionMeta();
console.log("Last connected by", connectionMeta, connectionMeta?.walletName);
const networkConnection = getConnection(ConnectionType.NETWORK);
if (networkConnection && networkConnection.connector)
connect(networkConnection.connector, ConnectionType.NETWORK);
useEffect(() => {
// try to connect with the most recent connection
if (connectionMeta && connectionMeta?.type) {
const connection = getConnection(connectionMeta?.type);
if (connection && connection.connector) {
connect(connection.connector, ConnectionType.EIP_6963_INJECTED);
} else {
console.warn("unsupported connector");
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
};
I am encountering an issue with the following connections configuration:
However, if a user does not connect a wallet, the application fails to retrieve data such as blockNumber from the provider:
When the wallet is connected, I can successfully obtain the blockNumber. If not, I encounter the following error:
Can someone explain why the fallback network is not functioning? I am somewhat confused by this behavior.