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

Đang mở
#431 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #748 của @Dzeezbtc — đã đóng, không merge

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
2
Fork
5
Merge trung bình
23 giờ 23 phút
Pull request đã merge (30 ngày)
97

Chuẩn bị môi trường

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của block52/ui

Tất cả issue của block52/ui

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.