Skip to content

Commit

Permalink
Update the whitelist script to get retool dapps
Browse files Browse the repository at this point in the history
  • Loading branch information
sayantan-b committed Nov 2, 2023
1 parent 57872b5 commit cb81004
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scripts/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GOOGLE_CLIENT_EMAIL=
STALE_DAPPS_SHEETS_ID=
RETOOL_DAPPS_SHEET_ID=
GOOGLE_PRIVATE_KEY=
GOOGLE_PRIVATE_KEY=
37 changes: 29 additions & 8 deletions scripts/whitelistDapps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
const fs = require('fs');
const { google } = require('googleapis');
require('dotenv').config();

// Function to read a JSON file
const dotenv = require('dotenv')

dotenv.config()
const google_key = process.env.GOOGLE_PRIVATE_KEY.split(String.raw`\n`).join(
"\n"
);

/**
* Reads a JSON file and returns its contents as a JavaScript object.
* @param {string} filename - The path of the JSON file to be read.
* @returns {Object|null} - The contents of the JSON file as a JavaScript object, or null if an error occurred.
*/
function readJSONFile(filename) {
try {
const data = fs.readFileSync(filename, 'utf8');
Expand All @@ -13,23 +22,32 @@ function readJSONFile(filename) {
}
}

// Function to write a JSON file
/**
* Writes data to a JSON file.
* @param {string} filename - The name of the file to write to.
* @param {object} data - The data to write to the file.
*/
function writeJSONFile(filename, data) {
try {
const jsonData = JSON.stringify(data, null, 2) + '\n'; // Add a newline character
const jsonData = JSON.stringify(data, null, 2) + '\n';
fs.writeFileSync(filename, jsonData);
} catch (error) {
console.error(`Error writing ${filename}: ${error.message}`);
}
}

// Fetch data from Google Sheet
/**
* Fetches Dapp IDs from a Google Sheet and updates reserved Dapp names.
* @async
* @function fetchDappIDsFromGoogleSheet
* @returns
*/
const fetchDappIDsFromGoogleSheet = async () => {
console.log(process.env.GOOGLE_CLIENT_EMAIL)
const jwtClient = new google.auth.JWT(
process.env.GOOGLE_CLIENT_EMAIL,
undefined,
process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'),
google_key,
['https://www.googleapis.com/auth/spreadsheets']
);

Expand Down Expand Up @@ -57,7 +75,10 @@ const fetchDappIDsFromGoogleSheet = async () => {
});
};

// Update reservedDappNames.json with new dappIDs
/**
* Updates the reserved Dapp names with new Dapp IDs.
* @param {Array<string>} newDappIDs - An array of new Dapp IDs to be added to the reserved Dapp names.
*/
const updateReservedDappNames = (newDappIDs) => {
const reservedDappNames = readJSONFile('reservedDappNames.json');

Expand Down

0 comments on commit cb81004

Please sign in to comment.