Skip to content

Commit

Permalink
PRO-2111- Config Changes (#65)
Browse files Browse the repository at this point in the history
* Added txn limit mode and indexer
* Added ponder ignore files
* Changed ponder config
* Added API key formats to all sql operations
* Added default env value
  • Loading branch information
vignesha22 authored Feb 28, 2024
1 parent c02ec09 commit b380f8e
Show file tree
Hide file tree
Showing 33 changed files with 1,196 additions and 117 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ There is an option to run the code locally without using AWS and only using loca
}
} which also needs to be converted into `base64` value

## API KEY VALIDATION
- In ARKA Admin Frontend, create an API_KEY with the following format -
* Min length - 8 Max length - 20
* contains atleast one Special characters out of these - `@$!%*-_&`
* contains atleast one lowercase alphabet
* contains atleast one uppercase alphabet
* contains atleast one digit 0-9


## 🔙 Arka Backend

Expand Down
2 changes: 2 additions & 0 deletions admin_frontend/demo.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_INDEXER_ENDPOINT=http://localhost:3003
REACT_APP_SERVER_URL=http://localhost:5050
50 changes: 25 additions & 25 deletions admin_frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions admin_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.15.3",
"@mui/lab": "^5.0.0-alpha.159",
"@mui/material": "^5.15.3",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.1",
"react-router-dom": "^6.21.1",
"@emotion/react": "11.11.3",
"@emotion/styled": "11.11.0",
"@mui/icons-material": "5.15.3",
"@mui/lab": "5.0.0-alpha.159",
"@mui/material": "5.15.3",
"@testing-library/jest-dom": "5.17.0",
"@testing-library/react": "13.4.0",
"@testing-library/user-event": "13.5.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hot-toast": "2.4.1",
"react-router-dom": "6.21.1",
"react-scripts": "5.0.1",
"styled-components": "^6.1.8",
"web-vitals": "^2.1.4"
"styled-components": "6.1.8",
"web-vitals": "2.1.4"
},
"scripts": {
"start": "PORT=3002 react-scripts start",
Expand All @@ -44,8 +44,8 @@
]
},
"devDependencies": {
"autoprefixer": "^10.4.16",
"postcss": "^8.4.33",
"tailwindcss": "^3.4.1"
"autoprefixer": "10.4.16",
"postcss": "8.4.33",
"tailwindcss": "3.4.1"
}
}
92 changes: 71 additions & 21 deletions admin_frontend/src/components/ApiKeys.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useEffect, useState } from "react";
import AddCircleIcon from "@mui/icons-material/AddCircle";
import RemoveCircleIcon from '@mui/icons-material/RemoveCircle';
import RemoveCircleIcon from "@mui/icons-material/RemoveCircle";
import toast from "react-hot-toast";
// components
import { TextField } from "@mui/material";
import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
Expand All @@ -17,15 +18,22 @@ 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 Checkbox from "@mui/material/Checkbox";

import Header from "./Header";

// constants
import { ENDPOINTS } from "../constants/common";

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 [txnMode, setTxnMode] = useState(0);
const [noOfTxn, setNoOfTxn] = useState(10);
const [showPassword, setShowPassword] = useState(false);

const handleClickShowPassword = () => setShowPassword(!showPassword);
Expand All @@ -34,21 +42,25 @@ const ApiKeysPage = () => {
event.preventDefault();
};

const handleChange = (event) => {
setTxnMode(event.target.checked ? 1 : 0);
};

