2025-10-23 12:16:25 +05:30
|
|
|
import React from "react";
|
|
|
|
|
import { OpChanClient, type OpChanClientConfig } from "@opchan/core";
|
|
|
|
|
import { ClientProvider } from "../context/ClientContext";
|
|
|
|
|
import { StoreWiring } from "./StoreWiring";
|
|
|
|
|
import { WalletAdapterInitializer } from "./WalletAdapterInitializer";
|
|
|
|
|
import { AppKitProvider } from "@reown/appkit/react";
|
|
|
|
|
import { WagmiProvider } from "wagmi";
|
|
|
|
|
import { appkitConfig, config as wagmiConfig } from "@opchan/core";
|
|
|
|
|
import { AppKitErrorBoundary } from "../components/AppKitErrorBoundary";
|
|
|
|
|
|
|
|
|
|
export interface OpChanProviderProps {
|
2025-09-25 21:52:40 +05:30
|
|
|
config: OpChanClientConfig;
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-23 12:16:25 +05:30
|
|
|
* OpChan provider that constructs the OpChanClient and provides wallet context.
|
2025-10-28 11:29:21 +05:30
|
|
|
* This component already wraps WagmiProvider and AppKitProvider internally,
|
|
|
|
|
* so you can mount it directly at your app root with the required config.
|
2025-09-25 21:52:40 +05:30
|
|
|
*/
|
2025-10-23 12:16:25 +05:30
|
|
|
export const OpChanProvider: React.FC<OpChanProviderProps> = ({
|
|
|
|
|
config,
|
|
|
|
|
children,
|
|
|
|
|
}) => {
|
2025-09-25 21:52:40 +05:30
|
|
|
const [client] = React.useState(() => new OpChanClient(config));
|
|
|
|
|
|
|
|
|
|
return (
|
2025-10-23 12:16:25 +05:30
|
|
|
<WagmiProvider config={wagmiConfig}>
|
|
|
|
|
<AppKitErrorBoundary>
|
|
|
|
|
<AppKitProvider {...appkitConfig}>
|
|
|
|
|
<ClientProvider client={client}>
|
|
|
|
|
<WalletAdapterInitializer />
|
|
|
|
|
<StoreWiring />
|
|
|
|
|
{children}
|
|
|
|
|
</ClientProvider>
|
|
|
|
|
</AppKitProvider>
|
|
|
|
|
</AppKitErrorBoundary>
|
|
|
|
|
</WagmiProvider>
|
2025-09-25 21:52:40 +05:30
|
|
|
);
|
|
|
|
|
};
|