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

Update submodule content #5

Open
wants to merge 1 commit into
base: master
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
45 changes: 43 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/public/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Core DAO Dapp tutorial</title>
<meta name="description" content="Core DAO DApp tutorial for building decentralized applications" />
<meta name="keywords" content="Core DAO, DApp, tutorial, decentralized applications, blockchain, Ethereum" />
<meta name="author" content="Your Name" />
<title>Core DAO DApp Tutorial</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" integrity="sha384-oSr3XRZI7DrZ9MXj40zC4iJXyo5U+E2Gx5Vbdk6y3vbC5Ij8is5u8gqfvTjDUfFr" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha384-k6RqeWeci5ZR/Lv4MR0sA0FfDOMUuAU8cd6rqfHfK6H7yNiHzBttC6vj9IG5DQDz" crossorigin="anonymous" />
<link rel="stylesheet" href="src/style/index.css" />
</head>
<body>
<div id="root"></div>
<div id="root" aria-live="polite">
<div id="loading-spinner" aria-hidden="true">
<i class="fas fa-spinner fa-spin"></i>
</div>
</div>
<script type="module" src="/src/index.tsx"></script>
<script>
// Load the Web3 library if not already loaded
if (typeof web3 === 'undefined') {
const script = document.createElement('script');
script.src = "https://cdnjs.cloudflare.com/ajax/libs/web3/1.3.6/web3.min.js";
script.integrity = "sha384-QC0BuCGs3rZ4z7OaO3EHe0dVmyMwi+PjqiySEbFlx2YkQvJ8lLgPZR6KZJ1CzAIG";
script.crossOrigin = "anonymous";
document.head.appendChild(script);
}

// Hide loading spinner once the app is loaded
window.addEventListener('load', () => {
const spinner = document.getElementById('loading-spinner');
if (spinner) {
spinner.setAttribute('aria-hidden', 'true');
spinner.style.display = 'none';
}
});

// Service Worker for offline capabilities
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/src/public/service-worker.js').then((registration) => {
console.log('Service Worker registered with scope:', registration.scope);
}).catch((error) => {
console.log('Service Worker registration failed:', error);
});
});
}
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"@vitejs/plugin-react": "^2.0.0",
"autoprefixer": "^10.4.7",
"autoprefixer": "^10.4.19",
"babel-jest": "^28.1.3",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -38,9 +38,9 @@
"eslint-plugin-tailwindcss": "^3.6.0",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"postcss": "^8.4.14",
"postcss": "^8.4.39",
"prettier": "2.7.1",
"tailwindcss": "^3.1.6",
"tailwindcss": "^3.4.4",
"typescript": "^4.7.4",
"vite": "^3.0.0",
"vite-tsconfig-paths": "^3.5.0"
Expand Down
58 changes: 58 additions & 0 deletions src/WalletConnect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, { useState, useEffect } from 'react';
import { ethers } from 'ethers';

const WalletConnect: React.FC = () => {
const [account, setAccount] = useState<string | null>(null);
const [provider, setProvider] = useState<ethers.providers.Web3Provider | null>(null); // State to hold ethers provider

const connectWallet = async () => {
const { ethereum } = window as any;

if (ethereum) {
try {
const accounts: string[] = await ethereum.request({ method: 'eth_requestAccounts' });
setAccount(accounts[0]);
const newProvider = new ethers.providers.Web3Provider(ethereum);
setProvider(newProvider); // Set ethers provider after connection
} catch (error) {
console.error("Error connecting to wallet:", error);
}
} else {
alert("Please install MetaMask or another wallet provider.");
}
};

useEffect(() => {
const { ethereum } = window as any;

if (ethereum) {
const handleAccountsChanged = (accounts: string[]) => {
setAccount(accounts[0] || null); // Set the first account or null if disconnected
};

const handleChainChanged = (chainId: string) => {
console.log("Chain changed to:", chainId);
};

ethereum.on('accountsChanged', handleAccountsChanged);
ethereum.on('chainChanged', handleChainChanged);

return () => {
ethereum.removeListener('accountsChanged', handleAccountsChanged);
ethereum.removeListener('chainChanged', handleChainChanged);
};
}
}, []);

return (
<div>
{account ? (
<p>Connected account: {account}</p>
) : (
<button onClick={connectWallet}>Connect Wallet</button>
)}
</div>
);
};

export default WalletConnect;
Loading