Skip to content

Commit

Permalink
fix: switch network only on argent
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Nov 29, 2024
1 parent dad2936 commit d4c67ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 12 additions & 6 deletions components/UI/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getConnectorIcon,
getLastConnected,
getLastConnector,
isArgentWallet,
} from "@/utils/connectorWrapper";
import WalletConnect from "./walletConnect";
import ArrowDownIcon from "./iconsComponents/icons/arrowDownIcon";
Expand All @@ -45,7 +46,7 @@ const Navbar: FunctionComponent = () => {
const [desktopNav, setDesktopNav] = useState<boolean>(false);
const { address } = useAccount();
const [isConnected, setIsConnected] = useState<boolean>(false);
const { connectAsync, connectors } = useConnect();
const { connectAsync, connectors, connector } = useConnect();
const { disconnect } = useDisconnect();
const isMobile = useMediaQuery("(max-width:425px)");
const domainOrAddress = useDisplayName(address ?? "", isMobile);
Expand Down Expand Up @@ -145,9 +146,12 @@ const Navbar: FunctionComponent = () => {
return textToReturn;
}

const switchNetwork = async (network: string) => {
const res = await switchChainAsync();
if (res) setIsWrongNetwork(false);
const switchNetwork = async () => {
if (isArgentWallet(connector)) disconnectByClick();
else {
const res = await switchChainAsync();
if (res) setIsWrongNetwork(false);
}
};

return (
Expand Down Expand Up @@ -390,8 +394,10 @@ const Navbar: FunctionComponent = () => {
network to be able use it.
</p>
<div className="mt-5">
<Button onClick={() => switchNetwork(network)}>
{`Switch to ${network}`}
<Button onClick={() => switchNetwork()}>
{isArgentWallet(connector)
? `Switch to ${network}`
: "Disconnect"}
</Button>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions utils/connectorWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { InjectedConnector } from "starknetkit/injected";
import { WebWalletConnector } from "starknetkit/webwallet";
import { getBrowser } from "./browserService";
import { constants } from "starknet";
import { Connector as StarknetReactConnector } from "@starknet-react/core";

export const getConnectors = () => {
const connectors = [
Expand Down Expand Up @@ -90,6 +91,15 @@ export const getLastConnected = (): Connector | null => {
return null;
};

export const isArgentWallet = (connector?: StarknetReactConnector) => {
return (
connector &&
(connector.id === "argentX" ||
connector.id === "argentMobile" ||
connector.id === "argentWebWallet")
);
};

const wallets = [
{
id: "argentX",
Expand Down

0 comments on commit d4c67ee

Please sign in to comment.