Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRO-2111- Config Changes #65

Merged
merged 14 commits into from
Feb 28, 2024
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": "0.1.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"
}
}
59 changes: 30 additions & 29 deletions admin_frontend/src/components/ApiKeys.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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";
import { TextField } from "@mui/material";
import Table from "@mui/material/Table";
Expand All @@ -17,7 +17,7 @@ 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 Checkbox from "@mui/material/Checkbox";
import Header from "./Header";

const ApiKeysPage = () => {
Expand All @@ -38,8 +38,8 @@ const ApiKeysPage = () => {
};

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

const fetchData = async () => {
try {
Expand All @@ -49,13 +49,10 @@ const ApiKeysPage = () => {
method: "GET",
})
).json();
console.log("data: ", data);
setKeys(data);
setLoading(false);
} catch (err) {
toast.error(
"Check Backend Service for more info"
);
toast.error("Check Backend Service for more info");
vignesha22 marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand All @@ -68,8 +65,14 @@ 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");
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 {
Expand All @@ -80,16 +83,16 @@ const ApiKeysPage = () => {
SUPPORTED_NETWORKS: supportedNetworks ?? "",
ERC20_PAYMASTERS: customErc20Paymaster ?? "",
TRANSACTION_LIMIT: txnMode,
NO_OF_TRANSACTIONS_IN_A_MONTH: noOfTxn,
INDEXER_ENDPOINT: 'http://localhost:3003'
NO_OF_TRANSACTIONS_IN_A_MONTH: noOfTxn,
INDEXER_ENDPOINT:
process.env.REACT_APP_INDEXER_ENDPOINT ?? "http://localhost:3003",
vignesha22 marked this conversation as resolved.
Show resolved Hide resolved
};
const data = await (
await fetch("http://localhost:5050/saveKey", {
method: "POST",
body: JSON.stringify(requestData),
})
).json();
if (!data.error) {
const data = await fetch("http://localhost:5050/saveKey", {
vignesha22 marked this conversation as resolved.
Show resolved Hide resolved
method: "POST",
body: JSON.stringify(requestData),
});
const dataJson = await data.json();
vignesha22 marked this conversation as resolved.
Show resolved Hide resolved
if (!dataJson.error) {
toast.success("Saved Successfully");
setApiKey("");
setPrivateKey("");
Expand All @@ -99,9 +102,7 @@ const ApiKeysPage = () => {
toast.error("Could not save");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give extra instructions to what the user should do next?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have to see the logs on backend on what's causing the error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I give that on the toast?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toast is okay, but for now you can just ask them to check their details and try again, or contact the support team.

}
} catch (err) {
toast.error(
"Check Backend Service for more info"
);
toast.error("Check Backend Service for more info");
vignesha22 marked this conversation as resolved.
Show resolved Hide resolved
setLoading(false);
}
};
Expand All @@ -124,9 +125,7 @@ const ApiKeysPage = () => {
}
} catch (err) {
console.log("err: ", err);
toast.error(
"Check Backend Service for more info"
);
toast.error("Check Backend Service for more info");
vignesha22 marked this conversation as resolved.
Show resolved Hide resolved
setLoading(false);
}
};
Expand Down Expand Up @@ -229,13 +228,13 @@ const ApiKeysPage = () => {
</TableCell>
<TableCell>
<Checkbox
checked={txnMode === 0? false : true}
checked={txnMode === 0 ? false : true}
onChange={handleChange}
inputProps={{ 'aria-label': 'controlled' }}
inputProps={{ "aria-label": "controlled" }}
vignesha22 marked this conversation as resolved.
Show resolved Hide resolved
/>
</TableCell>
<TableCell>
<TextField
<TextField
type="number"
variant="outlined"
color="secondary"
Expand Down Expand Up @@ -284,7 +283,9 @@ const ApiKeysPage = () => {
</TableCell>
<TableCell>{row.SUPPORTED_NETWORKS}</TableCell>
<TableCell>{row.ERC20_PAYMASTERS}</TableCell>
<TableCell>{row.TRANSACTION_LIMIT === 0 ? 'OFF': 'ON'}</TableCell>
<TableCell>
{row.TRANSACTION_LIMIT === 0 ? "OFF" : "ON"}
</TableCell>
<TableCell>{row.NO_OF_TRANSACTIONS_IN_A_MONTH}</TableCell>
<TableCell>
<LoadingButton
Expand Down
2 changes: 1 addition & 1 deletion backend/indexer/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "ponder"
}
}
3 changes: 2 additions & 1 deletion backend/indexer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
/generated/
/.ponder/

