forked from StellarSend/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfirmSubscriptionModal.tsx
More file actions
119 lines (110 loc) · 4.01 KB
/
Copy pathConfirmSubscriptionModal.tsx
File metadata and controls
119 lines (110 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React from 'react'
import { ShieldCheck, AlertTriangle, Loader2 } from 'lucide-react'
import { Modal, ModalFooter } from '@/components/ui/Modal'
import { Button } from '@/components/ui/Button'
import { truncateAddress, formatAmount } from '@/lib/stellar'
import type { SubscriptionFormValues } from '@/types'
interface ConfirmSubscriptionModalProps {
isOpen: boolean
onClose: () => void
onConfirm: () => void
formValues: SubscriptionFormValues
isLoading: boolean
step: 'signing' | 'submitting' | 'review'
}
const intervalLabel: Record<SubscriptionFormValues['interval'], string> = {
daily: 'Every day',
weekly: 'Every week',
monthly: 'Every month',
yearly: 'Every year',
}
export function ConfirmSubscriptionModal({
isOpen,
onClose,
onConfirm,
formValues,
isLoading,
step,
}: ConfirmSubscriptionModalProps) {
const stepLabel =
step === 'signing'
? 'Waiting for Freighter signature...'
: step === 'submitting'
? 'Registering schedule...'
: null
return (
<Modal
isOpen={isOpen}
onClose={isLoading ? undefined : onClose}
title="Confirm Recurring Payment"
description="Review the schedule below before signing with Freighter."
size="md"
>
<div className="space-y-4">
<div className="flex justify-center">
<div className="w-14 h-14 rounded-2xl bg-stellar-gradient flex items-center justify-center shadow-glow">
<ShieldCheck size={28} className="text-white" />
</div>
</div>
<div className="rounded-xl bg-navy-900/60 border border-navy-700/40 divide-y divide-navy-700/40">
<Row label="Amount">
<span className="font-bold text-white tabular-nums">
{formatAmount(formValues.amount, 4)} {formValues.assetCode}
</span>
</Row>
<Row label="Frequency">
<span className="text-slate-200">{intervalLabel[formValues.interval]}</span>
</Row>
<Row label="Starts">
<span className="text-slate-200">{formValues.startDate}</span>
</Row>
<Row label="To">
<span className="font-mono text-sm text-slate-300">
{truncateAddress(formValues.destinationAddress, 8)}
</span>
</Row>
{formValues.memo && (
<Row label="Memo">
<span className="text-slate-300 font-mono text-sm">{formValues.memo}</span>
</Row>
)}
</div>
<div className="flex items-start gap-2.5 p-3.5 rounded-xl bg-warning-500/8 border border-warning-500/20">
<AlertTriangle size={15} className="text-warning-400 mt-0.5 shrink-0" />
<p className="text-xs text-slate-400 leading-relaxed">
You authorize this schedule with your own wallet. You can{' '}
<strong className="text-warning-300">cancel it any time</strong> from the
Subscriptions page.
</p>
</div>
{isLoading && stepLabel && (
<div className="flex items-center gap-3 p-3.5 rounded-xl bg-stellar-500/10 border border-stellar-500/20">
<Loader2 size={16} className="text-stellar-400 animate-spin shrink-0" />
<p className="text-sm text-stellar-300">{stepLabel}</p>
</div>
)}
<ModalFooter>
<Button variant="secondary" onClick={onClose} disabled={isLoading}>
Cancel
</Button>
<Button
loading={isLoading}
onClick={onConfirm}
disabled={isLoading}
icon={<ShieldCheck size={15} />}
>
{isLoading ? stepLabel?.split('...')[0] || 'Processing' : 'Sign & Create'}
</Button>
</ModalFooter>
</div>
</Modal>
)
}
function Row({ label, children }: { label: string; children: React.ReactNode }) {
return (
<div className="flex items-center justify-between px-4 py-3 gap-3">
<span className="text-sm text-slate-400 shrink-0">{label}</span>
<div className="text-right">{children}</div>
</div>
)
}