const fetchData = async () => {
try {
setLoading(true);
const data = await (
await fetch("http://localhost:5050/getKeys", {
await fetch(`${process.env.REACT_APP_SERVER_URL}${ENDPOINTS['getKeys']}`, {
method: "GET",
})
).json();
console.log("data: ", data);
setKeys(data);
setLoading(false);
} catch (err) {
toast.error(
"Check Backend Service for more info"
);
if (err.message.includes("Falied to fetch"))
toast.error("Failed to connect. Please make sure that the backend is running")
else
toast.error(err.message)
}
};

Expand All @@ -61,21 +73,34 @@ const ApiKeysPage = () => {
toast.error("Please input both API_KEY & PRIVATE_KEY field");
return;
}
if (
!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*-_&])[A-Za-z\d@$!%*-_&]{8,}$/.test(
apiKey
)
) {
toast.error(
"Invalid Validation: API_KEY format. Please see the docs for more info"
);
return;
}
try {
setLoading(true);
const requestData = {
API_KEY: apiKey,
PRIVATE_KEY: privateKey,
SUPPORTED_NETWORKS: supportedNetworks ?? "",
ERC20_PAYMASTERS: customErc20Paymaster ?? "",
TRANSACTION_LIMIT: txnMode,
NO_OF_TRANSACTIONS_IN_A_MONTH: noOfTxn,
INDEXER_ENDPOINT:
process.env.REACT_APP_INDEXER_ENDPOINT ?? "http://localhost:3003",
};
const data = await (
await fetch("http://localhost:5050/saveKey", {
method: "POST",
body: JSON.stringify(requestData),
})
).json();
if (!data.error) {
const data = await fetch(`${process.env.REACT_APP_SERVER_URL}${ENDPOINTS['saveKey']}`, {
method: "POST",
body: JSON.stringify(requestData),
});
const dataJson = await data.json();
if (!dataJson.error) {
toast.success("Saved Successfully");
setApiKey("");
setPrivateKey("");
Expand All @@ -85,9 +110,10 @@ const ApiKeysPage = () => {
toast.error("Could not save");
}
} catch (err) {
toast.error(
"Check Backend Service for more info"
);
if (err.message.includes("Falied to fetch"))
toast.error("Failed to connect. Please make sure that the backend is running")
else
toast.error(err.message)
setLoading(false);
}
};
Expand All @@ -96,7 +122,7 @@ const ApiKeysPage = () => {
try {
setLoading(true);
const data = await (
await fetch("http://localhost:5050/deleteKey", {
await fetch(`${process.env.REACT_APP_SERVER_URL}${ENDPOINTS['deleteKey']}`, {
method: "POST",
body: JSON.stringify({ API_KEY: key }),
})
Expand All @@ -109,10 +135,10 @@ const ApiKeysPage = () => {
toast.error("Could not save");
}
} catch (err) {
console.log("err: ", err);
toast.error(
"Check Backend Service for more info"
);
if (err.message.includes("Falied to fetch"))
toast.error("Failed to connect. Please make sure that the backend is running")
else
toast.error(err.message)
setLoading(false);
}
};
Expand All @@ -129,6 +155,8 @@ const ApiKeysPage = () => {
<TableCell>Private Key</TableCell>
<TableCell>Supported Networks</TableCell>
<TableCell>Custom ERC20 Paymasters</TableCell>
<TableCell>Transaction Limit Mode</TableCell>
<TableCell>No of Transactions Allowed</TableCell>
<TableCell>Actions Available</TableCell>
</TableRow>
</TableHead>
Expand Down Expand Up @@ -211,6 +239,24 @@ const ApiKeysPage = () => {
fullWidth
/>
</TableCell>
<TableCell>
<Checkbox
checked={txnMode === 0 ? false : true}
onChange={handleChange}
/>
</TableCell>
<TableCell>
<TextField
type="number"
variant="outlined"
color="secondary"
label="NO_OF_TRANSACTIONS_IN_A_MONTH"
onChange={(e) => setNoOfTxn(e.target.value)}
value={noOfTxn}
required
fullWidth
/>
</TableCell>
<TableCell>
<LoadingButton
loading={loading}
Expand Down Expand Up @@ -249,6 +295,10 @@ const ApiKeysPage = () => {
</TableCell>
<TableCell>{row.SUPPORTED_NETWORKS}</TableCell>
<TableCell>{row.ERC20_PAYMASTERS}</TableCell>
<TableCell>
{row.TRANSACTION_LIMIT === 0 ? "OFF" : "ON"}
</TableCell>
<TableCell>{row.NO_OF_TRANSACTIONS_IN_A_MONTH}</TableCell>
<TableCell>
<LoadingButton
loading={loading}
Expand Down
5 changes: 5 additions & 0 deletions admin_frontend/src/constants/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const ENDPOINTS = {
'getKeys': '/getKeys',
'saveKey' : '/saveKey',
'deleteKey': '/deleteKey',
}
6 changes: 5 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ config.json
database.sqlite

package-lock.json
pnpm-lock.yaml
pnpm-lock.yaml

# Ponder
/indexer/.ponder
/indexer/generated
4 changes: 3 additions & 1 deletion backend/demo.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ API_HOST=127.0.0.1
API_PORT=5050

STACKUP_API_KEY=
SUPPORTED_NETWORKS=
SUPPORTED_NETWORKS=
ADMIN_WALLET_ADDRESS=
DEFAULT_INDEXER_ENDPOINT=http://localhost:3003
3 changes: 3 additions & 0 deletions backend/indexer/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "ponder"
}
21 changes: 21 additions & 0 deletions backend/indexer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Dependencies
/node_modules

# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# Misc
.DS_Store

# Env files
.env*.local

# Ponder
/generated/
/.ponder/

package-lock.json

Loading

0 comments on commit b380f8e

Please sign in to comment.