Skip to content

Commit

Permalink
fix: autoconnect & argent mobile connection (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv authored Jul 16, 2024
1 parent bd658e6 commit 2cbcc66
Show file tree
Hide file tree
Showing 4 changed files with 7,837 additions and 12,115 deletions.
3 changes: 2 additions & 1 deletion components/UI/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ const Navbar: FunctionComponent = () => {
// Autoconnect
useEffect(() => {
const connectToStarknet = async () => {
if (isConnected || isMobile) return;
const connector = getLastConnected();
if (connector && connector.available()) await connectWallet(connector);
};
connectToStarknet();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [connectAsync, connectors]); // Disable to make sure it only runs once
}, [connectors]); // Disable to make sure it only runs once

useEffect(() => {
address ? setIsConnected(true) : setIsConnected(false);
Expand Down
12 changes: 11 additions & 1 deletion components/UI/walletConnect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FunctionComponent } from "react";
import React, { FunctionComponent, useEffect, useState } from "react";
import { useRouter } from "next/router";
import { Modal, useMediaQuery } from "@mui/material";
import { Connector } from "starknetkit";
Expand All @@ -8,6 +8,7 @@ import {
getConnectorDiscovery,
getConnectorIcon,
getConnectorName,
isInArgentMobileAppBrowser,
sortConnectors,
} from "@/utils/connectorWrapper";

Expand All @@ -25,13 +26,22 @@ const WalletConnect: FunctionComponent<WalletConnectProps> = ({
connectWallet,
}) => {
const router = useRouter();
const [isArgentMobile, setIsArgentMobile] = useState(false);
const connect = (connector: Connector) => {
connectWallet(connector);
closeModal();
};
const isMobile = useMediaQuery("(max-width: 768px)");

useEffect(() => {
if (typeof window !== "undefined")
setIsArgentMobile(isInArgentMobileAppBrowser());
}, []);

const filterConnectors = (connectors: Connector[]) => {
if (isArgentMobile) {
return connectors.filter((connector) => connector.id === "argentMobile");
}
if (!isMobile) return connectors;
return connectors.filter((connector) => connector.id !== "argentX");
};
Expand Down
Loading

0 comments on commit 2cbcc66

Please sign in to comment.