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

refactor: Update OnchainKit and layout components #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
import type { Metadata } from 'next';
import { NEXT_PUBLIC_URL } from '../config';

import OnchainProviders from '../components/OnchainProviders';
import './global.css';
import '@coinbase/onchainkit/styles.css';
import '@rainbow-me/rainbowkit/styles.css';
import dynamic from 'next/dynamic';

const OnchainProviders = dynamic(
() => import('src/components/OnchainProviders'),
{
ssr: false,
},
);

export const viewport = {
width: 'device-width',
initialScale: 1.0,
};

export const metadata: Metadata = {
title: 'Onchain App Template',
description: 'Built with OnchainKit',
title: 'Chainable Guru',
description: 'Cross-Chain DeFi Platform',
openGraph: {
title: 'Onchain App Template',
description: 'Built with OnchainKit',
title: 'Chainable Guru',
description: 'Cross-Chain DeFi Platform',
images: [`${NEXT_PUBLIC_URL}/vibes/vibes-19.png`],
},
};

export default function RootLayout({
children,
}: { children: React.ReactNode }) {
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className="flex items-center justify-center">
<OnchainProviders>{children}</OnchainProviders>
<OnchainProviders>
{children}
</OnchainProviders>
</body>
</html>
);
Expand Down
91 changes: 72 additions & 19 deletions src/components/OnchainProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,84 @@
'use client';
import { OnchainKitProvider } from '@coinbase/onchainkit';
import { RainbowKitProvider } from '@rainbow-me/rainbowkit';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import type { ReactNode } from 'react';
import { base } from 'viem/chains';
import { WagmiProvider } from 'wagmi';
import { NEXT_PUBLIC_CDP_API_KEY } from '../config';
import { useWagmiConfig } from '../wagmi';

type Props = { children: ReactNode };
import { WagmiProvider } from 'wagmi';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { WagmiAdapter } from '@reown/appkit-adapter-wagmi';
import { SolanaAdapter } from '@reown/appkit-adapter-solana';
import { createAppKit } from '@reown/appkit/react';
import { useEffect, useState } from 'react';
import {
solana,
mainnet,
arbitrum,
polygon,
optimism,
base
} from '@reown/appkit/networks';
import { SolflareWalletAdapter, PhantomWalletAdapter } from '@solana/wallet-adapter-wallets';
import React from 'react';

// Create QueryClient
const queryClient = new QueryClient();

function OnchainProviders({ children }: Props) {
const wagmiConfig = useWagmiConfig();
// Define supported networks
const networks = [
mainnet,
arbitrum,
polygon,
optimism,
base,
solana
];

// Create Wagmi Adapter
const wagmiAdapter = new WagmiAdapter({
networks,
projectId: process.env.NEXT_PUBLIC_WC_PROJECT_ID || '',
ssr: true,
});

// Create Solana adapter
const solanaAdapter = new SolanaAdapter({
wallets: [new PhantomWalletAdapter(), new SolflareWalletAdapter()]
});

export default function OnchainProviders({ children }: { children: React.ReactNode }): JSX.Element {
const [mounted, setMounted] = useState(false);

useEffect(() => {
if (typeof window !== 'undefined') {
const metadata = {
name: 'Chainable Guru',
description: 'Cross-Chain DeFi Platform',
url: process.env.NEXT_PUBLIC_ENVIRONMENT || '',
icons: ['https://avatars.githubusercontent.com/u/179229932']
};

// Initialize AppKit with both adapters
createAppKit({
adapters: [wagmiAdapter, solanaAdapter],
networks,
projectId: process.env.NEXT_PUBLIC_WC_PROJECT_ID || '',
metadata,
features: {
onramp: true,
swaps: true
}
});

setMounted(true);
}
}, []);

if (!mounted) {
return null;
}

return (
<WagmiProvider config={wagmiConfig}>
<WagmiProvider config={wagmiAdapter.wagmiConfig}>
<QueryClientProvider client={queryClient}>
<OnchainKitProvider apiKey={NEXT_PUBLIC_CDP_API_KEY} chain={base}>
<RainbowKitProvider modalSize="compact">
{children}
</RainbowKitProvider>
</OnchainKitProvider>
{children}
</QueryClientProvider>
</WagmiProvider>
);
}

export default OnchainProviders;
19 changes: 15 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es2020",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand All @@ -11,7 +15,7 @@
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"jsx": "preserve",
"incremental": true,
"plugins": [
{
Expand All @@ -20,6 +24,13 @@
],
"baseUrl": "."
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}