@@ -47,7 +47,6 @@ export function App() {
4747 const [ lastTxReceipt , setLastTxReceipt ] = useState < TransactionReceipt | null > ( null ) ;
4848 const [ lastTxHash , setLastTxHash ] = useState < string | null > ( null ) ;
4949
50- const pollRef = useRef < number | null > ( null ) ;
5150 const lastPendingIdRef = useRef < string | null > ( null ) ;
5251
5352 const walletClient = useMemo ( ( ) => {
@@ -112,6 +111,8 @@ export function App() {
112111 } catch { }
113112 } , [ ensureServerConnected , pending ] ) ;
114113
114+ const pollFnRef = useRef < ( ) => void > ( ( ) => { } ) ;
115+
115116 const connect = async ( ) => {
116117 if ( ! walletClient || ! selected ) return ;
117118
@@ -232,13 +233,15 @@ export function App() {
232233 useEffect ( ( ) => {
233234 ( async ( ) => {
234235 if ( ! selected ) return ;
236+
235237 try {
236238 const raw = await selected . provider . request < string > ( { method : "eth_chainId" } ) ;
237239 applyChainId ( raw , setChainId , setChain ) ;
238240 } catch {
239241 setChainId ( undefined ) ;
240242 setChain ( undefined ) ;
241243 }
244+
242245 if ( walletClient ) {
243246 try {
244247 const addrs = await getAddresses ( walletClient ) ;
@@ -250,22 +253,24 @@ export function App() {
250253 } ) ( ) ;
251254 } , [ selected , walletClient ] ) ;
252255
256+ useEffect ( ( ) => {
257+ pollFnRef . current = ( ) => {
258+ void pollTick ( ) ;
259+ } ;
260+ } , [ pollTick ] ) ;
261+
253262 // Polling loop to check for new pending transactions.
254263 useEffect ( ( ) => {
255- void pollTick ( ) ;
264+ pollFnRef . current ( ) ;
256265
257- if ( ! pollRef . current ) {
258- pollRef . current = window . setInterval ( pollTick , 1000 ) ;
259- }
266+ const id = window . setInterval ( ( ) => {
267+ pollFnRef . current ( ) ;
268+ } , 1000 ) ;
260269
261270 return ( ) => {
262- if ( pollRef . current ) {
263- window . clearInterval ( pollRef . current ) ;
264- }
265-
266- pollRef . current = null ;
271+ window . clearInterval ( id ) ;
267272 } ;
268- } , [ pollTick ] ) ;
273+ } , [ ] ) ;
269274
270275 return (
271276 < div className = "wrapper" >
0 commit comments