Skip to content

Commit 41f32da

Browse files
committed
feat: Add CustomSelector component for enhanced item selection, closes #28
1 parent 1bed4e6 commit 41f32da

File tree

2 files changed

+91
-141
lines changed

2 files changed

+91
-141
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function CustomSelector({ onChange, items, selected }) {
2+
return (
3+
<select
4+
id="custom-select"
5+
name="custom-select"
6+
className="flex items-center bg-tychePrimary text-white text-[14px] md:text-[16px] pl-3 pr-12 md:pl-6 py-1 min-h-[50px] rounded-full w-fit focus:outline-none focus:ring-tycheGreen focus:border-tycheGreen appearance-none bg-[url('https://upload.wikimedia.org/wikipedia/commons/9/9d/Caret_down_font_awesome_whitevariation.svg')] bg-no-repeat bg-[right_1rem_center] bg-[length:12px_12px] cursor-pointer"
7+
onChange={onChange}
8+
>
9+
{items.map((item) => {
10+
const [key, value] = Object.entries(item)[0]; // key-value çiftini ayırır
11+
return (
12+
<option key={key} value={key} selected={selected === key}>
13+
{value}
14+
</option>
15+
);
16+
})}
17+
</select>
18+
);
19+
}
20+
21+
export default CustomSelector;

tyche-frontend/src/components/Content/SettingsPopup.jsx

Lines changed: 70 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
deleteAddress,
1515
updateAddress,
1616
} from "../../redux/slices/walletSlice";
17+
import CustomSelector from "./CustomSelector";
18+
import shortenAddress from "../../utils/shortenAddress";
1719

