forked from StellarSend/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfirmModal.tsx
More file actions
133 lines (125 loc) · 4.21 KB
/
Copy pathConfirmModal.tsx
File metadata and controls
133 lines (125 loc) · 4.21 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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 { Quote, SendFormValues } from '@/types'
interface ConfirmModalProps {
isOpen: boolean
onClose: () => void
onConfirm: () => void
quote: Quote
formValues: SendFormValues
isLoading: boolean
step: 'signing' | 'submitting' | 'review'
}
export function ConfirmModal({
isOpen,
onClose,
onConfirm,
quote,
formValues,
isLoading,
step,
}: ConfirmModalProps) {
const stepLabel =
step === 'signing'
? 'Waiting for Freighter signature...'
: step === 'submitting'
? 'Submitting to Stellar network...'
: null
return (
<Modal
isOpen={isOpen}
onClose={isLoading ? undefined : onClose}
title="Confirm Transaction"
description="Review the details below before signing with Freighter."
size="md"
>
<div className="space-y-4">
{/* Shield icon */}
<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>
{/* Amount summary */}
<div className="rounded-xl bg-navy-900/60 border border-navy-700/40 divide-y divide-navy-700/40">
<ConfirmRow label="You Send">
<span className="font-bold text-white tabular-nums">
{formatAmount(quote.sendAmount, 4)} {quote.sourceAsset.code}
</span>
</ConfirmRow>
<ConfirmRow label="They Receive">
<span className="font-bold text-stellar-400 tabular-nums">
{formatAmount(quote.receiveAmount, 4)} {quote.destinationAsset.code}
</span>
</ConfirmRow>
<ConfirmRow label="To">
<span className="font-mono text-sm text-slate-300">
{truncateAddress(formValues.destinationAddress, 8)}
</span>
</ConfirmRow>
<ConfirmRow label="Network Fee">
<span className="text-slate-300">
{formatAmount(quote.networkFee, 7)} XLM
</span>
</ConfirmRow>
{formValues.memo && (
<ConfirmRow label="Memo">
<span className="text-slate-300 font-mono text-sm">
{formValues.memo}
</span>
</ConfirmRow>
)}
</div>
{/* Warning */}
<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">
Stellar transactions are <strong className="text-warning-300">irreversible</strong>.
Double-check the destination address and amount before confirming.
</p>
</div>
{/* Loading state */}
{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 & Send'}
</Button>
</ModalFooter>
</div>
</Modal>
)
}
function ConfirmRow({
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>
)
}