Main
File Structure
// Import dependencies
import React, { useState, useRef, useEffect } from 'react';
import ReactDOM from 'react-dom/client';
import { backend } from 'declarations/backend';
import botImg from '/bot.svg';
import userImg from '/user.svg';
import Sidebar from './components/Sidebar';
import ChatWindow from './components/ChatWindow';
import '/index.css';
import { createThirdwebClient } from "thirdweb";
import { client } from "./../config/client";
import { useProfiles, useActiveAccount, ConnectButton, ThirdwebProvider } from "thirdweb/react";
// Wallet connection component
export function WalletConnectComponent() {
const account = useActiveAccount();
useEffect(() => {
if (account) {
const address = account.address;
console.log("Wallet connected:", address);
backend.create_account(address)
.then(() => console.log("Account registered"))
.catch(err => console.error("Failed to register:", err));
}
}, [account]);
return <ConnectButton client={client} />;
}
// Main App component
function App() {
return (
<div className="flex h-screen dark bg-zinc-900 text-white">
<ChatWindow />
<div className="w-64 bg-zinc-800 p-4 flex flex-col">
<WalletConnectComponent />
</div>
</div>
);
}
// Root rendering
export default App;
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<ThirdwebProvider client={client}>
<App />
</ThirdwebProvider>
</React.StrictMode>
);Core Components
1. WalletConnectComponent
WalletConnectComponentHandles cryptocurrency wallet connection and account registration.
useActiveAccount()
Thirdweb hook for detecting connected wallets
useEffect()
Triggers when wallet connection state changes
backend.create_account()
Creates user account on Internet Computer canister
<ConnectButton>
Renders wallet connection UI (Metamask, Coinbase, etc.)
2. App Component
App ComponentMain application layout and structure.
<div className="flex...">
Main container with dark mode styling
<ChatWindow />
Primary chat interface component
<WalletConnectComponent>
Sidebar wallet connection/management
3. Root Rendering
Initializes the React application.
<React.StrictMode>
Development checks for potential problems
<ThirdwebProvider>
Provides wallet context to all components
client={client}
Thirdweb configuration (from ./config/client)
Key Features
Wallet Integration:
Automatic account creation on wallet connection
Supports Ethereum-compatible wallets (Metamask, WalletConnect, etc.)
Seamless integration with Internet Computer backend
UI Structure:
Responsive layout using Tailwind CSS
Dark mode styling (
bg-zinc-900,text-white)Component-based architecture
Backend Communication:
Uses
declarations/backendfor canister interactionAutomatic account registration via
create_account()method
Dependencies
thirdweb/react
Crypto wallet connection and Web3 functionality
react-dom
DOM rendering for React components
declarations/backend
Generated interface for Internet Computer canister
tailwindcss
CSS styling framework
Customization Guide
1. Add Wallet Information Display
2. Enhance Error Handling
3. Add Multi-Chain Support
4. Implement Loading States
Last updated