Skip to content

missing array dependency useMemo hook creating contractClient only depends on [chainId] Results in older reference #57

@aniket866

Description

@aniket866

Where ? : components/swap/swap-interface.tsx

• A user opens the app and everything works normally
• The app creates a helper that talks to the blockchain
• That helper is built using the current wallet connection
• The wallet disconnects and reconnects in the background
• A new provider is created by the wallet
• The app keeps using the old helper without realizing it
• The old helper is still pointing to a dead connection
• The user clicks swap
• The call goes to the old provider
• The request fails even though the wallet looks connected
• This happens because the helper was never rebuilt
• Once the helper is recreated with the new provider
• All contract calls start working again

fix:

const contractClient = useMemo(
    () => new ContractClient(writeContractAsync, publicClient, chainId),
    `[chainId, writeContractAsync, publicClient]` // FIX: Add missing dependencies
  );

@kaneki003 Please checkout this solution: #56

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions