diff --git a/.gitignore b/.gitignore index f9d9adc..cfb0b46 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -*.htm \ No newline at end of file +*.htm + +*.env \ No newline at end of file diff --git a/dev-config.json b/dev-config.json index 2b965e3..bdc0ebf 100644 --- a/dev-config.json +++ b/dev-config.json @@ -9,5 +9,6 @@ "GAS_PRICE": 60000000, "GAS_LIMIT": 100000, "VALUE_TO_DISPENSE": 0.005, - "TAG_MANAGER_ID": "NO_ID" + "TAG_MANAGER_ID": "NO_ID", + "FILTER_BY_IP": true } \ No newline at end of file diff --git a/pages/api/dispense.ts b/pages/api/dispense.ts index 3924bb8..790ccb3 100644 --- a/pages/api/dispense.ts +++ b/pages/api/dispense.ts @@ -11,7 +11,7 @@ import { DispenseResponse, } from '../../types/types'; import { CronJob } from 'cron'; -import { provider } from '../../utils/env-util'; +import { filterByIP, provider } from '../../utils/env-util'; import { alreadyDispensed, captchaRejected, @@ -180,9 +180,10 @@ function runValidations( } function filterAddresses(faucetHistory: FaucetHistory, dispenseAddress: string, ip:string) { + const isFilterByIP = filterByIP(); const key = Object.keys(faucetHistory).find((key) => { const historyEntry = faucetHistory[key]; - return historyEntry.ip === ip || historyEntry.address === dispenseAddress.toLowerCase() + return (historyEntry.ip === ip && isFilterByIP) || historyEntry.address === dispenseAddress.toLowerCase() }); const adddress = key ? faucetHistory[key!] : null; if (!adddress?.mint && !adddress?.loading) delete faucetHistory[dispenseAddress.toLowerCase()] diff --git a/prod-config.json b/prod-config.json index 44e41ec..9eaf5f1 100644 --- a/prod-config.json +++ b/prod-config.json @@ -7,5 +7,6 @@ "GAS_PRICE": 60000000, "GAS_LIMIT": 100000, "VALUE_TO_DISPENSE": 0.005, - "TAG_MANAGER_ID": "NO_ID" + "TAG_MANAGER_ID": "NO_ID", + "FILTER_BY_IP": true } diff --git a/test-config.json b/test-config.json index 9add69c..4827508 100644 --- a/test-config.json +++ b/test-config.json @@ -8,5 +8,6 @@ "FAUCET_PRIVATE_KEY": "c3d40c98585e2c61add9c6a94b66cd7f5c5577e45d900c6c0e3139df1310292f", "GAS_PRICE": 60000000, "GAS_LIMIT": 100000, - "VALUE_TO_DISPENSE": 0.005 + "VALUE_TO_DISPENSE": 0.005, + "FILTER_BY_IP": true } diff --git a/utils/env-util.ts b/utils/env-util.ts index ef6abf4..d8e6296 100644 --- a/utils/env-util.ts +++ b/utils/env-util.ts @@ -97,3 +97,11 @@ export function siteKey(): string { export function tagManagerId(): string { return productionDevelopmentTest(prodConfig.TAG_MANAGER_ID, devConfig.TAG_MANAGER_ID, devConfig.TAG_MANAGER_ID); } + +export function filterByIP(): string { + return productionDevelopmentTest( + prodConfig.FILTER_BY_IP, + devConfig.FILTER_BY_IP, + devConfig.FILTER_BY_IP + ); +} \ No newline at end of file diff --git a/utils/validations.ts b/utils/validations.ts index d5da096..500558d 100644 --- a/utils/validations.ts +++ b/utils/validations.ts @@ -1,5 +1,6 @@ import { CaptchaSolutionResponse, FaucetHistory } from '../types/types'; import {isValidAddress} from 'rskjs-util'; +import { filterByIP } from './env-util'; const EROR_CODE = { 'missing-input-secret': 'The secret parameter is missing.', @@ -18,7 +19,8 @@ export const alreadyDispensed = (address: string, ip:string, faucetHistory: Fauc const usedAddress = faucetHistory.hasOwnProperty(address) const key = Object.keys(faucetHistory).find((key) => faucetHistory[key].ip === ip); const usedIp = key ? faucetHistory[key!] : null; - if (usedIp?.ip) return 'IP already used today, try again tomorrow.' + const isFilterByIP = filterByIP(); + if (usedIp?.ip && isFilterByIP) return 'IP already used today, try again tomorrow.' if (usedAddress) return 'Address already used today, try again tomorrow.' faucetHistory[address] = { address,