Skip to content

Commit

Permalink
update frontend to show more details
Browse files Browse the repository at this point in the history
  • Loading branch information
jklepatch committed Apr 30, 2021
1 parent de968c5 commit da158a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
21 changes: 16 additions & 5 deletions token/airdrop/pages/api/authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ import Web3 from 'web3';

const recipientSchema = new mongoose.Schema({
address: String,
amount: Number
basicAllocation: String,
bonusAllocation: String,
totalAllocation: String
});
const Recipient = mongoose.models.Recipient || mongoose.model('Recipient', recipientSchema, 'recipients');
const Recipient = mongoose.models.Recipient || mongoose.model(
'Recipient',
recipientSchema,
'recipients'
);

export default async (req, res) => {
//1. get record
await mongoose.connect(
process.env.DB_URL,
{useNewUrlParser: true}
{
useNewUrlParser: true,
useUnifiedTopology: true
}
);
const recipient = await Recipient
.findOne({ address: req.body.address })
Expand All @@ -21,7 +30,7 @@ export default async (req, res) => {
if(recipient) {
const message = Web3.utils.soliditySha3(
{t: 'address', v: recipient.address},
{t: 'uint256', v: recipient.amount.toString()}
{t: 'uint256', v: recipient.totalAllocation.toString()}
).toString('hex');
const web3 = new Web3('');
const { signature } = web3.eth.accounts.sign(
Expand All @@ -32,7 +41,9 @@ export default async (req, res) => {
.status(200)
.json({
address: req.body.address,
amount: recipient.amount,
basicAllocation: recipient.basicAllocation,
bonusAllocation: recipient.bonusAllocation,
totalAllocation: recipient.totalAllocation,
signature
});
return;
Expand Down
13 changes: 9 additions & 4 deletions token/airdrop/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,29 @@ export default function Home() {
type: 'primary',
payload: `
Claiming token from Airdrop contract...
Amount: ${Web3.utils.fromWei(response.data.amount.toString())} ETB
Address: ${response.data.address}
Total Amount: ${Web3.utils.fromWei(response.data.totalAllocation.toString())} ETB
-> Basic allocation: ${Web3.utils.fromWei(response.data.basicAllocation.toString())} ETB
-> Bonus allocation: ${Web3.utils.fromWei(response.data.bonusAllocation.toString())} ETB
`
});
const receipt = await airdrop
.methods
.claimTokens(
response.data.address,
response.data.amount.toString(),
response.data.totalAllocation.toString(),
response.data.signature
)
.send({from: accounts[0]});
setClaimMessage({
type: 'primary',
payload: `Airdrop success!
Tokens successfully in tx ${receipt.transactionHash}
Amount: ${Web3.utils.fromWei(response.data.amount.toString())} ETB
Address: ${response.data.address}`
Address: ${response.data.address}
Total Amount: ${Web3.utils.fromWei(response.data.totalAllocation.toString())} ETB
-> Basic allocation: ${Web3.utils.fromWei(response.data.basicAllocation.toString())} ETB
-> Bonus allocation: ${Web3.utils.fromWei(response.data.bonusAllocation.toString())} ETB
`
});
} catch(e) {
if(e.message === 'Request failed with status code 401') {
Expand Down

0 comments on commit da158a9

Please sign in to comment.