-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathactivity.tsx
More file actions
70 lines (66 loc) · 2.84 KB
/
activity.tsx
File metadata and controls
70 lines (66 loc) · 2.84 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
import { useEffect, useState } from "react";
import { type Transfers, useWallet } from "@crossmint/client-sdk-react-ui";
import { shortenAddress } from "@/lib/utils";
export function Activity() {
const { wallet } = useWallet();
const [activity, setActivity] = useState<Transfers | null>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
async function fetchActivity() {
if (wallet == null) {
return;
}
setLoading(true);
try {
const activity = await wallet.transfers({ tokens: "eth", status: "successful" });
setActivity(activity);
} catch (error) {
console.error("Error fetching wallet activity:", error);
alert("Error fetching wallet activity: " + error);
} finally {
setLoading(false);
}
}
fetchActivity();
}, [wallet]);
return (
<div className="bg-white flex flex-col gap-3 rounded-xl border shadow-sm p-5" data-testid="activity-section">
<div>
<h2 className="text-lg font-medium">Recent activity</h2>
<p className="text-sm text-gray-500">View your recent activity</p>
</div>
<div
className="flex flex-col gap-2.5 max-h-[300px] overflow-y-auto border-t border-gray-100"
data-testid="activity-events-container"
>
{loading ? (
<div className="text-gray-500 text-center" data-testid="activity-loading">
Loading...
</div>
) : !activity || activity.events.length === 0 ? (
<div className="text-gray-500 text-center" data-testid="activity-empty">
No recent activity
</div>
) : (
activity.events.map((event, idx) => (
<div
key={`${event.transaction_hash}-${idx}`}
data-testid={`activity-event-${idx}`}
className="flex justify-between items-center py-2.5 border-t border-gray-100 first:border-t-0"
>
<div>
<div className="font-medium">
{event.amount} {event.token_symbol}
</div>
<div className="text-xs text-gray-500">
From: {shortenAddress(event.from_address)} → To: {shortenAddress(event.to_address)}
</div>
</div>
</div>
))
)}
</div>
</div>
);
}
export default Activity;