Skip to content

Commit

Permalink
fix: argent mobile connection (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv authored Sep 12, 2024
1 parent d499e97 commit ac7a5c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 11 additions & 1 deletion app/components/connection/starknetConnect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React, { FunctionComponent } from "react";
import React, { FunctionComponent, useEffect, useState } from "react";
import { Modal, useMediaQuery } from "@mui/material";
import { Connector } from "starknetkit";
import styles from "../../styles/components/walletConnect.module.css";
Expand All @@ -9,6 +9,7 @@ import {
getConnectorDiscovery,
getConnectorIcon,
getConnectorName,
isInArgentMobileAppBrowser,
sortConnectors,
} from "@/utils/starknetConnectorsWrapper";
import Button from "../button";
Expand All @@ -29,6 +30,12 @@ const StarknetWalletConnect: FunctionComponent<StarknetWalletConnectProps> = ({
onWalletConnected,
}) => {
const { connectAsync } = useConnect();
const [isArgentMobile, setIsArgentMobile] = useState(false);

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

const connect = async (connector: Connector) => {
await connectAsync({ connector });
Expand All @@ -38,6 +45,9 @@ const StarknetWalletConnect: FunctionComponent<StarknetWalletConnectProps> = ({
const isMobile = useMediaQuery("(max-width: 768px)");

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
15 changes: 14 additions & 1 deletion utils/starknetConnectorsWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { constants } from "starknet";
import { Connector } from "starknetkit";
import { Connector, StarknetWindowObject } from "starknetkit";
import { ArgentMobileConnector } from "starknetkit/argentMobile";
import { InjectedConnector } from "starknetkit/injected";
import { WebWalletConnector } from "starknetkit/webwallet";
Expand Down Expand Up @@ -146,6 +146,19 @@ export const getBraavosWebsite = (): string => {
return wallets.find((wallet) => wallet.id === "braavos")?.website as string;
};

export const isInArgentMobileAppBrowser = (): boolean => {
if (typeof window === "undefined" || !window?.starknet_argentX) {
return false;
}

const starknetMobile =
window?.starknet_argentX as unknown as StarknetWindowObject & {
isInAppBrowser: boolean;
};

return starknetMobile?.isInAppBrowser;
};

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

0 comments on commit ac7a5c7

Please sign in to comment.