|
| 1 | +import { useEffect, useState } from "react"; |
| 2 | +import { useStore } from "../store"; |
| 3 | + |
| 4 | +export function Settings() { |
| 5 | + const [listenAddress, setListenAddress] = useState(""); |
| 6 | + |
| 7 | + const walletshieldListenAddress = useStore( |
| 8 | + (s) => s.walletshieldListenAddress, |
| 9 | + ); |
| 10 | + |
| 11 | + const setMessage = useStore((s) => s.setMessage); |
| 12 | + const setWalletshieldListenAddress = useStore( |
| 13 | + (s) => s.setWalletshieldListenAddress, |
| 14 | + ); |
| 15 | + |
| 16 | + useEffect(() => { |
| 17 | + setListenAddress(walletshieldListenAddress); |
| 18 | + }, []); |
| 19 | + |
| 20 | + const handleReset = () => { |
| 21 | + setListenAddress(""); |
| 22 | + setWalletshieldListenAddress(""); |
| 23 | + setMessage("success", "Settings reset to default."); |
| 24 | + }; |
| 25 | + |
| 26 | + const handleApply = () => { |
| 27 | + setWalletshieldListenAddress(listenAddress); |
| 28 | + setMessage("success", "Settings saved."); |
| 29 | + }; |
| 30 | + |
| 31 | + return ( |
| 32 | + <div className="flex flex-col items-center h-full"> |
| 33 | + <form |
| 34 | + onSubmit={(e) => { |
| 35 | + e.preventDefault(); |
| 36 | + handleApply(); |
| 37 | + }} |
| 38 | + > |
| 39 | + <fieldset className="fieldset w-xs bg-base-200 border border-base-300 p-4 rounded-box"> |
| 40 | + <legend className="fieldset-legend">Walletshield</legend> |
| 41 | + |
| 42 | + <label className="fieldset-label">Listen Address & Port</label> |
| 43 | + <input |
| 44 | + type="text" |
| 45 | + className="input validator" |
| 46 | + placeholder=":7070" |
| 47 | + value={listenAddress} |
| 48 | + onChange={(e) => setListenAddress(e.target.value)} |
| 49 | + pattern="^((\d{1,3}\.){3}\d{1,3}|[a-zA-Z0-9.-]+)?:(\d{1,5})$" |
| 50 | + required |
| 51 | + /> |
| 52 | + <p className="fieldset-label"> |
| 53 | + Where the Walletshield listens for connections. |
| 54 | + </p> |
| 55 | + </fieldset> |
| 56 | + <div className="flex w-full h-full gap-4 p-4"> |
| 57 | + <div className="tooltip flex-1" data-tip="Restore Defaults"> |
| 58 | + <button |
| 59 | + type="button" |
| 60 | + className="btn btn-secondary w-full" |
| 61 | + onClick={handleReset} |
| 62 | + > |
| 63 | + Reset |
| 64 | + </button> |
| 65 | + </div> |
| 66 | + <div className="tooltip flex-1" data-tip="Save Settings"> |
| 67 | + <button type="submit" className="btn btn-primary w-full"> |
| 68 | + Apply |
| 69 | + </button> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + </form> |
| 73 | + </div> |
| 74 | + ); |
| 75 | +} |
0 commit comments