-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
259 lines (231 loc) · 9.05 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web3 Profile App</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/web3/dist/web3.min.js"></script>
<style>
body {
background-color: #2b2b2b;
font-family: Arial, sans-serif;
color: #e0c7ff;
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
nav {
position: absolute;
top: 20px;
left: 20px;
}
nav a {
color: #e0c7ff;
margin: 0 10px;
text-decoration: none;
font-size: 18px;
transition: color 0.3s ease;
}
nav a:hover {
color: #a389d4;
}
.container {
background: #383838;
border-radius: 10px;
padding: 30px;
width: 400px;
display: none;
animation: fadeIn 0.7s ease-out;
}
.active {
display: block;
}
.btn-primary, .btn-success {
background-color: #7d5fb2;
border: none;
transition: background-color 0.3s ease;
}
.btn-primary:hover, .btn-success:hover {
background-color: #a389d4;
}
.nodes-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #2b2b2b;
overflow: hidden;
z-index: -1;
}
canvas {
display: block;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
</style>
</head>
<body>
<!-- Navigation Links -->
<nav>
<a href="#" onclick="showPage('home')">Home</a>
<a href="#" onclick="showPage('about')">About</a>
<a href="#" onclick="showPage('profile')">Profile</a>
</nav>
<!-- Logo -->
<img src="https://bafkreihilb2p2y2s7tpbkwhm4xio4kok7h23jntxijj3mesvhlghgdgede.ipfs.flk-ipfs.xyz" alt="Logo" style="position: absolute; top: 10px; right: 10px; width: 60px; height: 60px;">
<!-- Home Page -->
<div id="home" class="container active animate__animated animate__fadeIn">
<h1 class="text-center">Web3 Profile Management</h1>
<button id="connectButton" class="btn btn-primary btn-block">Connect Wallet</button>
<div id="profileForm" class="mt-3" style="display: none;">
<h2>Your Profile</h2>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" class="form-control">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" class="form-control">
</div>
<button id="saveButton" class="btn btn-success btn-block">Save Profile</button>
</div>
</div>
<!-- About Page -->
<div id="about" class="container">
<h1 class="text-center">About Web3 App</h1>
<p>This app demonstrates a simple Web3 profile management interface using a connected Ethereum wallet. You can store your profile locally and interact with your blockchain wallet.</p>
</div>
<!-- Profile Page -->
<div id="profile" class="container">
<h1 class="text-center">Your Profile</h1>
<div id="profileInfo" style="color: #e0c7ff;"></div>
</div>
<!-- Networking Nodes Animation (About Page) -->
<div class="nodes-bg" id="networking-nodes">
<canvas id="networkCanvas"></canvas>
</div>
<script>
let web3;
let userAddress;
// Connect Wallet
document.getElementById('connectButton').onclick = async () => {
// Check if the Ethereum provider (MetaMask) is available
if (typeof window.ethereum !== 'undefined') {
try {
// Initialize a Web3 instance using the provided provider (MetaMask)
web3 = new Web3(window.ethereum);
// Request access to the user's accounts
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
// Get the first account (default account)
userAddress = accounts[0];
// Display the connected wallet address
document.getElementById('connectButton').innerText = `Connected: ${userAddress}`;
// Save user profile in local storage (optional)
loadProfile();
// Redirect to profile page after successful connection
window.location.href = "https://test.com/profile"; // Change this to your desired URL
} catch (error) {
console.error("User denied account access or other error:", error);
alert("Failed to connect to wallet. Please try again.");
}
} else {
alert('No Ethereum provider detected. Please install MetaMask!');
}
};
// Save profile to localStorage
document.getElementById('saveButton').onclick = () => {
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
// Store profile in localStorage
const profile = { address: userAddress, name, email };
localStorage.setItem(userAddress, JSON.stringify(profile));
alert('Profile saved!');
};
// Load profile from localStorage
function loadProfile() {
const profile = localStorage.getItem(userAddress);
if (profile) {
const { name, email } = JSON.parse(profile);
document.getElementById('name').value = name || '';
document.getElementById('email').value = email || '';
document.getElementById('profileInfo').innerHTML = `
<p><strong>Address:</strong> ${userAddress}</p>
<p><strong>Name:</strong> ${name || 'N/A'}</p>
<p><strong>Email:</strong> ${email || 'N/A'}</p>`;
}
}
// Show different pages
function showPage(page) {
document.querySelectorAll('.container').forEach(container => container.classList.remove('active'));
document.getElementById(page).classList.add('active');
}
// Networking nodes animation
const canvas = document.getElementById("networkCanvas");
const ctx = canvas.getContext("2d");
let width = canvas.width = window.innerWidth;
let height = canvas.height = window.innerHeight;
let particles = [];
let numParticles = 100;
function createParticle() {
return {
x: Math.random() * width,
y: Math.random() * height,
vx: (Math.random() - 0.5) * 2,
vy: (Math.random() - 0.5) * 2,
radius: 2
};
}
for (let i = 0; i < numParticles; i++) {
particles.push(createParticle());
}
function updateParticles() {
ctx.clearRect(0, 0, width, height);
particles.forEach(p => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0 || p.x > width) p.vx *= -1;
if (p.y < 0 || p.y > height) p.vy *= -1;
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2);
ctx.fillStyle = "#e0c7ff";
ctx.fill();
});
connectParticles();
}
function connectParticles() {
for (let i = 0; i < numParticles; i++) {
for (let j = i + 1; j < numParticles; j++) {
let dx = particles[i].x - particles[j].x;
let dy = particles[i].y - particles[j].y;
let distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 100) {
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.strokeStyle = "#7d5fb2";
ctx.lineWidth = 0.5;
ctx.stroke();
}
}
}
}
function loop() {
updateParticles();
requestAnimationFrame(loop);
}
loop();
window.onresize = function () {
width = canvas.width = window.innerWidth;
height = canvas.height = window.innerHeight;
};
</script>
</body>
</html>