perf(ux): useNewTable sleeps 2s for tx indexer — replace with WS event or backoff poll

Aperta
#431 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #748 di @Dzeezbtc — chiusa senza merge

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

enhancement UI

Severity: UX bug — 2 seconds of UI dead time on every table creation, for no good reason.

Where

`src/hooks/game/useNewTable.ts:134`

```ts
if (txHash) {
setNewGameId(txHash);
const cosmosClient = getCosmosClient(currentNetwork);
if (!cosmosClient) return null;

// Wait a moment for the transaction to be indexed
await new Promise(resolve => setTimeout(resolve, 2000));

let tx;
try {
    tx = await cosmosClient.getTx(txHash);
} catch (_txError) {
    // Indexer hiccup — tx is on-chain but we couldn't fetch it.
    return { txHash, gameId: null };
}
...

}
```

What's happening

Cosmos returns the tx hash from `broadcastTx` before the indexer has fully recorded the tx, so an immediate `getTx(hash)` can 404. The author sleeps 2s and hopes.

Why this is wrong

  • 2s is a guess, not a guarantee. Under chain load it might not be enough — the `getTx` falls through into the catch block (`return { txHash, gameId: null }`), and the user gets a partial result anyway.
  • Under normal conditions you're paying 2s of UI dead time for nothing. The indexer is almost certainly ready in <500ms; the user just stares at a spinner for the remaining 1.5s.
  • The catch block already handles the 404 case. So the sleep is a coin flip between "too short and falls into the catch anyway" and "too long and the UI hangs."

Proposed fix

Option A (preferred): poll with backoff

Try `getTx` immediately. If it 404s, retry with backoff (e.g., 200ms, 500ms, 1s, 2s), capped at ~5s total. Returns the moment the indexer has the tx, which is usually well under the current 2s sleep.

```ts
async function getTxWithBackoff(client, hash, totalBudgetMs = 5000) {
const delays = [0, 200, 500, 1000, 2000];
const start = Date.now();
for (const delay of delays) {
if (Date.now() - start + delay > totalBudgetMs) break;
if (delay > 0) await new Promise(r => setTimeout(r, delay));
try {
return await client.getTx(hash);
} catch {
// 404 — indexer not ready yet, retry
}
}
return null;
}
```

Option B: subscribe via WebSocket

We already subscribe to chain events for tables. The new-game-created event will arrive over the WS faster than any REST polling. Wire that signal into the table-creation flow and skip the `getTx` round trip entirely.

Option B is the architecturally correct fix (aligns with the WS-first principle from #421) but requires plumbing the new-game event through whichever subscription handles it. Option A is the smaller change and gets the immediate UX win.

Acceptance criteria

  • No fixed-duration `setTimeout` sleep before `getTx`
  • Median table-creation completes in <500ms (vs current ~2s+)
  • Worst-case behaviour under a slow indexer is the same or better than today (i.e., still falls through to `{ txHash, gameId: null }` after a reasonable budget)
  • No regression on the "chain accepted but message failed" path (the `code !== 0` check below the sleep)

Related

Part of #421 (FE CPU umbrella). Surfaced alongside #(auto-action race bug) while auditing `setTimeout` usage.

Lingua principale
TypeScript
Stelle
2
Fork
5
Merge medio
23h 23m
PR unite (30g)
97

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di block52/ui

Tutte le issue di block52/ui

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.