Skip to content

Commit

Permalink
Add date count down script
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillweston committed Mar 31, 2024
1 parent dfad6b4 commit 64a38bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ Click [here](https://github.com/WalletConnect/blockchain-api/blob/master/SUPPORT
"address": "0xbA6a68677e0A16dcB1ff4BDDF613563133201280",
"transaction_count": 8552,
"airdrop_count": 1000000000,
"has_airdropped": false
"has_airdropped": false,
"scheduled_delivery": "2024-03-31T11:00:00Z"
}
}
```
Expand All @@ -148,6 +149,7 @@ Click [here](https://github.com/WalletConnect/blockchain-api/blob/master/SUPPORT
| `data.transaction_count` | Integer | The number of transactions associated with the address. |
| `data.airdrop_count`| Integer | The airdrop count for the address, which is either `0` or `1000000000`. |
| `data.has_airdropped` | Boolean | Indicates if the airdrop has occurred. `false` means airdrop has not started; `true` means airdrop has occurred, and the user cannot claim it again if already claimed. |
| `data.scheduled_delivery` | String | The next available time for claiming the airdrop. If it cannot be claimed (transaction_count <= 10), it will be set to 0000-12-31T00:00:00Z in UTC+0 timezone. |

## Setting Up `contract-config.json` for Local Deployment

Expand Down
20 changes: 13 additions & 7 deletions js/claim-airdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,31 @@ function checkUserEligibility() {
const txCount = data.data.transaction_count;
const hasAirdropped = data.data.has_airdropped;
const obtainedAddress = data.data.address;
const scheduledDelivery = new Date(data.data.scheduled_delivery);
const now = new Date();

// Compare the obtained address with the sent address
if (obtainedAddress.toLowerCase() !== fullAddress.toLowerCase()) {
throw new Error('The obtained address does not match the sent address');
throw new Error('The obtained address does not match the sent address, please refresh the browser cache and retry.');
}

if (txCount >= 10) {
if (scheduledDelivery.toISOString() === "0000-12-31T00:00:00Z" || txCount <= 10) {
displayMessage('You do not have the eligibility to claim the airdrop', 'info');
} else if (scheduledDelivery > now) {
// Calculate time difference and display countdown
let timeDiff = scheduledDelivery.getTime() - now.getTime();
let days = Math.floor(timeDiff / (1000 * 3600 * 24));
let hours = Math.floor((timeDiff % (1000 * 3600 * 24)) / (1000 * 3600));
let minutes = Math.floor((timeDiff % (1000 * 3600)) / (1000 * 60));
displayMessage(`Please wait: ${days} days, ${hours} hours, ${minutes} minutes for available airdrop`, 'info');
} else {
if (!hasAirdropped) {
// User is eligible, but airdrop has not started
console.log('Airdrop has not started yet. Please wait patiently.');
displayMessage('Airdrop has not started yet. Please wait patiently.', 'info');
} else {
// User is eligible and airdrop is available
console.log('User is eligible to claim the airdrop');
document.getElementById('claimAirdrop').textContent = 'Claim Your Airdrop';
}
} else {
// User is not eligible
displayMessage('You are not eligible to claim the airdrop', 'info');
}
} else {
throw new Error(data.error || 'Unknown error occurred');
Expand Down

0 comments on commit 64a38bd

Please sign in to comment.