-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
57 lines (54 loc) · 2.14 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>App</title>
<link rel="icon" href="favicon.ico"/>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="dark:bg-zinc-800 bg-white min-h-screen">
<body
class="bg-zinc-100 dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 transition-colors duration-300"
>
<div class="max-w-4xl mx-auto p-4 sm:p-8 md:p-12 lg:px-16 lg:py-24">
<h1 class="text-3xl md:text-4xl lg:text-5xl font-bold mb-4">Pi Network SDK Integration</h1>
<p class="text-lg md:text-xl">
This example demonstrates how to integrate the Pi Network SDK into a web application.
</p>
<div id="user-info" class="mt-8 p-4 bg-white dark:bg-zinc-800 rounded-lg shadow-md"></div>
<button
id="authenticate"
class="mt-8 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded transition-colors duration-200 ease-in-out"
>
Authenticate with Pi
</button>
</div>
<script src="https://sdk.minepi.com/pi-sdk.js"></script>
<script>
Pi.init({ version: "2.0", sandbox: true });
document.getElementById('authenticate').addEventListener('click', () => {
Pi.authenticate(['username', 'payments', 'wallet_address'], onIncompletePaymentFound)
.then((authResult) => {
displayUserInfo(authResult.user);
})
.catch((error) => {
console.error('Authentication failed', error);
});
});
function onIncompletePaymentFound(payment) {
console.log('Incomplete payment found', payment);
// Handle the incomplete payment here, e.g., by sending it to your server
}
function displayUserInfo(user) {
const userInfoDiv = document.getElementById('user-info');
userInfoDiv.innerHTML = `
<div class="text-lg md:text-xl">
<p class="font-semibold"><span class="text-blue-500 dark:text-blue-400">UID:</span> ${user.uid}</p>
<p class="font-semibold"><span class="text-blue-500 dark:text-blue-400">Username:</span> ${user.username}</p>
</div>
`;
}
</script>
</body>
</html>