|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Fetches the SCW getSupportedChains API and regenerates the |
| 3 | +# docs/snippets/supported-chains.mdx file, inserting any chains |
| 4 | +# tagged "simple-chain" into the dynamic section. |
| 5 | +# |
| 6 | +# Usage: |
| 7 | +# bash scripts/update-supported-chains.sh |
| 8 | +# |
| 9 | +# The snippet has two parts: |
| 10 | +# 1. Hardcoded core chains (manually maintained above the markers) |
| 11 | +# 2. Dynamic "basic chains" pulled from the API (between the markers) |
| 12 | +# |
| 13 | +# Only chains with the "simple-chain" tag are inserted dynamically. |
| 14 | +# If none are found, the dynamic section is left empty. |
| 15 | + |
| 16 | +set -euo pipefail |
| 17 | + |
| 18 | +API_URL="${API_URL:-https://api.wallet.coinbase.com/rpc/v3/scw/getSupportedChains}" |
| 19 | +SNIPPET="docs/snippets/supported-chains.mdx" |
| 20 | + |
| 21 | +# Resolve paths relative to repo root |
| 22 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 23 | +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 24 | +SNIPPET_PATH="$REPO_ROOT/$SNIPPET" |
| 25 | + |
| 26 | +if [ ! -f "$SNIPPET_PATH" ]; then |
| 27 | + echo "Error: $SNIPPET not found at $SNIPPET_PATH" >&2 |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +# Fetch the API |
| 32 | +RESPONSE=$(curl -sf "$API_URL") || { |
| 33 | + echo "Error: failed to fetch $API_URL" >&2 |
| 34 | + exit 1 |
| 35 | +} |
| 36 | + |
| 37 | +# Extract simple-chain entries grouped by mainnet/testnet |
| 38 | +DYNAMIC_BLOCK=$(echo "$RESPONSE" | python3 -c " |
| 39 | +import sys, json |
| 40 | +
|
| 41 | +data = json.load(sys.stdin) |
| 42 | +chains = data.get('chains', []) |
| 43 | +
|
| 44 | +simple = [c for c in chains if 'simple-chain' in c.get('tags', [])] |
| 45 | +
|
| 46 | +if not simple: |
| 47 | + sys.exit(0) # nothing to output |
| 48 | +
|
| 49 | +mainnets = sorted([c['name'] for c in simple if 'testnet' not in c['networkId']]) |
| 50 | +testnets = sorted([c['name'] for c in simple if 'testnet' in c['networkId']]) |
| 51 | +
|
| 52 | +all_simple = sorted(mainnets + testnets) |
| 53 | +
|
| 54 | +lines = [] |
| 55 | +lines.append('**Basic support:** ' + ' • '.join(all_simple)) |
| 56 | +lines.append('') |
| 57 | +lines.append('Basic support only includes transfers through the [Base Account Web](https://account.base.app) surface for select tokens.') |
| 58 | +
|
| 59 | +print('\n'.join(lines)) |
| 60 | +") |
| 61 | + |
| 62 | +# Replace content between the markers in the snippet |
| 63 | +python3 -c " |
| 64 | +import sys |
| 65 | +
|
| 66 | +snippet_path = sys.argv[1] |
| 67 | +dynamic_block = sys.argv[2] |
| 68 | +
|
| 69 | +with open(snippet_path, 'r') as f: |
| 70 | + content = f.read() |
| 71 | +
|
| 72 | +start_marker = '{/* DYNAMIC_CHAINS_START */}' |
| 73 | +end_marker = '{/* DYNAMIC_CHAINS_END */}' |
| 74 | +
|
| 75 | +start_idx = content.find(start_marker) |
| 76 | +end_idx = content.find(end_marker) |
| 77 | +
|
| 78 | +if start_idx == -1 or end_idx == -1: |
| 79 | + print('Error: markers not found in snippet', file=sys.stderr) |
| 80 | + sys.exit(1) |
| 81 | +
|
| 82 | +# Build the replacement: markers + dynamic content between them |
| 83 | +if dynamic_block.strip(): |
| 84 | + replacement = start_marker + '\n' + dynamic_block + '\n' + end_marker |
| 85 | +else: |
| 86 | + replacement = start_marker + '\n' + end_marker |
| 87 | +
|
| 88 | +new_content = content[:start_idx] + replacement + content[end_idx + len(end_marker):] |
| 89 | +
|
| 90 | +with open(snippet_path, 'w') as f: |
| 91 | + f.write(new_content) |
| 92 | +" "$SNIPPET_PATH" "$DYNAMIC_BLOCK" |
| 93 | + |
| 94 | +echo "Updated $SNIPPET" |
0 commit comments