Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate the ui lib chains.json file from the same go script #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
299 changes: 150 additions & 149 deletions apis_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7,302 changes: 7,301 additions & 1 deletion codegen/chains.json

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions codegen/gen_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"encoding/json"
"log"
"net/http"
"os"
"text/template"

Expand Down Expand Up @@ -50,4 +51,48 @@ var etherscanConfig map[string]string = map[string]string{
}

f.Close()

// Download and filter chains_mini.json
miniChainsURL := "https://chainid.network/chains_mini.json"
resp, err := http.Get(miniChainsURL)
if err != nil {
log.Fatal("Error downloading chains_mini.json:", err)
}
defer resp.Body.Close()

var miniChains []map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&miniChains); err != nil {
log.Fatal("Error decoding chains_mini.json:", err)
}

// Create a set of chain IDs from the new chains
chainIDs := make(map[int]bool)
for _, chain := range chains {
chainIDs[chain.ID] = true
}

// Filter miniChains based on the new chain IDs
var filteredChains []map[string]interface{}
for _, chain := range miniChains {
if chainID, ok := chain["chainId"].(float64); ok {
if chainIDs[int(chainID)] {
filteredChains = append(filteredChains, chain)
}
}
}

// Save filtered chains to ui/src/lib/chains.json
uiChainsFile, err := os.Create("./ui/src/lib/chains.json")
if err != nil {
log.Fatal("Error creating ui/src/lib/chains.json:", err)
}
defer uiChainsFile.Close()

encoder := json.NewEncoder(uiChainsFile)
encoder.SetIndent("", " ")
if err := encoder.Encode(filteredChains); err != nil {
log.Fatal("Error encoding filtered chains:", err)
}

log.Println("Successfully filtered and saved chains to ui/src/lib/chains.json")
}
5,230 changes: 5,229 additions & 1 deletion ui/src/lib/chains.json

Large diffs are not rendered by default.