import { WalletApi as JBApi, CashoutConfirmation } from "@/api_jb"; import { useEffect, useRef, useState } from "react"; type ExchangeState = "working" | "failed" | "missing"; const MagicWallet = function () { const started = useRef(false); const [state, setState] = useState("working"); const [errorMsg, setErrorMesg] = useState(""); useEffect(() => { // React Strict Mode runs effects twice in development. Never redeem twice. if (started.current) return; started.current = true; const params = new URLSearchParams(window.location.search); const token = params.get("token"); if (!token) { setState("missing"); return; } // Keep the credential out of browser history and subsequent Referer headers. window.history.replaceState({}, "", window.location.pathname); const cc = { token: token, } as CashoutConfirmation; // const config = new Configuration({ basePath: "http://localhost:5174" }); new JBApi() .confirmCashoutWalletCashoutConfirmPost(cc) .then((res) => { console.log("confirmCashoutWalletCashoutConfirmPost", res.data); // if (!res.ok) throw new Error("Magic-link exchange failed"); window.location.replace("/"); }) .catch((err) => { const response = err?.response?.data; setErrorMesg(response?.detail ?? err.message); setState("failed"); }); }, []); if (state === "missing") { return

This login link is missing its token.

; } if (state === "failed") { return

{errorMsg}

; } return

Signing you in…

; }; export default MagicWallet;