Skip to content

Commit

Permalink
clean up config
Browse files Browse the repository at this point in the history
  • Loading branch information
lochie committed Feb 1, 2024
1 parent 4b72e57 commit df9a5f4
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions packages/connectkit/src/defaultConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type CreateConnectorFn } from 'wagmi';
import { http } from 'wagmi';
import { type CreateConfigParameters } from '@wagmi/core';
import { mainnet, polygon, optimism, arbitrum } from 'wagmi/chains';

Expand All @@ -18,37 +18,44 @@ type DefaultConfigProps = {

// WC 2.0 requires a project ID (get one here: https://cloud.walletconnect.com/sign-in)
walletConnectProjectId: string;
} & CreateConfigParameters;
} & Partial<CreateConfigParameters>;

const defaultConfig = ({
appName = 'ConnectKit',
appIcon,
appDescription,
appUrl,
chains = [mainnet, polygon, optimism, arbitrum],
connectors,
walletConnectProjectId,

chains = [mainnet, polygon, optimism, arbitrum],
client,
...props
}: DefaultConfigProps): CreateConfigParameters => {
globalAppName = appName;
if (appIcon) globalAppIcon = appIcon;

// TODO: nice to have, automate transports based on chains
// TODO: nice to have, automate transports based on chains, but for now just provide public if not provided
const transports: CreateConfigParameters['transports'] =
props?.transports ??
Object.fromEntries(chains.map((chain) => [chain.id, http()]));

const connectors: CreateConfigParameters['connectors'] =
props?.connectors ??
defaultConnectors({
app: {
name: appName,
icon: appIcon,
description: appDescription,
url: appUrl,
},
walletConnectProjectId,
});

const config: CreateConfigParameters = {
const config: CreateConfigParameters<any, any> = {
...props,
chains,
connectors:
connectors ??
defaultConnectors({
app: {
name: appName,
icon: appIcon,
description: appDescription,
url: appUrl,
},
walletConnectProjectId,
}),
connectors,
transports,
};

return config;
Expand Down

0 comments on commit df9a5f4

Please sign in to comment.