Skip to content

Disable CoinGecko requests on testnet #8

Disable CoinGecko requests on testnet

Disable CoinGecko requests on testnet #8

Workflow file for this run

name: Deploy to GitHub Pages
on:
push:
branches: [ main ]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
build:
name: Build site
runs-on: ubuntu-latest
steps:
- name: Git Checkout Latest
uses: actions/checkout@v4
with:
submodules: recursive
- name: Update explorer to latest
run: |
git submodule update --remote --checkout explorer
git -C explorer log -1 --oneline
- name: Allow Slise ads in CSP
run: |
perl -0pi -e "s#(script-src[^;]*https://\*\.ping\.pub)#\$1 https://v1.slise.xyz#" explorer/index.html
perl -0pi -e "s#(frame-src[^;]*https://wallet\.keplr\.app)#\$1 https://v1.slise.xyz#" explorer/index.html
grep -n "Content-Security-Policy" -A1 explorer/index.html
- name: Center Slise ad banner
run: |
perl -0pi -e "s#display: 'inline-block',\n width:#display: 'block',\n margin: '0 auto',\n width:#" explorer/src/components/ad/AdBanner.vue
grep -n "const adStyle" -A6 explorer/src/components/ad/AdBanner.vue
- name: Disable CoinGecko on testnet
run: |
node <<'NODE'
const fs = require('fs');
const updateFile = (path, replacements) => {
let source = fs.readFileSync(path, 'utf8');
for (const [from, to] of replacements) {
if (!source.includes(from)) {
throw new Error(`Expected text not found in ${path}: ${from}`);
}
source = source.replace(from, to);
}
fs.writeFileSync(path, source);
};
updateFile('explorer/src/stores/useCoinGecko.ts', [
[
"const LocalStoreKey = 'currency';",
"const LocalStoreKey = 'currency';\nconst disableCoingecko = window.location.hostname.includes('testnet');",
],
[
"return get(`${coingeckoUrl}/api/v3/coins/${coinId}/market_chart?vs_currency=usd&days=${days}`);",
"return disableCoingecko\n ? Promise.resolve({ prices: [], market_caps: [], total_volumes: [] })\n : get(`${coingeckoUrl}/api/v3/coins/${coinId}/market_chart?vs_currency=usd&days=${days}`);",
],
[
"fetchCoinPrice(ids: string[]) {",
"fetchCoinPrice(ids: string[]) {\n if (disableCoingecko) return;",
],
[
"return get(`${coingeckoUrl}/api/v3/coins/${coinId}`);",
"return disableCoingecko ? Promise.resolve({ tickers: [] }) : get(`${coingeckoUrl}/api/v3/coins/${coinId}`);",
],
]);
updateFile('explorer/src/stores/useDashboard.ts', [
[
"loadingPrices() {",
"loadingPrices() {\n if (window.location.hostname.includes('testnet')) return;",
],
]);
updateFile('explorer/src/modules/wallet/portfolio.vue', [
[
"function loadPrice() {",
"function loadPrice() {\n if (window.location.hostname.includes('testnet')) return;",
],
]);
NODE
grep -n "disableCoingecko\|loadingPrices\|function loadPrice" explorer/src/stores/useCoinGecko.ts explorer/src/stores/useDashboard.ts explorer/src/modules/wallet/portfolio.vue
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: yarn
cache-dependency-path: explorer/yarn.lock
- name: Setup testnet config
run: |
mkdir -p explorer/chains/testnet
rm -f explorer/chains/mainnet/*.json explorer/chains/testnet/*.json
cp chains/testnet/*.json explorer/chains/testnet/
- name: Install dependencies
working-directory: explorer
run: yarn install --frozen-lockfile
- name: Build
working-directory: explorer
run: yarn build
env:
NODE_OPTIONS: --max_old_space_size=4096
- name: Copy logos
run: cp -rf logos explorer/dist/
- name: Set custom domain
run: echo testnet.ping.pub > explorer/dist/CNAME
- name: Create SPA 404 fallback
run: cp explorer/dist/index.html explorer/dist/404.html
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: explorer/dist
deploy:
name: Deploy site
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4