package-lock.json
package-lock.json

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing new line, this can be done automatically with editorconfig

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 21 is a new line

2 changes: 1 addition & 1 deletion backend/indexer/EtherspotAbi.ts
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an ABI and nothing else. Should this file not be in a folder similar to /data/abis/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ponder is a separate module by itself so thats why I thought I will keep it stored separately than going into src and getting that

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So i think it's more about the contents of the file as opposed to who it's for. It's ultimately a JSON object which is a data file and that's how it should be reflected in the directory structure of the service

Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,4 @@ export const EtherspotPaymasterAbi = [
"stateMutability": "nonpayable",
"type": "function"
}
] as const;
] as const;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not comfortable with a JSON file being cast as s JS object and exported in a TS file... it's just a JSON file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but the import through assertion, the ponder does not take it and moreover the ponder docs have the same type

50 changes: 25 additions & 25 deletions backend/indexer/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"name": "indexer",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"dev": "ponder dev --port 3003",
"start": "ponder start --port 3003",
"codegen": "ponder codegen",
"lint": "eslint .",
"typecheck": "tsc"
},
"dependencies": {
"@ponder/core": "0.2.2",
"viem": "1.19.3"
},
"devDependencies": {
"@types/node": "20.9.0",
"eslint": "8.53.0",
"eslint-config-ponder": "0.2.2",
"typescript": "5.2.2"
},
"engines": {
"node": ">=18.14"
}
}
"name": "indexer",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"dev": "ponder dev --port 3003",
"start": "ponder start --port 3003",
"codegen": "ponder codegen",
"lint": "eslint .",
"typecheck": "tsc"
},
"dependencies": {
"@ponder/core": "0.2.2",
"viem": "1.19.3"
},
"devDependencies": {
"@types/node": "20.9.0",
"eslint": "8.53.0",
"eslint-config-ponder": "0.2.2",
"typescript": "5.2.2"
},
"engines": {
"node": ">=18.14"
}
}
vignesha22 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion backend/indexer/ponder.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export default createSchema((p) => ({
year: p.int(),
chainId: p.int(),
}),
}));
}));
31 changes: 17 additions & 14 deletions backend/indexer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ ponder.on("EtherspotPaymaster:SponsorSuccessful", async ({ event, context }) =>
const { args, block, transaction, log } = event;
const time = Number(BigNumber.from(block.timestamp).toString());
const timestamp = new Date(time * 1000);

await db.PaymasterEvent.create({
id: transaction.hash + log.logIndex,
data: {
chainId: network.chainId,
sender: args.sender,
paymaster: args.paymaster,
transactionHash: transaction.hash,
timestamp: block.timestamp,
month: timestamp.getMonth(),
year: timestamp.getFullYear()
}
})
});
try {
await db.PaymasterEvent.create({
id: transaction.hash + log.logIndex,
data: {
chainId: network.chainId,
sender: args.sender,
paymaster: args.paymaster,
transactionHash: transaction.hash,
timestamp: block.timestamp,
month: timestamp.getMonth(),
year: timestamp.getFullYear()
}
})
} catch (err) {
// caught err
vignesha22 marked this conversation as resolved.
Show resolved Hide resolved
}
});
2 changes: 1 addition & 1 deletion backend/indexer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
},
"include": ["./**/*.ts"],
"exclude": ["node_modules"]
}
}
Loading