1820
function SettingsPopup({ onClose, preferredTab, newWallet, walletToEdit }) {
1921
const [activeTab, setActiveTab] = useState(preferredTab || "settings");
@@ -47,134 +49,67 @@ function SettingsPopup({ onClose, preferredTab, newWallet, walletToEdit }) {
4749
function GeneralSettings() {
4850
const generalSettings = useSelector((state) => state.settings);
4951
const dispatch = useDispatch();
52+
53+
const handleCurrencyChange = (e) => {
54+
dispatch(
55+
updateSettings({
56+
currency: e.target.value,
57+
timezone: generalSettings.timezone,
58+
})
59+
);
60+
}
61+
62+
const handleTimezoneChange = (e) => {
63+
dispatch(
64+
updateSettings({
65+
currency: generalSettings.currency,
66+
timezone: e.target.value,
67+
})
68+
);
69+
}
5070
return (
5171
<div className="flex flex-col gap-6 md:gap-[45px]">
5272
<div className="flex flex-row gap-2 md:gap-4 items-center">
5373
<p className="flex font-medium text-[16px] md:text-[18px]">Currency:</p>
54-
<select
55-
id="currency"
56-
name="currency"
57-
className="flex items-center bg-tychePrimary text-white text-[14px] md:text-[16px] px-4 md:px-6 py-1 h-[40px] md:h-[50px] rounded-full w-fit focus:outline-none focus:ring-tycheGreen focus:border-tycheGreen"
58-
onChange={(e) =>
59-
dispatch(
60-
updateSettings({
61-
currency: e.target.value,
62-
timezone: generalSettings.timezone,
63-
})
64-
)
65-
}
66-
>
67-
<option selected={generalSettings.currency === "USD"}>USD</option>
68-
<option selected={generalSettings.currency === "EUR"}>EUR</option>
69-
<option selected={generalSettings.currency === "GBP"}>GBP</option>
70-
</select>
74+
<CustomSelector
75+
items={[{ USD: "USD" }, { EUR: "EUR" }, { GBP: "GBP" }]}
76+
selected={generalSettings.currency}
77+
onChange={handleCurrencyChange}
78+
/>
7179
</div>
7280
<div className="flex flex-row gap-2 md:gap-4 items-center">
7381
<p className="flex font-medium text-[16px] md:text-[18px] whitespace-nowrap">
7482
Timezone:
7583
</p>
76-
<select
77-
id="timezone"
78-
name="timezone"
79-
className="flex items-center bg-tychePrimary text-white text-[12px] md:text-[14px] px-2 md:px-4 py-1 h-[40px] md:h-[50px] w-fit max-w-[200px] md:max-w-none rounded-full focus:outline-none focus:ring-tycheGreen focus:border-tycheGreen"
80-
onChange={(e) =>
81-
dispatch(
82-
updateSettings({
83-
currency: generalSettings.currency,
84-
timezone: e.target.value,
85-
})
86-
)
87-
}
88-
>
89-
<option
90-
value="Pacific/Honolulu"
91-
selected={generalSettings.timezone === "Pacific/Honolulu"}
92-
>
93-
Pacific/Honolulu (HST)
94-
</option>
95-
<option
96-
value="America/Anchorage"
97-
selected={generalSettings.timezone === "America/Anchorage"}
98-
>
99-
America/Anchorage (AKST)
100-
</option>
101-
<option
102-
value="America/Los_Angeles"
103-
selected={generalSettings.timezone === "America/Los_Angeles"}
104-
>
105-
America/Los Angeles (PST)
106-
</option>
107-
<option
108-
value="America/Denver"
109-
selected={generalSettings.timezone === "America/Denver"}
110-
>
111-
America/Denver (MST)
112-
</option>
113-
<option
114-
value="America/Chicago"
115-
selected={generalSettings.timezone === "America/Chicago"}
116-
>
117-
America/Chicago (CST)
118-
</option>
119-
<option
120-
value="America/New_York"
121-
selected={generalSettings.timezone === "America/New_York"}
122-
>
123-
America/New York (EST)
124-
</option>
125-
<option
126-
value="Europe/London"
127-
selected={generalSettings.timezone === "Europe/London"}
128-
>
129-
Europe/London (GMT+0)
130-
</option>
131-
<option
132-
value="Europe/Paris"
133-
selected={generalSettings.timezone === "Europe/Paris"}
134-
>
135-
Europe/Paris (CET)
136-
</option>
137-
<option
138-
value="Europe/Berlin"
139-
selected={generalSettings.timezone === "Europe/Berlin"}
140-
>
141-
Europe/Berlin (CET)
142-
</option>
143-
<option
144-
value="Europe/Istanbul"
145-
selected={generalSettings.timezone === "Europe/Istanbul"}
146-
>
147-
Europe/Istanbul (TRT)
148-
</option>
149-
<option selected={generalSettings.timezone === "Europe/Moscow"}>
150-
Europe/Moscow (MSK)
151-
</option>
152-
<option
153-
value="Asia/Dubai"
154-
selected={generalSettings.timezone === "Asia/Dubai"}
155-
>
156-
Asia/Dubai (GST)
157-
</option>
158-
<option
159-
value="Asia/Tokyo"
160-
selected={generalSettings.timezone === "Asia/Tokyo"}
161-
>
162-
Asia/Tokyo (JST)
163-
</option>
164-
<option
165-
value="Australia/Sydney"
166-
selected={generalSettings.timezone === "Australia/Sydney"}
167-
>
168-
Australia/Sydney (AEST)
169-
</option>
170-
</select>
84+
<CustomSelector
85+
items={[
86+
{ "Pacific/Honolulu": "Pacific/Honolulu (HST)" },
87+
{ "America/Anchorage": "America/Anchorage (AKST)" },
88+
{ "America/Los_Angeles": "America/Los Angeles (PST)" },
89+
{ "America/Denver": "America/Denver (MST)" },
90+
{ "America/Chicago": "America/Chicago (CST)" },
91+
{ "America/New_York": "America/New York (EST)" },
92+
{ "Europe/London": "Europe/London (GMT+0)" },
93+
{ "Europe/Paris": "Europe/Paris (CET)" },
94+
{ "Europe/Berlin": "Europe/Berlin (CET)" },
95+
{ "Europe/Istanbul": "Europe/Istanbul (TRT)" },
96+
{ "Europe/Moscow": "Europe/Moscow (MSK)" },
97+
{ "Asia/Dubai": "Asia/Dubai (GST)" },
98+
{ "Asia/Tokyo": "Asia/Tokyo (JST)" },
99+
{ "Australia/Sydney": "Australia/Sydney (AEST)" },
100+
]}
101+
selected={generalSettings.timezone}
102+
onChange={handleTimezoneChange}
103+
/>
171104
</div>
172105
</div>
173106
);
174107
}
175108

109+
110+
176111
function SavedWallets({ newWallet, walletToEdit, onClose }) {
177-
const networks = getSupportedNetworks();
112+
const networks = ["All Networks", ...getSupportedNetworks()];
178113
const [selectedNetwork, setSelectedNetwork] = useState("All Networks");
179114
const [saveWalletButtonClicked, setSaveWalletButtonClicked] = useState(false);
180115
const [editWalletId, setEditWalletId] = useState(null);
@@ -228,38 +163,32 @@ function SavedWallets({ newWallet, walletToEdit, onClose }) {
228163
<>
229164
<div className="flex flex-col h-full">
230165
{/* Network selector */}
231-
<select
232-
id="currency"
233-
name="currency"
234-
className="flex items-center bg-tychePrimary text-white text-[16px] md:text-[20px] py-[13px] w-fit px-[20px] h-[50px] rounded-full focus:outline-none focus:ring-tycheGreen focus:border-tycheGreen mb-4"
166+
<CustomSelector
235167
onChange={handleNetworkChange}
236-
>
237-
<option>All Networks</option>
238-
{networks.map((network) => (
239-
<option key={network} value={network}>
240-
{network}
241-
</option>
242-
))}
243-
</select>
244-
168+
items={networks.map((network) => ({ [network]: network }))}
169+
selected={selectedNetwork}
170+
/>
245171
{/* Table header and content */}
246-
<div className="flex flex-col flex-grow min-h-0">
247-
{addresses.length === 0 ? (
172+
<div className="flex flex-col flex-grow min-h-0 mt-4">
173+
{addresses.filter(
174+
(wallet) =>
175+
selectedNetwork === "All Networks" || wallet.network === selectedNetwork
176+
).length === 0 ? (
248177
<p className="flex font-bold text-[16px] md:text-[20px] w-full justify-center">
249178
There is no saved address!
250179
</p>
251180
) : (
252181
<div className="hidden md:flex flex-row gap-4 items-center w-full px-6 mb-4">
253-
<p className="flex font-bold text-[16px] md:text-[18px] w-[200px]">
182+
<p className="flex font-bold text-[16px] md:text-[18px] w-full">
254183
Address
255184
</p>
256-
<p className="flex font-bold text-[16px] md:text-[18px] w-[200px]">
185+
<p className="flex font-bold text-[16px] md:text-[18px] w-full">
257186
Tag
258187
</p>
259-
<p className="flex font-bold text-[16px] md:text-[18px] w-[200px]">
188+
<p className="flex font-bold text-[16px] md:text-[18px] w-full">
260189
Network
261190
</p>
262-
<p className="flex font-bold text-[16px] md:text-[18px] w-[100px] justify-end">
191+
<p className="flex font-bold text-[16px] md:text-[18px] w-full justify-end">
263192
Operations
264193
</p>
265194
</div>
@@ -287,19 +216,19 @@ function SavedWallets({ newWallet, walletToEdit, onClose }) {
287216
key={index}
288217
className="flex flex-col md:flex-row gap-3 items-start md:items-center w-full rounded-[25px] p-4 md:px-6 bg-white"
289218
>
290-
<div className="flex flex-col w-full md:w-[200px]">
219+
<div className="flex flex-col w-full">
291220
<span className="text-[14px] font-bold md:hidden">
292221
Address:
293222
</span>
294223
<span
295224
className="text-[14px] md:text-[16px] text-tycheDarkBlue break-words md:truncate cursor-pointer hover:underline"
296225
onClick={handleAddressClick(wallet)}
297226
>
298-
{wallet.address}
227+
{shortenAddress(wallet.address)}
299228
</span>
300229
</div>
301230

302-
<div className="flex flex-col w-full md:w-[200px]">
231+
<div className="flex flex-col w-full">
303232
<span className="text-[14px] font-bold md:hidden">
304233
Tag:
305234
</span>
@@ -308,7 +237,7 @@ function SavedWallets({ newWallet, walletToEdit, onClose }) {
308237
</span>
309238
</div>
310239

311-
<div className="flex flex-col w-full md:w-[200px]">
240+
<div className="flex flex-col w-full">
312241
<span className="text-[14px] font-bold md:hidden">
313242
Network:
314243
</span>
@@ -317,15 +246,15 @@ function SavedWallets({ newWallet, walletToEdit, onClose }) {
317246
</span>
318247
</div>
319248

320-
<div className="flex flex-row gap-4 w-full md:w-[100px] justify-end md:justify-end mt-2 md:mt-0">
249+
<div className="flex flex-row gap-4 w-full justify-end md:justify-end mt-2 md:mt-0">
321250
<button
322251
className="p-2 hover:bg-gray-100 rounded-full"
323252
onClick={() => handleEditWallet(wallet)}
324253
>
325254
<img
326255
src={tagEditIcon}
327256
alt="Edit"
328-
className="w-5 h-5 md:w-6 md:h-6"
257+
className="max-w-5 max-h-5 min-w-5 min-h-5 md:max-w-6 md:max-h-6 md:min-w-6 md:min-h-6"
329258
/>
330259
</button>
331260
<button
@@ -335,7 +264,7 @@ function SavedWallets({ newWallet, walletToEdit, onClose }) {
335264
<img
336265
src={tagDeleteIcon}
337266
alt="Delete"
338-
className="w-5 h-5 md:w-6 md:h-6"
267+
className="max-w-5 max-h-5 min-w-5 min-h-5 md:max-w-6 md:max-h-6 md:min-w-6 md:min-h-6"
339268
/>
340269
</button>
341270
</div>
@@ -512,7 +441,7 @@ function AddOrEditWallet({ wallet, onSave, onCancel }) {
512441
<img
513442
src={tagConfirmIcon}
514443
alt="Confirm"
515-
className="w-5 h-5 md:w-6 md:h-6"
444+
className="max-w-5 max-h-5 min-w-5 min-h-5 md:max-w-6 md:max-h-6 md:min-w-6 md:min-h-6"
516445
/>
517446
</button>
518447
<button
@@ -522,7 +451,7 @@ function AddOrEditWallet({ wallet, onSave, onCancel }) {
522451
<img
523452
src={tagCancelIcon}
524453
alt="Cancel"
525-
className="w-5 h-5 md:w-6 md:h-6"
454+
className="max-w-5 max-h-5 min-w-5 min-h-5 md:max-w-6 md:max-h-6 md:min-w-6 md:min-h-6"
526455
/>
527456
</button>
528457
</div>

0 commit comments

Comments
 (0)