From ad8780c6a408a20304c6e9e7b5695b907ce97665 Mon Sep 17 00:00:00 2001 From: benya7 Date: Fri, 9 Aug 2024 12:37:52 +0200 Subject: [PATCH] format --- testnet-faucet/src/lib/checkUsageLimit.ts | 30 +++++++++---------- .../src/lib/getLatestTransactions.ts | 12 ++++---- .../src/lib/getSenderAccountSigner.ts | 2 +- .../src/pages/api/latestTransactions.ts | 2 +- testnet-faucet/src/pages/api/usageLimit.ts | 2 +- .../src/pages/api/validateAndClaim.ts | 6 ++-- testnet-faucet/src/pages/index.tsx | 4 +-- 7 files changed, 28 insertions(+), 30 deletions(-) diff --git a/testnet-faucet/src/lib/checkUsageLimit.ts b/testnet-faucet/src/lib/checkUsageLimit.ts index fa9c768a..e740f989 100644 --- a/testnet-faucet/src/lib/checkUsageLimit.ts +++ b/testnet-faucet/src/lib/checkUsageLimit.ts @@ -1,19 +1,19 @@ -import { getUnixTime } from "date-fns"; +import { getUnixTime } from 'date-fns'; -import getLatestTransactions from "./getLatestTransactions"; -import { shiftDateBackwards } from "./utils"; +import getLatestTransactions from './getLatestTransactions'; +import { shiftDateBackwards } from './utils'; export default async function checkUsageLimit(hoursLimit: number, receiverAddress: string): Promise { - let isAllowed = true; - const limitDate = getUnixTime(shiftDateBackwards(hoursLimit)); - const transactionResponse: PartialTransaction[] = await getLatestTransactions(1000); + let isAllowed = true; + const limitDate = getUnixTime(shiftDateBackwards(hoursLimit)); + const transactionResponse: PartialTransaction[] = await getLatestTransactions(1000); - transactionResponse.forEach(({ blockTime, transferDestination }) => { - if (receiverAddress == transferDestination ) { - if (Number(blockTime) > limitDate) { - isAllowed = false; - } - } - }); - return isAllowed -} \ No newline at end of file + transactionResponse.forEach(({ blockTime, transferDestination }) => { + if (receiverAddress == transferDestination) { + if (Number(blockTime) > limitDate) { + isAllowed = false; + } + } + }); + return isAllowed; +} diff --git a/testnet-faucet/src/lib/getLatestTransactions.ts b/testnet-faucet/src/lib/getLatestTransactions.ts index 521ec167..a3a4b091 100644 --- a/testnet-faucet/src/lib/getLatestTransactions.ts +++ b/testnet-faucet/src/lib/getLatestTransactions.ts @@ -1,16 +1,14 @@ export default async function getLatestTransactions(limit: number): Promise { const explorerApiUrl = process.env.EXPLORER_API_URL; const senderAddress = process.env.SENDER_ADDRESS; - + if (!senderAddress || !explorerApiUrl) { - throw new Error( - 'EXPLORER_API_URL, SENDER_ADDRESS env vars undefined.', - ); + throw new Error('EXPLORER_API_URL, SENDER_ADDRESS env vars undefined.'); } const latestTransactionsPath = `/accTransactions/${senderAddress}?limit=${limit}&order=descending&includeRawRejectReason`; - + const response = await fetch(`${explorerApiUrl}${latestTransactionsPath}`); - + if (!response.ok) { throw new Error(`Failed to fetch transactions: ${response.statusText}`); } @@ -19,6 +17,6 @@ export default async function getLatestTransactions(limit: number): Promise ({ blockTime, transactionHash, - transferDestination: details.transferDestination + transferDestination: details.transferDestination, })); } diff --git a/testnet-faucet/src/lib/getSenderAccountSigner.ts b/testnet-faucet/src/lib/getSenderAccountSigner.ts index abdf7db3..88cb937e 100644 --- a/testnet-faucet/src/lib/getSenderAccountSigner.ts +++ b/testnet-faucet/src/lib/getSenderAccountSigner.ts @@ -6,4 +6,4 @@ export default function getSenderAccountSigner(): AccountSigner { throw new Error('SENDER_PRIVATE_KEY env var undefined'); } return buildBasicAccountSigner(SENDER_PRIVATE_KEY); -}; +} diff --git a/testnet-faucet/src/pages/api/latestTransactions.ts b/testnet-faucet/src/pages/api/latestTransactions.ts index 4c25388b..ea98584d 100644 --- a/testnet-faucet/src/pages/api/latestTransactions.ts +++ b/testnet-faucet/src/pages/api/latestTransactions.ts @@ -12,7 +12,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(405).json({ error: 'Method Not Allowed. Please use GET.' }); } try { - const transactions = await getLatestTransactions(5) + const transactions = await getLatestTransactions(5); return res.status(200).json({ transactions }); } catch (e) { return res.status(500).json({ error: `An unexpected error has occurred: ${e}` }); diff --git a/testnet-faucet/src/pages/api/usageLimit.ts b/testnet-faucet/src/pages/api/usageLimit.ts index 5d37f056..a292bd5f 100644 --- a/testnet-faucet/src/pages/api/usageLimit.ts +++ b/testnet-faucet/src/pages/api/usageLimit.ts @@ -24,7 +24,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< }); } try { - const isAllowed = await checkUsageLimit(hoursLimit, receiver) + const isAllowed = await checkUsageLimit(hoursLimit, receiver); return res.status(200).json({ isAllowed }); } catch (e) { return res.status(500).json({ error: `An unexpected error has occurred: ${e}` }); diff --git a/testnet-faucet/src/pages/api/validateAndClaim.ts b/testnet-faucet/src/pages/api/validateAndClaim.ts index cdcdb9f0..4d4fa13e 100644 --- a/testnet-faucet/src/pages/api/validateAndClaim.ts +++ b/testnet-faucet/src/pages/api/validateAndClaim.ts @@ -37,10 +37,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< }); } try { - const isAllowed = await checkUsageLimit(hoursLimit, receiver) + const isAllowed = await checkUsageLimit(hoursLimit, receiver); if (!isAllowed) { return res.status(401).json({ - error: `You already get tokens in the last ${hoursLimit} ${hoursLimit > 1 ? 'hours' : 'hour'}. Please try again later.`, + error: `You already get tokens in the last ${hoursLimit} ${hoursLimit > 1 ? 'hours' : 'hour'}. Please try again later.`, }); } const rettiwt = new Rettiwt(); @@ -60,7 +60,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< error: 'X Post verification failed. Please make sure you do not modify the template text and that your address is present.', }); } - + const client = createGRPCNodeClient(); const signer = getSenderAccountSigner(); diff --git a/testnet-faucet/src/pages/index.tsx b/testnet-faucet/src/pages/index.tsx index 05cf8826..8e8b6120 100644 --- a/testnet-faucet/src/pages/index.tsx +++ b/testnet-faucet/src/pages/index.tsx @@ -37,7 +37,7 @@ const getLatestTransactions = async () => { method: 'GET', headers: { 'Content-Type': 'application/json', - } + }, }); const data = await response.json(); @@ -57,7 +57,7 @@ const validateAndClaim = async (hoursLimit: number, XPostId: string | undefined, body: JSON.stringify({ hoursLimit, XPostId, - receiver + receiver, }), });