aboutsummaryrefslogtreecommitdiff
path: root/jb-ui/src/pages/CashoutConfirmation.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'jb-ui/src/pages/CashoutConfirmation.tsx')
-rw-r--r--jb-ui/src/pages/CashoutConfirmation.tsx41
1 files changed, 41 insertions, 0 deletions
diff --git a/jb-ui/src/pages/CashoutConfirmation.tsx b/jb-ui/src/pages/CashoutConfirmation.tsx
new file mode 100644
index 0000000..6964672
--- /dev/null
+++ b/jb-ui/src/pages/CashoutConfirmation.tsx
@@ -0,0 +1,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;