Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autoconnect & argent mobile connection #856

Merged
merged 8 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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