forked from FlowwStar/FlowStar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-confirmation.tsx
More file actions
181 lines (170 loc) · 5.8 KB
/
Copy pathcreate-confirmation.tsx
File metadata and controls
181 lines (170 loc) · 5.8 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
"use client";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Info } from "lucide-react";
import {
formatDateTime,
formatTokenAmount,
formatRate,
shortenAddress,
} from "@/lib/stream-utils";
import { calculateFeeBreakdown, TYPICAL_FEES } from "@/lib/fee-utils";
import { useTokenPrice } from "@/hooks/use-token-price";
import type { TokenInfo } from "@/types/stream";
interface ConfirmationProps {
open: boolean;
onConfirm: () => void;
onCancel: () => void;
pending: boolean;
feeEstimate?: string | null;
recipient: string;
token: TokenInfo;
totalAmount: bigint;
startTime: bigint;
endTime: bigint;
cliffTime: bigint;
cliffAmount: bigint;
amountPerSecond: bigint;
}
function Row({ label, value }: { label: string; value: React.ReactNode }) {
return (
<div className="flex items-start justify-between gap-4 py-2 border-b border-border last:border-0">
<span className="text-sm text-muted-foreground shrink-0">{label}</span>
<span className="text-sm text-right font-medium">{value}</span>
</div>
);
}
export function CreateConfirmation({
open,
onConfirm,
onCancel,
pending,
feeEstimate,
recipient,
token,
totalAmount,
startTime,
endTime,
cliffTime,
cliffAmount,
amountPerSecond,
}: ConfirmationProps) {
const rate = formatRate(amountPerSecond, token.decimals, token.symbol);
// Fetch live XLM/USD price for fee USD estimate
const { usdPrice: xlmPrice } = useTokenPrice("XLM");
// Calculate fee breakdown if estimate is available
const estimatedFeeStroops = feeEstimate
? Math.ceil(parseFloat(feeEstimate) * 1e7)
: TYPICAL_FEES.createStream.typical;
const feeBreakdown = calculateFeeBreakdown(
estimatedFeeStroops,
xlmPrice ?? undefined,
);
return (
<Dialog open={open} onOpenChange={(o) => !o && !pending && onCancel()}>
<DialogContent className="sm:max-w-md max-h-[90vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>Confirm stream creation</DialogTitle>
<DialogDescription>
Review the details below. You'll sign two transactions: one
token approval, then stream creation.
</DialogDescription>
</DialogHeader>
<div className="mt-2 space-y-4">
<div>
<h3 className="text-xs font-medium text-muted-foreground uppercase tracking-wide mb-3">
Stream details
</h3>
<Row
label="Recipient"
value={
<span className="font-mono">
{shortenAddress(recipient, 8)}
</span>
}
/>
<Row label="Token" value={token.symbol} />
<Row
label="Total amount"
value={`${formatTokenAmount(totalAmount, token.decimals, 4)} ${token.symbol}`}
/>
<Row label="Rate" value={rate.perDay} />
<Row label="Start" value={formatDateTime(startTime)} />
<Row label="End" value={formatDateTime(endTime)} />
{cliffTime > startTime && (
<Row
label="Cliff"
value={
<>
{formatDateTime(cliffTime)}
{cliffAmount > 0n && (
<span className="text-muted-foreground ml-1">
(+{formatTokenAmount(cliffAmount, token.decimals, 4)}{" "}
{token.symbol})
</span>
)}
</>
}
/>
)}
</div>
{/* Fee breakdown section */}
<div className="border-t border-border pt-3 space-y-3">
<h3 className="text-xs font-medium text-muted-foreground uppercase tracking-wide">
Network fees
</h3>
<div className="space-y-2">
<Row
label="Base fee estimate"
value={
<span className="font-mono">
{(feeBreakdown.minFee / 1e7).toFixed(7)} XLM
</span>
}
/>
{feeBreakdown.bufferFee > 0 && (
<Row
label="Safety buffer (15%)"
value={
<span className="font-mono">
{(feeBreakdown.bufferFee / 1e7).toFixed(7)} XLM
</span>
}
/>
)}
<div className="flex items-start justify-between gap-4 border-t border-border bg-secondary/30 px-3 py-2 rounded">
<span className="text-sm font-medium text-foreground">
Total estimated
</span>
<span className="text-sm font-mono font-bold text-primary">
{(feeBreakdown.totalEstimated / 1e7).toFixed(7)} XLM
</span>
</div>
</div>
<div className="flex items-start gap-2 rounded-lg bg-blue-500/10 border border-blue-500/30 p-2.5">
<Info className="size-4 shrink-0 text-blue-600 dark:text-blue-400 mt-0.5" />
<p className="text-xs text-blue-700 dark:text-blue-400 leading-relaxed">
Fees are estimated from transaction simulation. Actual costs may
vary based on network conditions.
</p>
</div>
</div>
</div>
<div className="flex justify-end gap-2 pt-4">
<Button variant="ghost" onClick={onCancel} disabled={pending}>
Back
</Button>
<Button onClick={onConfirm} disabled={pending}>
{pending ? "Creating…" : "Confirm & sign"}
</Button>
</div>
</DialogContent>
</Dialog>
);
}