diff --git a/app/mint/page.tsx b/app/mint/page.tsx index 6da71d2..c1ddf77 100644 --- a/app/mint/page.tsx +++ b/app/mint/page.tsx @@ -9,6 +9,7 @@ export const metadata: Metadata = { import React, { useState, useEffect, useMemo } from 'react'; import Link from 'next/link'; +import { useRouter, useSearchParams } from 'next/navigation'; import { PageContainer } from '@/components/layout/page-container'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; @@ -83,6 +84,8 @@ export default function MintPage() { refetch: refetchBalance, } = useBalance(); const kit = useStellarWalletsKit(); + const router = useRouter(); + const searchParams = useSearchParams(); const { uiError: mintUiError, setApiError: setMintApiError, clearError: clearMintError, isSubmitDisabled: isMintDisabled } = useApiError(); const { uiError: burnUiError, setApiError: setBurnApiError, clearError: clearBurnError, isSubmitDisabled: isBurnDisabled } = useApiError(); const [activeTab, setActiveTab] = useState<'mint' | 'burn' | 'rates'>('mint'); @@ -130,6 +133,34 @@ export default function MintPage() { .finally(() => setFiatAccountsLoading(false)); }, [opts.token]); + useEffect(() => { + if (activeTab !== "rates") return; + setRatesLoading(true); + ratesApi + .getRates(opts) + .then(setRates) + .catch(() => setRates(null)) + .finally(() => setRatesLoading(false)); + }, [activeTab, opts.token]); + + useEffect(() => { + const stepParam = searchParams.get("step"); + if (stepParam === "confirm" || stepParam === "success") { + setStep(stepParam); + } else { + setStep("input"); + } + }, [searchParams]); + + const handleMintConfirm = () => { + setMintError(""); + router.push("/mint?step=confirm", { scroll: false }); + setStep("confirm"); + }; + const handleBurnConfirm = () => { + router.push("/mint?step=confirm", { scroll: false }); + setStep("confirm"); + }; const handleMintConfirm = () => { clearMintError(); setStep("confirm"); @@ -236,7 +267,8 @@ export default function MintPage() { setMintAcbuReceived( typeof acbu === "number" && Number.isFinite(acbu) ? acbu : null, ); - refetchBalance(); + refreshBalance(); + router.replace("/mint?step=success", { scroll: false }); setStep("success"); } catch (e) { setMintApiError(e); @@ -313,6 +345,7 @@ export default function MintPage() { opts, ); setTxId(res.transaction_id || res.transactionId || null); + router.replace("/mint?step=success", { scroll: false }); setStep("success"); } catch (e) { setBurnApiError(e); @@ -328,6 +361,7 @@ export default function MintPage() { }; const resetForm = () => { setStep("input"); + router.replace("/mint", { scroll: false }); setFiatAmount(""); setBurnAmount(""); clearBurnError(); @@ -661,7 +695,15 @@ export default function MintPage() { - + { + if (!open) { + router.replace("/mint", { scroll: false }); + } + setStep(open ? "confirm" : "input"); + }} + > @@ -696,7 +738,10 @@ export default function MintPage() {
setStep("input")} + onClick={() => { + setStep("input"); + router.replace("/mint", { scroll: false }); + }} disabled={executing} > {t('mint.cancel')} @@ -712,7 +757,14 @@ export default function MintPage() { - + { + if (!open) { + router.replace("/mint", { scroll: false }); + } + }} + > {t('mint.operationComplete')} diff --git a/app/send/page.tsx b/app/send/page.tsx index f8f258b..ca07d4b 100644 --- a/app/send/page.tsx +++ b/app/send/page.tsx @@ -10,6 +10,7 @@ export const metadata: Metadata = { import React, { useState, useEffect, useCallback, useMemo, useRef } from "react"; import { useVirtualizer } from "@tanstack/react-virtual"; import Link from "next/link"; +import { useRouter, useSearchParams } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; @@ -120,16 +121,41 @@ export default function SendPage() { const [contactsError, setContactsError] = useState(""); const [submitError, setSubmitError] = useState(""); const [sending, setSending] = useState(false); - const [loadError, setLoadError] = useState(""); - - const contactsParentRef = useRef(null); - - const virtualizer = useVirtualizer({ - count: contacts.length, - getScrollElement: () => contactsParentRef.current?.parentElement as Element | null, - estimateSize: () => 36, - overscan: 5, - }); + const router = useRouter(); + const searchParams = useSearchParams(); + + useEffect(() => { + const step = searchParams.get("step"); + setShowConfirmDialog(step === "confirm"); + setShowSuccessDialog(step === "success"); + + if (step === "confirm") { + setShowSendDialog(true); + } + if (step === "success") { + setShowSendDialog(false); + } + }, [searchParams]); + + const openConfirmDialog = () => { + setShowConfirmDialog(true); + router.push("/send?step=confirm", { scroll: false }); + }; + + const closeConfirmDialog = () => { + setShowConfirmDialog(false); + router.replace("/send", { scroll: false }); + }; + + const openSuccessDialog = () => { + setShowSuccessDialog(true); + router.replace("/send?step=success", { scroll: false }); + }; + + const closeSuccessDialog = () => { + setShowSuccessDialog(false); + router.replace("/send", { scroll: false }); + }; const loadTransfers = useCallback(async () => { setLoadError(""); @@ -251,6 +277,8 @@ export default function SendPage() { refetchBalance(); setShowConfirmDialog(false); setShowSendDialog(false); + setLastSentAmount(amount); + openSuccessDialog(); setLastSentAmount(confirmedAmount); setShowSuccessDialog(true); @@ -526,6 +554,8 @@ export default function SendPage() { {t('send.cancel')}
- {t('send.cancel')} - {sending ? t('send.sending') : t('send.sendAcbu', { amount })} + + Cancel + + + {sending ? 'Sending...' : `Send ACBU ${amount}`} +
- - -
-
- -
-

- {t('send.transferSent')} -

-

- {t('send.transferSentDescription', { amount: formatAmount(lastSentAmount) })} -

- - {t('send.pending')} - -
-
-
- - ); + + { + setShowSuccessDialog(open); + if (!open) { + router.replace("/send", { scroll: false }); + } + }} + > + +
+
+ +
+

+ Transfer Sent! +

+

+ Your transfer for ACBU {formatAmount(lastSentAmount)}{" "} + is being processed. +

+ + Pending + +
+
+
+ + ); }