-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
53 lines (46 loc) · 1.92 KB
/
test.js
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
var maxPercentage = 60;
if (window.location.href.indexOf('/lend') > -1) {
const WEB3_URL = window.location.href.includes('staging') ? "https://web3dev.ev.io:2096" : "https://web3.ev.io:2096";
$ = jQuery;
let ownerID;
let ownerUID;
async function lendNFT(uid, percentage, nftAddress, flagId) {
document.getElementById('lend-to-container').innerHTML = '<p>📡 Registering new scholarship..</p><br><br>';
document.getElementById('lend-update-earn').innerHTML = '<p>📡 Requesting scholarship update....</p><br><br>';
let sendData = {
uid,
nftAddress,
flagId,
percentage,
ownerID
};
const response = await fetch(WEB3_URL + '/lend', {
method: 'POST',
body: JSON.stringify(sendData)
});
const json = await response.json();
if (json.result.header) {
document.getElementById('lend-to-container').innerHTML = '<p>Approved.</p><br><br>';
document.getElementById('lend-update-earn').innerHTML = '<p>Approved.</p><br><br>';
if (json.result.header === 'ok') {
document.getElementById('lend-to-container').style.display = 'none';
document.getElementById('lend-done-confirmation').style.display = 'block';
window.location.reload();
} else {
if(json.result.cooldown)
{
console.log("cooldown");
document.getElementById('lend-to-container').innerHTML = '<br><p>You cannot lend this NFT for another '+ json.result.cooldown +'</p>';
setTimeout(()=>{ window.location.reload();}, 5000);
}
else
{
window.alert('Something went wrong lending your NFT. Please try again later.');
setTimeout(()=>{ window.location.reload(); }, 5000);
}
}
} else {
window.alert('Bad');
setTimeout(hidePopupUI, 1500);
}
};