From 390dafb6096b215e0f2df7f9dbf987b623169d6a Mon Sep 17 00:00:00 2001 From: gudnuf Date: Fri, 30 Jan 2026 14:04:48 -0800 Subject: [PATCH] refactor how we use the redirectTo param --- app/features/gift-cards/gift-card-details.tsx | 4 +- app/features/receive/index.ts | 15 ++- app/features/receive/receive-cashu-token.tsx | 19 ++-- app/features/receive/receive-cashu.tsx | 25 ++--- app/features/receive/receive-flow.tsx | 93 ++++++++++++++++++ app/features/receive/receive-input.tsx | 40 ++++---- app/features/receive/receive-spark.tsx | 25 ++--- app/features/receive/scan.tsx | 15 +-- app/features/send/send-confirmation.tsx | 46 +++++++-- app/features/send/send-input.tsx | 12 ++- app/features/send/send-scanner.tsx | 12 ++- app/features/send/share-cashu-token.tsx | 10 +- .../transactions/transaction-details.tsx | 8 +- app/hooks/use-redirect-to.ts | 72 ++++++++++++++ app/lib/transitions/view-transition.tsx | 4 +- .../_protected.receive.cashu_.token.tsx | 3 +- app/routes/_protected.receive.tsx | 94 ++++++++++++++++++- app/routes/_protected.send.share.$swapId.tsx | 22 ++++- ...protected.transactions.$transactionId_.tsx | 12 +-- app/routes/_public.mint-risks.tsx | 9 +- app/routes/_public.privacy.tsx | 9 +- app/routes/_public.terms.tsx | 9 +- 22 files changed, 432 insertions(+), 126 deletions(-) create mode 100644 app/features/receive/receive-flow.tsx create mode 100644 app/hooks/use-redirect-to.ts diff --git a/app/features/gift-cards/gift-card-details.tsx b/app/features/gift-cards/gift-card-details.tsx index ed9f20d7f..fb762f029 100644 --- a/app/features/gift-cards/gift-card-details.tsx +++ b/app/features/gift-cards/gift-card-details.tsx @@ -150,14 +150,14 @@ export default function GiftCardDetails({ cardId }: GiftCardDetailsProps) {
diff --git a/app/features/receive/index.ts b/app/features/receive/index.ts index ebb28b96b..a24bce744 100644 --- a/app/features/receive/index.ts +++ b/app/features/receive/index.ts @@ -1,6 +1,19 @@ import ReceiveCashu from './receive-cashu'; import ReceiveCashuToken from './receive-cashu-token'; +import { + type ReceiveFlowDefinition, + ReceiveFlowProvider, + useReceiveFlowStep, +} from './receive-flow'; import ReceiveInput from './receive-input'; import { ReceiveProvider } from './receive-provider'; -export { ReceiveInput, ReceiveCashuToken, ReceiveCashu, ReceiveProvider }; +export { + ReceiveInput, + ReceiveCashuToken, + ReceiveCashu, + ReceiveProvider, + ReceiveFlowProvider, + useReceiveFlowStep, +}; +export type { ReceiveFlowDefinition }; diff --git a/app/features/receive/receive-cashu-token.tsx b/app/features/receive/receive-cashu-token.tsx index bf351eb8a..e969c239a 100644 --- a/app/features/receive/receive-cashu-token.tsx +++ b/app/features/receive/receive-cashu-token.tsx @@ -21,10 +21,7 @@ import { Button } from '~/components/ui/button'; import { useToast } from '~/hooks/use-toast'; import { useFeatureFlag } from '~/lib/feature-flags'; import type { Currency } from '~/lib/money'; -import { - LinkWithViewTransition, - useNavigateWithViewTransition, -} from '~/lib/transitions'; +import { LinkWithViewTransition } from '~/lib/transitions'; import { AccountSelector } from '../accounts/account-selector'; import { GiftCardItem } from '../gift-cards/gift-card-item'; import { getGiftCardImageByUrl } from '../gift-cards/use-discover-cards'; @@ -45,6 +42,7 @@ import { type ReceiveCashuTokenAccount, isClaimingToSameCashuAccount, } from './receive-cashu-token-models'; +import { useReceiveFlowStep } from './receive-flow'; type Props = { token: Token; @@ -104,7 +102,7 @@ export default function ReceiveToken({ preferredReceiveAccountId, }: Props) { const { toast } = useToast(); - const navigate = useNavigateWithViewTransition(); + const { back, onSuccess } = useReceiveFlowStep('claimCashuToken'); const { claimableToken, cannotClaimReason } = useCashuTokenWithClaimableProofs({ token }); const { @@ -160,10 +158,7 @@ export default function ReceiveToken({ return result.lightningReceiveQuote.transactionId; }, onSuccess: (transactionId) => { - navigate(`/transactions/${transactionId}?redirectTo=/`, { - transition: 'slideLeft', - applyTo: 'newView', - }); + onSuccess(transactionId); }, onError: (error) => { console.error('Error claiming token', { cause: error }); @@ -179,9 +174,9 @@ export default function ReceiveToken({ <> Receive diff --git a/app/features/receive/receive-cashu.tsx b/app/features/receive/receive-cashu.tsx index 6e0987f98..16d50f833 100644 --- a/app/features/receive/receive-cashu.tsx +++ b/app/features/receive/receive-cashu.tsx @@ -15,10 +15,7 @@ import type { CashuAccount } from '~/features/accounts/account'; import { useEffectNoStrictMode } from '~/hooks/use-effect-no-strict-mode'; import { useToast } from '~/hooks/use-toast'; import type { Money } from '~/lib/money'; -import { - LinkWithViewTransition, - useNavigateWithViewTransition, -} from '~/lib/transitions'; +import { LinkWithViewTransition } from '~/lib/transitions'; import { getDefaultUnit } from '../shared/currencies'; import { MoneyWithConvertedAmount } from '../shared/money-with-converted-amount'; import type { CashuReceiveQuote } from './cashu-receive-quote'; @@ -26,6 +23,7 @@ import { useCashuReceiveQuote, useCreateCashuReceiveQuote, } from './cashu-receive-quote-hooks'; +import { useReceiveFlowStep } from './receive-flow'; type CreateQuoteProps = { account: CashuAccount; @@ -110,16 +108,13 @@ export default function ReceiveCashu({ amount, account }: Props) { const [showOk, setShowOk] = useState(false); const [, copyToClipboard] = useCopyToClipboard(); const { toast } = useToast(); - const navigate = useNavigateWithViewTransition(); + const { back, onSuccess } = useReceiveFlowStep('cashuLightningInvoice'); const { quote, errorMessage, isLoading } = useCreateQuote({ account, amount, onPaid: (quote) => { - navigate(`/transactions/${quote.transactionId}?redirectTo=/`, { - transition: 'fade', - applyTo: 'newView', - }); + onSuccess(quote.transactionId); }, }); @@ -141,9 +136,9 @@ export default function ReceiveCashu({ amount, account }: Props) { <> Receive Ecash @@ -172,9 +167,9 @@ export default function ReceiveCashu({ amount, account }: Props) { diff --git a/app/features/receive/receive-spark.tsx b/app/features/receive/receive-spark.tsx index f94b4d626..1b883a640 100644 --- a/app/features/receive/receive-spark.tsx +++ b/app/features/receive/receive-spark.tsx @@ -12,12 +12,10 @@ import { Button } from '~/components/ui/button'; import { useEffectNoStrictMode } from '~/hooks/use-effect-no-strict-mode'; import { useToast } from '~/hooks/use-toast'; import type { Money } from '~/lib/money'; -import { - LinkWithViewTransition, - useNavigateWithViewTransition, -} from '~/lib/transitions'; +import { LinkWithViewTransition } from '~/lib/transitions'; import type { SparkAccount } from '../accounts/account'; import { MoneyWithConvertedAmount } from '../shared/money-with-converted-amount'; +import { useReceiveFlowStep } from './receive-flow'; import type { SparkReceiveQuote } from './spark-receive-quote'; import { useCreateSparkReceiveQuote, @@ -68,19 +66,16 @@ const useCreateQuote = ({ }; export default function ReceiveSpark({ amount, account }: Props) { - const navigate = useNavigateWithViewTransition(); const [showOk, setShowOk] = useState(false); const [, copyToClipboard] = useCopyToClipboard(); const { toast } = useToast(); + const { back, onSuccess } = useReceiveFlowStep('sparkLightningInvoice'); const { quote, errorMessage, isLoading } = useCreateQuote({ account, amount, onPaid: (quote) => { - navigate(`/transactions/${quote.transactionId}?redirectTo=/`, { - transition: 'fade', - applyTo: 'newView', - }); + onSuccess(quote.transactionId); }, }); @@ -98,9 +93,9 @@ export default function ReceiveSpark({ amount, account }: Props) { <> Receive @@ -118,9 +113,9 @@ export default function ReceiveSpark({ amount, account }: Props) { diff --git a/app/features/send/send-scanner.tsx b/app/features/send/send-scanner.tsx index 34d328eed..bebe24775 100644 --- a/app/features/send/send-scanner.tsx +++ b/app/features/send/send-scanner.tsx @@ -6,6 +6,7 @@ import { } from '~/components/page'; import { QRScanner } from '~/components/qr-scanner'; import { useExchangeRate } from '~/hooks/use-exchange-rate'; +import { useRedirectTo } from '~/hooks/use-redirect-to'; import { useToast } from '~/hooks/use-toast'; import type { Money } from '~/lib/money'; import { useNavigateWithViewTransition } from '~/lib/transitions/view-transition'; @@ -35,6 +36,7 @@ const useConverter = (sendAccount: Account) => { export default function SendScanner() { const { toast } = useToast(); const navigate = useNavigateWithViewTransition(); + const { buildTo } = useRedirectTo('/'); const sendAccount = useSendStore((state) => state.getSourceAccount()); const selectDestination = useSendStore((state) => state.selectDestination); @@ -57,7 +59,7 @@ export default function SendScanner() { if (!amount) { // Navigate to send input to enter the amount - return navigate('/send', { + return navigate(buildTo('/send'), { applyTo: 'oldView', transition: 'slideDown', }); @@ -75,7 +77,7 @@ export default function SendScanner() { }); } - navigate('/send/confirm', { + navigate(buildTo('/send/confirm'), { applyTo: 'newView', transition: 'slideUp', }); @@ -84,7 +86,11 @@ export default function SendScanner() { return ( <> - + Scan diff --git a/app/features/send/share-cashu-token.tsx b/app/features/send/share-cashu-token.tsx index a1c999431..84fdb5115 100644 --- a/app/features/send/share-cashu-token.tsx +++ b/app/features/send/share-cashu-token.tsx @@ -20,6 +20,7 @@ import { CarouselItem, } from '~/components/ui/carousel'; import useLocationData from '~/hooks/use-location'; +import { useRedirectTo } from '~/hooks/use-redirect-to'; import { useToast } from '~/hooks/use-toast'; import { canShare, shareContent } from '~/lib/share'; import { LinkWithViewTransition } from '~/lib/transitions'; @@ -33,6 +34,7 @@ type Props = { export function ShareCashuToken({ token }: Props) { const { toast } = useToast(); const { origin } = useLocationData(); + const { redirectTo } = useRedirectTo('/'); const [, copyToClipboard] = useCopyToClipboard(); const amount = tokenToMoney(token); const [showOk, setShowOk] = useState(false); @@ -45,7 +47,11 @@ export function ShareCashuToken({ token }: Props) { return ( - + Send {canShare() && ( @@ -110,7 +116,7 @@ export function ShareCashuToken({ token }: Props) {