-
Notifications
You must be signed in to change notification settings - Fork 6
Add gift card transfer flow #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gudnuf
wants to merge
1
commit into
add-buy-transfer-types
Choose a base branch
from
gift-card-add-funds
base: add-buy-transfer-types
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import { MoneyDisplay } from '~/components/money-display'; | ||
| import { | ||
| PageBackButton, | ||
| PageContent, | ||
| PageFooter, | ||
| PageHeader, | ||
| PageHeaderTitle, | ||
| } from '~/components/page'; | ||
| import { Button } from '~/components/ui/button'; | ||
| import { Card, CardContent } from '~/components/ui/card'; | ||
| import { MoneyWithConvertedAmount } from '~/features/shared/money-with-converted-amount'; | ||
| import { useToast } from '~/hooks/use-toast'; | ||
| import { useNavigateWithViewTransition } from '~/lib/transitions'; | ||
| import { useAccount } from '../accounts/account-hooks'; | ||
| import { getDefaultUnit } from '../shared/currencies'; | ||
| import { DomainError } from '../shared/error'; | ||
| import { useInitiateTransfer } from './transfer-hooks'; | ||
| import { useTransferStore } from './transfer-provider'; | ||
| import type { TransferQuote } from './transfer-service'; | ||
|
|
||
| const ConfirmationRow = ({ | ||
| label, | ||
| value, | ||
| }: { label: string; value: React.ReactNode }) => { | ||
| return ( | ||
| <div className="flex items-center justify-between"> | ||
| <p className="text-muted-foreground">{label}</p> | ||
| <div>{value}</div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| type TransferConfirmationProps = { | ||
| transferQuote: TransferQuote; | ||
| }; | ||
|
|
||
| export default function TransferConfirmation({ | ||
| transferQuote, | ||
| }: TransferConfirmationProps) { | ||
| const { toast } = useToast(); | ||
| const navigate = useNavigateWithViewTransition(); | ||
|
|
||
| const destinationAccountId = useTransferStore((s) => s.destinationAccountId); | ||
| const sourceAccountId = useTransferStore((s) => s.sourceAccountId); | ||
|
|
||
| const destinationAccount = useAccount(destinationAccountId); | ||
| const sourceAccount = useAccount(sourceAccountId); | ||
|
|
||
| const { mutate: initiateTransfer, status: transferStatus } = | ||
| useInitiateTransfer({ | ||
| onSuccess: ({ receiveTransactionId }) => { | ||
| const params = new URLSearchParams({ | ||
| showOkButton: 'true', | ||
| redirectTo: `/gift-cards/${destinationAccount.id}`, | ||
| }); | ||
| navigate( | ||
| { | ||
| pathname: `/transactions/${receiveTransactionId}`, | ||
| search: params.toString(), | ||
| }, | ||
| { | ||
| transition: 'slideLeft', | ||
| applyTo: 'newView', | ||
| }, | ||
| ); | ||
| }, | ||
| onError: (error) => { | ||
| if (error instanceof DomainError) { | ||
| toast({ description: error.message }); | ||
| } else { | ||
| console.error('Failed to initiate transfer', { cause: error }); | ||
| toast({ | ||
| description: 'Transfer failed. Please try again.', | ||
| variant: 'destructive', | ||
| }); | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| const handleConfirm = () => { | ||
| initiateTransfer({ | ||
| sourceAccount, | ||
| destinationAccount, | ||
| transferQuote, | ||
| }); | ||
| }; | ||
|
|
||
| const isPending = ['pending', 'success'].includes(transferStatus); | ||
|
|
||
| return ( | ||
| <> | ||
| <PageHeader className="z-10"> | ||
| <PageBackButton to=".." transition="slideRight" applyTo="oldView" /> | ||
| <PageHeaderTitle>Confirm</PageHeaderTitle> | ||
| </PageHeader> | ||
| <PageContent className="flex flex-col items-center gap-4"> | ||
| <MoneyWithConvertedAmount money={transferQuote.estimatedTotal} /> | ||
| <div className="absolute top-0 right-0 bottom-0 left-0 mx-auto flex max-w-sm items-center justify-center"> | ||
| <Card className="m-4 w-full"> | ||
| <CardContent className="flex flex-col gap-6 pt-6"> | ||
| <ConfirmationRow | ||
| label="Amount" | ||
| value={ | ||
| <MoneyDisplay | ||
| size="sm" | ||
| money={transferQuote.amount} | ||
| unit={getDefaultUnit(transferQuote.amount.currency)} | ||
| /> | ||
| } | ||
| /> | ||
| <ConfirmationRow | ||
| label="Estimated fee" | ||
| value={ | ||
| <MoneyDisplay | ||
| size="sm" | ||
| money={transferQuote.estimatedFee} | ||
| unit={getDefaultUnit(transferQuote.estimatedFee.currency)} | ||
| /> | ||
| } | ||
| /> | ||
| <ConfirmationRow label="From" value={sourceAccount.name} /> | ||
| <ConfirmationRow label="To" value={destinationAccount.name} /> | ||
| </CardContent> | ||
| </Card> | ||
| </div> | ||
| </PageContent> | ||
| <PageFooter className="pb-14"> | ||
| <Button onClick={handleConfirm} loading={isPending}> | ||
| Confirm | ||
| </Button> | ||
| </PageFooter> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { useMutation } from '@tanstack/react-query'; | ||
| import type { Money } from '~/lib/money'; | ||
| import type { Account } from '../accounts/account'; | ||
| import { ConcurrencyError, DomainError } from '../shared/error'; | ||
| import { useUser } from '../user/user-hooks'; | ||
| import type { TransferQuote } from './transfer-service'; | ||
| import { useTransferService } from './transfer-service'; | ||
|
|
||
| export function useCreateTransferQuote() { | ||
| const transferService = useTransferService(); | ||
|
|
||
| return useMutation({ | ||
| scope: { id: 'create-transfer-quote' }, | ||
| mutationFn: ({ | ||
| sourceAccount, | ||
| destinationAccount, | ||
| amount, | ||
| }: { | ||
| sourceAccount: Account; | ||
| destinationAccount: Account; | ||
| amount: Money; | ||
| }) => | ||
| transferService.getTransferQuote({ | ||
| sourceAccount, | ||
| destinationAccount, | ||
| amount, | ||
| }), | ||
| retry: (failureCount, error) => { | ||
| if (error instanceof DomainError) return false; | ||
| return failureCount < 1; | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export function useInitiateTransfer({ | ||
| onSuccess, | ||
| onError, | ||
| }: { | ||
| onSuccess: (data: { | ||
| sendTransactionId: string; | ||
| receiveTransactionId: string; | ||
| }) => void; | ||
| onError: (error: Error) => void; | ||
| }) { | ||
| const userId = useUser((user) => user.id); | ||
| const transferService = useTransferService(); | ||
|
|
||
| return useMutation({ | ||
| scope: { id: 'initiate-transfer' }, | ||
| mutationFn: ({ | ||
| sourceAccount, | ||
| destinationAccount, | ||
| transferQuote, | ||
| }: { | ||
| sourceAccount: Account; | ||
| destinationAccount: Account; | ||
| transferQuote: TransferQuote; | ||
| }) => | ||
| transferService.initiateTransfer({ | ||
| userId, | ||
| sourceAccount, | ||
| destinationAccount, | ||
| transferQuote, | ||
| }), | ||
| onSuccess: (data) => { | ||
| onSuccess({ | ||
| sendTransactionId: data.sendTransactionId, | ||
| receiveTransactionId: data.receiveTransactionId, | ||
| }); | ||
| }, | ||
| onError, | ||
| retry: (failureCount, error) => { | ||
| if (error instanceof ConcurrencyError) return true; | ||
| if (error instanceof DomainError) return false; | ||
| return failureCount < 1; | ||
| }, | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@claude this redirectTo should not have been removed. We still want to reidrect back when the transfer is completed
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude finished @gudnuf's task in 54s —— View job
Restored
redirectToon gift card transfer linkredirectToparameterThe "Add" button's link was missing the
redirectTosearch param. Restored it usingbuildLinkWithSearchParams(same pattern as the "Send" button), so navigating back after transfer completion works correctly.Commit: 46c27c4