-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwallet.html
More file actions
157 lines (134 loc) · 5.71 KB
/
wallet.html
File metadata and controls
157 lines (134 loc) · 5.71 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wallet Details</title>
<link rel="stylesheet" href="style.css">
<script src="https://unpkg.com/ethers@5.7.2/dist/ethers.umd.min.js"></script>
</head>
<body>
<section id="header">
<div id="logo">
<a href="index.html"><img src="img/logo.png" alt="logo"></a>
<span>Confy</span>
</div>
<ul id="navbar">
<li> <a href="index.html">Home</a></li>
<li> <a href="video.html">Videos</a></li>
<li> <a class="active" href="wallet.html">Wallet</a></li>
</ul>
</section>
<div id="wallet-details" class="section-p1">
<h2>Your Wallet Details</h2>
<p><strong>Address:</strong> <span id="walletAddress">Loading...</span></p>
<p><strong>Balance:</strong> <span id="walletBalance">Loading...</span> ETH</p>
<div id="wallet-button">
<button class="wallet white">Connect Wallet</button>
<button class="reset-wallet white">Reset Wallet Data</button>
</div>
</div>
<section id="sign-up" class="section-p1 section-m1">
<div class="newstext">
<h4>Sign up for latest news</h4>
<p>Get E-mail updates about our latest contents and <span>special offers.</span></p>
</div>
<div class="form">
<input type="text" placeholder="Your e-mail address">
<button class="normal">Sign Up</button>
</div>
</section>
<footer class="section-p1">
<div class="col-container">
<div class="col">
<img class="logo" src="img/logo.png" alt="logo">
<h4>Contact</h4>
<p><strong>Address:</strong> 1, Jalan Emas 2, Taman Bunga Tiga, Subang, Selanogr.</p>
<p><strong>Phone:</strong> +6012-345 6789</p>
<p><strong>Hours:</strong> 10:00 - 18:00, Mon - Sat</p>
<div class="follow">
<h4>Follow Us</h4>
<div class="icon">
<i class="fab fa-facebook-f"></i>
<i class="fab fa-twitter"></i>
<i class="fab fa-instagram"></i>
<i class="fab fa-pinterest-p"></i>
<i class="fab fa-youtube"></i>
</div>
</div>
</div>
<div class="col">
<h4>About</h4>
<a href="#">About Us</a>
<a href="#">Privacy Policy</a>
<a href="#">Terms and Conditions</a>
<a href="#">Contact Us</a>
</div>
<div class="col">
<h4>My Account</h4>
<a href="#">Sign In</a>
<a href="#">Wallet</a>
<a href="#">Track My History</a>
<a href="#">Help</a>
</div>
<div class="col install">
<h4>Install App</h4>
<p>From App Store or Google Play</p>
<div class="row">
<img src="img/pay/app.jpg" alt="App Store">
<img src="img/pay/play.jpg" alt="Google Play">
</div>
<p>Secured Payment Gateways</p>
<img src="img/pay/pay.png" alt="Payment Gateways">
</div>
</div>
<div class="copyright">
<p>© 2024, Confy</p>
</div>
</footer>
<script src="https://kit.fontawesome.com/494e0813cb.js" crossorigin="anonymous"></script>
<script>
console.log("Ethers.js loaded:", typeof ethers !== "undefined");
async function connectWallet() {
console.log("Attempting to connect to MetaMask...");
if (typeof window.ethereum !== 'undefined') {
try {
// Request connection to MetaMask
const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
if (accounts.length === 0) {
console.log("No accounts found.");
alert("No accounts found. Please check your MetaMask.");
return;
}
console.log("Accounts:", accounts);
const provider = new ethers.providers.Web3Provider(window.ethereum);
const walletAddress = accounts[0];
const balance = await provider.getBalance(walletAddress);
const balanceInEther = ethers.utils.formatEther(balance);
// Display wallet details
document.getElementById('walletAddress').textContent = walletAddress;
document.getElementById('walletBalance').textContent = balanceInEther;
alert("Wallet connected successfully!");
} catch (error) {
console.error("Error connecting wallet:", error);
if (error.code === 4001) {
alert("Connection request denied. Please authorize the connection in MetaMask.");
} else {
alert("Failed to connect wallet. Please try again or check the console for more details.");
}
}
} else {
alert("MetaMask is not installed. Please install MetaMask to connect your wallet.");
}
}
function resetWalletDisplay() {
document.getElementById('walletAddress').textContent = 'Not connected';
document.getElementById('walletBalance').textContent = 'N/A';
alert("Wallet data reset successfully!");
}
// Event Listeners for Wallet Actions
document.querySelector('.wallet').addEventListener('click', connectWallet);
document.querySelector('.reset-wallet').addEventListener('click', resetWalletDisplay);
</script>
</body>
</html>