fix: restore staging imtoken login behavior
Some checks failed
Deploy Staging (terry-wallet-login) / deploy (push) Failing after 37s
Some checks failed
Deploy Staging (terry-wallet-login) / deploy (push) Failing after 37s
This commit is contained in:
@@ -2,8 +2,6 @@ import { useEffect } from "react";
|
||||
import {
|
||||
connectInjectedWallet,
|
||||
getInjectedWallet,
|
||||
isImTokenBrowser,
|
||||
signInWithInjectedWallet,
|
||||
type WalletKind,
|
||||
} from "./injected";
|
||||
import { localWalletToken, useWallet } from "./WalletProvider";
|
||||
@@ -51,28 +49,19 @@ export function AutoInjectedLogin() {
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const explicitKind = parseKind(params.get(AUTO_LOGIN_PARAM));
|
||||
const kind = explicitKind ?? (isImTokenBrowser() ? "imToken" : null);
|
||||
const kind = parseKind(params.get(AUTO_LOGIN_PARAM));
|
||||
if (!kind) return;
|
||||
if (status === "loading") return;
|
||||
|
||||
if (explicitKind) stripAutoLoginParam();
|
||||
stripAutoLoginParam();
|
||||
if (status === "loggedIn") return;
|
||||
|
||||
let cancelled = false;
|
||||
void waitForInjected(kind).then(async (ready) => {
|
||||
if (cancelled || !ready) return;
|
||||
try {
|
||||
if (kind === "imToken") {
|
||||
const address = await connectInjectedWallet(kind);
|
||||
if (cancelled) return;
|
||||
completeLogin(localWalletToken(address), address);
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await signInWithInjectedWallet(kind);
|
||||
const address = await connectInjectedWallet(kind);
|
||||
if (cancelled) return;
|
||||
completeLogin(res.token, res.wallet);
|
||||
completeLogin(localWalletToken(address), address);
|
||||
} catch (err) {
|
||||
console.warn("[wallet-autologin] failed", err);
|
||||
}
|
||||
@@ -80,7 +69,7 @@ export function AutoInjectedLogin() {
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [completeLogin, status]);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { hasWalletConnectProjectId } from "./RainbowWalletProvider";
|
||||
import {
|
||||
connectInjectedWallet,
|
||||
getInjectedWallet,
|
||||
signInWithInjectedWallet,
|
||||
type WalletKind,
|
||||
} from "./injected";
|
||||
import { localWalletToken, useWallet } from "./WalletProvider";
|
||||
@@ -167,40 +166,21 @@ export function useWalletConnectLogin() {
|
||||
getInjectedWallet(preferredWallet)
|
||||
) {
|
||||
try {
|
||||
if (preferredWallet === "imToken") {
|
||||
const injectedAddress =
|
||||
await connectInjectedWallet(preferredWallet);
|
||||
console.info("[wallet-login] injected connected", {
|
||||
preferredWallet,
|
||||
address: injectedAddress,
|
||||
chain: "BNB Chain",
|
||||
chainId: bsc.id,
|
||||
});
|
||||
completeLogin(localWalletToken(injectedAddress), injectedAddress);
|
||||
setState("idle");
|
||||
return;
|
||||
}
|
||||
|
||||
setState("signing");
|
||||
const result = await signInWithInjectedWallet(preferredWallet);
|
||||
console.info("[wallet-login] injected verified", {
|
||||
const injectedAddress = await connectInjectedWallet(preferredWallet);
|
||||
console.info("[wallet-login] injected connected", {
|
||||
preferredWallet,
|
||||
address: result.wallet,
|
||||
address: injectedAddress,
|
||||
chain: "BNB Chain",
|
||||
chainId: bsc.id,
|
||||
});
|
||||
completeLogin(result.token, result.wallet);
|
||||
completeLogin(localWalletToken(injectedAddress), injectedAddress);
|
||||
setState("idle");
|
||||
return;
|
||||
} catch (err) {
|
||||
pendingRef.current = false;
|
||||
setState("idle");
|
||||
setError(err instanceof Error ? err.message : "Wallet login failed");
|
||||
console.info("[wallet-login] injected verification failed", {
|
||||
console.info("[wallet-login] injected connect fallback to wc", {
|
||||
preferredWallet,
|
||||
message: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user