Skip to content

Commit

Permalink
feat: add chains setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 9, 2023
1 parent 662dfe7 commit d77c241
Show file tree
Hide file tree
Showing 3,353 changed files with 166 additions and 35 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
import fs from "fs-extra";
import path from "path";

const DataDirectory = ".";
const DataDirectory = "./chains";
const IndexName = "index.json";

function validate(directory) {
let allValid = true;
for (let name of fs.readdirSync(directory)) {
if (name.startsWith(".") || name === IndexName || name === 'node_modules') continue;
let file = path.join(directory, name);
const file = path.join(directory, name);
const stat = fs.lstatSync(file);
if (stat.isDirectory()) {
if (name.startsWith("0x")) {
try {
if (name.toLowerCase() !== name) {
console.error(`Error: "${name}" is not lowercased. Should be "${name.toLowerCase()}".`);
allValid = false;
const newName = name.toLowerCase();
const newFile = path.join(directory, newName);
if (fs.existsSync(newFile)) {
console.log(`Deleting existing folder "${newName}"...`);
fs.removeSync(newFile);
}
console.log(`Renaming folder "${name}" to "${newName}"...`);
fs.renameSync(file, newFile);
name = newName; // Update the name variable to the new lowercase name
file = newFile; // Update the file variable to the new folder path
}
} catch(error) {
console.error(`Error: "${name}" is not lowercased. Should be "${name.toLowerCase()}".`);
allValid = false;
}
}
if (name.startsWith("_")) {
continue;
continue
}

allValid &= validate(file);

if (name.startsWith("0x")) {
if (name.match(/^[0-9]+$/) != null) {
if (!fs.existsSync(path.join(file, "logo-128.png"))) {
console.error(`Error: "${file}" is missing logo-128.png`);
allValid = false;
Expand All @@ -47,7 +23,6 @@ function validate(directory) {
console.error(`Error: "${file}" is missing logo-32.png`);
allValid = false;
}

if (!fs.existsSync(path.join(file, "logo.svg"))) {
console.error(`Error: "${file}" is missing logo.svg`);
allValid = false;
Expand All @@ -59,6 +34,7 @@ function validate(directory) {
}
}
}
allValid &= validate(file);
}
}
return allValid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs-extra";
import path from "path";

const DataDirectory = ".";
const DataDirectory = "./tokens";
const IndexName = "index.json";

function validate(directory) {
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ jobs:
- name: Install deps
run: npm install

- name: Verify checksum
run: node ./.github/scripts/verify.mjs
- name: Verify tokens
run: node ./.github/scripts/verify-tokens.mjs

- name: Verify chains
run: node ./.github/scripts/verify-chains.mjs
45 changes: 45 additions & 0 deletions _config/nodeAPI/app/api/chains/[chainID]/[filename]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

type TContext = {
params: {
chainID: string
tokenAddress: string
filename: string
}
}
async function resolveNotFound(request: Request): Promise<Response> {
const fallback = new URL(request.url).searchParams.get('fallback');
if (fallback === 'true') {
const baseURI = (process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : (request as any)?.nextUrl?.origin);
const result = await fetch(`${baseURI}/not-found.png`);
return new Response(result.body, {headers: {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
}

if (fallback) {
const result = await fetch(fallback);
const contentTypeFromFallback = result.headers.get('Content-Type');
if (contentTypeFromFallback?.startsWith('image/')) {
console.warn(`Using fallback image for gas token: ${fallback}`);
return new Response(result.body, {headers: {'Content-Type': contentTypeFromFallback, 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
}
}
return new Response('Not found', {status: 404});
}

export async function GET(request: Request, context: TContext): Promise<Response> {
const chainIDStr = (context?.params?.chainID || 1).toString();
const fileName = (context?.params?.filename || '').toLowerCase();
if (!['logo.svg', 'logo-32.png', 'logo-128.png'].includes(fileName)) {
return await resolveNotFound(request);
}

const baseURI = (process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : (request as any)?.nextUrl?.origin);
const result = await fetch(`${baseURI}/chains/${chainIDStr}/${fileName}`);
if (result.ok) {
if (fileName.endsWith('.svg')) {
return new Response(result.body, {headers: {'Content-Type': 'image/svg+xml', 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
}
return new Response(result.body, {headers: {'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
}

return await resolveNotFound(request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function GET(request: Request, context: TContext): Promise<Response
}

const baseURI = (process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : (request as any)?.nextUrl?.origin);
const result = await fetch(`${baseURI}/${chainIDStr}/${tokenAddress}/${fileName}`);
const result = await fetch(`${baseURI}/tokens/${chainIDStr}/${tokenAddress}/${fileName}`);
if (result.ok) {
if (fileName.endsWith('.svg')) {
return new Response(result.body, {headers: {'Content-Type': 'image/svg+xml', 'Cache-Control': 'public, max-age=86400, must-revalidate'}});
Expand Down
10 changes: 8 additions & 2 deletions _config/nodeAPI/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ mkdir -p ./public
# Copy all files from the root directory starting with a number (chainID)
# cp -rf ../../1 ./public/

allDirectories=$(find ../.. -maxdepth 1 -type d -name '[0-9]*')
allDirectories=$(find ../../tokens -maxdepth 1 -type d -name '[0-9]*')
for directory in $allDirectories
do
cp -rf $directory ./public/
cp -rf $directory ./public/tokens/
done

allDirectories=$(find ../../chains -maxdepth 1 -type d -name '[0-9]*')
for directory in $allDirectories
do
cp -rf $directory ./public/chains/
done
Empty file.
Empty file.
Binary file added chains/1/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/1/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions chains/1/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/10/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/10/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions chains/10/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/1101/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/1101/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions chains/1101/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/137/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/137/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions chains/137/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/250/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/250/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions chains/250/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/324/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/324/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions chains/324/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/42161/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/42161/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions chains/42161/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/43114/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/43114/logo-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions chains/43114/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/56/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chains/56/logo-32.png
Loading

0 comments on commit d77c241

Please sign in to comment.