-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added unsafe mode env and its functionalities * updated readme file
- Loading branch information
1 parent
ace6bcf
commit 32fb3a0
Showing
27 changed files
with
864 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
import { useEffect, useState } from "react"; | ||
import AddCircleIcon from "@mui/icons-material/AddCircle"; | ||
import RemoveCircleIcon from '@mui/icons-material/RemoveCircle'; | ||
import toast from "react-hot-toast"; | ||
import { TextField } from "@mui/material"; | ||
import Table from "@mui/material/Table"; | ||
import TableBody from "@mui/material/TableBody"; | ||
import TableCell from "@mui/material/TableCell"; | ||
import TableContainer from "@mui/material/TableContainer"; | ||
import TableHead from "@mui/material/TableHead"; | ||
import TableRow from "@mui/material/TableRow"; | ||
import LoadingButton from "@mui/lab/LoadingButton"; | ||
import InputAdornment from "@mui/material/InputAdornment"; | ||
import Visibility from "@mui/icons-material/Visibility"; | ||
import VisibilityOff from "@mui/icons-material/VisibilityOff"; | ||
import IconButton from "@mui/material/IconButton"; | ||
import OutlinedInput from "@mui/material/OutlinedInput"; | ||
import FormControl from "@mui/material/FormControl"; | ||
import InputLabel from "@mui/material/InputLabel"; | ||
import Header from "./Header"; | ||
|
||
const ApiKeysPage = () => { | ||
const [keys, setKeys] = useState([]); | ||
const [loading, setLoading] = useState(false); | ||
const [apiKey, setApiKey] = useState(""); | ||
const [privateKey, setPrivateKey] = useState(""); | ||
const [supportedNetworks, setSupportedNetworks] = useState(""); | ||
const [customErc20Paymaster, setCustomErc20Paymaster] = useState(""); | ||
const [showPassword, setShowPassword] = useState(false); | ||
|
||
const handleClickShowPassword = () => setShowPassword(!showPassword); | ||
|
||
const handleMouseDownPassword = (event) => { | ||
event.preventDefault(); | ||
}; | ||
|
||
const fetchData = async () => { | ||
try { | ||
setLoading(true); | ||
const data = await ( | ||
await fetch("http://localhost:5050/getKeys", { | ||
method: "GET", | ||
}) | ||
).json(); | ||
console.log("data: ", data); | ||
setKeys(data); | ||
setLoading(false); | ||
} catch (err) { | ||
toast.error( | ||
"Check Backend Service for more info" | ||
); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchData(); | ||
}, []); | ||
|
||
const handleSubmit = async () => { | ||
if (apiKey === "" || privateKey === "") { | ||
toast.error("Please input both API_KEY & PRIVATE_KEY field"); | ||
return; | ||
} | ||
try { | ||
setLoading(true); | ||
const requestData = { | ||
API_KEY: apiKey, | ||
PRIVATE_KEY: privateKey, | ||
SUPPORTED_NETWORKS: supportedNetworks ?? "", | ||
ERC20_PAYMASTERS: customErc20Paymaster ?? "", | ||
}; | ||
const data = await ( | ||
await fetch("http://localhost:5050/saveKey", { | ||
method: "POST", | ||
body: JSON.stringify(requestData), | ||
}) | ||
).json(); | ||
if (!data.error) { | ||
toast.success("Saved Successfully"); | ||
setApiKey(""); | ||
setPrivateKey(""); | ||
fetchData(); | ||
} else { | ||
setLoading(false); | ||
toast.error("Could not save"); | ||
} | ||
} catch (err) { | ||
toast.error( | ||
"Check Backend Service for more info" | ||
); | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const handleDelete = async (key) => { | ||
try { | ||
setLoading(true); | ||
const data = await ( | ||
await fetch("http://localhost:5050/deleteKey", { | ||
method: "POST", | ||
body: JSON.stringify({ API_KEY: key }), | ||
}) | ||
).json(); | ||
if (!data.error) { | ||
toast.success("Deleted Successfully"); | ||
fetchData(); | ||
} else { | ||
setLoading(false); | ||
toast.error("Could not save"); | ||
} | ||
} catch (err) { | ||
console.log("err: ", err); | ||
toast.error( | ||
"Check Backend Service for more info" | ||
); | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Header className="align-center" text="Arka Admin Api Keys" /> | ||
<TableContainer> | ||
<Table aria-label="simple table" stickyHeader> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>Wallet Address</TableCell> | ||
<TableCell>Api Key</TableCell> | ||
<TableCell>Private Key</TableCell> | ||
<TableCell>Supported Networks</TableCell> | ||
<TableCell>Custom ERC20 Paymasters</TableCell> | ||
<TableCell>Actions Available</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
<TableRow> | ||
<TableCell> | ||
<TextField | ||
type="text" | ||
variant="outlined" | ||
color="secondary" | ||
label="WALLET_ADDRESS" | ||
value={"AutoFill"} | ||
multiline | ||
disabled | ||
/> | ||
</TableCell> | ||
<TableCell> | ||
<TextField | ||
type="text" | ||
variant="outlined" | ||
color="secondary" | ||
label="API_KEY" | ||
onChange={(e) => setApiKey(e.target.value)} | ||
value={apiKey} | ||
required | ||
multiline | ||
fullWidth | ||
/> | ||
</TableCell> | ||
<TableCell> | ||
<FormControl variant="outlined" required fullWidth> | ||
<InputLabel htmlFor="outlined-adornment-password"> | ||
PRIVATE_KEY | ||
</InputLabel> | ||
<OutlinedInput | ||
id="outlined-adornment-password" | ||
type={showPassword ? "text" : "password"} | ||
endAdornment={ | ||
<InputAdornment position="end"> | ||
<IconButton | ||
aria-label="toggle password visibility" | ||
onClick={handleClickShowPassword} | ||
onMouseDown={handleMouseDownPassword} | ||
edge="end" | ||
> | ||
{showPassword ? <VisibilityOff /> : <Visibility />} | ||
</IconButton> | ||
</InputAdornment> | ||
} | ||
label="PRIVATE_KEY" | ||
multiline | ||
value={privateKey} | ||
onChange={(e) => setPrivateKey(e.target.value)} | ||
/> | ||
</FormControl> | ||
</TableCell> | ||
<TableCell> | ||
<TextField | ||
type="text" | ||
variant="outlined" | ||
color="secondary" | ||
label="SUPPORTED_NETWORKS" | ||
onChange={(e) => setSupportedNetworks(e.target.value)} | ||
value={supportedNetworks} | ||
required | ||
multiline | ||
fullWidth | ||
/> | ||
</TableCell> | ||
<TableCell> | ||
<TextField | ||
type="text" | ||
variant="outlined" | ||
color="secondary" | ||
label="ERC20_PAYMASTERS" | ||
onChange={(e) => setCustomErc20Paymaster(e.target.value)} | ||
value={customErc20Paymaster} | ||
required | ||
multiline | ||
fullWidth | ||
/> | ||
</TableCell> | ||
<TableCell> | ||
<LoadingButton | ||
loading={loading} | ||
disabled={loading} | ||
loadingPosition="start" | ||
startIcon={<AddCircleIcon />} | ||
variant="contained" | ||
onClick={() => { | ||
handleSubmit(); | ||
}} | ||
> | ||
Add Row | ||
</LoadingButton> | ||
</TableCell> | ||
</TableRow> | ||
{keys.map((row) => ( | ||
<TableRow key={row.API_KEY}> | ||
<TableCell>{row.WALLET_ADDRESS}</TableCell> | ||
<TableCell>{row.API_KEY}</TableCell> | ||
<TableCell> | ||
<div className="flex flex-row"> | ||
<div>{showPassword ? row.PRIVATE_KEY : "*****"} </div> | ||
<div> | ||
<InputAdornment position="end"> | ||
<IconButton | ||
aria-label="toggle password visibility" | ||
onClick={handleClickShowPassword} | ||
onMouseDown={handleMouseDownPassword} | ||
edge="end" | ||
> | ||
{showPassword ? <VisibilityOff /> : <Visibility />} | ||
</IconButton> | ||
</InputAdornment> | ||
</div> | ||
</div> | ||
</TableCell> | ||
<TableCell>{row.SUPPORTED_NETWORKS}</TableCell> | ||
<TableCell>{row.ERC20_PAYMASTERS}</TableCell> | ||
<TableCell> | ||
<LoadingButton | ||
loading={loading} | ||
disabled={loading} | ||
loadingPosition="start" | ||
startIcon={<RemoveCircleIcon />} | ||
variant="contained" | ||
onClick={() => { | ||
handleDelete(row.API_KEY); | ||
}} | ||
> | ||
Delete Row | ||
</LoadingButton> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
</> | ||
); | ||
}; | ||
|
||
export default ApiKeysPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
NODE_ENV=development | ||
LOG_LEVEL=debug | ||
UNSAFE_MODE=false | ||
|
||
API_HOST=127.0.0.1 | ||
API_PORT=5050 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.