forked from StellarSend/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEscrowItem.tsx
More file actions
116 lines (110 loc) · 3.82 KB
/
Copy pathEscrowItem.tsx
File metadata and controls
116 lines (110 loc) · 3.82 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
import React from 'react'
import { Lock, Unlock, RotateCcw, Clock, Scale } from 'lucide-react'
import { Badge } from '@/components/ui/Badge'
import { Button } from '@/components/ui/Button'
import { truncateAddress, formatAmount } from '@/lib/stellar'
import { formatDateTime } from '@/lib/utils'
import { getEscrowPermissions } from '@/types'
import type { Escrow } from '@/types'
interface EscrowItemProps {
escrow: Escrow
currentPublicKey: string | null
onRelease: (id: string) => void
onRefund: (id: string) => void
isReleasing?: boolean
isRefunding?: boolean
now?: Date
}
const statusVariant: Record<Escrow['status'], 'success' | 'neutral' | 'danger' | 'warning'> = {
funded: 'warning',
released: 'success',
refunded: 'neutral',
cancelled: 'danger',
}
const roleLabel: Record<string, string> = {
depositor: 'Depositor',
beneficiary: 'Beneficiary',
arbiter: 'Arbiter',
}
export function EscrowItem({
escrow,
currentPublicKey,
onRelease,
onRefund,
isReleasing,
isRefunding,
now,
}: EscrowItemProps) {
const { canRelease, canRefund, role } = getEscrowPermissions(escrow, currentPublicKey, now)
const unlocked = new Date(escrow.unlockTime).getTime() <= (now ?? new Date()).getTime()
return (
<div className="py-4 border-b border-navy-700/40 last:border-0">
<div className="flex items-start justify-between gap-4">
<div className="flex items-center gap-3 min-w-0">
<div className="w-9 h-9 rounded-xl bg-stellar-500/10 border border-stellar-500/20 flex items-center justify-center shrink-0">
<Lock size={15} className="text-stellar-400" />
</div>
<div className="min-w-0">
<div className="flex items-center gap-2 flex-wrap">
<p className="text-sm font-semibold text-white truncate">
{formatAmount(escrow.amount, 4)} {escrow.assetCode}
</p>
<Badge variant={statusVariant[escrow.status]} size="xs">
{escrow.status}
</Badge>
{role && (
<Badge variant="info" size="xs">
You: {roleLabel[role]}
</Badge>
)}
</div>
<p className="text-xs text-slate-400 font-mono truncate">
beneficiary {truncateAddress(escrow.beneficiaryPublicKey, 6)}
{escrow.arbiterPublicKey && (
<>
{' '}
· arbiter {truncateAddress(escrow.arbiterPublicKey, 6)}
</>
)}
</p>
<p className="text-[11px] text-slate-500 flex items-center gap-1 mt-0.5">
<Clock size={10} />
{unlocked ? 'Unlocked since' : 'Unlocks'} {formatDateTime(escrow.unlockTime)}
</p>
</div>
</div>
<div className="flex items-center gap-1.5 shrink-0">
{canRelease && (
<Button
variant="secondary"
size="xs"
icon={<Unlock size={13} />}
loading={isReleasing}
onClick={() => onRelease(escrow.id)}
>
Release
</Button>
)}
{canRefund && (
<Button
variant="ghost"
size="xs"
icon={<RotateCcw size={13} />}
loading={isRefunding}
onClick={() => onRefund(escrow.id)}
className="text-warning-400 hover:text-warning-300 hover:bg-warning-500/10"
>
Refund
</Button>
)}
{role === 'depositor' && !unlocked && escrow.status === 'funded' && (
<span className="flex items-center gap-1 text-[11px] text-slate-500">
<Scale size={11} />
Refund available after unlock
</span>
)}
</div>
</div>
</div>
)
}