Skip to content

Commit

Permalink
Hide turnstile site key variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillweston committed Mar 30, 2024
1 parent 1a6ffb4 commit 4e1784a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 54 deletions.
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
ACTIVE_NETWORK: ${{ secrets.ACTIVE_NETWORK }}
CONTRACT_ADDRESS: ${{ secrets.CONTRACT_ADDRESS }}
WEB_ADDRESS: ${{ secrets.WEB_ADDRESS }}
TURNSTILE_SITE_KEY: ${{ secrets.TURNSTILE_SITE_KEY }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
ACTIVE_NETWORK: ${{ secrets.ACTIVE_NETWORK }}
CONTRACT_ADDRESS: ${{ secrets.CONTRACT_ADDRESS }}
WEB_ADDRESS: ${{ secrets.WEB_ADDRESS }}
TURNSTILE_SITE_KEY: ${{ secrets.TURNSTILE_SITE_KEY }}
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ This section provides guidance on deploying your project to GitHub Pages and Clo
- **`ACTIVE_NETWORK`**
- **`CONTRACT_ADDRESS`**
- **`WEB_ADDRESS`**
- **`TURNSTILE_SITE_KEY`**
### Setting Environment Variables in GitHub
Expand All @@ -220,7 +221,7 @@ This section provides guidance on deploying your project to GitHub Pages and Clo
3. Click on "New repository secret" and add each environment variable:
- Name: Variable name (e.g., `PROJECT_ID`).
- Value: Corresponding value for the variable.
4. Repeat this process for `ACTIVE_NETWORK`, `CONTRACT_ADDRESS` and `WEB_ADDRESS`.
4. Repeat this process for `ACTIVE_NETWORK`, `CONTRACT_ADDRESS`, `WEB_ADDRESS` and `TURNSTILE_SITE_KEY`.
### Deploying to GitHub Pages
Expand Down
3 changes: 2 additions & 1 deletion create-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const config = {
"projectId": process.env.PROJECT_ID,
"activeNetwork": process.env.ACTIVE_NETWORK,
"contractAddress": process.env.CONTRACT_ADDRESS,
"webAddress": process.env.WEB_ADDRESS
"webAddress": process.env.WEB_ADDRESS,
"turnstileSiteKey": process.env.TURNSTILE_SITE_KEY
};

fs.writeFileSync('contract-config.json', JSON.stringify(config, null, 2));
84 changes: 33 additions & 51 deletions js/claim-airdrop.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import Web3 from 'web3';

async function initiateTransaction() {
if (typeof window.ethereum !== 'undefined') {
// MetaMask is installed
const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.base.org'));
let activeNetwork, contractAddress, webAddress, turnstileSiteKey;

let activeNetwork, contractAddress;
try {
// Attempt to load the configuration file
const config = require('../contract-config.json');

try {
// Attempt to load the configuration file
const config = require('../contract-config.json');
// Access properties
activeNetwork = config.activeNetwork;
contractAddress = config.contractAddress;
webAddress = config.webAddress;
turnstileSiteKey = config.turnstileSiteKey;

// Access properties
activeNetwork = config.activeNetwork;
contractAddress = config.contractAddress;
// Additional validation can be performed here as needed
if (!activeNetwork || !contractAddress || !webAddress || !turnstileSiteKey) {
throw new Error("Required configuration values (activeNetwork or contractAddress or webAddress) are missing.");
}

// Additional validation can be performed here as needed
if (!activeNetwork || !contractAddress) {
throw new Error("Required configuration values (activeNetwork or contractAddress) are missing.");
}
} catch (error) {
// Check if the error is due to missing file
if (error.code === 'MODULE_NOT_FOUND') {
console.error("Error: Configuration file not found.");
process.exit(1);
}

} catch (error) {
// Check if the error is due to missing file
if (error.code === 'MODULE_NOT_FOUND') {
console.error("Error: Configuration file not found.");
return; // Return or handle error as needed
}
// Handle other errors
console.error("Error loading configuration: ", error.message);
}

// Handle other errors
console.error("Error loading configuration: ", error.message);
}
async function initiateTransaction() {
if (typeof window.ethereum !== 'undefined') {
// MetaMask is installed
const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.base.org'));

// Updated contract ABI
const contractABI = [
Expand Down Expand Up @@ -115,31 +117,6 @@ function checkUserEligibility() {
const fullAddress = document.getElementById('address').getAttribute('data-full-address');
console.log('Checking eligibility for address:', fullAddress);

let webAddress;

try {
// Attempt to load the configuration file
const config = require('../contract-config.json');

// Access properties
webAddress = config.webAddress;

// Additional validation can be performed here as needed
if (!webAddress) {
throw new Error("Required configuration values (activeNetwork or contractAddress) are missing.");
}

} catch (error) {
// Check if the error is due to missing file
if (error.code === 'MODULE_NOT_FOUND') {
console.error("Error: Configuration file not found.");
return; // Return or handle error as needed
}

// Handle other errors
console.error("Error loading configuration: ", error.message);
}

const url = webAddress + `?address=${encodeURIComponent(fullAddress)}`;

fetch(url)
Expand Down Expand Up @@ -198,8 +175,13 @@ document.addEventListener('DOMContentLoaded', function () {
document.head.appendChild(script);

var widgetDiv = document.getElementById('turnstileWidget');
var theme = getElementById('connectAccept').getAttribute('data-param');
widgetDiv.innerHTML = '<div class="cf-turnstile" data-sitekey="0x4AAAAAAAV4P5jUGTn18kDG" data-theme="' + theme + '"></div>';
var theme = document.getElementById('connectAccept').getAttribute('data-param');
var turnstileElement = document.createElement('div');
turnstileElement.className = 'cf-turnstile';
turnstileElement.setAttribute('data-sitekey', turnstileSiteKey);
turnstileElement.setAttribute('data-theme', theme);
// Append the Turnstile element to the widget div
widgetDiv.appendChild(turnstileElement);
}

if (claimAirdropButton) {
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = {
'process.env.PROJECT_ID': JSON.stringify(process.env.PROJECT_ID),
'process.env.ACTIVE_NETWORK': JSON.stringify(process.env.ACTIVE_NETWORK),
'process.env.CONTRACT_ADDRESS': JSON.stringify(process.env.CONTRACT_ADDRESS),
'process.env.WEB_ADDRESS': JSON.stringify(process.env.WEB_ADDRESS)
'process.env.WEB_ADDRESS': JSON.stringify(process.env.WEB_ADDRESS),
'process.env.TURNSTILE_SITE_KEY': JSON.stringify(process.env.TURNSTILE_SITE_KEY),
})
]
};

0 comments on commit 4e1784a

Please sign in to comment.