blob: 69646729a6aa3cd04a6e16ed3c3824cd9f0fb72a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import { useEffect, useRef, useState } from "react";
type ConfirmationState = "working" | "confirmed" | "failed" | "missing";
const CashoutConfirmation = function () {
const started = useRef(false);
const [state, setState] = useState<ConfirmationState>("working");
useEffect(() => {
if (started.current) return;
started.current = true;
const params = new URLSearchParams(window.location.search);
const token = params.get("token");
if (!token) {
setState("missing");
return;
}
window.history.replaceState({}, "", window.location.pathname);
void fetch("/wallet/cashout/confirm/", {
method: "POST",
credentials: "include",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token }),
})
.then((response) => {
if (!response.ok) throw new Error("Cashout confirmation failed");
setState("confirmed");
})
.catch(() => setState("failed"));
}, []);
if (state === "missing") return <p>This cashout link is missing its token.</p>;
if (state === "failed") return <p>This cashout link is invalid or has expired.</p>;
if (state === "confirmed") return <p>Your cashout has been confirmed.</p>;
return <p>Confirming your cashout…</p>;
};
export default CashoutConfirmation;
|