Skip to content

Commit

Permalink
make it json (#1)
Browse files Browse the repository at this point in the history
* Update main.ts

* refactor
  • Loading branch information
Lomet authored Dec 22, 2024
1 parent cab8b40 commit 369d851
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 64 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ dist
/typechain-types

temp.zip
yarn.lock
yarn.lock
# to serve the app
/serve
30 changes: 0 additions & 30 deletions index.html

This file was deleted.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"build": "tsc",
"deploy": "gh-pages -d dist"
"deploy": "gh-pages -d dist",
"generate": "node src/generate.js"
},
"repository": {
"type": "git",
Expand All @@ -26,4 +28,4 @@
"typescript": "^5.7.2",
"undici": "^6.21.0"
}
}
}
39 changes: 39 additions & 0 deletions src/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { AVAILABLE_CHAINS } from "@poolzfinance/reacthelper";
import fs from "fs";
import path from "path";

const outputDir = "./dist"; // Directory for generated files
const indexSource = "./view/index.html"; // Source of index.html
const indexDestination = path.join(outputDir, "index.html");

// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

// Array to store metadata for the index
const fileList = [];

// Generate JSON files for each chain and collect metadata
AVAILABLE_CHAINS.forEach((data, chainId) => {
const fileName = `${chainId}.json`;
const filePath = path.join(outputDir, fileName);
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
console.log(`Generated: ${filePath}`);

// Add to the list
fileList.push({
chainId,
fileName,
url: fileName,
});
});

// Create the list.json file
const listFilePath = path.join(outputDir, "list.json");
fs.writeFileSync(listFilePath, JSON.stringify(fileList, null, 2));
console.log(`Generated: ${listFilePath}`);

// Copy index.html to the output directory
fs.copyFileSync(indexSource, indexDestination);
console.log(`Copied index.html to ${indexDestination}`);
8 changes: 0 additions & 8 deletions src/main.ts

This file was deleted.

23 changes: 0 additions & 23 deletions tsconfig.json

This file was deleted.

42 changes: 42 additions & 0 deletions view/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<title>JSON Viewer</title>
<script src="https://cdn.jsdelivr.net/npm/jsoneditor@9.10.0/dist/jsoneditor.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/jsoneditor@9.10.0/dist/jsoneditor.min.css" rel="stylesheet">
<style>
#jsoneditor { width: 100%; height: 400px; }
</style>
</head>
<body>
<h1>JSON Viewer</h1>
<p>Enter Chain ID to view data:</p>
<input type="text" id="chainIdInput" placeholder="Enter Chain ID">
<button onclick="fetchJSON()">Load JSON</button>
<div id="jsoneditor"></div>

<script>
const container = document.getElementById("jsoneditor");
const editor = new JSONEditor(container);

function fetchJSON() {
const chainId = document.getElementById("chainIdInput").value;
const url = `static-data/${chainId}.json`;

fetch(url)
.then(response => {
if (!response.ok) {
throw new Error(`Error: ${response.status}`);
}
return response.json();
})
.then(data => {
editor.set(data);
})
.catch(error => {
editor.set({ error: error.message });
});
}
</script>
</body>
</html>

0 comments on commit 369d851

Please sign in to comment.