Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(browser): price ETH across four feeds and bound the login, tile and signal calls that could hang

nirholas0476595e5ff1
diff --git a/public/skills/crypto-price/handlers.js b/public/skills/crypto-price/handlers.js
index 1729e489c..fc24ffb69 100644
--- a/public/skills/crypto-price/handlers.js
+++ b/public/skills/crypto-price/handlers.js
@@ -5,23 +5,38 @@ export default {
return { ok: false, error: 'coin_id and vs_currency are required' };
}
- try {
- const url = `https://api.coingecko.com/api/v3/simple/price?ids=${coin_id}&vs_currencies=${vs_currency}`;
- const response = await fetch(url);
- if (!response.ok) {
- return { ok: false, error: `API request failed with status ${response.status}` };
- }
- const data = await response.json();
-
- if (data[coin_id] && data[coin_id][vs_currency]) {
- const price = data[coin_id][vs_currency];
- return { ok: true, output: `The current price of ${coin_id} is ${price} ${vs_currency.toUpperCase()}.` };
- } else {
- return { ok: false, error: `Could not retrieve price for ${coin_id} in ${vs_currency}` };
+ // Two independent feeds, each bounded and each with its OWN parser. A
+ // second URL whose response shape the first parser cannot read is not a
+ // fallback, it is a silent miss, so the source and its reader travel
+ // together. DefiLlama only quotes USD, so it stands in for the USD case and
+ // steps aside for any other vs_currency rather than answering the wrong
+ // question.
+ const feeds = [
+ {
+ url: `https://api.coingecko.com/api/v3/simple/price?ids=${encodeURIComponent(coin_id)}&vs_currencies=${encodeURIComponent(vs_currency)}`,
+ parse: (d) => d?.[coin_id]?.[vs_currency],
+ },
+ ...(String(vs_currency).toLowerCase() === 'usd'
+ ? [{
+ url: `https://coins.llama.fi/prices/current/coingecko:${encodeURIComponent(coin_id)}`,
+ parse: (d) => d?.coins?.[`coingecko:${coin_id}`]?.price,
+ }]
+ : []),
+ ];
+
+ for (const feed of feeds) {
+ try {
+ const r = await fetch(feed.url, { signal: AbortSignal.timeout(6000) });
+ if (!r.ok) continue;
+ const price = feed.parse(await r.json());
+ if (typeof price === 'number' && Number.isFinite(price)) {
+ return { ok: true, output: `The current price of ${coin_id} is ${price} ${vs_currency.toUpperCase()}.` };
+ }
+ } catch (error) {
+ console.error('Error fetching crypto price:', error);
}
- } catch (error) {
- console.error('Error fetching crypto price:', error);
- return { ok: false, error: 'An error occurred while fetching the price.' };
}
+
+ return { ok: false, error: `Could not retrieve price for ${coin_id} in ${vs_currency}` };
}
};
diff --git a/src/erc8004/reputation-panel.js b/src/erc8004/reputation-panel.js
index e1d1ccc94..17a975b06 100644
--- a/src/erc8004/reputation-panel.js
+++ b/src/erc8004/reputation-panel.js
@@ -20,6 +20,7 @@ import { CHAIN_META, switchChain, txExplorerUrl, readProvider } from './chain-me
import { REGISTRY_DEPLOYMENTS } from './abi.js';
import { submitReputation, stakeReputation, getTotalStake, getReputation, getRecentReviews } from './reputation.js';
import { log } from '../shared/log.js';
+import { getEthPriceUsd } from '../shared/usd-price.js';
const REVIEWS_LOOKBACK_BLOCKS = 50_000;
const MIN_STAKE_ETH = 0.001;
@@ -31,11 +32,10 @@ async function fetchEthPriceUsd() {
const now = Date.now();
if (_ethPriceUsd && now - _ethPriceFetchedAt < 5 * 60 * 1000) return _ethPriceUsd;
try {
- const res = await fetch(
- 'https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd',
- );
- const data = await res.json();
- _ethPriceUsd = data?.ethereum?.usd ?? null;
+ // Four feeds with per-provider cooldowns, not one un-timed CoinGecko call:
+ // a throttle there used to blank the USD figure printed beside a real ETH
+ // stake amount.
+ _ethPriceUsd = await getEthPriceUsd();
_ethPriceFetchedAt = now;
} catch {
/* best-effort */
diff --git a/src/home-bento.js b/src/home-bento.js
index a00e71f9a..58ca9bd57 100644
--- a/src/home-bento.js
+++ b/src/home-bento.js
@@ -377,7 +377,9 @@
var runners = {
jupiter: function(my) {
setLoading('jupiter_swap');
- return fetch('https://lite-api.jup.ag/swap/v1/quote?inputMint=' + USDC + '&outputMint=' + WSOL + '&amount=10000000&slippageBps=50')
+ // Bounded: without a timeout the tile spins forever on a stalled
+ // connection, which reads as a broken page rather than a slow quote.
+ return fetch('https://lite-api.jup.ag/swap/v1/quote?inputMint=' + USDC + '&outputMint=' + WSOL + '&amount=10000000&slippageBps=50', { signal: AbortSignal.timeout(8000) })
.then(function(r) { if (!r.ok) throw new Error('HTTP ' + r.status); return r.json(); })
.then(function(q) {
if (my !== seq) return;
diff --git a/src/privy-login.js b/src/privy-login.js
index 0e65bb7db..1e821fc07 100644
--- a/src/privy-login.js
+++ b/src/privy-login.js
@@ -48,8 +48,12 @@ if (!appId) {
async function fetchCaptchaConfig(id) {
try {
+ // This gates the login form, so an unbounded call stalls sign-in on a slow
+ // network instead of degrading. Failing to null is already the designed
+ // state (no captcha), the timeout just makes sure we reach it.
const r = await fetch(`https://auth.privy.io/api/v1/apps/${id}`, {
headers: { 'privy-app-id': id },
+ signal: AbortSignal.timeout(6000),
});
if (!r.ok) return null;
const cfg = await r.json();
diff --git a/src/pump/telegram-delivery.js b/src/pump/telegram-delivery.js
index e2b35b13f..986673725 100644
--- a/src/pump/telegram-delivery.js
+++ b/src/pump/telegram-delivery.js
@@ -10,11 +10,26 @@ const KIND_LABEL = {
export async function sendTelegramSignal({ botToken, chatId, signal }) {
const text = formatSignal(signal);
const url = `https://api.telegram.org/bot${botToken}/sendMessage`;
- const res = await fetch(url, {
- method: 'POST',
- headers: { 'content-type': 'application/json' },
- body: JSON.stringify({ chat_id: chatId, text, parse_mode: 'Markdown' }),
- });
+ // Bounded, and retried once on the statuses Telegram uses for backpressure.
+ // A signal is worth delivering late; it is not worth losing to one 429, and
+ // an unbounded POST could hold the caller open indefinitely.
+ let res = null;
+ for (let attempt = 0; attempt < 2; attempt++) {
+ res = await fetch(url, {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ chat_id: chatId, text, parse_mode: 'Markdown' }),
+ signal: AbortSignal.timeout(8000),
+ });
+ if (res.ok) break;
+ if (attempt === 0 && (res.status === 429 || res.status >= 500)) {
+ const retryAfter = Number(res.headers.get('retry-after'));
+ const waitMs = Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter * 1000, 5000) : 750;
+ await new Promise((r) => setTimeout(r, waitMs));
+ continue;
+ }
+ break;
+ }
if (!res.ok) {
const body = await res.text();
throw Object.assign(new Error(`Telegram API ${res.status}: ${body}`), { status: 502 });
diff --git a/src/shared/usd-price.js b/src/shared/usd-price.js
index ef108fa10..f063af521 100644
--- a/src/shared/usd-price.js
+++ b/src/shared/usd-price.js
@@ -161,6 +161,54 @@ const BTC_FEEDS = [
},
];
+// ETH/USD across the same four independent feeds, for the surfaces that price
+// a stake or a balance in ether. Previously each caller made its own single
+// keyless CoinGecko call, so a throttle there (its free tier is shared per
+// egress IP) left USD figures blank next to real ETH amounts.
+const ETH_FEEDS = [
+ {
+ name: 'coingecko',
+ url: 'https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd',
+ parse: async (r) => asPrice((await r.json())?.ethereum?.usd),
+ },
+ {
+ name: 'coinbase',
+ url: 'https://api.coinbase.com/v2/prices/ETH-USD/spot',
+ parse: async (r) => asPrice((await r.json())?.data?.amount),
+ },
+ {
+ name: 'kraken',
+ url: 'https://api.kraken.com/0/public/Ticker?pair=ETHUSD',
+ parse: async (r) => asPrice((await r.json())?.result?.XETHZUSD?.c?.[0]),
+ },
+ {
+ name: 'llama',
+ url: 'https://coins.llama.fi/prices/current/coingecko:ethereum',
+ parse: async (r) => asPrice((await r.json())?.coins?.['coingecko:ethereum']?.price),
+ },
+];
+
+let _ethPrice = 0;
+let _ethPriceAt = 0;
+
+/**
+ * Live ETH/USD across four feeds. Returns null when all of them miss, so a
+ * caller hides the fiat estimate rather than printing an invented one.
+ *
+ * @returns {Promise<number|null>}
+ */
+export async function getEthPriceUsd() {
+ if (Date.now() - _ethPriceAt < CACHE_TTL_MS && _ethPrice > 0) return _ethPrice;
+ try {
+ const { value } = await fetchFirst(ETH_FEEDS, { timeoutMs: 4000, label: 'eth-price-client' });
+ _ethPrice = value;
+ _ethPriceAt = Date.now();
+ return _ethPrice;
+ } catch {
+ return _ethPrice > 0 ? _ethPrice : null;
+ }
+}
+
let _btcPrice = 0;
let _btcPriceAt = 0;