forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment-status.tsx
More file actions
207 lines (189 loc) · 5.95 KB
/
Copy pathpayment-status.tsx
File metadata and controls
207 lines (189 loc) · 5.95 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
"use client"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { Separator } from "@/components/ui/separator"
import { CheckCircle, ExternalLink, Copy, Clock, AlertCircle } from "lucide-react"
import { useToast } from "@/hooks/use-toast"
interface PaymentStatusProps {
status: 'pending' | 'confirmed' | 'failed'
txHash?: string
amount: number
token: string
timestamp?: Date
confirmations?: number
requiredConfirmations?: number
}
export function PaymentStatus({
status,
txHash,
amount,
token,
timestamp,
confirmations = 0,
requiredConfirmations = 3
}: PaymentStatusProps) {
const { toast } = useToast()
const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text)
toast({
title: "Copied",
description: "Transaction hash copied to clipboard",
})
}
const openExplorer = () => {
if (txHash) {
// Base explorer URL (adjust for network)
const explorerUrl = `https://basescan.org/tx/${txHash}`
window.open(explorerUrl, '_blank')
}
}
const getStatusColor = () => {
switch (status) {
case 'confirmed':
return 'bg-green-500'
case 'pending':
return 'bg-yellow-500'
case 'failed':
return 'bg-red-500'
default:
return 'bg-gray-500'
}
}
const getStatusIcon = () => {
switch (status) {
case 'confirmed':
return <CheckCircle className="h-5 w-5 text-green-500" />
case 'pending':
return <Clock className="h-5 w-5 text-yellow-500" />
case 'failed':
return <AlertCircle className="h-5 w-5 text-red-500" />
default:
return <Clock className="h-5 w-5 text-gray-500" />
}
}
const getStatusText = () => {
switch (status) {
case 'confirmed':
return 'Payment Confirmed'
case 'pending':
return 'Payment Pending'
case 'failed':
return 'Payment Failed'
default:
return 'Unknown Status'
}
}
return (
<Card className="nm-flat">
<CardHeader>
<CardTitle className="flex items-center justify-between">
<div className="flex items-center space-x-2">
{getStatusIcon()}
<span>{getStatusText()}</span>
</div>
<Badge
variant="secondary"
className={`${getStatusColor()} text-white`}
>
{status.toUpperCase()}
</Badge>
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
{/* Payment Details */}
<div className="nm-flat p-4 rounded-lg space-y-3">
<div className="flex justify-between">
<span className="text-muted-foreground">Amount:</span>
<span className="font-bold text-primary">
{amount.toFixed(6)} {token}
</span>
</div>
{timestamp && (
<div className="flex justify-between">
<span className="text-muted-foreground">Time:</span>
<span className="text-foreground">
{timestamp.toLocaleString()}
</span>
</div>
)}
{status === 'pending' && (
<div className="flex justify-between">
<span className="text-muted-foreground">Confirmations:</span>
<span className="text-foreground">
{confirmations}/{requiredConfirmations}
</span>
</div>
)}
</div>
{/* Transaction Hash */}
{txHash && (
<div className="space-y-2">
<label className="text-sm font-medium text-muted-foreground">
Transaction Hash
</label>
<div className="flex items-center space-x-2 nm-flat p-3 rounded-lg">
<code className="flex-1 text-xs font-mono break-all text-foreground">
{txHash}
</code>
<Button
variant="ghost"
size="sm"
onClick={() => copyToClipboard(txHash)}
className="h-8 w-8 p-0"
>
<Copy className="h-3 w-3" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={openExplorer}
className="h-8 w-8 p-0"
>
<ExternalLink className="h-3 w-3" />
</Button>
</div>
</div>
)}
<Separator />
{/* Status Messages */}
<div className="text-sm">
{status === 'confirmed' && (
<div className="text-green-600 bg-green-50 p-3 rounded-lg">
✅ Payment has been confirmed on the blockchain. The invoice has been marked as paid.
</div>
)}
{status === 'pending' && (
<div className="text-yellow-600 bg-yellow-50 p-3 rounded-lg">
⏳ Payment is being processed. Please wait for blockchain confirmation.
</div>
)}
{status === 'failed' && (
<div className="text-red-600 bg-red-50 p-3 rounded-lg">
❌ Payment failed. Please try again or contact support.
</div>
)}
</div>
{/* Action Buttons */}
{status === 'confirmed' && (
<div className="flex space-x-2">
<Button variant="default" className="flex-1">
<CheckCircle className="h-4 w-4 mr-2" />
Mark Invoice as Paid
</Button>
</div>
)}
{status === 'failed' && (
<div className="flex space-x-2">
<Button variant="default" className="flex-1">
Retry Payment
</Button>
<Button variant="outline" className="flex-1">
Contact Support
</Button>
</div>
)}
</CardContent>
</Card>
)
}