Skip to content

Commit

Permalink
Use inapp spy (#1253)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Jan 8, 2025
1 parent 4f40694 commit 11a7727
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"framer-motion": "^6",
"graphql": "^16.3.0",
"graphql-request": "^5.0.0",
"inapp-spy": "4.2.1",
"js-cookie": "^3.0.1",
"p-throttle": "^6.2.0",
"posthog-js": "^1.181.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useCreateController } from "./useCreateController";
import { Input } from "@cartridge/ui-next";
import { ErrorAlert } from "@/components/ErrorAlert";
import { VerifiableControllerTheme } from "@/context/theme";
import InAppSpy from "inapp-spy";

interface CreateControllerViewProps {
theme: VerifiableControllerTheme;
Expand Down Expand Up @@ -168,30 +169,15 @@ export function CreateController({
loginMode,
});

const [isInAppBrowser, setIsInAppBrowser] = useState(false);
const [{ isInApp }] = useState(() => InAppSpy());

useEffect(() => {
const ua = navigator.userAgent;
// Check for common in-app browser signatures
const isInApp =
ua.includes("FBAN") || // Facebook
ua.includes("FBAV") || // Facebook
ua.includes("Twitter") || // Twitter
ua.includes("Instagram") || // Instagram
ua.includes("Line") || // Line
/\bFB[\w_]+\//.test(ua) || // Facebook
/\bInstagram\b/.test(ua); // Instagram

setIsInAppBrowser(isInApp);

if (isInApp) {
const nativeBrowserUrl = getNativeBrowserUrl();
if (nativeBrowserUrl) {
// Try to open in native browser
window.location.href = nativeBrowserUrl;
}

setIsInAppBrowser(true);
}
}, []);

Check warning on line 182 in packages/keychain/src/components/connect/create/CreateController.tsx

View workflow job for this annotation

GitHub Actions / ts-lint

React Hook useEffect has a missing dependency: 'isInApp'. Either include it or remove the dependency array

Expand Down Expand Up @@ -234,7 +220,7 @@ export function CreateController({
validation={validation}
isLoading={isLoading}
error={error}
isInAppBrowser={isInAppBrowser}
isInAppBrowser={isInApp}
onUsernameChange={handleUsernameChange}
onUsernameFocus={handleUsernameFocus}
onUsernameClear={handleUsernameClear}
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 11a7727

Please sign in to comment.