import React, { CSSProperties, FunctionComponent, useEffect, useMemo, useState, } from "react"; import QRCode from "qrcode.react"; import { isAndroid, isMobile } from "./util"; export type ModalUIOptions = { backdrop?: { className?: string; style?: CSSProperties; disableDefaultStyle?: boolean; }; modalContainer?: { className?: string; style?: CSSProperties; disableDefaultStyle?: boolean; }; modalHeader?: { className?: string; style?: CSSProperties; disableDefaultStyle?: boolean; }; qrCodeContainer?: { className?: string; style?: CSSProperties; }; qrCodeSize?: number; appButtonContainer?: { className?: string; style?: CSSProperties; }; appButton?: { className?: string; style?: CSSProperties; }; }; export const Modal: FunctionComponent<{ uiOptions?: ModalUIOptions; uri: string; close: () => void; }> = ({ uiOptions, uri, close }) => { const [checkMobile] = useState(() => isMobile()); const [checkAndroid] = useState(() => isAndroid()); const saveMobileLinkInfo = (info: { name: string; href: string }) => { localStorage.setItem("wallet-connect-v2-mobile-link", JSON.stringify(info)); }; const navigateToAppURL = useMemo(() => { if (checkMobile) { if (checkAndroid) { // Save the mobile link. saveMobileLinkInfo({ name: "Keplr", href: "intent://wcV2#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;", }); return `intent://wcV2?${uri}#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`; } else { // Save the mobile link. saveMobileLinkInfo({ name: "Keplr", href: `keplrwallet://wcV2`, }); return `keplrwallet://wcV2?${uri}`; } } }, [checkAndroid, checkMobile, uri]); useEffect(() => { // Try opening the app without interaction. if (navigateToAppURL) { window.location.href = navigateToAppURL; } }, [navigateToAppURL]); return (
{ e.preventDefault(); e.stopPropagation(); close(); }} >
{ e.preventDefault(); e.stopPropagation(); }} > {!checkMobile ? (

Scan QR Code

) : (

Open App

)}
); };