-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConnectionBadge.tsx
119 lines (113 loc) · 3.54 KB
/
ConnectionBadge.tsx
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
import { Button } from "@/components/UI/Button";
import { Card } from "@/components/UI/Card";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuTrigger,
} from "@/components/UI/DropdownMenu";
import { ZOND_PROVIDER } from "@/configuration/zondConfig";
import { useStore } from "@/stores/store";
import { cva } from "class-variance-authority";
import { Check, ChevronDown, HardDrive, Network, Workflow } from "lucide-react";
import { observer } from "mobx-react-lite";
const networkStatusClasses = cva("h-2 w-2 rounded-full", {
variants: {
networkStatus: {
true: ["bg-constructive"],
false: ["bg-destructive"],
},
},
defaultVariants: {
networkStatus: false,
},
});
const blockchainSelectionClasses = cva("cursor-pointer ", {
variants: {
isSelected: {
true: ["text-constructive focus:text-constructive"],
},
},
defaultVariants: {
isSelected: false,
},
});
const ConnectionBadge = observer(() => {
const { zondStore } = useStore();
const { zondConnection, selectBlockchain } = zondStore;
const { isConnected, zondNetworkName } = zondConnection;
const { DEV, TEST_NET, MAIN_NET } = ZOND_PROVIDER;
const [isDevNetwork, isTestNetwork, isMainNetwork] = [
DEV.name === zondNetworkName,
TEST_NET.name === zondNetworkName,
MAIN_NET.name === zondNetworkName,
];
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" className="flex gap-2 rounded-full">
<Card
className={networkStatusClasses({
networkStatus: isConnected,
})}
/>
{zondNetworkName}
<ChevronDown className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56">
<DropdownMenuLabel>Blockchain network</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem
className={blockchainSelectionClasses({
isSelected: isDevNetwork,
})}
onClick={() => selectBlockchain(DEV.id)}
>
<HardDrive className="mr-2 h-4 w-4" />
<span>{DEV.name}</span>
{isDevNetwork && (
<DropdownMenuShortcut>
<Check className="h-4 w-4" />
</DropdownMenuShortcut>
)}
</DropdownMenuItem>
<DropdownMenuItem
className={blockchainSelectionClasses({
isSelected: isTestNetwork,
})}
onClick={() => selectBlockchain(TEST_NET.id)}
>
<Workflow className="mr-2 h-4 w-4" />
<span>{TEST_NET.name}</span>
{isTestNetwork && (
<DropdownMenuShortcut>
<Check className="h-4 w-4" />
</DropdownMenuShortcut>
)}
</DropdownMenuItem>
<DropdownMenuItem
className={blockchainSelectionClasses({
isSelected: isMainNetwork,
})}
onClick={() => selectBlockchain(MAIN_NET.id)}
>
<Network className="mr-2 h-4 w-4" />
<span>{MAIN_NET.name}</span>
{isMainNetwork && (
<DropdownMenuShortcut>
<Check className="h-4 w-4" />
</DropdownMenuShortcut>
)}
</DropdownMenuItem>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
);
});
export default ConnectionBadge;