Skip to content

Commit 3dc541c

Browse files
committed
Disable CoinGecko requests on testnet
1 parent d800c0d commit 3dc541c

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

.github/workflows/deploy.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,57 @@ jobs:
4141
perl -0pi -e "s#display: 'inline-block',\n width:#display: 'block',\n margin: '0 auto',\n width:#" explorer/src/components/ad/AdBanner.vue
4242
grep -n "const adStyle" -A6 explorer/src/components/ad/AdBanner.vue
4343
44+
- name: Disable CoinGecko on testnet
45+
run: |
46+
node <<'NODE'
47+
const fs = require('fs');
48+
49+
const updateFile = (path, replacements) => {
50+
let source = fs.readFileSync(path, 'utf8');
51+
for (const [from, to] of replacements) {
52+
if (!source.includes(from)) {
53+
throw new Error(`Expected text not found in ${path}: ${from}`);
54+
}
55+
source = source.replace(from, to);
56+
}
57+
fs.writeFileSync(path, source);
58+
};
59+
60+
updateFile('explorer/src/stores/useCoinGecko.ts', [
61+
[
62+
"const LocalStoreKey = 'currency';",
63+
"const LocalStoreKey = 'currency';\nconst disableCoingecko = window.location.hostname.includes('testnet');",
64+
],
65+
[
66+
"return get(`${coingeckoUrl}/api/v3/coins/${coinId}/market_chart?vs_currency=usd&days=${days}`);",
67+
"return disableCoingecko\n ? Promise.resolve({ prices: [], market_caps: [], total_volumes: [] })\n : get(`${coingeckoUrl}/api/v3/coins/${coinId}/market_chart?vs_currency=usd&days=${days}`);",
68+
],
69+
[
70+
"fetchCoinPrice(ids: string[]) {",
71+
"fetchCoinPrice(ids: string[]) {\n if (disableCoingecko) return;",
72+
],
73+
[
74+
"return get(`${coingeckoUrl}/api/v3/coins/${coinId}`);",
75+
"return disableCoingecko ? Promise.resolve({ tickers: [] }) : get(`${coingeckoUrl}/api/v3/coins/${coinId}`);",
76+
],
77+
]);
78+
79+
updateFile('explorer/src/stores/useDashboard.ts', [
80+
[
81+
"loadingPrices() {",
82+
"loadingPrices() {\n if (window.location.hostname.includes('testnet')) return;",
83+
],
84+
]);
85+
86+
updateFile('explorer/src/modules/wallet/portfolio.vue', [
87+
[
88+
"function loadPrice() {",
89+
"function loadPrice() {\n if (window.location.hostname.includes('testnet')) return;",
90+
],
91+
]);
92+
NODE
93+
grep -n "disableCoingecko\|loadingPrices\|function loadPrice" explorer/src/stores/useCoinGecko.ts explorer/src/stores/useDashboard.ts explorer/src/modules/wallet/portfolio.vue
94+
4495
- name: Setup Pages
4596
uses: actions/configure-pages@v5
4697

0 commit comments

Comments
 (0)