forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWalletModal.tsx
More file actions
177 lines (163 loc) · 5.45 KB
/
Copy pathWalletModal.tsx
File metadata and controls
177 lines (163 loc) · 5.45 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
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { Loader2, X, ExternalLink, CheckCircle2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { useWallet } from "@/hooks/useWallet";
interface WalletOption {
id: string;
name: string;
icon: string;
descriptionKey: string;
installUrl?: string;
}
// Wallet names are proper nouns/brand names and are intentionally not translated.
const WALLET_OPTIONS: WalletOption[] = [
{
id: "freighter",
name: "Freighter",
icon: "🦊",
descriptionKey: "wallet.modal.wallets.freighter",
installUrl: "https://freighter.app",
},
{
id: "xbull",
name: "xBull",
icon: "🐂",
descriptionKey: "wallet.modal.wallets.xbull",
installUrl: "https://xbull.app",
},
{
id: "albedo",
name: "Albedo",
icon: "🌌",
descriptionKey: "wallet.modal.wallets.albedo",
installUrl: "https://albedo.link",
},
{
id: "lobstr",
name: "Lobstr",
icon: "🦞",
descriptionKey: "wallet.modal.wallets.lobstr",
installUrl: "https://lobstr.co",
},
{
id: "rabet",
name: "Rabet",
icon: "🐰",
descriptionKey: "wallet.modal.wallets.rabet",
installUrl: "https://rabet.io",
},
];
const E2E_WALLET: WalletOption = {
id: "e2e-mock",
name: "E2E Mock Wallet",
icon: "🧪",
description: "Deterministic local wallet for browser tests",
};
interface WalletModalProps {
isOpen: boolean;
onClose: () => void;
}
export function WalletModal({ isOpen, onClose }: WalletModalProps) {
const { t } = useTranslation();
const { connect, status, error } = useWallet();
const [connectingId, setConnectingId] = useState<string | null>(null);
const [connectionError, setConnectionError] = useState<string | null>(null);
if (!isOpen) return null;
const options =
import.meta.env.DEV &&
new URLSearchParams(window.location.search).get("e2e") === "1"
? [E2E_WALLET, ...WALLET_OPTIONS]
: WALLET_OPTIONS;
const handleConnect = async (walletId: string) => {
setConnectingId(walletId);
setConnectionError(null);
try {
await connect(walletId);
onClose();
} catch (err) {
const message = err instanceof Error ? err.message : t("wallet.modal.connection_failed");
setConnectionError(message);
} finally {
setConnectingId(null);
}
};
return (
<div
role="dialog"
aria-modal="true"
aria-labelledby="modal-title"
className="fixed inset-0 bg-slate-950/80 backdrop-blur-sm flex items-center justify-center z-50"
>
<div className="bg-slate-900 border border-white/10 rounded-2xl p-6 shadow-2xl max-w-md w-full mx-4 relative">
{/* Header */}
<div className="flex items-center justify-between mb-6">
<div>
<h2 id="modal-title" className="text-xl font-bold text-white">
{t("wallet.modal.title")}
</h2>
<p className="text-sm text-slate-400 mt-1">
{t("wallet.modal.subtitle")}
</p>
</div>
<button
onClick={onClose}
aria-label={t("wallet.modal.close")}
className="text-slate-400 hover:text-white transition-colors p-1 rounded-lg hover:bg-white/10"
>
<X className="w-5 h-5" />
</button>
</div>
{/* Error message */}
{(connectionError || (status === "error" && error)) && (
<div className="mb-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-sm">
{connectionError || error}
</div>
)}
{/* Wallet options */}
<div className="space-y-2">
{options.map((wallet) => {
const isConnecting = connectingId === wallet.id;
return (
<button
key={wallet.id}
onClick={() => void handleConnect(wallet.id)}
disabled={connectingId !== null}
className="w-full flex items-center gap-4 p-4 rounded-xl border border-white/10 bg-white/5 hover:bg-white/10 hover:border-white/20 transition-all disabled:opacity-50 disabled:cursor-not-allowed group"
>
<span className="text-2xl">{wallet.icon}</span>
<div className="flex-1 text-left">
<div className="font-medium text-white group-hover:text-amber-300 transition-colors">
{wallet.name}
</div>
<div className="text-xs text-slate-400">
{t(wallet.descriptionKey)}
</div>
</div>
{isConnecting ? (
<Loader2 className="w-5 h-5 animate-spin text-amber-400" />
) : (
<ExternalLink className="w-4 h-4 text-slate-500 opacity-0 group-hover:opacity-100 transition-opacity" />
)}
</button>
);
})}
</div>
{/* Footer */}
<div className="mt-6 pt-4 border-t border-white/10">
<p className="text-xs text-slate-500 text-center">
{t("wallet.modal.new_to_stellar")}{" "}
<a
href="https://stellar.org/learn/keys"
target="_blank"
rel="noopener noreferrer"
className="text-amber-400 hover:text-amber-300 transition-colors"
>
{t("wallet.modal.learn_about_wallets")}
</a>
</p>
</div>
</div>
</div>
);
}