-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
156 lines (142 loc) · 4.78 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/coins.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- font roboto -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet"
/>
<title>Yescoin - Home</title>
</head>
<body>
<div
id="loader"
class="absolute z-10 w-full h-screen bg-black flex justify-center items-center"
>
<span class="loading loading-dots loading-lg"></span>
</div>
<div id="root"></div>
<script>
const loader = document.getElementById("loader");
const initializeApp = async () => {
const getUserId = localStorage.getItem("userId");
const data = {
points: 0,
totalRefer: 0,
friendList: [],
};
const referUrl = window.location.search;
// refer user create
if (referUrl && !getUserId) {
try {
const referId = referUrl.split("=")[1].split("&")[0];
if (referId) {
// update data points
data.points = 50000;
data.friendList.push(referId);
}
// refer code user create
if (!getUserId) {
try {
const response = await fetch(
"https://yescoin-server-bt120s.vercel.app/users",
{
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-type": "application/json",
},
}
);
const responseData = await response.json();
if (responseData?.userId) {
const userId = responseData.userId;
localStorage.setItem("userId", userId);
}
} catch (e) {
console.log(e);
}
}
// update refer information
if (getUserId !== referId) {
// load refer user information
const response = await fetch(
`https://yescoin-server-bt120s.vercel.app/users/${referId}`
);
const responseData = await response.json();
// update refer information
const points = 50000;
const totalRefer = responseData.totalRefer + 1;
const prevFriend = responseData.friendList;
const newFriendId = localStorage.getItem("userId");
const newFriendList = [...prevFriend, newFriendId];
const referUserData = {
points,
totalRefer,
friendList: newFriendList,
};
// save refer information
const resUser = await fetch(
`https://yescoin-server-bt120s.vercel.app/users/${referId}`,
{
method: "PATCH",
body: JSON.stringify(referUserData),
headers: {
"Content-type": "application/json",
},
}
);
const resUserData = await resUser.json();
}
} catch (err) {
console.log(err);
}
} else {
// no refer code user create
if (!getUserId) {
try {
const response = await fetch(
"https://yescoin-server-bt120s.vercel.app/users",
{
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-type": "application/json",
},
}
);
const responseData = await response.json();
if (responseData?.userId) {
const userId = responseData.userId;
localStorage.setItem("userId", userId);
}
} catch (e) {
console.log(e);
}
}
}
// load window
if (referUrl) {
window.location.href = window.location.origin;
}
};
initializeApp();
</script>
<script type="module" src="/src/main.jsx"></script>
<script>
let hasLoaded = false;
// Delay displaying rootEle by 0.6 seconds, but only execute once
if (!hasLoaded) {
setTimeout(function () {
loader.style.display = "none";
hasLoaded = true;
}, 3000);
}
</script>
</body>
</html>