From 0abd2ef109bd80e72a72c462fd92212f1bf46a1a Mon Sep 17 00:00:00 2001 From: Bhupendra Chouhan <78025043+bhupendra-chouhan@users.noreply.github.com> Date: Sat, 4 Jan 2025 21:50:11 +0530 Subject: [PATCH] Added 'Connect Wallet' feature: Access website only after connecting via MetaMask. (#560) --- connectwallet.js | 69 + index.html | 4088 +++++++++++++++++++++++----------------------- 2 files changed, 2132 insertions(+), 2025 deletions(-) create mode 100644 connectwallet.js diff --git a/connectwallet.js b/connectwallet.js new file mode 100644 index 0000000..60c4167 --- /dev/null +++ b/connectwallet.js @@ -0,0 +1,69 @@ +document.addEventListener("DOMContentLoaded", function () { + const connectButton = document.getElementById("connectButton"); + const mainContent = document.getElementById("mainContent"); + const errorMessage = document.getElementById("errorMessage"); + const walletAddress = document.getElementById("walletAddress"); + + // Add hover effect for button + connectButton.addEventListener("mouseover", function () { + this.style.backgroundColor = "#45a049"; + }); + connectButton.addEventListener("mouseout", function () { + this.style.backgroundColor = "#4CAF50"; + }); + + // Check if MetaMask is installed + const isMetaMaskInstalled = () => { + return typeof window.ethereum !== "undefined" && window.ethereum.isMetaMask; + }; + + // Function to format address + function formatAddress(address) { + return `${address.slice(0, 4)}...${address.slice(-4)}`; + } + + // Connect Wallet Function + async function connectWallet() { + if (!isMetaMaskInstalled()) { + errorMessage.style.display = "block"; + return; + } + + try { + // Request account access + const accounts = await window.ethereum.request({ + method: "eth_requestAccounts", + }); + + if (accounts.length > 0) { + // Hide connect button and show main content + connectButton.style.display = "none"; + mainContent.style.display = "block"; + + // Display formatted wallet address + const connectedAccount = accounts[0]; + walletAddress.textContent = formatAddress(connectedAccount); + console.log("Connected account:", connectedAccount); + } + } catch (error) { + console.error("Error connecting wallet:", error); + } + } + + // Add click event listener to connect button + connectButton.addEventListener("click", connectWallet); + + // Handle account changes + if (window.ethereum) { + window.ethereum.on("accountsChanged", function (accounts) { + if (accounts.length === 0) { + // User disconnected their wallet + connectButton.style.display = "block"; + mainContent.style.display = "none"; + } else { + // Update displayed address when account changes + walletAddress.textContent = formatAddress(accounts[0]); + } + }); + } +}); diff --git a/index.html b/index.html index 7404c2e..bd6ed99 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - +
@@ -10,2172 +10,2210 @@ - - -- Empower Your Blockchain & Open-Source Journey with India's Largest Community Of Enthusiast People. We are - Bridging the Gap between Tech Industry & Student Communities, Platform for Students to Learn new Skills, - Network With Industry Professionals and grow as an individual. -
- -- A Place where you can Learn, meet passionate individuals, Build Real World Products, and Grow as an - Individual. -
-- Assisting Startups & Providing them a MarketPlace. Helping Web3 Enthusiast to become a Blockchain - Developer. -
-- Helping Developers & Organizations to Levrage the Power Of Open Source & Expand their Horizon. -
-- Connecting with Diverse Communities Of Creative Minds to Network, Share Ideas, and Gain Valuable - Insights. -
-- Collaborating with Different Tech Communities & Helping them Grow together. -
-- Empowering Campuses with Industry Experts & Giving Real World Exposure. -
-- Making Knowledge Accessible amongst Developers in our Events. -
-- Empowering Every Individual Because You dont Need Fancy Tags to Make an Impact :) -
-+ Empower Your Blockchain & Open-Source Journey with India's Largest Community Of Enthusiast People. + We are + Bridging the Gap between Tech Industry & Student Communities, Platform for Students to Learn new + Skills, + Network With Industry Professionals and grow as an individual. +
+- - It’s a community for learners by learners. The vision of this community is to build an environment - where people can learn, implement and grow together. It provides people the opportunity to work with - peers, showcase their talent and enhance their skills by working in-team. We promote Open source, - Web3, Web dev culture through our community. #letstakeyouforward - -
- We are on a mission to empower the next generation to discover better ways to Learn, Earn, and - Network! Helping Startups & Organizations to build a Community around their Product -
- -- Be Bold: Don't be afraid Of what other's say, don't wait for anyone's permission- If you want - to get it dont then do it!! -
-- Collaboration >> Competition: Great things happen when people come together!! -
-- The people who're Consistently Pushing Their Limits to Take Eduhub to Next Level. -
-+ A Place where you can Learn, meet passionate individuals, Build Real World Products, and Grow as an + Individual. +
++ Assisting Startups & Providing them a MarketPlace. Helping Web3 Enthusiast to become a Blockchain + Developer. +
++ Helping Developers & Organizations to Levrage the Power Of Open Source & Expand their Horizon. +
++ Connecting with Diverse Communities Of Creative Minds to Network, Share Ideas, and Gain Valuable + Insights. +
+- Co-Founder -
-+ Collaborating with Different Tech Communities & Helping them Grow together. +
++ Empowering Campuses with Industry Experts & Giving Real World Exposure. +
++ Making Knowledge Accessible amongst Developers in our Events. +
+- Co-Founder +
+ Empowering Every Individual Because You dont Need Fancy Tags to Make an Impact :)
- Even though the number of initiatives we've taken is quite high and not enough to display here, but still - let's - have a glimpse :) -
-+ + It’s a community for learners by learners. The vision of this community is to build an + environment + where people can learn, implement and grow together. It provides people the opportunity to + work with + peers, showcase their talent and enhance their skills by working in-team. We promote Open + source, + Web3, Web dev culture through our community. #letstakeyouforward - -
+ We are on a mission to empower the next generation to discover better ways to Learn, Earn, and + Network! Helping Startups & Organizations to build a Community around their Product +
- ++ The people who're Consistently Pushing Their Limits to Take Eduhub to Next Level. +
- Let's have a look at what does an average Eduhub Member say about us 🤔? -
-- “Eduhub is really a lovely community. I’ve learned many skills and networked with many people - because of - the community. Keep up the good work -
- -- Systems Engineer @Tata Consultancy Service. +
+ Co-Founder
- “I can't express how grateful I am to be a part of this incredible community. It's not just a - group; it's a support system, a source of inspiration, and a place to thrive. They are very good - at commitments and deliver some amazing results to the organization. -
- -- Developer Relations Engineer @Nordek. +
+ Co-Founder
+ Even though the number of initiatives we've taken is quite high and not enough to display here, but + still + let's + have a glimpse :)
- Contact our team to get a quote. -
-- Below Given Our Some Of The Blogs Written about Different Technologies Like- Open Source, Blockchain - Development, Web Development, etc. -
-
-
-
-
-
-
-
-
-
-
-
-
-
- Let's have a coffee meet and discuss an idea roaming in your mind ☕️! -
+- support@eduhubcommunity.tech -
-- Jaipur, Rajasthan, India. -
-+ Let's have a look at what does an average Eduhub Member say about us 🤔? +
+ “Eduhub is really a lovely community. I’ve learned many skills and networked with many + people + because of + the community. Keep up the good work +
+ ++ Systems Engineer @Tata Consultancy Service. +
++ “I can't express how grateful I am to be a part of this incredible community. It's not just + a + group; it's a support system, a source of inspiration, and a place to thrive. They are very + good + at commitments and deliver some amazing results to the organization. +
+ ++ Developer Relations Engineer @Nordek. +
+-