Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] WagmiAdapter to correctly infer wagmiConfig type #3224

Open
AzzouQ opened this issue Nov 9, 2024 · 2 comments
Open

[bug] WagmiAdapter to correctly infer wagmiConfig type #3224

AzzouQ opened this issue Nov 9, 2024 · 2 comments
Labels
bug Something isn't working needs review

Comments

@AzzouQ
Copy link

AzzouQ commented Nov 9, 2024

Link to minimal reproducible example

https://stackblitz.com/edit/viem-getting-started-dqqqdr?file=index.ts

Summary

When using the WagmiAdapter, we can access the wagmi config by doing wagmiAdapter.wagmiConfig as stated in the documentation . However, wagmiAdapter.wagmiConfig doesn't leverage generics from wagmi's createConfig.

import { WagmiAdapter } from '@reown/appkit-adapter-wagmi';
import { createConfig, http } from 'wagmi';
import { arbitrum, sepolia } from 'viem/chains';

const wagmiAdapter = new WagmiAdapter({
  projectId: process.env.NEXT_PUBLIC_REOWN_PROJECT_ID!,
  networks: [arbitrum, sepolia],
});

// Poorly typed: Config
wagmiAdapter.wagmiConfig;

const config = createConfig({
  chains: [arbitrum, sepolia],
  transports: {
    [arbitrum.id]: http(),
    [sepolia.id]: http(),
  },
});

// Strongly typed: Config<chains, transport>
config;

declare module 'wagmi' {
  interface Register {
    config: typeof wagmiAdapter.wagmiConfig; // Won't work because the type is not correctly inferred
  }
}

Doing so prevent strong type-safety as stated in wagmi's documentation.

Could it be possible for the WagmiAdapter to take those in consideration ?

List of related npm package versions

@reown/appkit: ^1.3.1
@reown/appkit-adapter-wagmi: ^1.3.1
viem: 2.21.44
wagmi: 2.12.29

@AzzouQ AzzouQ added bug Something isn't working needs review labels Nov 9, 2024
@AzzouQ
Copy link
Author

AzzouQ commented Nov 9, 2024

I'm actually using the following workaround to mimic wagmi's createConfig behavior in WagmiAdapter

declare class WagmiAdapter<
  const networks extends readonly [AppKitNetwork, ...AppKitNetwork[]]
> implements ChainAdapter {
  public wagmiChains: networks;
  public wagmiConfig: AdapterOptions<Config<networks>>['wagmiConfig'];
  public constructor(configParams: Partial<CreateConfigParameters> & {
    networks: networks;
    projectId: string;
});

It does the tricks for me since I only use Viem's chain, but I guess it wouldn't work with the Solana network.

@AzzouQ
Copy link
Author

AzzouQ commented Nov 9, 2024

May be related to #2823

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs review
Projects
None yet
Development

No branches or pull requests

1 participant