-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Labels
enhancementNew feature or requestNew feature or request
Description
What problem does this new feature solve?
The switchNetwork function requires an AppKitNetwork, but the networks exported from '@reown/appkit/networks' are not in the AppKitNetwork format.
I noticed that AppKit internally formats these networks and attaches them to this.networks, but unfortunately, this data is not exported.
As a result, I have to manually reformat the imported network from '@reown/appkit/networks' like this
appKitNetwork: { ...arbitrum, chainNamespace: 'eip155', caipNetworkId: 'eip155:42161' }
This approach is less than ideal and feels a bit clunky. I’m opening this issue to propose exporting the appKit instance, so developers can directly access the data and functions it provides.
Describe the solution you'd like
export const useAppKit = (): UseAppKitReturn => {
const context = useContext(AppKitContext);
if (context === undefined) {
throw new Error('useAppKit must be used within an AppKitProvider');
}
if (!context.appKit) {
// This might happen if the provider is rendered before AppKit is initialized
throw new Error('AppKit instance is not yet available in context.');
}
const { appKit } = context;
const stableFunctions = useMemo(() => {
if (!context.appKit) {
throw new Error('AppKit instance is not available');
}
return {
open: context.appKit.open.bind(context.appKit),
close: context.appKit.close.bind(context.appKit),
disconnect: (namespace?: ChainNamespace) =>
context.appKit!.disconnect.bind(context.appKit!)(namespace),
switchNetwork: context.appKit.switchNetwork.bind(context.appKit),
};
}, [context.appKit]);
return { appkit, ...stableFunctions };
};Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request