Transfer Review
A controlled review of recipient, quoted amounts, fees, arrival, and transfer actions with busy and error states.
Install
First install? Set up the registry in your app.
npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add transfer-reviewSource files
Expand a file to read the source the installer copies into your app.
components/blocks/transfer-review/TransferReview.tsx
import * as React from 'react'
import { View, type ViewProps } from 'react-native'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { Button, type ButtonProps } from '@/components/ui/button'
import { Separator } from '@/components/ui/separator'
import { Text } from '@/components/ui/text'
import { useAnnouncement } from '@/lib/accessibility'
import { cn } from '@/lib/utils'
const defaultLabels = {
recipient: 'Recipient',
amount: 'Recipient receives',
fee: 'Transfer fee',
total: 'Total you pay',
arrival: 'Expected arrival',
unavailable: 'Unavailable',
edit: 'Edit transfer',
confirm: 'Confirm transfer',
confirming: 'Confirming…',
}
export interface TransferReviewProps extends ViewProps {
className?: string
recipient: string
/** A non-sensitive identifier, such as an account suffix. */
recipientDetail?: string
/** Localized values from the caller's quote. */
amount: string
fee: string
total: string
arrival: string
busy?: boolean
/** A quote error blocks Confirm while leaving Edit available. */
error?: string
labels?: Partial<typeof defaultLabels>
/** Compose TransferReviewEdit to inherit the busy state. */
editAction?: React.ReactNode
/** Compose TransferReviewConfirm to inherit quote validity and the busy state. */
confirmAction?: React.ReactNode
}
const ReviewContext = React.createContext<{
busy: boolean
canConfirm: boolean
copy: typeof defaultLabels
} | null>(null)
export function TransferReview({
className,
recipient,
recipientDetail,
amount,
fee,
total,
arrival,
busy = false,
error,
labels,
editAction,
confirmAction,
...props
}: TransferReviewProps) {
const copy = { ...defaultLabels, ...labels }
const hasQuote = [recipient, amount, fee, total, arrival].every((value) => value.trim().length > 0)
const canConfirm = hasQuote && !error && !busy
useAnnouncement(error && !busy ? error : undefined)
return (
<ReviewContext.Provider value={{ busy, canConfirm, copy }}>
<View {...props} className={cn('gap-4', className)}>
<View className="gap-4 rounded-2xl border border-border bg-card p-5">
<View className="gap-1">
<Text size="sm" variant="muted">
{copy.recipient}
</Text>
<Text size="lg" className="font-semibold">
{recipient.trim() || copy.unavailable}
</Text>
{recipientDetail ? (
<Text size="sm" variant="muted">
{recipientDetail}
</Text>
) : null}
</View>
<Separator />
<View className="gap-1">
<Text size="sm" variant="muted">
{copy.amount}
</Text>
<Text size="title" style={{ fontVariant: ['tabular-nums'] }}>
{amount.trim() || copy.unavailable}
</Text>
</View>
</View>
<View className="gap-3 rounded-2xl border border-border bg-card p-4">
<View className="flex-row flex-wrap items-baseline justify-between gap-x-4 gap-y-1">
<Text size="sm" variant="muted">
{copy.fee}
</Text>
<Text size="sm" style={{ fontVariant: ['tabular-nums'] }}>
{fee.trim() || copy.unavailable}
</Text>
</View>
<View className="flex-row flex-wrap items-baseline justify-between gap-x-4 gap-y-1">
<Text size="sm" variant="muted">
{copy.arrival}
</Text>
<Text size="sm" className="shrink">
{arrival.trim() || copy.unavailable}
</Text>
</View>
<Separator />
<View className="flex-row flex-wrap items-baseline justify-between gap-x-4 gap-y-1">
<Text className="font-semibold">{copy.total}</Text>
<Text className="font-semibold" style={{ fontVariant: ['tabular-nums'] }}>
{total.trim() || copy.unavailable}
</Text>
</View>
</View>
{error && !busy ? (
<Alert variant="destructive">
<AlertDescription>{error}</AlertDescription>
</Alert>
) : null}
{confirmAction || editAction ? (
<View className="gap-2">
{confirmAction}
{editAction}
</View>
) : null}
</View>
</ReviewContext.Provider>
)
}
export interface TransferReviewActionProps extends Omit<ButtonProps, 'children' | 'loading' | 'onPress'> {
label?: string
onPress: NonNullable<ButtonProps['onPress']>
}
function ReviewAction({
kind,
label,
disabled,
accessibilityLabel,
onPress,
...props
}: TransferReviewActionProps & { kind: 'confirm' | 'edit' }) {
const review = React.useContext(ReviewContext)
if (!review) throw new Error('Transfer review actions must be inside TransferReview')
const confirmed = kind === 'confirm'
const blocked = !!disabled || (confirmed ? !review.canConfirm : review.busy)
const loading = confirmed && review.busy
const text = loading ? review.copy.confirming : (label ?? (confirmed ? review.copy.confirm : review.copy.edit))
return (
<Button
variant={confirmed ? 'default' : 'outline'}
{...props}
disabled={blocked && !loading}
loading={loading}
accessibilityLabel={loading ? text : (accessibilityLabel ?? text)}
onPress={(event) => {
if (!blocked) onPress(event)
}}
>
{text}
</Button>
)
}
export function TransferReviewEdit(props: TransferReviewActionProps) {
return <ReviewAction kind="edit" {...props} />
}
export function TransferReviewConfirm(props: TransferReviewActionProps) {
return <ReviewAction kind="confirm" {...props} />
}
components/blocks/transfer-review/index.ts
export {
TransferReview,
TransferReviewConfirm,
TransferReviewEdit,
type TransferReviewActionProps,
type TransferReviewProps,
} from './TransferReview'