forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkPill.tsx
More file actions
57 lines (49 loc) · 1.55 KB
/
Copy pathNetworkPill.tsx
File metadata and controls
57 lines (49 loc) · 1.55 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
import React from "react";
import { Icon } from "@stellar/design-system";
import { useWallet } from "../hooks/useWallet";
import { stellarNetwork } from "../lib/env";
// Format network name with first letter capitalized
const formatNetworkName = (name: string) =>
// TODO: This is a workaround until @creit-tech/stellar-wallets-kit uses the new name for a local network.
name === "STANDALONE"
? "Local"
: name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
const appNetwork = formatNetworkName(stellarNetwork);
const bgColor = "#F0F2F5";
const textColor = "#4A5362";
const NetworkPill: React.FC = () => {
const { network, address } = useWallet();
// Check if there's a network mismatch
const walletNetwork = formatNetworkName(network ?? "");
const isNetworkMismatch = walletNetwork !== appNetwork;
let title = "";
let color = "#2ED06E";
if (!address) {
title = "Connect your wallet using this network.";
color = "#C1C7D0";
} else if (isNetworkMismatch) {
title = `Wallet is on ${walletNetwork}, connect to ${appNetwork} instead.`;
color = "#FF3B30";
}
return (
<div
style={{
backgroundColor: bgColor,
color: textColor,
padding: "4px 10px",
borderRadius: "16px",
fontSize: "12px",
fontWeight: "bold",
display: "flex",
alignItems: "center",
gap: "4px",
cursor: isNetworkMismatch ? "help" : "default",
}}
title={title}
>
<Icon.Circle color={color} />
{appNetwork}
</div>
);
};
export default NetworkPill;