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-2166-Frontend Changes #69

Merged
merged 8 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions admin_frontend/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
27 changes: 25 additions & 2 deletions backend/src/paymaster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,30 @@ export class Paymaster {
};
} catch (err: any) {
if (err.message.includes('already whitelisted')) throw new Error(err);
throw new Error('Error while submitting transaction');
throw new Error('The wallet does not have enough funds or the gas price is too high at the moment. Please try again later or contact support team');
}
}

async removeWhitelistAddress(address: string[], paymasterAddress: string, bundlerRpc: string, relayerKey: string) {
try {
const provider = new providers.JsonRpcProvider(bundlerRpc);
const paymasterContract = new ethers.Contract(paymasterAddress, abi, provider);
const signer = new Wallet(relayerKey, provider)
for (let i = 0; i < address.length; i++) {
const isAdded = await paymasterContract.check(signer.address, address[i]);
if (!isAdded) {
throw new Error(`${address[i]} is not whitelisted`)
}
}
const encodedData = paymasterContract.interface.encodeFunctionData('removeBatchToWhitelist', [address]);
const tx = await signer.sendTransaction({ to: paymasterAddress, data: encodedData });
await tx.wait();
return {
message: `Successfully removed whitelisted addresses with transaction Hash ${tx.hash}`
};
} catch (err: any) {
if (err.message.includes('is not whitelisted')) throw new Error(err);
throw new Error('The wallet does not have enough funds or the gas price is too high at the moment. Please try again later or contact support team');
ch4r10t33r marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -147,7 +170,7 @@ export class Paymaster {
message: `Successfully deposited with transaction Hash ${tx.hash}`
};
} catch (err) {
throw new Error('Error while submitting transaction');
throw new Error('The wallet does not have enough funds or the gas price is too high at the moment. Please try again later or contact support team');
}
}
}
56 changes: 56 additions & 0 deletions backend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,62 @@ const routes: FastifyPluginAsync = async (server) => {
}
)

server.post("/removeWhitelist", async function (request, reply) {
try {
const body: any = request.body;
const query: any = request.query;
const address = body.params[0];
const chainId = query['chainId'] ?? body.params[1];
const api_key = query['apiKey'] ?? body.params[2];
if (!api_key)
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
if (!unsafeMode) {
const AWSresponse = await client.send(
new GetSecretValueCommand({
SecretId: prefixSecretId + api_key,
})
);
const secrets = JSON.parse(AWSresponse.SecretString ?? '{}');
if (!secrets['PRIVATE_KEY']) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
privateKey = secrets['PRIVATE_KEY'];
supportedNetworks = secrets['SUPPORTED_NETWORKS'];
} else {
const record: any = await getSQLdata(api_key);
console.log(record);
if (!record) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
privateKey = decode(record['PRIVATE_KEY']);
supportedNetworks = record['SUPPORTED_NETWORKS'];
}
if (!privateKey) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
if (
!Array.isArray(address) ||
address.length > 10 ||
!chainId ||
isNaN(chainId)
) {
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_DATA });
}
if (server.config.SUPPORTED_NETWORKS == '' && !SupportedNetworks) {
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK });
}
const networkConfig = getNetworkConfig(chainId, supportedNetworks ?? '');
if (!networkConfig) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK });
const validAddresses = address.every(ethers.utils.isAddress);
if (!validAddresses) return reply.code(ReturnCode.FAILURE).send({ error: "Invalid Address passed" });
const result = await paymaster.removeWhitelistAddress(address, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, privateKey);
if (body.jsonrpc)
return reply.code(ReturnCode.SUCCESS).send({ jsonrpc: body.jsonrpc, id: body.id, result, error: null })
return reply.code(ReturnCode.SUCCESS).send(result);
} catch (err: any) {
request.log.error(err);
if (err.name == "ResourceNotFoundException")
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY });
return reply.code(ReturnCode.FAILURE).send({ error: err.message ?? ErrorMessage.SOMETHING_WENT_WRONG })
IAmKio marked this conversation as resolved.
Show resolved Hide resolved
}
})

server.post(
"/checkWhitelist",
async function (request, reply) {
Expand Down
12 changes: 12 additions & 0 deletions frontend/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 2 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ chrome-user-data
.vscode
*.swp
*.swo

.env.local
12 changes: 6 additions & 6 deletions frontend/src/components/ConnectedIcon.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { Fragment } from "react";

const ColoredCircle = ({ color }) => {
const styles = { backgroundColor: color };
const styles = { backgroundColor: color };

return color ? (
<Fragment>
<span className="colored-circle" style={styles} />
</Fragment>
) : null;
return color ? (
<Fragment>
<span className="colored-circle" style={styles} />
</Fragment>
) : null;
};

export default ColoredCircle;
Loading
Loading