fix: auto login inside imtoken browser
This commit is contained in:
@@ -2,6 +2,7 @@ import { useEffect } from "react";
|
||||
import {
|
||||
connectInjectedWallet,
|
||||
getInjectedWallet,
|
||||
isImTokenBrowser,
|
||||
signInWithInjectedWallet,
|
||||
type WalletKind,
|
||||
} from "./injected";
|
||||
@@ -47,9 +48,9 @@ function waitForInjected(kind: WalletKind): Promise<boolean> {
|
||||
/**
|
||||
* When the page is opened via a `?autoLogin=<wallet>` deeplink (typically from
|
||||
* inside TokenPocket / imToken in-app browsers), wait for the wallet to inject
|
||||
* `window.ethereum`, then require a wallet signature and complete a verified
|
||||
* backend wallet session. Bypasses WalletConnect entirely so it works on
|
||||
* networks where the WC relay is blocked.
|
||||
* `window.ethereum`, then complete wallet login without WalletConnect. imToken
|
||||
* may drop the query string while opening its in-app browser, so imToken browser
|
||||
* detection also starts the same direct-login path.
|
||||
*/
|
||||
export function AutoInjectedLogin() {
|
||||
const { completeLogin, status } = useWallet();
|
||||
@@ -57,11 +58,12 @@ export function AutoInjectedLogin() {
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const kind = parseKind(params.get(AUTO_LOGIN_PARAM));
|
||||
const explicitKind = parseKind(params.get(AUTO_LOGIN_PARAM));
|
||||
const kind = explicitKind ?? (isImTokenBrowser() ? "imToken" : null);
|
||||
if (!kind) return;
|
||||
if (status === "loading") return;
|
||||
|
||||
stripAutoLoginParam();
|
||||
if (explicitKind) stripAutoLoginParam();
|
||||
if (status === "loggedIn") return;
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
Reference in New Issue
Block a user