Skip to content

[Bug] Story detail page fires repeated RPC calls — needs batching or debounce #396

@realproject7

Description

@realproject7

Summary

The story detail page (`/story/[id]`) fires multiple individual RPC calls from TradingWidget that trigger 429 rate limits. The home page was fixed with multicall (#392), but the story page was not addressed.

Sources of RPC calls on story detail page

From `TradingWidget.tsx`:

  • Line 45: `balanceOf` — polls every 15s (`refetchInterval: 15000`)
  • Line 61: `getReserveForToken` / `getRefundForTokens` — polls every 15s
  • Line 87: `allowance` — called during trade execution
  • Lines 102, 117, 138, 152: `waitForTransactionReceipt` — during trade execution

From story page SSR (`page.tsx`):

  • `getTokenPrice()` — 2 calls (priceForNextMint + totalSupply)

The balance and estimate queries both poll every 15 seconds, generating continuous RPC traffic.

Fix Options

Option A: Reduce polling frequency (quick fix)

  • Increase `refetchInterval` from 15s to 60s for balance and estimate
  • Only poll when the trade panel is open / user has entered an amount

Option B: Batch balance + estimate into one multicall

```typescript
const { data } = useQuery({
queryKey: ["trade-data", tokenAddress, address, tab, amount],
queryFn: async () => {
const results = await browserClient.multicall({
contracts: [
{ address: balanceToken, abi: erc20Abi, functionName: "balanceOf", args: [address!] },
{ address: MCV2_BOND, abi: mcv2BondAbi, functionName: tab === "buy" ? "getReserveForToken" : "getRefundForTokens", args: [tokenAddress, parsedAmount] },
],
allowFailure: true,
});
return { balance: results[0].result, estimate: results[1].result };
},
refetchInterval: 30000,
});
```

2 RPC calls → 1 multicall. Polling reduced to 30s.

Option C: Only fetch estimate on input change (no polling)

  • Remove `refetchInterval` from estimate query
  • Only refetch when `amount` changes (already handled by queryKey)
  • Keep balance polling at 60s

Recommendation: Option C + multicall

Combine estimate + balance into one multicall, only re-fetch when amount changes (no polling for estimate), and poll balance every 60s.

Acceptance Criteria

  • No 429 errors on story detail page during normal browsing
  • Balance and estimate still update when relevant (amount change, after trade)
  • Reduce unnecessary polling
  • `npm run typecheck` passes

Branch

`task/{issue-number}-trading-rpc-batch`

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/T3Assigned to T3 builder agentbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions